static void prvSetupHardware( void ) { extern void SystemCoreClockUpdate( void ); struct eic_line_config xEICLineConfiguration; /* Configure the external interrupt controller so button pushes can generate interrupts. */ xEICLineConfiguration.eic_mode = EIC_MODE_EDGE_TRIGGERED; xEICLineConfiguration.eic_edge = EIC_EDGE_FALLING_EDGE; xEICLineConfiguration.eic_level = EIC_LEVEL_LOW_LEVEL; xEICLineConfiguration.eic_filter = EIC_FILTER_DISABLED; xEICLineConfiguration.eic_async = EIC_ASYNCH_MODE; eic_enable( EIC ); eic_line_set_config( EIC, GPIO_PUSH_BUTTON_EIC_LINE, &xEICLineConfiguration ); eic_line_set_callback( EIC, GPIO_PUSH_BUTTON_EIC_LINE, prvButtonISR, EIC_5_IRQn, 0 ); eic_line_enable( EIC, GPIO_PUSH_BUTTON_EIC_LINE ); /* ASF function to setup clocking. */ sysclk_init(); /* Ensure all priority bits are assigned as preemption priority bits. */ NVIC_SetPriorityGrouping( 0 ); /* Atmel library function to setup for the evaluation kit being used. */ board_init(); /* Initialise the sleep manager in case the low power demo is being used. */ sleepmgr_init(); }
//! [eic_setup] static void eic_setup(void) { //! [enable_eic_module] eic_enable(EIC); //! [enable_eic_module] struct eic_line_config eic_line_conf; eic_line_conf.eic_mode = EIC_MODE_EDGE_TRIGGERED; eic_line_conf.eic_edge = EIC_EDGE_FALLING_EDGE; eic_line_conf.eic_level = EIC_LEVEL_LOW_LEVEL; eic_line_conf.eic_filter = EIC_FILTER_DISABLED; eic_line_conf.eic_async = EIC_ASYNCH_MODE; //! [configure_eic_mode] eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_conf); //! [configure_eic_mode] //! [set_eic_callback_1] eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, eic_callback, GPIO_PUSH_BUTTON_EIC_IRQ, 1); //! [set_eic_callback_1] //! [enable_eic_line] eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE); //! [enable_eic_line] }
/** * \brief Event Button Init. */ void event_button_init(void) { // Structure holding the configuration parameters // of the EIC module. struct eic_line_config eic_line_conf; // Initialize EIC Controller sysclk_enable_peripheral_clock(EIC); // Enable level-triggered interrupt. eic_line_conf.eic_mode = EIC_MODE_EDGE_TRIGGERED; // Interrupt will trigger on low-level. eic_line_conf.eic_level = EIC_LEVEL_LOW_LEVEL; // Edge on falling edge eic_line_conf.eic_edge = EIC_EDGE_FALLING_EDGE; // Enable filter. eic_line_conf.eic_filter = EIC_FILTER_DISABLED; // For Wake Up mode, initialize in asynchronous mode eic_line_conf.eic_async = EIC_ASYNCH_MODE; // Enable clock for EIC controller eic_enable(EIC); // Init the EIC controller with the options eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_conf); // Init the callback eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, eic5_callback, EIC_5_IRQn, 1); // Enable the EIC line eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE); // EIC can wake the device from backup mode bpm_enable_wakeup_source(BPM, BPM_BKUP_WAKEUP_SRC_EIC | BPM_BKUP_WAKEUP_SRC_AST); // EIC can wake the device from backup mode bpm_enable_backup_pin(BPM, 1 << GPIO_PUSH_BUTTON_EIC_LINE); // Retain I/O lines after wakeup from backup bpm_disable_io_retention(BPM); bpm_enable_io_retention(BPM); bpm_enable_fast_wakeup(BPM); sysclk_disable_peripheral_clock(EIC); event_pbEvent = false; // Initialize WDT Controller sysclk_enable_peripheral_clock(WDT); enable_wdt(); }
/** * Configure push button 0 to generate an EIC interrupt. */ static void configure_button(void) { struct eic_line_config eic_line_conf; eic_line_conf.eic_mode = EIC_MODE_EDGE_TRIGGERED; eic_line_conf.eic_edge = EIC_EDGE_FALLING_EDGE; eic_line_conf.eic_level = EIC_LEVEL_LOW_LEVEL; eic_line_conf.eic_filter = EIC_FILTER_DISABLED; eic_line_conf.eic_async = EIC_ASYNCH_MODE; eic_enable(EIC); eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_conf); eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, set_toggle_flag, GPIO_PUSH_BUTTON_EIC_IRQ, 1); eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE); }
static void config_buttons(void) { /* Initialize EIC for button wakeup. */ struct eic_line_config eic_line_conf = { EIC_MODE_EDGE_TRIGGERED, EIC_EDGE_FALLING_EDGE, EIC_LEVEL_LOW_LEVEL, EIC_FILTER_DISABLED, EIC_ASYNCH_MODE }; eic_enable(EIC); eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_conf); eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, eic_5_callback, EIC_5_IRQn, 1); eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE); }
/** * \brief Initializes and enables interrupt pin change */ static void ui_enable_asynchronous_interrupt(void) { /* Initialize EIC for button wakeup */ sysclk_enable_peripheral_clock(EIC); struct eic_line_config eic_opt ={ .eic_mode = EIC_MODE_EDGE_TRIGGERED, .eic_edge = EIC_EDGE_FALLING_EDGE, .eic_level = EIC_LEVEL_LOW_LEVEL, .eic_filter = EIC_FILTER_DISABLED, .eic_async = EIC_ASYNCH_MODE }; eic_enable(EIC); eic_line_set_config(EIC, UI_WAKEUP_EIC_LINE, &eic_opt); eic_line_set_callback(EIC, UI_WAKEUP_EIC_LINE, UI_WAKEUP_HANDLER, UI_WAKEUP_IRQN, UI_WAKEUP_IRQ_LEVEL); eic_line_enable(EIC, UI_WAKEUP_EIC_LINE); eic_line_enable_interrupt(EIC, UI_WAKEUP_EIC_LINE); }
/** * \brief Application entry point for eic example. * * \return Unused (ANSI-C compatibility). */ int main(void) { struct eic_line_config eic_line_conf; /* Initialize the SAM system. */ sysclk_init(); board_init(); /* Initialize the UART console. */ configure_console(); /* Output example information. */ puts(STRING_HEADER); eic_line_conf.eic_mode = EIC_MODE_EDGE_TRIGGERED; eic_line_conf.eic_edge = EIC_EDGE_FALLING_EDGE; eic_line_conf.eic_level = EIC_LEVEL_LOW_LEVEL; eic_line_conf.eic_filter = EIC_FILTER_DISABLED; eic_line_conf.eic_async = EIC_ASYNCH_MODE; eic_enable(EIC); eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_conf); eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, set_toggle_flag, GPIO_PUSH_BUTTON_EIC_IRQ, 1); eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE); puts("--Push the button to toggle the LED--\r\n\r"); while (1) { if (bToggle == 1) { puts("--Toggle the LED--\r"); ioport_toggle_port_level(EXAMPLE_LED_PORT, EXAMPLE_LED_MASK); bToggle = 0; } } }
/* \brief Main entry point * This is an example of how to use watchdog. */ int main(void) { struct eic_line_config eic_line_cfg; /* Initialize the SAM system */ sysclk_init(); board_init(); /* Initialize the console uart */ configure_console(); /* Output example information */ printf("\r\n\r\n-- Watchdog example --\r\n"); printf("-- %s\r\n", BOARD_NAME); printf("-- Compiled: %s %s --\r\n", __DATE__, __TIME__); /* Systick configuration. */ if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) { puts("-F- Systick configuration error\r"); } /* Configure push button */ eic_line_cfg.eic_mode = EIC_MODE_EDGE_TRIGGERED; eic_line_cfg.eic_edge = EIC_EDGE_FALLING_EDGE; eic_line_cfg.eic_level = EIC_LEVEL_LOW_LEVEL; eic_line_cfg.eic_filter = EIC_FILTER_DISABLED; eic_line_cfg.eic_async = EIC_ASYNCH_MODE; eic_enable(EIC); eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, &eic_line_cfg); eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, set_toggle_flag, EIC_5_IRQn, 1); eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE); /* * Intialize and enable the watchdog. * Use default configuration but change timeout period * to about 4.56s (Ttimeout = 2pow(PSEL+1) / Fclk_cnt = 524288 / 115000). */ wdt_get_config_defaults(&g_wdt_cfg); g_wdt_cfg.timeout_period = WDT_PERIOD_524288_CLK; wdt_init(&g_wdt_inst, WDT, &g_wdt_cfg); wdt_enable(&g_wdt_inst); puts("\r\nPlease press PB0 to simulate a deadlock.\r"); while (1) { if (g_b_systick_event == true) { g_b_systick_event = false; /* Toggle LED at the given period. */ if ((g_ul_ms_ticks % BLINK_PERIOD) == 0) { ioport_toggle_pin_level(LED0_GPIO); } /* Clear watchdog at the given period. */ if ((g_ul_ms_ticks % WDT_RESTART_PERIOD) == 0) { wdt_clear(&g_wdt_inst); } } /* Simulate deadlock when button is pressed. */ if (g_b_button_event == true) { puts("The program enters an infinite loop, the WDT reset will " \ "trigger in about 5s.\r"); wdt_clear(&g_wdt_inst); while (1) { if (g_b_systick_event == true) { g_b_systick_event = false; if ((g_ul_ms_ticks % BLINK_PERIOD) == 0) { printf("."); } } } } } }