drivers: UART based drivers could now use uart_flush_input() to discard junk bytes on input.

This commit is contained in:
Romuald Conty 2011-05-25 10:31:19 +00:00
parent 22e25a8b1e
commit 917717c4ca
5 changed files with 44 additions and 3 deletions

View file

@ -100,9 +100,6 @@ uart_open (const char *pcPortName)
sp->tiNew.c_cc[VMIN] = 0; // block until n bytes are received
sp->tiNew.c_cc[VTIME] = 0; // block until a timer expires (n * 100 mSec.)
// This line seems to produce absolutely no effect on my system (GNU/Linux 2.6.35)
tcflush (sp->fd, TCIFLUSH);
if (tcsetattr (sp->fd, TCSANOW, &sp->tiNew) == -1) {
uart_close (sp);
return INVALID_SERIAL_PORT;
@ -110,6 +107,29 @@ uart_open (const char *pcPortName)
return sp;
}
void
uart_flush_input (serial_port sp)
{
// This line seems to produce absolutely no effect on my system (GNU/Linux 2.6.35)
tcflush (((serial_port_unix *) sp)->fd, TCIFLUSH);
// So, I wrote this byte-eater
// Retrieve the count of the incoming bytes
int available_bytes_count = 0;
int res;
res = ioctl (((serial_port_unix *) sp)->fd, FIONREAD, &available_bytes_count);
if (res != 0) {
return;
}
if (available_bytes_count == 0) {
return;
}
char* rx = malloc (available_bytes_count);
// There is something available, read the data
res = read (((serial_port_unix *) sp)->fd, rx, available_bytes_count);
DBG ("%d bytes have eatten.", available_bytes_count);
free (rx);
}
void
uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
{