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); }
/** * \brief Main Application Routine * - Initialize the system clocks * - Initialize the sleep manager * - Initialize the power save measures * - Initialize the ACIFB module * - Initialize the AST to trigger ACIFB at regular intervals * - Go to STATIC sleep mode and wake up on a touch status change */ int main(void) { /* Switch on the STATUS LED */ gpio_clr_gpio_pin(STATUS_LED); /* Switch off the error LED. */ gpio_set_gpio_pin(ERROR_LED); /* * Initialize the system clock. * Note: Clock settings are specified in conf_clock.h */ sysclk_init(); /* * Initialize the sleep manager. * Note: CONFIG_SLEEPMGR_ENABLE should have been defined in conf_sleepmgr.h */ sleepmgr_init(); /* Lock required sleep mode. */ sleepmgr_lock_mode(SLEEPMGR_STATIC); /* Initialize the delay routines */ delay_init(sysclk_get_cpu_hz()); /* Initialize the power saving features */ power_save_measures_init(); /* Switch off the error LED. */ gpio_set_gpio_pin(ERROR_LED); #if DEBUG_MESSAGES /* Enable the clock to USART interface */ sysclk_enable_peripheral_clock(DBG_USART); /* Initialize the USART interface to print trace messages */ init_dbg_rs232(sysclk_get_pba_hz()); print_dbg("\r Sleepwalking with ACIFB Module in UC3L \n"); print_dbg("\r Initializing ACIFB Module..... \n"); #endif /* Initialize the Analog Comparator peripheral */ if (ac_init() != STATUS_OK) { #if DEBUG_MESSAGES /* Error initializing the ACIFB peripheral */ print_dbg("\r Error initializing Analog Comparator module \n"); #endif while (1) { delay_ms(LED_DELAY); gpio_tgl_gpio_pin(ERROR_LED); } } #if DEBUG_MESSAGES print_dbg("\r ACIFB Module initialized. \n"); print_dbg("\r Initializing AST Module..... \n"); #endif /* Initialize the AST peripheral */ if (ast_init() != STATUS_OK) { #if DEBUG_MESSAGES print_dbg("\r Error initializing AST module \n"); #endif /* Error initializing the AST peripheral */ while (1) { delay_ms(LED_DELAY); gpio_tgl_gpio_pin(ERROR_LED); } } #if DEBUG_MESSAGES print_dbg("\r AST Module initialized. \n"); #endif /* Application routine */ while (1) { /* Enable Asynchronous wake-up for ACIFB */ pm_asyn_wake_up_enable(AVR32_PM_AWEN_ACIFBWEN_MASK); #if DEBUG_MESSAGES print_dbg("\r Going to STATIC sleep mode \n"); print_dbg( "\r Wake up only when input is higher than threshold \n"); #endif /* Switch off the status LED */ gpio_set_gpio_pin(STATUS_LED); /* Disable GPIO clock before entering sleep mode */ sysclk_disable_pba_module(SYSCLK_GPIO); AVR32_INTC.ipr[0]; /* Enter STATIC sleep mode */ sleepmgr_enter_sleep(); /* Enable GPIO clock after waking from sleep mode */ sysclk_enable_pba_module(SYSCLK_GPIO); /* Switch on the status LED */ gpio_clr_gpio_pin(STATUS_LED); #if DEBUG_MESSAGES print_dbg("\r Output higher than threshold \n"); print_dbg("\n"); #else /* LED on for few ms */ delay_ms(LED_DELAY); #endif /* Clear the wake up & enable it to enter sleep mode again */ pm_asyn_wake_up_disable(AVR32_PM_AWEN_ACIFBWEN_MASK); /* Clear All AST Interrupt request and clear SR */ ast_clear_all_status_flags(&AVR32_AST); } return 0; } /* End of main() */
/** Main function to configure the CAN, and begin transfers. */ int main(void) { /* Initialize the system clocks */ sysclk_init(); /* Setup the generic clock for CAN */ scif_gc_setup(AVR32_SCIF_GCLK_CANIF, SCIF_GCCTRL_OSC0, AVR32_SCIF_GC_NO_DIV_CLOCK, 0); /* Now enable the generic clock */ scif_gc_enable(AVR32_SCIF_GCLK_CANIF); init_dbg_rs232(FPBA_HZ); /* Disable all interrupts. */ Disable_global_interrupt(); /* Initialize interrupt vectors. */ INTC_init_interrupts(); static const gpio_map_t CAN_GPIO_MAP = { {AVR32_CANIF_RXLINE_0_0_PIN, AVR32_CANIF_RXLINE_0_0_FUNCTION}, {AVR32_CANIF_TXLINE_0_0_PIN, AVR32_CANIF_TXLINE_0_0_FUNCTION} }; /* Assign GPIO to CAN. */ gpio_enable_module(CAN_GPIO_MAP, sizeof(CAN_GPIO_MAP) / sizeof(CAN_GPIO_MAP[0])); /* Initialize channel 0 */ can_init(CAN_CHANNEL_EXAMPLE, ((uint32_t)&mob_ram_ch0[0]), CANIF_CHANNEL_MODE_LISTENING, can_out_callback_channel0); /* Enable all interrupts. */ Enable_global_interrupt(); print_dbg("\r\nUC3C CAN Examples 1\r\n"); print_dbg(CAN_Wakeup); /* Initialize CAN Channel 0 */ can_init(CAN_CHANNEL_EXAMPLE, ((uint32_t)&mob_ram_ch0[0]), CANIF_CHANNEL_MODE_NORMAL, can_out_callback_channel0); /* Allocate one mob for RX */ appli_rx_msg.handle = can_mob_alloc(CAN_CHANNEL_EXAMPLE); /* Initialize RX message */ can_rx(CAN_CHANNEL_EXAMPLE, appli_rx_msg.handle, appli_rx_msg.req_type, appli_rx_msg.can_msg); /* Enable Async Wake Up Mode */ pm_asyn_wake_up_enable(CAN_WAKEUP_MASK_EXAMPLE); /* ---------SLEEP MODE PROCEDURE------------- */ /* Disable CAN Channel 0 */ CANIF_disable(CAN_CHANNEL_EXAMPLE); /* Wait CAN Channel 0 is disabled */ while(!CANIF_channel_enable_status(CAN_CHANNEL_EXAMPLE)); /* Enable Wake-Up Mode */ CANIF_enable_wakeup(CAN_CHANNEL_EXAMPLE); /* Go to sleep mode. */ SLEEP(AVR32_PM_SMODE_STATIC); /* ---------SLEEP MODE PROCEDURE------------- */ print_dbg(CAN_WakeupD); /* Initialize again CAN Channel 0 */ can_init(CAN_CHANNEL_EXAMPLE, ((uint32_t)&mob_ram_ch0[0]), CANIF_CHANNEL_MODE_NORMAL, can_out_callback_channel0); /* Allocate one mob for RX */ appli_rx_msg.handle = can_mob_alloc(CAN_CHANNEL_EXAMPLE); /* Initialize RX message */ can_rx(CAN_CHANNEL_EXAMPLE, appli_rx_msg.handle, appli_rx_msg.req_type, appli_rx_msg.can_msg); for (;;) { /* Do nothing; interrupts handle the DAC conversions */ } }
/** * \brief Main Application Routine * - Initialize the system clocks * - Initialize the sleep manager * - Initialize the power save measures * - Initialize the touch library and sensors * - Initialize the AST to trigger CAT at regular intervals * - Go to STATIC sleep mode and wake up on a touch status change */ int main(void) { #if DEF_TOUCH_QDEBUG_ENABLE == 1 uint32_t delay_counter; #endif uint32_t i; /* Switch on the STATUS LED */ gpio_clr_gpio_pin(STATUS_LED); /* Switch off the error LED. */ gpio_set_gpio_pin(ERROR_LED); /* * Initialize the system clock. * Note: Clock settings are specified in conf_clock.h */ sysclk_init(); /* * Initialize the sleep manager. * Note: CONFIG_SLEEPMGR_ENABLE should have been defined in conf_sleepmgr.h */ sleepmgr_init(); /* Lock required sleep mode. */ sleepmgr_lock_mode(SLEEPMGR_STATIC); /* Initialize the power saving features */ power_save_measures_init(); /* Switch off the error LED. */ gpio_set_gpio_pin(ERROR_LED); #if DEF_TOUCH_QDEBUG_ENABLE == 0 /* Initialize the AST peripheral */ if (ast_init() != STATUS_OK) { /* Error initializing the AST peripheral */ while (1) { for (i = 0; i < 10000; i++) { } gpio_tgl_gpio_pin(ERROR_LED); } } #endif /* Initialize the touch library */ if (touch_api_init() != STATUS_OK) { /* Error initializing the touch sensors */ while (1) { for (i = 0; i < 10000; i++) { } gpio_tgl_gpio_pin(ERROR_LED); } } #if DEF_TOUCH_QDEBUG_ENABLE == 1 /* Enable PBA clock for AST clock to switch its source */ sysclk_enable_peripheral_clock(QDEBUG_USART); /* * Initialize the QDebug interface. * QT600 USB Bridge two-way QDebug communication. */ QDebug_Init(); #endif /* Turn OFF the Status LED */ gpio_set_gpio_pin(STATUS_LED); /* Loop forever */ while (1) { #if DEF_TOUCH_QDEBUG_ENABLE == 1 /* Process any commands received from QTouch Studio. */ QDebug_ProcessCommands(); /* * Send out the Touch debug information data each time when * Touch measurement process is completed. * param - 0x000A -> Enable TOUCH_STATUS_CHANGE & * TOUCH_CHANNEL_REF_CHANGE * qt_lib_flags always for Autonomous QTouch. */ QDebug_SendData(0x000A); /* Delay to avoid sending the data to QTouch Studio too frequently. */ for (delay_counter = 0u; delay_counter < 1200u; delay_counter++) { } #else /* Enable Asynchronous Wakeup for CAT module */ pm_asyn_wake_up_enable(AVR32_PM_AWEN_CATWEN_MASK); /* Disable GPIO clock after waking from sleep mode */ sysclk_disable_pba_module(SYSCLK_GPIO); /* Enter STATIC sleep mode */ sleepmgr_enter_sleep(); /* Disable Asynchronous Wakeup for CAT module. */ pm_asyn_wake_up_disable(AVR32_PM_AWEN_CATWEN_MASK); /* Clear All AST Interrupt request and clear SR */ ast_clear_all_status_flags(&AVR32_AST); /** * When woken up by Autonomous QTouch interrupt, the * touch_at_status_change_interrupt_callback() is called that * updates the autonomous_qtouch_in_touch status flag. */ /* Host application code goes here */ #endif } } /* End of main() */