[En-Nut-Discussion] detecting UART parity errors
Trevor O'Grady
togrady at comtech.uk.com
Fri Jan 2 15:25:32 CET 2004
>However, I'd prefer to fix parity error handling in the new driver.
>No question, I'd welcome if you add (and test) the required
>modifications, send it to me and I'll commit it. :-)
Hi Harold,
Here is the modified RxComplete function (uartavr.c) that discards bytes
received with parity error. Sorry it took so long but I struggled with
building the OS until I changed from ICC to winavr.
I have tested all combinations ( parity = none, odd and even )and it works.
I have tested this on a mega128 (Ethernut 1.3F). There was no define for
USR1 so I had to use UCSR1A.
static void RxComplete(void *arg)
{
NUTDEVICE *dev = (NUTDEVICE *) arg;
IFSTREAM *ifs = dev->dev_icb;
UARTDCB *dcb;
u_char par;
#ifdef UDR1
if (dev->dev_base)
{
par = inp (UCSR1A) & 0x04; //parity error if UCSRnA bit 2 is set
ifs->if_rx_buf[ifs->if_rx_idx] = inp(UDR1);
}
else
#endif
{
par = inp (USR) & 0x04; //parity error if UCSRnA bit 2 is set
ifs->if_rx_buf[ifs->if_rx_idx] = inp(UDR);
}
if(!par) {
if (ifs->if_rd_idx == ifs->if_rx_idx++) {
dcb = dev->dev_dcb;
NutEventPostAsync(&dcb->dcb_rx_rdy);
}
}
}
Regards and happy new year,
Trevor
More information about the En-Nut-Discussion
mailing list