Loading...
Searching...
No Matches
nimble_npl_os.h File Reference

Mynewt-Nimble Porting layer wrappers. More...

Detailed Description

Mynewt-Nimble Porting layer wrappers.

Author
Hauke Petersen hauke.nosp@m..pet.nosp@m.ersen.nosp@m.@fu-.nosp@m.berli.nosp@m.n.de

Definition in file nimble_npl_os.h.

#include <stdint.h>
#include <stdbool.h>
#include "os/os.h"
#include "mcu/mcu.h"
+ Include dependency graph for nimble_npl_os.h:

Go to the source code of this file.

Data Structures

struct  ble_npl_event
 ble_npl event wrapper More...
 
struct  ble_npl_eventq
 ble_npl event queue wrapper More...
 
struct  ble_npl_callout
 ble_npl callout wrapper More...
 
struct  ble_npl_mutex
 ble_npl mutex wrapper More...
 
struct  ble_npl_sem
 ble_npl semaphore wrapper More...
 

Typedefs

typedef uint32_t ble_npl_time_t
 time type
 
typedef int32_t ble_npl_stime_t
 time type
 

Functions

static bool ble_npl_os_started (void)
 Not used in RIOT.
 
static void ble_npl_event_init (struct ble_npl_event *ev, ble_npl_event_fn *fn, void *arg)
 Init a event.
 
static bool ble_npl_event_is_queued (struct ble_npl_event *ev)
 Check if event is in queue.
 
static void * ble_npl_event_get_arg (struct ble_npl_event *ev)
 Runs an event.
 
static void ble_npl_event_set_arg (struct ble_npl_event *ev, void *arg)
 Set the vent arg.
 
static void ble_npl_event_run (struct ble_npl_event *ev)
 Runs an event.
 
static void ble_npl_eventq_init (struct ble_npl_eventq *evq)
 Initialize the event queue.
 
static int ble_npl_eventq_inited (struct ble_npl_eventq *evq)
 Check whether the event queue is initialized.
 
static void ble_npl_eventq_deinit (struct ble_npl_eventq *evq)
 Deinitialize an event queue.
 
static struct ble_npl_eventble_npl_eventq_get (struct ble_npl_eventq *evq, ble_npl_time_t tmo)
 Get next event from event queue, blocking.
 
static struct ble_npl_eventble_npl_eventq_get_no_wait (struct ble_npl_eventq *evq)
 Get next event from event queue, non-blocking.
 
static void ble_npl_eventq_put (struct ble_npl_eventq *evq, struct ble_npl_event *ev)
 Put an event on the event queue.
 
static void ble_npl_eventq_remove (struct ble_npl_eventq *evq, struct ble_npl_event *ev)
 Remove an event from the queue.
 
static void ble_npl_eventq_run (struct ble_npl_eventq *evq)
 Gets and runs an event from the queue callback.
 
static bool ble_npl_eventq_is_empty (struct ble_npl_eventq *evq)
 Check if queue is empty.
 
static ble_npl_error_t ble_npl_mutex_init (struct ble_npl_mutex *mu)
 Initializes a mutex object.
 
static ble_npl_error_t ble_npl_mutex_pend (struct ble_npl_mutex *mu, ble_npl_time_t timeout)
 Pend (wait) for a mutex.
 
static ble_npl_error_t ble_npl_mutex_release (struct ble_npl_mutex *mu)
 Release a mutex.
 
static ble_npl_error_t ble_npl_sem_init (struct ble_npl_sem *sem, uint16_t tokens)
 Initialize a semaphore.
 
static ble_npl_error_t ble_npl_sem_pend (struct ble_npl_sem *sem, ble_npl_time_t timeout)
 Pend (wait) for a semaphore.
 
static ble_npl_error_t ble_npl_sem_release (struct ble_npl_sem *sem)
 Release a semaphore.
 
static uint16_t ble_npl_sem_get_count (struct ble_npl_sem *sem)
 Get current semaphore's count.
 
static void ble_npl_callout_init (struct ble_npl_callout *c, struct ble_npl_eventq *q, ble_npl_event_fn *e_cb, void *e_arg)
 Initialize a callout.
 
static ble_npl_error_t ble_npl_callout_reset (struct ble_npl_callout *c, ble_npl_time_t ticks)
 Reset the callout to fire off in 'ticks' ticks.
 
