public inbox for gentoo-embedded@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-embedded] displaying serial port status
@ 2010-04-21 17:14 Relson, David
  2010-04-21 18:51 ` Bob Dunlop
  0 siblings, 1 reply; 3+ messages in thread
From: Relson, David @ 2010-04-21 17:14 UTC (permalink / raw
  To: gentoo-embedded

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\n");
    if (status & 0x04) printf("Parity Error\n");
    if (status & 0x08) printf("Framing Error\n");
    if (status & 0x10) printf("Break Interrupt\n");
    if (status & 0x80) printf("Timeout Error\n");
}

How does one perform the same thing for /dev/ttyS0 (or any other serial port)?

I've been looking at various ioctl's, but haven't yet spotted one that provides information on overrun errors, parity errors, etc.

Thanks in advance!
 
David




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-embedded] displaying serial port status
  2010-04-21 17:14 [gentoo-embedded] displaying serial port status Relson, David
@ 2010-04-21 18:51 ` Bob Dunlop
  2010-04-21 19:24   ` Relson, David
  0 siblings, 1 reply; 3+ messages in thread
From: Bob Dunlop @ 2010-04-21 18:51 UTC (permalink / raw
  To: gentoo-embedded

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\n");
>     if (status & 0x04) printf("Parity Error\n");
>     if (status & 0x08) printf("Framing Error\n");
>     if (status & 0x10) printf("Break Interrupt\n");
>     if (status & 0x80) printf("Timeout Error\n");
> }
> 
> 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [gentoo-embedded] displaying serial port status
  2010-04-21 18:51 ` Bob Dunlop
@ 2010-04-21 19:24   ` Relson, David
  0 siblings, 0 replies; 3+ messages in thread
From: Relson, David @ 2010-04-21 19:24 UTC (permalink / raw
  To: gentoo-embedded

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\n");
>     if (status & 0x04) printf("Parity Error\n");
>     if (status & 0x08) printf("Framing Error\n");
>     if (status & 0x10) printf("Break Interrupt\n");
>     if (status & 0x80) printf("Timeout Error\n");
> }
> 
> 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-04-21 20:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-21 17:14 [gentoo-embedded] displaying serial port status Relson, David
2010-04-21 18:51 ` Bob Dunlop
2010-04-21 19:24   ` Relson, David

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox