This file contains definitions and services for the AVR32 WatchDog Timer.
Definition in file wdt.h.
Go to the source code of this file.
Functions | |
void | wdt_clear (void) |
Clears the WatchDog Timer. | |
void | wdt_disable (void) |
Disables the WatchDog Timer. | |
unsigned long long | wdt_enable (unsigned long long us_timeout_period) |
Enables the WatchDog Timer with the us_timeout_period time-out period saturated to the supported range and rounded up to the nearest supported greater time-out period. | |
long long | wdt_get_us_timeout_period (void) |
Gets the time-out period of the WatchDog Timer in microseconds. | |
void | wdt_reenable (void) |
Re-enables the WatchDog Timer with the last time-out period configured. | |
void | wdt_reset_mcu (void) |
Resets the MCU with the WatchDog Timer as fast as possible. |
void wdt_clear | ( | void | ) |
void wdt_disable | ( | void | ) |
Disables the WatchDog Timer.
Definition at line 75 of file wdt.c.
References wdt_set_ctrl().
00076 { 00077 wdt_set_ctrl(AVR32_WDT.ctrl & ~AVR32_WDT_CTRL_EN_MASK); 00078 }
unsigned long long wdt_enable | ( | unsigned long long | us_timeout_period | ) |
Enables the WatchDog Timer with the us_timeout_period time-out period saturated to the supported range and rounded up to the nearest supported greater time-out period.
us_timeout_period | Time-out period to configure in microseconds. |
Definition at line 81 of file wdt.c.
References MAX_US_TIMEOUT_PERIOD, MIN_US_TIMEOUT_PERIOD, wdt_get_us_timeout_period(), and wdt_set_ctrl().
Referenced by wdt_reset_mcu(), and wdt_scheduler().
00082 { 00083 #define MIN_US_TIMEOUT_PERIOD (((1ULL << 1 ) * 1000000 + AVR32_PM_RCOSC_FREQUENCY / 2) / AVR32_PM_RCOSC_FREQUENCY) 00084 #define MAX_US_TIMEOUT_PERIOD (((1ULL << (1 << AVR32_WDT_CTRL_PSEL_SIZE)) * 1000000 + AVR32_PM_RCOSC_FREQUENCY / 2) / AVR32_PM_RCOSC_FREQUENCY) 00085 00086 // Set the CTRL.EN bit and translate the us timeout to fit in CTRL.PSEL using 00087 // the formula Twdt = 2pow(PSEL+1) / fRCosc 00088 wdt_set_ctrl(AVR32_WDT_CTRL_EN_MASK | 00089 ((32 - clz(((((Min(Max(us_timeout_period, MIN_US_TIMEOUT_PERIOD), MAX_US_TIMEOUT_PERIOD) * 00090 AVR32_PM_RCOSC_FREQUENCY + 500000) / 1000000) << 1) - 1) >> 1) - 1) << 00091 AVR32_WDT_CTRL_PSEL_OFFSET)); 00092 00093 // Return the actual wdt period in us. 00094 return wdt_get_us_timeout_period(); 00095 }
long long wdt_get_us_timeout_period | ( | void | ) |
Gets the time-out period of the WatchDog Timer in microseconds.
<0 | The WatchDog Timer is disabled. | |
>=0 | Active time-out period of the WatchDog Timer in microseconds. |
Definition at line 65 of file wdt.c.
Referenced by wdt_enable().
00066 { 00067 // Read CTRL.PSEL and translate it into us. 00068 return (AVR32_WDT.ctrl & AVR32_WDT_CTRL_EN_MASK) ? 00069 ((1ULL << (((AVR32_WDT.ctrl & AVR32_WDT_CTRL_PSEL_MASK) >> AVR32_WDT_CTRL_PSEL_OFFSET) + 1)) * 00070 1000000 + AVR32_PM_RCOSC_FREQUENCY / 2) / AVR32_PM_RCOSC_FREQUENCY : 00071 -1ULL; 00072 }
void wdt_reenable | ( | void | ) |
Re-enables the WatchDog Timer with the last time-out period configured.
Definition at line 98 of file wdt.c.
References wdt_set_ctrl().
Referenced by wdt_scheduler().
00099 { 00100 wdt_set_ctrl(AVR32_WDT.ctrl | AVR32_WDT_CTRL_EN_MASK); 00101 }
void wdt_reset_mcu | ( | void | ) |
Resets the MCU with the WatchDog Timer as fast as possible.
Definition at line 110 of file wdt.c.
References wdt_enable().
00111 { 00112 Disable_global_interrupt(); 00113 // Enable the WDT with a 0s period (fastest way to get a Watchdog reset). 00114 wdt_enable(0); 00115 while (1); 00116 }