📄 usb.c
字号:
//****************************************************************************//// USB.C - USB driver for the Philips PDIUSBD12 USB interface device.//// Copyright (c) 1999,2000,2001 Cirrus Logic, Inc.////****************************************************************************#include "globals.h"#include "../hwport.h"#include "../hwdefs.h"#include "time.h"#include "usb.h"#include "usbven.h"//****************************************************************************//// Define a NOP instruction, which is compiler dependent (each compiler has// its own way of doing inline assembly).////****************************************************************************#if defined(sdt25) || defined(ads)#define NOP __asm { nop }#elif defined(gcc)#define NOP __asm__ ( "nop" )#else#error Unknown compiler!#endif//****************************************************************************//// This structure defines the setup packet received from the host via the// control out endpoint.////****************************************************************************typedef struct{ unsigned char bmRequestType; unsigned char bRequest; unsigned short wValue; unsigned short wIndex; unsigned short wLength;} ControlTransfer;//****************************************************************************//// Function prototypes for the standard device request handling routines.////****************************************************************************static void USBGetStatus(void);static void USBClearFeature(void);static void USBSetFeature(void);static void USBSetAddress(void);static void USBGetDescriptor(void);static void USBGetConfiguration(void);static void USBSetConfiguration(void);static void USBGetInterface(void);static void USBSetInterface(void);static void USBReserved(void);//****************************************************************************//// This is the device descriptor for the Internet audio player. See the USB// specification for the definition of this descriptor.////****************************************************************************static const unsigned char ucDeviceDescriptor[] ={ 0x12, // bLength 0x01, // bDescriptorType 0x00, 0x01, // bcdUSB 0x00, // bDeviceClass 0x00, // bDeviceSubClass 0x00, // bDeviceProtocol 0x10, // bMaxPacketSize0 0x29, 0x04, // idVendor 0x01, 0x10, // idProduct 0x00, 0x01, // bcdDevice 0x01, // iManufacturer 0x02, // iProduct 0x00, // iSerial Number 0x01 // bNumConfigurations};//****************************************************************************//// This is the configuration descriptor for the Internet audio player. See// the USB specification for the definition of this descriptor.////****************************************************************************static const unsigned char ucConfigurationDescriptor[] ={ // // The configuration descriptor structure. // 0x09, // bLength 0x02, // bDescriptorType 0x20, 0x00, // wTotalLength 0x01, // bNumInterfaces 0x01, // bConfigurationValue 0x03, // iConfiguration 0xc0, // bmAttributes 0x01, // MaxPower // // The interface descriptor structure. // 0x09, // bLength 0x04, // bDescriptorType 0x00, // bInterfaceNumber 0x00, // bAlternateSetting 0x02, // bNumEndpoints 0x00, // bInterfaceClass 0x00, // bInterfaceSubClass 0x00, // bInterfaceProtocol 0x00, // iInterface // // The endpoint descriptor structure. // 0x07, // bLength 0x05, // bDescriptorType 0x82, // bEndpointAddress 0x02, // bmAttributes 0x40, 0x00, // wMaxPacketSize 0x00, // bInterval // // The endpoint descriptor structure. // 0x07, // bLength 0x05, // bDescriptorType 0x02, // bEndpointAddress 0x02, // bmAttributes 0x40, 0x00, // wMaxPacketSize 0x00 // bInterval};//****************************************************************************//// String descriptor 0 for the Internet audio player. This defines the// languages supported by the string descriptors. See the USB specification// for the definition of this descriptor.////****************************************************************************static const unsigned char ucString0[] ={ 0x04, // bLength 0x03, // bDescriptorType 0x09, 0x04 // wLANGID[0] -> US English};//****************************************************************************//// String descriptor 1 for the Internet audio player. This defines the// manufacturer of the player. See the USB specification for the definition// of this descriptor.////****************************************************************************static const unsigned char ucString1[] ={ 0x26, // bLength 0x03, // bDescriptorType 'C', 0x00, // wString[] 'i', 0x00, 'r', 0x00, 'r', 0x00, 'u', 0x00, 's', 0x00, ' ', 0x00, 'L', 0x00, 'o', 0x00, 'g', 0x00, 'i', 0x00, 'c', 0x00, ',', 0x00, ' ', 0x00, 'I', 0x00, 'n', 0x00, 'c', 0x00, '.', 0x00};//****************************************************************************//// String descriptor 2 for the Internet audio player. This defines the// product description of the player. See the USB specification for the// definition of this descriptor.////****************************************************************************static const unsigned char ucString2[] ={ 0x60, // bLength 0x03, // bDescriptorType 'C', 0x00, // wString[] 'i', 0x00, 'r', 0x00, 'r', 0x00, 'u', 0x00, 's', 0x00, ' ', 0x00, 'L', 0x00, 'o', 0x00, 'g', 0x00, 'i', 0x00, 'c', 0x00, ' ', 0x00, 'M', 0x00, 'a', 0x00, 'v', 0x00, 'e', 0x00, 'r', 0x00, 'i', 0x00, 'c', 0x00, 'k', 0x00, '(', 0x00, 't', 0x00, 'm', 0x00, ')', 0x00, ' ', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, 'r', 0x00, 'n', 0x00, 'e', 0x00, 't', 0x00, ' ', 0x00, 'A', 0x00, 'u', 0x00, 'd', 0x00, 'i', 0x00, 'o', 0x00, ' ', 0x00, 'P', 0x00, 'l', 0x00, 'a', 0x00, 'y', 0x00, 'e', 0x00, 'r', 0x00};//****************************************************************************//// String descriptor 3 for the Internet audio player. This defines the// configuration description of the player. See the USB specification for the// definition of this descriptor.////****************************************************************************static const unsigned char ucString3[] ={ 0x2c, // bLength 0x03, // bDescriptorType 'D', 0x00, // wString[] 'e', 0x00, 'f', 0x00, 'a', 0x00, 'u', 0x00, 'l', 0x00, 't', 0x00, ' ', 0x00, 'C', 0x00, 'o', 0x00, 'n', 0x00, 'f', 0x00, 'i', 0x00, 'g', 0x00, 'u', 0x00, 'r', 0x00, 'a', 0x00, 't', 0x00, 'i', 0x00, 'o', 0x00, 'n', 0x00};//****************************************************************************//// An array of pointers to the USB standard device request handler Functions.////****************************************************************************static void (* const USBStandardDeviceRequest[])(void) ={ USBGetStatus, USBClearFeature, USBReserved, USBSetFeature, USBReserved, USBSetAddress, USBGetDescriptor, USBReserved, USBGetConfiguration, USBSetConfiguration, USBGetInterface, USBSetInterface, USBReserved};//****************************************************************************//// The following structure contains the persistent state of the USB interface.////****************************************************************************static struct{ // // Flags which describe the current state of the USB connection. // unsigned char ucFlags; // // Indicates if a vendor specific setup packet has been received on the // control out endpoint and is waiting to be processed. // unsigned char ucHaveVendorMessage; // // The number of bytes to be sent to the control endpoint. // unsigned short usControlInCount; // // The buffer of data that is being sent to the control endpoint. // const unsigned char *pucControlIn; // // The buffer of data that is being received from the control endpoint. // ControlTransfer sControlOut; // // The number of bytes to be sent to the bulk endpoint. // unsigned short usBulkInCount; // // The number of bytes still to be read from the bulk endpoint. // unsigned short usBulkOutCount; // // The buffer of data that is being sent to the bulk endpoint. // const unsigned char *pucBulkIn; // // The buffer of data that is being received from the bulk endpoint. // unsigned char *pucBulkOut;} sUSB;//****************************************************************************//// USBWriteCommand will write the specified value to the command register of// the PDIUSBD12.////****************************************************************************static voidUSBWriteCommand(unsigned char ucValue){#ifdef HwPortABCD_USB_CS volatile unsigned long *pulPtr = (unsigned long *)HwBaseAddress;#endif volatile unsigned char *pucReg = (unsigned char *)(HwUSBAddress + HwUSBCommand); int iIdx; // // Assert the USB chip select if it is controllable. //#ifdef HwPortABCD_USB_CS pulPtr[HwPortABCD >> 2] &= ~HwPortABCD_USB_CS;#endif // // Write the value to the command register. // *pucReg = ucValue; // // Delay ~500ns to comply with the timing specification of the PDIUSBD12. // for(iIdx = 0; iIdx < 24; iIdx++) { } // // De-assert the USB chip select if it is controllable. //#ifdef HwPortABCD_USB_CS pulPtr[HwPortABCD >> 2] |= HwPortABCD_USB_CS;#endif}//****************************************************************************//// USBWriteData will write the specified value to the data register of the// PDIUSBD12.////****************************************************************************static voidUSBWriteData(unsigned char ucValue){#ifdef HwPortABCD_USB_CS volatile unsigned long *pulPtr = (unsigned long *)HwBaseAddress;#endif volatile unsigned char *pucReg = (unsigned char *)(HwUSBAddress + HwUSBData); int iIdx; // // Assert the USB chip select if it is controllable. //#ifdef HwPortABCD_USB_CS pulPtr[HwPortABCD >> 2] &= ~HwPortABCD_USB_CS;#endif // // Write the value to the data register. // *pucReg = ucValue; // // Delay ~500ns to comply with the timing specification of the PDIUSBD12. // for(iIdx = 0; iIdx < 24; iIdx++) { } // // De-assert the USB chip select if it is controllable. //#ifdef HwPortABCD_USB_CS pulPtr[HwPortABCD >> 2] |= HwPortABCD_USB_CS;#endif}//****************************************************************************//// USBReadData will read a value from the data register of the PDIUSBD12.////****************************************************************************static unsigned charUSBReadData(void){#ifdef HwPortABCD_USB_CS volatile unsigned long *pulPtr = (unsigned long *)HwBaseAddress;#endif volatile unsigned char *pucReg = (unsigned char *)(HwUSBAddress + HwUSBData); int iIdx; unsigned char ucRet; // // Assert the USB chip select if it is controllable. //#ifdef HwPortABCD_USB_CS pulPtr[HwPortABCD >> 2] &= ~HwPortABCD_USB_CS;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -