mirror of https://github.com/ARMmbed/mbed-os.git
Use EventQueue for elapsed time
Current implementation uses high resolution timers to calculate elapsed time. This prevents for example deep sleep completely and causes unnecessary timer events. This commit changes implamentation to use EventQueue::tick() to get elapsed time.pull/6087/head
parent
b0889f7d21
commit
7872b6a29c
|
@ -199,7 +199,7 @@ lora_mac_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
|
|||
_compliance_test.app_data_buffer = compliance_test_buffer;
|
||||
#endif
|
||||
|
||||
TimerTimeCounterInit( );
|
||||
TimerTimeCounterInit(queue);
|
||||
LoRaMacPrimitives.MacMcpsConfirm = callback(this, &LoRaWANStack::mcps_confirm);
|
||||
LoRaMacPrimitives.MacMcpsIndication = callback(this, &LoRaWANStack::mcps_indication);
|
||||
LoRaMacPrimitives.MacMlmeConfirm = callback(this, &LoRaWANStack::mlme_confirm);
|
||||
|
|
|
@ -20,46 +20,22 @@ SPDX-License-Identifier: BSD-3-Clause
|
|||
|
||||
#include "lorawan/system/LoRaWANTimer.h"
|
||||
|
||||
static mbed::Timer TimeCounter;
|
||||
static mbed::Ticker LoadTimeCounter;
|
||||
static events::EventQueue *_queue = NULL;
|
||||
|
||||
volatile uint32_t CurrentTime = 0;
|
||||
|
||||
void TimerResetTimeCounter( void )
|
||||
void TimerTimeCounterInit(events::EventQueue *queue)
|
||||
{
|
||||
CurrentTime = CurrentTime + TimeCounter.read_us( ) / 1000;
|
||||
TimeCounter.reset( );
|
||||
TimeCounter.start( );
|
||||
}
|
||||
|
||||
void TimerTimeCounterInit( void )
|
||||
{
|
||||
TimeCounter.start( );
|
||||
LoadTimeCounter.attach( mbed::callback( &TimerResetTimeCounter ), 10 );
|
||||
_queue = queue;
|
||||
}
|
||||
|
||||
TimerTime_t TimerGetCurrentTime( void )
|
||||
{
|
||||
CurrentTime += TimeCounter.read_us( ) / 1000;
|
||||
TimeCounter.reset( );
|
||||
TimeCounter.start( );
|
||||
return ( ( TimerTime_t )CurrentTime );
|
||||
const uint32_t current_time = _queue->tick();
|
||||
return (TimerTime_t)current_time;
|
||||
}
|
||||
|
||||
TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime )
|
||||
{
|
||||
CurrentTime += TimeCounter.read_us( ) / 1000;
|
||||
TimeCounter.reset( );
|
||||
TimeCounter.start( );
|
||||
return ( TimerTime_t )( CurrentTime - savedTime );
|
||||
}
|
||||
|
||||
TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture )
|
||||
{
|
||||
CurrentTime += TimeCounter.read_us( ) / 1000;
|
||||
TimeCounter.reset( );
|
||||
TimeCounter.start( );
|
||||
return ( TimerTime_t )( CurrentTime + eventInFuture );
|
||||
return TimerGetCurrentTime() - savedTime;
|
||||
}
|
||||
|
||||
void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) )
|
||||
|
|
|
@ -23,6 +23,7 @@ SPDX-License-Identifier: BSD-3-Clause
|
|||
#include "drivers/Timer.h"
|
||||
#include "drivers/Ticker.h"
|
||||
#include "lorawan/system/lorawan_data_structures.h"
|
||||
#include "events/EventQueue.h"
|
||||
|
||||
/*!
|
||||
* \brief Timer object description
|
||||
|
@ -34,13 +35,6 @@ typedef struct TimerEvent_s
|
|||
mbed::Ticker Timer;
|
||||
}TimerEvent_t;
|
||||
|
||||
/*!
|
||||
* \brief Initializes the timer used to get the current time.
|
||||
*
|
||||
* \remark The current time corresponds to the time since system startup.
|
||||
*/
|
||||
void TimerTimeCounterInit( void );
|
||||
|
||||
/*!
|
||||
* \brief Initializes the timer object.
|
||||
*
|
||||
|
@ -81,6 +75,15 @@ void TimerReset( TimerEvent_t *obj );
|
|||
*/
|
||||
void TimerSetValue( TimerEvent_t *obj, uint32_t value );
|
||||
|
||||
/*!
|
||||
* \brief Initializes the timer used to get the current time.
|
||||
*
|
||||
* \remark The current time corresponds to the time since system startup.
|
||||
*
|
||||
* \param [in] queue Handle to EventQueue object
|
||||
*/
|
||||
void TimerTimeCounterInit(events::EventQueue *queue);
|
||||
|
||||
/*!
|
||||
* \brief Read the current time.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue