58typedef enum : uint32_t {
97 return BLE_NPL_INVALID_PARAM;
100 static CHAR s_name[] = {
'n',
'p',
'l',
'_',
'm',
'u',
'\0'};
102 return (st ==
TX_SUCCESS) ? BLE_NPL_OK : BLE_NPL_ERROR;
109 return BLE_NPL_INVALID_PARAM;
115 return (st == TX_NOT_AVAILABLE) ? BLE_NPL_TIMEOUT : BLE_NPL_ERROR;
122 return BLE_NPL_INVALID_PARAM;
125 return (st ==
TX_SUCCESS) ? BLE_NPL_OK : BLE_NPL_ERROR;
136 if (sem ==
nullptr) {
137 return BLE_NPL_INVALID_PARAM;
140 static CHAR s_name[] = {
'n',
'p',
'l',
'_',
's',
'e',
'm',
'\0'};
141 const UINT st = tx_semaphore_create(&sem->
handle, s_name, (
ULONG)tokens);
142 return (st ==
TX_SUCCESS) ? BLE_NPL_OK : BLE_NPL_ERROR;
148 if (sem ==
nullptr) {
149 return BLE_NPL_INVALID_PARAM;
155 return (st == TX_NO_INSTANCE) ? BLE_NPL_TIMEOUT : BLE_NPL_ERROR;
161 if (sem ==
nullptr) {
162 return BLE_NPL_INVALID_PARAM;
164 const UINT st = tx_semaphore_put(&sem->
handle);
165 return (st ==
TX_SUCCESS) ? BLE_NPL_OK : BLE_NPL_ERROR;
171 if (sem ==
nullptr) {
175 (void)tx_semaphore_info_get(&sem->
handle,
nullptr, ¤t,
nullptr,
nullptr,
nullptr);
176 return (uint16_t)current;
190 (void)
memset(ev, 0,
sizeof(*ev));
198 if (evq ==
nullptr) {
201 (void)
memset(evq, 0,
sizeof(*evq));
203 static CHAR s_name[] = {
'n',
'p',
'l',
'_',
'e',
'v',
'q',
'\0'};
222 if (evq ==
nullptr) {
239 if (evq ==
nullptr || ev ==
nullptr) {
247 (void)tx_queue_send(&evq->
q, &slot, TX_NO_WAIT);
263 if (ev ==
nullptr || ev->
fn ==
nullptr) {
272 return (ev !=
nullptr) && (ev->
queued != 0U);
302 if (evq ==
nullptr) {
306 if (tx_queue_info_get(&evq->
q,
nullptr, &enqueued,
nullptr,
nullptr,
nullptr,
nullptr) !=
310 return enqueued == 0U;
345 ble_npl_event_fn* ev_cb,
351 (void)
memset(co, 0,
sizeof(*co));
356 static CHAR s_name[] = {
'n',
'p',
'l',
'_',
'c',
'o',
'\0'};
357 (void)tx_timer_create(&co->
handle,
360 (
ULONG)(uintptr_t)co,
370 return BLE_NPL_INVALID_PARAM;
375 (void)tx_timer_deactivate(&co->
handle);
376 (void)tx_timer_change(&co->
handle, (
ULONG)ticks, 0U);
377 const UINT st = tx_timer_activate(&co->
handle);
378 return (st ==
TX_SUCCESS) ? BLE_NPL_OK : BLE_NPL_ERROR;
387 (void)tx_timer_deactivate(&co->
handle);
397 if (tx_timer_info_get(&co->
handle,
nullptr, &active,
nullptr,
nullptr,
nullptr) !=
TX_SUCCESS) {
425 if (out_ticks ==
nullptr) {
426 return BLE_NPL_INVALID_PARAM;
436 if (out_ms ==
nullptr) {
437 return BLE_NPL_INVALID_PARAM;
439 *out_ms = (uint32_t)ticks;
457 return (uint32_t)tx_interrupt_control(TX_INT_DISABLE);
463 (void)tx_interrupt_control((
UINT)ctx);
603[[gnu::weak]]
int os_mbuf_append(
struct os_mbuf* om,
const void* data, uint16_t len)
uint32_t ble_npl_time_t
Tick-count type used by the NPL.
void ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg)
struct ble_npl_eventq * nimble_port_get_dflt_eventq(void)
Return the address of the default eventq.
ble_npl_time_t ble_npl_time_get(void)
void ble_npl_eventq_remove(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
static struct ble_npl_eventq s_dflt_eventq
Default eventq used by the host stack.
bool ble_npl_hw_is_in_critical(void)
Test whether the calling context is inside a critical section.
struct ble_npl_event * ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
Wait for an event from an NPL event queue.
static ULONG internal_tmo_to_tx(ble_npl_time_t tmo)
Translate an NPL timeout into a ThreadX wait code.
ble_npl_error_t ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
void ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg)
int ble_transport_to_hs_acl(struct os_mbuf *om)
Push an ACL packet up to the host stack.
void nimble_port_run(void)
Run the NimBLE host event loop forever.
void * ble_npl_event_get_arg(struct ble_npl_event *ev)
Read the user-arg pointer attached to an event.
void nimble_port_init(void)
Bring the NimBLE host port up.
void ble_npl_callout_stop(struct ble_npl_callout *co)
void ble_npl_hw_exit_critical(uint32_t ctx)
static uint8_t s_dflt_eventq_ready
Initialized flag for the default eventq.
int os_mbuf_free_chain(struct os_mbuf *om)
Free every mbuf in a chain.
void ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn, void *arg)
void ble_transport_free(void *buf)
Release a buffer obtained from ble_transport_alloc_evt().
ble_npl_error_t ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout)
uint16_t os_mbuf_len(const struct os_mbuf *om)
Total payload length of an mbuf chain.
void ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, ble_npl_event_fn *ev_cb, void *ev_arg)
int ble_transport_to_ll_cmd(void *buf)
Host-to-controller HCI command entry point.
bool ble_npl_event_is_queued(struct ble_npl_event *ev)
int ble_transport_to_ll_acl(struct os_mbuf *om)
Host-to-controller ACL entry point.
int os_mbuf_copydata(const struct os_mbuf *om, int off, int len, void *dst)
Copy a byte range out of an mbuf chain.
void ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
ble_npl_error_t ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
void ble_npl_eventq_init(struct ble_npl_eventq *evq)
uint32_t ble_npl_hw_enter_critical(void)
void ble_npl_time_delay(ble_npl_time_t ticks)
ble_npl_error_t ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout)
ble_npl_error_t ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
int os_mbuf_append(struct os_mbuf *om, const void *data, uint16_t len)
Append bytes to an mbuf chain (upstream os_mbuf.h).
static void internal_callout_trampoline(ULONG arg)
Post a callout event from the ThreadX timer trampoline.
int ble_transport_to_hs_evt(void *buf)
Push an HCI event up to the host stack.
void * ble_transport_alloc_evt(int discardable)
Allocate an HCI event buffer (upstream ble_transport.h).
struct os_mbuf * ble_transport_alloc_acl_from_ll(void)
Allocate an ACL mbuf for the LL-to-host direction.
bool ble_npl_callout_is_active(struct ble_npl_callout *co)
void ble_npl_event_run(struct ble_npl_event *ev)
uint16_t ble_npl_sem_get_count(struct ble_npl_sem *sem)
ble_npl_error_t ble_npl_sem_release(struct ble_npl_sem *sem)
bool ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
ble_npl_error_t ble_npl_mutex_init(struct ble_npl_mutex *mu)
ble_npl_error_t ble_npl_mutex_release(struct ble_npl_mutex *mu)
ble_npl_threadx_const_t
Local sizing/timeout constants.
@ k_ble_npl_tx_wait_forever
TX_WAIT_FOREVER literal.
@ k_ble_npl_tx_no_wait
TX_NO_WAIT literal.
@ k_ble_npl_ms_per_sec
Helper: ms / second.
ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
NimBLE Native Porting Layer mapping onto Eclipse ThreadX.
@ k_ble_npl_threadx_wait_forever
Wait forever – maps onto TX_WAIT_FOREVER.
Weak link stubs standing in for the NimBLE transport core.
int ble_transport_to_ll_cmd_impl(void *buf)
Controller-side handler for an HCI command from the host.
int ble_transport_to_ll_acl_impl(struct os_mbuf *om)
Controller-side handler for an ACL packet from the host.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
char CHAR
ThreadX-compatible CHAR (host stub).
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
One-shot timer that posts an event into a queue when it fires.
struct ble_npl_event ev
Event posted on each firing.
TX_TIMER handle
Backing ThreadX one-shot timer.
struct ble_npl_eventq * evq
Queue to post the event into.
NimBLE event opaque – pairs a callback with an argument.
ble_npl_event_fn * fn
Callback invoked by ble_npl_event_run.
uint8_t queued
1 while sitting in an evq, 0 otherwise.
void * arg
Opaque user argument passed to fn().
Event queue mapped onto TX_QUEUE.
TX_QUEUE q
Backing ThreadX queue.
uint8_t storage[64]
Backing storage (16 entries * 4 bytes).
Mutex mapped onto TX_MUTEX.
TX_MUTEX handle
Backing ThreadX mutex.
Counting semaphore mapped onto TX_SEMAPHORE.
TX_SEMAPHORE handle
Backing ThreadX counting semaphore.