📄 udc_ahb.c.orig
字号:
break; case 1: *VUINTP USB_TX_FIFO_1_DONE = 0x0; break; case 2: *VUINTP USB_TX_FIFO_2_DONE = 0x0; break; }}static voidUSBGetPckFromFIFO(int epNum, DmaUsbBulkDescr *descp){ int offset = 0; char *bufp = descp->DmaUsb_Addr; unsigned int reg_done = 0; switch (epNum) { case 0: offset = Out_Endp0; reg_done = USB_RX_FIFO_0_DONE; break; case 1: offset = Out_Endp1; reg_done = USB_RX_FIFO_1_DONE; break; case 2: offset = Out_Endp2; reg_done = USB_RX_FIFO_2_DONE; break; default: return; } /************************* * SETUP Transactions * OUT Transactions ***************************/ if (((*VUINTP (Endp_Status + offset)) & Endp_Status_OUTMsk) == Endp_Status_OUT_Setup) { unsigned int *SetupPtr = (unsigned int *)&UsbSetupBuf; /* * SETUP packet * This take place only for Endpoint 0. */ // Read the SETUP Packet Header. // ENDIANITY (TODO) !! *SetupPtr = *VUINTP USB_RX_FIFO; *(SetupPtr + 1) = *VUINTP USB_RX_FIFO; //USBParseSetup(); } else if (((*VUINTP (Endp_Status + offset)) & Endp_Status_OUTMsk) == Endp_Status_OUT_Data) { unsigned int len = (*VUINTP (Endp_Status + offset) >> 11) & 0xfff; unsigned int nw; unsigned int i; /* * DATA received. */ if (len > USB_BUFFER_SIZE) return; if (len == 0) *VUINTP reg_done; nw = (len + (sizeof(int) - 1)) / sizeof(int); // calculate number of words for (i = 0; i < nw; i++) { // DATA packet received (TODO!!!!! Buffer) ((unsigned int *)bufp)[i] = *VUINTP USB_RX_FIFO; } descp->DmaUsb_Status = len & DmaUsb_Len_Mask; *VUINTP (Endp_Status + offset) = 0x0; // clear the Endpoint Status Register. } else if (((*VUINTP (Endp_Status + offset)) & Endp_Status_OUTMsk) == Endp_Status_OUT_none) { // NONE received }}#endif/* * Parse the SETUP packet. * * This is the USB SETUP Packet Header Format: * * 0 1 2 4 6 * +--------+--------+----------------+----------------+----------------+ * | bmReq | bReq | wValue | wIndex | wLength | * +--------+--------+----------------+----------------+----------------+ * * where: * * bmReq : Characteristic of Request. * 0:4 - Recipient * 0 = Device * 1 = Interface * 2 = Endpoint * 3 = Other * 4..31 = Reserved * * 6:5 - Type * 0 = Standard * 1 = Class * 2 = Vendor * 3 = Reserved * * 7 - DATA Transfer Direction * 0 = HOST --> DEV * 1 = DEV --> HOST * * bReq : Specific Request. * * --- Standard USB Requests handled by UDC. * USB_GET_STATUS * USB_CLEAR_FEATURE * USB_SET_FEATURE * USB_SET_ADDRESS * USB_GET_CONFIGURATION * USB_SET_CONFIGURATION * USB_GET_INTERFACE * USB_SET_INTERFACE * USB_SYNCH_FRAME * * --- Standard USB Requests handled by this Driver. * USB_GET_DESCRIPTOR * USB_SET_DESCRIPTOR * * * wValue : Parameter field. * wIndex : Index field. * wLength : Number of bytes to transfer if there's a data stage. */static voidUSBParseSetup(){ //unsigned short val; DmaUsbBulkDescr *BulkDescrPtr, *HEADBlkinDPtr; int i; int length, direction, protocol, recipient; TotalDescrLen = -1; //Print("\r\n(AV) -- USBParseSetup :: "); //Print("bmReq [%d] ", UsbSetupBuf.bReq); ////PrintMessInLastKB("USBParseSetup()"); length = (UsbSetupBuf.wLen_hi << 8) | UsbSetupBuf.wLen_lo; direction = UsbSetupBuf.bmReqType & USB_DIR_MASK; protocol = UsbSetupBuf.bmReqType & USB_TYPE_MASK; recipient = UsbSetupBuf.bmReqType & USB_DEST_MASK; if (protocol == USB_TYPE_STANDARD) { /* * STANDARD requests */ // Parse SETUP Packet Type switch(UsbSetupBuf.bReq) { /* * The following USB commands are handled directly by HW (UDC 2.0). */ case USB_GET_STATUS: case USB_CLEAR_FEATURE: case USB_SET_FEATURE: case USB_SET_ADDRESS: case USB_GET_CONFIGURATION: case USB_SET_CONFIGURATION: case USB_GET_INTERFACE: case USB_SET_INTERFACE: case USB_SYNCH_FRAME: USBCtrlTransftateMachine = USB_CTRL_IDLE; *VUINTP (Endp_Cntl + Out_Endp0) |= Endp_Cntl_STALL; break; // STALL default: USBCtrlTransftateMachine = USB_CTRL_IDLE; *VUINTP (Endp_Cntl + Out_Endp0) |= Endp_Cntl_STALL; break; // STALL /* * GetDescriptor command: * * 0 1 2 3 4 - 5 6 - 7 * +----------+---+------+------+---------+-----------+ * | 10000000 | 6 | DT | DI | 0 | Len | * +----------+---+------+------+---------+-----------+ * * where: * * DT : Descriptor Type * 1 = Device (USB_DEVICE) * 2 = Configuration (USB_CONFIGURATION) * 3 = String (USB_STRING) * 4 = Interface (USB_INTERFACE) * 5 = Endpoint (USB_ENDPOINT) * 6 = Qualifier (USB_DEVICE_QUALIFIER) * 7 = Configuration (USB_OTHER_SPEED_CONFIGURATION) * 8 = Interface (USB_INTERFACE_POWER) * * DI : Descriptor Index * Len : Length of Descriptor */ case USB_GET_DESCRIPTOR: /* * Check bmReqType (should be 10000000) if (UsbSetupBuf.bmReqType != ( USB_DIR_TO_HOST | USB_TYPE_STANDARD | USB_DEST_DEV)) { return; // STALL (??) -- TODO } */ //val = ntohs(UsbSetupBuf.wValue); /* * Switch on Descriptor Type. * * According to the USB Specification, GetDescriptor() supports * three kinds of Descriptors: DEVICE, CONFIGURATION and STRING. */ switch (UsbSetupBuf.wValue_hi) { case USB_DEVICE: /* * GetDescriptor --> DEVICE * Returns: Device Descriptor */ // Print("\r\n(AV) -- GetDescriptor (DEVICE)"); //PrintMessInLastKB("GD dev");#if defined (_USB_DMA) BulkDescrPtr = (DmaUsbBulkDescr *)USB_GetDescrFromFreeList(1); if (BulkDescrPtr) { char *destp = BulkDescrPtr->DmaUsb_Addr; unsigned short dlen = min(length, sizeof(DevDescr)); BulkDescrPtr->DmaUsb_Status = DmaUsb_LastDescr | (dlen & DmaUsb_Len_Mask); /* Copy Device Descriptor . */ if (destp) memcpy(destp, (char *)&DevDescr, dlen); USB_PutDescrIntoEpt(IN_EP0, BulkDescrPtr); } else { /* return STALL */ *VUINTP (Endp_Cntl + Out_Endp0) |= Endp_Cntl_STALL; } #else // Packet size is 8 bytes. //UsbPutPckToFIFO(0, (char *)&DevDescr, sizeof(DevDescr));#endif //while (*VUINTP (Endp_Cntl + Out_Endp0) & Endp_Cntl_NAK) *VUINTP (Endp_Cntl + Out_Endp0) = Endp_Cntl_CNAK; //while (*VUINTP (Endp_Cntl + In_Endp0) & Endp_Cntl_NAK) *VUINTP (Endp_Cntl + In_Endp0) = Endp_Cntl_CNAK; DmaUsbDescrType = USB_DEVICE; USBCtrlTransftateMachine = USB_CTRLIN_STATUS_OUT_STAGE; break; case USB_CONFIGURATION: /* * GetDescriptor --> CONFIGURATION 1 * Returns: Configuration Descriptor 1 + * Interface 0 + * Endpt 1 (Bulk-OUT) + * Endpt 2 (Bulk-IN) */ // Print("\r\n(AV) -- GetDescriptor (CONFIG)"); //PrintMessInLastKB("GD conf");#if defined (_USB_DMA) BulkDescrPtr = HEADBlkinDPtr = (DmaUsbBulkDescr *)USB_GetDescrFromFreeList(1); if (BulkDescrPtr) { char *destp = BulkDescrPtr->DmaUsb_Addr; unsigned short dlen = min(length, (sizeof(CfgDescr) + sizeof(IfDescr) + sizeof(BulkInDescrFS) + sizeof(BulkOutDescrFS))); BulkDescrPtr->DmaUsb_Status = DmaUsb_LastDescr | ( dlen & DmaUsb_Len_Mask); /* Copy Configuration Descriptor 1. */ if (destp) memcpy(destp, (char *)&CfgDescr, sizeof(CfgDescr)); destp += sizeof(CfgDescr); /* Copy Interface Descriptor 0. */ if (destp) memcpy(destp, (char *)&IfDescr, sizeof(IfDescr)); destp += sizeof(IfDescr); if ((*VUINTP Dev_Stat & Dev_Stat_ENUM) == Dev_Stat_ENUM_SPEED_HS) { /* Copy Bulk-OUT Descriptor . */ if (destp) memcpy(destp, (char *)&BulkOutDescrHS, sizeof(BulkOutDescrHS)); destp += sizeof(BulkOutDescrHS); /* Copy Bulk-IN Descriptor 1. */ if (destp) memcpy(destp, (char *)&BulkInDescrHS, sizeof(BulkInDescrHS)); destp += sizeof(BulkInDescrHS); } else { /* Copy Bulk-OUT Descriptor . */ if (destp) memcpy(destp, (char *)&BulkOutDescrFS, sizeof(BulkOutDescrFS)); destp += sizeof(BulkOutDescrFS);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -