Skip to content

Implement nanostack eventloop tick timer #10475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions features/nanostack/nanostack-hal-mbed-cmsis-rtos/arm_hal_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down