static void ble_npl_callout_stop (struct ble_npl_callout *c)
 Stops the callout from firing.
 
static bool ble_npl_callout_is_active (struct ble_npl_callout *c)
 Check if callout is active.
 
static ble_npl_time_t ble_npl_callout_get_ticks (struct ble_npl_callout *co)
 Get the callout set ticks.
 
static ble_npl_time_t ble_npl_callout_remaining_ticks (struct ble_npl_callout *co, ble_npl_time_t time)
 Get the remaining ticks for callout expire.
 
static void ble_npl_callout_set_arg (struct ble_npl_callout *co, void *arg)
 Set the callout event argument.
 
static ble_npl_time_t ble_npl_time_get (void)
 Returns the low 32 bits of cputime.
 
static ble_npl_error_t ble_npl_time_ms_to_ticks (uint32_t ms, ble_npl_time_t *out_ticks)
 Converts the given number of milliseconds into cputime ticks.
 
static ble_npl_error_t ble_npl_time_ticks_to_ms (ble_npl_time_t ticks, uint32_t *out_ms)
 Convert the given number of ticks into milliseconds.
 
static ble_npl_time_t ble_npl_time_ms_to_ticks32 (uint32_t ms)
 Converts the given number of milliseconds into cputime ticks.
 
static ble_npl_time_t ble_npl_time_ticks_to_ms32 (ble_npl_time_t ticks)
 Convert the given number of ticks into milliseconds.
 
static void ble_npl_time_delay (ble_npl_time_t ticks)
 Wait until the number of ticks has elapsed, BLOICKING.
 
static uint32_t ble_npl_hw_enter_critical (void)
 Disable ISRs.
 
static void ble_npl_hw_exit_critical (uint32_t ctx)
 Restores ISR context.
 
static bool ble_npl_hw_is_in_critical (void)
 Check if is in critical section.
 
static void * ble_npl_get_current_task_id (void)
 Return current thread PID.
 
static void ble_npl_hw_set_isr (int irqn, void(*addr)(void))
 Set nrf5x radio ISR callback.
 

BLE NPL layer macros

#define BLE_NPL_OS_ALIGNMENT   (OS_ALIGNMENT)
 
#define BLE_NPL_TIME_FOREVER   (OS_WAIT_FOREVER)
 

Macro Definition Documentation

◆ BLE_NPL_OS_ALIGNMENT

#define BLE_NPL_OS_ALIGNMENT   (OS_ALIGNMENT)

Definition at line 40 of file nimble_npl_os.h.

◆ BLE_NPL_TIME_FOREVER

#define BLE_NPL_TIME_FOREVER   (OS_WAIT_FOREVER)

Definition at line 41 of file nimble_npl_os.h.

Typedef Documentation

◆ ble_npl_stime_t

typedef int32_t ble_npl_stime_t

time type

Definition at line 51 of file nimble_npl_os.h.

◆ ble_npl_time_t

typedef uint32_t ble_npl_time_t

time type

Definition at line 47 of file nimble_npl_os.h.

Function Documentation

◆ ble_npl_callout_get_ticks()

static ble_npl_time_t ble_npl_callout_get_ticks ( struct ble_npl_callout co)
inlinestatic

Get the callout set ticks.

Parameters
[in]cothe callout to check

Definition at line 419 of file nimble_npl_os.h.

◆ ble_npl_callout_init()

static void ble_npl_callout_init ( struct ble_npl_callout c,
struct ble_npl_eventq q,
ble_npl_event_fn *  e_cb,
void *  e_arg 
)
inlinestatic

Initialize a callout.

Callouts are used to schedule events in the future onto an event queue. Callout timers are scheduled using the ble_npl_callout_reset() function. When the timer expires, an event is posted to the event queue specified in ble_npl_callout_init(). The event argument given here is posted in the ev_arg field of that event.

Parameters
[out]ccallout to initialize
[in]qevent queue to queue event in
[in]e_cbcallback function
[in]e_argcallback function argument

Definition at line 368 of file nimble_npl_os.h.

◆ ble_npl_callout_is_active()

static bool ble_npl_callout_is_active ( struct ble_npl_callout c)
inlinestatic

Check if callout is active.

Parameters
[in]cthe callout to check
Returns
true if active, false otherwise

