porting: Add missing API functions used by Mesh

This commit is contained in:
Michał Narajowski
2018-05-15 14:21:14 +02:00
parent c29971e38d
commit a1005bd9c5
5 changed files with 113 additions and 5 deletions
@@ -99,6 +99,12 @@ ble_npl_eventq_init(struct ble_npl_eventq *evq)
evq->q = xQueueCreate(32, sizeof(struct ble_npl_eventq *));
}
static inline struct ble_npl_event *
ble_npl_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
{
return npl_freertos_eventq_get_tmo(evq, tmo);
}
static inline struct ble_npl_event *
ble_npl_eventq_get(struct ble_npl_eventq *evq)
{
@@ -128,6 +134,12 @@ ble_npl_eventq_run(struct ble_npl_eventq *evq)
ev->fn(ev);
}
static inline int
ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
{
return xQueueIsQueueEmptyFromISR(evq->q);
}
static inline void
ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
void *arg)
@@ -228,6 +240,19 @@ ble_npl_callout_get_ticks(struct ble_npl_callout *co)
return xTimerGetExpiryTime(co->handle);
}
static inline uint32_t
ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t time)
{
return npl_freertos_callout_remaining_ticks(co, time);
}
static inline void
ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg)
{
co->ev.arg = arg;
}
static inline uint32_t
ble_npl_time_get(void)
{
@@ -258,6 +283,12 @@ ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks)
return ticks * 1000 / configTICK_RATE_HZ;
}
static inline void
ble_npl_time_delay(ble_npl_time_t ticks)
{
vTaskDelay(ticks);
}
#if NIMBLE_CFG_CONTROLLER
static inline void
ble_npl_hw_set_isr(int irqn, uint32_t addr)
@@ -26,6 +26,8 @@ extern "C" {
struct ble_npl_eventq *npl_freertos_eventq_dflt_get(void);
struct ble_npl_event *npl_freertos_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo);
struct ble_npl_event *npl_freertos_eventq_get(struct ble_npl_eventq *evq);
void npl_freertos_eventq_put(struct ble_npl_eventq *evq,
@@ -55,6 +57,9 @@ void npl_freertos_callout_init(struct ble_npl_callout *co,
int npl_freertos_callout_reset(struct ble_npl_callout *co,
ble_npl_time_t ticks);
ble_npl_time_t npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t now);
ble_npl_error_t npl_freertos_time_ms_to_ticks(uint32_t ms,
ble_npl_time_t *out_ticks);
+33 -5
View File
@@ -42,19 +42,27 @@ npl_freertos_eventq_dflt_get(void)
}
struct ble_npl_event *
npl_freertos_eventq_get(struct ble_npl_eventq *evq)
npl_freertos_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
{
struct ble_npl_event *ev;
struct ble_npl_event *ev = NULL;
BaseType_t ret;
ret = xQueueReceive(evq->q, &ev, portMAX_DELAY);
assert(ret == pdPASS);
ret = xQueueReceive(evq->q, &ev, tmo);
assert(ret == pdPASS || ret == errQUEUE_EMPTY);
ev->queued = false;
if (ev) {
ev->queued = false;
}
return ev;
}
struct ble_npl_event *
npl_freertos_eventq_get(struct ble_npl_eventq *evq)
{
return npl_freertos_eventq_get_tmo(evq, portMAX_DELAY);
}
void
npl_freertos_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
{
@@ -281,6 +289,26 @@ npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
return BLE_NPL_OK;
}
ble_npl_time_t
npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t now)
{
ble_npl_time_t rt;
uint32_t exp = xTimerGetExpiryTime(co->handle);
taskENTER_CRITICAL();
if (exp > now) {
rt = exp - now;
} else {
return 0;
}
taskEXIT_CRITICAL();
return rt;
}
ble_npl_error_t
npl_freertos_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
{
@@ -82,6 +82,12 @@ ble_npl_eventq_init(struct ble_npl_eventq *evq)
os_eventq_init(&evq->evq);
}
static inline struct ble_npl_event *
ble_npl_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
{
return (struct ble_npl_event *)os_eventq_poll((struct os_eventq **)&evq, 1, tmo);
}
static inline struct ble_npl_event *
ble_npl_eventq_get(struct ble_npl_eventq *evq)
{
@@ -107,6 +113,12 @@ ble_npl_eventq_run(struct ble_npl_eventq *evq)
os_eventq_run(&evq->evq);
}
static inline int
ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
{
return STAILQ_EMPTY(&evq->evq.evq_list);
}
static inline void
ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
void *arg)
@@ -208,6 +220,20 @@ ble_npl_callout_get_ticks(struct ble_npl_callout *co)
return co->co.c_ticks;
}
static inline ble_npl_time_t
ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t time)
{
return os_callout_remaining_ticks(&co->co, time);
}
static inline void
ble_npl_callout_set_arg(struct ble_npl_callout *co,
void *arg)
{
co->co.c_ev.ev_arg = arg;
}
static inline uint32_t
ble_npl_time_get(void)
{
@@ -238,6 +264,12 @@ ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks)
return os_time_ticks_to_ms32(ticks);
}
static inline void
ble_npl_time_delay(ble_npl_time_t ticks)
{
return os_time_delay(ticks);
}
static inline uint32_t
ble_npl_hw_enter_critical(void)
{