tags:

views:

37

answers:

1

Hi,

I am a newbie to developing drivers for Linux ... . I am developing a SMS-driver (AT commands over serial port to modem) using TTY for accessing the serial port. The driver is written in C.

In the design messages from modem to driver can be triggered by two events:

1) Status as respond to AT commands issued by driver (i.e. expected messages)

2) Indication of new SMS (i.e. unexpected messages)

I am planning on two threads - one for writing to TTY and one for reading from TTY. Is it possible to configure TTY so that my read-thread wakes-up on incoming chars (i.e. read-thread is event-triggered and not based on polling)?

Best Regards, Witek

+2  A: 

I don't think you really want two threads. Typical program flow (write AT command, check response etc ...) will be easier to write and debug in a monothreaded program.

Waiting for chars can be made with select() call. The tty layer is mostly configured through the tcsetattr, tcgetattr and friends system call. With this call you can configure wether you want to be interrupted on new line or on each char for example. See man termios for the manpage. The two big options are wether you want the special characters like EOF, EOL Ctrl-C etc... to be treated has data (raw mode) or be interpreted by the tty layer (canonical mode).

See the part on select in the serial programming guide, or the select manpage for more info

shodanex
Agreed - single-threaded should be fine. Use `select()` to block until data is available either from the serial port or whatever clients your driver has, then `read()` the data and deal with it.
caf