Linux device driver for RS232 device in embedded system

I recently started learning how to write Linux device drivers for a specific project I'm working on. In the past, most of my work has been in non-OS devices, so Linux drivers and development are somewhat new to me. For a project I am working on, I have an embedded system running a Linux based operating system. I have an external device with RS232 control, for which I need to write a driver.

Questions:

1) Is there a way to access the serial ports using kernel space (and maybe use serial.h, serial_core.h, etc.) as is usually done, any good examples?

2) From what I've found, it looks like it would be much easier to access the serial ports in user space by simply opening dev / ttyS * and writing to it. When writing a driver for such a device (RS232 device) is it preferable to do it in user space or is there a way to write a kernel module? How is the decision made to write the driver as a kernel module over user space, or vice versa?

Are the drivers only for generic devices like UART / serial and then above, is it user space or should this driver be written as a kernel module? I appreciate the help, I couldn't find much information to answer my questions.

+3


source to share


1 answer


There are several times when a module that communicates over a serial port may be in the kernel. Pppd (Point to Point Protocol Daemon) is one example that Linux has some kernel code dedicated to this as it is high traffic usage for the serial interface and it also needs to deploy and put IP packets in kernel space.

Most other uses will work better from user space, since you have a good API that is already doing a lot of mistakes that can happen. It also reduces the likelihood that your mistakes will lead to a serious system crash.



Doing this from user space introduces some latency. Reads and writes are buffered, and it is often difficult to determine where the hardware actually resides in write operations, and it is not really possible to undo a write call that has already been made from user space, even if the hardware has not yet received the bytes.

My advice would be to first try to do this from user space and then move to OS if necessary. Even if it needs to be moved to an OS-level driver, you will most likely be able to make some progress in user space.

+2


source







All Articles