📄 m5373evb_host_mouse_test.c
字号:
free((void *)usb_qtd2->malloc_ptr);}/********************************************************************/void get_dev_desc(USB_QH * usb_qh_ep0, uint8 * device_descriptor, uint32 device_address){ USB_QTD * usb_qtd1, *usb_qtd2, *usb_qtd3; uint32 i, temp; uint32 buf0[MAX_USB_BUFFER_SIZE]; /* data for Get Descriptor command */ buf0[0] = 0x80060001; buf0[1] = 0x00001200; usb_qtd1 = usb_qtd_init(0x8, 0, SETUP_PID, buf0); usb_qtd2 = usb_qtd_init(0x40, 0, IN_PID, (uint32*) device_descriptor); usb_qtd3 = usb_qtd_init(0x0, 1, OUT_PID, 0); usb_qtd1->next_qtd = (uint32)usb_qtd2; usb_qtd2->next_qtd = (uint32)usb_qtd3; /* Point the QH to the linked list of qTDs */ usb_qh_ep0->next_qtd = (uint32)usb_qtd1; MCF_USB_ASYNCLISTADDR(USB_MODULE) = (uint32) usb_qh_ep0; /* Wait for transaction to complete */ while (!((MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UI) | (MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UEI))); /* Check for errors */ if( MCF_USB_USBSTS(USB_MODULE) & MCF_USB_USBSTS_UEI) { printf("ERROR!!!\n"); temp = *(uint32 *)(MCF_USB_ASYNCLISTADDR(USB_MODULE) + 0x18); printf("qTD status = 0x%08x\n",temp); for(i=0; i<5; i++) device_descriptor[i] = 0; } else { printf("Device descriptor has been read!!\n\n"); #ifdef DEBUG_PRINT printf("USBSTS = 0x%08x\n",MCF_USB_USBSTS(USB_MODULE)); #endif } #ifdef DEBUG_PRINT for( i=0; i<0x12; i++) printf("device_descriptor[%02x] = 0x%02x\n",i,device_descriptor[i]); #endif /* Clear the USB interrupt status bit */ MCF_USB_USBSTS(USB_MODULE) |= (MCF_USB_USBSTS_UI | MCF_USB_USBSTS_UEI); /* Set the max packet size in the QH to the max packet size in the device descriptor */ usb_qh_ep0->ep_char = ((usb_qh_ep0->ep_char & ~USB_QH_EP_CHAR_MAX_PACKET(0xFFF)) | USB_QH_EP_CHAR_MAX_PACKET(device_descriptor[0x7])); /* Return memory for descriptors to the heap */ free((void *)usb_qtd1->malloc_ptr); free((void *)usb_qtd2->malloc_ptr); free((void *)usb_qtd3->malloc_ptr); }/********************************************************************/void get_config_desc(USB_QH * usb_qh_ep0, uint8 * config_descriptor, uint32 device_address){ USB_QTD * usb_qtd1, *usb_qtd2, *usb_qtd3; uint32 i, temp; uint32 buf0[MAX_USB_BUFFER_SIZE]; /* data for Get Configuration Descriptor command */ buf0[0] = 0x80060002; buf0[1] = 0x00000900; usb_qtd1 = usb_qtd_init(0x8, 0, SETUP_PID, buf0); usb_qtd2 = usb_qtd_init(0x9, 0, IN_PID, (uint32 *)config_descriptor); usb_qtd3 = usb_qtd_init(0x0, 1, OUT_PID, 0); usb_qtd1->next_qtd = (uint32)usb_qtd2; usb_qtd2->next_qtd = (uint32)usb_qtd3; /* Point the QH to the linked list of qTDs */ usb_qh_ep0->next_qtd = (uint32)usb_qtd1; /* Wait for transaction to complete */ while (!((MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UI) | (MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UEI))); /* Check for errors */ if( MCF_USB_USBSTS(USB_MODULE) & MCF_USB_USBSTS_UEI) { printf("ERROR!!!\n"); temp = *(uint32 *)(MCF_USB_ASYNCLISTADDR(USB_MODULE) + 0x18); printf("qTD status = 0x%08x\n",temp); for(i=0; i<3; i++) config_descriptor[i] = 0; } else { #ifdef DEBUG_PRINT printf("Configuration descriptor has been read!!\n\n"); printf("USBSTS = 0x%08x\n",MCF_USB_USBSTS(USB_MODULE)); #endif } #ifdef DEBUG_PRINT for( i=0; i<0x9; i++) printf("config_descriptor[%02x] = 0x%02x\n",i,config_descriptor[i]); #endif /* Clear the USB interrupt status bit */ MCF_USB_USBSTS(USB_MODULE) |= (MCF_USB_USBSTS_UI | MCF_USB_USBSTS_UEI); /* Return memory for descriptors to the heap */ free((void *)usb_qtd1->malloc_ptr); free((void *)usb_qtd2->malloc_ptr); free((void *)usb_qtd3->malloc_ptr); }/********************************************************************/void get_interface_desc(USB_QH * usb_qh_ep0, uint8 * interface_descriptor, uint8 * hid_descriptor, uint8 * ep_descriptor, uint32 device_address){ USB_QTD * usb_qtd1, *usb_qtd2, *usb_qtd3; uint32 i, temp; uint32 buf0[MAX_USB_BUFFER_SIZE]; uint8 buf1[MAX_USB_BUFFER_SIZE]; /* data for Get Configuration Descriptor command */ buf0[0] = 0x80060002; buf0[1] = 0x0000FF00; usb_qtd1 = usb_qtd_init(0x8, 0, SETUP_PID, buf0); usb_qtd2 = usb_qtd_init(0xFF, 0, IN_PID, (uint32 *) buf1); usb_qtd3 = usb_qtd_init(0x0, 1, OUT_PID, 0); usb_qtd1->next_qtd = (uint32)usb_qtd2; usb_qtd2->next_qtd = (uint32)usb_qtd3; /* Point the QH to the linked list of qTDs */ usb_qh_ep0->next_qtd = (uint32)usb_qtd1; /* Wait for transaction to complete */ while (!((MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UI) | (MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UEI))); /* Check for errors */ if( MCF_USB_USBSTS(USB_MODULE) & MCF_USB_USBSTS_UEI) { printf("ERROR!!!\n"); temp = *(uint32 *)(MCF_USB_ASYNCLISTADDR(USB_MODULE) + 0x18); printf("qTD status = 0x%08x\n",temp); for(i=0; i<3; i++) interface_descriptor[i] = 0; } else { #ifdef DEBUG_PRINT printf("Interface, hid, and endpoint descriptors have been read!!\n\n"); printf("USBSTS = 0x%08x\n",MCF_USB_USBSTS(USB_MODULE)); #endif } for( i=0; i<0x9; i++) interface_descriptor[i] = buf1[i+9]; for( i=0; i<0x9; i++) hid_descriptor[i] = buf1[i+18]; for( i=0; i<0x7; i++) ep_descriptor[i] = buf1[i+27]; #ifdef DEBUG_PRINT for( i=0; i<0x9; i++) printf("interface_descriptor[%02x] = 0x%02x\n",i,interface_descriptor[i]); for( i=0; i<0x9; i++) printf("hid_descriptor[%02x] = 0x%02x\n",i,hid_descriptor[i]); for( i=0; i<0x7; i++) printf("ep_descriptor[%02x] = 0x%02x\n",i,ep_descriptor[i]); #endif /* Clear the USB interrupt status bit */ MCF_USB_USBSTS(USB_MODULE) |= (MCF_USB_USBSTS_UI | MCF_USB_USBSTS_UEI); /* Return memory for descriptors to the heap */ free((void *)usb_qtd1->malloc_ptr); free((void *)usb_qtd2->malloc_ptr); free((void *)usb_qtd3->malloc_ptr); }/********************************************************************/void set_configuration(USB_QH * usb_qh_ep0, uint32 config_value, uint32 device_address){ USB_QTD * usb_qtd1, *usb_qtd2; uint32 temp; uint32 buf0[MAX_USB_BUFFER_SIZE]; /* data for Set Address command */ buf0[0] = 0x00090000 | ((0x7F & config_value) <<8); buf0[1] = 0x00000000; usb_qtd1 = usb_qtd_init(0x8, 0, SETUP_PID, buf0); usb_qtd2 = usb_qtd_init(0x0, 1, IN_PID, 0); usb_qtd1->next_qtd = (uint32)usb_qtd2; /* Point the QH to the linked list of qTDs */ usb_qh_ep0->next_qtd = (uint32)usb_qtd1; /* Enable async schedule */// MCF_USB_USBCMD(USB_MODULE) |= MCF_USB_USBCMD_ASE; /* Wait for asynchronous schedule to enable */// while (!(MCF_USB_USBSTS(USB_MODULE) & MCF_USB_USBSTS_AS)); /* Wait for transaction to complete */ while (!((MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UI) | (MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UEI))); /* Check for errors */ if( MCF_USB_USBSTS(USB_MODULE) & MCF_USB_USBSTS_UEI) { printf("ERROR!!!\n"); temp = *(uint32 *)(MCF_USB_ASYNCLISTADDR(USB_MODULE) + 0x18); printf("qTD status = 0x%08x\n",temp); } else { printf("Set configuration command complete!!\n\n"); #ifdef DEBUG_PRINT printf("USBSTS = 0x%08x\n",MCF_USB_USBSTS(USB_MODULE)); #endif } /* Clear the USB interrupt status bit */ MCF_USB_USBSTS(USB_MODULE) |= (MCF_USB_USBSTS_UI | MCF_USB_USBSTS_UEI); /* Return memory for descriptors to the heap */ free((void *)usb_qtd1->malloc_ptr); free((void *)usb_qtd2->malloc_ptr);}/********************************************************************/void get_report_desc(USB_QH * usb_qh_ep0, uint8 * report_descriptor, uint32 device_address){ USB_QTD * usb_qtd1, *usb_qtd2, *usb_qtd3; uint32 i, temp; uint32 buf0[MAX_USB_BUFFER_SIZE]; /* data for Get Configuration Descriptor command */ buf0[0] = 0x81060022; buf0[1] = 0x00007400; usb_qtd1 = usb_qtd_init(0x8, 0, SETUP_PID, buf0); usb_qtd2 = usb_qtd_init(0x74, 0, IN_PID, (uint32 *)report_descriptor); usb_qtd3 = usb_qtd_init(0x0, 1, OUT_PID, 0); usb_qtd1->next_qtd = (uint32)usb_qtd2; usb_qtd2->next_qtd = (uint32)usb_qtd3; /* Point the QH to the linked list of qTDs */ usb_qh_ep0->next_qtd = (uint32)usb_qtd1; /* Enable async schedule */// MCF_USB_USBCMD(USB_MODULE) |= MCF_USB_USBCMD_ASE; /* Wait for asynchronous schedule to enable */// while (!(MCF_USB_USBSTS(USB_MODULE) & MCF_USB_USBSTS_AS)); /* Wait for transaction to complete */ while (!((MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UI) | (MCF_USB_USBSTS(USB_MODULE)&MCF_USB_USBSTS_UEI))); /* Check for errors */ if( MCF_USB_USBSTS(USB_MODULE) & MCF_USB_USBSTS_UEI) { printf("ERROR!!!\n"); temp = *(uint32 *)(MCF_USB_ASYNCLISTADDR(USB_MODULE) + 0x18); printf("qTD status = 0x%08x\n",temp); for(i=0; i<3; i++) report_descriptor[i] = 0; } else { #ifdef DEBUG_PRINT printf("Report descriptor has been read!!\n\n"); printf("USBSTS = 0x%08x\n",MCF_USB_USBSTS(USB_MODULE)); #endif } #ifdef DEBUG_PRINT i=0; while (!((report_descriptor[i-1] == 0xC0) & (report_descriptor[i-2] == 0xC0))) { printf("report_descriptor[%02x] = 0x%02x\n",i,report_descriptor[i]); i++; } #endif /* Clear the USB interrupt status bit */ MCF_USB_USBSTS(USB_MODULE) |= (MCF_USB_USBSTS_UI | MCF_USB_USBSTS_UEI); /* Return memory for descriptors to the heap */ free((void *)usb_qtd1->malloc_ptr); free((void *)usb_qtd2->malloc_ptr); free((void *)usb_qtd3->malloc_ptr); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -