From bbc33efb70a0062b36cc415452922e7ba69c748f Mon Sep 17 00:00:00 2001 From: bernie Date: Sun, 27 Nov 2005 03:58:40 +0000 Subject: [PATCH] Add POSIX timer emulator. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@455 38d2e660-2303-0410-9eaa-f027e97ec537 --- drv/timer_posix.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ drv/timer_posix.h | 44 +++++++++++++++++++++++++++++++++ drv/timer_test.c | 4 +++ drv/wdt.h | 17 ++++++++++++- 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100755 drv/timer_posix.c create mode 100755 drv/timer_posix.h diff --git a/drv/timer_posix.c b/drv/timer_posix.c new file mode 100755 index 00000000..9814dc24 --- /dev/null +++ b/drv/timer_posix.c @@ -0,0 +1,62 @@ +/*! + * \file + * + * + * \version $Id$ + * + * \author Bernardo Innocenti + * + * \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 // hptime.t +#include + +#include // sigaction() +#include // setitimer() +#include // 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 index 00000000..cd9ec84d --- /dev/null +++ b/drv/timer_posix.h @@ -0,0 +1,44 @@ +/*! + * \file + * + * + * \version $Id$ + * + * \author Bernardo Innocenti + * + * \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 + +/// 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 */ diff --git a/drv/timer_test.c b/drv/timer_test.c index cc15f11c..bfc712ad 100755 --- a/drv/timer_test.c +++ b/drv/timer_test.c @@ -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) { diff --git a/drv/wdt.h b/drv/wdt.h index 29780607..9f57618f 100755 --- 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 + #elif OS_POSIX + #include #elif CPU_AVR #include #include // 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); -- 2.25.1