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