打开WDT例程很方使,可以在有开发板和无开发板的情况下都可以打开。
以下是打开后的截图:
这个例程是这样,先配置好串口和看门狗定时及LED管脚定义。
/**
* \brief Handler for System Tick interrupt.
*/
void SysTick_Handler(void)
{
/* Set systick event flag (g_b_systick_event) and add 1 to systick. */
g_b_systick_event = true;
g_ul_ms_ticks++;
}
/**
* \brief Handler for watchdog interrupt.
*/
void WDT_Handler(void)
{
puts("Enter watchdog interrupt.\r");
/* Clear status bit to acknowledge interrupt by dummy read. */
wdt_get_status(WDT);
/* Restart the WDT counter. */
wdt_restart(WDT);
puts("The watchdog timer was restarted.\r");
}
/**
* \brief Handler for Button 1 rising edge interrupt.
*/
static void button_handler(uint32_t id, uint32_t mask)
{
/* Set button event flag (g_b_button_event). */
if ((PUSHBUTTON_ID == id) && (PUSHBUTTON_MASK == mask)) {
g_b_button_event = true;
}
}
/**
* \brief Configure the Console UART.
*/
static void configure_console(void)
{
const usart_serial_options_t uart_serial_options = {
.baudrate = CONF_UART_BAUDRATE,
#ifdef CONF_UART_CHAR_LENGTH
.charlength = CONF_UART_CHAR_LENGTH,
#endif
.paritytype = CONF_UART_PARITY,
#ifdef CONF_UART_STOP_BITS
.stopbits = CONF_UART_STOP_BITS,
#endif
};
/* Configure console UART. */
sysclk_enable_peripheral_clock(CONSOLE_UART_ID);
stdio_serial_init(CONF_UART, &uart_serial_options);
}
/**
* \brief Configure the Pushbutton.
*/
static void configure_button(void)
{
/* Enable the peripheral clock for the push button on board. */
pmc_enable_periph_clk(PUSHBUTTON_ID);
/* Configure PIOs as input pins. */
pio_configure(PUSHBUTTON_PIO, PUSHBUTTON_TYPE, PUSHBUTTON_MASK,
PUSHBUTTON_ATTR);
/* Adjust PIO debounce filter parameters. */
pio_set_debounce_filter(PUSHBUTTON_PIO, PUSHBUTTON_MASK,
PUSHBUTTON_FILTER_GLITCH_VAULE);
/* Initialize PIO interrupt handler, interrupt on rising edge. */
pio_handler_set(PUSHBUTTON_PIO, PUSHBUTTON_ID, PUSHBUTTON_MASK,
PUSHBUTTON_ATTR, button_handler);
}
/**
* \brief Configure LED.
*/
static void configure_led(void)
{
/* Configure PIOs for LED. */
pio_configure(LED_PIO, LED_TYPE, LED_MASK, LED_ATTR);
}
然后正常喂狗
/* Restart watchdog at the given period. */
if ((g_ul_ms_ticks % WDT_RESTART_PERIOD) == 0) {
wdt_restart(WDT);
}
当有用户按键时,这时就破坏了喂狗,这时转向看门狗的中断程序。
/* Simulate deadlock when button is pressed. */
if (g_b_button_event == true) {
puts("Program enters infinite loop for triggering watchdog interrupt.\r");
while (1) {
}
}
最后进入看门狗中断程序:
*/
void WDT_Handler(void)
{
puts("Enter watchdog interrupt.\r");
/* Clear status bit to acknowledge interrupt by dummy read. */
wdt_get_status(WDT);
/* Restart the WDT counter. */
wdt_restart(WDT);
puts("The watchdog timer was restarted.\r");
}
|