1 / 22

NET+OS 6.1 Training

NET+OS 6.1 Training. USB Device. USB Device topics. Introduction / Performance USB device driver APIs and internal USB Examples USB test setup info. USB device programming. 13 DMA channels A set of USB device IP control registers Number of BBUS DMA control registers

small
Download Presentation

NET+OS 6.1 Training

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NET+OS 6.1 Training NetSilicon & Digi Confidential

  2. USB Device NetSilicon & Digi Confidential

  3. USB Device topics • Introduction / Performance • USB device driver APIs and internal • USB Examples • USB test setup info NetSilicon & Digi Confidential

  4. USB device programming • 13 DMA channels • A set of USB device IP control registers • Number of BBUS DMA control registers • File I/O functions: open, close, read, write, and ioctl. • Dedicated I/O lines – No change of gpio.h except for a GPIO line used for PNP. NetSilicon & Digi Confidential

  5. Performance for Bulk-Out/In • 750KBytes/second • Supporting of PNP for printing device. • Support USB 1.1/ USB2.0 Low & Full Speed • Support Control, Bulk, Interrupt transfers • Driver is used in: Hitachi SL5 printer. NetSilicon & Digi Confidential

  6. Device Open() • Calls usb_dev_open() • The open function opens the specific DMA channel for file I/O operation. • fd=open(“/usb/0”,USB_CTRL); • The USB device channels are: /usb/0, /usb/1, … /usb/12. • The USB mode are: O_WRONLY, O_RDONLY and USB_CTRL. NetSilicon & Digi Confidential

  7. Device close() • Calls usb_dev_close() • Close a specific DMA channel from further access. • Example: Close(fd); NetSilicon & Digi Confidential

  8. Device read() • Calls usb_dev_read. • int usb_dev_read(int dmaIndex, void * buffer, int length, int * notUsed) • Example: • Ret=Read(fd, (char*) buffer, bufferlength); • Buffer is returned from a read callback function in an ISR context. DON’T access it before it is returned. • Can not read DMA ch 0 and 1. NetSilicon & Digi Confidential

  9. Device Write() • Calls usb_dev_write(). • int usb_dev_read(int dmaIndex, void * buffer, int length, int * notUsed); • Example: ret=write(fd, (char *) buffer, bufferLength); • The buffer is returned from a write callback function in an ISR context. Do not access it before it is returned. • Can not write to fds for DMA ch 0 and 1. NetSilicon & Digi Confidential

  10. Internal Driver Structure NetSilicon & Digi Confidential

  11. Interrupt State NetSilicon & Digi Confidential

  12. Device Ioctl • Calls usb_dev_ioctl() • Fd is limited to those of DMA ch 0 and 1. • Some important flags for the ioctl • USB_SET_REQUEST_CALLBACK_FUNCTION USB_SET_RECV_BUFFER_CALLBACK_FUNCTION • USB_SET_WRITE_BUFFER_CALLBACK_FUNCTION • USB_FLUSH_BUFFER • USB_SET_DMA_LOADING_IN_BATCH NetSilicon & Digi Confidential

  13. Other APIs • UsbBuildInterfaceDesc(USB_INTERFACE_DESCRIPTOR * itd, MC_USB_INTERFACE_DESCRIPTOR *pUsbIT,MC_USB_ENDPOINT_DESCRIPTOR endpointArray[], size_t endpointNumber); • MCUsbBuildConfigurationDesc(USB_CONFIG_DESCRIPTOR* cfd, MC_USB_CONFIGURATION_DESCRIPTOR *pUsbCD, USB_INTERFACE_DESCRIPTOR usbInterfaceDesc[], size_t numInterface); NetSilicon & Digi Confidential

  14. Example • Typical User application • usb_dev[0] = open ("/usb/0", USB_CTRL); • usb_dev[1] = open ("/usb/1", USB_CTRL); • usb_dev[2] = open ("/usb/2", USB_BULK); • usb_dev[3] = open ("/usb/3", USB_BULK); NetSilicon & Digi Confidential

  15. Example • ret = ioctl (usb_dev[0], USB_SET_WRITE_BUFFER_CALLBACK_FUNCTION, (void *) writeCallBackFunc); • ret = ioctl (usb_dev[0], USB_SET_RECV_BUFFER_CALLBACK_FUNCTION, (void *) readCallBackFunc); • ret = ioctl (usb_dev[0], USB_SET_REQUEST_CALLBACK_FUNCTION, (void *) requestToSendCallBackFunc); NetSilicon & Digi Confidential

  16. Typical Callback Function • void readCallBackFunc (unsigned int channel, char *ptrData, int bufferLen, int dataRead) • {…. int usbCallbackData[4]; int status; usbCallbackData[0] = (unsigned long) ptrData; usbCallbackData[1] = (unsigned long) bufferLen; usbCallbackData[2] = (unsigned long) dataRead; usbCallbackData[3] = channel; /* 1 = read */ status = tx_queue_send(&usbQueue, usbCallbackData, TX_NO_WAIT); tx_event_flags_set (&usbEvent, USB_READ_EVENT_FLAG, TX_OR); return}; NetSilicon & Digi Confidential

  17. Typical Write callback function • void writeCallBackFunc (unsigned int channel, char *ptrData, int bufferLen, int dataWritten) { int usbCallbackData[4]; int status; usbCallbackData[0] = (unsigned long) ptrData; usbCallbackData[1] = (unsigned long) bufferLen; usbCallbackData[2] = (unsigned long) dataWritten; usbCallbackData[3] = channel; /* 1 = read */ status = tx_queue_send(&usbQueue, usbCallbackData, TX_NO_WAIT); /* process the finished data buffer here */ tx_event_flags_set (&usbEvent, USB_WRITE_EVENT_FLAG, TX_OR); return; } NetSilicon & Digi Confidential

  18. Typical Read() call for (i = 0; i < 8; i++) { ret = read (usb_dev[2], (char *) dataBuffer[2][i], 4096); if (ret != 0) { printf("Read failed.\n"); break; } } NetSilicon & Digi Confidential

  19. PNP function control • Using one of the GPIO line. dmaChan = 2; /* two control endpoints */ ioctl(usb_dev[0], USB_SET_CONTROL_ENDPOINT, (void *) &dmaChan); /* setting up control Desc */ MCInstallIsr (USB_INTERRUPT, (MC_ISR_HANDLER) usbDmaIsr, (void *) 2, 0); /* Turn off the GPIO pin #17 to support PNP */ MCsetGPIOpin(17, 0); /* set up the GPIO configuration */ *(unsigned long*) 0x90600018 |= 0x000000b0; NetSilicon & Digi Confidential

  20. Important files • Driver: Src/bsp/devices/ns9750/usb/*.* • Example: (1) src/examples/nausbdevapp/data.c (2) src/examples/nausbdevapp/usb_test.c NetSilicon & Digi Confidential

  21. Data.c • Has important Endpoint, Interface, Configuration data. • Mostly reusable in a typical application. NetSilicon & Digi Confidential

  22. Reference • References: http://www.intel-u-press.com/usb_dbe/USBdocs/USBspec.pdf NetSilicon & Digi Confidential

More Related