displaying serial port status
Hi Bob,
Great tip! It lead to serial_core.c (for processing TIOCSERGETLSR) and
to serial_reg.h (for defining UART_LSR_BI/FE/PE/etc). I'm pleasantly
surprised to see that the UART_LSR_xx symbols have values that
numerically match the register bits.
Thanks for the tip!
Regards,
David
-----Original Message-----
From: Bob Dunlop [mailto:bob.dunlop@xyzzy.org.uk]
Sent: Wednesday, April 21, 2010 2:51 PM
To: gentoo-embedded@lists.gentoo.org
Subject: Re: [gentoo-embedded] displaying serial port status
Hi again,
On Wed, Apr 21 at 01:14, Relson, David wrote:
> Gretings,
>
> In the old days when we used direct port I/O to perform serial port
actions, code like the following would display the port's status:
>
> #define BASE 0x03F8 /* COM1 port base address */
> #define LS_REG (BASE+5) /* Line Status Register */
>
> void ShowLineStatus(void)
> {
> int status = inportb(LS_REG);
> if (status & 0x02) printf("Overrun Error
");
> if (status & 0x04) printf("Parity Error
");
> if (status & 0x08) printf("Framing Error
");
> if (status & 0x10) printf("Break Interrupt
");
> if (status & 0x80) printf("Timeout Error
");
> }
>
> How does one perform the same thing for /dev/ttyS0 (or any other
serial port)?
#include <termios.h> /* or ioctl.h (can't remember)
*/
int fd = open("/dev/ttyS0", O_RDWR);
int status;
ioctl (fd, TIOCSERGETLSR, &status);
/* Print as above */
You might want to add error checking. Also remember the live LSR may
not be
syncronised with the characters your are currently reading if there is a
queue anywhere. To get an inline marker of an error use PARMRK in your
termios structure.
Alternativly you might want to look at the TIOCGICOUNT ioctl. This
fills out
a serial_icounter_struct (see /usr/include/linux/serial.h) with counts
of the
number of overrun errors etc.
--
Bob Dunlop
|