This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Reading serial ports with timeout
- From: "Laurie Gellatly" <laurie dot gellatly at netic dot com>
- To: <ecos-discuss at ecos dot sourceware dot org>
- Date: Wed, 16 Jan 2008 22:03:07 +1100
- Subject: [ECOS] Reading serial ports with timeout
Hi All,
On my LPC2212 board I have serial 1 running at 115K baud.
The data coming into the port is CRC checked.
What we've found is that when the micro at the other end of the serial sends
a packet,
(say 60 bytes) about 10% of the time, one of the characters in the data
stream is missed.
I can sniff the line and see the characters are all there, but my
application misses one at random.
The serial port is interrupt driven. We don't use the 16 char FIFO.
Our code does this:
while( iDataItr < L2OVERHEADSIZE-1 ) { // need more chars
cyg_io_get_config(ser_handle, CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO,
&serial_buffer_info, &iLen); // How many available?
while( (serial_buffer_info.rx_count != 0) && (iDataItr <
L2OVERHEADSIZE-1) ){ // There are some ready and we need them
cyg_io_read( ser_handle, &ucHeader[iDataItr++], &iNumBytesToRead );
//blocking read 1 char in
cyg_io_get_config(ser_handle, CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO,
&serial_buffer_info, &iLen); // How many available now?
}
ulTimeNow = cyg_current_time(); // What the time now
if( (ulTimeNow - ulTimeStart) > iTimeToWait ){ // Has it taken too long to
read them in (timeout)?
printf( "Error: processRXPacket(): Header timeout!!\n");
return PROCESSRX_TIMEOUT;
}
}
Which is basically,
While we have more data to get, get the number of characters ready to be
read.
While there are characters available and we need more
read the next 1 character and add it to the buffer
find out how many characters are ready to be read now?
Get the current time
check to see if its been too long to get this data
When I looked at eCos' PPP implementation I see it uses cyg_alarm_xxx and
just blocks on a cyg_io_read
Is that the 'right' way to do this? Can someone see a flaw in the existing
code?
Many thanks ...Laurie:{)
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss