Implement nanostack eventloop tick timer

Nanostack eventloop tick timer can be used in case high resolution
platform timer is not needed. One usecase for that is Pelion
Cloud client when using for example cellular connectivity. This enables
PDMC application to enter deep sleep state.
pull/10475/head
Kimmo Vaisanen 2019-04-24 14:37:16 +03:00
parent 46603f831e
commit 7349bc8a47
2 changed files with 58 additions and 0 deletions

View File

@ -24,6 +24,7 @@
#include "platform/mbed_assert.h"
#include "Timeout.h"
#include "Timer.h"
#include "Ticker.h"
#include "events/Event.h"
#include "events/mbed_shared_queues.h"
@ -45,6 +46,61 @@ static EventQueue *equeue;
static uint32_t due;
static void (*arm_hal_callback)(void);
#if defined(NS_EVENTLOOP_USE_TICK_TIMER)
#if MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
static SingletonPtr<Ticker> tick_ticker;
#endif
static int tick_timer_id;
static void (*tick_timer_cb)(void);
int8_t platform_tick_timer_register(void (*tick_timer_cb_handler)(void))
{
#if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
equeue = mbed_highprio_event_queue();
MBED_ASSERT(equeue != NULL);
#endif
tick_timer_cb = tick_timer_cb_handler;
return 0;
}
int8_t platform_tick_timer_start(uint32_t period_ms)
{
int8_t retval = -1;
if (tick_timer_cb && tick_timer_id == 0) {
#if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
tick_timer_id = equeue->call_every(period_ms, tick_timer_cb);
if (tick_timer_id != 0) {
retval = 0;
}
#else
tick_ticker->attach_us(tick_timer_cb, period_ms * 1000);
tick_timer_id = 1;
retval = 0;
#endif
}
return retval;
}
int8_t platform_tick_timer_stop(void)
{
int8_t retval = -1;
if (tick_timer_id != 0) {
#if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
equeue->cancel(tick_timer_id);
#else
tick_ticker->detach();
#endif
tick_timer_id = 0;
retval = 0;
}
return retval;
}
#endif // NS_EVENTLOOP_USE_TICK_TIMER
// Called once at boot
void platform_timer_enable(void)
{

View File

@ -43,7 +43,9 @@ void ns_hal_init(void *heap, size_t h_size, void (*passed_fptr)(heap_fail_t), me
}
platform_critical_init();
ns_dyn_mem_init(heap, h_size, passed_fptr, info_ptr);
#ifndef NS_EXCLUDE_HIGHRES_TIMER
platform_timer_enable();
#endif
eventOS_scheduler_init();
// We do not initialise randlib, as it should be done after