![]() |
SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Pure C interface for C++ API of SuperTinyKernel RTOS. More...
Classes | |
| struct | stk_event_overrider_t |
C-level callback table that mirrors stk::IPlatform::IEventOverrider. More... | |
| struct | stk_mutex_mem_t |
| Opaque memory container for a Mutex instance. More... | |
| struct | stk_spinlock_mem_t |
| Opaque memory container for SpinLock object. More... | |
| struct | stk_cv_mem_t |
| Opaque memory container for a ConditionVariable instance. More... | |
| struct | stk_event_mem_t |
| Opaque memory container for an Event instance. More... | |
| struct | stk_sem_mem_t |
| Opaque memory container for a Semaphore instance. More... | |
| struct | stk_ef_mem_t |
| Opaque memory container for an EventFlags instance. More... | |
| struct | stk_pipe_mem_t |
| Opaque memory container for a Pipe control-block. More... | |
| struct | stk_msgq_mem_t |
| Opaque memory container for a MessageQueue instance. More... | |
| struct | stk_rwmutex_mem_t |
| Opaque memory container for an RWMutex instance. More... | |
Macros | |
| #define | STK_C_KERNEL_MAX_TASKS (4) |
| Maximum number of tasks per kernel instance (default: 4). | |
| #define | STK_C_CPU_COUNT (1) |
| Number of kernel instances / CPU cores supported (default: 1). | |
| #define | STK_SYNC_DEBUG_NAMES (0) |
| Enable names for synchronization primitives for debugging/tracing purpose. | |
| #define | STK_C_ASSERT(e) |
| Assertion macro used inside STK C bindings. | |
| #define | STK_STATIC_CAST(type, val) |
| Convenience wrapper for static_cast and C-style cast. | |
| #define | STK_PERIODICITY_DEFAULT (1000U) |
| Default tick period (1 ms). | |
| #define | STK_WAIT_INFINITE (STK_STATIC_CAST(stk_timeout_t, INT32_MAX)) |
| Infinite timeout constant. | |
| #define | STK_NO_WAIT (STK_STATIC_CAST(stk_timeout_t, 0)) |
| No timeout constant. | |
| #define | STK_ALIGN_SIZE sizeof(stk_word_t) |
| Memory buffer alignment. | |
| #define | STK_ALIGN_MASK (STK_ALIGN_SIZE - 1U) |
| Alignment mask. | |
| #define | STK_STACK_MEMORY_ALIGN (4U) |
| Stack memory alignment. | |
| #define | STK_DEFINE_STACK_POOL(name, max_tasks, stack_size) |
| Allocates a statically bound, multi-dimensional stack pool for tasks. | |
| #define | STK_GET_STACK_FROM_POOL(name, task_id) |
| Retrieves the base stack pointer for a specific task ID from a stack pool. | |
| #define | __stk_c_stack |
| Stack attribute (applies required alignment for a stack memory). | |
| #define | __stk_c_aligned |
| Memory buffer alignment attribute. | |
| #define | STK_TLS_GET_T(type) |
| Typed helper for getting TLS value. | |
| #define | STK_TLS_SET_T(ptr) |
| Typed helper for setting TLS value. | |
| #define | STK_MUTEX_IMPL_SIZE (10U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
| A memory size (multiples of stk_word_t) required for Mutex instance. | |
| #define | STK_SPINLOCK_IMPL_SIZE (1) |
| A memory size (multiples of stk_word_t) required for SpinLock instance. | |
| #define | STK_CV_IMPL_SIZE (7U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
| A memory size (multiples of stk_word_t) required for ConditionVariable instance. | |
| #define | STK_EVENT_IMPL_SIZE (8U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
| A memory size (multiples of stk_word_t) required for Event instance. | |
| #define | STK_SEM_IMPL_SIZE (8U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
| A memory size (multiples of stk_word_t) required for Semaphore instance. | |
| #define | STK_EF_OPT_WAIT_ANY (0x00000000U) |
| Options bitmask constants for stk_ef_wait() / stk_ef_trywait(). | |
| #define | STK_EF_OPT_WAIT_ALL (0x00000001U) |
| #define | STK_EF_OPT_NO_CLEAR (0x00000002U) |
| #define | STK_EF_ERROR_PARAMETER (0x80000001U) |
| Return-value error sentinels (bit 31 set indicates an error). | |
| #define | STK_EF_ERROR_TIMEOUT (0x80000002U) |
| #define | STK_EF_ERROR_ISR (0x80000004U) |
| #define | STK_EF_ERROR_MASK (0x80000000U) |
| #define | STK_EF_IMPL_SIZE (STK_CV_IMPL_SIZE + 1U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
| A memory size (multiples of stk_word_t) required for EventFlags instance. | |
| #define | STK_PIPE_IMPL_SIZE (6U + (2U * STK_CV_IMPL_SIZE) + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
| A memory size (multiples of stk_word_t) required for a Pipe control-block. | |
| #define | STK_PIPE_BUF_SIZE(capacity, element_size) |
| Compute the required data-buffer size (in bytes) for a Pipe. | |
| #define | STK_MSGQ_IMPL_SIZE (6 + (2 * STK_CV_IMPL_SIZE) + (STK_SYNC_DEBUG_NAMES ? 1 : 0)) |
| A memory size (multiples of stk_word_t) required for a MessageQueue instance. | |
| #define | STK_MSGQ_BUF_SIZE(capacity, msg_size) |
| Compute the required data-buffer size (in bytes) for a MessageQueue. | |
| #define | STK_RWMUTEX_IMPL_SIZE (17U + (STK_SYNC_DEBUG_NAMES ? 3U : 0U)) |
| A memory size (multiples of stk_word_t) required for RWMutex instance. | |
Typedefs | |
| typedef uintptr_t | stk_word_t |
| CPU register type. | |
| typedef stk_word_t | stk_tid_t |
| Task id. | |
| typedef int64_t | stk_tick_t |
| Ticks value. | |
| typedef int64_t | stk_time_t |
| Time value. | |
| typedef int32_t | stk_timeout_t |
| Timeout value. | |
| typedef uint64_t | stk_cycle_t |
| CPU cycles value. | |
| typedef int32_t | stk_weight_t |
| Task weight value. | |
| typedef struct stk_kernel_t | stk_kernel_t |
| Opaque handle to a kernel instance. | |
| typedef struct stk_task_t | stk_task_t |
| Opaque handle to a task instance. | |
| typedef void(* | stk_task_entry_t) (void *arg) |
| Task entry point function type. | |
| typedef enum stk_kernel_state_t | stk_kernel_state_t |
| Kernel state. | |
| typedef struct stk_event_overrider_t | stk_event_overrider_t |
| typedef struct stk_mutex_mem_t | stk_mutex_mem_t |
| Opaque memory container for a Mutex instance. | |
| typedef struct stk_mutex_t | stk_mutex_t |
| Opaque handle to a Mutex instance. | |
| typedef struct stk_spinlock_t | stk_spinlock_t |
| Opaque handle to a SpinLock instance. | |
| typedef struct stk_cv_mem_t | stk_cv_mem_t |
| Opaque memory container for a ConditionVariable instance. | |
| typedef struct stk_cv_t | stk_cv_t |
| Opaque handle to a Condition Variable instance. | |
| typedef struct stk_event_mem_t | stk_event_mem_t |
| Opaque memory container for an Event instance. | |
| typedef struct stk_event_t | stk_event_t |
| Opaque handle to an Event instance. | |
| typedef struct stk_sem_mem_t | stk_sem_mem_t |
| Opaque memory container for a Semaphore instance. | |
| typedef struct stk_sem_t | stk_sem_t |
| Opaque handle to a Semaphore instance. | |
| typedef struct stk_ef_mem_t | stk_ef_mem_t |
| Opaque memory container for an EventFlags instance. | |
| typedef struct stk_ef_t | stk_ef_t |
| Opaque handle to an EventFlags instance. | |
| typedef struct stk_pipe_mem_t | stk_pipe_mem_t |
| Opaque memory container for a Pipe control-block. | |
| typedef struct stk_pipe_t | stk_pipe_t |
| Opaque handle to a Pipe instance. | |
| typedef struct stk_msgq_mem_t | stk_msgq_mem_t |
| Opaque memory container for a MessageQueue instance. | |
| typedef struct stk_msgq_t | stk_msgq_t |
| Opaque handle to a MessageQueue instance. | |
| typedef struct stk_rwmutex_mem_t | stk_rwmutex_mem_t |
| Opaque memory container for an RWMutex instance. | |
| typedef struct stk_rwmutex_t | stk_rwmutex_t |
| Opaque handle to an RWMutex instance. | |
Enumerations | |
| enum | stk_kernel_state_t { STK_KERNEL_STATE_INACTIVE = 0 , STK_KERNEL_STATE_READY = 1 , STK_KERNEL_STATE_RUNNING = 2 , STK_KERNEL_STATE_SUSPENDED = 3 } |
| Kernel state. More... | |
Functions | |
| stk_kernel_t * | stk_kernel_create (uint8_t core_nr) |
| Create kernel. | |
| void | stk_kernel_init (stk_kernel_t *k, uint32_t tick_period_us) |
| Initialize kernel with given tick period. | |
| void | stk_kernel_add_task (stk_kernel_t *k, stk_task_t *tsk) |
| Add task to non-HRT kernel (static or dynamic). | |
| void | stk_kernel_add_task_hrt (stk_kernel_t *k, stk_task_t *tsk, int32_t periodicity_ticks, int32_t deadline_ticks, int32_t start_delay_ticks) |
| Add task with HRT timing parameters (HRT kernels only). | |
| void | stk_kernel_remove_task (stk_kernel_t *k, stk_task_t *tsk) |
| Remove finished task from dynamic kernel. | |
| void | stk_kernel_start (stk_kernel_t *k) |
| Start the scheduler - never returns. | |
| stk_kernel_state_t | stk_kernel_get_state (const stk_kernel_t *k) |
| Get state of the scheduler. | |
| bool | stk_kernel_is_schedulable (const stk_kernel_t *k) |
| Test whether currently configured task set is schedulable. | |
| bool | stk_kernel_is_started (const stk_kernel_t *k) |
| Check whether the scheduler is currently running (first task switch has occurred). | |
| void | stk_kernel_schedule_task_removal (stk_kernel_t *k, stk_task_t *task) |
| Schedule removal of a running task from the kernel on the next tick. | |
| void | stk_kernel_suspend_task (stk_kernel_t *k, stk_task_t *task, bool *suspended) |
| Suspend a task (prevent it from being scheduled). | |
| void | stk_kernel_resume_task (stk_kernel_t *k, stk_task_t *task) |
| Resume a previously suspended task. | |
| stk_timeout_t | stk_kernel_suspend (stk_kernel_t *k) |
| Suspend scheduling (tickless idle entry point). | |
| void | stk_kernel_resume (stk_kernel_t *k, stk_timeout_t elapsed_ticks) |
| Resume scheduling after a prior stk_kernel_suspend() call. | |
| size_t | stk_kernel_enumerate_tasks (stk_kernel_t *k, stk_task_t **tasks, size_t max_count) |
| Enumerate all currently active tasks. | |
| void | stk_kernel_process_tick (stk_kernel_t *k) |
| Manually deliver one scheduler tick to the kernel. | |
| void | stk_kernel_process_hard_fault (stk_kernel_t *k) |
| Trigger a kernel hard fault (safe-state handler). | |
| void | stk_kernel_set_event_overrider (stk_kernel_t *k, stk_event_overrider_t *overrider) |
| Install a platform event overrider on the kernel. | |
| stk_task_t * | stk_task_create_privileged (stk_task_entry_t entry, void *arg, stk_word_t *stack, uint32_t stack_size) |
| Create privileged-mode (kernel-mode) task. | |
| stk_task_t * | stk_task_create_user (stk_task_entry_t entry, void *arg, stk_word_t *stack, uint32_t stack_size) |
| Create user-mode task. | |
| void | stk_task_set_weight (stk_task_t *tsk, stk_weight_t weight) |
| Set task weight (used only by Smooth Weighted Round Robin). | |
| void | stk_task_set_priority (stk_task_t *tsk, uint8_t priority) |
| Set task priority (used only by Fixed Priority scheduler). | |
| void | stk_task_set_name (stk_task_t *tsk, const char *tname) |
| Assign human-readable task name (for tracing/debugging). | |
| const char * | stk_task_get_name (const stk_task_t *tsk) |
| Get human-readable task name previously set with stk_task_set_name(). | |
| stk_tid_t | stk_task_get_id (const stk_task_t *tsk) |
| Get the unique identifier of a task. | |
| stk_tid_t | stk_tid (void) |
| Returns current task/thread ID (the value set by stk_task_set_id). | |
| stk_tick_t | stk_ticks (void) |
| Returns number of ticks elapsed since kernel start. | |
| uint32_t | stk_tick_resolution (void) |
| Returns how many microseconds correspond to one kernel tick. | |
| stk_tick_t | stk_ticks_from_ms (stk_time_t msec) |
| Get ticks from milliseconds using current kernel tick resolution. | |
| static stk_tick_t | stk_ticks_from_ms_r (stk_time_t msec, uint32_t resolution) |
| Get ticks from milliseconds using an explicit tick resolution. | |
| stk_time_t | stk_time_now_ms (void) |
| Returns current time in milliseconds since kernel start. | |
| static stk_time_t | stk_ms_from_ticks_r (stk_tick_t ticks, uint32_t resolution) |
| Convert ticks to milliseconds using an explicit tick resolution. | |
| static stk_time_t | stk_ms_from_ticks (stk_tick_t ticks) |
| Convert ticks to milliseconds using the current kernel tick resolution. | |
| stk_cycle_t | stk_sys_timer_count (void) |
| Get raw system timer counter value. | |
| uint32_t | stk_sys_timer_frequency (void) |
| Get system timer frequency in Hz. | |
| stk_cycle_t | stk_hires_cycles (void) |
| Get raw CPU cycle counter. | |
| uint32_t | stk_hires_frequency (void) |
| Get CPU clock frequency in Hz. | |
| stk_tick_t | stk_hires_time_us (void) |
| Get elapsed time in microseconds from the high-resolution clock. | |
| void | stk_delay (stk_timeout_t ticks) |
| Busy-wait delay (other tasks continue to run). | |
| void | stk_delay_ms (stk_timeout_t ms) |
| Busy-wait delay (other tasks continue to run). | |
| void | stk_sleep (stk_timeout_t ticks) |
| Put current task to sleep (non-HRT kernels only). | |
| void | stk_sleep_ms (stk_timeout_t ms) |
| Put current task to sleep (non-HRT kernels only). | |
| bool | stk_sleep_until (stk_tick_t ts) |
| Put current task to sleep (non-HRT kernels only). | |
| void | stk_yield (void) |
| Voluntarily give up CPU to another ready task (cooperative yield). | |
| void | stk_sleep_cancel (stk_tid_t tid) |
| Cancel the sleep of a task, waking it immediately. | |
| void | stk_kernel_destroy (stk_kernel_t *k) |
| Destroy dynamic kernel instance (only when not running). | |
| void | stk_task_destroy (stk_task_t *tsk) |
| Destroy dynamically created task object. | |
| void * | stk_tls_get (void) |
| Get thread-local pointer (platform-specific slot). | |
| void | stk_tls_set (void *ptr) |
| Set thread-local pointer. | |
| void | stk_critical_section_enter (void) |
| Enter critical section - disable context switches on current core. | |
| void | stk_critical_section_exit (void) |
| Leave critical section - re-enable context switches. | |
| stk_mutex_t * | stk_mutex_create (stk_mutex_mem_t *const membuf, uint32_t membuf_size) |
| Create a Mutex (using provided memory). | |
| void | stk_mutex_destroy (stk_mutex_t *mtx) |
| Destroy a Mutex. | |
| void | stk_mutex_lock (stk_mutex_t *mtx) |
| Lock the mutex. Blocks until available. | |
| bool | stk_mutex_trylock (stk_mutex_t *mtx) |
| Try locking the mutex. Does not block if already locked. | |
| void | stk_mutex_unlock (stk_mutex_t *mtx) |
| Unlock the mutex. | |
| bool | stk_mutex_timed_lock (stk_mutex_t *mtx, stk_timeout_t timeout) |
| Try to lock the mutex with a timeout. | |
| stk_spinlock_t * | stk_spinlock_create (stk_spinlock_mem_t *const membuf, uint32_t membuf_size) |
| Create a recursive SpinLock. | |
| void | stk_spinlock_destroy (stk_spinlock_t *slock) |
| Destroy the SpinLock. | |
| void | stk_spinlock_lock (stk_spinlock_t *slock) |
| Acquire the SpinLock (recursive). | |
| bool | stk_spinlock_trylock (stk_spinlock_t *slock) |
| Attempt to acquire the SpinLock immediately. | |
| void | stk_spinlock_unlock (stk_spinlock_t *slock) |
| Release the SpinLock. | |
| stk_cv_t * | stk_cv_create (stk_cv_mem_t *const membuf, uint32_t membuf_size) |
| Create a Condition Variable (using provided memory). | |
| void | stk_cv_destroy (stk_cv_t *cv) |
| Destroy a Condition Variable. | |
| bool | stk_cv_wait (stk_cv_t *cv, stk_mutex_t *mtx, stk_timeout_t timeout) |
| Wait for a signal on the condition variable. | |
| void | stk_cv_notify_one (stk_cv_t *cv) |
| Wake one task waiting on the condition variable. | |
| void | stk_cv_notify_all (stk_cv_t *cv) |
| Wake all tasks waiting on the condition variable. | |
| stk_event_t * | stk_event_create (stk_event_mem_t *const membuf, uint32_t membuf_size, bool manual_reset) |
| Create an Event (using provided memory). | |
| void | stk_event_destroy (stk_event_t *ev) |
| Destroy an Event. | |
| bool | stk_event_wait (stk_event_t *ev, stk_timeout_t timeout) |
| Wait for the event to become signaled. | |
| bool | stk_event_trywait (stk_event_t *ev) |
| Wait for the event to become signaled. | |
| bool | stk_event_set (stk_event_t *ev) |
| Set the event to signaled state. | |
| bool | stk_event_reset (stk_event_t *ev) |
| Reset the event to non-signaled state. | |
| void | stk_event_pulse (stk_event_t *ev) |
| Pulse the event (signal then immediately reset). | |
| stk_sem_t * | stk_sem_create (stk_sem_mem_t *const membuf, uint32_t membuf_size, uint32_t initial_count, uint32_t max_count) |
| Create a Semaphore (using provided memory). | |
| void | stk_sem_destroy (stk_sem_t *sem) |
| Destroy a Semaphore. | |
| bool | stk_sem_wait (stk_sem_t *sem, stk_timeout_t timeout) |
| Wait for a semaphore resource. | |
| bool | stk_sem_trywait (stk_sem_t *sem) |
| Poll the semaphore without blocking. | |
| void | stk_sem_signal (stk_sem_t *sem) |
| Signal/Release a semaphore resource. | |
| uint16_t | stk_sem_get_count (const stk_sem_t *sem) |
| Get the current counter value. | |
| static bool | stk_ef_is_error (uint32_t result) |
| Returns true if a value returned by stk_ef_set(), stk_ef_clear(), stk_ef_wait(), or stk_ef_trywait() is an error sentinel (bit 31 set). | |
| stk_ef_t * | stk_ef_create (stk_ef_mem_t *const membuf, uint32_t membuf_size, uint32_t initial_flags) |
| Create an EventFlags object (using provided memory). | |
| void | stk_ef_destroy (stk_ef_t *ef) |
| Destroy an EventFlags object. | |
| uint32_t | stk_ef_set (stk_ef_t *ef, uint32_t flags) |
| Set one or more flags. | |
| uint32_t | stk_ef_clear (stk_ef_t *ef, uint32_t flags) |
| Clear one or more flags. | |
| uint32_t | stk_ef_get (stk_ef_t *ef) |
| Read the current flags word without modifying it. | |
| uint32_t | stk_ef_wait (stk_ef_t *ef, uint32_t flags, uint32_t options, stk_timeout_t timeout) |
| Wait for one or more flags to be set. | |
| uint32_t | stk_ef_trywait (stk_ef_t *ef, uint32_t flags, uint32_t options) |
| Non-blocking flag poll. | |
| stk_pipe_t * | stk_pipe_create (stk_pipe_mem_t *const membuf, uint32_t membuf_size, uint8_t *buf, uint32_t buf_size, size_t capacity, size_t element_size) |
| Create a Pipe (using provided memory). | |
| void | stk_pipe_destroy (stk_pipe_t *pipe) |
| Destroy a Pipe. | |
| bool | stk_pipe_write (stk_pipe_t *pipe, const void *data, stk_timeout_t timeout) |
| Write a single element to the pipe. | |
| bool | stk_pipe_trywrite (stk_pipe_t *pipe, const void *data) |
| Attempt to write a single element to the pipe without blocking. | |
| bool | stk_pipe_read (stk_pipe_t *pipe, void *data, stk_timeout_t timeout) |
| Read a single element from the pipe. | |
| bool | stk_pipe_tryread (stk_pipe_t *pipe, void *data) |
| Attempt to read a single element from the pipe without blocking. | |
| size_t | stk_pipe_write_bulk (stk_pipe_t *pipe, const void *src, size_t count, stk_timeout_t timeout) |
| Write multiple elements to the pipe. | |
| size_t | stk_pipe_trywrite_bulk (stk_pipe_t *pipe, const void *src, size_t count) |
| Attempt to write multiple elements to the pipe without blocking. | |
| size_t | stk_pipe_read_bulk (stk_pipe_t *pipe, void *dst, size_t count, stk_timeout_t timeout) |
| Read multiple elements from the pipe. | |
| size_t | stk_pipe_tryread_bulk (stk_pipe_t *pipe, void *dst, size_t count) |
| Attempt to read multiple elements from the pipe without blocking. | |
| size_t | stk_pipe_read_bulk_triggered (stk_pipe_t *pipe, void *dst, size_t trigger, size_t max_count, stk_timeout_t timeout) |
| Read at least trigger elements, then drain up to max_count without blocking. | |
| size_t | stk_pipe_tryread_bulk_triggered (stk_pipe_t *pipe, void *dst, size_t max_count) |
| Non-blocking variant of stk_pipe_read_bulk_triggered. | |
| void | stk_pipe_reset (stk_pipe_t *pipe) |
| Discard all elements and reset the pipe to the empty state. | |
| size_t | stk_pipe_get_capacity (const stk_pipe_t *pipe) |
| Get the maximum number of elements the pipe can hold. | |
| size_t | stk_pipe_get_element_size (const stk_pipe_t *pipe) |
| Get the size of each element in bytes. | |
| size_t | stk_pipe_get_count (const stk_pipe_t *pipe) |
| Get the current number of elements in the pipe. | |
| size_t | stk_pipe_get_space (const stk_pipe_t *pipe) |
| Get the number of free slots currently available. | |
| bool | stk_pipe_is_empty (const stk_pipe_t *pipe) |
| Check whether the pipe is currently empty. | |
| bool | stk_pipe_is_full (const stk_pipe_t *pipe) |
| Check whether the pipe is currently full. | |
| bool | stk_pipe_is_storage_valid (const stk_pipe_t *pipe) |
| Verify that the backing storage is valid and the pipe is ready for use. | |
| stk_msgq_t * | stk_msgq_create (stk_msgq_mem_t *const membuf, uint32_t membuf_size, uint8_t *buf, uint32_t buf_size, size_t capacity, size_t msg_size) |
| Create a MessageQueue (using provided memory). | |
| void | stk_msgq_destroy (stk_msgq_t *mq) |
| Destroy a MessageQueue. | |
| bool | stk_msgq_put (stk_msgq_t *mq, const void *msg, stk_timeout_t timeout) |
| Put a message into the queue. | |
| bool | stk_msgq_tryput (stk_msgq_t *mq, const void *msg) |
| Attempt to put a message into the queue without blocking. | |
| bool | stk_msgq_putfront (stk_msgq_t *mq, const void *msg, stk_timeout_t timeout) |
| Put a message into the front of the queue (priority insert). | |
| bool | stk_msgq_tryputfront (stk_msgq_t *mq, const void *msg) |
| Attempt to put a message into the front of the queue without blocking. | |
| bool | stk_msgq_get (stk_msgq_t *mq, void *msg, stk_timeout_t timeout) |
| Get a message from the queue. | |
| bool | stk_msgq_tryget (stk_msgq_t *mq, void *msg) |
| Attempt to get a message from the queue without blocking. | |
| bool | stk_msgq_peek (stk_msgq_t *mq, void *msg, stk_timeout_t timeout) |
| Peek at the next message to be delivered without removing it. | |
| bool | stk_msgq_trypeek (stk_msgq_t *mq, void *msg) |
| Attempt to peek at the next message without blocking. | |
| bool | stk_msgq_peekfront (stk_msgq_t *mq, void *msg, stk_timeout_t timeout) |
| Peek at the most recently front-inserted message without removing it. | |
| bool | stk_msgq_trypeekfront (stk_msgq_t *mq, void *msg) |
| Attempt to peek at the front message without blocking. | |
| void | stk_msgq_reset (stk_msgq_t *mq) |
| Discard all messages and reset the queue to the empty state. | |
| size_t | stk_msgq_get_capacity (const stk_msgq_t *mq) |
| Get the maximum number of messages the queue can hold. | |
| size_t | stk_msgq_get_msg_size (const stk_msgq_t *mq) |
| Get the size of each message in bytes. | |
| size_t | stk_msgq_get_count (const stk_msgq_t *mq) |
| Get the current number of messages waiting in the queue. | |
| size_t | stk_msgq_get_space (const stk_msgq_t *mq) |
| Get the number of free slots currently available. | |
| bool | stk_msgq_is_empty (const stk_msgq_t *mq) |
| Check whether the queue is currently empty. | |
| uint8_t * | stk_msgq_get_buffer (stk_msgq_t *mq) |
| Get a pointer to the raw message data buffer. | |
| bool | stk_msgq_is_full (const stk_msgq_t *mq) |
| Check whether the queue is currently full. | |
| bool | stk_msgq_is_storage_valid (const stk_msgq_t *mq) |
| Verify that the backing storage is valid and the queue is ready for use. | |
| stk_rwmutex_t * | stk_rwmutex_create (stk_rwmutex_mem_t *const membuf, uint32_t membuf_size) |
| Create an RWMutex (using provided memory). | |
| void | stk_rwmutex_destroy (stk_rwmutex_t *rw) |
| Destroy an RWMutex. | |
| void | stk_rwmutex_read_lock (stk_rwmutex_t *rw) |
| Acquire the lock for shared reading. Blocks until available. | |
| bool | stk_rwmutex_try_read_lock (stk_rwmutex_t *rw) |
| Try to acquire the read lock without blocking. | |
| bool | stk_rwmutex_timed_read_lock (stk_rwmutex_t *rw, stk_timeout_t timeout) |
| Try to acquire the read lock with a timeout. | |
| void | stk_rwmutex_read_unlock (stk_rwmutex_t *rw) |
| Release the shared reader lock. | |
| void | stk_rwmutex_lock (stk_rwmutex_t *rw) |
| Acquire the lock for exclusive writing. Blocks until available. | |
| bool | stk_rwmutex_trylock (stk_rwmutex_t *rw) |
| Try to acquire the write lock without blocking. | |
| bool | stk_rwmutex_timed_lock (stk_rwmutex_t *rw, stk_timeout_t timeout) |
| Try to acquire the write lock with a timeout. | |
| void | stk_rwmutex_unlock (stk_rwmutex_t *rw) |
| Release the exclusive writer lock. | |
Pure C interface for C++ API of SuperTinyKernel RTOS.
| #define __stk_c_aligned |
Memory buffer alignment attribute.
| #define __stk_c_stack |
| #define STK_ALIGN_MASK (STK_ALIGN_SIZE - 1U) |
| #define STK_ALIGN_SIZE sizeof(stk_word_t) |
| #define STK_C_ASSERT | ( | e | ) |
| #define STK_C_CPU_COUNT (1) |
Number of kernel instances / CPU cores supported (default: 1).
Definition at line 60 of file stk_c.h.
Referenced by SetEventOverrider(), stk_kernel_create(), stk_timerhost_get(), and UnregisterKernel().
| #define STK_C_KERNEL_MAX_TASKS (4) |
| #define STK_CV_IMPL_SIZE (7U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
A memory size (multiples of stk_word_t) required for ConditionVariable instance.
| #define STK_DEFINE_STACK_POOL | ( | name, | |
| max_tasks, | |||
| stack_size ) |
Allocates a statically bound, multi-dimensional stack pool for tasks.
| [in] | name | Identifier name of the generated array. |
| [in] | max_tasks | Maximum number of tasks (rows in the array). |
| [in] | stack_size | Size of each individual stack in words (columns). |
Definition at line 181 of file stk_c.h.
| #define STK_EF_ERROR_ISR (0x80000004U) |
| #define STK_EF_ERROR_MASK (0x80000000U) |
Mask for testing any error; bit 31 set means error
Definition at line 1118 of file stk_c.h.
Referenced by stk_ef_is_error().
| #define STK_EF_ERROR_PARAMETER (0x80000001U) |
| #define STK_EF_ERROR_TIMEOUT (0x80000002U) |
| #define STK_EF_IMPL_SIZE (STK_CV_IMPL_SIZE + 1U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
A memory size (multiples of stk_word_t) required for EventFlags instance.
| #define STK_EF_OPT_NO_CLEAR (0x00000002U) |
| #define STK_EF_OPT_WAIT_ALL (0x00000001U) |
| #define STK_EF_OPT_WAIT_ANY (0x00000000U) |
Options bitmask constants for stk_ef_wait() / stk_ef_trywait().
Unblock when ANY requested bit is set (OR semantics, default)
| #define STK_EVENT_IMPL_SIZE (8U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
A memory size (multiples of stk_word_t) required for Event instance.
| #define STK_GET_STACK_FROM_POOL | ( | name, | |
| task_id ) |
Retrieves the base stack pointer for a specific task ID from a stack pool.
| [in] | name | Identifier name of the allocated stack pool. |
| [in] | task_id | Index of the task whose stack pointer is requested. |
| #define STK_MSGQ_BUF_SIZE | ( | capacity, | |
| msg_size ) |
Compute the required data-buffer size (in bytes) for a MessageQueue.
| [in] | capacity | Maximum number of messages. |
| [in] | msg_size | Size of each message in bytes. |
uint8_t buffer passed to stk_msgq_create(): | #define STK_MSGQ_IMPL_SIZE (6 + (2 * STK_CV_IMPL_SIZE) + (STK_SYNC_DEBUG_NAMES ? 1 : 0)) |
A memory size (multiples of stk_word_t) required for a MessageQueue instance.
Covers the fixed-overhead fields of stk::sync::MessageQueue: six size_t members (buffer ptr, capacity, msg_size, count, head, tail) plus two ConditionVariable objects (cv_not_empty, cv_not_full) and optional debug-name word.
| #define STK_MUTEX_IMPL_SIZE (10U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
A memory size (multiples of stk_word_t) required for Mutex instance.
| #define STK_NO_WAIT (STK_STATIC_CAST(stk_timeout_t, 0)) |
| #define STK_PERIODICITY_DEFAULT (1000U) |
| #define STK_PIPE_BUF_SIZE | ( | capacity, | |
| element_size ) |
Compute the required data-buffer size (in bytes) for a Pipe.
| [in] | capacity | Maximum number of elements the pipe can hold. |
| [in] | element_size | Size of a single element in bytes. |
uint8_t buffer passed to stk_pipe_create():Definition at line 1257 of file stk_c.h.
| #define STK_PIPE_IMPL_SIZE (6U + (2U * STK_CV_IMPL_SIZE) + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
A memory size (multiples of stk_word_t) required for a Pipe control-block.
Covers the fixed-overhead fields of stk::sync::Pipe: one uint8_t pointer plus five size_t members (capacity, element_size, count, head, tail), two ConditionVariable objects (cv_not_empty, cv_not_full) and an optional debug-name word.
| #define STK_RWMUTEX_IMPL_SIZE (17U + (STK_SYNC_DEBUG_NAMES ? 3U : 0U)) |
A memory size (multiples of stk_word_t) required for RWMutex instance.
| #define STK_SEM_IMPL_SIZE (8U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U)) |
A memory size (multiples of stk_word_t) required for Semaphore instance.
| #define STK_SPINLOCK_IMPL_SIZE (1) |
A memory size (multiples of stk_word_t) required for SpinLock instance.
| #define STK_STATIC_CAST | ( | type, | |
| val ) |
Convenience wrapper for static_cast and C-style cast.
| [in] | type | Value type. |
| [in] | val | Value. |
Definition at line 83 of file stk_c.h.
Referenced by stk_ms_from_ticks_r(), and stk_ticks_from_ms_r().
| #define STK_SYNC_DEBUG_NAMES (0) |
| #define STK_TLS_GET_T | ( | type | ) |
Typed helper for getting TLS value.
| #define STK_TLS_SET_T | ( | ptr | ) |
Typed helper for setting TLS value.
| #define STK_WAIT_INFINITE (STK_STATIC_CAST(stk_timeout_t, INT32_MAX)) |
| typedef struct stk_cv_mem_t stk_cv_mem_t |
Opaque memory container for a ConditionVariable instance.
| typedef struct stk_cv_t stk_cv_t |
| typedef uint64_t stk_cycle_t |
CPU cycles value.
| typedef struct stk_ef_mem_t stk_ef_mem_t |
Opaque memory container for an EventFlags instance.
| typedef struct stk_ef_t stk_ef_t |
| typedef struct stk_event_mem_t stk_event_mem_t |
Opaque memory container for an Event instance.
| typedef struct stk_event_overrider_t stk_event_overrider_t |
| typedef struct stk_event_t stk_event_t |
| typedef enum stk_kernel_state_t stk_kernel_state_t |
| typedef struct stk_kernel_t stk_kernel_t |
Opaque handle to a kernel instance.
| typedef struct stk_msgq_mem_t stk_msgq_mem_t |
Opaque memory container for a MessageQueue instance.
| typedef struct stk_msgq_t stk_msgq_t |
| typedef struct stk_mutex_mem_t stk_mutex_mem_t |
Opaque memory container for a Mutex instance.
| typedef struct stk_mutex_t stk_mutex_t |
| typedef struct stk_pipe_mem_t stk_pipe_mem_t |
Opaque memory container for a Pipe control-block.
| typedef struct stk_pipe_t stk_pipe_t |
| typedef struct stk_rwmutex_mem_t stk_rwmutex_mem_t |
Opaque memory container for an RWMutex instance.
| typedef struct stk_rwmutex_t stk_rwmutex_t |
| typedef struct stk_sem_mem_t stk_sem_mem_t |
Opaque memory container for a Semaphore instance.
| typedef struct stk_sem_t stk_sem_t |
| typedef struct stk_spinlock_t stk_spinlock_t |
| typedef void(* stk_task_entry_t) (void *arg) |
Task entry point function type.
| [in] | arg | User-supplied argument (may be NULL) |
| typedef struct stk_task_t stk_task_t |
| typedef int64_t stk_tick_t |
Ticks value.
| typedef stk_word_t stk_tid_t |
Task id.
| typedef int64_t stk_time_t |
Time value.
| typedef int32_t stk_timeout_t |
Timeout value.
| typedef int32_t stk_weight_t |
Task weight value.
| typedef uintptr_t stk_word_t |
CPU register type.
| enum stk_kernel_state_t |
Kernel state.
| Enumerator | |
|---|---|
| STK_KERNEL_STATE_INACTIVE | not ready, stk_kernel_init() must be called |
| STK_KERNEL_STATE_READY | ready to start, stk_kernel_start() must be called |
| STK_KERNEL_STATE_RUNNING | initialized and running, stk_kernel_start() was called successfully |
| STK_KERNEL_STATE_SUSPENDED | scheduling suspended via stk_kernel_service_suspend() (tickless idle) |
Definition at line 364 of file stk_c.h.
| void stk_critical_section_enter | ( | void | ) |
Enter critical section - disable context switches on current core.
Definition at line 651 of file stk_c.cpp.
References stk::hw::CriticalSection::Enter().
| void stk_critical_section_exit | ( | void | ) |
Leave critical section - re-enable context switches.
Definition at line 656 of file stk_c.cpp.
References stk::hw::CriticalSection::Exit().
| stk_cv_t * stk_cv_create | ( | stk_cv_mem_t *const | membuf, |
| uint32_t | membuf_size ) |
Create a Condition Variable (using provided memory).
| [in] | membuf | Pointer to static memory container. |
| [in] | membuf_size | Size of the container (must be >= sizeof(stk_cv_mem_t)). |
Definition at line 141 of file stk_c_sync.cpp.
References stk_cv_mem_t::data, and STK_ASSERT.
| void stk_cv_destroy | ( | stk_cv_t * | cv | ) |
Destroy a Condition Variable.
| [in] | cv | CV handle. |
Definition at line 155 of file stk_c_sync.cpp.
| void stk_cv_notify_all | ( | stk_cv_t * | cv | ) |
Wake all tasks waiting on the condition variable.
| [in] | cv | CV handle. |
Definition at line 178 of file stk_c_sync.cpp.
References stk_cv_t::handle, stk::sync::ConditionVariable::NotifyAll(), and STK_ASSERT.
| void stk_cv_notify_one | ( | stk_cv_t * | cv | ) |
Wake one task waiting on the condition variable.
| [in] | cv | CV handle. |
Definition at line 171 of file stk_c_sync.cpp.
References stk_cv_t::handle, stk::sync::ConditionVariable::NotifyOne(), and STK_ASSERT.
| bool stk_cv_wait | ( | stk_cv_t * | cv, |
| stk_mutex_t * | mtx, | ||
| stk_timeout_t | timeout ) |
Wait for a signal on the condition variable.
Atomically releases the mutex and suspends the task. The mutex is re-acquired before returning.
| [in] | cv | CV handle. |
| [in] | mtx | Locked mutex handle protecting the state. |
| [in] | timeout | Max time to wait (or STK_WAIT_INFINITE). |
Definition at line 163 of file stk_c_sync.cpp.
References stk_cv_t::handle, stk_mutex_t::handle, STK_ASSERT, and stk::sync::ConditionVariable::Wait().
| void stk_delay | ( | stk_timeout_t | ticks | ) |
Busy-wait delay (other tasks continue to run).
| [in] | ticks | Ticks to delay. |
Definition at line 625 of file stk_c.cpp.
References stk::Delay().
| void stk_delay_ms | ( | stk_timeout_t | ms | ) |
Busy-wait delay (other tasks continue to run).
| [in] | ms | Milliseconds to delay. |
Definition at line 627 of file stk_c.cpp.
References stk::DelayMs().
| uint32_t stk_ef_clear | ( | stk_ef_t * | ef, |
| uint32_t | flags ) |
Clear one or more flags.
Atomically clears the specified bits.
| [in] | ef | EventFlags handle. |
| [in] | flags | Bitmask of bits to clear. Must not be 0 and must not have bit 31 set. |
STK_EF_ERROR_PARAMETER on invalid input. Definition at line 365 of file stk_c_sync.cpp.
References stk::sync::EventFlags::Clear(), stk_ef_t::handle, and STK_ASSERT.
| stk_ef_t * stk_ef_create | ( | stk_ef_mem_t *const | membuf, |
| uint32_t | membuf_size, | ||
| uint32_t | initial_flags ) |
Create an EventFlags object (using provided memory).
| [in] | membuf | Pointer to static memory container. |
| [in] | membuf_size | Size of the container (must be >= sizeof(stk_ef_mem_t)). |
| [in] | initial_flags | Initial value of the 32-bit flags word (bits 0..30 only; bit 31 is reserved and must not be set). |
Definition at line 334 of file stk_c_sync.cpp.
References stk_ef_mem_t::data, and STK_ASSERT.
| void stk_ef_destroy | ( | stk_ef_t * | ef | ) |
Destroy an EventFlags object.
| [in] | ef | EventFlags handle. |
Definition at line 350 of file stk_c_sync.cpp.
| uint32_t stk_ef_get | ( | stk_ef_t * | ef | ) |
Read the current flags word without modifying it.
| [in] | ef | EventFlags handle. |
Definition at line 372 of file stk_c_sync.cpp.
References stk::sync::EventFlags::Get(), stk_ef_t::handle, and STK_ASSERT.
|
inlinestatic |
Returns true if a value returned by stk_ef_set(), stk_ef_clear(), stk_ef_wait(), or stk_ef_trywait() is an error sentinel (bit 31 set).
< Mask for testing any error; bit 31 set means error
Definition at line 1123 of file stk_c.h.
References STK_EF_ERROR_MASK.
| uint32_t stk_ef_set | ( | stk_ef_t * | ef, |
| uint32_t | flags ) |
Set one or more flags.
Atomically OR-sets the specified bits and wakes all current waiters so each can re-evaluate its own predicate.
| [in] | ef | EventFlags handle. |
| [in] | flags | Bitmask of bits to set. Must not be 0 and must not have bit 31 set. |
STK_EF_ERROR_PARAMETER on invalid input. Definition at line 358 of file stk_c_sync.cpp.
References stk_ef_t::handle, stk::sync::EventFlags::Set(), and STK_ASSERT.
| uint32_t stk_ef_trywait | ( | stk_ef_t * | ef, |
| uint32_t | flags, | ||
| uint32_t | options ) |
Non-blocking flag poll.
Checks immediately whether the flag condition is satisfied. Clears matched bits on success unless STK_EF_OPT_NO_CLEAR is set.
| [in] | ef | EventFlags handle. |
| [in] | flags | Bitmask of flag bits to watch. |
| [in] | options | STK_EF_OPT_WAIT_ANY (default) or STK_EF_OPT_WAIT_ALL, optionally OR-ed with STK_EF_OPT_NO_CLEAR. |
STK_EF_ERROR_TIMEOUT immediately if the condition is not met. Definition at line 386 of file stk_c_sync.cpp.
References stk_ef_t::handle, STK_ASSERT, and stk::sync::EventFlags::TryWait().
| uint32_t stk_ef_wait | ( | stk_ef_t * | ef, |
| uint32_t | flags, | ||
| uint32_t | options, | ||
| stk_timeout_t | timeout ) |
Wait for one or more flags to be set.
Suspends the calling task until the requested flag condition is satisfied or the timeout expires. On success, matched bits are atomically cleared unless STK_EF_OPT_NO_CLEAR is set in options.
| [in] | ef | EventFlags handle. |
| [in] | flags | Bitmask of flag bits to watch. Must not be 0 and must not have bit 31 set. |
| [in] | options | Combination of STK_EF_OPT_WAIT_ANY / STK_EF_OPT_WAIT_ALL and optionally STK_EF_OPT_NO_CLEAR. |
| [in] | timeout | Maximum time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking poll. |
STK_EF_ERROR_* sentinel on failure. Always check stk_ef_is_error() before using the return value as a flags mask. STK_NO_WAIT, ISR-unsafe otherwise. Definition at line 379 of file stk_c_sync.cpp.
References stk_ef_t::handle, STK_ASSERT, and stk::sync::EventFlags::Wait().
| stk_event_t * stk_event_create | ( | stk_event_mem_t *const | membuf, |
| uint32_t | membuf_size, | ||
| bool | manual_reset ) |
Create an Event (using provided memory).
| [in] | membuf | Pointer to static memory container. |
| [in] | membuf_size | Size of the container (must be >= sizeof(stk_event_mem_t)). |
| [in] | manual_reset | True for manual-reset, False for auto-reset. |
Definition at line 196 of file stk_c_sync.cpp.
References stk_event_mem_t::data, and STK_ASSERT.
| void stk_event_destroy | ( | stk_event_t * | ev | ) |
Destroy an Event.
| [in] | ev | Event handle. |
Definition at line 212 of file stk_c_sync.cpp.
| void stk_event_pulse | ( | stk_event_t * | ev | ) |
Pulse the event (signal then immediately reset).
| [in] | ev | Event handle. |
Definition at line 248 of file stk_c_sync.cpp.
References stk_event_t::handle, stk::sync::Event::Pulse(), and STK_ASSERT.
| bool stk_event_reset | ( | stk_event_t * | ev | ) |
Reset the event to non-signaled state.
| [in] | ev | Event handle. |
true if state was changed from signaled to non-signaled, false if event was already non-signaled. Definition at line 241 of file stk_c_sync.cpp.
References stk_event_t::handle, stk::sync::Event::Reset(), and STK_ASSERT.
| bool stk_event_set | ( | stk_event_t * | ev | ) |
Set the event to signaled state.
| [in] | ev | Event handle. |
true if state was changed from non-signaled to signaled, false if event was already signaled. Definition at line 234 of file stk_c_sync.cpp.
References stk_event_t::handle, stk::sync::Event::Set(), and STK_ASSERT.
| bool stk_event_trywait | ( | stk_event_t * | ev | ) |
Wait for the event to become signaled.
| [in] | ev | Event handle. |
Definition at line 227 of file stk_c_sync.cpp.
References stk_event_t::handle, STK_ASSERT, and stk::sync::Event::TryWait().
| bool stk_event_wait | ( | stk_event_t * | ev, |
| stk_timeout_t | timeout ) |
Wait for the event to become signaled.
| [in] | ev | Event handle. |
| [in] | timeout | Max time to wait in milliseconds. |
Definition at line 220 of file stk_c_sync.cpp.
References stk_event_t::handle, STK_ASSERT, and stk::sync::Event::Wait().
| stk_cycle_t stk_hires_cycles | ( | void | ) |
Get raw CPU cycle counter.
Definition at line 622 of file stk_c.cpp.
References stk::hw::HiResClock::GetCycles().
| uint32_t stk_hires_frequency | ( | void | ) |
Get CPU clock frequency in Hz.
Definition at line 623 of file stk_c.cpp.
References stk::hw::HiResClock::GetFrequency().
| stk_tick_t stk_hires_time_us | ( | void | ) |
Get elapsed time in microseconds from the high-resolution clock.
Definition at line 624 of file stk_c.cpp.
References stk::hw::HiResClock::GetTimeUs().
| void stk_kernel_add_task | ( | stk_kernel_t * | k, |
| stk_task_t * | tsk ) |
Add task to non-HRT kernel (static or dynamic).
| [in] | k | Kernel handle. |
| [in] | tsk | Task handle created with one of stk_task_create_* functions. |
Definition at line 417 of file stk_c.cpp.
References stk::IKernel::AddTask(), CastCToKernelInterface(), stk_task_t::handle, and STK_ASSERT.
| void stk_kernel_add_task_hrt | ( | stk_kernel_t * | k, |
| stk_task_t * | tsk, | ||
| int32_t | periodicity_ticks, | ||
| int32_t | deadline_ticks, | ||
| int32_t | start_delay_ticks ) |
Add task with HRT timing parameters (HRT kernels only).
| [in] | k | Kernel handle. |
| [in] | tsk | Task handle. |
| [in] | periodicity_ticks | Period in ticks. |
| [in] | deadline_ticks | Relative deadline in ticks. |
| [in] | start_delay_ticks | Initial offset / phase in ticks (>= 0). |
Definition at line 525 of file stk_c.cpp.
References stk::IKernel::AddTask(), CastCToKernelInterface(), stk_task_t::handle, and STK_ASSERT.
| stk_kernel_t * stk_kernel_create | ( | uint8_t | core_nr | ) |
Create kernel.
| [in] | core_nr | CPU core number (starts with 0). Max: 7 (for 8 cores). |
Definition at line 333 of file stk_c.cpp.
References CastCppKernelInterfaceToC(), STK_ASSERT, STK_C_CPU_COUNT, STK_KERNEL_CASE, and STK_STATIC_ASSERT.
| void stk_kernel_destroy | ( | stk_kernel_t * | k | ) |
Destroy dynamic kernel instance (only when not running).
| [in] | k | Kernel handle. |
Definition at line 374 of file stk_c.cpp.
References CastCToKernelInterface(), STK_ASSERT, and UnregisterKernel().
| size_t stk_kernel_enumerate_tasks | ( | stk_kernel_t * | k, |
| stk_task_t ** | tasks, | ||
| size_t | max_count ) |
Enumerate all currently active tasks.
| [in] | k | Kernel handle. |
| [out] | tasks | Caller-allocated array of opaque task pointers. Each element is a stk_task_t* that can be passed to other stk_task_* / stk_kernel_* functions. |
| [in] | max_count | Capacity of the tasks array (number of elements). |
Definition at line 466 of file stk_c.cpp.
References CastCppTaskInterfaceToC(), CastCToKernelInterface(), stk::IKernel::EnumerateTasks(), STK_ASSERT, and STK_C_TASKS_MAX.
| stk_kernel_state_t stk_kernel_get_state | ( | const stk_kernel_t * | k | ) |
Get state of the scheduler.
| [in] | k | Kernel handle. |
Definition at line 402 of file stk_c.cpp.
References CastCToKernelInterfaceConst(), stk::IKernel::GetState(), and STK_ASSERT.
| void stk_kernel_init | ( | stk_kernel_t * | k, |
| uint32_t | tick_period_us ) |
Initialize kernel with given tick period.
| [in] | k | Kernel handle. |
| [in] | tick_period_us | System tick period in microseconds (usually 100–10000). |
Definition at line 388 of file stk_c.cpp.
References CastCToKernelInterface(), stk::IKernel::Initialize(), and STK_ASSERT.
| bool stk_kernel_is_schedulable | ( | const stk_kernel_t * | k | ) |
Test whether currently configured task set is schedulable.
| [in] | k | Kernel handle. |
Definition at line 409 of file stk_c.cpp.
References CastCToKernelInterfaceConst(), stk::SchedulabilityCheck::IsSchedulableWCRT(), and STK_ASSERT.
| bool stk_kernel_is_started | ( | const stk_kernel_t * | k | ) |
Check whether the scheduler is currently running (first task switch has occurred).
| [in] | k | Kernel handle. |
Definition at line 433 of file stk_c.cpp.
References CastCToKernelInterfaceConst(), stk::IKernel::GetState(), stk::IKernel::KSTATE_RUNNING, stk::IKernel::KSTATE_SUSPENDED, and STK_ASSERT.
| void stk_kernel_process_hard_fault | ( | stk_kernel_t * | k | ) |
Trigger a kernel hard fault (safe-state handler).
| [in] | k | Kernel handle. |
Definition at line 511 of file stk_c.cpp.
References CastCToKernelInterface(), stk::IKernel::GetPlatform(), stk::IPlatform::ProcessHardFault(), and STK_ASSERT.
| void stk_kernel_process_tick | ( | stk_kernel_t * | k | ) |
Manually deliver one scheduler tick to the kernel.
| [in] | k | Kernel handle. |
Definition at line 504 of file stk_c.cpp.
References CastCToKernelInterface(), stk::IKernel::GetPlatform(), stk::IPlatform::ProcessTick(), and STK_ASSERT.
| void stk_kernel_remove_task | ( | stk_kernel_t * | k, |
| stk_task_t * | tsk ) |
Remove finished task from dynamic kernel.
| [in] | k | Kernel handle. |
| [in] | tsk | Task that has already returned from its entry function. |
Definition at line 425 of file stk_c.cpp.
References CastCToKernelInterface(), stk_task_t::handle, stk::IKernel::RemoveTask(), and STK_ASSERT.
| void stk_kernel_resume | ( | stk_kernel_t * | k, |
| stk_timeout_t | elapsed_ticks ) |
Resume scheduling after a prior stk_kernel_suspend() call.
| [in] | k | Kernel handle. |
| [in] | elapsed_ticks | Number of ticks that elapsed during the suspended period. The kernel uses this value to advance internal time counters and wake tasks whose sleep deadlines have expired. |
Definition at line 497 of file stk_c.cpp.
References CastCToKernelInterface(), stk::IKernel::GetPlatform(), stk::IPlatform::Resume(), and STK_ASSERT.
| void stk_kernel_resume_task | ( | stk_kernel_t * | k, |
| stk_task_t * | task ) |
Resume a previously suspended task.
| [in] | k | Kernel handle. |
| [in] | task | Task to resume. Must have been suspended with stk_kernel_suspend_task(). |
Definition at line 458 of file stk_c.cpp.
References CastCToKernelInterface(), stk_task_t::handle, stk::IKernel::ResumeTask(), and STK_ASSERT.
| void stk_kernel_schedule_task_removal | ( | stk_kernel_t * | k, |
| stk_task_t * | task ) |
Schedule removal of a running task from the kernel on the next tick.
| [in] | k | Kernel handle. |
| [in] | task | Task to remove. Must be currently scheduled. |
Definition at line 441 of file stk_c.cpp.
References CastCToKernelInterface(), stk_task_t::handle, stk::IKernel::ScheduleTaskRemoval(), and STK_ASSERT.
| void stk_kernel_set_event_overrider | ( | stk_kernel_t * | k, |
| stk_event_overrider_t * | overrider ) |
Install a platform event overrider on the kernel.
Forwards to IPlatform::SetEventOverrider() via an internal C++ bridge object. Any previously installed overrider is replaced.
| [in] | k | Kernel handle obtained from stk_kernel_create(). |
| [in] | overrider | Pointer to a caller-owned stk_event_overrider_t. Pass NULL to remove a previously installed overrider. When non-NULL, the struct must remain valid for the entire lifetime of the kernel (static or global storage is recommended). |
stk_kernel_init() and before stk_kernel_start(). Definition at line 518 of file stk_c.cpp.
References CastCToKernelInterface(), SetEventOverrider(), and STK_ASSERT.
| void stk_kernel_start | ( | stk_kernel_t * | k | ) |
Start the scheduler - never returns.
| [in] | k | Kernel handle. |
Definition at line 395 of file stk_c.cpp.
References CastCToKernelInterface(), stk::IKernel::Start(), and STK_ASSERT.
| stk_timeout_t stk_kernel_suspend | ( | stk_kernel_t * | k | ) |
Suspend scheduling (tickless idle entry point).
| [in] | k | Kernel handle. |
Definition at line 490 of file stk_c.cpp.
References CastCToKernelInterface(), stk::IKernel::GetPlatform(), STK_ASSERT, and stk::IPlatform::Suspend().
| void stk_kernel_suspend_task | ( | stk_kernel_t * | k, |
| stk_task_t * | task, | ||
| bool * | suspended ) |
Suspend a task (prevent it from being scheduled).
| [in] | k | Kernel handle. |
| [in] | task | Task to suspend. |
| [out] | suspended | Set to true if the task was successfully suspended (was awake), false if the task was already sleeping (e.g. blocked on a mutex or timed Sleep). |
Definition at line 449 of file stk_c.cpp.
References CastCToKernelInterface(), stk_task_t::handle, STK_ASSERT, and stk::IKernel::SuspendTask().
|
inlinestatic |
Convert ticks to milliseconds using the current kernel tick resolution.
| [in] | ticks | Tick count to convert. |
Definition at line 664 of file stk_c.h.
References stk_ms_from_ticks_r(), and stk_tick_resolution().
|
inlinestatic |
Convert ticks to milliseconds using an explicit tick resolution.
| [in] | ticks | Tick count to convert. |
| [in] | resolution | Microseconds per tick (see stk_tick_resolution()). |
Definition at line 653 of file stk_c.h.
References STK_STATIC_CAST.
Referenced by stk_ms_from_ticks().
| stk_msgq_t * stk_msgq_create | ( | stk_msgq_mem_t *const | membuf, |
| uint32_t | membuf_size, | ||
| uint8_t * | buf, | ||
| uint32_t | buf_size, | ||
| size_t | capacity, | ||
| size_t | msg_size ) |
Create a MessageQueue (using provided memory).
Constructs a stk::sync::MessageQueue in-place inside membuf. The queue will hold up to capacity messages, each msg_size bytes wide. The backing storage for messages must be supplied by the caller via buf / buf_size.
| [in] | membuf | Pointer to static memory container for the queue object. Must be at least sizeof(stk_msgq_mem_t) bytes. |
| [in] | membuf_size | Size of membuf in bytes (must be >= sizeof(stk_msgq_mem_t)). |
| [in] | buf | Pointer to the message data buffer. Must be at least capacity * msg_size bytes. |
| [in] | buf_size | Size of buf in bytes (used only for the safety assertion; must equal capacity * msg_size). |
| [in] | capacity | Maximum number of messages [1, 65534]. |
| [in] | msg_size | Size of each individual message in bytes (>= 1). |
Definition at line 582 of file stk_c_sync.cpp.
References STK_ASSERT.
| void stk_msgq_destroy | ( | stk_msgq_t * | mq | ) |
Destroy a MessageQueue.
| [in] | mq | MessageQueue handle. |
Definition at line 605 of file stk_c_sync.cpp.
| bool stk_msgq_get | ( | stk_msgq_t * | mq, |
| void * | msg, | ||
| stk_timeout_t | timeout ) |
Get a message from the queue.
Copies the oldest message into msg. Blocks if the queue is empty until a message arrives or the timeout expires.
| [in] | mq | MessageQueue handle. |
| [out] | msg | Destination buffer (must be >= msg_size bytes). |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
STK_NO_WAIT. Definition at line 645 of file stk_c_sync.cpp.
References stk::sync::MessageQueue::Get(), stk_msgq_t::handle, and STK_ASSERT.
| uint8_t * stk_msgq_get_buffer | ( | stk_msgq_t * | mq | ) |
Get a pointer to the raw message data buffer.
| [in] | mq | MessageQueue handle. |
Definition at line 742 of file stk_c_sync.cpp.
References stk::sync::MessageQueue::GetBuffer(), stk_msgq_t::handle, and STK_ASSERT.
| size_t stk_msgq_get_capacity | ( | const stk_msgq_t * | mq | ) |
Get the maximum number of messages the queue can hold.
| [in] | mq | MessageQueue handle. |
Definition at line 700 of file stk_c_sync.cpp.
References stk::sync::MessageQueue::GetCapacity(), stk_msgq_t::handle, and STK_ASSERT.
| size_t stk_msgq_get_count | ( | const stk_msgq_t * | mq | ) |
Get the current number of messages waiting in the queue.
| [in] | mq | MessageQueue handle. |
Definition at line 714 of file stk_c_sync.cpp.
References stk::sync::MessageQueue::GetCount(), stk_msgq_t::handle, and STK_ASSERT.
| size_t stk_msgq_get_msg_size | ( | const stk_msgq_t * | mq | ) |
Get the size of each message in bytes.
| [in] | mq | MessageQueue handle. |
Definition at line 707 of file stk_c_sync.cpp.
References stk::sync::MessageQueue::GetMsgSize(), stk_msgq_t::handle, and STK_ASSERT.
| size_t stk_msgq_get_space | ( | const stk_msgq_t * | mq | ) |
Get the number of free slots currently available.
| [in] | mq | MessageQueue handle. |
Definition at line 721 of file stk_c_sync.cpp.
References stk::sync::MessageQueue::GetSpace(), stk_msgq_t::handle, and STK_ASSERT.
| bool stk_msgq_is_empty | ( | const stk_msgq_t * | mq | ) |
Check whether the queue is currently empty.
| [in] | mq | MessageQueue handle. |
Definition at line 728 of file stk_c_sync.cpp.
References stk_msgq_t::handle, stk::sync::MessageQueue::IsEmpty(), and STK_ASSERT.
| bool stk_msgq_is_full | ( | const stk_msgq_t * | mq | ) |
Check whether the queue is currently full.
| [in] | mq | MessageQueue handle. |
Definition at line 735 of file stk_c_sync.cpp.
References stk_msgq_t::handle, stk::sync::MessageQueue::IsFull(), and STK_ASSERT.
| bool stk_msgq_is_storage_valid | ( | const stk_msgq_t * | mq | ) |
Verify that the backing storage is valid and the queue is ready for use.
Always true for queues constructed with a non-NULL buffer. Useful as a post-construction sanity check in no-exceptions environments; stk_msgq_create() returning NULL already covers the primary failure path.
| [in] | mq | MessageQueue handle. |
Definition at line 749 of file stk_c_sync.cpp.
References stk_msgq_t::handle, stk::sync::MessageQueue::IsStorageValid(), and STK_ASSERT.
| bool stk_msgq_peek | ( | stk_msgq_t * | mq, |
| void * | msg, | ||
| stk_timeout_t | timeout ) |
Peek at the next message to be delivered without removing it.
Copies msg_size bytes from the oldest slot into msg, leaving the message in place so that a subsequent stk_msgq_get() returns the same message. Blocks if the queue is empty until a message is available or the timeout expires.
| [in] | mq | MessageQueue handle. |
| [out] | msg | Destination buffer (must be >= msg_size bytes). |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
STK_NO_WAIT. Definition at line 661 of file stk_c_sync.cpp.
References stk_msgq_t::handle, stk::sync::MessageQueue::Peek(), and STK_ASSERT.
| bool stk_msgq_peekfront | ( | stk_msgq_t * | mq, |
| void * | msg, | ||
| stk_timeout_t | timeout ) |
Peek at the most recently front-inserted message without removing it.
Copies msg_size bytes from the front slot (i.e. the message that stk_msgq_putfront() most recently placed) into msg, leaving the message in the queue. Blocks if the queue is empty until a message is available or the timeout expires.
| [in] | mq | MessageQueue handle. |
| [out] | msg | Destination buffer (must be >= msg_size bytes). |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
STK_NO_WAIT. Definition at line 677 of file stk_c_sync.cpp.
References stk_msgq_t::handle, stk::sync::MessageQueue::PeekFront(), and STK_ASSERT.
| bool stk_msgq_put | ( | stk_msgq_t * | mq, |
| const void * | msg, | ||
| stk_timeout_t | timeout ) |
Put a message into the queue.
Copies msg_size bytes from msg into the next available slot. Blocks if the queue is full until space becomes available or the timeout expires.
| [in] | mq | MessageQueue handle. |
| [in] | msg | Pointer to the message payload (must be >= msg_size bytes). |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
STK_NO_WAIT. Definition at line 613 of file stk_c_sync.cpp.
References stk_msgq_t::handle, stk::sync::MessageQueue::Put(), and STK_ASSERT.
| bool stk_msgq_putfront | ( | stk_msgq_t * | mq, |
| const void * | msg, | ||
| stk_timeout_t | timeout ) |
Put a message into the front of the queue (priority insert).
Copies msg_size bytes from msg into the slot immediately before the current read pointer, making it the next message that stk_msgq_get() will return. Blocks if the queue is full until space becomes available or the timeout expires.
| [in] | mq | MessageQueue handle. |
| [in] | msg | Pointer to the message payload (must be >= msg_size bytes). |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
STK_NO_WAIT. Definition at line 629 of file stk_c_sync.cpp.
References stk_msgq_t::handle, stk::sync::MessageQueue::PutFront(), and STK_ASSERT.
| void stk_msgq_reset | ( | stk_msgq_t * | mq | ) |
Discard all messages and reset the queue to the empty state.
Tasks blocked in Put() are woken so they can re-enqueue into the now-empty queue.
| [in] | mq | MessageQueue handle. |
Definition at line 693 of file stk_c_sync.cpp.
References stk_msgq_t::handle, stk::sync::MessageQueue::Reset(), and STK_ASSERT.
| bool stk_msgq_tryget | ( | stk_msgq_t * | mq, |
| void * | msg ) |
Attempt to get a message from the queue without blocking.
| [in] | mq | MessageQueue handle. |
| [out] | msg | Destination buffer. |
Definition at line 653 of file stk_c_sync.cpp.
References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryGet().
| bool stk_msgq_trypeek | ( | stk_msgq_t * | mq, |
| void * | msg ) |
Attempt to peek at the next message without blocking.
| [in] | mq | MessageQueue handle. |
| [out] | msg | Destination buffer (must be >= msg_size bytes). |
Definition at line 669 of file stk_c_sync.cpp.
References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryPeek().
| bool stk_msgq_trypeekfront | ( | stk_msgq_t * | mq, |
| void * | msg ) |
Attempt to peek at the front message without blocking.
| [in] | mq | MessageQueue handle. |
| [out] | msg | Destination buffer (must be >= msg_size bytes). |
Definition at line 685 of file stk_c_sync.cpp.
References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryPeekFront().
| bool stk_msgq_tryput | ( | stk_msgq_t * | mq, |
| const void * | msg ) |
Attempt to put a message into the queue without blocking.
| [in] | mq | MessageQueue handle. |
| [in] | msg | Pointer to the message payload. |
Definition at line 621 of file stk_c_sync.cpp.
References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryPut().
| bool stk_msgq_tryputfront | ( | stk_msgq_t * | mq, |
| const void * | msg ) |
Attempt to put a message into the front of the queue without blocking.
| [in] | mq | MessageQueue handle. |
| [in] | msg | Pointer to the message payload. |
Definition at line 637 of file stk_c_sync.cpp.
References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryPutFront().
| stk_mutex_t * stk_mutex_create | ( | stk_mutex_mem_t *const | membuf, |
| uint32_t | membuf_size ) |
Create a Mutex (using provided memory).
| [in] | membuf | Pointer to static memory container. |
| [in] | membuf_size | Size of the container (must be >= sizeof(stk_mutex_mem_t)). |
Definition at line 35 of file stk_c_sync.cpp.
References stk_mutex_mem_t::data, and STK_ASSERT.
| void stk_mutex_destroy | ( | stk_mutex_t * | mtx | ) |
Destroy a Mutex.
| [in] | mtx | Mutex handle. |
Definition at line 49 of file stk_c_sync.cpp.
| void stk_mutex_lock | ( | stk_mutex_t * | mtx | ) |
Lock the mutex. Blocks until available.
| [in] | mtx | Mutex handle. |
Definition at line 57 of file stk_c_sync.cpp.
References stk_mutex_t::handle, stk::sync::Mutex::Lock(), and STK_ASSERT.
| bool stk_mutex_timed_lock | ( | stk_mutex_t * | mtx, |
| stk_timeout_t | timeout ) |
Try to lock the mutex with a timeout.
| [in] | mtx | Mutex handle. |
| [in] | timeout | Max time to wait in milliseconds. |
Definition at line 78 of file stk_c_sync.cpp.
References stk_mutex_t::handle, STK_ASSERT, and stk::sync::Mutex::TimedLock().
| bool stk_mutex_trylock | ( | stk_mutex_t * | mtx | ) |
Try locking the mutex. Does not block if already locked.
| [in] | mtx | Mutex handle. |
Definition at line 64 of file stk_c_sync.cpp.
References stk_mutex_t::handle, STK_ASSERT, and stk::sync::Mutex::TryLock().
| void stk_mutex_unlock | ( | stk_mutex_t * | mtx | ) |
Unlock the mutex.
| [in] | mtx | Mutex handle. |
Definition at line 71 of file stk_c_sync.cpp.
References stk_mutex_t::handle, STK_ASSERT, and stk::sync::Mutex::Unlock().
| stk_pipe_t * stk_pipe_create | ( | stk_pipe_mem_t *const | membuf, |
| uint32_t | membuf_size, | ||
| uint8_t * | buf, | ||
| uint32_t | buf_size, | ||
| size_t | capacity, | ||
| size_t | element_size ) |
Create a Pipe (using provided memory).
Constructs a stk::sync::Pipe in-place inside membuf. The pipe will hold up to capacity elements, each element_size bytes wide. The backing ring-buffer storage must be supplied by the caller via buf / buf_size.
| [in] | membuf | Pointer to static memory container for the Pipe control-block. Must be at least sizeof(stk_pipe_mem_t) bytes. |
| [in] | membuf_size | Size of membuf in bytes. |
| [in] | buf | Pointer to the element data buffer. Must be at least capacity * element_size bytes. |
| [in] | buf_size | Size of buf in bytes (used for the safety assertion; must equal capacity * element_size). |
| [in] | capacity | Maximum number of elements [1, 65534]. |
| [in] | element_size | Size of each individual element in bytes (>= 1). |
Definition at line 405 of file stk_c_sync.cpp.
References stk_pipe_mem_t::data, and STK_ASSERT.
| void stk_pipe_destroy | ( | stk_pipe_t * | pipe | ) |
Destroy a Pipe.
| [in] | pipe | Pipe handle. |
Definition at line 428 of file stk_c_sync.cpp.
| size_t stk_pipe_get_capacity | ( | const stk_pipe_t * | pipe | ) |
Get the maximum number of elements the pipe can hold.
| [in] | pipe | Pipe handle. |
Definition at line 521 of file stk_c_sync.cpp.
References stk::sync::Pipe::GetCapacity(), stk_pipe_t::handle, and STK_ASSERT.
| size_t stk_pipe_get_count | ( | const stk_pipe_t * | pipe | ) |
Get the current number of elements in the pipe.
| [in] | pipe | Pipe handle. |
Definition at line 535 of file stk_c_sync.cpp.
References stk::sync::Pipe::GetCount(), stk_pipe_t::handle, and STK_ASSERT.
| size_t stk_pipe_get_element_size | ( | const stk_pipe_t * | pipe | ) |
Get the size of each element in bytes.
| [in] | pipe | Pipe handle. |
Definition at line 528 of file stk_c_sync.cpp.
References stk::sync::Pipe::GetElementSize(), stk_pipe_t::handle, and STK_ASSERT.
| size_t stk_pipe_get_space | ( | const stk_pipe_t * | pipe | ) |
Get the number of free slots currently available.
| [in] | pipe | Pipe handle. |
Definition at line 542 of file stk_c_sync.cpp.
References stk::sync::Pipe::GetSpace(), stk_pipe_t::handle, and STK_ASSERT.
| bool stk_pipe_is_empty | ( | const stk_pipe_t * | pipe | ) |
Check whether the pipe is currently empty.
| [in] | pipe | Pipe handle. |
Definition at line 549 of file stk_c_sync.cpp.
References stk_pipe_t::handle, stk::sync::Pipe::IsEmpty(), and STK_ASSERT.
| bool stk_pipe_is_full | ( | const stk_pipe_t * | pipe | ) |
Check whether the pipe is currently full.
| [in] | pipe | Pipe handle. |
Definition at line 556 of file stk_c_sync.cpp.
References stk_pipe_t::handle, stk::sync::Pipe::IsFull(), and STK_ASSERT.
| bool stk_pipe_is_storage_valid | ( | const stk_pipe_t * | pipe | ) |
Verify that the backing storage is valid and the pipe is ready for use.
| [in] | pipe | Pipe handle. |
Definition at line 563 of file stk_c_sync.cpp.
References stk_pipe_t::handle, stk::sync::Pipe::IsStorageValid(), and STK_ASSERT.
| bool stk_pipe_read | ( | stk_pipe_t * | pipe, |
| void * | data, | ||
| stk_timeout_t | timeout ) |
Read a single element from the pipe.
Copies element_size bytes from the oldest slot into the buffer pointed to by data. Blocks if the pipe is empty until data is produced or the timeout expires.
| [in] | pipe | Pipe handle. |
| [out] | data | Destination buffer (must be >= element_size bytes). |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
STK_NO_WAIT. Definition at line 452 of file stk_c_sync.cpp.
References stk_pipe_t::handle, stk::sync::Pipe::Read(), and STK_ASSERT.
| size_t stk_pipe_read_bulk | ( | stk_pipe_t * | pipe, |
| void * | dst, | ||
| size_t | count, | ||
| stk_timeout_t | timeout ) |
Read multiple elements from the pipe.
Attempts to retrieve count elements from the FIFO. Blocks until the full amount is read or the timeout expires.
| [in] | pipe | Pipe handle. |
| [out] | dst | Pointer to the destination array (must hold at least count elements of element_size bytes each). |
| [in] | count | Number of elements to read. |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
count unless a timeout occurred. STK_NO_WAIT. Definition at line 482 of file stk_c_sync.cpp.
References stk_pipe_t::handle, stk::sync::Pipe::ReadBulk(), and STK_ASSERT.
| size_t stk_pipe_read_bulk_triggered | ( | stk_pipe_t * | pipe, |
| void * | dst, | ||
| size_t | trigger, | ||
| size_t | max_count, | ||
| stk_timeout_t | timeout ) |
Read at least trigger elements, then drain up to max_count without blocking.
Blocks until at least trigger elements are simultaneously available in the pipe, or the timeout expires. Once the threshold is reached the call dequeues min(max_count, available) elements in a single atomic pass.
| [in] | pipe | Pipe handle. |
| [out] | dst | Destination buffer; must hold at least max_count elements of element_size bytes. |
| [in] | trigger | Minimum number of elements that must be available before any data is dequeued. Clamped to [1, max_count] internally. |
| [in] | max_count | Maximum number of elements to return in total. |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
STK_NO_WAIT. Definition at line 496 of file stk_c_sync.cpp.
References stk_pipe_t::handle, stk::sync::Pipe::ReadBulkTriggered(), and STK_ASSERT.
| void stk_pipe_reset | ( | stk_pipe_t * | pipe | ) |
Discard all elements and reset the pipe to the empty state.
Any tasks blocked in Write() are woken so they can re-evaluate.
| [in] | pipe | Pipe handle. |
Definition at line 514 of file stk_c_sync.cpp.
References stk_pipe_t::handle, stk::sync::Pipe::Reset(), and STK_ASSERT.
| bool stk_pipe_tryread | ( | stk_pipe_t * | pipe, |
| void * | data ) |
Attempt to read a single element from the pipe without blocking.
| [in] | pipe | Pipe handle. |
| [out] | data | Destination buffer (must be >= element_size bytes). |
Definition at line 460 of file stk_c_sync.cpp.
References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryRead().
| size_t stk_pipe_tryread_bulk | ( | stk_pipe_t * | pipe, |
| void * | dst, | ||
| size_t | count ) |
Attempt to read multiple elements from the pipe without blocking.
Reads as many elements as are currently available without blocking.
| [in] | pipe | Pipe handle. |
| [out] | dst | Pointer to the destination array. |
| [in] | count | Number of elements to read. |
Definition at line 489 of file stk_c_sync.cpp.
References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryReadBulk().
| size_t stk_pipe_tryread_bulk_triggered | ( | stk_pipe_t * | pipe, |
| void * | dst, | ||
| size_t | max_count ) |
Non-blocking variant of stk_pipe_read_bulk_triggered.
Returns immediately with however many elements are available, up to max_count. The trigger threshold is not enforced.
| [in] | pipe | Pipe handle. |
| [out] | dst | Destination buffer. |
| [in] | max_count | Maximum number of elements to read. |
Definition at line 507 of file stk_c_sync.cpp.
References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryReadBulkTriggered().
| bool stk_pipe_trywrite | ( | stk_pipe_t * | pipe, |
| const void * | data ) |
Attempt to write a single element to the pipe without blocking.
| [in] | pipe | Pipe handle. |
| [in] | data | Pointer to the element payload. |
Definition at line 444 of file stk_c_sync.cpp.
References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryWrite().
| size_t stk_pipe_trywrite_bulk | ( | stk_pipe_t * | pipe, |
| const void * | src, | ||
| size_t | count ) |
Attempt to write multiple elements to the pipe without blocking.
Copies as many elements as possible. Elements that do not fit are discarded.
| [in] | pipe | Pipe handle. |
| [in] | src | Pointer to the source array. |
| [in] | count | Number of elements to write. |
Definition at line 475 of file stk_c_sync.cpp.
References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryWriteBulk().
| bool stk_pipe_write | ( | stk_pipe_t * | pipe, |
| const void * | data, | ||
| stk_timeout_t | timeout ) |
Write a single element to the pipe.
Copies element_size bytes from data into the next available slot. Blocks if the pipe is full until space becomes available or the timeout expires.
| [in] | pipe | Pipe handle. |
| [in] | data | Pointer to the element payload (must be >= element_size bytes). |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
STK_NO_WAIT. Definition at line 436 of file stk_c_sync.cpp.
References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::Write().
| size_t stk_pipe_write_bulk | ( | stk_pipe_t * | pipe, |
| const void * | src, | ||
| size_t | count, | ||
| stk_timeout_t | timeout ) |
Write multiple elements to the pipe.
Copies a block of count elements. Blocks until the full amount is written or the timeout expires.
| [in] | pipe | Pipe handle. |
| [in] | src | Pointer to the source array (must hold at least count elements of element_size bytes each). |
| [in] | count | Number of elements to write. |
| [in] | timeout | Max time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt. |
count unless a timeout occurred. STK_NO_WAIT. Definition at line 468 of file stk_c_sync.cpp.
References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::WriteBulk().
| stk_rwmutex_t * stk_rwmutex_create | ( | stk_rwmutex_mem_t *const | membuf, |
| uint32_t | membuf_size ) |
Create an RWMutex (using provided memory).
| [in] | membuf | Pointer to static memory container. |
| [in] | membuf_size | Size of the container (must be >= sizeof(stk_rwmutex_mem_t)). |
Definition at line 764 of file stk_c_sync.cpp.
References stk_rwmutex_mem_t::data, and STK_ASSERT.
| void stk_rwmutex_destroy | ( | stk_rwmutex_t * | rw | ) |
Destroy an RWMutex.
| [in] | rw | RWMutex handle. |
Definition at line 778 of file stk_c_sync.cpp.
| void stk_rwmutex_lock | ( | stk_rwmutex_t * | rw | ) |
Acquire the lock for exclusive writing. Blocks until available.
Blocks until all active readers have released their locks and no other writer is active.
| [in] | rw | RWMutex handle. |
Definition at line 814 of file stk_c_sync.cpp.
References stk_rwmutex_t::handle, stk::sync::RWMutex::Lock(), and STK_ASSERT.
| void stk_rwmutex_read_lock | ( | stk_rwmutex_t * | rw | ) |
Acquire the lock for shared reading. Blocks until available.
Blocks if a writer is currently active or writers are waiting (Writer Preference Policy).
| [in] | rw | RWMutex handle. |
Definition at line 786 of file stk_c_sync.cpp.
References stk_rwmutex_t::handle, stk::sync::RWMutex::ReadLock(), and STK_ASSERT.
| void stk_rwmutex_read_unlock | ( | stk_rwmutex_t * | rw | ) |
Release the shared reader lock.
If this is the last active reader, waiting writers are notified.
| [in] | rw | RWMutex handle. |
Definition at line 807 of file stk_c_sync.cpp.
References stk_rwmutex_t::handle, stk::sync::RWMutex::ReadUnlock(), and STK_ASSERT.
| bool stk_rwmutex_timed_lock | ( | stk_rwmutex_t * | rw, |
| stk_timeout_t | timeout ) |
Try to acquire the write lock with a timeout.
| [in] | rw | RWMutex handle. |
| [in] | timeout | Max time to wait (ticks). Use STK_NO_WAIT for non-blocking. |
Definition at line 828 of file stk_c_sync.cpp.
References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::TimedLock().
| bool stk_rwmutex_timed_read_lock | ( | stk_rwmutex_t * | rw, |
| stk_timeout_t | timeout ) |
Try to acquire the read lock with a timeout.
| [in] | rw | RWMutex handle. |
| [in] | timeout | Max time to wait (ticks). Use STK_NO_WAIT for non-blocking. |
Definition at line 800 of file stk_c_sync.cpp.
References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::TimedReadLock().
| bool stk_rwmutex_try_read_lock | ( | stk_rwmutex_t * | rw | ) |
Try to acquire the read lock without blocking.
| [in] | rw | RWMutex handle. |
Definition at line 793 of file stk_c_sync.cpp.
References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::TryReadLock().
| bool stk_rwmutex_trylock | ( | stk_rwmutex_t * | rw | ) |
Try to acquire the write lock without blocking.
| [in] | rw | RWMutex handle. |
Definition at line 821 of file stk_c_sync.cpp.
References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::TryLock().
| void stk_rwmutex_unlock | ( | stk_rwmutex_t * | rw | ) |
Release the exclusive writer lock.
Prioritizes waking waiting writers. If none are waiting, all waiting readers are woken (Writer Preference Policy).
| [in] | rw | RWMutex handle. |
Definition at line 835 of file stk_c_sync.cpp.
References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::Unlock().
| stk_sem_t * stk_sem_create | ( | stk_sem_mem_t *const | membuf, |
| uint32_t | membuf_size, | ||
| uint32_t | initial_count, | ||
| uint32_t | max_count ) |
Create a Semaphore (using provided memory).
| [in] | membuf | Pointer to static memory container. |
| [in] | membuf_size | Size of the container (must be >= sizeof(stk_sem_mem_t)). |
| [in] | initial_count | Starting value of the resource counter. |
| [in] | max_count | Maximum value the counter is allowed to reach. Pass 0 to use the default maximum (65534). Must be > initial_count. |
Definition at line 268 of file stk_c_sync.cpp.
References stk::sync::Semaphore::COUNT_MAX, stk_sem_mem_t::data, and STK_ASSERT.
| void stk_sem_destroy | ( | stk_sem_t * | sem | ) |
Destroy a Semaphore.
| [in] | sem | Semaphore handle. |
Definition at line 287 of file stk_c_sync.cpp.
| uint16_t stk_sem_get_count | ( | const stk_sem_t * | sem | ) |
Get the current counter value.
| [in] | sem | Semaphore handle. |
Definition at line 316 of file stk_c_sync.cpp.
References stk::sync::Semaphore::GetCount(), stk_sem_t::handle, and STK_ASSERT.
| void stk_sem_signal | ( | stk_sem_t * | sem | ) |
Signal/Release a semaphore resource.
| [in] | sem | Semaphore handle. |
Definition at line 309 of file stk_c_sync.cpp.
References stk_sem_t::handle, stk::sync::Semaphore::Signal(), and STK_ASSERT.
| bool stk_sem_trywait | ( | stk_sem_t * | sem | ) |
Poll the semaphore without blocking.
Acquires a resource token if one is immediately available; returns false instantly if the counter is zero.
| [in] | sem | Semaphore handle. |
Definition at line 302 of file stk_c_sync.cpp.
References stk_sem_t::handle, STK_ASSERT, and stk::sync::Semaphore::TryWait().
| bool stk_sem_wait | ( | stk_sem_t * | sem, |
| stk_timeout_t | timeout ) |
Wait for a semaphore resource.
| [in] | sem | Semaphore handle. |
| [in] | timeout | Max time to wait (ticks). |
Definition at line 295 of file stk_c_sync.cpp.
References stk_sem_t::handle, STK_ASSERT, and stk::sync::Semaphore::Wait().
| void stk_sleep | ( | stk_timeout_t | ticks | ) |
Put current task to sleep (non-HRT kernels only).
| [in] | ticks | Ticks to sleep. |
Definition at line 626 of file stk_c.cpp.
References stk::Sleep().
| void stk_sleep_cancel | ( | stk_tid_t | tid | ) |
Cancel the sleep of a task, waking it immediately.
| [in] | tid | Identifier of the task to wake (obtained from stk_tid() or stk_task_get_id()). |
Definition at line 630 of file stk_c.cpp.
References stk::SleepCancel().
| void stk_sleep_ms | ( | stk_timeout_t | ms | ) |
Put current task to sleep (non-HRT kernels only).
| [in] | ms | Milliseconds to sleep. |
Definition at line 628 of file stk_c.cpp.
References stk::SleepMs().
| bool stk_sleep_until | ( | stk_tick_t | ts | ) |
Put current task to sleep (non-HRT kernels only).
| [in] | ts | Absolute time (timestamp), a deadline for a sleep period. |
Definition at line 629 of file stk_c.cpp.
References stk::SleepUntil().
| stk_spinlock_t * stk_spinlock_create | ( | stk_spinlock_mem_t *const | membuf, |
| uint32_t | membuf_size ) |
Create a recursive SpinLock.
| [in] | membuf | Pointer to static memory container. |
| [in] | membuf_size | Size of the container (must be >= sizeof(stk_spinlock_mem_t)). |
Definition at line 93 of file stk_c_sync.cpp.
References stk_spinlock_mem_t::data, and STK_ASSERT.
| void stk_spinlock_destroy | ( | stk_spinlock_t * | slock | ) |
Destroy the SpinLock.
Definition at line 107 of file stk_c_sync.cpp.
| void stk_spinlock_lock | ( | stk_spinlock_t * | slock | ) |
Acquire the SpinLock (recursive).
Definition at line 115 of file stk_c_sync.cpp.
References stk_spinlock_t::handle, stk::sync::SpinLock::Lock(), and STK_ASSERT.
| bool stk_spinlock_trylock | ( | stk_spinlock_t * | slock | ) |
Attempt to acquire the SpinLock immediately.
Definition at line 121 of file stk_c_sync.cpp.
References stk_spinlock_t::handle, STK_ASSERT, and stk::sync::SpinLock::TryLock().
| void stk_spinlock_unlock | ( | stk_spinlock_t * | slock | ) |
Release the SpinLock.
Definition at line 127 of file stk_c_sync.cpp.
References stk_spinlock_t::handle, STK_ASSERT, and stk::sync::SpinLock::Unlock().
| stk_cycle_t stk_sys_timer_count | ( | void | ) |
Get raw system timer counter value.
Definition at line 620 of file stk_c.cpp.
References stk::GetSysTimerCount().
| uint32_t stk_sys_timer_frequency | ( | void | ) |
Get system timer frequency in Hz.
Definition at line 621 of file stk_c.cpp.
References stk::GetSysTimerFrequency().
| stk_task_t * stk_task_create_privileged | ( | stk_task_entry_t | entry, |
| void * | arg, | ||
| stk_word_t * | stack, | ||
| uint32_t | stack_size ) |
Create privileged-mode (kernel-mode) task.
| [in] | entry | Task entry function. |
| [in] | arg | Argument passed to entry function. |
| [in] | stack | Pointer to stack buffer (array of stk_word_t). |
| [in] | stack_size | Number of elements (words) in the stack buffer. |
Definition at line 544 of file stk_c.cpp.
References stk::ACCESS_PRIVILEGED, AllocateTask(), and STK_ASSERT.
| stk_task_t * stk_task_create_user | ( | stk_task_entry_t | entry, |
| void * | arg, | ||
| stk_word_t * | stack, | ||
| uint32_t | stack_size ) |
Create user-mode task.
| [in] | entry | Task entry function. |
| [in] | arg | Argument passed to entry function. |
| [in] | stack | Pointer to stack buffer (array of stk_word_t). |
| [in] | stack_size | Number of elements (words) in the stack buffer. |
Definition at line 556 of file stk_c.cpp.
References stk::ACCESS_USER, AllocateTask(), and STK_ASSERT.
| void stk_task_destroy | ( | stk_task_t * | tsk | ) |
Destroy dynamically created task object.
| [in] | tsk | Task handle. |
Definition at line 605 of file stk_c.cpp.
References FreeTask(), and STK_ASSERT.
| stk_tid_t stk_task_get_id | ( | const stk_task_t * | tsk | ) |
Get the unique identifier of a task.
| [in] | tsk | Task handle. |
Definition at line 598 of file stk_c.cpp.
References stk::ITask::GetId(), stk_task_t::handle, and STK_ASSERT.
| const char * stk_task_get_name | ( | const stk_task_t * | tsk | ) |
Get human-readable task name previously set with stk_task_set_name().
| [in] | tsk | Task handle. |
Definition at line 591 of file stk_c.cpp.
References TaskWrapper::GetTraceName(), stk_task_t::handle, and STK_ASSERT.
| void stk_task_set_name | ( | stk_task_t * | tsk, |
| const char * | tname ) |
Assign human-readable task name (for tracing/debugging).
| [in] | tsk | Task handle. |
| [in] | tname | Null-terminated string (may be NULL). |
Definition at line 584 of file stk_c.cpp.
References stk_task_t::handle, TaskWrapper::SetName(), and STK_ASSERT.
| void stk_task_set_priority | ( | stk_task_t * | tsk, |
| uint8_t | priority ) |
Set task priority (used only by Fixed Priority scheduler).
| [in] | tsk | Task handle. |
| [in] | priority | Priority level [0 = lowest … 31 = highest]. |
Definition at line 575 of file stk_c.cpp.
References STK_ASSERT, and stk_task_set_weight().
| void stk_task_set_weight | ( | stk_task_t * | tsk, |
| stk_weight_t | weight ) |
Set task weight (used only by Smooth Weighted Round Robin).
| [in] | tsk | Task handle. |
| [in] | weight | Positive weight value (recommended 1–16777215). |
Definition at line 568 of file stk_c.cpp.
References stk_task_t::handle, TaskWrapper::SetWeight(), and STK_ASSERT.
Referenced by stk_task_set_priority().
| uint32_t stk_tick_resolution | ( | void | ) |
Returns how many microseconds correspond to one kernel tick.
Definition at line 617 of file stk_c.cpp.
References stk::GetTickResolution().
Referenced by stk_ms_from_ticks().
| stk_tick_t stk_ticks | ( | void | ) |
Returns number of ticks elapsed since kernel start.
Definition at line 616 of file stk_c.cpp.
References stk::GetTicks().
| stk_tick_t stk_ticks_from_ms | ( | stk_time_t | msec | ) |
Get ticks from milliseconds using current kernel tick resolution.
| [in] | msec | Milliseconds to convert. |
Definition at line 619 of file stk_c.cpp.
References stk::GetTickResolution(), and stk_ticks_from_ms_r().
|
inlinestatic |
Get ticks from milliseconds using an explicit tick resolution.
| [in] | msec | Milliseconds to convert. |
| [in] | resolution | Microseconds per tick (see stk_tick_resolution()). |
Definition at line 629 of file stk_c.h.
References STK_STATIC_CAST.
Referenced by stk_ticks_from_ms().
| stk_tid_t stk_tid | ( | void | ) |
Returns current task/thread ID (the value set by stk_task_set_id).
Definition at line 615 of file stk_c.cpp.
References stk::GetTid().
| stk_time_t stk_time_now_ms | ( | void | ) |
Returns current time in milliseconds since kernel start.
Definition at line 618 of file stk_c.cpp.
References stk::GetTimeNowMs().
| void * stk_tls_get | ( | void | ) |
Get thread-local pointer (platform-specific slot).
| void stk_tls_set | ( | void * | ptr | ) |
Set thread-local pointer.
| [in] | ptr | Pointer value to store for the current task/thread. |
| void stk_yield | ( | void | ) |
Voluntarily give up CPU to another ready task (cooperative yield).
Definition at line 631 of file stk_c.cpp.
References stk::Yield().