34#include "ra8_esp_hosted_tx_shim_sync_internal.h"
49static const char*
s_tag =
"ESPH_RTOS";
67typedef enum : uint32_t {
218 if (used ==
nullptr) {
221 for (uint32_t i = 0U; i < count; ++i) {
236 if ((handle ==
nullptr) || (base ==
nullptr) || (used ==
nullptr)) {
239 for (uint32_t i = 0U; i < count; ++i) {
240 const void*
const row = (
const void*)((
const uint8_t*)base + ((
size_t)i * stride));
241 if ((row == handle) && used[i]) {
273 (void)
memset(dst, 0, cap);
274 if (src ==
nullptr) {
277 const size_t limit = cap - 1U;
279 while ((n < limit) && (src[n] !=
'\0')) {
301 const uint32_t idx = (uint32_t)index;
305 if (
s_rtos.thread_used[idx]) {
324 const uint32_t idx = (uint32_t)index;
328 if (
s_rtos.timer_used[idx]) {
351 volatile uint32_t sink = 0U;
366 if (timeout_ms < 0) {
369 if (timeout_ms == 0) {
370 return (uint32_t)TX_NO_WAIT;
377 if ((cpu_hz == 0U) || (usec == 0U)) {
418 uint32_t tstack_size,
422 if (!
s_rtos.ready || (start_routine ==
nullptr)) {
436 slot->
entry = start_routine;
449 s_rtos.thread_used[idx] =
false;
477 sizeof(
s_rtos.threads[0]),
490 s_rtos.threads[idx].entry =
nullptr;
491 s_rtos.thread_used[idx] =
false;
509 tx_thread_relinquish();
579 if (useconds == 0U) {
613 volatile uint32_t sink = 0U;
654 if (!
s_rtos.ready || (timeout_handler ==
nullptr) || (duration_ms <= 0)) {
667 slot->
cb_fn = timeout_handler;
672 if (tx_timer_create(&slot->
cb,
679 s_rtos.timer_used[idx] =
false;
719 s_rtos.timers[idx].cb_fn =
nullptr;
720 s_rtos.timer_used[idx] =
false;
751 if (now <
s_rtos.last_ticks) {
752 s_rtos.tick_epoch += ((uint64_t)UINT32_MAX + 1U);
776 uint32_t cpu_hz = 0U;
esp-hosted port header: RTOS handle types, return codes and budgets.
#define H_TIMER_TYPE_ONESHOT
Timer that fires once and then stops.
#define RET_FAIL
Operation failed for an unspecified reason.
#define RET_INVALID
A parameter was out of contract (null handle, bad size).
#define RET_OK
Operation completed.
#define H_TIMER_TYPE_PERIODIC
Timer that reschedules itself after every expiry.
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_BOUNDED_LOOP(symbol)
NASA Power-of-10 Rule 2: every loop in a FUNCTION has a constant bound.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#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_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.
static void internal_timer_expiry(ULONG arg)
ThreadX expiry function: run one sampling pass.
Public entry point of the RA8D2 + ThreadX port of esp-hosted.
@ k_ra8_esp_hosted_max_threads
Threads the port can start: the SPI transaction pump, the receive dispatcher, and headroom for the RP...
@ k_ra8_esp_hosted_max_timers
Software timers the port can arm concurrently.
static unsigned int internal_h_blocking_delay(unsigned int number)
Busy-delay for a bounded number of loop iterations.
ra8_err_t priv_ra8_esp_hosted_rtos_deinit(void)
Tear the RTOS substrate down, deleting every outstanding object.
uint32_t priv_ra8_esp_hosted_rtos_ms_to_ticks(int timeout_ms)
Convert an esp-hosted millisecond timeout to a ThreadX wait option.
static void * internal_h_timer_start(const char *name, int duration_ms, int type, ra8_esp_hosted_timer_cb_t timeout_handler, void *arg)
Create and start a software timer.
static void internal_timer_expiry(ULONG index)
ThreadX expiry shim that calls the core-supplied timer callback.
ra8_err_t priv_ra8_esp_hosted_rtos_bind(hosted_osi_funcs_t *out)
Populate the thread, sleep, timer and clock slots of the vtable.
void(* ra8_esp_hosted_timer_cb_t)(void *arg)
Signature of the expiry callback the vendored core hands to the port.
static void internal_copy_name(char *dst, size_t cap, const char *src)
Copy a caller-supplied object name into a fixed buffer.
static unsigned int internal_h_sleep(unsigned int seconds)
Sleep the calling thread for a whole number of seconds.
static void internal_thread_entry(ULONG index)
ThreadX entry shim that calls the core-supplied thread body.
void(* ra8_esp_hosted_thread_entry_t)(void const *arg)
Signature of the thread body the vendored core hands to the port.
static unsigned int internal_h_msleep(unsigned int mseconds)
Sleep the calling thread for a whole number of milliseconds.
uint32_t priv_ra8_esp_hosted_rtos_us_spin_iters(uint32_t cpu_hz, uint32_t usec)
Size the busy-wait loop that stands in for a microsecond delay.
bool priv_ra8_esp_hosted_rtos_is_ready(void)
Report whether the RTOS substrate is currently initialised.
static ra8_esp_hosted_rtos_state_t s_rtos
Singleton state of the thread, timer and clock half.
ra8_err_t priv_ra8_esp_hosted_rtos_init(void)
Bring the RTOS substrate up: byte pools and empty object tables.
uint32_t priv_ra8_esp_hosted_rtos_slot_take(bool *used, uint32_t count)
Claim the first free row of an occupancy bitmap.
static void internal_h_thread_yield(void)
Give up the remainder of the current time slice.
static void internal_spin_us(uint32_t usec)
Burn a bounded number of core cycles standing in for a short delay.
static uint64_t internal_h_get_time_ms(void)
Read milliseconds since kernel start, without a 32-bit wrap.
ra8_esp_hosted_rtos_const_t
Numeric constants of the object tables, sleeps and spin sizing.
@ k_ra8_esp_hosted_us_per_ms
Microseconds in one millisecond.
@ k_ra8_esp_hosted_spin_iters_max
Spin bound (NASA Rule 2).
@ k_ra8_esp_hosted_delay_iters_max
Busy-delay iteration bound.
@ k_ra8_esp_hosted_ms_per_sec
Milliseconds in one second.
@ k_ra8_esp_hosted_default_cpu_hz
Fallback core rate, 1 GHz.
@ k_ra8_esp_hosted_ms_per_tick
Milliseconds in one kernel tick.
@ k_ra8_esp_hosted_spin_cycles_per_iter
Core cycles per spin pass.
@ k_ra8_esp_hosted_thread_stack_bytes
Bytes per thread stack.
@ k_ra8_esp_hosted_hz_per_mhz
Hertz in one megahertz.
@ k_ra8_esp_hosted_name_max
Object name buffer size.
static uint8_t s_thread_stacks[k_ra8_esp_hosted_max_threads][k_ra8_esp_hosted_thread_stack_bytes]
Fixed stack storage, one region per thread table row.
static void * internal_h_thread_create(const char *tname, uint32_t tprio, uint32_t tstack_size, ra8_esp_hosted_thread_entry_t start_routine, void *sr_arg)
Start a thread from the fixed thread table.
uint32_t priv_ra8_esp_hosted_rtos_slot_index(const void *handle, const void *base, size_t stride, uint32_t count, const bool *used)
Resolve an opaque handle to its row index in a fixed table.
static int internal_h_timer_stop(void *timer_handle)
Stop a timer and free its table row.
static int internal_h_thread_cancel(void *thread_handle)
Terminate and delete a thread, freeing its table row.
static unsigned int internal_h_usleep(unsigned int useconds)
Delay for a number of microseconds, honestly.
Module-private contract of the esp-hosted RTOS abstraction slice.
ra8_err_t priv_ra8_esp_hosted_rtos_sync_deinit(void)
Delete every outstanding mutex and semaphore.
ra8_err_t priv_ra8_esp_hosted_rtos_sync_init(void)
Clear the mutex and semaphore tables and mark them usable.
ra8_err_t priv_ra8_esp_hosted_rtos_pool_init(void)
Create the two byte pools over their static backing arrays.
ra8_err_t priv_ra8_esp_hosted_rtos_pool_deinit(void)
Destroy every queue and both byte pools.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_warn(tag, message)
RA8 log warn.
#define ra8_log_error(tag, message)
RA8 log error.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
#define tx_thread_terminate
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
static void internal_thread_entry(ULONG arg)
The supervisor thread's entry point.
Opaque thread stand-in for the host build.
Module state of the thread, timer and clock half – entirely static.
uint32_t last_ticks
Most recent 32-bit tick reading.
ra8_esp_hosted_timer_slot_t timers[k_ra8_esp_hosted_max_timers]
Timers.
bool thread_used[k_ra8_esp_hosted_max_threads]
Thread occupancy.
bool ready
True while the substrate is initialised.
uint32_t cpu_hz
Cached core rate used to size the spin loop.
bool timer_used[k_ra8_esp_hosted_max_timers]
Timer occupancy.
uint64_t tick_epoch
Accumulated rollovers, in ticks.
ra8_esp_hosted_thread_slot_t threads[k_ra8_esp_hosted_max_threads]
Threads.
One row of the fixed thread table.
char name[k_ra8_esp_hosted_name_max]
Bounded name copy.
void * arg
Argument handed to the body.
ra8_esp_hosted_thread_entry_t entry
Core-supplied thread body.
TX_THREAD cb
ThreadX control block; must stay first.
One row of the fixed timer table.
char name[k_ra8_esp_hosted_name_max]
Bounded name copy.
void * arg
Argument handed to the callback.
TX_TIMER cb
ThreadX control block; must stay first.
ra8_esp_hosted_timer_cb_t cb_fn
Core-supplied expiry callback.
#define TX_MINIMUM_STACK
TX MINIMUM STACK.