X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcpu%2Favr%2Fdrv%2Fwdt_avr.h;h=21f5f9b13f07b8f8b784896c9b29e08bf286b160;hb=2b387e02ffd797dc8c68e072d29e445821189559;hp=109390eb0c93108eeae83b918798153947ebf6c3;hpb=b217309e0b56c7d9f69e6c80cf01b313489b1fd4;p=bertos.git diff --git a/bertos/cpu/avr/drv/wdt_avr.h b/bertos/cpu/avr/drv/wdt_avr.h index 109390eb..21f5f9b1 100644 --- a/bertos/cpu/avr/drv/wdt_avr.h +++ b/bertos/cpu/avr/drv/wdt_avr.h @@ -32,6 +32,10 @@ * * \brief Watchdog interface for AVR architecture. * + * \note The avr-libc already provide an api to manage the watchdog on AVR architecture. + * In avr-libc are also available several constants used to set the timeout value + * (see documentation for more detail). + * * \version $Id$ * * \author Daniele Basile @@ -46,54 +50,47 @@ #include // INLINE #include - -#if CPU_AVR_ATMEGA1281 - #define WDT_CRTL_REG WDTCSR -#else - #define WDT_CRTL_REG WDTCR -#endif +#include /** * Reset the watchdog timer. + * + * This functions is already defind in avr-libc. */ -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; -} +// void wdt_reset(void) /** - * Set watchdog timeout. + * Start the watchdog timer that fire at the select + * timeout. + * + * \param _timeout you can use the macro that are defineded in + * avr/wdt.h. + * + * (from avr libc documentation) + * WDTO_15MS + * WDTO_30MS + * WDTO_60MS + * WDTO_120MS + * WDTO_250MS + * WDTO_500MS + * WDTO_1S + * WDTO_2S + * WDTO_4S + * WDTO_8S */ -INLINE void wdt_setTimeout(uint32_t timeout) +INLINE void wdt_start(uint32_t _timeout) { - IRQ_DISABLE; - wdt_reset(); - WDT_CRTL_REG |= BV(WDCE) | BV(WDE); - WDT_CRTL_REG = timeout; - IRQ_ENABLE; + uint8_t timeout = _timeout; + + wdt_enable(timeout); } /** - * Init watchdog timer. + * Stop watchdog timer. */ -INLINE void wdt_init(void) +INLINE void wdt_stop(void) { - WDT_CRTL_REG |= BV(WDCE) | BV(WDE); + wdt_disable(); }