4 * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
10 * \author Bernardo Innocenti <bernie@develer.com>
12 * \brief Low-level timer module for Qt emulator (implementation).
17 *#* Revision 1.3 2006/02/21 21:28:02 bernie
18 *#* New time handling based on TIMER_TICKS_PER_SEC to support slow timers with ticks longer than 1ms.
20 *#* Revision 1.2 2006/02/20 02:01:35 bernie
23 *#* Revision 1.1 2005/11/27 03:06:36 bernie
24 *#* Qt timer emulation.
28 #include <cfg/compiler.h> /* hptime.t */
32 #include <qdatetime.h>
35 #include <QtCore/QDateTime>
36 #include <QtCore/QTimer>
40 // The user interrupt server routine
45 * Singleton class for Qt-based hardware timer emulation.
47 class EmulTimer : public QObject
52 /// System timer (counts ms since application startup)
55 /// The 1ms "hardware" tick counter.
59 * We deliberately don't use RAII because the real hardware
60 * we're simulating needs to be initialized manually.
64 /// Private ctor (singleton)
65 EmulTimer() : initialized(false) { }
68 /// Return singleton instance
69 static EmulTimer &instance()
75 /// Start timer emulator.
78 // Timer initialized twice?
81 // Record initial time
84 // Activate timer interrupt
85 timer.connect(&timer, SIGNAL(timeout()), this, SLOT(timerInterrupt()));
86 timer.start(1000 / TIMER_TICKS_PER_SEC);
91 /// Return current time in high-precision format.
95 return system_time.elapsed();
99 void timerInterrupt(void)
101 // Just call user interrupt server, timer restarts automatically.
107 #include "timer_qt_moc.cpp"
110 /// HW dependent timer initialization.
111 extern "C" static void timer_hw_init(void)
113 // Kick EmulTimer initialization
114 EmulTimer::instance().init();
117 extern "C" INLINE hptime_t timer_hw_hpread(void)
119 return EmulTimer::instance().hpread();