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.2 2006/02/20 02:01:35 bernie
20 *#* Revision 1.1 2005/11/27 03:06:36 bernie
21 *#* Qt timer emulation.
25 #include <cfg/compiler.h> /* hptime.t */
29 #include <qdatetime.h>
32 #include <QtCore/QDateTime>
33 #include <QtCore/QTimer>
37 // The user interrupt server routine
42 * Singleton class for Qt-based hardware timer emulation.
44 class EmulTimer : public QObject
49 /// System timer (counts ms since application startup)
52 /// The 1ms "hardware" tick counter.
56 * We deliberately don't use RAII because the real hardware
57 * we're simulating needs to be initialized manually.
61 /// Private ctor (singleton)
62 EmulTimer() : initialized(false) { }
65 /// Return singleton instance
66 static EmulTimer &instance()
72 /// Start timer emulator.
75 // Timer initialized twice?
78 // Record initial time
81 // Activate 1ms timer interrupt
82 timer.connect(&timer, SIGNAL(timeout()), this, SLOT(timerInterrupt()));
88 /// Return current time in high-precision format.
92 return system_time.elapsed();
96 void timerInterrupt(void)
98 // Just call user interrupt server, timer restarts automatically.
104 #include "timer_qt_moc.cpp"
107 /// HW dependent timer initialization.
108 extern "C" static void timer_hw_init(void)
110 // Kick EmulTimer initialization
111 EmulTimer::instance().init();
114 extern "C" INLINE hptime_t timer_hw_hpread(void)
116 return EmulTimer::instance().hpread();