|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
NimBLE Native Porting Layer mapping onto Eclipse ThreadX. More...
#include "nimble_npl_threadx.h"#include <stdint.h>#include <string.h>#include "nimble_transport_stubs.h"#include "ra8_attributes.h"#include "tx_api.h"Go to the source code of this file.
Enumerations | |
| enum | ble_npl_threadx_const_t : uint32_t { k_ble_npl_tx_wait_forever = 0xFFFFFFFFU , k_ble_npl_tx_no_wait = 0U , k_ble_npl_ms_per_sec = 1000U } |
| Local sizing/timeout constants. More... | |
Functions | |
| 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_mutex_init (struct ble_npl_mutex *mu) |
| ble_npl_error_t | ble_npl_mutex_pend (struct ble_npl_mutex *mu, ble_npl_time_t timeout) |
| ble_npl_error_t | ble_npl_mutex_release (struct ble_npl_mutex *mu) |
| ble_npl_error_t | ble_npl_sem_init (struct ble_npl_sem *sem, uint16_t tokens) |
| ble_npl_error_t | ble_npl_sem_pend (struct ble_npl_sem *sem, ble_npl_time_t timeout) |
| ble_npl_error_t | ble_npl_sem_release (struct ble_npl_sem *sem) |
| uint16_t | ble_npl_sem_get_count (struct ble_npl_sem *sem) |
| void | ble_npl_event_init (struct ble_npl_event *ev, ble_npl_event_fn *fn, void *arg) |
| void | ble_npl_eventq_init (struct ble_npl_eventq *evq) |
| 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. | |
| void | ble_npl_eventq_put (struct ble_npl_eventq *evq, struct ble_npl_event *ev) |
| void | ble_npl_eventq_remove (struct ble_npl_eventq *evq, struct ble_npl_event *ev) |
| void | ble_npl_event_run (struct ble_npl_event *ev) |
| bool | ble_npl_event_is_queued (struct ble_npl_event *ev) |
| void * | ble_npl_event_get_arg (struct ble_npl_event *ev) |
| Read the user-arg pointer attached to an event. | |
| void | ble_npl_event_set_arg (struct ble_npl_event *ev, void *arg) |
| bool | ble_npl_eventq_is_empty (struct ble_npl_eventq *evq) |
| static void | internal_callout_trampoline (ULONG arg) |
| Post a callout event from the ThreadX timer trampoline. | |
| void | ble_npl_callout_init (struct ble_npl_callout *co, struct ble_npl_eventq *evq, ble_npl_event_fn *ev_cb, void *ev_arg) |
| ble_npl_error_t | ble_npl_callout_reset (struct ble_npl_callout *co, ble_npl_time_t ticks) |
| void | ble_npl_callout_stop (struct ble_npl_callout *co) |
| bool | ble_npl_callout_is_active (struct ble_npl_callout *co) |
| void | ble_npl_callout_set_arg (struct ble_npl_callout *co, void *arg) |
| ble_npl_time_t | ble_npl_time_get (void) |
| ble_npl_error_t | ble_npl_time_ms_to_ticks (uint32_t ms, ble_npl_time_t *out_ticks) |
| ble_npl_error_t | ble_npl_time_ticks_to_ms (ble_npl_time_t ticks, uint32_t *out_ms) |
| void | ble_npl_time_delay (ble_npl_time_t ticks) |
| uint32_t | ble_npl_hw_enter_critical (void) |
| void | ble_npl_hw_exit_critical (uint32_t ctx) |
| bool | ble_npl_hw_is_in_critical (void) |
| Test whether the calling context is inside a critical section. | |
| void | nimble_port_init (void) |
| Bring the NimBLE host port up. | |
| struct ble_npl_eventq * | nimble_port_get_dflt_eventq (void) |
| Return the address of the default eventq. | |
| void | nimble_port_run (void) |
| Run the NimBLE host event loop forever. | |
| 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. | |
| void | ble_transport_free (void *buf) |
| Release a buffer obtained from ble_transport_alloc_evt(). | |
| int | ble_transport_to_hs_evt (void *buf) |
| Push an HCI event up to the host stack. | |
| int | ble_transport_to_hs_acl (struct os_mbuf *om) |
| Push an ACL packet up to the host stack. | |
| int | os_mbuf_append (struct os_mbuf *om, const void *data, uint16_t len) |
| Append bytes to an mbuf chain (upstream os_mbuf.h). | |
| int | os_mbuf_free_chain (struct os_mbuf *om) |
| Free every mbuf in a chain. | |
| uint16_t | os_mbuf_len (const struct os_mbuf *om) |
| Total payload length of an mbuf chain. | |
| int | os_mbuf_copydata (const struct os_mbuf *om, int off, int len, void *dst) |
| Copy a byte range out of an mbuf chain. | |
| int | ble_transport_to_ll_cmd (void *buf) |
| Host-to-controller HCI command entry point. | |
| int | ble_transport_to_ll_acl (struct os_mbuf *om) |
| Host-to-controller ACL entry point. | |
Variables | |
| static struct ble_npl_eventq | s_dflt_eventq |
| Default eventq used by the host stack. | |
| static uint8_t | s_dflt_eventq_ready = 0U |
| Initialized flag for the default eventq. | |
NimBLE Native Porting Layer mapping onto Eclipse ThreadX.
Implementation of the NimBLE NPL primitives on top of ThreadX. Each ble_npl_* symbol delegates to the matching tx_* service. This file also carries small stubs of the upstream ble_transport_alloc_* / os_mbuf_* symbols so the per-app build can link our adapter even before the curated upstream NimBLE host TUs are wired into the build (the heavyweight host stack is opt-in via RA8_USE_NIMBLE_HOST – without it we still provide a link-only scaffold so the demo links).
Tick rate: TX_TIMER_TICKS_PER_SECOND = 1000 (see port/threadx/inc/tx_user.h), so 1 NPL tick == 1 ms.
Definition in file nimble_npl_threadx.c.
| enum ble_npl_threadx_const_t : uint32_t |
Local sizing/timeout constants.
| Enumerator | |
|---|---|
| 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. |
Definition at line 58 of file nimble_npl_threadx.c.
| void ble_npl_callout_init | ( | struct ble_npl_callout * | co, |
| struct ble_npl_eventq * | evq, | ||
| ble_npl_event_fn * | ev_cb, | ||
| void * | ev_arg ) |
Mutable timer name retained by the ThreadX control block.
Definition at line 343 of file nimble_npl_threadx.c.
References ble_npl_event::arg, ble_npl_callout::ev, ble_npl_callout::evq, ble_npl_event::fn, ble_npl_callout::handle, internal_callout_trampoline(), and memset().
| bool ble_npl_callout_is_active | ( | struct ble_npl_callout * | co | ) |
Definition at line 391 of file nimble_npl_threadx.c.
References ble_npl_callout::handle, and TX_SUCCESS.
| ble_npl_error_t ble_npl_callout_reset | ( | struct ble_npl_callout * | co, |
| ble_npl_time_t | ticks ) |
Definition at line 367 of file nimble_npl_threadx.c.
References ble_npl_callout::handle, and TX_SUCCESS.
| void ble_npl_callout_set_arg | ( | struct ble_npl_callout * | co, |
| void * | arg ) |
Definition at line 404 of file nimble_npl_threadx.c.
References ble_npl_event::arg, and ble_npl_callout::ev.
| void ble_npl_callout_stop | ( | struct ble_npl_callout * | co | ) |
Definition at line 382 of file nimble_npl_threadx.c.
References ble_npl_callout::handle.
| void * ble_npl_event_get_arg | ( | struct ble_npl_event * | ev | ) |
Read the user-arg pointer attached to an event.
| [in] | ev | NPL event pointer. |
Definition at line 286 of file nimble_npl_threadx.c.
References ble_npl_event::arg, and nullptr.
| void ble_npl_event_init | ( | struct ble_npl_event * | ev, |
| ble_npl_event_fn * | fn, | ||
| void * | arg ) |
Definition at line 185 of file nimble_npl_threadx.c.
References ble_npl_event::arg, ble_npl_event::fn, and memset().
| bool ble_npl_event_is_queued | ( | struct ble_npl_event * | ev | ) |
Definition at line 270 of file nimble_npl_threadx.c.
References ble_npl_event::queued.
| void ble_npl_event_run | ( | struct ble_npl_event * | ev | ) |
Definition at line 261 of file nimble_npl_threadx.c.
References ble_npl_event::fn.
Referenced by nimble_port_run().
| void ble_npl_event_set_arg | ( | struct ble_npl_event * | ev, |
| void * | arg ) |
Definition at line 292 of file nimble_npl_threadx.c.
References ble_npl_event::arg.
| 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.
| [in,out] | evq | NPL event queue pointer. |
| [in] | tmo | NPL ticks to wait; 0xFFFFU is forever. |
< U.
< Slot.
< Ev.
Definition at line 220 of file nimble_npl_threadx.c.
References internal_tmo_to_tx(), ble_npl_eventq::q, ble_npl_event::queued, and TX_SUCCESS.
Referenced by nimble_port_run().
| void ble_npl_eventq_init | ( | struct ble_npl_eventq * | evq | ) |
Mutable queue name retained by the ThreadX control block.
Definition at line 196 of file nimble_npl_threadx.c.
References memset(), ble_npl_eventq::q, and ble_npl_eventq::storage.
Referenced by nimble_port_init().
| bool ble_npl_eventq_is_empty | ( | struct ble_npl_eventq * | evq | ) |
Definition at line 300 of file nimble_npl_threadx.c.
References ble_npl_eventq::q, and TX_SUCCESS.
| void ble_npl_eventq_put | ( | struct ble_npl_eventq * | evq, |
| struct ble_npl_event * | ev ) |
Definition at line 237 of file nimble_npl_threadx.c.
References ble_npl_eventq::q, and ble_npl_event::queued.
Referenced by internal_callout_trampoline().
| void ble_npl_eventq_remove | ( | struct ble_npl_eventq * | evq, |
| struct ble_npl_event * | ev ) |
Definition at line 251 of file nimble_npl_threadx.c.
References ble_npl_event::queued.
| uint32_t ble_npl_hw_enter_critical | ( | void | ) |
Definition at line 455 of file nimble_npl_threadx.c.
| void ble_npl_hw_exit_critical | ( | uint32_t | ctx | ) |
Definition at line 461 of file nimble_npl_threadx.c.
| bool ble_npl_hw_is_in_critical | ( | void | ) |
Test whether the calling context is inside a critical section.
Best-effort: ThreadX does not expose a "primask read" helper, so we always report 0 (NimBLE uses this for assertions only).
| 0 | Success or default value. |
Definition at line 484 of file nimble_npl_threadx.c.
| ble_npl_error_t ble_npl_mutex_init | ( | struct ble_npl_mutex * | mu | ) |
Mutable mutex name retained by the ThreadX control block.
Definition at line 94 of file nimble_npl_threadx.c.
References ble_npl_mutex::handle, tx_mutex_create, TX_NO_INHERIT, and TX_SUCCESS.
| ble_npl_error_t ble_npl_mutex_pend | ( | struct ble_npl_mutex * | mu, |
| ble_npl_time_t | timeout ) |
Definition at line 106 of file nimble_npl_threadx.c.
References ble_npl_mutex::handle, internal_tmo_to_tx(), tx_mutex_get, and TX_SUCCESS.
| ble_npl_error_t ble_npl_mutex_release | ( | struct ble_npl_mutex * | mu | ) |
Definition at line 119 of file nimble_npl_threadx.c.
References ble_npl_mutex::handle, tx_mutex_put, and TX_SUCCESS.
| uint16_t ble_npl_sem_get_count | ( | struct ble_npl_sem * | sem | ) |
Definition at line 169 of file nimble_npl_threadx.c.
References ble_npl_sem::handle.
| ble_npl_error_t ble_npl_sem_init | ( | struct ble_npl_sem * | sem, |
| uint16_t | tokens ) |
Mutable semaphore name retained by the ThreadX control block.
Definition at line 134 of file nimble_npl_threadx.c.
References ble_npl_sem::handle, and TX_SUCCESS.
| ble_npl_error_t ble_npl_sem_pend | ( | struct ble_npl_sem * | sem, |
| ble_npl_time_t | timeout ) |
Definition at line 146 of file nimble_npl_threadx.c.
References ble_npl_sem::handle, internal_tmo_to_tx(), and TX_SUCCESS.
| ble_npl_error_t ble_npl_sem_release | ( | struct ble_npl_sem * | sem | ) |
Definition at line 159 of file nimble_npl_threadx.c.
References ble_npl_sem::handle, and TX_SUCCESS.
| void ble_npl_time_delay | ( | ble_npl_time_t | ticks | ) |
Definition at line 444 of file nimble_npl_threadx.c.
References tx_thread_sleep.
| ble_npl_time_t ble_npl_time_get | ( | void | ) |
Definition at line 417 of file nimble_npl_threadx.c.
References tx_time_get.
| ble_npl_error_t ble_npl_time_ms_to_ticks | ( | uint32_t | ms, |
| ble_npl_time_t * | out_ticks ) |
Definition at line 423 of file nimble_npl_threadx.c.
| ble_npl_error_t ble_npl_time_ticks_to_ms | ( | ble_npl_time_t | ticks, |
| uint32_t * | out_ms ) |
Definition at line 434 of file nimble_npl_threadx.c.
| struct os_mbuf * ble_transport_alloc_acl_from_ll | ( | void | ) |
Allocate an ACL mbuf for the LL-to-host direction.
Stub: no mbuf pool exists in the curated build.
| NULL | Always, in the stub build. |
Definition at line 581 of file nimble_npl_threadx.c.
Referenced by internal_acl_cb().
| void * ble_transport_alloc_evt | ( | int | discardable | ) |
Allocate an HCI event buffer (upstream ble_transport.h).
Stub: the curated build has no transport buffer pool, so the allocation always fails and the caller drops the event.
| [in] | discardable | Non-zero when the caller can tolerate a NULL return (low-priority event). Unused by the stub, kept for ABI parity with upstream. |
| NULL | Always, in the stub build. |
Definition at line 575 of file nimble_npl_threadx.c.
Referenced by internal_event_cb().
| void ble_transport_free | ( | void * | buf | ) |
Release a buffer obtained from ble_transport_alloc_evt().
Stub: nothing was ever allocated, so nothing is freed.
| [in] | buf | Buffer to release. May be NULL. |
buf came from ble_transport_alloc_evt() or is NULL. Definition at line 586 of file nimble_npl_threadx.c.
Referenced by ble_transport_to_ll_cmd_impl().
| int ble_transport_to_hs_acl | ( | struct os_mbuf * | om | ) |
Push an ACL packet up to the host stack.
Stub: the mbuf is dropped and success is reported.
| [in] | om | ACL mbuf chain to deliver. |
| 0 | Always, in the stub build. |
om is a valid mbuf chain. om passes to the transport. Definition at line 597 of file nimble_npl_threadx.c.
Referenced by internal_acl_cb().
| int ble_transport_to_hs_evt | ( | void * | buf | ) |
Push an HCI event up to the host stack.
Stub: the event is dropped and success is reported so the controller side does not treat the missing host as an error.
| [in] | buf | Event buffer from ble_transport_alloc_evt(). |
| 0 | Always, in the stub build. |
buf is a valid event buffer. buf passes to the transport. Definition at line 591 of file nimble_npl_threadx.c.
Referenced by internal_event_cb().
| int ble_transport_to_ll_acl | ( | struct os_mbuf * | om | ) |
Host-to-controller ACL entry point.
Stub wrapper: forwards straight to ble_transport_to_ll_acl_impl().
| [in] | om | ACL mbuf chain to send. |
| 0 | Packet accepted by the controller side. |
om is a valid ACL mbuf chain. om passes to the controller side. Definition at line 637 of file nimble_npl_threadx.c.
References ble_transport_to_ll_acl_impl().
| int ble_transport_to_ll_cmd | ( | void * | buf | ) |
Host-to-controller HCI command entry point.
Stub wrapper: forwards straight to ble_transport_to_ll_cmd_impl() so an app that bypasses the upstream transport core still reaches this port's controller side.
| [in] | buf | HCI command buffer. |
| 0 | Command accepted by the controller side. |
buf holds a well-formed HCI command. buf passes to the controller side. Definition at line 632 of file nimble_npl_threadx.c.
References ble_transport_to_ll_cmd_impl().
|
static |
Post a callout event from the ThreadX timer trampoline.
Recovers the caller-owned NPL callout from the timer argument and queues its embedded event when the recovered pointer is valid.
| [in] | arg | Integer representation of the callout pointer supplied at timer creation. |
arg identifies a live caller-owned callout object. Definition at line 333 of file nimble_npl_threadx.c.
References ble_npl_eventq_put(), ble_npl_callout::ev, ble_npl_callout::evq, and RA8_INTERNAL.
Referenced by ble_npl_callout_init().
|
static |
Translate an NPL timeout into a ThreadX wait code.
Preserves finite tick counts and maps the NPL forever sentinel to ThreadX's exact wait-forever value.
| [in] | tmo | NPL timeout value to translate. |
tmo. | TX_WAIT_FOREVER | The input requested an unbounded wait. |
tmo is a value accepted by the calling NPL primitive. Definition at line 80 of file nimble_npl_threadx.c.
References k_ble_npl_threadx_wait_forever, k_ble_npl_tx_wait_forever, and RA8_INTERNAL.
Referenced by ble_npl_eventq_get(), ble_npl_mutex_pend(), and ble_npl_sem_pend().
| struct ble_npl_eventq * nimble_port_get_dflt_eventq | ( | void | ) |
Return the address of the default eventq.
Return the host's default eventq pointer.
< S dflt eventq.
Definition at line 530 of file nimble_npl_threadx.c.
References s_dflt_eventq.
| void nimble_port_init | ( | void | ) |
Bring the NimBLE host port up.
Initialises the default eventq used by the host stack. The adapter implementation lives in nimble_npl_threadx.c and is marked weak so the upstream NimBLE host TUs can supersede it once they are wired into the build.
Definition at line 512 of file nimble_npl_threadx.c.
References ble_npl_eventq_init(), s_dflt_eventq, and s_dflt_eventq_ready.
Referenced by internal_demo_ble_or_halt().
| void nimble_port_run | ( | void | ) |
Run the NimBLE host event loop forever.
Pump the NimBLE host event loop forever.
Pumps events out of the default eventq; never returns under normal operation.
Definition at line 550 of file nimble_npl_threadx.c.
References ble_npl_event_run(), ble_npl_eventq_get(), k_ble_npl_threadx_wait_forever, and s_dflt_eventq.
| int os_mbuf_append | ( | struct os_mbuf * | om, |
| const void * | data, | ||
| uint16_t | len ) |
Append bytes to an mbuf chain (upstream os_mbuf.h).
Stub: no mbuf pool exists, so the append is a no-op.
| [in,out] | om | Chain to append to. |
| [in] | data | Bytes to copy in. |
| [in] | len | Number of bytes at data. |
| 0 | Always, in the stub build. |
om and data are valid for len bytes. om is unchanged in the stub build. Definition at line 603 of file nimble_npl_threadx.c.
Referenced by internal_acl_cb().
| int os_mbuf_copydata | ( | const struct os_mbuf * | om, |
| int | off, | ||
| int | len, | ||
| void * | dst ) |
Copy a byte range out of an mbuf chain.
Stub: copies nothing and reports success.
| [in] | om | Chain to read from. |
| [in] | off | Byte offset into the chain payload. |
| [in] | len | Number of bytes to copy. |
| [out] | dst | Destination buffer, at least len bytes. |
| 0 | Always, in the stub build. |
dst is writable for len bytes. off and len lie inside the chain payload. dst is untouched in the stub build. om is not modified.Definition at line 623 of file nimble_npl_threadx.c.
Referenced by ble_transport_to_ll_acl_impl().
| int os_mbuf_free_chain | ( | struct os_mbuf * | om | ) |
Free every mbuf in a chain.
Stub: nothing was allocated, so nothing is freed.
| [in] | om | Head of the chain to release. May be NULL. |
| 0 | Always, in the stub build. |
om is a chain head or NULL. om. Definition at line 611 of file nimble_npl_threadx.c.
Referenced by ble_transport_to_ll_acl_impl(), ble_transport_to_ll_iso_impl(), and internal_acl_cb().
| uint16_t os_mbuf_len | ( | const struct os_mbuf * | om | ) |
Total payload length of an mbuf chain.
Stub: reports an empty chain.
| [in] | om | Chain to measure. May be NULL. |
| 0 | Always, in the stub build. |
om is a chain head or NULL. om is not modified. Definition at line 617 of file nimble_npl_threadx.c.
Referenced by ble_transport_to_ll_acl_impl().
|
static |
Default eventq used by the host stack.
Lives in BSS; ble_npl_eventq_init is called once at boot. Surfaced via nimble_port_get_dflt_eventq.
Definition at line 506 of file nimble_npl_threadx.c.
Referenced by nimble_port_get_dflt_eventq(), nimble_port_init(), and nimble_port_run().
|
static |
Initialized flag for the default eventq.
Definition at line 509 of file nimble_npl_threadx.c.
Referenced by nimble_port_init().