mirror of https://github.com/ARMmbed/mbed-os.git
refactor(pan-cordio): Use Timer class instead of raw ticker for timing
parent
299ae1d9c6
commit
e5aa84308f
|
@ -31,6 +31,7 @@
|
||||||
#include "ble/generic/GenericGap.h"
|
#include "ble/generic/GenericGap.h"
|
||||||
#include "ble/generic/GenericSecurityManager.h"
|
#include "ble/generic/GenericSecurityManager.h"
|
||||||
#include "SimpleEventQueue.h"
|
#include "SimpleEventQueue.h"
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
namespace ble {
|
namespace ble {
|
||||||
namespace vendor {
|
namespace vendor {
|
||||||
|
@ -153,6 +154,7 @@ private:
|
||||||
|
|
||||||
::BLE::InstanceID_t instanceID;
|
::BLE::InstanceID_t instanceID;
|
||||||
mutable SimpleEventQueue _event_queue;
|
mutable SimpleEventQueue _event_queue;
|
||||||
|
mbed::Timer _timer;
|
||||||
|
|
||||||
class SigningEventMonitorProxy : public pal::SigningEventMonitor {
|
class SigningEventMonitorProxy : public pal::SigningEventMonitor {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -121,6 +121,8 @@ ble_error_t BLE::init(
|
||||||
{
|
{
|
||||||
switch (initialization_status) {
|
switch (initialization_status) {
|
||||||
case NOT_INITIALIZED:
|
case NOT_INITIALIZED:
|
||||||
|
_timer.reset();
|
||||||
|
_timer.start();
|
||||||
_event_queue.initialize(this, instanceID);
|
_event_queue.initialize(this, instanceID);
|
||||||
_init_callback = initCallback;
|
_init_callback = initCallback;
|
||||||
start_stack_reset();
|
start_stack_reset();
|
||||||
|
@ -400,15 +402,16 @@ void BLE::callDispatcher()
|
||||||
_event_queue.process();
|
_event_queue.process();
|
||||||
|
|
||||||
// follow by stack events
|
// follow by stack events
|
||||||
static uint32_t lastTimeUs = us_ticker_read();
|
static us_timestamp_t last_time_us = _timer.read_high_resolution_us();
|
||||||
uint32_t currTimeUs, deltaTimeMs;
|
|
||||||
|
|
||||||
// Update the current cordio time
|
// Update the current cordio time
|
||||||
currTimeUs = us_ticker_read();
|
us_timestamp_t curr_time_us = _timer.read_high_resolution_us();
|
||||||
deltaTimeMs = (currTimeUs - lastTimeUs) / 1000;
|
uint64_t delta_time_ms = ((curr_time_us - last_time_us) / 1000);
|
||||||
if (deltaTimeMs > 0) {
|
|
||||||
WsfTimerUpdate(deltaTimeMs / WSF_MS_PER_TICK);
|
if (delta_time_ms > 0) {
|
||||||
lastTimeUs += deltaTimeMs * 1000;
|
WsfTimerUpdate(delta_time_ms / WSF_MS_PER_TICK);
|
||||||
|
|
||||||
|
last_time_us += (delta_time_ms * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
wsfOsDispatcher();
|
wsfOsDispatcher();
|
||||||
|
|
Loading…
Reference in New Issue