fix(pan-cordio): Reset timer after updating to reduce chance of overflow

pull/8876/head
Steve Cartmell 2018-11-26 11:58:36 +00:00 committed by Vincent Coubard
parent e5aa84308f
commit ca2efcdd11
2 changed files with 10 additions and 9 deletions

View File

@ -155,6 +155,7 @@ private:
::BLE::InstanceID_t instanceID; ::BLE::InstanceID_t instanceID;
mutable SimpleEventQueue _event_queue; mutable SimpleEventQueue _event_queue;
mbed::Timer _timer; mbed::Timer _timer;
uint64_t _last_update_us;
class SigningEventMonitorProxy : public pal::SigningEventMonitor { class SigningEventMonitorProxy : public pal::SigningEventMonitor {
public: public:

View File

@ -96,7 +96,8 @@ namespace cordio {
BLE::BLE(CordioHCIDriver& hci_driver) : BLE::BLE(CordioHCIDriver& hci_driver) :
initialization_status(NOT_INITIALIZED), initialization_status(NOT_INITIALIZED),
instanceID(::BLE::DEFAULT_INSTANCE), instanceID(::BLE::DEFAULT_INSTANCE),
_event_queue() _event_queue(),
_last_update_us(0)
{ {
_hci_driver = &hci_driver; _hci_driver = &hci_driver;
@ -401,17 +402,16 @@ void BLE::callDispatcher()
// process the external event queue // process the external event queue
_event_queue.process(); _event_queue.process();
// follow by stack events _last_update_us += (uint64_t)_timer.read_high_resolution_us();
static us_timestamp_t last_time_us = _timer.read_high_resolution_us(); _timer.reset();
// Update the current cordio time uint64_t last_update_ms = (_last_update_us / 1000);
us_timestamp_t curr_time_us = _timer.read_high_resolution_us(); wsfTimerTicks_t wsf_ticks = (last_update_ms / WSF_MS_PER_TICK);
uint64_t delta_time_ms = ((curr_time_us - last_time_us) / 1000);
if (delta_time_ms > 0) { if (wsf_ticks > 0) {
WsfTimerUpdate(delta_time_ms / WSF_MS_PER_TICK); WsfTimerUpdate(wsf_ticks);
last_time_us += (delta_time_ms * 1000); _last_update_us -= (last_update_ms * 1000);
} }
wsfOsDispatcher(); wsfOsDispatcher();