USB driver stack-1 in VxWorks

Source: Internet
Author: User

The USB module can be divided into the multi-port host (MPH) module and the dual-role (DR) module, which can connect one or two external ports. These modules and external ports are called USB interfaces. The USB Module of the mpc8379 uses dr. Its registers and data structures are based on Intel's EHCI (enhanced Host Controller Interface Specification for Universal Serial Bus ), the DR module can act as a host and peripherals on the USB bus, and support portable on-the-go (OTG) to negotiate with the host/peripherals.

The DR module has three basic operation modes: Host, device, and OTG. You can configure the DR module to use any of the PHY interfaces in the utmi, ulpi, or FS/ls serial transceiver. Due to pin limitations, the utmi interface can only be used in device operation mode. It is worth noting that the DR module in device mode does not support ls operations. The interface of the 8377 PHY chip smsc3300 is ulpi (utmi + low pin interface ).

Wind River USB provides USB transmission initialization (USB hosts) and allows the VxWorks target to be used as USB peripherals for Universal Serial Bus. USB hosts (also known as USB Host Stack) and USB peripherals (also known as USB Peripheral stack) follow the USB 2.0 protocol. Host Stack enables VxWorks to use a USB device, while peripheral stack allows Windows machines to use the VxWorks Board as a USB device. Here we will first introduce the host, which is USB
Host driver stack structure:

The USB Host Stack driver includes USB driver (usbd), host control driver (HCD), Hub driver, and class driver. Wind River provides HCD drivers for standard interface protocols EHCI, uhci, and OHCI. In addition, it also provides root hub diver for USB controllers and class driver collection for various USB peripherals. Among them, usbd is hardware independent. It provides a communication channel between the upper layer of the driver stack (including USB class drivers) and the USB bus, also responsible for power management, USB bandwidth management, dynamic mounting/release of USB devices and other functions. For the USB
Host Stack composition diagram:



As mentioned above, USB tool is a USB test tool kit provided by Fenghe. We can see from the process of using USB tool that the steps for USB initialization are as follows:

1. First execute usbinit to initialize the Host Stack of usb2. The source code is as follows:

Status usbinit (void) {If (! Usbdinitbykernel) {/* set the memory space for the USB driver (2 MB by default) */osspartsizeset (usb_mem_part_size);/* initialize the usb2 Host Stack, initialize usbd2.0 global variable */If (usbdinit () = OK) {usbdinitbykernel = true; # ifdef debug_announce_usb printf ("usb2 Host Stack initialized \ n "); # endif/* register the USB hub class driver to the USB host driver stack, and initialize the USB 1.1 Conversion Layer */If (usrusbhubinit ()! = OK) | (usbdtranslationinit ()! = OK) {Return Error ;}}else {printf ("usb2 Host Stack already initialized \ n");} Return OK ;}

2. Execute usbdinitialize to initialize usbd. This function must be executed more than once before the system calls other usbd functions. There is a public counter guusbdinited, and 1 is added to the initialize function, shutdown will be reduced by 1. If it is greater than 0, it indicates that the initial recognition is complete. Note: Because usbdinitialize can be run in a nested manner, you must follow the mutex access rules when performing counter operations. It is used to prepare usbd and transfer units required to access URBS. OSS is o/s-independent
Services, used to protect mutex semaphores. For the source code of the usbd2.0 and hub class modules of Host Stack, refer to these two directories:


3. initialize the EHCI, OHCI, and uhci controllers. In the USB tool, this process is called attach. It is used to initialize HCD and register it with vxbus. The two functions usbxhcdinit and vxbusbxhciregister are called successively. The former is actually used to call usbhsthcdregister and register HCD to usbd. Here a struct usbhst_hc_driver is involved, which contains the HCD function pointer, during HCD initialization, it is passed to usbd, which uses these pointers to communicate with HCD. The struct is defined as follows:

Typedef struct usbhst_hc_driver {/* Number of buses used for this HCD */uint8 unumberofbus;/* struct vxbbustypeinfo stores bus information */struct vxbbustypeinfo * pusbhcdbustype; /* The following are all function pointers * // * obtain num */usbhst_status (* getframenumber) (uint8 ubusindex, uint16 * puframenumber) from frame number reg ); /* set the frame bit width */usbhst_status (* setbitrate) (uint8 ubusindex, bool bincrement, uint32 * pucurrentframewidth ); /* determine whether the bus bandwidth is sufficient */usbhst_status (* supported) (uint8 ubusindex, uint8 udeviceaddress, uint8 udevicespeed, uchar * pcurrentdescriptor, uchar * pnewdescriptor ); /* parse and create pipe */usbhst_status (* createpipe) (uint8 ubusindex, uint8 udeviceaddress, uint8 udevicespeed, uchar * pendpointdescriptor, uint16 protocol, uint32 * Protocol) for specific USB endpoints ); /* modify the default pipe attribute (address 0, endpoint 0) */usbhst_status (* modifydefaultpipe) (uint8 ubusindex, uint32 success, uint8 udevicespeed, uint8 umaxpacketsize, uint16 success ); /* Delete pipe */usbhst_status (* deletepipe) (uint8 ubusindex, uint32 upipehandle);/* request pending on pipe */usbhst_status (* isrequestpending) (uint8 ubusindex, uint32 upipehandle);/* submit the request to the endpoint, urb: USB request block */usbhst_status (* submiturb) (uint8 ubusindex, uint32 upipehandle, pusbhst_urb purb); usbhst_status) (uint8 ubusindex, uint32 upipehandle, pusbhst_urb purb);/* the following two errors occurred when processing split transaction */usbhst_status (* handle) (uint8 urelativebusindex, void * pcontext, usbhst_status nstatus);/* function pointer to submit the status of the reset TT Request */usbhst_status (* handle) (uint8 urelativebusindex, void * pcontext, usbhst_status nstatus);} handle, * pusbhst_hc_driver;

The latter indicates that the analysis is of little significance. All of them are registered to vxbus by calling vxbdevregister.

As for these drivers, the Wind River has been compiled (depressing, you can only view the code to learn), see the DirectoryInstalldir/Target/src/hwif/busctrl/USB/HCDThe three interfaces are separated. Although only one interface can be used at a time, the Wind River allows multiple interface drivers to be added at the same time, thus enhancing product compatibility. Note that you cannot add any other init functions after adding USB tool. Otherwise, compilation errors may occur.

If you do not have a USB tool, you need to perform four steps of initialization at the start of VxWorks to completely include the component and use the usbd2.0 interface:

1. register the USB host controller to vxbus Based on the selected components. In this process, vxbus discovers the Controller Device and performs a specific vxbus initialization operation. The call function is vxbusbcontrollerregister,

2. Execute the usbd entry function usbdinit,

3. Execute usbhubinit to initialize hub class drivers;

4. Run usbhcdinit to register a specific HCD to usbd.

There is also an osal, which is used to provide an abstract and simplified view of the Host Stack Operating System Service in VxWorks. It includes process management, mutex, memory scheduling, and system time. In usbd, It is the osslib library. Note that when writing a USB driver, you need to focus on mutex access and memory scheduling.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.