void Main_Task (void) { /* Body */ USB_STATUS status = USB_OK; /*----------------------------------------------------** ** Infinite loop, waiting for events requiring action ** **----------------------------------------------------*/ switch (mass_device.dev_state) { case USB_DEVICE_IDLE: break; case USB_DEVICE_ATTACHED: printf( "Mass Storage Device Attached\n" ); mass_device.dev_state = USB_DEVICE_SET_INTERFACE_STARTED; status = _usb_hostdev_select_interface(mass_device.dev_handle, mass_device.intf_handle, (pointer)&mass_device.class_intf); break; case USB_DEVICE_SET_INTERFACE_STARTED: break; case USB_DEVICE_INTERFACED: usb_host_mass_test_storage(); //mass_device.dev_state = USB_DEVICE_OTHER; break; case USB_DEVICE_DETACHED: printf ( "\nMass Storage Device Detached\n" ); mass_device.dev_state = USB_DEVICE_IDLE; break; case USB_DEVICE_OTHER: break; default: printf ( "Unknown Mass Storage Device State = %d\n",\ (int)mass_device.dev_state ); break; } /* Endswitch */ } /* Endbody */
void Main_Task ( uint_32 param ) { /* Body */ USB_STATUS status = USB_OK; _int_disable(); _int_install_unexpected_isr(); status = _usb_host_driver_install(HOST_CONTROLLER_NUMBER, (pointer)&_bsp_usb_host_callback_table); if (status) { _int_enable(); printf("ERROR: %ls", status); exit(1); } /* Endif */ status = _usb_host_init (HOST_CONTROLLER_NUMBER, /* Use value in header file */ MAX_FRAME_SIZE, /* Frame size per USB spec */ &host_handle); /* Returned pointer */ if (status != USB_OK) { _int_enable(); printf("\nUSB Host Initialization failed. STATUS: %x", status); fflush(stdout); goto Error_Cleanup; } /* Endif */ /* ** Since we are going to act as the host driver, register ** the driver information for wanted class/subclass/protocols */ status = _usb_host_driver_info_register(host_handle, DriverInfoTable); if (status != USB_OK) { _int_enable(); printf("\nDriver Registration failed. STATUS: %x", status); fflush(stdout); goto Error_Cleanup; } _int_enable(); pCmd = (COMMAND_OBJECT_PTR) USB_mem_alloc_zero(sizeof(COMMAND_OBJECT_STRUCT)); if (pCmd == NULL) { printf ("\nUnable to allocate Command Object"); fflush (stdout); goto Error_Cleanup; } pCmd->CBW_PTR = (CBW_STRUCT_PTR) USB_mem_alloc_zero(sizeof(CBW_STRUCT)); if (pCmd->CBW_PTR == NULL) { printf ("\nUnable to allocate Command Block Wrapper"); fflush (stdout); goto Error_Cleanup; } pCmd->CSW_PTR = (CSW_STRUCT_PTR) USB_mem_alloc_zero(sizeof(CSW_STRUCT)); if (pCmd->CSW_PTR == NULL) { printf ("\nUnable to allocate Command Status Wrapper"); fflush (stdout); goto Error_Cleanup; } buff_in = (uchar_ptr)USB_mem_alloc_uncached(0x400C); if (buff_in == NULL) { printf ("\nUnable to allocate Input Buffer"); fflush (stdout); goto Error_Cleanup; } _mem_zero(buff_in, 0x400C); buff_out = (uchar_ptr) USB_mem_alloc_uncached(0x0F); if (buff_out == NULL) { printf ("\nUnable to allocate Output Buffer"); fflush (stdout); goto Error_Cleanup; } _mem_zero(buff_out, 0x0F); printf("\nPlease insert Mass Storage Device.\n"); /*----------------------------------------------------** ** Infinite loop, waiting for events requiring action ** **----------------------------------------------------*/ for ( ; ; ) { switch ( mass_device.dev_state ) { case USB_DEVICE_IDLE: break ; case USB_DEVICE_ATTACHED: printf( "Mass Storage Device Attached\n" ); fflush(stdout); mass_device.dev_state = USB_DEVICE_SET_INTERFACE_STARTED; status = _usb_hostdev_select_interface(mass_device.dev_handle, mass_device.intf_handle, (pointer)&mass_device.class_intf); break ; case USB_DEVICE_SET_INTERFACE_STARTED: break; case USB_DEVICE_INTERFACED: usb_host_mass_test_storage(); mass_device.dev_state = USB_DEVICE_OTHER; break ; case USB_DEVICE_DETACHED: printf ( "\nMass Storage Device Detached\n" ); fflush(stdout); mass_device.dev_state = USB_DEVICE_IDLE; break; case USB_DEVICE_OTHER: break ; default: printf ( "Unknown Mass Storage Device State = %d\n",\ mass_device.dev_state ); fflush(stdout); break ; } /* Endswitch */ } /* Endfor */ Error_Cleanup: { if (pCmd != NULL) { if (pCmd->CSW_PTR != NULL) { USB_mem_free(pCmd->CSW_PTR); } if (pCmd->CBW_PTR != NULL) { USB_mem_free(pCmd->CBW_PTR); } USB_mem_free(pCmd); } if (buff_in != NULL) { USB_mem_free(buff_in); } if (buff_out != NULL) { USB_mem_free(buff_out); } if (host_handle != NULL) { _usb_host_shutdown (host_handle); } } } /* Endbody */