1 |
Hi Bob, |
2 |
|
3 |
Great tip! It lead to serial_core.c (for processing TIOCSERGETLSR) and |
4 |
to serial_reg.h (for defining UART_LSR_BI/FE/PE/etc). I'm pleasantly |
5 |
surprised to see that the UART_LSR_xx symbols have values that |
6 |
numerically match the register bits. |
7 |
|
8 |
Thanks for the tip! |
9 |
|
10 |
Regards, |
11 |
|
12 |
David |
13 |
|
14 |
-----Original Message----- |
15 |
From: Bob Dunlop [mailto:bob.dunlop@×××××××××.uk] |
16 |
Sent: Wednesday, April 21, 2010 2:51 PM |
17 |
To: gentoo-embedded@l.g.o |
18 |
Subject: Re: [gentoo-embedded] displaying serial port status |
19 |
|
20 |
Hi again, |
21 |
|
22 |
On Wed, Apr 21 at 01:14, Relson, David wrote: |
23 |
> Gretings, |
24 |
> |
25 |
> In the old days when we used direct port I/O to perform serial port |
26 |
actions, code like the following would display the port's status: |
27 |
> |
28 |
> #define BASE 0x03F8 /* COM1 port base address */ |
29 |
> #define LS_REG (BASE+5) /* Line Status Register */ |
30 |
> |
31 |
> void ShowLineStatus(void) |
32 |
> { |
33 |
> int status = inportb(LS_REG); |
34 |
> if (status & 0x02) printf("Overrun Error\n"); |
35 |
> if (status & 0x04) printf("Parity Error\n"); |
36 |
> if (status & 0x08) printf("Framing Error\n"); |
37 |
> if (status & 0x10) printf("Break Interrupt\n"); |
38 |
> if (status & 0x80) printf("Timeout Error\n"); |
39 |
> } |
40 |
> |
41 |
> How does one perform the same thing for /dev/ttyS0 (or any other |
42 |
serial port)? |
43 |
|
44 |
#include <termios.h> /* or ioctl.h (can't remember) |
45 |
*/ |
46 |
|
47 |
int fd = open("/dev/ttyS0", O_RDWR); |
48 |
int status; |
49 |
|
50 |
ioctl (fd, TIOCSERGETLSR, &status); |
51 |
/* Print as above */ |
52 |
|
53 |
You might want to add error checking. Also remember the live LSR may |
54 |
not be |
55 |
syncronised with the characters your are currently reading if there is a |
56 |
queue anywhere. To get an inline marker of an error use PARMRK in your |
57 |
termios structure. |
58 |
|
59 |
|
60 |
Alternativly you might want to look at the TIOCGICOUNT ioctl. This |
61 |
fills out |
62 |
a serial_icounter_struct (see /usr/include/linux/serial.h) with counts |
63 |
of the |
64 |
number of overrun errors etc. |
65 |
|
66 |
|
67 |
-- |
68 |
Bob Dunlop |