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