Skip to content

Commit

Permalink
pserial: Support usb2serial convertors
Browse files Browse the repository at this point in the history
This patch fixes the bugs which prevented support of usb2serial
devices. Tested with FT232BM and prolific usb2serial convertors

Signed-off-by: Nishanth Menon <nm@ti.com>
  • Loading branch information
nmenon authored and Nishanth Menon committed Dec 5, 2008
1 parent e8a54cc commit d597d0b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
5 changes: 2 additions & 3 deletions README
Expand Up @@ -30,9 +30,8 @@ documentation in docs/html/index.html file
==========
Before using any tools, I would love to know it's limitations, hence the
section 0 ;). some of the known caveats at the time of writing are:
a) USB2serial convertors and pserial dont like each other on Linux
b) pusb does not yet work on windows. This is still a work in progress
c) ukermit is cranky when used with large packets - it is disabled at the moment
a) pusb does not yet work on windows. This is still a work in progress
b) ukermit is cranky when used with large packets - it is disabled at the moment

1) COMPILATION Environment:
===========================
Expand Down
1 change: 0 additions & 1 deletion docs/caveat.dox
@@ -1,7 +1,6 @@
/**
@page ub_caveats Known Caveats
The following lists the known issues with omap U-Boot utils
@li USB2serial convertors and pserial dont like each other on Linux
@li pusb does not yet work on windows. This is still a work in progress
@li ukermit is cranky when used with large packets - it is disabled at the moment
*/
24 changes: 21 additions & 3 deletions lib/serial_posix.c
Expand Up @@ -41,7 +41,6 @@

#include <serial.h>


/************* CONSTS ***************/
#define S_ERROR(ARGS...) perror("Serial: System Error"); fprintf(stderr,ARGS)
#ifdef DEBUG
Expand All @@ -51,6 +50,9 @@
#define S_INFO(ARGS...)
#endif

/* Setup delay time */
#define VTIME_SET 5

/************* VARS ***************/
static unsigned char port[30];
static int fd;
Expand Down Expand Up @@ -178,15 +180,17 @@ signed char s_configure(unsigned long s_baud_rate, unsigned char s_parity,
return SERIAL_FAILED;
}

newtio.c_iflag |= IGNBRK;
newtio.c_cflag |= CLOCAL | CREAD;

S_INFO("c_cflag: 0x%08x\n", (unsigned int)(newtio.c_cflag));

newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = VTIME_SET;
newtio.c_cc[VMIN] = 1;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VSWTC] = 0;
ret = tcflush(fd, TCIFLUSH);
if (ret < 0) {
S_ERROR("failed to set flush buffers\n");
Expand Down Expand Up @@ -239,12 +243,26 @@ signed char s_close(void)
S_ERROR("terminal is not open!\n");
return SERIAL_FAILED;
}
/*
* To prevent switching modes before the last vestiges
* of the data bits have been send, sleep a second.
* This seems to be especially true for usb2serial
* convertors.. it does look as if the data is buffered
* at the usb2serial device itself and closing/changing
* attribs before the final data is pushed is going to
* kill the last bits which need to be send
*/
sleep(1);
/* restore the old port settings */
ret = tcsetattr(fd, TCSANOW, &oldtio);
if (ret < 0) {
S_ERROR("failed to rest old settings\n");
return SERIAL_FAILED;
}
ret = tcflush(fd, TCIFLUSH);
if (ret < 0) {
S_ERROR("failed to flush serial file handle\n");
}
ret = close(fd);
fd = 0;
if (ret < 0) {
Expand Down Expand Up @@ -272,7 +290,7 @@ signed int s_read(unsigned char *p_buffer, unsigned long size)
}
/* read entire chunk.. no giving up! */
newtio.c_cc[VMIN] = size;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VTIME] = VTIME_SET;
ret = tcsetattr(fd, TCSANOW, &newtio);
ret = read(fd, p_buffer, size);
if (ret < 0) {
Expand Down

0 comments on commit d597d0b

Please sign in to comment.