52#define RA8_ESP_HOSTED_TX_SHIM_IMPL
53#include "ra8_esp_hosted_tx_shim_internal.h"
68static const char*
s_tag =
"ESPH_MEM";
85typedef enum : uint32_t {
119 "allocation header must fit the documented 16-byte slot");
235 if (tx_byte_pool_create(&
s_pool.transport,
242 if (tx_byte_pool_create(&
s_pool.queue_pool,
246 (void)tx_byte_pool_delete(&
s_pool.transport);
263 if (!
s_pool.queues[i].used) {
272 s_pool.queues[i].used =
false;
286 ULONG available = 0U;
287 ULONG fragments = 0U;
289 (void)tx_byte_pool_info_get(&
s_pool.transport,
297 if (out_available !=
nullptr) {
298 *out_available = (uint32_t)available;
300 if (out_fragments !=
nullptr) {
301 *out_fragments = (uint32_t)fragments;
314 ((align & (align - 1U)) != 0U)) {
317 void* base =
nullptr;
329 if ((tx_byte_allocate(&
s_pool.transport, &base, total, TX_NO_WAIT) !=
TX_SUCCESS) ||
334 const uintptr_t aligned = (raw + (uintptr_t)align - 1U) & ~((uintptr_t)align - 1U);
338 hdr.
size = (uint32_t)size;
340 return (
void*)aligned;
371 *out_size = (size_t)hdr.
size;
378 const uint32_t words = (item_bytes + (word - 1U)) / word;
409 if ((dest ==
nullptr) || (src ==
nullptr)) {
412 return memcpy(dest, src, (
size_t)size);
435 if (buf ==
nullptr) {
438 return memset(buf, val, len);
481 if ((blk_no == 0U) || (size == 0U)) {
490 (void)
memset(p, 0, blk_no * size);
535 if (mem ==
nullptr) {
547 if (fresh ==
nullptr) {
550 (void)
memcpy(fresh, mem, (oldsize < newsize) ? oldsize : newsize);
619 if ((handle ==
nullptr) || !
s_pool.ready) {
623 if ((handle == (
const void*)&
s_pool.queues[i]) &&
s_pool.queues[i].used) {
651 if (!
s_pool.ready || (words == 0U)) {
658 if (
s_pool.queues[i].used) {
661 void* ring =
nullptr;
663 if (tx_byte_allocate(&
s_pool.queue_pool, &ring, bytes, TX_NO_WAIT) !=
TX_SUCCESS) {
668 (void)tx_byte_release(ring);
671 s_pool.queues[i].storage = ring;
672 s_pool.queues[i].enqueued = 0U;
673 s_pool.queues[i].used =
true;
704 if ((slot ==
nullptr) || (item ==
nullptr)) {
740 if ((slot ==
nullptr) || (item ==
nullptr)) {
773 if (slot ==
nullptr) {
799 if (slot ==
nullptr) {
829 if (slot ==
nullptr) {
esp-hosted port header: RTOS handle types, return codes and budgets.
#define RET_FAIL
Operation failed for an unspecified reason.
#define RET_FAIL_TIMEOUT
The requested wait expired before the operation could complete.
#define RET_INVALID
A parameter was out of contract (null handle, bad size).
#define RET_OK
Operation completed.
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_rtos_error
Generic RTOS error (reserved for future use).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Public entry point of the RA8D2 + ThreadX port of esp-hosted.
@ k_ra8_esp_hosted_queue_pool_bytes
Bytes reserved for queue message storage, shared across all queues; one esp-hosted buffer handle is 2...
@ k_ra8_esp_hosted_max_queues
Message queues the port can hand out before refusing.
@ k_ra8_esp_hosted_pool_bytes
Bytes reserved for the transport buffer pool: enough for the receive ring, a transmit frame,...
uint32_t priv_ra8_esp_hosted_rtos_ms_to_ticks(int timeout_ms)
Convert an esp-hosted millisecond timeout to a ThreadX wait option.
Module-private contract of the esp-hosted RTOS abstraction slice.
static ra8_esp_hosted_pool_state_t s_pool
Singleton state of the memory and queue half.
static int internal_h_dequeue_item(void *queue_handle, void *item, int timeout)
Dequeue one message, blocking for at most timeout.
static ra8_esp_hosted_queue_slot_t * internal_queue_slot(const void *handle)
Resolve an opaque queue handle to its live table row.
static void * internal_h_realloc(void *mem, size_t newsize)
Resize a block, preserving its contents up to the shorter length.
ra8_err_t priv_ra8_esp_hosted_rtos_release(void *ptr)
Release a block obtained from priv_ra8_esp_hosted_rtos_alloc.
static void * internal_h_calloc(size_t blk_no, size_t size)
Serve a zeroed array allocation from the transport byte pool.
ra8_err_t priv_ra8_esp_hosted_rtos_block_size(const void *ptr, size_t *out_size)
Read back the payload size recorded for an allocated block.
static void * internal_h_memset(void *buf, int val, size_t len)
Fill a byte range for the vendored core.
static void * internal_h_memcpy(void *dest, const void *src, uint32_t size)
Copy a byte range for the vendored core.
static void * internal_h_malloc(size_t size)
Serve an unaligned allocation from the transport byte pool.
static void * internal_h_malloc_align(size_t size, size_t align)
Serve an aligned allocation from the transport byte pool.
static void internal_h_free_align(void *ptr)
Return an aligned block to the transport byte pool.
static uint8_t s_queue_mem[k_ra8_esp_hosted_queue_pool_bytes]
Backing storage for the queue message-storage pool.
static char s_tx_name_esph_buf[]
Writable ThreadX object name for the esph_buf object.
static uint8_t s_transport_mem[k_ra8_esp_hosted_pool_bytes]
Backing storage for the transport buffer pool.
static int internal_h_queue_item(void *queue_handle, void *item, int timeout)
Enqueue one message, blocking for at most timeout.
ra8_esp_hosted_pool_const_t
Numeric constants of the fixed-storage allocator and queue table.
@ k_ra8_esp_hosted_align_none
"No extra alignment" selector.
@ k_ra8_esp_hosted_queue_elems_max
Deepest ring the port will make.
@ k_ra8_esp_hosted_align_max
Strictest alignment served.
@ k_ra8_esp_hosted_alloc_max
Largest single payload served.
@ k_ra8_esp_hosted_queue_word_bytes
Bytes in one ThreadX message word.
@ k_ra8_esp_hosted_hdr_magic
'R8MB' sentinel in each header.
@ k_ra8_esp_hosted_queue_words_max
ThreadX message-size cap, words.
@ k_ra8_esp_hosted_hdr_bytes
Per-block header footprint.
static int internal_h_reset_queue(void *queue_handle)
Discard every message a queue is holding.
ra8_err_t priv_ra8_esp_hosted_rtos_pool_init(void)
Create the two byte pools over their static backing arrays.
uint32_t priv_ra8_esp_hosted_rtos_queue_words(uint32_t item_bytes)
Round an esp-hosted queue element size up to whole ThreadX words.
static void internal_h_free(void *ptr)
Return a block to the transport byte pool.
ra8_err_t priv_ra8_esp_hosted_rtos_bind_pool(hosted_osi_funcs_t *out)
Populate the memory and queue slots of the vtable.
static int internal_h_queue_msg_waiting(void *queue_handle)
Report how many messages a queue is currently holding.
ra8_err_t priv_ra8_esp_hosted_rtos_pool_deinit(void)
Destroy every queue and both byte pools.
static char s_tx_name_esph_q[]
Writable ThreadX object name for the esph_q object.
static void * internal_h_create_queue(uint32_t qnum_elem, uint32_t qitem_size)
Create a fixed-capacity message queue for the vendored core.
void * priv_ra8_esp_hosted_rtos_alloc(size_t size, size_t align)
Allocate an aligned block from the transport byte pool.
void priv_ra8_esp_hosted_rtos_pool_stats(uint32_t *out_available, uint32_t *out_fragments)
Read live transport-pool occupancy.
static int internal_h_destroy_queue(void *queue_handle)
Delete a queue and return its ring storage to the queue pool.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_error(tag, message)
RA8 log error.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Bookkeeping written immediately below every allocated payload.
uint32_t magic
k_ra8_esp_hosted_hdr_magic while live.
uint32_t size
Payload bytes the caller asked for.
void * base
Exact pointer tx_byte_allocate returned.
Module state of the memory and queue half – entirely static.
TX_BYTE_POOL transport
Transport buffer pool.
TX_BYTE_POOL queue_pool
Queue message-storage pool.
ra8_esp_hosted_queue_slot_t queues[k_ra8_esp_hosted_max_queues]
Table.
bool ready
True while both pools live.
One row of the fixed queue table.
void * storage
Message ring carved from the queue pool.
uint32_t enqueued
Messages currently held.
bool used
Slot occupancy flag.
TX_QUEUE cb
ThreadX queue control block; must stay first.