Definition at line 409 of file nimble_npl_os.h.

◆ ble_npl_callout_remaining_ticks()

static ble_npl_time_t ble_npl_callout_remaining_ticks ( struct ble_npl_callout co,
ble_npl_time_t  time 
)
inlinestatic

Get the remaining ticks for callout expire.

Parameters
[in]cothe callout to check
[in]timeignored
Returns
remaining ticks

Definition at line 432 of file nimble_npl_os.h.

◆ ble_npl_callout_reset()

static ble_npl_error_t ble_npl_callout_reset ( struct ble_npl_callout c,
ble_npl_time_t  ticks 
)
inlinestatic

Reset the callout to fire off in 'ticks' ticks.

Parameters
[in]ccallout to reset
[in]ticksnumber of ticks to wait before posting an event
Returns
0 on success, non-zero on failure

Definition at line 382 of file nimble_npl_os.h.

◆ ble_npl_callout_set_arg()

static void ble_npl_callout_set_arg ( struct ble_npl_callout co,
void *  arg 
)
inlinestatic

Set the callout event argument.

Parameters
[in]cothe callout
[in]argcallback function argument

Definition at line 446 of file nimble_npl_os.h.

◆ ble_npl_callout_stop()

static void ble_npl_callout_stop ( struct ble_npl_callout c)
inlinestatic

Stops the callout from firing.

Parameters
[in]cthe callout to stop

Definition at line 397 of file nimble_npl_os.h.

◆ ble_npl_event_get_arg()

static void * ble_npl_event_get_arg ( struct ble_npl_event ev)
inlinestatic

Runs an event.

Parameters
[in]evevent to run

Definition at line 129 of file nimble_npl_os.h.

◆ ble_npl_event_init()

static void ble_npl_event_init ( struct ble_npl_event ev,
ble_npl_event_fn *  fn,
void *  arg 
)
inlinestatic

Init a event.

Parameters
[in]evpointer to event to set
[in]fnevent callback function
[in]argevent argument

Definition at line 106 of file nimble_npl_os.h.

◆ ble_npl_event_is_queued()

static bool ble_npl_event_is_queued ( struct ble_npl_event ev)
inlinestatic

Check if event is in queue.

Parameters
[in]evevent to check
Returns
true if event is queues, false otherwise

Definition at line 119 of file nimble_npl_os.h.

◆ ble_npl_event_run()

static void ble_npl_event_run ( struct ble_npl_event ev)
inlinestatic

Runs an event.

Parameters
[in]evevent to run

Definition at line 150 of file nimble_npl_os.h.

◆ ble_npl_event_set_arg()

static void ble_npl_event_set_arg ( struct ble_npl_event ev,
void *  arg 
)
inlinestatic

Set the vent arg.

Parameters
[in]evevent
[in]argarg to set event

Definition at line 140 of file nimble_npl_os.h.

◆ ble_npl_eventq_deinit()

static void ble_npl_eventq_deinit ( struct ble_npl_eventq evq)
inlinestatic

Deinitialize an event queue.

Note
Not supported in RIOT
Parameters
[in]evqthe event queue to deinit

Definition at line 182 of file nimble_npl_os.h.

◆ ble_npl_eventq_get()

static struct ble_npl_event * ble_npl_eventq_get ( struct ble_npl_eventq evq,
ble_npl_time_t  tmo 
)
inlinestatic

Get next event from event queue, blocking.

Parameters
[in]evqthe event queue to pull an event from
[in]tmotimeout, NPL_TIME_FOREVER to block, 0 to return immediately
Returns
the event from the queue

Definition at line 196 of file nimble_npl_os.h.

◆ ble_npl_eventq_get_no_wait()

static struct ble_npl_event * ble_npl_eventq_get_no_wait ( struct ble_npl_eventq evq)
inlinestatic

Get next event from event queue, non-blocking.

Parameters
[in]evqthe event queue to pull an event from
Returns
event from the queue, or NULL if none available.

Definition at line 209 of file nimble_npl_os.h.

◆ ble_npl_eventq_init()

static void ble_npl_eventq_init ( struct ble_npl_eventq evq)
inlinestatic

Initialize the event queue.

Parameters
[in]evqThe event queue to initialize

Definition at line 160 of file nimble_npl_os.h.

◆ ble_npl_eventq_inited()

