简体   繁体   中英

Userspace Serial communication Library on Linux

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!

from a quick search is seem like there is alot of libraries, so not sure why you want to invent the wheel eg https://www.acmesystems.it/user_i2c

but anyway if it is new type of bus/device, a user space library is always good approach

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM