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 #if CONFIG_KERN_IRQ 00046 #include <kern/irq.h> 00047 #endif 00048 00049 00050 // The user interrupt server routine 00051 void timer_isr(void); 00052 00053 00057 class EmulTimer : public QObject 00058 { 00059 private: 00060 Q_OBJECT; 00061 00063 QTime system_time; 00064 00066 QTimer timer; 00067 00072 bool initialized; 00073 00075 EmulTimer() : initialized(false) { } 00076 00077 public: 00079 static EmulTimer &instance() 00080 { 00081 static EmulTimer et; 00082 return et; 00083 } 00084 00086 void init() 00087 { 00088 // Timer initialized twice? 00089 ASSERT(!initialized); 00090 00091 // Record initial time 00092 system_time.start(); 00093 00094 #if CONFIG_KERN_IRQ 00095 irq_register(SIGALRM, timer_isr); 00096 #endif 00097 00098 // Activate timer interrupt 00099 connect(&timer, SIGNAL(timeout()), SLOT(timerInterrupt())); 00100 timer.start(1000 / TIMER_TICKS_PER_SEC); 00101 00102 initialized = true; 00103 } 00104 00105 void cleanup() 00106 { 00107 // Timer cleaned twice? 00108 ASSERT(initialized); 00109 00110 timer.stop(); 00111 timer.disconnect(); 00112 00113 initialized = false; 00114 } 00115 00117 hptime_t hpread() 00118 { 00119 ASSERT(initialized); 00120 return system_time.elapsed(); 00121 } 00122 00123 public slots: 00124 void timerInterrupt(void) 00125 { 00126 // Just call user interrupt server, timer restarts automatically. 00127 #if CONFIG_KERN_IRQ 00128 irq_entry(SIGALRM); 00129 #else 00130 timer_isr(); 00131 #endif 00132 } 00133 00134 }; 00135 00136 #include "timer_qt_moc.cpp" 00137 00138 00140 static void timer_hw_init(void) 00141 { 00142 EmulTimer::instance().init(); 00143 } 00144 00145 static void timer_hw_cleanup(void) 00146 { 00147 EmulTimer::instance().cleanup(); 00148 } 00149 00150 INLINE hptime_t timer_hw_hpread(void) 00151 { 00152 return EmulTimer::instance().hpread(); 00153 } 00154 00156 #define timer_hw_triggered() (true)
