//------------------------------------------------------------------------------ /// Initializes the USB process /// Depending on the mode supported (HOST/DEVICE/DUAL_ROLE) the function calls /// the coresponding USB mode initialization function //------------------------------------------------------------------------------ void usb_task_init(void) { // DUAL ROLE DEVICE USB MODE Otg_message_task_init(); // OTG program needs to display event messages to the user b_uut_device_state = B_IDLE; // init state machines variables device_state = DEVICE_UNATTACHED; otg_device_nb_hnp_retry = BDEV_HNP_NB_RETRY; Clear_all_user_request(); Usb_enable_uid_pin(); g_usb_mode=USB_MODE_UNDEFINED; if(Is_usb_id_device()) { g_usb_mode=USB_MODE_DEVICE; #ifdef MSD_PROJECT MSDDriver_Initialize(luns, numMedias); #else // HID HIDDMouseDriver_Initialize(); #endif id_changed_to_host_event = DISABLE; } else { Usb_send_event(EVT_USB_HOST_FUNCTION); g_usb_mode=USB_MODE_HOST; // Startup with ID=0, Ack ID pin transistion (default hwd start up is device mode) Usb_ack_id_transition(); Usb_enable_id_interrupt(); usb_host_task_init(); id_changed_to_host_event = ENABLE; } // Store current usb mode, for mode change detection g_old_usb_mode = g_usb_mode; }
//! //! @brief This function initializes the USB device controller //! //! This function enables the USB controller and init the USB interrupts. //! The aim is to allow the USB connection detection in order to send //! the appropriate USB event to the operating mode manager. //! Start device function is executed once VBUS connection has been detected //! either by the VBUS change interrupt either by the VBUS high level //! //! @param none //! //! @return none //! void usb_start_device (void) { Pll_start_auto(); Wait_pll_ready(); Usb_unfreeze_clock(); usb_init_device(); // configure the USB controller EP0 Usb_attach(); Usb_enable_suspend_interrupt(); Usb_enable_reset_interrupt(); #if (USB_OTG_FEATURE == ENABLED) Usb_enable_id_interrupt(); #endif }
/** * @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) { // ---- DUAL-ROLE DEVICE/HOST USB MODE ----------------------------------------- #if USB_DEVICE_FEATURE == true && USB_HOST_FEATURE == true if (g_old_usb_mode != g_usb_mode) { if (Is_usb_id_device()) { usb_device_task_init(); }else{ private_sof_counter = 0; usb_host_task_init(); } g_old_usb_mode = g_usb_mode; // Store current USB mode, for mode change detection Usb_enable_id_interrupt(); Enable_global_interrupt(); } // Depending on current USB mode, launch the correct USB task (device or host) switch (g_old_usb_mode) { case USB_MODE_DEVICE: usb_device_task(); break; case USB_MODE_HOST: usb_host_task(); break; case USB_MODE_UNDEFINED: default: break; } // ----------------------------------------------------------------------------- // ---- DEVICE-ONLY USB MODE --------------------------------------------------- #elif USB_DEVICE_FEATURE == true usb_device_task(); // ----------------------------------------------------------------------------- // ---- REDUCED-HOST-ONLY USB MODE --------------------------------------------- #elif USB_HOST_FEATURE == true usb_host_task(); // ----------------------------------------------------------------------------- // ---- ERROR, NO MODE true ------------------------------------------------- #else #error At least one of USB_DEVICE_FEATURE and USB_HOST_FEATURE must be enabled #endif // ----------------------------------------------------------------------------- }
//! //! @brief This function initializes the USB device controller and system interrupt //! //! This function enables the USB controller and init the USB interrupts. //! The aim is to allow the USB connection detection in order to send //! the appropriate USB event to the operating mode manager. //! //! @param none //! //! @return none //! //!/ void usb_device_task_init(void) { Enable_interrupt(); Usb_disable(); Usb_enable(); Usb_select_device(); #if (USB_LOW_SPEED_DEVICE==ENABLE) Usb_low_speed_mode(); #endif Enable_interrupt(); #if (USB_OTG_FEATURE == ENABLED) Usb_enable_id_interrupt(); Clear_otg_features_from_host(); otg_device_sessions = 0; #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 }