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
Diff: Timer64.cpp
- Revision:
- 8:5d17ff4f9c23
- Parent:
- 4:9ca673a83acb
diff -r 381bafbb2218 -r 5d17ff4f9c23 Timer64.cpp --- a/Timer64.cpp Fri Apr 01 18:37:38 2016 +0000 +++ b/Timer64.cpp Tue Apr 05 19:07:09 2016 +0000 @@ -19,8 +19,8 @@ Timer64::Timer64() : _timerInitialized(false), _timerRunning(false), - _tickerStartTimeUsec(0L), - _totalTimeUsec(0L), + _tickerStartTimeUsec(0u), + _totalTimeUsec(0llu), _ticker_data(get_us_ticker_data()), _rollOverCheckTimer(NULL), _rollOverCheckTimerPeriodInMsec(TIMER64_DEFAULT_ROLLOVER_CHECK_IN_MSECS), @@ -51,8 +51,8 @@ } _timerRunning = false; - _tickerStartTimeUsec = 0L; - _totalTimeUsec = 0L; + _tickerStartTimeUsec = 0u; + _totalTimeUsec = 0llu; _rollOverCheckTimerPeriodInMsec = rolloverCheckTimeInMsec; _rollOverCheckTimer = new RtosTimer(_rollOverCheck, osTimerPeriodic, this); _sem = new Semaphore(1); @@ -73,8 +73,8 @@ stop(); } - _tickerStartTimeUsec = 0L; - _totalTimeUsec = 0L; + _tickerStartTimeUsec = 0u; + _totalTimeUsec = 0llu; _timerInitialized = false; _rollOverCheckTimer->stop(); delete _rollOverCheckTimer; @@ -155,7 +155,7 @@ _rollOverCheckTimer->start(_rollOverCheckTimerPeriodInMsec); } - _totalTimeUsec = 0L; + _totalTimeUsec = 0llu; } } _sem->release(); @@ -212,11 +212,11 @@ { if (_timerRunning) { - *timeInMsec = _read_us(this)/1000L; + *timeInMsec = _read_us(this)/1000LU; } else { - *timeInMsec = _totalTimeUsec/1000L; + *timeInMsec = _totalTimeUsec/1000LU; } } } @@ -297,7 +297,7 @@ else { // rollover! - timer->_totalTimeUsec += (4294967296L - ((uint64_t)timer->_tickerStartTimeUsec)) + (uint64_t)ticker_current_timeUsec; + timer->_totalTimeUsec += (uint64_t)(4294967296U - timer->_tickerStartTimeUsec) + (uint64_t)ticker_current_timeUsec; }