From: asterix Date: Tue, 2 Dec 2008 13:41:22 +0000 (+0000) Subject: Use avr libc for wdt cpu specific. Comply the wdt interface function. Clean code. X-Git-Tag: 2.1.0~729 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=bd646534b07bbf3c22a4d2ec01d800b0ad718aa6;p=bertos.git Use avr libc for wdt cpu specific. Comply the wdt interface function. Clean code. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1953 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/avr/drv/wdt_avr.h b/bertos/cpu/avr/drv/wdt_avr.h index 109390eb..0edb5d16 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 provvide the api to manange + * the watchdog on AVR architecture. In LibC also define several + * macro to set the timeout value (see documentation for more detail). + * * \version $Id$ * * \author Daniele Basile @@ -46,54 +50,48 @@ #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 definded to avr libc, + * we use it. */ -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(); } diff --git a/bertos/drv/wdt.h b/bertos/drv/wdt.h index 0cb221c3..6e2cde30 100644 --- a/bertos/drv/wdt.h +++ b/bertos/drv/wdt.h @@ -66,8 +66,8 @@ #endif /* CONFIG_WATCHDOG */ - #if OS_HOSTED || !CONFIG_WATCHDOG + /** * Reset the watchdog timer. */ @@ -86,11 +86,13 @@ } /** - * Set watchdog timer timeout. + * Start the watchdog timer that fire at the select + * timeout. * - * \param timeout 0: 16.3ms, 7: 2.1s + * \param timeout, this value is target dependant. + * See the target documentation for more detail. */ - INLINE void wdt_init(uint8_t timeout) + INLINE void wdt_start(uint32_t timeout) { #if CONFIG_WATCHDOG #if OS_QT @@ -103,29 +105,14 @@ (void)timeout; #elif OS_POSIX (void)timeout; // NOP - #else - #error unknown CPU #endif #endif /* CONFIG_WATCHDOG */ - (void)timeout; - } - - INLINE void wdt_start(void) - { -#if CONFIG_WATCHDOG - #if OS_QT - // NOP - #elif OS_POSIX - // NOP - #else - #error unknown CPU - #endif -#endif /* CONFIG_WATCHDOG */ + (void)timeout; // NOP } INLINE void wdt_stop(void) { -#if CONFIG_WATCHDOG + #if CONFIG_WATCHDOG #if OS_QT // NOP #elif OS_POSIX @@ -133,7 +120,7 @@ #else #error unknown CPU #endif -#endif /* CONFIG_WATCHDOG */ + #endif /* CONFIG_WATCHDOG */ } #endif /* OS_HOSTED || !CONFIG_WATCHDOG */