From f706854f93d5168bb36ea25d66a4d5b0d60c4ac2 Mon Sep 17 00:00:00 2001 From: bernie Date: Sun, 27 Nov 2005 03:06:36 +0000 Subject: [PATCH] Qt timer emulation. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@451 38d2e660-2303-0410-9eaa-f027e97ec537 --- drv/timer_qt.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ drv/timer_qt.h | 40 ++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100755 drv/timer_qt.c create mode 100755 drv/timer_qt.h diff --git a/drv/timer_qt.c b/drv/timer_qt.c new file mode 100755 index 00000000..a9e38be6 --- /dev/null +++ b/drv/timer_qt.c @@ -0,0 +1,110 @@ +/*! + * \file + * + * + * \version $Id$ + * + * \author Bernardo Innocenti + * + * \brief Low-level timer module for Qt emulator (implementation). + */ + +/*#* + *#* $Log$ + *#* Revision 1.1 2005/11/27 03:06:36 bernie + *#* Qt timer emulation. + *#* + *#*/ + +#include /* hptime.t */ + +// Qt headers +#include +#include + + +// The user interrupt server routine +void timer_isr(void); + + +/** + * Singleton class for Qt-based hardware timer emulation. + */ +class EmulTimer : public QObject +{ +private: + Q_OBJECT; + + /// System timer (counts ms since application startup) + QTime system_time; + + /// The 1ms "hardware" tick counter. + QTimer timer; + + /** + * We deliberately don't use RAII because the real hardware + * we're simulating needs to be initialized manually. + */ + bool initialized; + + /// Private ctor (singleton) + EmulTimer() : initialized(false) { } + +public: + /// Return singleton instance + static EmulTimer &instance() + { + static EmulTimer et; + return et; + } + + /// Start timer emulator. + void init() + { + // Timer initialized twice? + ASSERT(!initialized); + + // Record initial time + system_time.start(); + + // Activate 1ms timer interrupt + timer.connect(&timer, SIGNAL(timeout()), this, SLOT(timerInterrupt())); + timer.start(1); + + initialized = true; + } + + /// Return current time in high-precision format. + hptime_t hpread() + { + ASSERT(initialized); + return system_time.elapsed(); + } + +public slots: + void timerInterrupt(void) + { + // Just call user interrupt server, timer restarts automatically. + timer_isr(); + } + +}; + +#include "timer_qt_moc.cpp" + + +/// HW dependent timer initialization. +extern "C" static void timer_hw_init(void) +{ + // Kick EmulTimer initialization + EmulTimer::instance().init(); +} + +extern "C" INLINE hptime_t timer_hw_hpread(void) +{ + return EmulTimer::instance().hpread(); +} + diff --git a/drv/timer_qt.h b/drv/timer_qt.h new file mode 100755 index 00000000..88fb71ea --- /dev/null +++ b/drv/timer_qt.h @@ -0,0 +1,40 @@ +/*! + * \file + * + * + * \version $Id$ + * + * \author Bernardo Innocenti + * + * \brief Low-level timer module for AVR (interface). + */ + +/*#* + *#* $Log$ + *#* Revision 1.1 2005/11/27 03:06:36 bernie + *#* Qt timer emulation. + *#* + *#*/ +#ifndef DRV_TIMER_QT_H +#define DRV_TIMER_QT_H + +// HW dependent timer initialization + +#define DEFINE_TIMER_ISR void timer_isr(void) +#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; + +/// Frequency of the hardware high-precision timer. +#define TIMER_HW_HPTICKS_PER_SEC 1000 + +/// Not needed, IRQ timer flag cleared automatically. +#define timer_hw_irq() do {} while (0) + + +#endif /* DRV_TIMER_QT_H */ -- 2.25.1