From b217309e0b56c7d9f69e6c80cf01b313489b1fd4 Mon Sep 17 00:00:00 2001 From: asterix Date: Mon, 1 Dec 2008 18:34:57 +0000 Subject: [PATCH] Add the wdt avr cpu specific. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1950 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/avr/drv/wdt_avr.h | 100 +++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 bertos/cpu/avr/drv/wdt_avr.h diff --git a/bertos/cpu/avr/drv/wdt_avr.h b/bertos/cpu/avr/drv/wdt_avr.h new file mode 100644 index 00000000..109390eb --- /dev/null +++ b/bertos/cpu/avr/drv/wdt_avr.h @@ -0,0 +1,100 @@ +/** + * \file + * + * + * \brief Watchdog interface for AVR architecture. + * + * \version $Id$ + * + * \author Daniele Basile + * + */ + +#ifndef DRV_WDT_AVR_H +#define DRV_WDT_AVR_H + +#include "cfg/cfg_wdt.h" + +#include // INLINE + +#include + +#if CPU_AVR_ATMEGA1281 + #define WDT_CRTL_REG WDTCSR +#else + #define WDT_CRTL_REG WDTCR +#endif + +/** + * Reset the watchdog timer. + */ +INLINE void wdt_reset(void) +{ + __asm__ __volatile__ ("wdr"); +} + +INLINE void wdt_enable(bool flag) +{ + IRQ_DISABLE; + if (flag) + { + WDT_CRTL_REG |= BV(WDE); + } + else + { + WDT_CRTL_REG |= BV(WDCE) | BV(WDE); + WDT_CRTL_REG &= ~BV(WDE); + } + IRQ_ENABLE; +} + +/** + * Set watchdog timeout. + */ +INLINE void wdt_setTimeout(uint32_t timeout) +{ + IRQ_DISABLE; + wdt_reset(); + WDT_CRTL_REG |= BV(WDCE) | BV(WDE); + WDT_CRTL_REG = timeout; + IRQ_ENABLE; +} + +/** + * Init watchdog timer. + */ +INLINE void wdt_init(void) +{ + WDT_CRTL_REG |= BV(WDCE) | BV(WDE); +} + + +#endif /* DRV_WDT_AVR_H */ -- 2.25.1