static int ble_npl_eventq_inited ( struct ble_npl_eventq evq)
inlinestatic

Check whether the event queue is initialized.

Parameters
[in]evqthe event queue to check

Definition at line 170 of file nimble_npl_os.h.

◆ ble_npl_eventq_is_empty()

static bool ble_npl_eventq_is_empty ( struct ble_npl_eventq evq)
inlinestatic

Check if queue is empty.

Parameters
[in]evqthe event queue to check
Returns
true if empty, false otherwise

Definition at line 253 of file nimble_npl_os.h.

◆ ble_npl_eventq_put()

static void ble_npl_eventq_put ( struct ble_npl_eventq evq,
struct ble_npl_event ev 
)
inlinestatic

Put an event on the event queue.

Parameters
[in]evqevent queue
[in]evevent to put in queue

Definition at line 220 of file nimble_npl_os.h.

◆ ble_npl_eventq_remove()

static void ble_npl_eventq_remove ( struct ble_npl_eventq evq,
struct ble_npl_event ev 
)
inlinestatic

Remove an event from the queue.

Parameters
[in]evqevent queue to remove the event from
[in]evevent to remove from the queue

Definition at line 231 of file nimble_npl_os.h.

◆ ble_npl_eventq_run()

static void ble_npl_eventq_run ( struct ble_npl_eventq evq)
inlinestatic

Gets and runs an event from the queue callback.

Parameters
[in]evqThe event queue to pull the item off.

Definition at line 241 of file nimble_npl_os.h.

◆ ble_npl_get_current_task_id()

static void * ble_npl_get_current_task_id ( void  )
inlinestatic

Return current thread PID.

Returns
PID

Definition at line 555 of file nimble_npl_os.h.

◆ ble_npl_hw_enter_critical()

static uint32_t ble_npl_hw_enter_critical ( void  )
inlinestatic

Disable ISRs.

Returns
current isr context

Definition at line 525 of file nimble_npl_os.h.

◆ ble_npl_hw_exit_critical()

static void ble_npl_hw_exit_critical ( uint32_t  ctx)
inlinestatic

Restores ISR context.

Parameters
[in]ctxISR context to restore.

Definition at line 535 of file nimble_npl_os.h.

◆ ble_npl_hw_is_in_critical()

static bool ble_npl_hw_is_in_critical ( void  )
inlinestatic

Check if is in critical section.

Returns
true, if in critical section, false otherwise

Definition at line 545 of file nimble_npl_os.h.

◆ ble_npl_hw_set_isr()

static void ble_npl_hw_set_isr ( int  irqn,
void(*)(void)  addr 
)
inlinestatic

Set nrf5x radio ISR callback.

Parameters
[in]irqnIRQ number
[in]addrthe ISR callback

Definition at line 566 of file nimble_npl_os.h.

◆ ble_npl_mutex_init()

static ble_npl_error_t ble_npl_mutex_init ( struct ble_npl_mutex mu)
inlinestatic

Initializes a mutex object.

Parameters
[out]mupre-allocated mutex structure, must not be NULL.

Definition at line 263 of file nimble_npl_os.h.

◆ ble_npl_mutex_pend()

static ble_npl_error_t ble_npl_mutex_pend ( struct ble_npl_mutex mu,
ble_npl_time_t  timeout 
)
inlinestatic

Pend (wait) for a mutex.

Parameters
[in]muPointer to mutex.
[in]timeoutTimeout, in os ticks. A timeout of 0 means do not wait if not available. A timeout of OS_TIMEOUT_NEVER means wait forever.
Returns
ble_npl_error_t BLE_NPL_INVALID_PARM mutex passed in was NULL BLE_NPL_OK no error

Definition at line 280 of file nimble_npl_os.h.

◆ ble_npl_mutex_release()

static ble_npl_error_t ble_npl_mutex_release ( struct ble_npl_mutex mu)
inlinestatic

Release a mutex.

Returns
ble_npl_error_t BLE_NPL_INVALID_PARM mutex was NULL BLE_NPL_OK no error

Definition at line 293 of file nimble_npl_os.h.

◆ ble_npl_os_started()

static bool ble_npl_os_started ( void  )
inlinestatic

Not used in RIOT.

Returns
Always true

Definition at line 94 of file nimble_npl_os.h.

◆ ble_npl_sem_get_count()

static uint16_t ble_npl_sem_get_count ( struct ble_npl_sem sem)
inlinestatic

Get current semaphore's count.

Definition at line 349 of file nimble_npl_os.h.

◆ ble_npl_sem_init()

static ble_npl_error_t ble_npl_sem_init ( struct ble_npl_sem sem,
uint16_t  tokens 
)
inlinestatic

Initialize a semaphore.

Parameters
[in]sempointer to semaphore
[in]tokens# of tokens the semaphore should contain initially.
Returns
ble_npl_error_t BLE_NPL_INVALID_PARM Semaphore passed in was NULL. BLE_NPL_OK no error.

Definition at line 308 of file nimble_npl_os.h.

◆ ble_npl_sem_pend()

static ble_npl_error_t ble_npl_sem_pend ( struct ble_npl_sem sem,
ble_npl_time_t  timeout 
)
inlinestatic

Pend (wait) for a semaphore.

Parameters
[in]sempointer to semaphore.
[in]timeouttimeout, in os ticks. A timeout of 0 means do not wait if not available. A timeout of BLE_NPL_TIMEOUT_NEVER means wait forever.
Returns
ble_npl_error_t BLE_NPL_INVALID_PARM semaphore passed in was NULL. BLE_NPL_TIMEOUT semaphore was owned by another task and timeout=0 BLE_NPL_OK no error

Definition at line 327 of file nimble_npl_os.h.

◆ ble_npl_sem_release()

static ble_npl_error_t ble_npl_sem_release ( struct ble_npl_sem sem)
inlinestatic

Release a semaphore.

Parameters
[in]sempointer to the semaphore to be released
Returns
ble_npl_error_t BLE_NPL_INVALID_PARM semaphore passed in was NULL. BLE_NPL_OK no error

Definition at line 341 of file nimble_npl_os.h.

◆ ble_npl_time_delay()

static void ble_npl_time_delay ( ble_npl_time_t  ticks)
inlinestatic

Wait until the number of ticks has elapsed, BLOICKING.

Parameters
[in]ticksThe number of ticks to wait.

Definition at line 515 of file nimble_npl_os.h.

◆ ble_npl_time_get()

static ble_npl_time_t ble_npl_time_get ( void  )
inlinestatic

Returns the low 32 bits of cputime.

Returns
uint32_t The lower 32 bits of cputime

Definition at line 456 of file nimble_npl_os.h.

◆ ble_npl_time_ms_to_ticks()

static ble_npl_error_t ble_npl_time_ms_to_ticks ( uint32_t  ms,
ble_npl_time_t out_ticks 
)
inlinestatic

Converts the given number of milliseconds into cputime ticks.

Parameters
[in]msThe number of milliseconds to convert to ticks
[out]out_ticksThe number of ticks corresponding to 'ms'
Returns
ble_npl_error_t BLE_NPL_OK - no error

Definition at line 469 of file nimble_npl_os.h.

◆ ble_npl_time_ms_to_ticks32()

static ble_npl_time_t ble_npl_time_ms_to_ticks32 ( uint32_t  ms)
inlinestatic

Converts the given number of milliseconds into cputime ticks.

Parameters
[in]msThe number of milliseconds to convert to ticks
Returns
uint32_t The number of ticks corresponding to 'ms'

Definition at line 494 of file nimble_npl_os.h.

◆ ble_npl_time_ticks_to_ms()

static ble_npl_error_t ble_npl_time_ticks_to_ms ( ble_npl_time_t  ticks,
uint32_t *  out_ms 
)
inlinestatic

Convert the given number of ticks into milliseconds.

Parameters
[in]ticksThe number of ticks to convert to milliseconds.
[out]out_msThe converted milliseconds from 'ticks'
Returns
ble_npl_error_t BLE_NPL_OK - no error

Definition at line 482 of file nimble_npl_os.h.

◆ ble_npl_time_ticks_to_ms32()

static ble_npl_time_t ble_npl_time_ticks_to_ms32 ( ble_npl_time_t  ticks)
inlinestatic

Convert the given number of ticks into milliseconds.

Parameters
[in]ticksThe number of ticks to convert to milliseconds.
Returns
uint32_t The number of milliseconds corresponding to 'ticks'

Definition at line 506 of file nimble_npl_os.h.