Once again, I am writing a buffered, interrupt-driven driver for the serial comm UART (SCI) in the TI TMS320F2812. The lowest level interface to the user will be a function
returns the next character received or EOF if nothing is available.
However, if there is an error in the receiver, there appear to be two ways to inform the user space:
- On the call to SCI_getc() after all valid chars have been removed from the buffer, return a special code other than EOF, such as a:
#define SCI_RXERR -2 /* or something like that */
Now if detailed info on the nature of the error were needed in this case, a call such as SCI_status() could provide this. In this case, the user mustn't always call SCI_status() after an EOF to find out if it was really no char available, or an error.
Since serial reception fundamentally differs from file IO, I find this option attractive.
- The second option is to return EOF always if there is no char available or there is an error, similar to fgetc(). Then the user would have to call another function SCI_status() or the like to get a code which can be parsed to determine the specific nature of the error.
Since the SCIx_getc() call will frequently return EOF while waiting for data, it seems cumbersome to always have to call SCI_status() to see if it was due to an error.
What is typically done?
Thanks for input.