mirror of https://github.com/ARMmbed/mbed-os.git
Timer: add a function to read the timer in a 64bit variable.
The Timer implementation has been refactored to take advantage of this implementation as the base for all functions reading the time elapsed.pull/4094/head
parent
15327ca607
commit
3b6c00b040
|
@ -45,30 +45,27 @@ void Timer::stop() {
|
|||
}
|
||||
|
||||
int Timer::read_us() {
|
||||
return read_high_resolution_us();
|
||||
}
|
||||
|
||||
float Timer::read() {
|
||||
return (float)read_us() / 1000000.0f;
|
||||
}
|
||||
|
||||
int Timer::read_ms() {
|
||||
return read_high_resolution_us() / 1000;
|
||||
}
|
||||
|
||||
us_timestamp_t Timer::read_high_resolution_us() {
|
||||
core_util_critical_section_enter();
|
||||
us_timestamp_t time = _time + slicetime();
|
||||
core_util_critical_section_exit();
|
||||
return time;
|
||||
}
|
||||
|
||||
float Timer::read() {
|
||||
core_util_critical_section_enter();
|
||||
us_timestamp_t time = _time + slicetime();
|
||||
core_util_critical_section_exit();
|
||||
time = time / 1000;
|
||||
return (float)read_ms() / 1000.0f;
|
||||
}
|
||||
|
||||
int Timer::read_ms() {
|
||||
core_util_critical_section_enter();
|
||||
us_timestamp_t time = _time + slicetime();
|
||||
core_util_critical_section_exit();
|
||||
return time / 1000;
|
||||
}
|
||||
|
||||
us_timestamp_t Timer::slicetime() {
|
||||
core_util_critical_section_enter();
|
||||
us_timestamp_t ret = 0;
|
||||
core_util_critical_section_enter();
|
||||
if (_running) {
|
||||
ret = ticker_read_us(_ticker_data) - _start;
|
||||
}
|
||||
|
|
|
@ -82,6 +82,10 @@ public:
|
|||
*/
|
||||
operator float();
|
||||
|
||||
/** Get in a high resolution type the time passed in micro-seconds.
|
||||
*/
|
||||
us_timestamp_t read_high_resolution_us();
|
||||
|
||||
protected:
|
||||
us_timestamp_t slicetime();
|
||||
int _running; // whether the timer is running
|
||||
|
|
Loading…
Reference in New Issue