简体   繁体   English

Linux上的用户空间串行通信库

[英]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). 我需要开发一个(用户空间)库来处理Linux上的串行通信(在Zynq-Zybo板上: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. 我浏览了各种网站和资料,并研究了xilinx-linux内核,以及有关O'Reilly Linux Device Drivers的一些参考。
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.). 到目前为止,我发现:Linux已经包含自己的内核模块来处理通信(例如:UART内核模块处理外围设备,以便它们显示在/ dev /中,并且可以通过该设备文件与该设备进行交互。从用户空间使用打开,读取,写入等)。
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 编写一个用户空间库,该库通过经典的open,read,write与所提供的设备文件(在/ dev / ..中)进行简单交互
  • 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 参考上图,开发一个字符设备驱动程序,并将此模块包含在内核中,以便用户空间库仅通过IOCTL(或类似方法)与之交互,然后此新模块将直接与(现有)设备进行交互司机
    (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-) (但是,这种解决方案对我来说听起来不太好:我读到在内核模块内部使用用户空间之类的东西,例如open,read,write并不是一个好主意-尽管可能)-

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 快速搜索中似乎有很多库,所以不确定为什么要发明轮子,例如https://www.acmesystems.it/user_i2c

but anyway if it is new type of bus/device, a user space library is always good approach 但是无论如何,如果它是新型的总线/设备,那么用户空间库始终是一个好方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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