FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo Embedded

 
 
LinkBack Thread Tools
 
Old 04-21-2010, 05:14 PM
"Relson, David"
 
Default displaying serial port status

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)?

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
 
Old 04-21-2010, 06:51 PM
Bob Dunlop
 
Default 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
 
Old 04-21-2010, 07:24 PM
"Relson, David"
 
Default 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
 

Thread Tools




All times are GMT. The time now is 06:37 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org