wdt.h
Go to the documentation of this file.00001
00040 #ifndef DRV_WDT_H
00041 #define DRV_WDT_H
00042
00043 #include <appconfig.h>
00044 #include <cfg/compiler.h>
00045 #include <cfg/arch_config.h>
00046
00047
00048 #if !defined(CONFIG_WATCHDOG) || (CONFIG_WATCHDOG != 0 && CONFIG_WATCHDOG != 1)
00049 #error CONFIG_WATCHDOG must be defined to either 0 or 1
00050 #endif
00051
00052 #if CONFIG_WATCHDOG
00053 #include <cpu/detect.h>
00054 #include <cfg/os.h>
00055
00056 #if OS_QT
00057 #if _QT < 4
00058 #include <qapplication.h>
00059 #else
00060 #include <QtGui/QApplication>
00061 #endif
00062 #elif OS_POSIX
00063 #include <sys/select.h>
00064 #elif CPU_AVR
00065 #include <avr/io.h>
00066 #include <cfg/macros.h>
00067 #if CPU_AVR_ATMEGA1281 // Name is different in atmega1281
00068 #define WDTCR WDTCSR
00069 #endif
00070 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
00071 #include <task.h>
00072 #else
00073 #error unknown CPU
00074 #endif
00075 #endif
00076
00080 INLINE void wdt_reset(void)
00081 {
00082 #if CONFIG_WATCHDOG
00083 #if OS_QT
00084
00085 ASSERT(qApp);
00086 qApp->processEvents();
00087 #elif OS_POSIX
00088 static struct timeval tv = { 0, 0 };
00089 select(0, NULL, NULL, NULL, &tv);
00090 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
00091 vTaskDelay(1);
00092 #elif CPU_AVR
00093 __asm__ __volatile__ ("wdr");
00094 #else
00095 #error unknown CPU
00096 #endif
00097 #endif
00098 }
00099
00105 INLINE void wdt_init(uint8_t timeout)
00106 {
00107 #if CONFIG_WATCHDOG
00108 #if OS_QT
00109
00110 if (!qApp)
00111 {
00112 int argc;
00113 new QApplication(argc, (char **)NULL);
00114 }
00115 (void)timeout;
00116 #elif OS_POSIX
00117 (void)timeout;
00118 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
00119
00120 #elif CPU_AVR
00121 WDTCR |= BV(WDCE) | BV(WDE);
00122 WDTCR = timeout;
00123 #else
00124 #error unknown CPU
00125 #endif
00126 #else
00127 (void)timeout;
00128 #endif
00129 }
00130
00131 INLINE void wdt_start(void)
00132 {
00133 #if CONFIG_WATCHDOG
00134 #if OS_QT
00135
00136 #elif OS_POSIX
00137
00138 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
00139
00140 #elif CPU_AVR
00141 WDTCR |= BV(WDE);
00142 #else
00143 #error unknown CPU
00144 #endif
00145 #endif
00146 }
00147
00148 INLINE void wdt_stop(void)
00149 {
00150 #if CONFIG_WATCHDOG
00151 #if OS_QT
00152
00153 #elif OS_POSIX
00154
00155 #elif defined(ARCH_FREERTOS) && (ARCH & ARCH_FREERTOS)
00156
00157 #elif CPU_AVR
00158 WDTCR |= BV(WDCE) | BV(WDE);
00159 WDTCR &= ~BV(WDE);
00160 #else
00161 #error unknown CPU
00162 #endif
00163 #endif
00164 }
00165
00166 #endif