|
#define ms_to_ticks(t) (((t << 8) / 1000) - 1) #define ticks_to_ms(t) (((t + 1) * 1000) >> 8)
/* Hardware timeout in seconds */ #define WDT_HW_TIMEOUT 2
/* * Set the watchdog time interval in 1/256Hz (write-once) * Counter is 12 bit. */ static int wdt_settimeout(unsigned int timeout) { unsigned int reg; wdt_t *wd = (wdt_t *) WDT_BASE;
/* Check if disabled */ if (readl(&wd->mr) & WDT_MR_WDDIS) { printf("sorry, watchdog is disabled\n"); return -1; }
/* * All counting occurs at SLOW_CLOCK / 128 = 256 Hz * * Since WDV is a 12-bit counter, the maximum period is * 4096 / 256 = 16 seconds. */
reg = WDT_MR_WDRSTEN /* causes watchdog reset */ | WDT_MR_WDDBGHLT /* disabled in debug mode */ | WDT_MR_WDD(0xfff) /* restart at any time */ | WDT_MR_WDV(timeout); /* timer value */
writel(reg, &wd->mr);
return 0; }
void hw_watchdog_reset(void) { wdt_t *wd = (wdt_t *) WDT_BASE; writel(WDT_CR_WDRSTT | WDT_CR_KEY, &wd->cr); }
void hw_watchdog_init(void) { /* 16 seconds timer, resets enabled */ at91_wdt_settimeout(ms_to_ticks(WDT_HW_TIMEOUT * 1000)); }
In this code there is "writel" function,where it is defined.Also my doubt is how to use watchdog timer in main application.I am trying like this,
main() { WDT_Enable(10sec); while(1) {
//end of while } }
So, in the above code i am enabling the watchdog for 10sec,if the code didn't reaches to end of while loop with in 10sec then the controller should get restart.But this is not working properly.I want to know what is the exact procedure to implement it.
|