Simple 64-bit timer for mbed. It is a drastically simplified version of Timer64 class by Tom Doyle. It is meant to be used in single-thread applications, where timer is used frequently, while standard 32-bit Timer is not enough.
Fork of Timer64 by
Timer64.h
- Committer:
- tedoyle
- Date:
- 2016-03-28
- Revision:
- 3:8396d3e6eb62
- Parent:
- 2:e89b02820e93
- Child:
- 4:9ca673a83acb
- Child:
- 6:100cf27b43aa
File content as of revision 3:8396d3e6eb62:
#ifndef __NEW_TIMER64__ #define __NEW_TIMER64__ #include "platform.h" #include "ticker_api.h" #include <stdint.h> #include "rtos.h" #define TIMER64_OK 0 #define TIMER64_ERROR_NOT_INITIALIZED -1 #define TIMER64_WARNING_ALREADY_INITIALIZED 1 #define TIMER64_WARNING_ALREADY_RUNNING 2 #define TIMER64_WARNING_ALREADY_STOPPED 3 #define TIMER64_WARNING_ALREADY_RELEASED 4 #define TIMER64_DEFAULT_ROLLOVER_CHECK_IN_MSECS 30000 #define TIMER64_MIN_ROLLOVER_CHECK_IN_MSECS 1000 #define TIMER64_MAX_ROLLOVER_CHECK_IN_MSECS 65535 class Timer64 { public: Timer64(); ~Timer64(); /** Initialize the timer - this must be called before the timer can be used */ int init(uint32_t rolloverCheckTimeInMsecc = TIMER64_15MINUTE_ROLLOVER_CHECK_IN_MSECS); /** Release the timer */ int release(void); /** Start the timer */ int start(void); /** Stop the timer */ int stop(void); /** Reset the timer to 0. * * If it was already counting, it will continue */ int reset(void); /** Get the time passed in micro-seconds */ int read_us(uint64_t* timeInUsec = NULL); /** Get the time passed in milli-seconds */ int read_ms(uint64_t* timeInMsec = NULL); /** Get the time passed in seconds */ int read(double* timeInSec = NULL); private: bool _timerInitialized; bool _timerRunning; // whether the timer is running timestamp_t _tickerStartTimeUsec; // the start time of the latest slice uint64_t _totalTimeUsec; // any accumulated time from previous slices const ticker_data_t *_ticker_data; RtosTimer* _rollOverCheckTimer; uint32_t _rollOverCheckTimerPeriodInMsec; Semaphore* _sem; static void _rollOverCheck(void const* args); static uint64_t _read_us(void const* args); }; #endif