Gentoo Archives: gentoo-embedded

From: Bob Dunlop <bob.dunlop@×××××××××.uk>
To: gentoo-embedded@l.g.o
Subject: Re: [gentoo-embedded] serial port handling question
Date: Thu, 14 Jan 2010 10:06:35
Message-Id: 20100114100531.GA16436@xyzzy.org.uk
In Reply to: [gentoo-embedded] serial port handling question by David Relson
1 On Wed, Jan 13 at 06:52, David Relson wrote:
2 ...
3 > Directly tweaking the I/O port runs against the grain, but it's the
4 > only thing I've found that works.
5 >
6 > Is there a better way to control the chip?
7
8
9 I know others have commented on using automatic settings for flow control
10 etc, but if you need to control the lines directly there are an often
11 neglected set of ioctls to do this.
12
13 Some snippets of code, last used on x86 four years ago but it looks like
14 the hooks are still in the kernel and a fair number of device drivers.
15
16 unsigned int flags;
17
18 /* Raise RTS and DTR.
19 * Linux will have already done this but some Unix system don't and
20 * some wait for DCD before doing so, so make it explicit.
21 */
22 flags = TIOCM_RTS | TIOCM_DTR;
23 if ( ioctl( fd, TIOCMBIS, &flags ) != 0 )
24 {
25 fprintf( stderr,"Failed to raise RTS and DTR. Errno %d\n", errno );
26 /* Possibly not fatal so we continue */
27 }
28
29 ...
30
31 /* Drop RTS */
32 flags = TIOCM_RTS;
33 if ( ioctl( fd, TIOCMBIC, &flags ) != 0 )
34 {
35 fprintf( stderr,"Failed to clear RTS. Errno %d\n", errno );
36 }
37
38 As well as set and clear there is a get (TIOCMGET) useful for checking DCD.
39
40 --
41 Bob Dunlop

Replies

Subject Author
Re: [gentoo-embedded] serial port handling question David Relson <relson@×××××××××××××.com>