Add POSIX timer emulator.
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 27 Nov 2005 03:58:40 +0000 (03:58 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 27 Nov 2005 03:58:40 +0000 (03:58 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@455 38d2e660-2303-0410-9eaa-f027e97ec537

drv/timer_posix.c [new file with mode: 0755]
drv/timer_posix.h [new file with mode: 0755]
drv/timer_test.c
drv/wdt.h

diff --git a/drv/timer_posix.c b/drv/timer_posix.c
new file mode 100755 (executable)
index 0000000..9814dc2
--- /dev/null
@@ -0,0 +1,62 @@
+/*!
+ * \file
+ * <!--
+ * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
+ * This file is part of DevLib - See README.devlib for information.
+ * -->
+ *
+ * \version $Id$
+ *
+ * \author Bernardo Innocenti <bernie@develer.com>
+ *
+ * \brief Low-level timer module for Qt emulator (implementation).
+ */
+
+/*#*
+ *#* $Log$
+ *#* Revision 1.1  2005/11/27 03:58:18  bernie
+ *#* Add POSIX timer emulator.
+ *#*
+ *#* Revision 1.1  2005/11/27 03:06:36  bernie
+ *#* Qt timer emulation.
+ *#*
+ *#*/
+
+#include <cfg/compiler.h> // hptime.t
+#include <os/hptime.h>
+
+#include <signal.h>       // sigaction()
+#include <sys/time.h>     // setitimer()
+#include <string.h>       // memset()
+
+
+// Forward declaration for the user interrupt server routine.
+void timer_isr(int);
+
+/// HW dependent timer initialization.
+extern "C" static void timer_hw_init(void)
+{
+       struct sigaction sa;
+       memset(&sa, 0, sizeof(sa));
+
+       // Setup interrupt callback
+       sa.sa_handler = timer_isr;
+       sigemptyset(&sa.sa_mask);
+       sigaddset(&sa.sa_mask, SIGALRM);
+       sa.sa_flags = SA_RESTART;
+       sigaction(SIGALRM, &sa, NULL);
+
+       // Setup POSIX realtime timer to interrupt every 10ms.
+       static struct itimerval itv =
+       {
+               { 0, 1000 }, /* it_interval */
+               { 0, 1000 }  /* it_value */
+       };
+       setitimer(ITIMER_REAL, &itv, NULL);
+}
+
+extern "C" INLINE hptime_t timer_hw_hpread(void)
+{
+       return hptime_get();
+}
+
diff --git a/drv/timer_posix.h b/drv/timer_posix.h
new file mode 100755 (executable)
index 0000000..cd9ec84
--- /dev/null
@@ -0,0 +1,44 @@
+/*!
+ * \file
+ * <!--
+ * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
+ * This file is part of DevLib - See README.devlib for information.
+ * -->
+ *
+ * \version $Id$
+ *
+ * \author Bernardo Innocenti <bernie@develer.com>
+ *
+ * \brief Low-level timer module for POSIX systems (interface).
+ */
+
+/*#*
+ *#* $Log$
+ *#* Revision 1.1  2005/11/27 03:58:18  bernie
+ *#* Add POSIX timer emulator.
+ *#*
+ *#* Revision 1.1  2005/11/27 03:06:36  bernie
+ *#* Qt timer emulation.
+ *#*
+ *#*/
+#ifndef DRV_TIMER_POSIX_H
+#define DRV_TIMER_POSIX_H
+
+// HW dependent timer initialization
+
+#define DEFINE_TIMER_ISR     void timer_isr(int)
+#define TIMER_TICKS_PER_MSEC 1
+#define TIMER_HW_CNT         (1<<31) /* We assume 32bit integers here */
+
+/// Type of time expressed in ticks of the hardware high-precision timer.
+//typedef unsigned int hptime_t;
+#include <os/hptime.h>
+
+/// Frequency of the hardware high-precision timer.
+#define TIMER_HW_HPTICKS_PER_SEC  HPTIME_TICKS_PER_SECOND
+
+/// Not needed.
+#define timer_hw_irq() do {} while (0)
+
+
+#endif /* DRV_TIMER_QT_H */
index cc15f11c8a88cab5d320fb53f7720fd660f4b924..bfc712ad2647766f64e91ccf49923510d3d6d288 100755 (executable)
@@ -13,6 +13,9 @@
 
 /*#*
  *#* $Log$
+ *#* Revision 1.2  2005/11/27 03:58:18  bernie
+ *#* Add POSIX timer emulator.
+ *#*
  *#* Revision 1.1  2005/11/27 03:04:08  bernie
  *#* Move test code to timer_test.c; Add OS_HOSTED support.
  *#*
@@ -20,6 +23,7 @@
 
 #include "timer.c"
 #include "mware/event.c"
+#include "os/hptime.c"
 
 static void timer_test_constants(void)
 {
index 29780607fb58cd840e59154c9cc55f416de723ac..9f57618f663b26b46be162379a050e141ffb7839 100755 (executable)
--- a/drv/wdt.h
+++ b/drv/wdt.h
@@ -14,6 +14,9 @@
 
 /*#*
  *#* $Log$
+ *#* Revision 1.7  2005/11/27 03:58:40  bernie
+ *#* Add POSIX timer emulator.
+ *#*
  *#* Revision 1.6  2005/11/27 03:03:08  bernie
  *#* Add Qt support hack.
  *#*
@@ -50,6 +53,8 @@
 
        #if OS_QT
                #include <qapplication.h>
+       #elif OS_POSIX
+               #include <sys/select.h>
        #elif CPU_AVR
                #include <avr/io.h>
                #include <cfg/macros.h> // BV()
@@ -68,6 +73,9 @@ INLINE void wdt_reset(void)
                // Let Qt handle events
                ASSERT(qApp);
                qApp->processEvents();
+       #elif OS_POSIX
+               static struct timeval tv = { 0, 0 };
+               select(0, NULL, NULL, NULL, &tv);
        #elif CPU_AVR
                __asm__ __volatile__ ("wdr");
        #else
@@ -85,12 +93,15 @@ INLINE void wdt_init(uint8_t timeout)
 {
 #if CONFIG_WATCHDOG
        #if OS_QT
-               // create a dummy QApplication object
+               // Create a dummy QApplication object
                if (!qApp)
                {
                        int argc;
                        new QApplication(argc, (char **)NULL);
                }
+               (void)timeout;
+       #elif OS_POSIX
+               (void)timeout; // NOP
        #elif CPU_AVR
                WDTCR |= BV(WDCE) | BV(WDE);
                WDTCR = timeout;
@@ -107,6 +118,8 @@ INLINE void wdt_start(void)
 #if CONFIG_WATCHDOG
        #if OS_QT
                // NOP
+       #elif OS_POSIX
+               // NOP
        #elif CPU_AVR
                WDTCR |= BV(WDE);
        #else
@@ -120,6 +133,8 @@ INLINE void wdt_stop(void)
 #if CONFIG_WATCHDOG
        #if OS_QT
                // NOP
+       #elif OS_POSIX
+               // NOP
        #elif CPU_AVR
                WDTCR |= BV(WDCE) | BV(WDE);
                WDTCR &= ~BV(WDE);