/** * @brief This function initializes the USB process. * * Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function * calls the coresponding usb mode initialization function * * @param none * * @return none */ void usb_task_init(void) { #if (USB_HOST_FEATURE == ENABLED && USB_DEVICE_FEATURE == ENABLED) U8 delay; #endif #if (USE_USB_PADS_REGULATOR==ENABLE) // Otherwise assume USB PADs regulator is not used Usb_enable_regulator(); #endif // ---- DUAL ROLE DEVICE USB MODE --------------------------------------------- #if ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == ENABLED)) Usb_enable_uid_pin(); delay=PORTA; g_usb_mode=USB_MODE_UNDEFINED; if(Is_usb_id_device()) { g_usb_mode=USB_MODE_DEVICE; usb_device_task_init(); } else { g_usb_mode=USB_MODE_HOST; Usb_ack_id_transition(); // REQUIRED !!! Startup with ID=0, Ack ID pin transistion (default hwd start up is device mode) #if ( ID_PIN_CHANGE_GENERATE_RESET == ENABLE) Usb_enable_id_interrupt(); #endif Enable_interrupt(); usb_host_task_init(); } g_old_usb_mode=g_usb_mode; // Store current usb mode, for mode change detection // ----------------------------------------------------------------------------- // ---- DEVICE ONLY USB MODE --------------------------------------------------- #elif ((USB_DEVICE_FEATURE == ENABLED)&& (USB_HOST_FEATURE == DISABLE)) Usb_force_device_mode(); usb_device_task_init(); // ----------------------------------------------------------------------------- // ---- REDUCED HOST ONLY USB MODE --------------------------------------------- #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == ENABLED)) Usb_force_host_mode(); usb_host_task_init(); #elif ((USB_DEVICE_FEATURE == DISABLE)&& (USB_HOST_FEATURE == DISABLE)) #error at least one of USB_DEVICE_FEATURE or USB_HOST_FEATURE should be enabled #endif // ----------------------------------------------------------------------------- }
void usb_task(void *pvParameters) { #endif // FREERTOS_USED // Register the USB interrupt handler to the interrupt controller and enable // the USB interrupt. Disable_global_interrupt(); INTC_register_interrupt((__int_handler)&usb_general_interrupt, AVR32_USBB_IRQ, USB_INT_LEV); Enable_global_interrupt(); #ifdef FREERTOS_USED while (true) { // Wait for the semaphore while (!xSemaphoreTake(usb_tsk_semphr, portMAX_DELAY)); #endif // FREERTOS_USED // ---- DUAL-ROLE DEVICE/HOST USB MODE ----------------------------------------- #if USB_DEVICE_FEATURE == true && USB_HOST_FEATURE == true #ifdef FREERTOS_USED if (usb_device_tsk) vTaskDelete(usb_device_tsk), usb_device_tsk = NULL; if (usb_host_tsk) vTaskDelete(usb_host_tsk), usb_host_tsk = NULL; #endif Usb_input_id_pin(); Usb_enable_id_pin(); if (Is_usb_id_device()) { g_usb_mode = USB_MODE_DEVICE; usb_device_task_init(); } else { private_sof_counter = 0; g_usb_mode = USB_MODE_HOST; usb_host_task_init(); } g_old_usb_mode = g_usb_mode; // Store current USB mode, for mode change detection Usb_raise_id_transition(); // Check no ID transition has been missed during initialization Usb_enable_id_interrupt(); Enable_global_interrupt(); // ----------------------------------------------------------------------------- // ---- DEVICE-ONLY USB MODE --------------------------------------------------- #elif USB_DEVICE_FEATURE == true #ifdef FREERTOS_USED if (usb_device_tsk) vTaskDelete(usb_device_tsk), usb_device_tsk = NULL; #endif Usb_force_device_mode(); usb_device_task_init(); // ----------------------------------------------------------------------------- // ---- REDUCED-HOST-ONLY USB MODE --------------------------------------------- #elif USB_HOST_FEATURE == true #ifdef FREERTOS_USED if (usb_host_tsk) vTaskDelete(usb_host_tsk), usb_host_tsk = NULL; #endif private_sof_counter = 0; Usb_force_host_mode(); usb_host_task_init(); // ----------------------------------------------------------------------------- // ---- ERROR, NO MODE true ------------------------------------------------- #else #error At least one of USB_DEVICE_FEATURE and USB_HOST_FEATURE must be enabled #endif // ----------------------------------------------------------------------------- #ifdef FREERTOS_USED } #endif }