void udd_enable(void) { irqflags_t flags; flags = cpu_irq_save(); #if SAMG55 matrix_set_usb_device(); #endif // Enable USB hardware udd_enable_periph_ck(); sysclk_enable_usb(); // Cortex, uses NVIC, no need to register IRQ handler NVIC_SetPriority((IRQn_Type) ID_UDP, UDD_USB_INT_LEVEL); NVIC_EnableIRQ((IRQn_Type) ID_UDP); // Reset internal variables #if (0!=USB_DEVICE_MAX_EP) udd_ep_job_table_reset(); #endif // Always authorize asynchronous USB interrupts to exit of sleep mode pmc_set_fast_startup_input(PMC_FSMR_USBAL); #ifndef UDD_NO_SLEEP_MGR // Initialize the sleep mode authorized for the USB suspend mode udd_b_idle = false; sleepmgr_lock_mode(UDP_SLEEP_MODE_USB_SUSPEND); #endif #if UDD_VBUS_IO /* Initialize VBus monitor */ udd_vbus_init(udd_vbus_handler); udd_vbus_monitor_sleep_mode(true); /* Force Vbus interrupt when Vbus is always high * This is possible due to a short timing between a Host mode stop/start. */ if (Is_udd_vbus_high()) { udd_vbus_handler(USB_VBUS_PIO_ID, USB_VBUS_PIO_MASK); } #else # ifndef USB_DEVICE_ATTACH_AUTO_DISABLE udd_attach(); # endif #endif cpu_irq_restore(flags); }
void udd_enable(void) { irqflags_t flags; flags = cpu_irq_save(); #ifdef UHD_ENABLE //* DUAL ROLE INITIALIZATION if (otg_dual_enable()) { // The current mode has been started by otg_dual_enable() cpu_irq_restore(flags); return; } #else //* SINGLE DEVICE MODE INITIALIZATION sysclk_enable_usb(); // Here, only the device mode is possible, then link USBB interrupt to UDD interrupt irq_register_handler( #ifdef FREERTOS_USED (__int_handler) #endif udd_interrupt, AVR32_USBB_IRQ, UDD_USB_INT_LEVEL); // Always authorize asynchronous USB interrupts to exit of sleep mode pm_asyn_wake_up_enable(AVR32_PM_AWEN_USB_WAKEN_MASK); #endif # if (defined USB_ID) && (defined UHD_ENABLE) // Check that the device mode is selected by ID pin if (!Is_otg_id_device()) { cpu_irq_restore(flags); return; // Device is not the current mode } # else // ID pin not used then force device mode otg_disable_id_pin(); otg_force_device_mode(); # endif // Enable USB hardware otg_enable_pad(); otg_enable(); otg_unfreeze_clock(); (void)Is_otg_clock_frozen(); // Reset internal variables #if (0!=USB_DEVICE_MAX_EP) udd_ep_job_table_reset(); #endif // Set the USB speed requested by configuration file #ifdef USB_DEVICE_LOW_SPEED udd_low_speed_enable(); #else udd_low_speed_disable(); # ifdef USB_DEVICE_HS_SUPPORT udd_high_speed_enable(); # else udd_high_speed_disable(); # endif #endif otg_ack_vbus_transition(); // Force Vbus interrupt in case of Vbus always with a high level // This is possible with a short timing between a Host mode stop/start. if (Is_otg_vbus_high()) { otg_raise_vbus_transition(); } otg_enable_vbus_interrupt(); otg_freeze_clock(); #ifndef UDD_NO_SLEEP_MGR // Initialize the sleep mode authorized for the USB suspend mode udd_b_idle = false; sleepmgr_lock_mode(USBB_SLEEP_MODE_USB_SUSPEND); #endif cpu_irq_restore(flags); }
void udd_enable(void) { irqflags_t flags; sysclk_enable_usb(); flags = cpu_irq_save(); //** Enable USB hardware otg_disable(); (void)Is_otg_enabled(); #ifdef OTG // Check UID pin state before enter in USB device mode if (!Is_otg_id_device()) return FALSE; #else // Here, only the Device mode is possible, then link USBB interrupt to UDD interrupt irq_register_handler(udd_interrupt, AVR32_USBB_IRQ, UDD_USB_INT_LEVEL); otg_force_device_mode(); #endif otg_disable_pad(); otg_enable_pad(); otg_enable(); otg_unfreeze_clock(); (void)Is_otg_clock_frozen(); #if UC3A3 // For parts with high speed feature, the "USABLE" clock is the UTMI clock, // and the UTMI clock is disabled in suspend mode. Thereby, the utmi clock // can't be checked when USB line is not attached or in suspend mode #else // Check USB clock while( !Is_clock_usable() ); #endif // Reset internal variables #if (0!=USB_DEVICE_MAX_EP) udd_ep_job_table_reset(); #endif // Set the USB speed requested by configuration file #ifdef USB_DEVICE_LOW_SPEED udd_low_speed_enable(); #else udd_low_speed_disable(); # ifdef USB_DEVICE_HS_SUPPORT udd_high_speed_enable(); # else udd_high_speed_disable(); # endif #endif udd_enable_vbus_interrupt(); otg_freeze_clock(); // Always authorize asynchrone USB interrupts to exit of sleep mode AVR32_PM.AWEN.usb_waken = 1; #ifndef UDD_NO_SLEEP_MGR // Initialize the sleep mode authorized for the USB suspend mode udd_b_idle = false; sleepmgr_lock_mode(USBB_SLEEP_MODE_USB_SUSPEND); #endif cpu_irq_restore(flags); }
void udd_enable(void) { irqflags_t flags; flags = cpu_irq_save(); #ifdef UHD_ENABLE // DUAL ROLE INITIALIZATION if (otg_dual_enable()) { // The current mode has been started by otg_dual_enable() cpu_irq_restore(flags); return; } #else // SINGLE DEVICE MODE INITIALIZATION sysclk_enable_usb(); pmc_enable_periph_clk(ID_UOTGHS); // Here, only the device mode is possible, then link UHDP interrupt to UDD interrupt NVIC_SetPriority((IRQn_Type) ID_UOTGHS, USB_INT_LEVEL); NVIC_EnableIRQ((IRQn_Type) ID_UOTGHS); // Always authorize asynchrony USB interrupts to exit of sleep mode // For SAM USB wake up device except BACKUP mode pmc_set_fast_startup_input(PMC_FSMR_USBAL); #endif #if (OTG_ID_IO) && (defined UHD_ENABLE) // Check that the device mode is selected by ID pin if (!Is_otg_id_device()) { cpu_irq_restore(flags); return; // Device is not the current mode } #else // ID pin not used and force device mode otg_force_device_mode(); #endif // Enable USB hardware otg_enable(); // Reset internal variables #if (0!=USB_DEVICE_MAX_EP) udd_ep_job_table_reset(); #endif #ifndef UDD_NO_SLEEP_MGR if (!udd_b_sleep_initialized) { udd_b_sleep_initialized = true; // Initialize the sleep mode authorized for the USB suspend mode udd_b_idle = false; sleepmgr_lock_mode(UHDP_SLEEP_MODE_USB_SUSPEND); } else { udd_sleep_mode(false); // Enter idle mode } #endif #if OTG_VBUS_IO /* Initialize VBus monitor */ otg_vbus_init(udd_vbus_handler); udd_vbus_monitor_sleep_mode(true); /* Force VBus interrupt when VBus is always high * This is possible due to a short timing between a Host mode stop/start. */ if (Is_otg_vbus_high()) { udd_vbus_handler(USB_VBUS_PIO_ID, USB_VBUS_PIO_MASK); } #else # ifndef USB_DEVICE_ATTACH_AUTO_DISABLE udd_attach(); # endif #endif cpu_irq_restore(flags); }