Move watchdog function platform depend to specific cpu directory.
[bertos.git] / bertos / drv / wdt.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \version $Id$
34  *
35  * \author Bernie Innocenti <bernie@codewiz.org>
36  *
37  * \brief Watchdog interface
38  */
39
40 #ifndef DRV_WDT_H
41 #define DRV_WDT_H
42
43 #include "cfg/cfg_wdt.h"
44 #include "cfg/cfg_arch.h"
45
46 #include <cfg/compiler.h> // INLINE
47
48 /* Configury sanity check */
49 #if !defined(CONFIG_WATCHDOG) || (CONFIG_WATCHDOG != 0 && CONFIG_WATCHDOG != 1)
50         #error CONFIG_WATCHDOG must be defined to either 0 or 1
51 #endif
52
53 #if OS_HOSTED || !CONFIG_WATCHDOG
54         #include <cpu/detect.h>
55         #include <cfg/os.h>
56
57         #if OS_QT
58                         #include <QtGui/QApplication>
59         #elif OS_POSIX
60                 #include <sys/select.h>
61         #else
62                 #error unknown CPU
63         #endif
64 #endif /* CONFIG_WATCHDOG */
65
66
67 #if OS_HOSTED || !CONFIG_WATCHDOG
68         /**
69          * Reset the watchdog timer.
70          */
71         INLINE void wdt_reset(void)
72         {
73         #if CONFIG_WATCHDOG
74                 #if OS_QT
75                         // Let Qt handle events
76                         ASSERT(qApp);
77                         qApp->processEvents();
78                 #elif OS_POSIX
79                         static struct timeval tv = { 0, 0 };
80                         select(0, NULL, NULL, NULL, &tv);
81                 #endif
82         #endif /* CONFIG_WATCHDOG */
83         }
84
85         /**
86          * Set watchdog timer timeout.
87          *
88          * \param timeout  0: 16.3ms, 7: 2.1s
89          */
90         INLINE void wdt_init(uint8_t timeout)
91         {
92         #if CONFIG_WATCHDOG
93                 #if OS_QT
94                         // Create a dummy QApplication object
95                         if (!qApp)
96                         {
97                                 int argc;
98                                 new QApplication(argc, (char **)NULL);
99                         }
100                         (void)timeout;
101                 #elif OS_POSIX
102                         (void)timeout; // NOP
103                 #else
104                         #error unknown CPU
105                 #endif
106         #endif /* CONFIG_WATCHDOG */
107                 (void)timeout;
108         }
109
110         INLINE void wdt_start(void)
111         {
112 #if CONFIG_WATCHDOG
113                 #if OS_QT
114                         // NOP
115                 #elif OS_POSIX
116                         // NOP
117                 #else
118                         #error unknown CPU
119                 #endif
120 #endif /* CONFIG_WATCHDOG */
121         }
122
123         INLINE void wdt_stop(void)
124         {
125 #if CONFIG_WATCHDOG
126                 #if OS_QT
127                         // NOP
128                 #elif OS_POSIX
129                         // NOP
130                 #else
131                         #error unknown CPU
132                 #endif
133 #endif /* CONFIG_WATCHDOG */
134         }
135 #endif /* OS_HOSTED || !CONFIG_WATCHDOG */
136
137 #endif /* DRV_WDT_H */