0

Assume that we have a serial device /dev/ttyS0 with a deafult speed 9600 bps.

Say, we have changed its speed to, for example, 4800 bps using cfsetospeed.

Now, the speed of writing to the wire must be slower.

Where is the source code that does this operation? Which part of the operating system controls this speed? Custom driver, tty driver or what? And how, by setting clock speed or delaying?

It may be in the driver, but I couldn't find it. For example, could anyone show me the place in RocketPort driver?

I also couldn't find in tty driver.

1

Serial port speed is typically handled by the hardware itself, and is configured by the hardware driver.

So the chain to follow would be the TCSETS ioctl call, which calls tty_set_termios() in tty_ioctl.c. If you followed that chain through then in the RocketPort driver it would call rp_set_termios() which, itself, calls configure_r_port().

This does some calculation of configuration settings to send to the RocketPort chip (e.g. the divisor setting), which eventually calls the sSetBaud (defined in rocket_int.h), which simply outputs the bytes to the chip.

So the kernel, itself, doesn't do "bit banging" of the serial lines to determine baud rate; the UART chip does all that hard work for us. We just need to program the chip :-)

  • Stephen, thanks for the awesome answer. You really enlightened me on. – Ricardo Cristian Ramirez Jul 30 '17 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.