📄 ev44b0_usb.c
字号:
{ // // Stall the both control endpoints. // USBStallEndpoint(USB_ENDPOINT_CONTROL_OUT, 1); USBStallEndpoint(USB_ENDPOINT_CONTROL_IN, 1); // // We're done handling this request. // break; } }}//****************************************************************************//// USBClearFeature implements the USB Clear_Feature device request.////****************************************************************************static void USBClearFeature(void){ unsigned long ulEndpoint; // // The only feature we support is stall on an endpoint. // if(((sUSB.sControlOut.bmRequestType & USB_RT_RECIPIENT_MASK) == USB_RT_RECIPIENT_ENDPOINT) && (sUSB.sControlOut.wValue == USB_FEATURE_ENDPOINT_STALL)) { // // Compute the endpoint number. // ulEndpoint = (sUSB.sControlOut.wIndex & USB_ENDPOINT_ADDRESS_MASK) * 2; if(sUSB.sControlOut.wIndex & USB_ENDPOINT_DIRECTION_MASK) { ulEndpoint++; } // // Clear the stall condition on the specified endpoint. // USBStallEndpoint(ulEndpoint, 0); } else { // // An unknown feature was specified, so stall both control endpoints. // USBStallEndpoint(USB_ENDPOINT_CONTROL_OUT, 1); USBStallEndpoint(USB_ENDPOINT_CONTROL_IN, 1); }}//****************************************************************************//// USBSendControl transmits a block of data back to the host via the control// endpoint.////****************************************************************************static unsigned longUSBSendControl(const unsigned char *pucData, unsigned long ulLength){ // // If a block is already being transmitted, then return a failure. // if(sUSB.ulControlInCount) { return(0); } // // Prepare to transmit this block back to the host. // sUSB.pucControlIn = pucData; sUSB.ulControlInCount = ulLength; // // Send the first packet of this block back to the host. // USBWriteEndpoint(USB_ENDPOINT_CONTROL_IN, &sUSB.pucControlIn, &sUSB.ulControlInCount); // // Success. // return(1);}//****************************************************************************//// USBSetFeature implements the USB Set_Feature device request.////****************************************************************************static void USBSetFeature(void){ unsigned long ulEndpoint; // // The only feature we support is stall on an endpoint. // if(((sUSB.sControlOut.bmRequestType & USB_RT_RECIPIENT_MASK) == USB_RT_RECIPIENT_ENDPOINT) && (sUSB.sControlOut.wValue == USB_FEATURE_ENDPOINT_STALL)) { // // Compute the endpoint number. // ulEndpoint = (sUSB.sControlOut.wIndex & USB_ENDPOINT_ADDRESS_MASK) * 2; if(sUSB.sControlOut.wIndex & USB_ENDPOINT_DIRECTION_MASK) { ulEndpoint++; } // // Set the stall condition on the specified endpoint. // USBStallEndpoint(ulEndpoint, 1); } else { // // An unknown feature was specified, so stall both control endpoints. // USBStallEndpoint(USB_ENDPOINT_CONTROL_OUT, 1); USBStallEndpoint(USB_ENDPOINT_CONTROL_IN, 1); }}//****************************************************************************//// USBSetAddress implements the USB Set_Address device request.////****************************************************************************static void USBSetAddress(void){ // // Configure our UBS controller for the USB address assigned by the host. // USBWriteCommand(USB_COMMAND_SET_ADDRESS_ENABLE); USBWriteData(sUSB.sControlOut.wValue | 0x80); // // Respond to the host with an empty packet. // USBSendControl(0, 0);}//****************************************************************************//// USBGetDescriptor implements the USB Get_Descriptor device request.////****************************************************************************static void USBGetDescriptor(void){ const unsigned char *pucDescriptor; unsigned long ulLength = 0; // // Determine how to handle this request based on the requested descriptor. // switch(sUSB.sControlOut.wValue & USB_DESCRIPTOR_TYPE_MASK) { // // The device descriptor was requested. // case USB_DESCRIPTOR_DEVICE: { // // Prepare to return the device descriptor. // pucDescriptor = ucDeviceDescriptor; ulLength = sizeof(ucDeviceDescriptor); // // We're done handling this request. // break; } // // The configuration descriptor was requested. // case USB_DESCRIPTOR_CONFIGURATION: { // // Prepare to return the configuration descriptor. // pucDescriptor = ucConfigurationDescriptor; ulLength = sizeof(ucConfigurationDescriptor); // // We're done handling this request. // break; } // // A string descriptor was requested. // case USB_DESCRIPTOR_STRING: { // // Make sure that the language and string index requested are // valid. // if(((sUSB.sControlOut.wValue & USB_DESCRIPTOR_INDEX_MASK) != 0) && ((sUSB.sControlOut.wIndex != 0x0409) || ((sUSB.sControlOut.wValue & USB_DESCRIPTOR_INDEX_MASK) > 2))) { // // Stall both of the control endpoints. // USBStallEndpoint(USB_ENDPOINT_CONTROL_OUT, 1); USBStallEndpoint(USB_ENDPOINT_CONTROL_IN, 1); // // We're done handling this request. // return; } // // Prepare to return the requested string. // switch(sUSB.sControlOut.wValue & USB_DESCRIPTOR_INDEX_MASK) { // // String index 0 is the language ID string. // case 0x00: { pucDescriptor = ucString0; ulLength = sizeof(ucString0); break; } // // String index 1 is the manufacturer name. // case 0x01: { pucDescriptor = ucString1; ulLength = sizeof(ucString1); break; } // // String index 2 is the product name. // case 0x02: { pucDescriptor = ucString2; ulLength = sizeof(ucString2); break; } } // // We're done handling this request. // break; } // // An invalid request is received, so stall both control endpoints. // default: { // // Stall both of the control endpoints. // USBStallEndpoint(USB_ENDPOINT_CONTROL_OUT, 1); USBStallEndpoint(USB_ENDPOINT_CONTROL_IN, 1); // // We're done handling this request. // return; } } // // If the requested length is less than the length of the descriptor to be // returned, then simply return the requested portion of the descriptor. // if(sUSB.sControlOut.wLength < ulLength) { ulLength = sUSB.sControlOut.wLength; } // // Send the descriptor back to the host. // USBSendControl(pucDescriptor, ulLength);}//****************************************************************************//// USBGetConfiguration implements the USB Get_Configuration device request.////****************************************************************************static void USBGetConfiguration(void){ // // Send the current configuration value back to the host. // USBSendControl((unsigned char *)&sUSB.ulConfiguration, 1);}//****************************************************************************//// USBSetConfiguration implements the USB Set_Configuration device request.////****************************************************************************static void USBSetConfiguration(void){ // // If the requested configuration is zero, then go into the unconfigured // state. // if(sUSB.sControlOut.wValue == 0) { // // Clear the global configuration flag. // sUSB.ulConfiguration = 0; // // Disable the generic endpoints. // USBWriteCommand(USB_COMMAND_SET_ENDPOINT_ENABLE); USBWriteData(0); // // Respond to the host with an empty packet. // USBSendControl(0, 0); } // // If the requested configuration is one, then go into the configured // state. // else if(sUSB.sControlOut.wValue == 1) { // // Set the global configuration flag. // sUSB.ulConfiguration = 1; // // Disable the generic endpoints. // USBWriteCommand(USB_COMMAND_SET_ENDPOINT_ENABLE); USBWriteData(0); // // Enable the generic endpoints. // USBWriteCommand(USB_COMMAND_SET_ENDPOINT_ENABLE); USBWriteData(1); // // Respond to the host with an empty packet. // USBSendControl(0, 0); USB_CONNECT_FLAG = 1; } // // If the requested configuration is anything else, then stall both of the // control endpoints. // else { USBStallEndpoint(USB_ENDPOINT_CONTROL_OUT, 1); USBStallEndpoint(USB_ENDPOINT_CONTROL_IN, 1); }}//****************************************************************************//// USBGetInterface implements the USB Get_Interface device request.////****************************************************************************static void USBGetInterface(void){ unsigned char ucInterface = 0; // // We only support a single interface, so the current interface is always // the first one. Send our response back to the host. // USBSendControl(&ucInterface, 1);}//****************************************************************************//// USBSetInterface implements the USB Set_Interface device request.////****************************************************************************static void USBSetInterface(void){ // // We only support a single interface. // if((sUSB.sControlOut.wValue == 0) && (sUSB.sControlOut.wIndex == 0)) { // // The first interface was requested, so do nothing. // return; } else { // // A non-existent interface was requested, so stall both control // endpoints. // USBStallEndpoint(USB_ENDPOINT_CONTROL_OUT, 1); USBStallEndpoint(USB_ENDPOINT_CONTROL_IN, 1); }}static int ev44b0ii_usb_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg){ int RetVal = 0; return RetVal;}static unsigned int ev44b0ii_usb_poll(struct file *filp, poll_table *wait){ struct ev44b0ii_usb_priv *dev = (struct ev44b0ii_usb_priv *)filp->private_data; return (dev->head == dev->tail ? 0 : (POLLIN | POLLRDNORM));}static struct file_operations ev44b0ii_usb_fops = { owner: THIS_MODULE, read: ev44b0ii_usb_read, write: ev44b0ii_usb_write, poll: ev44b0ii_usb_poll, ioctl: ev44b0ii_usb_ioctl, open: ev44b0ii_usb_open, release: ev44b0ii_usb_release, fasync: ev44b0ii_usb_fasync,};static int usb_cpu_init(void){ CSR_WRITE(rPCONG,(CSR_READ(rPCONG) | 0x30)); return 0; }int __init ev44b0ii_usb_init_module(void){ struct ev44b0ii_usb_priv *dev; dev = (struct ev44b0ii_usb_priv *)&gusb; USBInitStruct(); USBWriteCommand(USB_COMMAND_SEND_RESUME); usb_wait_ms (10); /* Delay 10ms*/ USBWriteCommand(USB_COMMAND_SET_ADDRESS_ENABLE); USBWriteData(0); USBWriteCommand(USB_COMMAND_SET_ENDPOINT_ENABLE); USBWriteData(0); // // Enable the interrupts for the bulk endpoints. // USBWriteCommand(USB_COMMAND_SET_DMA); USBWriteData(USB_DMA_ENDP4_INT_ENABLE | USB_DMA_ENDP5_INT_ENABLE);#if 0 // Qinwei??? // Configure the PDIUSBD12 and enable the SoftConnect pull-up. // USBWriteCommand(USB_COMMAND_SET_MODE); USBWriteData(USB_CONFIG1_NO_LAZY_CLOCK | USB_CONFIG1_CLOCK_RUNNING | USB_CONFIG1_SOFT_CONNECT); USBWriteData(USB_CONFIG2_SET_TO_ONE | USB_CONFIG2_CLOCK_4M); USB_isr(0,0,0); while(1) { USB_isr(0,0,0); }#endif if ( 0 != devfs_register_chrdev(USB_BULK_MAJOR, EV44B0II_USB_MODULE_NAME, &ev44b0ii_usb_fops)) { printk(__FUNCTION__ ": can't get major number\n"); return -1; } if ( 0 != request_irq(INT_EINT2, USB_isr ,SA_INTERRUPT,usb_bulk_id, NULL)) { printk(KERN_WARNING "ev44b0ii_usb: failed to get IRQ\n"); return 1; } usb_cpu_init(); dev->head = 0; dev->tail = 0; dev->usage_count = 0; dev->total = 0; dev->dropped = 0; dev->buf = gbuffer; printk("%s\n",usb_driver_version); return 0;}void __exit ev44b0ii_usb_cleanup_module(void){ printk(__FUNCTION__ ": EV44B0II USB BULK Exit.\n"); free_irq(INT_EINT2,usb_bulk_id); devfs_unregister_chrdev(USB_BULK_MAJOR, EV44B0II_USB_MODULE_NAME);}module_init(ev44b0ii_usb_init_module);module_exit(ev44b0ii_usb_cleanup_module);MODULE_DESCRIPTION("EV44B0-II USB driver");MODULE_AUTHOR("Qin Wei <king@micetek.com.cn>");MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -