Page MenuHomeFreeBSD

Allow control over initial state of RTS and DTR lines
ClosedPublic

Authored by shurd on Apr 23 2019, 8:47 PM.

Details

Summary

Some devices take undesired actions when RTS and DTR are
asserted. Some development boards for example will reset on DTR,
and some radio interfaces will transmit on RTS.

This patch allows "stty -f /dev/ttyu9.init -rtsdtr" to prevent
RTS and DTR from being asserted on open(), allowing these devices
to be used without problems.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 23940
Build 22857: arc lint + arc unit

Event Timeline

shurd created this revision.Apr 23 2019, 8:47 PM
kevans added a reviewer: ian.Apr 24 2019, 2:50 AM
kevans added a subscriber: ian.

Tagging @ian as well, as he may be interested in this for $work purposes.

I think this also needs to cover the DTR|RTS setting in ucom_open (^/sys/dev/usb/serial/usb_serial.c) for completeness sake, but I defer to @imp and @ian as they've likely got better intuition of how that should work.

shurd added a comment.Apr 24 2019, 4:26 PM

Tagging @ian as well, as he may be interested in this for $work purposes.
I think this also needs to cover the DTR|RTS setting in ucom_open (^/sys/dev/usb/serial/usb_serial.c) for completeness sake, but I defer to @imp and @ian as they've likely got better intuition of how that should work.

Hrm, presumably that's there for cases where ucom_open() is called via ucom_param() or ucom_attach_tty()?

Tagging @ian as well, as he may be interested in this for $work purposes.
I think this also needs to cover the DTR|RTS setting in ucom_open (^/sys/dev/usb/serial/usb_serial.c) for completeness sake, but I defer to @imp and @ian as they've likely got better intuition of how that should work.

Hrm, presumably that's there for cases where ucom_open() is called via ucom_param() or ucom_attach_tty()?

Yeah, that looks right. That gets a little bit tricky... if we're responding to an open of the tty, ucom will always invoke ucom_open through ucom_param because of how the lower layer operates. It'll subsequently get invoked as tsw_open, but at that point the upper layer will have already been initialized and it does nothing.

I think the right thing to do is probably to exclude only the ucom_attach_tty -> ucom_open path from honoring this.

ian added inline comments.Apr 25 2019, 5:56 PM
bin/stty/print.c
187

This seems insane, we have no precedent I can think of for a '--something' setting in stty, and it creates a potential conflict with getopt_long() style args, which are supported by linux stty, so you gotta think some day someone is going to add that to our version.

The option name should be nortsdtr, or the whole concept should be inverted to make it a positive CRTSDTR flag that's on by default and off with -rtsdtr.

share/man/man4/termios.4
1275

Manpage style requires a new sentence to begin on its own line.

shurd updated this revision to Diff 56724.Apr 26 2019, 6:17 PM

Address feedback, add support to umcs.

  • Use nortsdtr as the flag name rather than -rtsdtr.
  • Fix manpage style.
  • Add check in usb_serial.c to USB serial more devices.
  • Make umcs respect the flag in the ucom_cfg_open() callback.
imp added a comment.Apr 29 2019, 12:36 AM

I really dislike the noFOO stuff.
It should be like clocal. clocal ignores modem status lines on input.
One option is to call it just rtsdtr and -rtsdtr turns it off. It would default to being on, but that's tricky to implement
The other would be to call it something like cappready to signal that the application controls turning it on or off.

I know this is a somewhat meta comment, kinda late in the game.

bin/stty/print.c
187

Yes. I concur.

bin/stty/stty.1
148–149

Double negatives will generate much hate.

shurd updated this revision to Diff 56824.Apr 29 2019, 7:12 PM

Use rtsdtr as the stty argument to set the default mode, and -rtsdtr to
disable automatically asserting them on open().

This causes the stty argument to have the opposite polarity as the control
flag. The stty flag name can be renamed fairly easily, but the control flag
pretty much needs to default to zero.

shurd marked 4 inline comments as done.Apr 29 2019, 8:33 PM
imp accepted this revision.Jun 6 2019, 4:23 PM

Use rtsdtr as the stty argument to set the default mode, and -rtsdtr to
disable automatically asserting them on open().
This causes the stty argument to have the opposite polarity as the control
flag. The stty flag name can be renamed fairly easily, but the control flag
pretty much needs to default to zero.

mandtr is what I thought of, but rtsdtr works fine too.

This revision is now accepted and ready to land.Jun 6 2019, 4:23 PM
This revision was automatically updated to reflect the committed changes.