From: asterix Date: Mon, 1 Dec 2008 18:34:57 +0000 (+0000) Subject: Add the wdt avr cpu specific. X-Git-Tag: 2.1.0~732 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=b217309e0b56c7d9f69e6c80cf01b313489b1fd4;hp=d46fdbe9563676fb4d68a3ed096fd2ba1a826b2e;p=bertos.git Add the wdt avr cpu specific. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1950 38d2e660-2303-0410-9eaa-f027e97ec537 --- 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 */