Mark Gottscho / HardwareTimersLib

Fork of HardwareTimersLib by Mark Gottscho

Committer:
mgottscho
Date:
Sat Mar 08 20:31:49 2014 +0000
Revision:
0:47acc8320421
Child:
2:5056ec8c52e8
Fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mgottscho 0:47acc8320421 1 /* HardwareTimer.h
mgottscho 0:47acc8320421 2 * Tested with mbed board: FRDM-KL46Z
mgottscho 0:47acc8320421 3 * Author: Mark Gottscho
mgottscho 0:47acc8320421 4 * mgottscho@ucla.edu
mgottscho 0:47acc8320421 5 */
mgottscho 0:47acc8320421 6
mgottscho 0:47acc8320421 7 #ifndef HARDWARETIMER_H
mgottscho 0:47acc8320421 8 #define HARDWARETIMER_H
mgottscho 0:47acc8320421 9
mgottscho 0:47acc8320421 10 #include "mbed.h"
mgottscho 0:47acc8320421 11 #include "PreciseTime.h"
mgottscho 0:47acc8320421 12
mgottscho 0:47acc8320421 13 /**
mgottscho 0:47acc8320421 14 * This provides a base class from which actual hardware timers should derive their implementations.
mgottscho 0:47acc8320421 15 * This allows for a nice software interface regardless of the particular timer used.
mgottscho 0:47acc8320421 16 */
mgottscho 0:47acc8320421 17 class HardwareTimer {
mgottscho 0:47acc8320421 18 public:
mgottscho 0:47acc8320421 19 /**
mgottscho 0:47acc8320421 20 * Constructs a new HardwareTimer.
mgottscho 0:47acc8320421 21 * @param tickValue the amount of time corresponding to each timer tick. Units are arbitrary. Depends on specific timer clock rate.
mgottscho 0:47acc8320421 22 */
mgottscho 0:47acc8320421 23 HardwareTimer(uint32_t tickValue);
mgottscho 0:47acc8320421 24
mgottscho 0:47acc8320421 25 ~HardwareTimer();
mgottscho 0:47acc8320421 26
mgottscho 0:47acc8320421 27 /**
mgottscho 0:47acc8320421 28 * @returns true if this timer is valid. If false, no timing mechanisms are functional.
mgottscho 0:47acc8320421 29 */
mgottscho 0:47acc8320421 30 bool valid();
mgottscho 0:47acc8320421 31
mgottscho 0:47acc8320421 32 /**
mgottscho 0:47acc8320421 33 * @returns true if the timer is running.
mgottscho 0:47acc8320421 34 */
mgottscho 0:47acc8320421 35 bool isEnabled();
mgottscho 0:47acc8320421 36
mgottscho 0:47acc8320421 37 /**
mgottscho 0:47acc8320421 38 * @returns the amount of time corresponding to each timer tick. Units are arbitrary. Depends on specific timer clock rate.
mgottscho 0:47acc8320421 39 */
mgottscho 0:47acc8320421 40 float tickValue();
mgottscho 0:47acc8320421 41
mgottscho 0:47acc8320421 42 /**
mgottscho 0:47acc8320421 43 * Enables the timer.
mgottscho 0:47acc8320421 44 */
mgottscho 0:47acc8320421 45 virtual void enableTimer() = 0;
mgottscho 0:47acc8320421 46
mgottscho 0:47acc8320421 47 /**
mgottscho 0:47acc8320421 48 * Disables the timer.
mgottscho 0:47acc8320421 49 */
mgottscho 0:47acc8320421 50 virtual void disableTimer() = 0;
mgottscho 0:47acc8320421 51
mgottscho 0:47acc8320421 52 /**
mgottscho 0:47acc8320421 53 * Gets the timer value in a nice form.
mgottscho 0:47acc8320421 54 * Note that in general, the timer may overflow, leading to saturated values obtained from getTime().
mgottscho 0:47acc8320421 55 * To maximize resolution, accuracy, performance, and range, it is recommended to use
mgottscho 0:47acc8320421 56 * getTick() for most purposes. getTime() is mostly for convenience.
mgottscho 0:47acc8320421 57 * @returns the current tick converted into a PreciseTime representation.
mgottscho 0:47acc8320421 58 */
mgottscho 0:47acc8320421 59 virtual PreciseTime getTime() = 0;
mgottscho 0:47acc8320421 60
mgottscho 0:47acc8320421 61 /**
mgottscho 0:47acc8320421 62 * @returns the current tick number. Convert to real time units by multiplying by tickValue(), which may have arbitrary units.
mgottscho 0:47acc8320421 63 */
mgottscho 0:47acc8320421 64 virtual uint32_t getTick() = 0;
mgottscho 0:47acc8320421 65
mgottscho 0:47acc8320421 66 protected:
mgottscho 0:47acc8320421 67 bool __valid;
mgottscho 0:47acc8320421 68 bool __enabled;
mgottscho 0:47acc8320421 69 uint32_t __tickValue; //how many <units> per tick
mgottscho 0:47acc8320421 70 };
mgottscho 0:47acc8320421 71
mgottscho 0:47acc8320421 72 #endif