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.1 2005/11/27 03:06:36 bernie
18 *#* Qt timer emulation.
22 #include <cfg/compiler.h> /* hptime.t */
25 #include <qdatetime.h>
29 // The user interrupt server routine
34 * Singleton class for Qt-based hardware timer emulation.
36 class EmulTimer : public QObject
41 /// System timer (counts ms since application startup)
44 /// The 1ms "hardware" tick counter.
48 * We deliberately don't use RAII because the real hardware
49 * we're simulating needs to be initialized manually.
53 /// Private ctor (singleton)
54 EmulTimer() : initialized(false) { }
57 /// Return singleton instance
58 static EmulTimer &instance()
64 /// Start timer emulator.
67 // Timer initialized twice?
70 // Record initial time
73 // Activate 1ms timer interrupt
74 timer.connect(&timer, SIGNAL(timeout()), this, SLOT(timerInterrupt()));
80 /// Return current time in high-precision format.
84 return system_time.elapsed();
88 void timerInterrupt(void)
90 // Just call user interrupt server, timer restarts automatically.
96 #include "timer_qt_moc.cpp"
99 /// HW dependent timer initialization.
100 extern "C" static void timer_hw_init(void)
102 // Kick EmulTimer initialization
103 EmulTimer::instance().init();
106 extern "C" INLINE hptime_t timer_hw_hpread(void)
108 return EmulTimer::instance().hpread();