//! [setup] void configure_wdt(void) { /* Create a new configuration structure for the Watchdog settings and fill * with the default module settings. */ //! [setup_1] struct wdt_conf config_wdt; //! [setup_1] //! [setup_2] wdt_get_config_defaults(&config_wdt); //! [setup_2] /* Set the Watchdog configuration settings */ //! [setup_3] config_wdt.always_on = false; #if !((SAML21) || (SAMC21) || (SAML22)) config_wdt.clock_source = GCLK_GENERATOR_4; #endif config_wdt.timeout_period = WDT_PERIOD_2048CLK; //! [setup_3] /* Initialize and enable the Watchdog with the user settings */ //! [setup_4] wdt_set_config(&config_wdt); //! [setup_4] }
void wdt_config(void){ //GCLK->CLKCTRL.reg=0x4204; /* Create a new configuration structure for the Watchdog settings and fill * with the default module settings. */ //! [setup_1] struct wdt_conf config_wdt; //! [setup_1] //! [setup_2] wdt_get_config_defaults(&config_wdt); //! [setup_2] /* Set the Watchdog configuration settings */ //! [setup_3] config_wdt.always_on = false; #if !((SAML21) || (SAMC21) || (SAML22)) config_wdt.clock_source = GCLK_GENERATOR_2; #endif config_wdt.timeout_period = WDT_PERIOD_16384CLK; //! [setup_3] /* Initialize and enable the Watchdog with the user settings */ //! [setup_4] wdt_set_config(&config_wdt); //! [setup_4] //hmi.printf("config wdt\r\n"); }
/** * \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 */ } }
void main(void) { struct wdt_config wr_cfg; struct wdt_config cfg; struct device *wdt_dev; printk("Start watchdog test\n"); wr_cfg.timeout = WDT_2_27_CYCLES; wr_cfg.mode = WDT_MODE_INTERRUPT_RESET; wr_cfg.interrupt_fn = wdt_example_cb; wdt_dev = device_get_binding("WATCHDOG_0"); wdt_enable(wdt_dev); wdt_set_config(wdt_dev, &wr_cfg); wdt_get_config(wdt_dev, &cfg); printk("timeout: %d\n", cfg.timeout); printk("mode: %d\n", cfg.mode); }
/** * \brief Function for starting application * * This function will configure the WDT module and enable it. The LED is * kept toggling till WDT reset occurs. */ static void start_application(void) { struct wdt_conf wdt_config; WDT->CTRL.reg |= WDT_CTRL_ENABLE; /* Turn off LED */ port_pin_set_output_level(BOOT_LED, true); /* Get WDT default configuration */ wdt_get_config_defaults(&wdt_config); /* Set the required clock source and timeout period */ wdt_config.clock_source = GCLK_GENERATOR_4; wdt_config.timeout_period = WDT_PERIOD_2048CLK; /* Initialize and enable the Watchdog with the user settings */ wdt_set_config(&wdt_config); #ifdef __DEBUG_PRINT__ printf("\r\n[WATCHDOG RESET INVOKED]..Resetting !!!!\r\n"); #endif while(1); }
/* * Test command for panic generator: debug panic <panic_id> * * @param[in] argc Number of arguments in the Test Command (including group and name) * @param[in] argv Table of null-terminated buffers containing the arguments * @param[in] ctx The context to pass back to responses */ void debug_panic(int argc, char *argv[], struct tcmd_handler_ctx *ctx) { volatile uint32_t panic_id; volatile uint32_t aligned_var[2] = { 0xFFFFFFFF, 0xFFFFFFFF }; volatile uint32_t unaligned_ptr; volatile int opcode = 0; #ifdef CONFIG_INTEL_QRK_WDT struct device *wdt_dev; struct wdt_config config; int res; #endif if (argc != ARGC) goto print_help; panic_id = strtoul(argv[PANIC_ID_IDX], NULL, 10); switch (panic_id) { case 0: panic_id = 123 / panic_id; TCMD_RSP_ERROR( ctx, "Division by 0 did not panic (sw implementation ?)."); break; case 1: unaligned_ptr = (uint32_t)&aligned_var; if (*((uint32_t *)(unaligned_ptr + 1))) TCMD_RSP_ERROR( ctx, "Unaligned access is allowed on this platform."); break; case 2: #ifdef CONFIG_INTEL_QRK_WDT config.timeout = 2097; // Timeout: 2.097s (for 32MHz) config.mode = WDT_MODE_INTERRUPT_RESET; extern struct device DEVICE_NAME_GET(wdt); wdt_dev = DEVICE_GET(wdt); res = wdt_set_config(wdt_dev, &config); if (res == DEV_OK) { TCMD_RSP_FINAL(ctx, "Watchdog"); irq_lock(); while (1) ; } else TCMD_RSP_ERROR(ctx, "Watchdog configuration failure"); #else TCMD_RSP_ERROR(ctx, "Watchdog not supported"); #endif break; case 3: TCMD_RSP_FINAL(ctx, "Invalid address"); *((volatile uint32_t *)0xFFFFFFFF) = 0xABCD; break; case 4: TCMD_RSP_FINAL(ctx, "App Error."); panic(0x123456); break; case 5: /* Need MMU to support stack overflow */ TCMD_RSP_ERROR(ctx, "No Stack Overflow"); break; case 6: ((void (*)(void))(&opcode))(); TCMD_RSP_FINAL(ctx, "Wrong OpCode."); break; default: TCMD_RSP_ERROR(ctx, "KO 1"); break; } return; print_help: TCMD_RSP_ERROR(ctx, "Usage: debug panic <panic_id>."); }