Skip to content

Commit 328a582

Browse files
committed
Use Chrono in LowPowerTickerWrapper
1 parent 784c6ba commit 328a582

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

hal/LowPowerTickerWrapper.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "hal/LowPowerTickerWrapper.h"
1818
#include "platform/Callback.h"
1919

20+
using namespace mbed::chrono;
21+
2022
LowPowerTickerWrapper::LowPowerTickerWrapper(const ticker_data_t *data, const ticker_interface_t *interface, uint32_t min_cycles_between_writes, uint32_t min_cycles_until_match)
2123
: _intf(data->interface), _min_count_between_writes(min_cycles_between_writes + 1), _min_count_until_match(min_cycles_until_match + 1), _suspended(false)
2224
{
@@ -247,12 +249,12 @@ bool LowPowerTickerWrapper::_match_check(timestamp_t current)
247249
_ticker_match_interval_passed(_last_set_interrupt, current, _cur_match_time);
248250
}
249251

250-
uint32_t LowPowerTickerWrapper::_lp_ticks_to_us(uint32_t ticks)
252+
microseconds_u32 LowPowerTickerWrapper::_lp_ticks_to_us(uint32_t ticks)
251253
{
252254
MBED_ASSERT(core_util_in_critical_section());
253255

254256
// Add 4 microseconds to round up the micro second ticker time (which has a frequency of at least 250KHz - 4us period)
255-
return _us_per_tick * ticks + 4;
257+
return microseconds_u32(_us_per_tick * ticks + 4);
256258
}
257259

258260
void LowPowerTickerWrapper::_schedule_match(timestamp_t current)
@@ -277,7 +279,7 @@ void LowPowerTickerWrapper::_schedule_match(timestamp_t current)
277279
// then don't schedule it again.
278280
if (!_pending_timeout) {
279281
uint32_t ticks = cycles_until_match < _min_count_until_match ? cycles_until_match : _min_count_until_match;
280-
_timeout.attach_us(mbed::callback(this, &LowPowerTickerWrapper::_timeout_handler), _lp_ticks_to_us(ticks));
282+
_timeout.attach(mbed::callback(this, &LowPowerTickerWrapper::_timeout_handler), _lp_ticks_to_us(ticks));
281283
_pending_timeout = true;
282284
}
283285
return;
@@ -309,7 +311,7 @@ void LowPowerTickerWrapper::_schedule_match(timestamp_t current)
309311
// Low power ticker incremented to less than _min_count_until_match
310312
// so low power ticker may not fire. Use Timeout to ensure it does fire.
311313
uint32_t ticks = cycles_until_match < _min_count_until_match ? cycles_until_match : _min_count_until_match;
312-
_timeout.attach_us(mbed::callback(this, &LowPowerTickerWrapper::_timeout_handler), _lp_ticks_to_us(ticks));
314+
_timeout.attach(mbed::callback(this, &LowPowerTickerWrapper::_timeout_handler), _lp_ticks_to_us(ticks));
313315
_pending_timeout = true;
314316
return;
315317
}

hal/LowPowerTickerWrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "hal/us_ticker_api.h"
2727
#include "drivers/Timeout.h"
2828

29+
#include "platform/mbed_chrono.h"
2930
#include "platform/mbed_critical.h"
3031

3132

@@ -227,7 +228,7 @@ class LowPowerTickerWrapper {
227228
*
228229
* This value is always larger or equal to exact value.
229230
*/
230-
uint32_t _lp_ticks_to_us(uint32_t);
231+
mbed::chrono::microseconds_u32 _lp_ticks_to_us(uint32_t);
231232

232233
/*
233234
* Schedule a match interrupt to fire at the correct time

0 commit comments

Comments
 (0)