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