当前位置:首页 > 商业/管理/HR > 管理学资料 > USB设备驱动开发深度解析
嵌入式培训专家USBUSB设备驱动开发设备驱动开发主讲:宋宝华华清远见今天的内容Ø1.USB及驱动框架简介Ø1.1USB协议Ø1.2USB驱动的体系结构Ø2.主机端驱动Ø2.1主机控制器驱动Ø2.2设备驱动Ø3.设备端驱动Ø3.1设备控制器驱动Ø3.2gadget驱动Ø4.USBOTG华清远见USB协议(1)设备描述符配置0配置1接口0接口1接口0接口1接口2端点1端点2端点3端点…Ø设备、配置、接口和端点主机roothub设备设备hub设备设备hub设备设备设备Ø拓扑结构华清远见USB协议(2)Ø传输方式Ø控制(Control)传输方式Ø同步(Synchronization)传输方式Ø中断(Interrupt)传输方式Ø批量(Bulk)传输方式Ø事务处理华清远见USB协议(3)Ø设备状态Ø包格式华清远见直观的例子—U盘bDeviceSubClass0bDeviceProtocol0bMaxPacketSize064idVendor0x0781SanDiskCorp.idProduct0x5151bcdDevice0.10iManufacturer1SanDiskCorporationiProduct2CruzerMicroiSerial320060877500A1BE1FDE1bNumConfigurations1ConfigurationDescriptor:bLength9bDescriptorType2wTotalLength32bNumInterfaces1bConfigurationValue1iConfiguration0bmAttributes0x80MaxPower200mAInterfaceDescriptor:bLength9bDescriptorType4bInterfaceNumber0bAlternateSetting0bNumEndpoints2bInterfaceClass8MassStoragebInterfaceSubClass6SCSIbInterfaceProtocol80Bulk(Zip)iInterface0EndpointDescriptor:bLength7bDescriptorType5bEndpointAddress0x81EP1INbmAttributes2TransferTypeBulkSynchTypenonewMaxPacketSize512bInterval0EndpointDescriptor:bLength7bDescriptorType5bEndpointAddress0x01EP1OUTbmAttributes2TransferTypeBulkSynchTypenonewMaxPacketSize512bInterval1LanguageIDs:(length=4)0409English(US)Ølsusb华清远见USB驱动体系结构USB设备驱动Massstorage/CDC/HIDUSB核心USB主机控制器驱动OHCI/EHCI/UHCIUSB控制器OHCI/EHCI/UHCIGadget驱动(file_storage/serial...)GadgetAPIUDC驱动(omap/pxa2xx...)USB控制器OHCI/EHCI/UHCIUSB总线从运行Linux的主机侧看从运行Linux的设备侧看Ø从运行Linux的主机侧Ø从运行Linux的设备侧华清远见USB主机控制器驱动数据结构:Østructusb_hcdØstructhc_driverstaticconststructhc_driverxxx_hc_driver={.description=xxx_hcd_name,.product_desc=xxxOTGController,.hcd_priv_size=sizeof(xxx_hcd_t),.irq=xxx_hcd_irq,.flags=HCD_MEMORY|HCD_USB2,.start=xxx_hcd_start,.stop=xxx_hcd_stop,.urb_enqueue=xxx_hcd_urb_enqueue,.urb_dequeue=xxx_hcd_urb_dequeue,.endpoint_disable=xxx_hcd_endpoint_disable,.get_frame_number=xxx_hcd_get_frame_number,.hub_status_data=xxx_hcd_hub_status_data,.hub_control=xxx_hcd_hub_control,};API:structusb_hcd*usb_create_hcd(conststructhc_driver*driver,structdevice*dev,char*bus_name);MS1幻灯片8MS1StartsprocessingaUSBtransferrequestspecifiedbyaUSBRequestBlock(URB).mem_flagsindicatesthetypeofmemoryallocationtousewhileprocessingthisURB.MCSYSTEM,2008-12-12华清远见USB设备驱动体系结构华清远见USB设备驱动数据结构和APIØstructusb_driverstaticstructusb_driverskel_driver={.name=skeleton,.probe=skel_probe,.disconnect=skel_disconnect,.id_table=skel_table,};Østructusb_device_idstaticstructusb_device_idskel_table[]={{USB_DEVICE(USB_SKEL_VENDOR_ID,USB_SKEL_PRODUCT_ID)},{}};MODULE_DEVICE_TABLE(usb,skel_table);ØUSB字符设备intusb_register_dev(structusb_interface*intf,structusb_class_driver*class_driver);voidusb_deregister_dev(structusb_interface*intf,structusb_class_driver*class_driver);structusb_class_driver{char*name;/*sysfs中用来描述设备名*/structfile_operations*fops;/*文件操作结构体指针*/intminor_base;/*开始次设备号*/};华清远见USB设备驱动--URBusb_alloc_urb()中断:usb_fill_int_urb()批量:usb_fill_bulk_urb()控制:usb_fill_control_urb()等时:手工初始化isourbusb_submit_urb()usb核心、usb主机控制器处理urb-complete()usb_kill_urb()usb_unlink_urb()ØUSB请求块(USBrequestblock,urb)华清远见USB设备驱动实例分析ØUSB骨架程序ØUSB串口驱动ØUSB键盘驱动华清远见USB设备控制器驱动数据结构Østructusb_ep_opsstaticstructusb_ep_opsxxx_ep_ops={.enable=xxx_ep_enable,.disable=xxx_ep_disable,.alloc_request=xxx_alloc_request,.free_request=xxx_free_request,.alloc_buffer=xxx_alloc_buffer,.free_buffer=xxx_free_buffer,.queue=xxx_ep_queue,.dequeue=xxx_ep_dequeue,.set_halt=xxx_ep_set_halt,};Østructxxx_udcstructxxx_udc{structusb_gadgetgadget;structusb_gadget_driver*driver;...};Østructusb_gadget_opsstaticconststructusb_gadget_opsxxx_udc_ops={.get_frame=xxx_udc_get_frame,.wakeup=xxx_udc_wakeup,};华清远见USBGadget驱动--组成(1)Østructusb_gadget_driverstaticstructusb_gadget_driverzero_driver={#ifdefCONFIG_USB_GADGET_DUALSPEED.speed=USB_SPEED_HIGH,#else.speed=USB_SPEED_FULL,#endif.function=(char*)longname,.bind=zero_bind,.unbind=__exit_p(zero_unbind),.setup=zero_setup,.disconnect=zero_disconnect,.suspend=zero_suspend,.resume=zero_resume,.driver={.name=(char*)shortname,.owner=THIS_MODULE,},};华清远见USBGadget驱动--组成(2)Ø设备、配置、接口、端点描述符staticstructusb_device_descriptordevice_desc={...};staticstructusb_config_descriptorsource_sink_config={...};staticstructusb_config_descriptorsource_sink_config={...};staticstructusb_endpoint_descriptorfs_source_desc={...};staticstructusb_endpoint_descriptorfs_sink_desc={...,};....staticconststructusb_descriptor_header*fs_source_sink_function[]={(structusb_descriptor_header*)&otg_descriptor,(structusb_descriptor_header*)&source_sink_intf,(structusb_descriptor_header*)&fs_sink_desc,(structusb_descriptor_header*)&fs_source_desc,NULL,};intusb_gadget_config_buf(conststructusb_config_descriptor*config,void*buf,unsignedlength,conststructusb_descriptor_header**desc){.../*theninterface/endpoint/class/vendor/...*/len=usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE+(u8*)buf,length-USB_DT_CONFIG_SIZE,desc);...}华清远见USBGadget驱动--组成(3)Øsetupstaticintzero_setup(structusb_gadget*gadget,conststructusb_ctrlrequest*ctrl){structzero_dev*dev=get_gadget_data(gadget);structusb_request*req=de
本文标题:USB设备驱动开发深度解析
链接地址:https://www.777doc.com/doc-1307697 .html