SFBHWTimer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00042 #ifndef SFBHWTIMER_H_
00043 #define SFBHWTIMER_H_
00044
00045 #include "SFBTypes.h"
00046
00047 typedef void (*HWTimerHandler)() ;
00048
00053 class SFBHWTimer {
00054 public:
00104 void begin(u32 usecsPerTick = 1000, u32 ticksPerLap = 1000, bool running = false) ;
00105
00109 void end();
00110
00124 void setTickTime(u32 usecsPerTick) ;
00125
00129 void setRunning(bool isRunning);
00130
00134 void start() { setRunning(true); }
00135
00139 void stop() { setRunning(false); }
00140
00146 void reset(bool alsoStop = false) ;
00147
00182 void setLap(u32 ticksPerLap) ;
00183
00199 u32 getLap() ;
00200
00211 void setLapHandler(HWTimerHandler handler) ;
00212
00238 void setSplitHandler(u32 splitIndex, u32 ticks, HWTimerHandler handler) ;
00239
00257 void setSplit(u32 splitIndex, u32 ticks) ;
00258
00276 u32 getSplit(u32 splitIndex) ;
00277
00288 HWTimerHandler getSplitHandler(u32 splitIndex) ;
00289
00295 HWTimerHandler getLapHandler() ;
00296
00316 static u32 getSplitIndex() { return currentMatchIndex; }
00317
00321 u32 getLaps() { return lapCounter; }
00322
00326 u32 getTicks() ;
00327
00328 SFBHWTimer(u8 index) ;
00329
00330 void reinitForPCLK() ;
00331
00332 private:
00333 void interruptHandler() ;
00334 void configurePCLK() ;
00335 static u32 currentMatchIndex;
00336
00338 friend void Timer0Handler() ;
00339 friend void Timer1Handler() ;
00340 friend void Timer2Handler() ;
00341 friend void Timer3Handler() ;
00342 friend void Timer4Handler() ;
00343
00344
00345
00346 HWTimerHandler handlers[4];
00347 u32 usecsPerTick;
00348 u32 lapCounter;
00349 const u8 index;
00350 };
00351
00352 extern SFBHWTimer Timers[5];
00353 extern SFBHWTimer & Timer1;
00354 extern SFBHWTimer & Timer2;
00355 extern SFBHWTimer & Timer3;
00356 extern SFBHWTimer & Timer4;
00357
00358 #endif