4 * This file is part of BeRTOS.
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.
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.
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
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.
29 * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
35 * \author Bernardo Innocenti <bernie@develer.com>
37 * \brief Watchdog interface
42 *#* Revision 1.12 2007/06/07 14:35:12 batt
43 *#* Merge from project_ks.
45 *#* Revision 1.11 2006/07/19 12:56:26 bernie
46 *#* Convert to new Doxygen style.
48 *#* Revision 1.10 2006/05/18 00:38:42 bernie
49 *#* Work around missing ARCH_FREERTOS symbol.
51 *#* Revision 1.9 2006/03/22 09:49:09 bernie
52 *#* Add FreeRTOS support.
54 *#* Revision 1.8 2006/02/20 02:02:29 bernie
57 *#* Revision 1.7 2005/11/27 03:58:40 bernie
58 *#* Add POSIX timer emulator.
60 *#* Revision 1.6 2005/11/27 03:03:08 bernie
61 *#* Add Qt support hack.
63 *#* Revision 1.5 2005/11/04 16:20:02 bernie
64 *#* Fix reference to README.devlib in header.
66 *#* Revision 1.4 2005/04/12 01:37:17 bernie
67 *#* Prevent warning when watchdog is disabled.
69 *#* Revision 1.3 2005/04/11 19:10:28 bernie
70 *#* Include top-level headers from cfg/ subdir.
72 *#* Revision 1.2 2004/11/16 21:02:07 bernie
73 *#* Make driver optional; mark AVR specific parts as such.
75 *#* Revision 1.1 2004/10/26 08:34:47 bernie
76 *#* New DevLib module.
82 #include <appconfig.h>
83 #include <cfg/compiler.h> // INLINE
84 #include <cfg/arch_config.h>
86 /* Configury sanity check */
87 #if !defined(CONFIG_WATCHDOG) || (CONFIG_WATCHDOG != 0 && CONFIG_WATCHDOG != 1)
88 #error CONFIG_WATCHDOG must be defined to either 0 or 1
97 #include <qapplication.h>
99 #include <QtGui/QApplication>
102 #include <sys/select.h>
105 #include <cfg/macros.h> // BV()
106 #if CPU_AVR_ATMEGA1281 // Name is different in atmega1281
109 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
110 #include <task.h> /* taskYIELD() */
114 #endif /* CONFIG_WATCHDOG */
117 * Reset the watchdog timer.
119 INLINE void wdt_reset(void)
123 // Let Qt handle events
125 qApp->processEvents();
127 static struct timeval tv = { 0, 0 };
128 select(0, NULL, NULL, NULL, &tv);
129 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
132 __asm__ __volatile__ ("wdr");
136 #endif /* CONFIG_WATCHDOG */
140 * Set watchdog timer timeout.
142 * \param timeout 0: 16.3ms, 7: 2.1s
144 INLINE void wdt_init(uint8_t timeout)
148 // Create a dummy QApplication object
152 new QApplication(argc, (char **)NULL);
156 (void)timeout; // NOP
157 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
160 WDTCR |= BV(WDCE) | BV(WDE);
167 #endif /* CONFIG_WATCHDOG */
170 INLINE void wdt_start(void)
177 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
184 #endif /* CONFIG_WATCHDOG */
187 INLINE void wdt_stop(void)
194 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
197 WDTCR |= BV(WDCE) | BV(WDE);
202 #endif /* CONFIG_WATCHDOG */
205 #endif /* DRV_WDT_H */