I need to develop a (userspace) library to handle serial communication on Linux (on Zynq-Zybo Board: UART, SPI, I2C).
I explored various websites and stuff, and investigated the xilinx-linux kernel, as well as some references on O'Reilly Linux Device Drivers book.
What I found so far is: Linux already includes its own kernel modules to handle the communication (for example: the UART kernel module handles the peripherals so that they show up in /dev/, and through that device file I can interact with the device from userspace using open, read, write, etc.).
I also read that, as a common pattern, interaction with the device driver is done through a character device driver, which is accessed in user-space and is responsible of the interaction with the device driver (details in the following image)
The ideas which came to my mind are:
- Writing a user-space library which simply interacts with the provided device file (in /dev/..) through the classic open, read, write
- Referring to the above image, develop a character device driver and include this module in the kernel, so that the userspace library just interacts with it through IOCTL (or similar) and then this new module will directly interact with the (pre-existent) device drivers
(This solution, however, doesn't sound too good to me: I read that using user-space stuff like open, read, write inside kernel modules is not a good idea -although it's possible-)
My question is: which way should i pursue, and why?
Also, whatever article/book/link on the subject will be highly appreciated.
Thanks in advance!