New DevLib module.
[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.1  2004/10/26 08:34:47  bernie
18  *#* New DevLib module.
19  *#*
20  *#*/
21 #ifndef DRV_WDT_H
22 #define DRV_WDT_H
23
24 #include <avr/io.h>
25 #include <compiler.h>
26 #include <cpu.h>
27 #include <macros.h> // BV()
28
29 /*!
30  * Reset the watchdog timer.
31  */
32 INLINE void wdt_reset(void)
33 {
34         __asm__ __volatile__ ("wdr");
35 }
36
37 /*!
38  * Set watchdog timer timeout.
39  *
40  * \param timeout  0: 16.3ms, 7: 2.1s
41  */
42 INLINE void wdt_init(uint8_t timeout)
43 {
44 #if CPU_AVR
45         WDTCR |= BV(WDCE) | BV(WDE);
46         WDTCR = timeout;
47 #else
48         #error unknown CPU
49 #endif
50 }
51
52 INLINE void wdt_start(void)
53 {
54 #if CPU_AVR
55         WDTCR |= BV(WDE);
56 #else
57         #error unknown CPU
58 #endif
59 }
60
61 INLINE void wdt_stop(void)
62 {
63 #if CPU_AVR
64         WDTCR |= BV(WDCE) | BV(WDE);
65         WDTCR &= ~BV(WDE);
66 #else
67         #error unknown CPU
68 #endif
69 }
70
71 #endif /* DRV_WDT_H */