linux 串口对应设备,Linux驱动系列———USB转串口cp210x设备驱动

本文详细介绍了Linux系统中USB转串口设备驱动的原理和实现,包括USB设备驱动模型、USB驱动结构、USB驱动注册、线路规程设置以及USB设备驱动程序的探测函数。重点解析了`usb_driver`结构体、`probe()`和`disconnect()`函数,以及如何通过`usb_serial_probe()`进行设备初始化工作。
摘要由CSDN通过智能技术生成

USB设备驱动程序用来驱动相应的USB设备,USB设备驱动用usb_driver表示,它主要用来将USB设备挂接到USB核心中,并启动USB设备,让其正常工作。对于USB设备的具体读写操作由放在usb_driver设备中的usb_class_drivers成员来实现,该成员定义了一个file_operations结构体,用来对设备进行读写操作。

1. USB设备驱动模型

设备需要驱动才能正常工作,所以当系统检测到设备时,应该将其与对应的驱动程序绑定。设备与驱动的绑定,只能够在同一总线上的设备与驱动之间进行。总线与设备和驱动的连接,需要相应总线的核心代码来实现。对于USB总线,实现总线与驱动和设备的连接,是通过USB核心(USB core)来完成的。

USB core会完成总线的初始化工作,然后再扫描USB总线,看USB总线上连接了那一些设备。当USB core发现设备的时候,会为其分配一个struct device结构体,并将其连接到总线上。当发现所有的设备以后,USB总线上的设备链表就建立好了。

相比设备的连接,将驱动连接到总线上就更简单。每当驱动注册的时候,会将自己在总线上注册,并连接到总线的驱动链表中。这时,驱动会遍历总线的设备链表,寻找合适的设备,并将其通过内部指针联系起来。

2.USB驱动结构

在USB设备驱动模型中,USB设备驱动使用usb_driver结构体来表示,该结构体中包含了与具体设备相关的核心函数,对于不同的设备,需要实现不同功能的函数。usb_driver结构体的定义如下:

This bundle contains a modified CP210x driver for the 4.10.0 kernel (Ubuntu 17.04). It contains: - Support for the CP2102N NOTE: This driver is an example of how to perform GPIO operations within the CP210x driver since the driver on kernel.org does not support GPIO at this time. This driver has only been written and tested on the Linux 3.13.0 kernel on Ubuntu 14.04. This driver is a modified version of the existing driver in the Linux 3.13.0 kernel, which is maintained at kernel.org. It is recommened to use the driver there that matches your specific kernel version: www.kernel.org Build instrutions: Ubuntu: 1. make ( your cp210x driver ) 2. cp cp210x.ko to /lib/modules//kernel/drivers/usb/serial 3. insmod /lib/modules/<kernel-version/kernel/drivers/usb/serial/usbserial.ko 4. insmod cp210x.ko RedHat: 1. yum update kernel* //need to update the kernel first otherwise your header won't match 2. yum install kernel-devel kernel-headers //get the devel and header packages. 3. reboot //your build link should be fixed after your system come back 4. make ( your cp210x driver ) // should be able to build successfully at this point 5. cp cp210x.ko to /lib/modules//kernel/drivers/usb/serial 6a. insmod /lib/modules/<kernel-version/kernel/drivers/usb/serial/usbserial.ko 6. insmod cp210x.ko 7. sudo chmod 666 /dev/ttyUSB0 8. sudo chmod 666 /dev/ttyUSB1 GPIO example: This shows how to use the two IOCTLs to set GPIO state. Build instructions: 1. g++ cp210x_gpio_example.c -o cp210x_gpio_example 2. ./cp210x_gpio_example
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值