Gentoo Archives: gentoo-embedded

From: David Relson <relson@×××××××××××××.com>
To: gentoo-embedded@l.g.o
Cc: bob.dunlop@×××××××××.uk
Subject: Re: [gentoo-embedded] serial port handling question
Date: Thu, 14 Jan 2010 12:29:52
Message-Id: 20100114072913.2d8c52de@osage.osagesoftware.com
In Reply to: Re: [gentoo-embedded] serial port handling question by Bob Dunlop
1 On Thu, 14 Jan 2010 10:05:31 +0000
2 Bob Dunlop wrote:
3
4 > On Wed, Jan 13 at 06:52, David Relson wrote:
5 > ...
6 > > Directly tweaking the I/O port runs against the grain, but it's the
7 > > only thing I've found that works.
8 > >
9 > > Is there a better way to control the chip?
10 >
11 >
12 > I know others have commented on using automatic settings for flow
13 > control etc, but if you need to control the lines directly there are
14 > an often neglected set of ioctls to do this.
15 >
16 > Some snippets of code, last used on x86 four years ago but it looks
17 > like the hooks are still in the kernel and a fair number of device
18 > drivers.
19 >
20 > unsigned int flags;
21 >
22 > /* Raise RTS and DTR.
23 > * Linux will have already done this but some Unix system don't
24 > and
25 > * some wait for DCD before doing so, so make it explicit.
26 > */
27 > flags = TIOCM_RTS | TIOCM_DTR;
28 > if ( ioctl( fd, TIOCMBIS, &flags ) != 0 )
29 > {
30 > fprintf( stderr,"Failed to raise RTS and DTR. Errno %d\n",
31 > errno ); /* Possibly not fatal so we continue */
32 > }
33 >
34 > ...
35 >
36 > /* Drop RTS */
37 > flags = TIOCM_RTS;
38 > if ( ioctl( fd, TIOCMBIC, &flags ) != 0 )
39 > {
40 > fprintf( stderr,"Failed to clear RTS. Errno %d\n", errno );
41 > }
42 >
43 > As well as set and clear there is a get (TIOCMGET) useful for
44 > checking DCD.
45 >
46 > --
47 > Bob Dunlop
48
49 Sweet! Very sweet!
50
51 This sounds exactly like what I want. I saw the TIOCM_xxx symbols
52 being used in serial8250_get_mctrl() and serial8250_set_mctrl(), but
53 didn't know how to access those functions.
54
55 I'll test it later this morning when I get to work.
56
57 Regards,
58
59 David

Replies

Subject Author
Re: [gentoo-embedded] serial port handling question Peter Stuge <peter@×××××.se>