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_POSIX
00081             static struct timeval tv = { 0, 0 };
00082             select(0, NULL, NULL, NULL, &tv);
00083         #endif
00084     #endif /* CONFIG_WATCHDOG */
00085     }
00086 
00094     INLINE void wdt_start(uint32_t timeout)
00095     {
00096     #if CONFIG_WATCHDOG
00097         #if OS_QT
00098             // Create a dummy QApplication object
00099             if (!qApp)
00100             {
00101                 int argc;
00102                 new QApplication(argc, (char **)NULL);
00103             }
00104             (void)timeout;
00105         #elif OS_POSIX
00106             (void)timeout; // NOP
00107         #endif
00108     #endif /* CONFIG_WATCHDOG */
00109         (void)timeout; // NOP
00110     }
00111 
00112     INLINE void wdt_stop(void)
00113     {
00114     #if CONFIG_WATCHDOG
00115         #if OS_QT
00116             // NOP
00117         #elif OS_POSIX
00118             // NOP
00119         #else
00120             #error unknown CPU
00121         #endif
00122     #endif /* CONFIG_WATCHDOG */
00123     }
00124 #endif /* OS_HOSTED || !CONFIG_WATCHDOG */
00125 
00126 #endif /* DRV_WDT_H */