Roosbeh
The uTasker project includes verified code for the watchdog interrupt handler for all watchdog types that support it (including the one in the K20 - reference below).
1. Initialisation:
UNLOCK_WDOG();
WDOG_TOVALL = (2000/5);
WDOG_TOVALH = 0;
WDOG_STCTRLH = (WDOG_STCTRLH_STNDBYEN | WDOG_STCTRLH_WAITEN | WDOG_STCTRLH_STOPEN | WDOG_STCTRLH_WDOGEN | WDOG_STCTRLH_IRQRSTEN) // watchdog enabled to generate reset on 2s timeout (no further updates allowed) with interrupt before reset takes pace
2. Enable interrupt in NVIC:
fnEnterInterrupt(irq_WDOG_ID, 0, wdog_irq);
3. Interrupt handler:
static void wdog_irq(void)
{
WDOG_STCTRLL = (WDOG_STCTRLL_INTFLG | WDOG_STCTRLL_RES1); // clear interrupt flag
*BOOT_MAIL_BOX = 0x9876; // set a pattern to the boot mailbox to show that the watchdog interrupt took place
}
After the reset the location BOOT_MAIL_BOX ( allocation in SRAM that is otherwise not used or initialised) will show the value has been set.
The interrupt handler only has a very short time (number of clocks) to operate before the reset unconditionally occurs and so breakpoints in the routine (or writing data to Flash) are not possible.
Regards
Mark