timer_qt.c

Go to the documentation of this file.
00001 
00039 #include <cfg/compiler.h> /* hptime.t */
00040 
00041 // Qt headers
00042 #include <QtCore/QDateTime>
00043 #include <QtCore/QTimer>
00044 
00045 
00046 // The user interrupt server routine
00047 void timer_isr(void);
00048 
00049 
00053 class EmulTimer : public QObject
00054 {
00055 private:
00056     Q_OBJECT;
00057 
00059     QTime system_time;
00060 
00062     QTimer timer;
00063 
00068     bool initialized;
00069 
00071     EmulTimer() : initialized(false) { }
00072 
00073 public:
00075     static EmulTimer &instance()
00076     {
00077         static EmulTimer et;
00078         return et;
00079     }
00080 
00082     void init()
00083     {
00084         // Timer initialized twice?
00085         ASSERT(!initialized);
00086 
00087         // Record initial time
00088         system_time.start();
00089 
00090         // Activate timer interrupt
00091         timer.connect(&timer, SIGNAL(timeout()), this, SLOT(timerInterrupt()));
00092         timer.start(1000 / TIMER_TICKS_PER_SEC);
00093 
00094         initialized = true;
00095     }
00096 
00098     hptime_t hpread()
00099     {
00100         ASSERT(initialized);
00101         return system_time.elapsed();
00102     }
00103 
00104 public slots:
00105     void timerInterrupt(void)
00106     {
00107         // Just call user interrupt server, timer restarts automatically.
00108         timer_isr();
00109     }
00110 
00111 };
00112 
00113 #include "timer_qt_moc.cpp"
00114 
00115 
00117 static void timer_hw_init(void)
00118 {
00119     // Kick EmulTimer initialization
00120     EmulTimer::instance().init();
00121 }
00122 
00123 INLINE hptime_t timer_hw_hpread(void)
00124 {
00125     return EmulTimer::instance().hpread();
00126 }
00127 
00129 #define timer_hw_triggered() (true)