Browse files

Update Commit

- trying to get ftdi-based connection to work (uno32 arm7-kit)
- [bugfix] make pack failed looking for my1console binary
  • Loading branch information...
1 parent 45c312a commit 8aabf039cf4f2c76a068348629378216ec026a31 @azman committed Nov 21, 2012
Showing with 51 additions and 3 deletions.
  1. +1 −1 makefile
  2. +34 −0 src/my1comlib.c
  3. +4 −1 src/my1comlib.h
  4. +12 −1 src/my1termu.c
View
2 makefile
@@ -37,7 +37,7 @@ ifeq ($(DO_MINGW),YES)
LFLAGS += -L$(XTOOL_DIR)/lib
endif
-PACKDAT += $(CONSPRO) $(TESTPRO)
+PACKDAT += $(CONSPRO)
CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)g++
debug: CFLAGS += -DMY1DEBUG
View
34 src/my1comlib.c
@@ -5,6 +5,7 @@
#include <unistd.h> /* close */
#include <fcntl.h> /* OPEN_DFLAG */
#include <sys/ioctl.h> /* FIONREAD */
+#include <linux/serial.h> /* struct serial_struct */
#endif
/*----------------------------------------------------------------------------*/
#ifdef DO_MINGW
@@ -32,6 +33,7 @@ void initialize_serial(ASerialPort_t* aPort)
/* reset handler/flag */
aPort->mHandle = INVALID_HANDLE_VALUE;
aPort->mPortIndex = INVALID_PORT_INDEX;
+ aPort->mPortType = MY1PORT_HARDWARE;
sprintf(aPort->mPortName,"%s",COM_PORT_NAME);
#ifdef DO_MINGW
/* configure 9600,N81 for COM */
@@ -141,6 +143,38 @@ int open_serial(ASerialPort_t* aPort)
aPort->mHandle = INVALID_HANDLE_VALUE;
return 0;
}
+ /* for FTDI-based usb to serial? pl2303 doesn't support hi-speed */
+ speed_t cBaudRate = cfgetispeed(&aPort->mTIO);
+ if(aPort->mPortType==MY1PORT_FTDIUSB&&cBaudRate>B38400)
+ {
+ speed_t cBaudDumb = B38400;
+ cfsetispeed(&aPort->mTIO, cBaudDumb);
+ cfsetospeed(&aPort->mTIO, cBaudDumb);
+ purge_serial(aPort);
+ tcsetattr(aPort->mHandle, TCSANOW, &aPort->mTIO);
+ struct serial_struct sio;
+ ioctl(aPort->mHandle, TIOCGSERIAL, &sio);
+ sio.flags=(sio.flags&(~ASYNC_SPD_MASK));
+ sio.custom_divisor=0;
+ switch(cBaudRate)
+ {
+ case B57600: sio.flags=(sio.flags&ASYNC_SPD_HI); break;
+ case B115200: sio.flags=(sio.flags&ASYNC_SPD_VHI); break;
+ case B230400: sio.flags=(sio.flags&ASYNC_SPD_SHI); break;
+ case B460800: sio.flags=(sio.flags&ASYNC_SPD_WARP); break;
+ case B921600: // not supported?!
+ {
+ sio.flags=(sio.flags&ASYNC_SPD_CUST);
+ sio.custom_divisor = sio.baud_base / 921600;
+ //sio.reserved_char[0]=0;
+ break;
+ }
+ }
+ ioctl(aPort->mHandle, TIOCSSERIAL, &sio);
+ /* in case changed by ftdi thingy */
+ cfsetispeed(&aPort->mTIO, cBaudRate);
+ cfsetospeed(&aPort->mTIO, cBaudRate);
+ }
#endif
}
return serial_opened(aPort);
View
5 src/my1comlib.h
@@ -25,6 +25,9 @@
#define MY1BAUD460800 6
#define MY1BAUD921600 7
/*----------------------------------------------------------------------------*/
+#define MY1PORT_HARDWARE 0
+#define MY1PORT_FTDIUSB 1
+/*----------------------------------------------------------------------------*/
#define MY1PIN_RTS 1
#define MY1PIN_CTS 2
#define MY1PIN_DTR 4
@@ -50,7 +53,7 @@ typedef struct __ASerialPort
struct termios mTIO, mTIOsave;
long mHandle;
#endif
- int mPortIndex;
+ int mPortIndex, mPortType;
char mPortName[MAX_COM_CHAR];
}
ASerialPort_t;
View
13 src/my1termu.c
@@ -31,6 +31,7 @@ void about(void)
printf(" --port <number> : port number between 1-%d.\n",MAX_COM_PORT);
printf(" --baud <number> : baudrate e.g. 9600(default),38400,115200.\n");
printf(" --tty <device> : alternate device name (useful in Linux).\n");
+ printf(" --ftdi : use setting for FTDI-based USB to Serial.\n");
printf(" --help : show this message. overrides other options.\n");
printf(" --scan : scan and list ports. overrides other options.\n");
printf(" --echo : generate local echo.\n");
@@ -143,7 +144,8 @@ int main(int argc, char* argv[])
ASerialConf_t cConf;
my1key_t key;
termopts_t options = 0x0;
- int terminal = 1, baudrate = 0, scan = 0, test, loop, mask, drag;
+ int terminal = 1, baudrate = 0, scan = 0, ftdi = 0;
+ int test, loop, mask, drag;
int pin_dtr = 1, pin_rts = 1;
char filename[FILENAME_LEN], *ptty = 0x0;
FILE* pfile;
@@ -190,6 +192,10 @@ int main(int argc, char* argv[])
continue;
}
}
+ else if(!strcmp(argv[loop],"--ftdi"))
+ {
+ ftdi = 1;
+ }
else if(!strcmp(argv[loop],"--help"))
{
about();
@@ -243,6 +249,11 @@ int main(int argc, char* argv[])
return 0;
}
+ if(ftdi)
+ {
+ cPort.mPortType = MY1PORT_FTDIUSB;
+ }
+
/* try to prepare port with requested terminal */
if(!terminal) terminal = find_serial(&cPort,0x0);
if(!set_serial(&cPort,terminal))

0 comments on commit 8aabf03

Please sign in to comment.