64 bit Timer Class.

Committer:
tedoyle
Date:
Sun Mar 27 20:18:44 2016 +0000
Revision:
1:497fba179833
Parent:
0:1e0e79e82839
Child:
2:e89b02820e93
bug fixes and code updates;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tedoyle 0:1e0e79e82839 1 #ifndef __NEW_TIMER64__
tedoyle 0:1e0e79e82839 2 #define __NEW_TIMER64__
tedoyle 0:1e0e79e82839 3
tedoyle 0:1e0e79e82839 4 #include "platform.h"
tedoyle 0:1e0e79e82839 5 #include "ticker_api.h"
tedoyle 0:1e0e79e82839 6 #include <stdint.h>
tedoyle 0:1e0e79e82839 7 #include "rtos.h"
tedoyle 0:1e0e79e82839 8
tedoyle 1:497fba179833 9 #define TIMER64_OK 0
tedoyle 0:1e0e79e82839 10
tedoyle 1:497fba179833 11 #define TIMER64_ERROR_NOT_INITIALIZED -1
tedoyle 0:1e0e79e82839 12
tedoyle 1:497fba179833 13 #define TIMER64_WARNING_ALREADY_INITIALIZED 1
tedoyle 1:497fba179833 14 #define TIMER64_WARNING_ALREADY_RUNNING 2
tedoyle 1:497fba179833 15 #define TIMER64_WARNING_ALREADY_STOPPED 3
tedoyle 0:1e0e79e82839 16
tedoyle 0:1e0e79e82839 17 #define TIMER64_15MINUTE_ROLLOVER_CHECK_IN_MSECS 900000
tedoyle 0:1e0e79e82839 18 #define TIMER64_MIN_ROLLOVER_CHECK_IN_MSECS 60000 // 0:01:00.000
tedoyle 0:1e0e79e82839 19 #define TIMER64_MAX_ROLLOVER_CHECK_IN_MSECS 2147483 // 0:35:47.483
tedoyle 0:1e0e79e82839 20
tedoyle 0:1e0e79e82839 21 class Timer64
tedoyle 0:1e0e79e82839 22 {
tedoyle 0:1e0e79e82839 23
tedoyle 0:1e0e79e82839 24 public:
tedoyle 0:1e0e79e82839 25 Timer64();
tedoyle 1:497fba179833 26 ~Timer64();
tedoyle 0:1e0e79e82839 27
tedoyle 1:497fba179833 28 /** Initialize the timer - this must be called before the timer can be used
tedoyle 0:1e0e79e82839 29 */
tedoyle 0:1e0e79e82839 30 int init(uint32_t rolloverCheckTimeInMsecc = TIMER64_15MINUTE_ROLLOVER_CHECK_IN_MSECS);
tedoyle 0:1e0e79e82839 31
tedoyle 0:1e0e79e82839 32 /** Release the timer
tedoyle 0:1e0e79e82839 33 */
tedoyle 0:1e0e79e82839 34 int release(void);
tedoyle 0:1e0e79e82839 35
tedoyle 0:1e0e79e82839 36 /** Start the timer
tedoyle 0:1e0e79e82839 37 */
tedoyle 0:1e0e79e82839 38 int start(void);
tedoyle 0:1e0e79e82839 39
tedoyle 0:1e0e79e82839 40 /** Stop the timer
tedoyle 0:1e0e79e82839 41 */
tedoyle 0:1e0e79e82839 42 int stop(void);
tedoyle 0:1e0e79e82839 43
tedoyle 0:1e0e79e82839 44 /** Reset the timer to 0.
tedoyle 0:1e0e79e82839 45 *
tedoyle 0:1e0e79e82839 46 * If it was already counting, it will continue
tedoyle 0:1e0e79e82839 47 */
tedoyle 0:1e0e79e82839 48 int reset(void);
tedoyle 0:1e0e79e82839 49
tedoyle 0:1e0e79e82839 50 /** Get the time passed in seconds
tedoyle 0:1e0e79e82839 51 */
tedoyle 0:1e0e79e82839 52 double read(int* status = NULL);
tedoyle 0:1e0e79e82839 53
tedoyle 1:497fba179833 54 /** Get the time passed in milli-seconds
tedoyle 0:1e0e79e82839 55 */
tedoyle 0:1e0e79e82839 56 uint64_t read_ms(int* status = NULL);
tedoyle 0:1e0e79e82839 57
tedoyle 0:1e0e79e82839 58 /** Get the time passed in micro-seconds
tedoyle 0:1e0e79e82839 59 */
tedoyle 0:1e0e79e82839 60 uint64_t read_us(int* status = NULL);
tedoyle 0:1e0e79e82839 61
tedoyle 0:1e0e79e82839 62 private:
tedoyle 0:1e0e79e82839 63 bool _timerInitialized;
tedoyle 1:497fba179833 64 bool _timerRunning; // whether the timer is running
tedoyle 0:1e0e79e82839 65 timestamp_t _tickerStartTimeUsec; // the start time of the latest slice
tedoyle 0:1e0e79e82839 66 uint64_t _totalTimeUsec; // any accumulated time from previous slices
tedoyle 0:1e0e79e82839 67 const ticker_data_t *_ticker_data;
tedoyle 0:1e0e79e82839 68 RtosTimer* _rollOverCheckTimer;
tedoyle 0:1e0e79e82839 69 uint32_t _rollOverCheckTimerPeriodInMsec;
tedoyle 0:1e0e79e82839 70 static void _rollOverCheck(void const* args);
tedoyle 0:1e0e79e82839 71 };
tedoyle 0:1e0e79e82839 72
tedoyle 0:1e0e79e82839 73 #endif