wdt.h

Go to the documentation of this file.
00001 
00044 #ifndef DRV_WDT_H
00045 #define DRV_WDT_H
00046 
00047 #include "cfg/cfg_wdt.h"
00048 
00049 #include <cfg/compiler.h> // INLINE
00050 
00051 /* Configury sanity check */
00052 #if !defined(CONFIG_WATCHDOG) || (CONFIG_WATCHDOG != 0 && CONFIG_WATCHDOG != 1)
00053     #error CONFIG_WATCHDOG must be defined to either 0 or 1
00054 #endif
00055 
00056 #if OS_HOSTED
00057     #include <cpu/detect.h>
00058     #include <cfg/os.h>
00059 
00060     #if OS_QT
00061             #include <QtGui/QApplication>
00062     #elif OS_POSIX
00063         #include <sys/select.h>
00064     #else
00065         #error unknown CPU
00066     #endif
00067 #elif CONFIG_WATCHDOG
00068     #include CPU_HEADER(wdt)
00069 #endif /* CONFIG_WATCHDOG */
00070 
00071 
00072 #if OS_HOSTED || !CONFIG_WATCHDOG
00073 
00077     INLINE void wdt_reset(void)
00078     {
00079     #if CONFIG_WATCHDOG
00080         #if OS_QT
00081             // Let Qt handle events
00082             ASSERT(qApp);
00083             qApp->processEvents();
00084         #elif OS_POSIX
00085             static struct timeval tv = { 0, 0 };
00086             select(0, NULL, NULL, NULL, &tv);
00087         #endif
00088     #endif /* CONFIG_WATCHDOG */
00089     }
00090 
00098     INLINE void wdt_start(uint32_t timeout)
00099     {
00100     #if CONFIG_WATCHDOG
00101         #if OS_QT
00102             // Create a dummy QApplication object
00103             if (!qApp)
00104             {
00105                 int argc;
00106                 new QApplication(argc, (char **)NULL);
00107             }
00108             (void)timeout;
00109         #elif OS_POSIX
00110             (void)timeout; // NOP
00111         #endif
00112     #endif /* CONFIG_WATCHDOG */
00113         (void)timeout; // NOP
00114     }
00115 
00116     INLINE void wdt_stop(void)
00117     {
00118     #if CONFIG_WATCHDOG
00119         #if OS_QT
00120             // NOP
00121         #elif OS_POSIX
00122             // NOP
00123         #else
00124             #error unknown CPU
00125         #endif
00126     #endif /* CONFIG_WATCHDOG */
00127     }
00128 #endif /* OS_HOSTED || !CONFIG_WATCHDOG */
00129 
00130 #endif /* DRV_WDT_H */