mbed library sources. Supersedes mbed-src.
Dependents: SPIne CH_Communicatuin_Test CH_Communicatuin_Test2 MCP_SPIne ... more
Fork of mbed-dev-f303 by
Diff: drivers/Timer.cpp
- Revision:
- 167:e84263d55307
- Parent:
- 160:d5399cc887bb
- Child:
- 174:b96e65c34a4d
--- a/drivers/Timer.cpp Thu Jun 08 15:02:37 2017 +0100 +++ b/drivers/Timer.cpp Wed Jun 21 17:46:44 2017 +0100 @@ -31,7 +31,7 @@ void Timer::start() { core_util_critical_section_enter(); if (!_running) { - _start = ticker_read(_ticker_data); + _start = ticker_read_us(_ticker_data); _running = 1; } core_util_critical_section_exit(); @@ -45,10 +45,7 @@ } int Timer::read_us() { - core_util_critical_section_enter(); - int time = _time + slicetime(); - core_util_critical_section_exit(); - return time; + return read_high_resolution_us(); } float Timer::read() { @@ -56,14 +53,21 @@ } int Timer::read_ms() { - return read_us() / 1000; + return read_high_resolution_us() / 1000; } -int Timer::slicetime() { +us_timestamp_t Timer::read_high_resolution_us() { core_util_critical_section_enter(); - int ret = 0; + us_timestamp_t time = _time + slicetime(); + core_util_critical_section_exit(); + return time; +} + +us_timestamp_t Timer::slicetime() { + us_timestamp_t ret = 0; + core_util_critical_section_enter(); if (_running) { - ret = ticker_read(_ticker_data) - _start; + ret = ticker_read_us(_ticker_data) - _start; } core_util_critical_section_exit(); return ret; @@ -71,7 +75,7 @@ void Timer::reset() { core_util_critical_section_enter(); - _start = ticker_read(_ticker_data); + _start = ticker_read_us(_ticker_data); _time = 0; core_util_critical_section_exit(); }