Prevent warning when watchdog is disabled.
[bertos.git] / drv / wdt.h
1 /*!
2  * \file
3  * <!--
4  * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5  * This file is part of DevLib - See devlib/README for information.
6  * -->
7  *
8  * \version $Id$
9  *
10  * \author Bernardo Innocenti <bernie@develer.com>
11  *
12  * \brief Watchdog interface
13  */
14
15 /*#*
16  *#* $Log$
17  *#* Revision 1.4  2005/04/12 01:37:17  bernie
18  *#* Prevent warning when watchdog is disabled.
19  *#*
20  *#* Revision 1.3  2005/04/11 19:10:28  bernie
21  *#* Include top-level headers from cfg/ subdir.
22  *#*
23  *#* Revision 1.2  2004/11/16 21:02:07  bernie
24  *#* Make driver optional; mark AVR specific parts as such.
25  *#*
26  *#* Revision 1.1  2004/10/26 08:34:47  bernie
27  *#* New DevLib module.
28  *#*
29  *#*/
30 #ifndef DRV_WDT_H
31 #define DRV_WDT_H
32
33 #include <cfg/config.h>
34 #include <cfg/compiler.h> // INLINE
35
36 /* Configury sanity check */
37 #if !defined(CONFIG_WATCHDOG) || (CONFIG_WATCHDOG != 0 && CONFIG_WATCHDOG != 1)
38         #error CONFIG_WATCHDOG must be defined to either 0 or 1
39 #endif
40
41 #if CONFIG_WATCHDOG
42         #include <cfg/cpu.h>
43
44         #if CPU_AVR
45                 #include <avr/io.h>
46                 #include <cfg/macros.h> // BV()
47         #else
48                 #error unknown CPU
49         #endif
50 #endif /* CONFIG_WATCHDOG */
51
52 /*!
53  * Reset the watchdog timer.
54  */
55 INLINE void wdt_reset(void)
56 {
57 #if CONFIG_WATCHDOG
58         #if CPU_AVR
59                 __asm__ __volatile__ ("wdr");
60         #else
61                 #error unknown CPU
62         #endif
63 #endif /* CONFIG_WATCHDOG */
64 }
65
66 /*!
67  * Set watchdog timer timeout.
68  *
69  * \param timeout  0: 16.3ms, 7: 2.1s
70  */
71 INLINE void wdt_init(uint8_t timeout)
72 {
73 #if CONFIG_WATCHDOG
74         #if CPU_AVR
75                 WDTCR |= BV(WDCE) | BV(WDE);
76                 WDTCR = timeout;
77         #else
78                 #error unknown CPU
79         #endif
80 #else
81         (void)timeout;
82 #endif /* CONFIG_WATCHDOG */
83 }
84
85 INLINE void wdt_start(void)
86 {
87 #if CONFIG_WATCHDOG
88         #if CPU_AVR
89                 WDTCR |= BV(WDE);
90         #else
91                 #error unknown CPU
92         #endif
93 #endif /* CONFIG_WATCHDOG */
94 }
95
96 INLINE void wdt_stop(void)
97 {
98 #if CONFIG_WATCHDOG
99         #if CPU_AVR
100                 WDTCR |= BV(WDCE) | BV(WDE);
101                 WDTCR &= ~BV(WDE);
102         #else
103                 #error unknown CPU
104         #endif
105 #endif /* CONFIG_WATCHDOG */
106 }
107
108 #endif /* DRV_WDT_H */