mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #10475 from kivaisan/ns_eventloop_tick_timer
Implement nanostack eventloop tick timerpull/10503/head
commit
f28b82b831
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue