/** * \brief Run WDT unit tests * * Initializes the system and serial output, then sets up the * WDT unit test suite and runs it. */ int main(void) { /* Check whether reset cause was Watchdog */ #if (SAML21) wdr_flag = (system_get_reset_cause() & RSTC_RCAUSE_WDT); #else wdr_flag = (system_get_reset_cause() & PM_RCAUSE_WDT); #endif system_init(); /* Reset the Watchdog count */ wdt_reset_count(); struct wdt_conf config_wdt; /* Get the Watchdog default configuration */ wdt_get_config_defaults(&config_wdt); if(wdr_flag) { config_wdt.enable = false; } /* Set the desired configuration */ #if !(SAML21) config_wdt.clock_source = CONF_WDT_GCLK_GEN; #endif config_wdt.timeout_period = CONF_WDT_TIMEOUT_PERIOD; config_wdt.early_warning_period = CONF_WDT_EARLY_WARNING_PERIOD; wdt_set_config(&config_wdt); cdc_uart_init(); DEFINE_TEST_CASE(wdt_early_warning_test, NULL, run_wdt_early_warning_test, wait_for_wdt_reset, "WDT Early Warning Test"); DEFINE_TEST_CASE(reset_cause_test, NULL, run_reset_cause_test, NULL, "Confirming Watchdog Reset"); /* Put test case addresses in an array */ DEFINE_TEST_ARRAY(wdt_tests) = { &wdt_early_warning_test, &reset_cause_test, }; /* Define the test suite */ DEFINE_TEST_SUITE(wdt_suite, wdt_tests, "SAM WDT driver test suite"); /* Run all tests in the suite*/ test_suite_run(&wdt_suite); while (1) { /* Intentionally left empty */ } }
int main(void) { system_init(); //! [setup_init] configure_wdt(); //! [setup_init] //! [main] //! [main_1] enum system_reset_cause reset_cause = system_get_reset_cause(); //! [main_1] //! [main_2] if (reset_cause == SYSTEM_RESET_CAUSE_WDT) { port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE); } else { port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE); } //! [main_2] //! [main_3] while (true) { //! [main_3] //! [main_4] if (port_pin_get_input_level(BUTTON_0_PIN) == false) { //! [main_4] //! [main_5] port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE); wdt_reset_count(); //! [main_5] } } //! [main] }
void wdt_clear(void){ wdt_reset_count(); }