--- /dev/null
+/*!
+ * \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();
+}
+
--- /dev/null
+/*!
+ * \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 */
/*#*
*#* $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.
*#*
#include "timer.c"
#include "mware/event.c"
+#include "os/hptime.c"
static void timer_test_constants(void)
{
/*#*
*#* $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.
*#*
#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()
// 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
{
#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;
#if CONFIG_WATCHDOG
#if OS_QT
// NOP
+ #elif OS_POSIX
+ // NOP
#elif CPU_AVR
WDTCR |= BV(WDE);
#else
#if CONFIG_WATCHDOG
#if OS_QT
// NOP
+ #elif OS_POSIX
+ // NOP
#elif CPU_AVR
WDTCR |= BV(WDCE) | BV(WDE);
WDTCR &= ~BV(WDE);