SFBHWTimer.h

Go to the documentation of this file.
00001 /*                                              -*- mode:C++; fill-column:100 -*-
00002   SFBHWTimer.h Support for h/w-based timer interrupts
00003   Copyright (C) 2009 The Regents of the University of New Mexico.  All rights reserved.
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License
00016   along with this library; if not, write to the Free Software
00017   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00018   USA
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   /* \endcond */
00345 
00346   HWTimerHandler handlers[4];   // For each of the four match registers
00347   u32 usecsPerTick;             // Number of usecs per clock tick, or zero if timer not in use
00348   u32 lapCounter;               // Total number of clock laps since reset
00349   const u8 index;               // index of this timer into TimerInfo array
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 /*SFBHWTIMER_H_*/

Generated on Fri Apr 22 06:54:11 2011 for SFB by doxygen 1.5.9