SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
STK C API

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_tstk_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_tstk_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_tstk_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_tstk_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_tstk_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_tstk_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_tstk_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_tstk_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_tstk_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_tstk_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_tstk_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_tstk_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.

Detailed Description

Pure C interface for C++ API of SuperTinyKernel RTOS.

Macro Definition Documentation

◆ __stk_c_aligned

#define __stk_c_aligned

Memory buffer alignment attribute.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 211 of file stk_c.h.

◆ __stk_c_stack

#define __stk_c_stack

Stack attribute (applies required alignment for a stack memory).

Definition at line 202 of file stk_c.h.

◆ STK_ALIGN_MASK

#define STK_ALIGN_MASK   (STK_ALIGN_SIZE - 1U)

Alignment mask.

Definition at line 159 of file stk_c.h.

◆ STK_ALIGN_SIZE

#define STK_ALIGN_SIZE   sizeof(stk_word_t)

Memory buffer alignment.

Definition at line 155 of file stk_c.h.

◆ STK_C_ASSERT

#define STK_C_ASSERT ( e)
Value:
assert(e)

Assertion macro used inside STK C bindings.

Definition at line 75 of file stk_c.h.

◆ STK_C_CPU_COUNT

#define STK_C_CPU_COUNT   (1)

Number of kernel instances / CPU cores supported (default: 1).

Note
Each core usually gets its own independent kernel instance.

Definition at line 60 of file stk_c.h.

Referenced by SetEventOverrider(), stk_kernel_create(), stk_timerhost_get(), and UnregisterKernel().

◆ STK_C_KERNEL_MAX_TASKS

#define STK_C_KERNEL_MAX_TASKS   (4)

Maximum number of tasks per kernel instance (default: 4).

Note
Increase this value if you need more tasks. Has direct impact on RAM and FLASH usage.

Definition at line 52 of file stk_c.h.

◆ STK_CV_IMPL_SIZE

#define STK_CV_IMPL_SIZE   (7U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))

A memory size (multiples of stk_word_t) required for ConditionVariable instance.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 935 of file stk_c.h.

◆ STK_DEFINE_STACK_POOL

#define STK_DEFINE_STACK_POOL ( name,
max_tasks,
stack_size )
Value:
static stk_word_t name[max_tasks][stack_size] __stk_c_stack
#define __stk_c_stack
Stack attribute (applies required alignment for a stack memory).
Definition stk_c.h:202
uintptr_t stk_word_t
CPU register type.
Definition stk_c.h:94

Allocates a statically bound, multi-dimensional stack pool for tasks.

Parameters
[in]nameIdentifier name of the generated array.
[in]max_tasksMaximum number of tasks (rows in the array).
[in]stack_sizeSize of each individual stack in words (columns).
See also
STK_GET_STACK_FROM_POOL

Definition at line 181 of file stk_c.h.

181#define STK_DEFINE_STACK_POOL(name, max_tasks, stack_size) \
182 static stk_word_t name[max_tasks][stack_size] __stk_c_stack

◆ STK_EF_ERROR_ISR

#define STK_EF_ERROR_ISR   (0x80000004U)

Wait called from an ISR with a blocking timeout

Definition at line 1117 of file stk_c.h.

◆ STK_EF_ERROR_MASK

#define STK_EF_ERROR_MASK   (0x80000000U)

Mask for testing any error; bit 31 set means error

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1118 of file stk_c.h.

Referenced by stk_ef_is_error().

◆ STK_EF_ERROR_PARAMETER

#define STK_EF_ERROR_PARAMETER   (0x80000001U)

Return-value error sentinels (bit 31 set indicates an error).

flags argument is 0 or has bit 31 set

Definition at line 1115 of file stk_c.h.

◆ STK_EF_ERROR_TIMEOUT

#define STK_EF_ERROR_TIMEOUT   (0x80000002U)

Timeout expired before the flag condition was met

Definition at line 1116 of file stk_c.h.

◆ STK_EF_IMPL_SIZE

#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.

Note
EventFlags contains one ConditionVariable (STK_CV_IMPL_SIZE words) plus one 32-bit flags word and alignment padding.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1132 of file stk_c.h.

◆ STK_EF_OPT_NO_CLEAR

#define STK_EF_OPT_NO_CLEAR   (0x00000002U)

Do not clear matched bits on a successful return

Definition at line 1111 of file stk_c.h.

◆ STK_EF_OPT_WAIT_ALL

#define STK_EF_OPT_WAIT_ALL   (0x00000001U)

Unblock when ALL requested bits are simultaneously set (AND semantics)

Definition at line 1110 of file stk_c.h.

◆ STK_EF_OPT_WAIT_ANY

#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)

Definition at line 1109 of file stk_c.h.

◆ STK_EVENT_IMPL_SIZE

#define STK_EVENT_IMPL_SIZE   (8U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))

A memory size (multiples of stk_word_t) required for Event instance.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 983 of file stk_c.h.

◆ STK_GET_STACK_FROM_POOL

#define STK_GET_STACK_FROM_POOL ( name,
task_id )
Value:
(name[task_id])

Retrieves the base stack pointer for a specific task ID from a stack pool.

Parameters
[in]nameIdentifier name of the allocated stack pool.
[in]task_idIndex of the task whose stack pointer is requested.
See also
STK_DEFINE_STACK_POOL

Definition at line 190 of file stk_c.h.

◆ STK_MSGQ_BUF_SIZE

#define STK_MSGQ_BUF_SIZE ( capacity,
msg_size )
Value:
((capacity) * (msg_size))

Compute the required data-buffer size (in bytes) for a MessageQueue.

Parameters
[in]capacityMaximum number of messages.
[in]msg_sizeSize of each message in bytes.
Note
Use this macro when declaring the uint8_t buffer passed to stk_msgq_create():
#define MY_QUEUE_CAP 8
#define MY_MSG_SIZE sizeof(MyMsg_t)
static uint8_t s_msgq_buf[STK_MSGQ_BUF_SIZE(MY_QUEUE_CAP, MY_MSG_SIZE)];
static stk_msgq_mem_t s_msgq_mem;
stk_msgq_t *g_queue = stk_msgq_create(&s_msgq_mem, sizeof(s_msgq_mem),
s_msgq_buf, sizeof(s_msgq_buf),
MY_QUEUE_CAP, MY_MSG_SIZE);
#define STK_MSGQ_BUF_SIZE(capacity, msg_size)
Compute the required data-buffer size (in bytes) for a MessageQueue.
Definition stk_c.h:1513
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).
struct stk_msgq_t stk_msgq_t
Opaque handle to a MessageQueue instance.
Definition stk_c.h:1494
Opaque memory container for a MessageQueue instance.
Definition stk_c.h:1488

Definition at line 1513 of file stk_c.h.

◆ STK_MSGQ_IMPL_SIZE

#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.

Note
The backing data buffer is allocated separately by the caller and passed to stk_msgq_create() via the buf / buf_size parameters.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1484 of file stk_c.h.

◆ STK_MUTEX_IMPL_SIZE

#define STK_MUTEX_IMPL_SIZE   (10U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))

A memory size (multiples of stk_word_t) required for Mutex instance.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 843 of file stk_c.h.

◆ STK_NO_WAIT

#define STK_NO_WAIT   (STK_STATIC_CAST(stk_timeout_t, 0))

No timeout constant.

Definition at line 151 of file stk_c.h.

◆ STK_PERIODICITY_DEFAULT

#define STK_PERIODICITY_DEFAULT   (1000U)

Default tick period (1 ms).

in microseconds

Definition at line 134 of file stk_c.h.

◆ STK_PIPE_BUF_SIZE

#define STK_PIPE_BUF_SIZE ( capacity,
element_size )
Value:
((((capacity) * (element_size)) + STK_ALIGN_MASK) & ~STK_ALIGN_MASK)
#define STK_ALIGN_MASK
Alignment mask.
Definition stk_c.h:159

Compute the required data-buffer size (in bytes) for a Pipe.

Parameters
[in]capacityMaximum number of elements the pipe can hold.
[in]element_sizeSize of a single element in bytes.
Note
Use this macro when declaring the uint8_t buffer passed to stk_pipe_create():
#define MY_PIPE_CAP 16
#define MY_ELEM_SIZE sizeof(MyMsg_t)
static uint8_t s_pipe_buf[STK_PIPE_BUF_SIZE(MY_PIPE_CAP, MY_ELEM_SIZE)] __stk_c_aligned;
static stk_pipe_mem_t s_pipe_mem;
stk_pipe_t *g_pipe = stk_pipe_create(&s_pipe_mem, sizeof(s_pipe_mem),
s_pipe_buf, sizeof(s_pipe_buf),
MY_PIPE_CAP, MY_ELEM_SIZE);
#define STK_PIPE_BUF_SIZE(capacity, element_size)
Compute the required data-buffer size (in bytes) for a Pipe.
Definition stk_c.h:1257
#define __stk_c_aligned
Memory buffer alignment attribute.
Definition stk_c.h:211
struct stk_pipe_t stk_pipe_t
Opaque handle to a Pipe instance.
Definition stk_c.h:1238
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).
Opaque memory container for a Pipe control-block.
Definition stk_c.h:1232

Definition at line 1257 of file stk_c.h.

1257#define STK_PIPE_BUF_SIZE(capacity, element_size) \
1258 ((((capacity) * (element_size)) + STK_ALIGN_MASK) & ~STK_ALIGN_MASK)

◆ STK_PIPE_IMPL_SIZE

#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.

Note
The backing data buffer is allocated separately by the caller and passed to stk_pipe_create() via the buf / buf_size parameters.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1228 of file stk_c.h.

◆ STK_RWMUTEX_IMPL_SIZE

#define STK_RWMUTEX_IMPL_SIZE   (17U + (STK_SYNC_DEBUG_NAMES ? 3U : 0U))

A memory size (multiples of stk_word_t) required for RWMutex instance.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1732 of file stk_c.h.

◆ STK_SEM_IMPL_SIZE

#define STK_SEM_IMPL_SIZE   (8U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))

A memory size (multiples of stk_word_t) required for Semaphore instance.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1046 of file stk_c.h.

◆ STK_SPINLOCK_IMPL_SIZE

#define STK_SPINLOCK_IMPL_SIZE   (1)

A memory size (multiples of stk_word_t) required for SpinLock instance.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 894 of file stk_c.h.

◆ STK_STACK_MEMORY_ALIGN

#define STK_STACK_MEMORY_ALIGN   (4U)

Stack memory alignment.

Definition at line 170 of file stk_c.h.

◆ STK_STATIC_CAST

#define STK_STATIC_CAST ( type,
val )
Value:
static_cast<type>(val)

Convenience wrapper for static_cast and C-style cast.

Parameters
[in]typeValue type.
[in]valValue.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 83 of file stk_c.h.

Referenced by stk_ms_from_ticks_r(), and stk_ticks_from_ms_r().

◆ STK_SYNC_DEBUG_NAMES

#define STK_SYNC_DEBUG_NAMES   (0)

Enable names for synchronization primitives for debugging/tracing purpose.

Definition at line 69 of file stk_c.h.

◆ STK_TLS_GET_T

#define STK_TLS_GET_T ( type)
Value:
((type *)stk_tls_get())
void * stk_tls_get(void)
Get thread-local pointer (platform-specific slot).

Typed helper for getting TLS value.

Note
Expands to ((type *)stk_tls_get())

Definition at line 816 of file stk_c.h.

◆ STK_TLS_SET_T

#define STK_TLS_SET_T ( ptr)
Value:
stk_tls_set((void *)(ptr))
void stk_tls_set(void *ptr)
Set thread-local pointer.

Typed helper for setting TLS value.

Note
Expands to stk_tls_set((void *)(ptr))

Definition at line 821 of file stk_c.h.

◆ STK_WAIT_INFINITE

#define STK_WAIT_INFINITE   (STK_STATIC_CAST(stk_timeout_t, INT32_MAX))

Infinite timeout constant.

Definition at line 147 of file stk_c.h.

Typedef Documentation

◆ stk_cv_mem_t

typedef struct stk_cv_mem_t stk_cv_mem_t

Opaque memory container for a ConditionVariable instance.

◆ stk_cv_t

typedef struct stk_cv_t stk_cv_t

Opaque handle to a Condition Variable instance.

Definition at line 945 of file stk_c.h.

◆ stk_cycle_t

typedef uint64_t stk_cycle_t

CPU cycles value.

See also
stk_sys_timer_count, stk_hires_cycles
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 118 of file stk_c.h.

◆ stk_ef_mem_t

typedef struct stk_ef_mem_t stk_ef_mem_t

Opaque memory container for an EventFlags instance.

◆ stk_ef_t

typedef struct stk_ef_t stk_ef_t

Opaque handle to an EventFlags instance.

Definition at line 1142 of file stk_c.h.

◆ stk_event_mem_t

typedef struct stk_event_mem_t stk_event_mem_t

Opaque memory container for an Event instance.

◆ stk_event_overrider_t

typedef struct stk_event_overrider_t stk_event_overrider_t

◆ stk_event_t

typedef struct stk_event_t stk_event_t

Opaque handle to an Event instance.

Definition at line 993 of file stk_c.h.

◆ stk_kernel_state_t

Kernel state.

Note
It is a direct match for IKernel::EState enum.
See also
stk_kernel_get_state()

◆ stk_kernel_t

typedef struct stk_kernel_t stk_kernel_t

Opaque handle to a kernel instance.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 126 of file stk_c.h.

◆ stk_msgq_mem_t

typedef struct stk_msgq_mem_t stk_msgq_mem_t

Opaque memory container for a MessageQueue instance.

◆ stk_msgq_t

typedef struct stk_msgq_t stk_msgq_t

Opaque handle to a MessageQueue instance.

Definition at line 1494 of file stk_c.h.

◆ stk_mutex_mem_t

typedef struct stk_mutex_mem_t stk_mutex_mem_t

Opaque memory container for a Mutex instance.

◆ stk_mutex_t

typedef struct stk_mutex_t stk_mutex_t

Opaque handle to a Mutex instance.

Definition at line 853 of file stk_c.h.

◆ stk_pipe_mem_t

typedef struct stk_pipe_mem_t stk_pipe_mem_t

Opaque memory container for a Pipe control-block.

◆ stk_pipe_t

typedef struct stk_pipe_t stk_pipe_t

Opaque handle to a Pipe instance.

Definition at line 1238 of file stk_c.h.

◆ stk_rwmutex_mem_t

typedef struct stk_rwmutex_mem_t stk_rwmutex_mem_t

Opaque memory container for an RWMutex instance.

◆ stk_rwmutex_t

typedef struct stk_rwmutex_t stk_rwmutex_t

Opaque handle to an RWMutex instance.

Definition at line 1742 of file stk_c.h.

◆ stk_sem_mem_t

typedef struct stk_sem_mem_t stk_sem_mem_t

Opaque memory container for a Semaphore instance.

◆ stk_sem_t

typedef struct stk_sem_t stk_sem_t

Opaque handle to a Semaphore instance.

Definition at line 1056 of file stk_c.h.

◆ stk_spinlock_t

typedef struct stk_spinlock_t stk_spinlock_t

Opaque handle to a SpinLock instance.

Definition at line 905 of file stk_c.h.

◆ stk_task_entry_t

typedef void(* stk_task_entry_t) (void *arg)

Task entry point function type.

Parameters
[in]argUser-supplied argument (may be NULL)
Note
If KERNEL_STATIC, the function must never return. If KERNEL_DYNAMIC, it may return and then task will be considered as finished.
KERNEL_TICKLESS is compatible with both KERNEL_STATIC and KERNEL_DYNAMIC, but is incompatible with KERNEL_HRT (see kernel type definitions below).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 143 of file stk_c.h.

◆ stk_task_t

typedef struct stk_task_t stk_task_t

Opaque handle to a task instance.

Definition at line 130 of file stk_c.h.

◆ stk_tick_t

typedef int64_t stk_tick_t

Ticks value.

See also
stk_ticks
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 103 of file stk_c.h.

◆ stk_tid_t

Task id.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 98 of file stk_c.h.

◆ stk_time_t

typedef int64_t stk_time_t

Time value.

See also
stk_time_now_ms
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 108 of file stk_c.h.

◆ stk_timeout_t

typedef int32_t stk_timeout_t

Timeout value.

See also
stk_sleep, stk_delay
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 113 of file stk_c.h.

◆ stk_weight_t

typedef int32_t stk_weight_t

Task weight value.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 122 of file stk_c.h.

◆ stk_word_t

typedef uintptr_t stk_word_t

CPU register type.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 94 of file stk_c.h.

Enumeration Type Documentation

◆ stk_kernel_state_t

Kernel state.

Note
It is a direct match for IKernel::EState enum.
See also
stk_kernel_get_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)

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 364 of file stk_c.h.

364 {
stk_kernel_state_t
Kernel state.
Definition stk_c.h:364
@ STK_KERNEL_STATE_INACTIVE
not ready, stk_kernel_init() must be called
Definition stk_c.h:365
@ STK_KERNEL_STATE_READY
ready to start, stk_kernel_start() must be called
Definition stk_c.h:366
@ STK_KERNEL_STATE_RUNNING
initialized and running, stk_kernel_start() was called successfully
Definition stk_c.h:367
@ STK_KERNEL_STATE_SUSPENDED
scheduling suspended via stk_kernel_service_suspend() (tickless idle)
Definition stk_c.h:368

Function Documentation

◆ stk_critical_section_enter()

void stk_critical_section_enter ( void )

Enter critical section - disable context switches on current core.

Note
Supports nesting (number of enter calls must match number of exit calls).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 651 of file stk_c.cpp.

652{
654}
static void Enter()
Enter a critical section.

References stk::hw::CriticalSection::Enter().

Here is the call graph for this function:

◆ stk_critical_section_exit()

void stk_critical_section_exit ( void )

Leave critical section - re-enable context switches.

Note
Must be called once for each previous stk_critical_section_enter().
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 656 of file stk_c.cpp.

657{
659}
static void Exit()
Exit a critical section.

References stk::hw::CriticalSection::Exit().

Here is the call graph for this function:

◆ stk_cv_create()

stk_cv_t * stk_cv_create ( stk_cv_mem_t *const membuf,
uint32_t membuf_size )

Create a Condition Variable (using provided memory).

Parameters
[in]membufPointer to static memory container.
[in]membuf_sizeSize of the container (must be >= sizeof(stk_cv_mem_t)).
Returns
CV handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 141 of file stk_c_sync.cpp.

142{
143 STK_ASSERT(membuf != nullptr);
144 STK_ASSERT(membuf_size >= sizeof(stk_cv_t));
145
146 stk_cv_t *result = nullptr;
147 if (membuf_size >= sizeof(stk_cv_t))
148 {
149 result = new (membuf->data) stk_cv_t();
150 }
151
152 return result;
153}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:409
struct stk_cv_t stk_cv_t
Opaque handle to a Condition Variable instance.
Definition stk_c.h:945
stk_word_t data[(7U+((0) ? 1U :0U))]
Definition stk_c.h:940

References stk_cv_mem_t::data, and STK_ASSERT.

◆ stk_cv_destroy()

void stk_cv_destroy ( stk_cv_t * cv)

Destroy a Condition Variable.

Parameters
[in]cvCV handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 155 of file stk_c_sync.cpp.

156{
157 if (cv != nullptr)
158 {
159 cv->~stk_cv_t();
160 }
161}

◆ stk_cv_notify_all()

void stk_cv_notify_all ( stk_cv_t * cv)

Wake all tasks waiting on the condition variable.

Parameters
[in]cvCV handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 178 of file stk_c_sync.cpp.

179{
180 STK_ASSERT(cv != nullptr);
181
182 cv->handle.NotifyAll();
183}
void NotifyAll()
Wake all waiting tasks.
ConditionVariable handle

References stk_cv_t::handle, stk::sync::ConditionVariable::NotifyAll(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_cv_notify_one()

void stk_cv_notify_one ( stk_cv_t * cv)

Wake one task waiting on the condition variable.

Parameters
[in]cvCV handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 171 of file stk_c_sync.cpp.

172{
173 STK_ASSERT(cv != nullptr);
174
175 cv->handle.NotifyOne();
176}
void NotifyOne()
Wake one waiting task.

References stk_cv_t::handle, stk::sync::ConditionVariable::NotifyOne(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_cv_wait()

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.

Parameters
[in]cvCV handle.
[in]mtxLocked mutex handle protecting the state.
[in]timeoutMax time to wait (or STK_WAIT_INFINITE).
Returns
True if signaled, False on timeout.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 163 of file stk_c_sync.cpp.

164{
165 STK_ASSERT(cv != nullptr);
166 STK_ASSERT(mtx != nullptr);
167
168 return cv->handle.Wait(mtx->handle, timeout);
169}
bool Wait(IMutex &mutex, Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal.

References stk_cv_t::handle, stk_mutex_t::handle, STK_ASSERT, and stk::sync::ConditionVariable::Wait().

Here is the call graph for this function:

◆ stk_delay()

void stk_delay ( stk_timeout_t ticks)

Busy-wait delay (other tasks continue to run).

Parameters
[in]ticksTicks to delay.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 625 of file stk_c.cpp.

625{ stk::Delay(ticks); }
static void Delay(Timeout tick_count)
Delay calling process by busy-waiting until the deadline expires.
Definition stk_helper.h:419

References stk::Delay().

Here is the call graph for this function:

◆ stk_delay_ms()

void stk_delay_ms ( stk_timeout_t ms)

Busy-wait delay (other tasks continue to run).

Parameters
[in]msMilliseconds to delay.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 627 of file stk_c.cpp.

627{ stk::DelayMs(ms); }
static void DelayMs(Timeout ms)
Delay calling process by busy-waiting until the deadline expires.
Definition stk_helper.h:430

References stk::DelayMs().

Here is the call graph for this function:

◆ stk_ef_clear()

uint32_t stk_ef_clear ( stk_ef_t * ef,
uint32_t flags )

Clear one or more flags.

Atomically clears the specified bits.

Parameters
[in]efEventFlags handle.
[in]flagsBitmask of bits to clear. Must not be 0 and must not have bit 31 set.
Returns
Flags word value before clearing, or STK_EF_ERROR_PARAMETER on invalid input.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 365 of file stk_c_sync.cpp.

366{
367 STK_ASSERT(ef != nullptr);
368
369 return ef->handle.Clear(flags);
370}
uint32_t Clear(uint32_t flags)
Clear one or more flags.
EventFlags handle

References stk::sync::EventFlags::Clear(), stk_ef_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_ef_create()

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).

Parameters
[in]membufPointer to static memory container.
[in]membuf_sizeSize of the container (must be >= sizeof(stk_ef_mem_t)).
[in]initial_flagsInitial value of the 32-bit flags word (bits 0..30 only; bit 31 is reserved and must not be set).
Returns
EventFlags handle, or NULL if memory is too small.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 334 of file stk_c_sync.cpp.

337{
338 STK_ASSERT(membuf != nullptr);
339 STK_ASSERT(membuf_size >= sizeof(stk_ef_t));
340
341 stk_ef_t *result = nullptr;
342 if (membuf_size >= sizeof(stk_ef_t))
343 {
344 result = new (membuf->data) stk_ef_t(initial_flags);
345 }
346
347 return result;
348}
struct stk_ef_t stk_ef_t
Opaque handle to an EventFlags instance.
Definition stk_c.h:1142
stk_word_t data[((7U+((0) ? 1U :0U))+1U+((0) ? 1U :0U))]
Definition stk_c.h:1137

References stk_ef_mem_t::data, and STK_ASSERT.

◆ stk_ef_destroy()

void stk_ef_destroy ( stk_ef_t * ef)

Destroy an EventFlags object.

Parameters
[in]efEventFlags handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 350 of file stk_c_sync.cpp.

351{
352 if (ef != nullptr)
353 {
354 ef->~stk_ef_t();
355 }
356}

◆ stk_ef_get()

uint32_t stk_ef_get ( stk_ef_t * ef)

Read the current flags word without modifying it.

Parameters
[in]efEventFlags handle.
Returns
Point-in-time snapshot of the 32-bit flags word.
Note
ISR-safe. Never blocks or modifies state.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 372 of file stk_c_sync.cpp.

373{
374 STK_ASSERT(ef != nullptr);
375
376 return ef->handle.Get();
377}
uint32_t Get() const
Read the current flags word without modifying it.

References stk::sync::EventFlags::Get(), stk_ef_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_ef_is_error()

bool stk_ef_is_error ( uint32_t result)
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

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1123 of file stk_c.h.

1124{
1125 return ((result & STK_EF_ERROR_MASK) != 0U);
1126}
#define STK_EF_ERROR_MASK
Definition stk_c.h:1118

References STK_EF_ERROR_MASK.

◆ stk_ef_set()

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.

Parameters
[in]efEventFlags handle.
[in]flagsBitmask of bits to set. Must not be 0 and must not have bit 31 set.
Returns
Flags word value after setting, or STK_EF_ERROR_PARAMETER on invalid input.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 358 of file stk_c_sync.cpp.

359{
360 STK_ASSERT(ef != nullptr);
361
362 return ef->handle.Set(flags);
363}
uint32_t Set(uint32_t flags)
Set one or more flags.

References stk_ef_t::handle, stk::sync::EventFlags::Set(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_ef_trywait()

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.

Parameters
[in]efEventFlags handle.
[in]flagsBitmask of flag bits to watch.
[in]optionsSTK_EF_OPT_WAIT_ANY (default) or STK_EF_OPT_WAIT_ALL, optionally OR-ed with STK_EF_OPT_NO_CLEAR.
Returns
Matched flags bitmask on success, or STK_EF_ERROR_TIMEOUT immediately if the condition is not met.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 386 of file stk_c_sync.cpp.

387{
388 STK_ASSERT(ef != nullptr);
389
390 return ef->handle.TryWait(flags, options);
391}
uint32_t TryWait(uint32_t flags, uint32_t options=OPT_WAIT_ANY)
Non-blocking flag poll.

References stk_ef_t::handle, STK_ASSERT, and stk::sync::EventFlags::TryWait().

Here is the call graph for this function:

◆ stk_ef_wait()

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.

Parameters
[in]efEventFlags handle.
[in]flagsBitmask of flag bits to watch. Must not be 0 and must not have bit 31 set.
[in]optionsCombination of STK_EF_OPT_WAIT_ANY / STK_EF_OPT_WAIT_ALL and optionally STK_EF_OPT_NO_CLEAR.
[in]timeoutMaximum time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking poll.
Returns
Bitmask of the matched flags on success, or a STK_EF_ERROR_* sentinel on failure. Always check stk_ef_is_error() before using the return value as a flags mask.
Note
If the predicate becomes satisfied in the same tick that the deadline expires, the wait succeeds and returns the matched flags.
Warning
ISR-safe only with timeout = STK_NO_WAIT, ISR-unsafe otherwise.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 379 of file stk_c_sync.cpp.

380{
381 STK_ASSERT(ef != nullptr);
382
383 return ef->handle.Wait(flags, options, timeout);
384}
uint32_t Wait(uint32_t flags, uint32_t options=OPT_WAIT_ANY, Timeout timeout_ticks=WAIT_INFINITE)
Wait for one or more flags to be set.

References stk_ef_t::handle, STK_ASSERT, and stk::sync::EventFlags::Wait().

Here is the call graph for this function:

◆ stk_event_create()

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).

Parameters
[in]membufPointer to static memory container.
[in]membuf_sizeSize of the container (must be >= sizeof(stk_event_mem_t)).
[in]manual_resetTrue for manual-reset, False for auto-reset.
Returns
Event handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 196 of file stk_c_sync.cpp.

199{
200 STK_ASSERT(membuf != nullptr);
201 STK_ASSERT(membuf_size >= sizeof(stk_event_t));
202
203 stk_event_t *result = nullptr;
204 if (membuf_size >= sizeof(stk_event_t))
205 {
206 result = new (membuf->data) stk_event_t(manual_reset);
207 }
208
209 return result;
210}
struct stk_event_t stk_event_t
Opaque handle to an Event instance.
Definition stk_c.h:993
stk_word_t data[(8U+((0) ? 1U :0U))]
Definition stk_c.h:988

References stk_event_mem_t::data, and STK_ASSERT.

◆ stk_event_destroy()

void stk_event_destroy ( stk_event_t * ev)

Destroy an Event.

Parameters
[in]evEvent handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 212 of file stk_c_sync.cpp.

213{
214 if (ev != nullptr)
215 {
216 ev->~stk_event_t();
217 }
218}

◆ stk_event_pulse()

void stk_event_pulse ( stk_event_t * ev)

Pulse the event (signal then immediately reset).

Parameters
[in]evEvent handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 248 of file stk_c_sync.cpp.

249{
250 STK_ASSERT(ev != nullptr);
251
252 ev->handle.Pulse();
253}
void Pulse()
Pulse event: attempt to release waiters and then reset (Win32 PulseEvent() semantics).

References stk_event_t::handle, stk::sync::Event::Pulse(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_event_reset()

bool stk_event_reset ( stk_event_t * ev)

Reset the event to non-signaled state.

Parameters
[in]evEvent handle.
Returns
true if state was changed from signaled to non-signaled, false if event was already non-signaled.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 241 of file stk_c_sync.cpp.

242{
243 STK_ASSERT(ev != nullptr);
244
245 return ev->handle.Reset();
246}
bool Reset()
Reset event to non-signaled state.

References stk_event_t::handle, stk::sync::Event::Reset(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_event_set()

bool stk_event_set ( stk_event_t * ev)

Set the event to signaled state.

Parameters
[in]evEvent handle.
Returns
true if state was changed from non-signaled to signaled, false if event was already signaled.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 234 of file stk_c_sync.cpp.

235{
236 STK_ASSERT(ev != nullptr);
237
238 return ev->handle.Set();
239}
bool Set()
Set event to signaled state.

References stk_event_t::handle, stk::sync::Event::Set(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_event_trywait()

bool stk_event_trywait ( stk_event_t * ev)

Wait for the event to become signaled.

Parameters
[in]evEvent handle.
Returns
True if signaled, False on timeout.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 227 of file stk_c_sync.cpp.

228{
229 STK_ASSERT(ev != nullptr);
230
231 return ev->handle.TryWait();
232}
bool TryWait()
Poll event state without blocking.

References stk_event_t::handle, STK_ASSERT, and stk::sync::Event::TryWait().

Here is the call graph for this function:

◆ stk_event_wait()

bool stk_event_wait ( stk_event_t * ev,
stk_timeout_t timeout )

Wait for the event to become signaled.

Parameters
[in]evEvent handle.
[in]timeoutMax time to wait in milliseconds.
Returns
True if signaled, False on timeout.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 220 of file stk_c_sync.cpp.

221{
222 STK_ASSERT(ev != nullptr);
223
224 return ev->handle.Wait(timeout);
225}
bool Wait(Timeout timeout_ticks=WAIT_INFINITE)
Wait until event becomes signaled or the timeout expires.

References stk_event_t::handle, STK_ASSERT, and stk::sync::Event::Wait().

Here is the call graph for this function:

◆ stk_hires_cycles()

stk_cycle_t stk_hires_cycles ( void )

Get raw CPU cycle counter.

Returns
64-bit cycle count. Resolution is one clock cycle.
Note
ISR-safe. Use stk_hires_frequency() to convert to real time.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 622 of file stk_c.cpp.

static Cycles GetCycles()
Get number of clock cycles elapsed.

References stk::hw::HiResClock::GetCycles().

Here is the call graph for this function:

◆ stk_hires_frequency()

uint32_t stk_hires_frequency ( void )

Get CPU clock frequency in Hz.

Returns
Clock frequency in Hz.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 623 of file stk_c.cpp.

static uint32_t GetFrequency()
Get clock frequency.

References stk::hw::HiResClock::GetFrequency().

Here is the call graph for this function:

◆ stk_hires_time_us()

stk_tick_t stk_hires_time_us ( void )

Get elapsed time in microseconds from the high-resolution clock.

Returns
Microseconds since an arbitrary but fixed epoch (typically reset).
Note
ISR-safe. Equivalent to stk_hires_cycles() * 1000000 / stk_hires_frequency().
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 624 of file stk_c.cpp.

static __stk_forceinline Ticks GetTimeUs()
Get elapsed time in microseconds.
Definition stk_arch.h:497

References stk::hw::HiResClock::GetTimeUs().

Here is the call graph for this function:

◆ stk_kernel_add_task()

void stk_kernel_add_task ( stk_kernel_t * k,
stk_task_t * tsk )

Add task to non-HRT kernel (static or dynamic).

Parameters
[in]kKernel handle.
[in]tskTask handle created with one of stk_task_create_* functions.
Note
For static kernels this must be done before stk_kernel_start().
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 417 of file stk_c.cpp.

418{
419 STK_ASSERT(k != nullptr);
420 STK_ASSERT(tsk != nullptr);
421
423}
static IKernel * CastCToKernelInterface(stk_kernel_t *const k)
Definition stk_c.cpp:43
virtual void AddTask(ITask *user_task)=0
Add user task.
TaskWrapper handle
Definition stk_c.cpp:128

References stk::IKernel::AddTask(), CastCToKernelInterface(), stk_task_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_add_task_hrt()

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).

Parameters
[in]kKernel handle.
[in]tskTask handle.
[in]periodicity_ticksPeriod in ticks.
[in]deadline_ticksRelative deadline in ticks.
[in]start_delay_ticksInitial offset / phase in ticks (>= 0).
Note
Must be called after stk_kernel_init() and before stk_kernel_start().
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 525 of file stk_c.cpp.

530{
531 STK_ASSERT(k != nullptr);
532 STK_ASSERT(tsk != nullptr);
533
535 &tsk->handle,
536 periodicity_ticks,
537 deadline_ticks,
538 start_delay_ticks);
539}

References stk::IKernel::AddTask(), CastCToKernelInterface(), stk_task_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_create()

stk_kernel_t * stk_kernel_create ( uint8_t core_nr)

Create kernel.

Note
At least STK_C_KERNEL_TYPE_CPU_0 must be defined with the type of the kernel. Place STK_C_KERNEL_TYPE_CPU_X defines inside the stk_config.h file which is per project. STK_C_KERNEL_TYPE_CPU_X type will be assigned to X core.
Parameters
[in]core_nrCPU core number (starts with 0). Max: 7 (for 8 cores).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 333 of file stk_c.cpp.

334{
335 STK_STATIC_ASSERT((STK_C_CPU_COUNT <= 8U)); // switch (core_nr) below handles cases 0..7; STK_C_KERNEL_TYPE_CPU_N is only defined up to N=7
336 STK_ASSERT(core_nr < STK_C_CPU_COUNT);
337
338 IKernel *k;
339
340 switch (core_nr)
341 {
342#ifdef STK_C_KERNEL_TYPE_CPU_0
344#endif
345#ifdef STK_C_KERNEL_TYPE_CPU_1
347#endif
348#ifdef STK_C_KERNEL_TYPE_CPU_2
350#endif
351#ifdef STK_C_KERNEL_TYPE_CPU_3
353#endif
354#ifdef STK_C_KERNEL_TYPE_CPU_4
356#endif
357#ifdef STK_C_KERNEL_TYPE_CPU_5
359#endif
360#ifdef STK_C_KERNEL_TYPE_CPU_6
362#endif
363#ifdef STK_C_KERNEL_TYPE_CPU_7
365#endif
366 default: {
367 k = nullptr;
368 break; }
369 }
370
372}
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
Definition stk_defs.h:446
static stk_kernel_t * CastCppKernelInterfaceToC(IKernel *const k)
Definition stk_c.cpp:55
#define STK_KERNEL_CASE(X)
Definition stk_c.cpp:320
#define STK_C_CPU_COUNT
Number of kernel instances / CPU cores supported (default: 1).
Definition stk_c.h:60
Interface for the implementation of the kernel of the scheduler. It supports Soft and Hard Real-Time ...

References CastCppKernelInterfaceToC(), STK_ASSERT, STK_C_CPU_COUNT, STK_KERNEL_CASE, and STK_STATIC_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_destroy()

void stk_kernel_destroy ( stk_kernel_t * k)

Destroy dynamic kernel instance (only when not running).

Parameters
[in]kKernel handle.
Note
Kernel must not be running (all tasks must have exited or been removed). Only valid for kernels created with dynamic factory functions.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 374 of file stk_c.cpp.

375{
376 STK_ASSERT(k != nullptr);
377
378 // Detach the event overrider and clear the registry entry BEFORE calling
379 // the destructor: the platform teardown inside ~IKernel() may still invoke
380 // GetPlatform() paths, and we must not leave a dangling overrider pointer
381 // registered at that point.
383}
static void UnregisterKernel(const IKernel *k)
Definition stk_c.cpp:227

References CastCToKernelInterface(), STK_ASSERT, and UnregisterKernel().

Here is the call graph for this function:

◆ stk_kernel_enumerate_tasks()

size_t stk_kernel_enumerate_tasks ( stk_kernel_t * k,
stk_task_t ** tasks,
size_t max_count )

Enumerate all currently active tasks.

Parameters
[in]kKernel handle.
[out]tasksCaller-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_countCapacity of the tasks array (number of elements).
Returns
Number of active tasks written into tasks (0 .. max_count).
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 466 of file stk_c.cpp.

467{
468 STK_ASSERT(k != nullptr);
469 STK_ASSERT(tasks != nullptr);
470
471 stk::ITask *itasks[STK_C_TASKS_MAX] = {};
472
473 // Determine the safe upper bound for the temporary buffer
474 const size_t requested_size = (max_count < static_cast<size_t>(STK_C_TASKS_MAX)) ? max_count :
475 static_cast<size_t>(STK_C_TASKS_MAX);
476
477 // Pass via ArrayView temporary object
478 const size_t ret_count = CastCToKernelInterface(k)->EnumerateTasks(
479 ArrayView<stk::ITask *>(itasks, requested_size));
480
481 ArrayView<stk_task_t *> output_view(tasks, max_count);
482 for (size_t i = 0U; i < ret_count; ++i)
483 {
484 output_view[i] = CastCppTaskInterfaceToC(itasks[i]);
485 }
486
487 return ret_count;
488}
static stk_task_t * CastCppTaskInterfaceToC(ITask *const t)
Definition stk_c.cpp:142
#define STK_C_TASKS_MAX
Definition stk_c.cpp:37
Lightweight, non-owning view over a contiguous sequence of elements.
Definition stk_common.h:226
Interface for a user task.
Definition stk_common.h:599
virtual size_t EnumerateTasks(ArrayView< ITask * > user_tasks)=0
Enumerate user tasks.

References CastCppTaskInterfaceToC(), CastCToKernelInterface(), stk::IKernel::EnumerateTasks(), STK_ASSERT, and STK_C_TASKS_MAX.

Here is the call graph for this function:

◆ stk_kernel_get_state()

stk_kernel_state_t stk_kernel_get_state ( const stk_kernel_t * k)

Get state of the scheduler.

Parameters
[in]kKernel handle.
Returns
State value, see stk_kernel_state_t.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 402 of file stk_c.cpp.

403{
404 STK_ASSERT(k != nullptr);
405
407}
static const IKernel * CastCToKernelInterfaceConst(const stk_kernel_t *const k)
Definition stk_c.cpp:49
virtual EKernelState GetState() const =0
Get a snapshot of the kernel state.

References CastCToKernelInterfaceConst(), stk::IKernel::GetState(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_init()

void stk_kernel_init ( stk_kernel_t * k,
uint32_t tick_period_us )

Initialize kernel with given tick period.

Parameters
[in]kKernel handle.
[in]tick_period_usSystem tick period in microseconds (usually 100–10000).
Note
Must be called exactly once before adding tasks or starting scheduler.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 388 of file stk_c.cpp.

389{
390 STK_ASSERT(k != nullptr);
391
392 CastCToKernelInterface(k)->Initialize(tick_period_us);
393}
virtual void Initialize(uint32_t resolution_us=PERIODICITY_DEFAULT)=0
Initialize kernel.

References CastCToKernelInterface(), stk::IKernel::Initialize(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_is_schedulable()

bool stk_kernel_is_schedulable ( const stk_kernel_t * k)

Test whether currently configured task set is schedulable.

Parameters
[in]kKernel handle.
Returns
True if task set passes schedulability test, False otherwise.
Note
Only meaningful for HRT RM/DM kernels.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 409 of file stk_c.cpp.

410{
411 STK_ASSERT(k != nullptr);
412
414 const_cast<IKernel *>(CastCToKernelInterfaceConst(k))->GetSwitchStrategy());
415}
static SchedulabilityCheckResult< TTaskCount > IsSchedulableWCRT(const ITaskSwitchStrategy *strategy)
Perform WCRT schedulability analysis on the task set registered with strategy.

References CastCToKernelInterfaceConst(), stk::SchedulabilityCheck::IsSchedulableWCRT(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_is_started()

bool stk_kernel_is_started ( const stk_kernel_t * k)

Check whether the scheduler is currently running (first task switch has occurred).

Parameters
[in]kKernel handle.
Returns
True if stk_kernel_start() has been called and the first context switch has occurred, False before stk_kernel_start() or after all tasks have exited.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 433 of file stk_c.cpp.

434{
435 STK_ASSERT(k != nullptr);
436
439}
EKernelState
Kernel state.
@ KSTATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.
@ KSTATE_SUSPENDED
Scheduling is suspended with IKernelService::Suspend().

References CastCToKernelInterfaceConst(), stk::IKernel::GetState(), stk::IKernel::KSTATE_RUNNING, stk::IKernel::KSTATE_SUSPENDED, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_process_hard_fault()

void stk_kernel_process_hard_fault ( stk_kernel_t * k)

Trigger a kernel hard fault (safe-state handler).

Parameters
[in]kKernel handle.
Note
Normally invoked automatically by the kernel when an HRT task misses its deadline. Exposed here for custom fault handlers or test harnesses that need to force a controlled system halt via the platform driver's fault path.
This call does not return.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 511 of file stk_c.cpp.

512{
513 STK_ASSERT(k != nullptr);
514
516}
virtual void ProcessHardFault()=0
Cause a hard fault of the system.
virtual IPlatform * GetPlatform()=0
Get platform driver instance.

References CastCToKernelInterface(), stk::IKernel::GetPlatform(), stk::IPlatform::ProcessHardFault(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_process_tick()

void stk_kernel_process_tick ( stk_kernel_t * k)

Manually deliver one scheduler tick to the kernel.

Parameters
[in]kKernel handle.
Note
Use this when the platform driver's built-in SysTick handler is disabled (STK_SYSTICK_HANDLER = _STK_SYSTICK_HANDLER_DISABLE in stk_config.h) and the application provides its own tick source. Call from your custom tick ISR at the rate matching the tick period configured in stk_kernel_init().
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 504 of file stk_c.cpp.

505{
506 STK_ASSERT(k != nullptr);
507
509}
virtual void ProcessTick()=0
Process one tick.

References CastCToKernelInterface(), stk::IKernel::GetPlatform(), stk::IPlatform::ProcessTick(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_remove_task()

void stk_kernel_remove_task ( stk_kernel_t * k,
stk_task_t * tsk )

Remove finished task from dynamic kernel.

Parameters
[in]kKernel handle.
[in]tskTask that has already returned from its entry function.
Note
Only valid in dynamic kernels. Task must have exited (returned from entry function).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 425 of file stk_c.cpp.

426{
427 STK_ASSERT(k != nullptr);
428 STK_ASSERT(tsk != nullptr);
429
431}
virtual void RemoveTask(ITask *user_task)=0
Remove a previously added task from the kernel before Start().

References CastCToKernelInterface(), stk_task_t::handle, stk::IKernel::RemoveTask(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_resume()

void stk_kernel_resume ( stk_kernel_t * k,
stk_timeout_t elapsed_ticks )

Resume scheduling after a prior stk_kernel_suspend() call.

Parameters
[in]kKernel handle.
[in]elapsed_ticksNumber 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.
Note
ISR-safe.
See also
stk_kernel_suspend
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 497 of file stk_c.cpp.

498{
499 STK_ASSERT(k != nullptr);
500
501 CastCToKernelInterface(k)->GetPlatform()->Resume(static_cast<stk::Timeout>(elapsed_ticks));
502}
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:125
virtual void Resume(Timeout elapsed_ticks)=0
Resume scheduling after a prior Suspend() call.

References CastCToKernelInterface(), stk::IKernel::GetPlatform(), stk::IPlatform::Resume(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_resume_task()

void stk_kernel_resume_task ( stk_kernel_t * k,
stk_task_t * task )

Resume a previously suspended task.

Parameters
[in]kKernel handle.
[in]taskTask to resume. Must have been suspended with stk_kernel_suspend_task().
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 458 of file stk_c.cpp.

459{
460 STK_ASSERT(k != nullptr);
461 STK_ASSERT(tsk != nullptr);
462
463 CastCToKernelInterface(k)->ResumeTask(&tsk->handle);
464}
virtual void ResumeTask(ITask *user_task)=0
Resume task.

References CastCToKernelInterface(), stk_task_t::handle, stk::IKernel::ResumeTask(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_schedule_task_removal()

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.

Parameters
[in]kKernel handle.
[in]taskTask to remove. Must be currently scheduled.
Note
KERNEL_DYNAMIC only. The task is removed on the next scheduling tick and its OnExit() callback is invoked automatically.
To remove a task before stk_kernel_start(), use stk_kernel_remove_task() instead.
See also
stk_kernel_remove_task
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 441 of file stk_c.cpp.

442{
443 STK_ASSERT(k != nullptr);
444 STK_ASSERT(tsk != nullptr);
445
447}
virtual void ScheduleTaskRemoval(ITask *user_task)=0
Schedule task removal from scheduling (exit).

References CastCToKernelInterface(), stk_task_t::handle, stk::IKernel::ScheduleTaskRemoval(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_set_event_overrider()

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.

Parameters
[in]kKernel handle obtained from stk_kernel_create().
[in]overriderPointer 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).
Note
Must be called after stk_kernel_init() and before stk_kernel_start().
Not ISR-safe.
See also
stk_event_overrider_t
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 518 of file stk_c.cpp.

519{
520 STK_ASSERT(k != nullptr);
521
523}
static void SetEventOverrider(IKernel *k, stk_event_overrider_t *overrider)
Definition stk_c.cpp:240

References CastCToKernelInterface(), SetEventOverrider(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_start()

void stk_kernel_start ( stk_kernel_t * k)

Start the scheduler - never returns.

Parameters
[in]kKernel handle.
Note
Transfers control to the scheduler and a first ready task. May return if all tasks are finished and kernel is dynamic.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 395 of file stk_c.cpp.

396{
397 STK_ASSERT(k != nullptr);
398
400}
virtual void Start()=0
Start kernel scheduling.

References CastCToKernelInterface(), stk::IKernel::Start(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_kernel_suspend()

stk_timeout_t stk_kernel_suspend ( stk_kernel_t * k)

Suspend scheduling (tickless idle entry point).

Parameters
[in]kKernel handle.
Returns
Number of ticks available for the suspension period, determined by the nearest pending wake-up deadline across all sleeping tasks. The caller may program a hardware timer with this value to suppress SysTick wakeups.
Note
ISR-safe. Pair every call with stk_kernel_resume().
Only meaningful when the kernel was created with KERNEL_TICKLESS mode.
See also
stk_kernel_resume, STK_KERNEL_STATE_SUSPENDED
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 490 of file stk_c.cpp.

491{
492 STK_ASSERT(k != nullptr);
493
494 return static_cast<stk_timeout_t>(CastCToKernelInterface(k)->GetPlatform()->Suspend());
495}
int32_t stk_timeout_t
Timeout value.
Definition stk_c.h:113
virtual Timeout Suspend()=0
Suspend scheduling.

References CastCToKernelInterface(), stk::IKernel::GetPlatform(), STK_ASSERT, and stk::IPlatform::Suspend().

Here is the call graph for this function:

◆ stk_kernel_suspend_task()

void stk_kernel_suspend_task ( stk_kernel_t * k,
stk_task_t * task,
bool * suspended )

Suspend a task (prevent it from being scheduled).

Parameters
[in]kKernel handle.
[in]taskTask to suspend.
[out]suspendedSet 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).
Note
Do not hold a critical section when suspending the calling task - this will deadlock.
If the task suspends itself, the call blocks until the kernel switches it out.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 449 of file stk_c.cpp.

450{
451 STK_ASSERT(k != nullptr);
452 STK_ASSERT(tsk != nullptr);
453 STK_ASSERT(suspended != nullptr);
454
455 CastCToKernelInterface(k)->SuspendTask(&tsk->handle, *suspended);
456}
virtual void SuspendTask(ITask *user_task, bool &suspended)=0
Suspend task.

References CastCToKernelInterface(), stk_task_t::handle, STK_ASSERT, and stk::IKernel::SuspendTask().

Here is the call graph for this function:

◆ stk_ms_from_ticks()

stk_time_t stk_ms_from_ticks ( stk_tick_t ticks)
inlinestatic

Convert ticks to milliseconds using the current kernel tick resolution.

Parameters
[in]ticksTick count to convert.
Returns
Equivalent time in milliseconds.
Note
Requires the kernel to be initialized before calling.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 664 of file stk_c.h.

665{
667}
uint32_t stk_tick_resolution(void)
Returns how many microseconds correspond to one kernel tick.
Definition stk_c.cpp:617
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.
Definition stk_c.h:653

References stk_ms_from_ticks_r(), and stk_tick_resolution().

Here is the call graph for this function:

◆ stk_ms_from_ticks_r()

stk_time_t stk_ms_from_ticks_r ( stk_tick_t ticks,
uint32_t resolution )
inlinestatic

Convert ticks to milliseconds using an explicit tick resolution.

Parameters
[in]ticksTick count to convert.
[in]resolutionMicroseconds per tick (see stk_tick_resolution()).
Returns
Equivalent time in milliseconds.
Note
ISR-safe (arithmetic only).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 653 of file stk_c.h.

654{
655 const stk_tick_t total_ticks = ticks * STK_STATIC_CAST(stk_tick_t, resolution);
656 return STK_STATIC_CAST(stk_time_t, total_ticks / 1000LL);
657}
#define STK_STATIC_CAST(type, val)
Convenience wrapper for static_cast and C-style cast.
Definition stk_c.h:83
int64_t stk_tick_t
Ticks value.
Definition stk_c.h:103
int64_t stk_time_t
Time value.
Definition stk_c.h:108

References STK_STATIC_CAST.

Referenced by stk_ms_from_ticks().

Here is the caller graph for this function:

◆ stk_msgq_create()

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.

Parameters
[in]membufPointer to static memory container for the queue object. Must be at least sizeof(stk_msgq_mem_t) bytes.
[in]membuf_sizeSize of membuf in bytes (must be >= sizeof(stk_msgq_mem_t)).
[in]bufPointer to the message data buffer. Must be at least capacity * msg_size bytes.
[in]buf_sizeSize of buf in bytes (used only for the safety assertion; must equal capacity * msg_size).
[in]capacityMaximum number of messages [1, 65534].
[in]msg_sizeSize of each individual message in bytes (>= 1).
Returns
MessageQueue handle, or NULL if any size assertion fails.
Note
Convenience macro STK_MSGQ_BUF_SIZE(capacity, msg_size) computes the required buf_size.
Only available when kernel is compiled with KERNEL_SYNC mode enabled.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 582 of file stk_c_sync.cpp.

588{
589 STK_ASSERT(membuf != nullptr);
590 STK_ASSERT(buf != nullptr);
591 STK_ASSERT(capacity >= 1U);
592 STK_ASSERT(msg_size >= 1U);
593 STK_ASSERT(membuf_size >= sizeof(stk_msgq_t));
594 STK_ASSERT(buf_size >= capacity * msg_size);
595
596 stk_msgq_t *result = nullptr;
597 if ((membuf_size >= sizeof(stk_msgq_t)) && (buf_size >= (capacity * msg_size)))
598 {
599 result = new (membuf) stk_msgq_t(buf, capacity, msg_size);
600 }
601
602 return result;
603}

References STK_ASSERT.

◆ stk_msgq_destroy()

void stk_msgq_destroy ( stk_msgq_t * mq)

Destroy a MessageQueue.

Parameters
[in]mqMessageQueue handle.
Note
Any tasks still blocked on Put/Get at destruction time are considered a logic error; an assertion is triggered in debug builds.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 605 of file stk_c_sync.cpp.

606{
607 if (mq != nullptr)
608 {
609 mq->~stk_msgq_t();
610 }
611}

◆ stk_msgq_get()

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.

Parameters
[in]mqMessageQueue handle.
[out]msgDestination buffer (must be >= msg_size bytes).
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
True if a message was retrieved, False on timeout.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 645 of file stk_c_sync.cpp.

646{
647 STK_ASSERT(mq != nullptr);
648 STK_ASSERT(msg != nullptr);
649
650 return mq->handle.Get(msg, timeout);
651}
bool Get(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Get a message from the queue.
MessageQueue handle

References stk::sync::MessageQueue::Get(), stk_msgq_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_get_buffer()

uint8_t * stk_msgq_get_buffer ( stk_msgq_t * mq)

Get a pointer to the raw message data buffer.

Parameters
[in]mqMessageQueue handle.
Returns
Pointer to the beginning of the backing byte buffer supplied at construction time.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 742 of file stk_c_sync.cpp.

743{
744 STK_ASSERT(mq != nullptr);
745
746 return mq->handle.GetBuffer();
747}
uint8_t * GetBuffer()
Get pointer to the message buffer.

References stk::sync::MessageQueue::GetBuffer(), stk_msgq_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_get_capacity()

size_t stk_msgq_get_capacity ( const stk_msgq_t * mq)

Get the maximum number of messages the queue can hold.

Parameters
[in]mqMessageQueue handle.
Returns
Construction-time capacity.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 700 of file stk_c_sync.cpp.

701{
702 STK_ASSERT(mq != nullptr);
703
704 return mq->handle.GetCapacity();
705}
size_t GetCapacity() const
Get the maximum number of messages the queue can hold.

References stk::sync::MessageQueue::GetCapacity(), stk_msgq_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_get_count()

size_t stk_msgq_get_count ( const stk_msgq_t * mq)

Get the current number of messages waiting in the queue.

Parameters
[in]mqMessageQueue handle.
Returns
Point-in-time snapshot of the message count.
Note
ISR-safe on targets where a size_t-aligned read is atomic.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 714 of file stk_c_sync.cpp.

715{
716 STK_ASSERT(mq != nullptr);
717
718 return mq->handle.GetCount();
719}
size_t GetCount() const
Get the current number of messages in the queue.

References stk::sync::MessageQueue::GetCount(), stk_msgq_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_get_msg_size()

size_t stk_msgq_get_msg_size ( const stk_msgq_t * mq)

Get the size of each message in bytes.

Parameters
[in]mqMessageQueue handle.
Returns
Construction-time message size.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 707 of file stk_c_sync.cpp.

708{
709 STK_ASSERT(mq != nullptr);
710
711 return mq->handle.GetMsgSize();
712}
size_t GetMsgSize() const
Get the size of each message in bytes.

References stk::sync::MessageQueue::GetMsgSize(), stk_msgq_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_get_space()

size_t stk_msgq_get_space ( const stk_msgq_t * mq)

Get the number of free slots currently available.

Parameters
[in]mqMessageQueue handle.
Returns
Point-in-time snapshot of the free-slot count.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 721 of file stk_c_sync.cpp.

722{
723 STK_ASSERT(mq != nullptr);
724
725 return mq->handle.GetSpace();
726}
size_t GetSpace() const
Get the number of free slots currently available.

References stk::sync::MessageQueue::GetSpace(), stk_msgq_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_is_empty()

bool stk_msgq_is_empty ( const stk_msgq_t * mq)

Check whether the queue is currently empty.

Parameters
[in]mqMessageQueue handle.
Returns
True if the queue contains no messages.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 728 of file stk_c_sync.cpp.

729{
730 STK_ASSERT(mq != nullptr);
731
732 return mq->handle.IsEmpty();
733}
bool IsEmpty() const
Check whether the queue is currently empty.

References stk_msgq_t::handle, stk::sync::MessageQueue::IsEmpty(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_is_full()

bool stk_msgq_is_full ( const stk_msgq_t * mq)

Check whether the queue is currently full.

Parameters
[in]mqMessageQueue handle.
Returns
True if the queue contains capacity messages.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 735 of file stk_c_sync.cpp.

736{
737 STK_ASSERT(mq != nullptr);
738
739 return mq->handle.IsFull();
740}
bool IsFull() const
Check whether the queue is currently full.

References stk_msgq_t::handle, stk::sync::MessageQueue::IsFull(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_is_storage_valid()

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.

Parameters
[in]mqMessageQueue handle.
Returns
True if the queue is ready for use.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 749 of file stk_c_sync.cpp.

750{
751 STK_ASSERT(mq != nullptr);
752
753 return mq->handle.IsStorageValid();
754}
bool IsStorageValid() const
Verify that the backing storage is valid and the pool is ready for use.

References stk_msgq_t::handle, stk::sync::MessageQueue::IsStorageValid(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_peek()

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.

Parameters
[in]mqMessageQueue handle.
[out]msgDestination buffer (must be >= msg_size bytes).
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
True if a message was peeked, False on timeout.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 661 of file stk_c_sync.cpp.

662{
663 STK_ASSERT(mq != nullptr);
664 STK_ASSERT(msg != nullptr);
665
666 return mq->handle.Peek(msg, timeout);
667}
bool Peek(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Peek at the next message to be delivered (back of the FIFO) without removing it.

References stk_msgq_t::handle, stk::sync::MessageQueue::Peek(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_peekfront()

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.

Parameters
[in]mqMessageQueue handle.
[out]msgDestination buffer (must be >= msg_size bytes).
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
True if a message was peeked, False on timeout.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 677 of file stk_c_sync.cpp.

678{
679 STK_ASSERT(mq != nullptr);
680 STK_ASSERT(msg != nullptr);
681
682 return mq->handle.PeekFront(msg, timeout);
683}
bool PeekFront(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Peek at the most recently front-inserted message (front of the FIFO) without removing it.

References stk_msgq_t::handle, stk::sync::MessageQueue::PeekFront(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_put()

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.

Parameters
[in]mqMessageQueue handle.
[in]msgPointer to the message payload (must be >= msg_size bytes).
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
True if the message was enqueued, False on timeout.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 613 of file stk_c_sync.cpp.

614{
615 STK_ASSERT(mq != nullptr);
616 STK_ASSERT(msg != nullptr);
617
618 return mq->handle.Put(msg, timeout);
619}
bool Put(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the back of the queue (FIFO order).

References stk_msgq_t::handle, stk::sync::MessageQueue::Put(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_putfront()

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.

Parameters
[in]mqMessageQueue handle.
[in]msgPointer to the message payload (must be >= msg_size bytes).
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
True if the message was enqueued at the front, False on timeout.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 629 of file stk_c_sync.cpp.

630{
631 STK_ASSERT(mq != nullptr);
632 STK_ASSERT(msg != nullptr);
633
634 return mq->handle.PutFront(msg, timeout);
635}
bool PutFront(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the front of the queue (LIFO / priority-insert order).

References stk_msgq_t::handle, stk::sync::MessageQueue::PutFront(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_reset()

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.

Parameters
[in]mqMessageQueue handle.
Warning
Messages that were in the queue are silently discarded.
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 693 of file stk_c_sync.cpp.

694{
695 STK_ASSERT(mq != nullptr);
696
697 mq->handle.Reset();
698}
void Reset()
Discard all messages and reset the queue to the empty state.

References stk_msgq_t::handle, stk::sync::MessageQueue::Reset(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_msgq_tryget()

bool stk_msgq_tryget ( stk_msgq_t * mq,
void * msg )

Attempt to get a message from the queue without blocking.

Parameters
[in]mqMessageQueue handle.
[out]msgDestination buffer.
Returns
True if a message was retrieved, False if the queue was empty.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 653 of file stk_c_sync.cpp.

654{
655 STK_ASSERT(mq != nullptr);
656 STK_ASSERT(msg != nullptr);
657
658 return mq->handle.TryGet(msg);
659}
bool TryGet(void *msg_ptr)
Attempt to get a message from the queue without blocking.

References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryGet().

Here is the call graph for this function:

◆ stk_msgq_trypeek()

bool stk_msgq_trypeek ( stk_msgq_t * mq,
void * msg )

Attempt to peek at the next message without blocking.

Parameters
[in]mqMessageQueue handle.
[out]msgDestination buffer (must be >= msg_size bytes).
Returns
True if a message was peeked, False if the queue was empty.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 669 of file stk_c_sync.cpp.

670{
671 STK_ASSERT(mq != nullptr);
672 STK_ASSERT(msg != nullptr);
673
674 return mq->handle.TryPeek(msg);
675}
bool TryPeek(void *msg_ptr)
Attempt to peek at the next message without blocking.

References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryPeek().

Here is the call graph for this function:

◆ stk_msgq_trypeekfront()

bool stk_msgq_trypeekfront ( stk_msgq_t * mq,
void * msg )

Attempt to peek at the front message without blocking.

Parameters
[in]mqMessageQueue handle.
[out]msgDestination buffer (must be >= msg_size bytes).
Returns
True if a message was peeked, False if the queue was empty.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 685 of file stk_c_sync.cpp.

686{
687 STK_ASSERT(mq != nullptr);
688 STK_ASSERT(msg != nullptr);
689
690 return mq->handle.TryPeekFront(msg);
691}
bool TryPeekFront(void *msg_ptr)
Attempt to peek at the front message without blocking.

References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryPeekFront().

Here is the call graph for this function:

◆ stk_msgq_tryput()

bool stk_msgq_tryput ( stk_msgq_t * mq,
const void * msg )

Attempt to put a message into the queue without blocking.

Parameters
[in]mqMessageQueue handle.
[in]msgPointer to the message payload.
Returns
True if enqueued, False if the queue was full.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 621 of file stk_c_sync.cpp.

622{
623 STK_ASSERT(mq != nullptr);
624 STK_ASSERT(msg != nullptr);
625
626 return mq->handle.TryPut(msg);
627}
bool TryPut(const void *msg_ptr)
Attempt to put a message into the back of the queue without blocking.

References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryPut().

Here is the call graph for this function:

◆ stk_msgq_tryputfront()

bool stk_msgq_tryputfront ( stk_msgq_t * mq,
const void * msg )

Attempt to put a message into the front of the queue without blocking.

Parameters
[in]mqMessageQueue handle.
[in]msgPointer to the message payload.
Returns
True if enqueued at the front, False if the queue was full.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 637 of file stk_c_sync.cpp.

638{
639 STK_ASSERT(mq != nullptr);
640 STK_ASSERT(msg != nullptr);
641
642 return mq->handle.TryPutFront(msg);
643}
bool TryPutFront(const void *msg_ptr)
Attempt to put a message into the front of the queue without blocking.

References stk_msgq_t::handle, STK_ASSERT, and stk::sync::MessageQueue::TryPutFront().

Here is the call graph for this function:

◆ stk_mutex_create()

stk_mutex_t * stk_mutex_create ( stk_mutex_mem_t *const membuf,
uint32_t membuf_size )

Create a Mutex (using provided memory).

Parameters
[in]membufPointer to static memory container.
[in]membuf_sizeSize of the container (must be >= sizeof(stk_mutex_mem_t)).
Returns
Mutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 35 of file stk_c_sync.cpp.

36{
37 STK_ASSERT(membuf != nullptr);
38 STK_ASSERT(membuf_size >= sizeof(stk_mutex_t));
39
40 stk_mutex_t *result = nullptr;
41 if (membuf_size >= sizeof(stk_mutex_t))
42 {
43 result = new (membuf->data) stk_mutex_t();
44 }
45
46 return result;
47}
struct stk_mutex_t stk_mutex_t
Opaque handle to a Mutex instance.
Definition stk_c.h:853
stk_word_t data[(10U+((0) ? 1U :0U))]
Definition stk_c.h:848

References stk_mutex_mem_t::data, and STK_ASSERT.

◆ stk_mutex_destroy()

void stk_mutex_destroy ( stk_mutex_t * mtx)

Destroy a Mutex.

Parameters
[in]mtxMutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 49 of file stk_c_sync.cpp.

50{
51 if (mtx != nullptr)
52 {
53 mtx->~stk_mutex_t();
54 }
55}

◆ stk_mutex_lock()

void stk_mutex_lock ( stk_mutex_t * mtx)

Lock the mutex. Blocks until available.

Parameters
[in]mtxMutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 57 of file stk_c_sync.cpp.

58{
59 STK_ASSERT(mtx != nullptr);
60
61 mtx->handle.Lock();
62}
void Lock() override
Acquire lock.

References stk_mutex_t::handle, stk::sync::Mutex::Lock(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_mutex_timed_lock()

bool stk_mutex_timed_lock ( stk_mutex_t * mtx,
stk_timeout_t timeout )

Try to lock the mutex with a timeout.

Parameters
[in]mtxMutex handle.
[in]timeoutMax time to wait in milliseconds.
Returns
True if locked successfully, False on timeout.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 78 of file stk_c_sync.cpp.

79{
80 STK_ASSERT(mtx != nullptr);
81
82 return mtx->handle.TimedLock(timeout);
83}
bool TimedLock(Timeout timeout_ticks)
Acquire lock.

References stk_mutex_t::handle, STK_ASSERT, and stk::sync::Mutex::TimedLock().

Here is the call graph for this function:

◆ stk_mutex_trylock()

bool stk_mutex_trylock ( stk_mutex_t * mtx)

Try locking the mutex. Does not block if already locked.

Parameters
[in]mtxMutex handle.
Returns
True if locked successfully, False on timeout.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 64 of file stk_c_sync.cpp.

65{
66 STK_ASSERT(mtx != nullptr);
67
68 return mtx->handle.TryLock();
69}
bool TryLock()
Acquire the lock.

References stk_mutex_t::handle, STK_ASSERT, and stk::sync::Mutex::TryLock().

Here is the call graph for this function:

◆ stk_mutex_unlock()

void stk_mutex_unlock ( stk_mutex_t * mtx)

Unlock the mutex.

Parameters
[in]mtxMutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 71 of file stk_c_sync.cpp.

72{
73 STK_ASSERT(mtx != nullptr);
74
75 mtx->handle.Unlock();
76}
void Unlock() override
Release lock.

References stk_mutex_t::handle, STK_ASSERT, and stk::sync::Mutex::Unlock().

Here is the call graph for this function:

◆ stk_pipe_create()

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.

Parameters
[in]membufPointer to static memory container for the Pipe control-block. Must be at least sizeof(stk_pipe_mem_t) bytes.
[in]membuf_sizeSize of membuf in bytes.
[in]bufPointer to the element data buffer. Must be at least capacity * element_size bytes.
[in]buf_sizeSize of buf in bytes (used for the safety assertion; must equal capacity * element_size).
[in]capacityMaximum number of elements [1, 65534].
[in]element_sizeSize of each individual element in bytes (>= 1).
Returns
Pipe handle, or NULL if any size assertion fails.
Note
Convenience macro STK_PIPE_BUF_SIZE(capacity, element_size) computes the required buf_size.
Only available when kernel is compiled with KERNEL_SYNC mode enabled.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 405 of file stk_c_sync.cpp.

411{
412 STK_ASSERT(membuf != nullptr);
413 STK_ASSERT(buf != nullptr);
414 STK_ASSERT(capacity >= 1U);
415 STK_ASSERT(element_size >= 1U);
416 STK_ASSERT(membuf_size >= sizeof(stk_pipe_t));
417 STK_ASSERT(buf_size >= capacity * element_size);
418
419 stk_pipe_t *result = nullptr;
420 if ((membuf_size >= sizeof(stk_pipe_t)) && (buf_size >= (capacity * element_size)))
421 {
422 result = new (membuf->data) stk_pipe_t(buf, capacity, element_size);
423 }
424
425 return result;
426}
stk_word_t data[(6U+(2U *(7U+((0) ? 1U :0U)))+((0) ? 1U :0U))]
Definition stk_c.h:1233

References stk_pipe_mem_t::data, and STK_ASSERT.

◆ stk_pipe_destroy()

void stk_pipe_destroy ( stk_pipe_t * pipe)

Destroy a Pipe.

Parameters
[in]pipePipe handle.
Note
Any tasks still blocked on Write/Read at destruction time are considered a logic error; an assertion is triggered in debug builds.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 428 of file stk_c_sync.cpp.

429{
430 if (pipe != nullptr)
431 {
432 pipe->~stk_pipe_t();
433 }
434}

◆ stk_pipe_get_capacity()

size_t stk_pipe_get_capacity ( const stk_pipe_t * pipe)

Get the maximum number of elements the pipe can hold.

Parameters
[in]pipePipe handle.
Returns
Construction-time capacity.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 521 of file stk_c_sync.cpp.

522{
523 STK_ASSERT(pipe != nullptr);
524
525 return pipe->handle.GetCapacity();
526}
size_t GetCapacity() const
Get the maximum number of elements the pipe can hold.

References stk::sync::Pipe::GetCapacity(), stk_pipe_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_get_count()

size_t stk_pipe_get_count ( const stk_pipe_t * pipe)

Get the current number of elements in the pipe.

Parameters
[in]pipePipe handle.
Returns
Point-in-time snapshot of the element count.
Note
ISR-safe on targets where a size_t-aligned read is atomic.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 535 of file stk_c_sync.cpp.

536{
537 STK_ASSERT(pipe != nullptr);
538
539 return pipe->handle.GetCount();
540}
size_t GetCount() const
Get the current number of elements in the pipe.

References stk::sync::Pipe::GetCount(), stk_pipe_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_get_element_size()

size_t stk_pipe_get_element_size ( const stk_pipe_t * pipe)

Get the size of each element in bytes.

Parameters
[in]pipePipe handle.
Returns
Construction-time element size.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 528 of file stk_c_sync.cpp.

529{
530 STK_ASSERT(pipe != nullptr);
531
532 return pipe->handle.GetElementSize();
533}
size_t GetElementSize() const
Get the size of each element in bytes.

References stk::sync::Pipe::GetElementSize(), stk_pipe_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_get_space()

size_t stk_pipe_get_space ( const stk_pipe_t * pipe)

Get the number of free slots currently available.

Parameters
[in]pipePipe handle.
Returns
Point-in-time snapshot of the free-slot count.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 542 of file stk_c_sync.cpp.

543{
544 STK_ASSERT(pipe != nullptr);
545
546 return pipe->handle.GetSpace();
547}
size_t GetSpace() const
Get the number of free slots currently available.

References stk::sync::Pipe::GetSpace(), stk_pipe_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_is_empty()

bool stk_pipe_is_empty ( const stk_pipe_t * pipe)

Check whether the pipe is currently empty.

Parameters
[in]pipePipe handle.
Returns
True if the pipe contains no elements.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 549 of file stk_c_sync.cpp.

550{
551 STK_ASSERT(pipe != nullptr);
552
553 return pipe->handle.IsEmpty();
554}
bool IsEmpty() const
Check if the pipe is currently empty.

References stk_pipe_t::handle, stk::sync::Pipe::IsEmpty(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_is_full()

bool stk_pipe_is_full ( const stk_pipe_t * pipe)

Check whether the pipe is currently full.

Parameters
[in]pipePipe handle.
Returns
True if the pipe contains capacity elements.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 556 of file stk_c_sync.cpp.

557{
558 STK_ASSERT(pipe != nullptr);
559
560 return pipe->handle.IsFull();
561}
bool IsFull() const
Check if the pipe is currently full.

References stk_pipe_t::handle, stk::sync::Pipe::IsFull(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_is_storage_valid()

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.

Parameters
[in]pipePipe handle.
Returns
True if the pipe is ready for use.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 563 of file stk_c_sync.cpp.

564{
565 STK_ASSERT(pipe != nullptr);
566
567 return pipe->handle.IsStorageValid();
568}
bool IsStorageValid() const
Verify that the backing storage is valid and the pipe is ready for use.

References stk_pipe_t::handle, stk::sync::Pipe::IsStorageValid(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_read()

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.

Parameters
[in]pipePipe handle.
[out]dataDestination buffer (must be >= element_size bytes).
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
True if an element was read, False on timeout.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 452 of file stk_c_sync.cpp.

453{
454 STK_ASSERT(pipe != nullptr);
455 STK_ASSERT(data != nullptr);
456
457 return pipe->handle.Read(data, timeout);
458}
bool Read(void *data, Timeout timeout_ticks=WAIT_INFINITE)
Read a single element from the pipe.

References stk_pipe_t::handle, stk::sync::Pipe::Read(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_read_bulk()

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.

Parameters
[in]pipePipe handle.
[out]dstPointer to the destination array (must hold at least count elements of element_size bytes each).
[in]countNumber of elements to read.
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
Number of elements actually read. Equal to count unless a timeout occurred.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 482 of file stk_c_sync.cpp.

483{
484 STK_ASSERT(pipe != nullptr);
485
486 return pipe->handle.ReadBulk(dst, count, timeout);
487}
size_t ReadBulk(void *dst, size_t count, Timeout timeout_ticks=WAIT_INFINITE)
Read multiple elements from the pipe.

References stk_pipe_t::handle, stk::sync::Pipe::ReadBulk(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_read_bulk_triggered()

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.

Parameters
[in]pipePipe handle.
[out]dstDestination buffer; must hold at least max_count elements of element_size bytes.
[in]triggerMinimum number of elements that must be available before any data is dequeued. Clamped to [1, max_count] internally.
[in]max_countMaximum number of elements to return in total.
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
Number of elements actually read (0 if timeout fired before trigger was reached).
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 496 of file stk_c_sync.cpp.

501{
502 STK_ASSERT(pipe != nullptr);
503
504 return pipe->handle.ReadBulkTriggered(dst, trigger, max_count, timeout);
505}
size_t ReadBulkTriggered(void *dst, size_t trigger, size_t max_count, Timeout timeout_ticks=WAIT_INFINITE)
Read at least trigger elements, then drain up to max_count without blocking.

References stk_pipe_t::handle, stk::sync::Pipe::ReadBulkTriggered(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_reset()

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.

Parameters
[in]pipePipe handle.
Warning
Elements that were in the pipe are silently discarded.
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 514 of file stk_c_sync.cpp.

515{
516 STK_ASSERT(pipe != nullptr);
517
518 pipe->handle.Reset();
519}
void Reset()
Discard all elements and reset the pipe to the empty state.

References stk_pipe_t::handle, stk::sync::Pipe::Reset(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_tryread()

bool stk_pipe_tryread ( stk_pipe_t * pipe,
void * data )

Attempt to read a single element from the pipe without blocking.

Parameters
[in]pipePipe handle.
[out]dataDestination buffer (must be >= element_size bytes).
Returns
True if an element was read, False if the pipe was empty.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 460 of file stk_c_sync.cpp.

461{
462 STK_ASSERT(pipe != nullptr);
463 STK_ASSERT(data != nullptr);
464
465 return pipe->handle.TryRead(data);
466}
bool TryRead(void *data)
Attempt to read a single element from the pipe without blocking.

References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryRead().

Here is the call graph for this function:

◆ stk_pipe_tryread_bulk()

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.

Parameters
[in]pipePipe handle.
[out]dstPointer to the destination array.
[in]countNumber of elements to read.
Returns
Number of elements actually read.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 489 of file stk_c_sync.cpp.

490{
491 STK_ASSERT(pipe != nullptr);
492
493 return pipe->handle.TryReadBulk(dst, count);
494}
size_t TryReadBulk(void *dst, size_t count)
Attempt to read multiple elements from the pipe without blocking.

References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryReadBulk().

Here is the call graph for this function:

◆ stk_pipe_tryread_bulk_triggered()

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.

Parameters
[in]pipePipe handle.
[out]dstDestination buffer.
[in]max_countMaximum number of elements to read.
Returns
Number of elements actually read.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 507 of file stk_c_sync.cpp.

508{
509 STK_ASSERT(pipe != nullptr);
510
511 return pipe->handle.TryReadBulkTriggered(dst, max_count);
512}
size_t TryReadBulkTriggered(void *dst, size_t max_count)
Non-blocking variant of ReadBulkTriggered.

References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryReadBulkTriggered().

Here is the call graph for this function:

◆ stk_pipe_trywrite()

bool stk_pipe_trywrite ( stk_pipe_t * pipe,
const void * data )

Attempt to write a single element to the pipe without blocking.

Parameters
[in]pipePipe handle.
[in]dataPointer to the element payload.
Returns
True if written, False if the pipe was full.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 444 of file stk_c_sync.cpp.

445{
446 STK_ASSERT(pipe != nullptr);
447 STK_ASSERT(data != nullptr);
448
449 return pipe->handle.TryWrite(data);
450}
bool TryWrite(const void *data)
Attempt to write a single element to the pipe without blocking.

References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryWrite().

Here is the call graph for this function:

◆ stk_pipe_trywrite_bulk()

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.

Parameters
[in]pipePipe handle.
[in]srcPointer to the source array.
[in]countNumber of elements to write.
Returns
Number of elements actually written.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 475 of file stk_c_sync.cpp.

476{
477 STK_ASSERT(pipe != nullptr);
478
479 return pipe->handle.TryWriteBulk(src, count);
480}
size_t TryWriteBulk(const void *src, size_t count)
Attempt to write multiple elements to the pipe without blocking.

References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::TryWriteBulk().

Here is the call graph for this function:

◆ stk_pipe_write()

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.

Parameters
[in]pipePipe handle.
[in]dataPointer to the element payload (must be >= element_size bytes).
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
True if the element was written, False on timeout.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 436 of file stk_c_sync.cpp.

437{
438 STK_ASSERT(pipe != nullptr);
439 STK_ASSERT(data != nullptr);
440
441 return pipe->handle.Write(data, timeout);
442}
bool Write(const void *data, Timeout timeout_ticks=WAIT_INFINITE)
Write a single element to the pipe.

References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::Write().

Here is the call graph for this function:

◆ stk_pipe_write_bulk()

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.

Parameters
[in]pipePipe handle.
[in]srcPointer to the source array (must hold at least count elements of element_size bytes each).
[in]countNumber of elements to write.
[in]timeoutMax time to wait (ticks). Use STK_WAIT_INFINITE to block indefinitely, STK_NO_WAIT for a non-blocking attempt.
Returns
Number of elements actually written. Equal to count unless a timeout occurred.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 468 of file stk_c_sync.cpp.

469{
470 STK_ASSERT(pipe != nullptr);
471
472 return pipe->handle.WriteBulk(src, count, timeout);
473}
size_t WriteBulk(const void *src, size_t count, Timeout timeout_ticks=WAIT_INFINITE)
Write multiple elements to the pipe.

References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe::WriteBulk().

Here is the call graph for this function:

◆ stk_rwmutex_create()

stk_rwmutex_t * stk_rwmutex_create ( stk_rwmutex_mem_t *const membuf,
uint32_t membuf_size )

Create an RWMutex (using provided memory).

Parameters
[in]membufPointer to static memory container.
[in]membuf_sizeSize of the container (must be >= sizeof(stk_rwmutex_mem_t)).
Returns
RWMutex handle, or NULL if memory is too small.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 764 of file stk_c_sync.cpp.

765{
766 STK_ASSERT(membuf != nullptr);
767 STK_ASSERT(membuf_size >= sizeof(stk_rwmutex_t));
768
769 stk_rwmutex_t *result = nullptr;
770 if (membuf_size >= sizeof(stk_rwmutex_t))
771 {
772 result = new (membuf->data) stk_rwmutex_t();
773 }
774
775 return result;
776}
struct stk_rwmutex_t stk_rwmutex_t
Opaque handle to an RWMutex instance.
Definition stk_c.h:1742
stk_word_t data[(17U+((0) ? 3U :0U))]
Definition stk_c.h:1737

References stk_rwmutex_mem_t::data, and STK_ASSERT.

◆ stk_rwmutex_destroy()

void stk_rwmutex_destroy ( stk_rwmutex_t * rw)

Destroy an RWMutex.

Parameters
[in]rwRWMutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 778 of file stk_c_sync.cpp.

779{
780 if (rw != nullptr)
781 {
782 rw->~stk_rwmutex_t();
783 }
784}

◆ stk_rwmutex_lock()

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.

Parameters
[in]rwRWMutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 814 of file stk_c_sync.cpp.

815{
816 STK_ASSERT(rw != nullptr);
817
818 rw->handle.Lock();
819}
void Lock() override
Acquire the lock for exclusive writing (IMutex interface).
sync::RWMutex handle

References stk_rwmutex_t::handle, stk::sync::RWMutex::Lock(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_rwmutex_read_lock()

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).

Parameters
[in]rwRWMutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 786 of file stk_c_sync.cpp.

787{
788 STK_ASSERT(rw != nullptr);
789
790 rw->handle.ReadLock();
791}
void ReadLock()
Acquire the lock for shared reading.

References stk_rwmutex_t::handle, stk::sync::RWMutex::ReadLock(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_rwmutex_read_unlock()

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.

Parameters
[in]rwRWMutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 807 of file stk_c_sync.cpp.

808{
809 STK_ASSERT(rw != nullptr);
810
811 rw->handle.ReadUnlock();
812}
void ReadUnlock()
Release the shared reader lock.

References stk_rwmutex_t::handle, stk::sync::RWMutex::ReadUnlock(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_rwmutex_timed_lock()

bool stk_rwmutex_timed_lock ( stk_rwmutex_t * rw,
stk_timeout_t timeout )

Try to acquire the write lock with a timeout.

Parameters
[in]rwRWMutex handle.
[in]timeoutMax time to wait (ticks). Use STK_NO_WAIT for non-blocking.
Returns
True if acquired, False on timeout.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 828 of file stk_c_sync.cpp.

829{
830 STK_ASSERT(rw != nullptr);
831
832 return rw->handle.TimedLock(timeout);
833}
bool TimedLock(Timeout timeout_ticks)
Acquire the lock for exclusive writing with a timeout.

References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::TimedLock().

Here is the call graph for this function:

◆ stk_rwmutex_timed_read_lock()

bool stk_rwmutex_timed_read_lock ( stk_rwmutex_t * rw,
stk_timeout_t timeout )

Try to acquire the read lock with a timeout.

Parameters
[in]rwRWMutex handle.
[in]timeoutMax time to wait (ticks). Use STK_NO_WAIT for non-blocking.
Returns
True if acquired, False on timeout.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 800 of file stk_c_sync.cpp.

801{
802 STK_ASSERT(rw != nullptr);
803
804 return rw->handle.TimedReadLock(timeout);
805}
bool TimedReadLock(Timeout timeout_ticks)
Acquire the lock for shared reading with a timeout.

References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::TimedReadLock().

Here is the call graph for this function:

◆ stk_rwmutex_try_read_lock()

bool stk_rwmutex_try_read_lock ( stk_rwmutex_t * rw)

Try to acquire the read lock without blocking.

Parameters
[in]rwRWMutex handle.
Returns
True if the read lock was acquired, False if a writer is active or waiting.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 793 of file stk_c_sync.cpp.

794{
795 STK_ASSERT(rw != nullptr);
796
797 return rw->handle.TryReadLock();
798}
bool TryReadLock()
Attempt to acquire the lock for shared reading without blocking.

References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::TryReadLock().

Here is the call graph for this function:

◆ stk_rwmutex_trylock()

bool stk_rwmutex_trylock ( stk_rwmutex_t * rw)

Try to acquire the write lock without blocking.

Parameters
[in]rwRWMutex handle.
Returns
True if the exclusive lock was acquired, False otherwise.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 821 of file stk_c_sync.cpp.

822{
823 STK_ASSERT(rw != nullptr);
824
825 return rw->handle.TryLock();
826}
bool TryLock()
Attempt to acquire the lock for exclusive writing without blocking.

References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::TryLock().

Here is the call graph for this function:

◆ stk_rwmutex_unlock()

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).

Parameters
[in]rwRWMutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 835 of file stk_c_sync.cpp.

836{
837 STK_ASSERT(rw != nullptr);
838
839 rw->handle.Unlock();
840}
void Unlock() override
Release the exclusive writer lock (IMutex interface).

References stk_rwmutex_t::handle, STK_ASSERT, and stk::sync::RWMutex::Unlock().

Here is the call graph for this function:

◆ stk_sem_create()

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).

Parameters
[in]membufPointer to static memory container.
[in]membuf_sizeSize of the container (must be >= sizeof(stk_sem_mem_t)).
[in]initial_countStarting value of the resource counter.
[in]max_countMaximum value the counter is allowed to reach. Pass 0 to use the default maximum (65534). Must be > initial_count.
Returns
Semaphore handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 268 of file stk_c_sync.cpp.

272{
273 STK_ASSERT(membuf != nullptr);
274 STK_ASSERT(membuf_size >= sizeof(stk_sem_t));
275 STK_ASSERT(initial_count < (max_count == 0U ? Semaphore::COUNT_MAX : max_count));
276
277 stk_sem_t *result = nullptr;
278 if (membuf_size >= sizeof(stk_sem_t))
279 {
280 const uint32_t effective_max = ((max_count == 0U) ? Semaphore::COUNT_MAX : max_count);
281 result = new (membuf->data) stk_sem_t(initial_count, effective_max);
282 }
283
284 return result;
285}
struct stk_sem_t stk_sem_t
Opaque handle to a Semaphore instance.
Definition stk_c.h:1056
static const uint16_t COUNT_MAX
Max count value supported.
stk_word_t data[(8U+((0) ? 1U :0U))]
Definition stk_c.h:1051

References stk::sync::Semaphore::COUNT_MAX, stk_sem_mem_t::data, and STK_ASSERT.

◆ stk_sem_destroy()

void stk_sem_destroy ( stk_sem_t * sem)

Destroy a Semaphore.

Parameters
[in]semSemaphore handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 287 of file stk_c_sync.cpp.

288{
289 if (sem != nullptr)
290 {
291 sem->~stk_sem_t();
292 }
293}

◆ stk_sem_get_count()

uint16_t stk_sem_get_count ( const stk_sem_t * sem)

Get the current counter value.

Parameters
[in]semSemaphore handle.
Returns
Advisory snapshot of the counter. May be stale by the time the caller acts on it.
Note
ISR-safe on targets where a 16-bit aligned read is atomic.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 316 of file stk_c_sync.cpp.

317{
318 STK_ASSERT(sem != nullptr);
319
320 return sem->handle.GetCount();
321}
uint16_t GetCount() const
Get current counter value.
Semaphore handle

References stk::sync::Semaphore::GetCount(), stk_sem_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_sem_signal()

void stk_sem_signal ( stk_sem_t * sem)

Signal/Release a semaphore resource.

Parameters
[in]semSemaphore handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 309 of file stk_c_sync.cpp.

310{
311 STK_ASSERT(sem != nullptr);
312
313 sem->handle.Signal();
314}
void Signal()
Post a signal (increment counter).

References stk_sem_t::handle, stk::sync::Semaphore::Signal(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_sem_trywait()

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.

Parameters
[in]semSemaphore handle.
Returns
True if a token was acquired, False if count was zero.
Warning
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 302 of file stk_c_sync.cpp.

303{
304 STK_ASSERT(sem != nullptr);
305
306 return sem->handle.TryWait();
307}
bool TryWait()
Poll the semaphore without blocking (decrement counter if available).

References stk_sem_t::handle, STK_ASSERT, and stk::sync::Semaphore::TryWait().

Here is the call graph for this function:

◆ stk_sem_wait()

bool stk_sem_wait ( stk_sem_t * sem,
stk_timeout_t timeout )

Wait for a semaphore resource.

Parameters
[in]semSemaphore handle.
[in]timeoutMax time to wait (ticks).
Returns
True if resource acquired, False on timeout.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 295 of file stk_c_sync.cpp.

296{
297 STK_ASSERT(sem != nullptr);
298
299 return sem->handle.Wait(timeout);
300}
bool Wait(Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal (decrement counter).

References stk_sem_t::handle, STK_ASSERT, and stk::sync::Semaphore::Wait().

Here is the call graph for this function:

◆ stk_sleep()

void stk_sleep ( stk_timeout_t ticks)

Put current task to sleep (non-HRT kernels only).

Parameters
[in]ticksTicks to sleep.
Note
Unlike stk_delay_ms(), this function does not spin and allows the kernel to idle the CPU. When KERNEL_TICKLESS is active and all tasks are sleeping, the SysTick is suppressed and the CPU enters a low-power WFI state until the nearest wake-up deadline.
Unsupported in KERNEL_HRT mode; in HRT mode tasks sleep automatically according to their periodicity and workload, use stk_yield instead.
See also
stk_sleep_ms, stk_sleep_until, stk_ticks
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 626 of file stk_c.cpp.

626{ stk::Sleep(ticks); }
static void Sleep(Timeout tick_count)
Put calling process into a sleep state.
Definition stk_helper.h:364

References stk::Sleep().

Here is the call graph for this function:

◆ stk_sleep_cancel()

void stk_sleep_cancel ( stk_tid_t tid)

Cancel the sleep of a task, waking it immediately.

Parameters
[in]tidIdentifier of the task to wake (obtained from stk_tid() or stk_task_get_id()).
Note
No-op if the target task is not currently sleeping.
ISR-safe.
See also
stk_sleep, stk_sleep_ms, stk_sleep_until
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 630 of file stk_c.cpp.

630{ stk::SleepCancel(tid); }
static void SleepCancel(TId task_id)
Cancel sleep of the task.
Definition stk_helper.h:399

References stk::SleepCancel().

Here is the call graph for this function:

◆ stk_sleep_ms()

void stk_sleep_ms ( stk_timeout_t ms)

Put current task to sleep (non-HRT kernels only).

Parameters
[in]msMilliseconds to sleep.
Note
Unlike stk_delay_ms(), this function does not spin and allows the kernel to idle the CPU. When KERNEL_TICKLESS is active and all tasks are sleeping, the SysTick is suppressed and the CPU enters a low-power WFI state until the nearest wake-up deadline.
Unsupported in KERNEL_HRT mode; in HRT mode tasks sleep automatically according to their periodicity and workload, use stk_yield instead.
See also
stk_sleep, stk_sleep_until, stk_ticks
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 628 of file stk_c.cpp.

628{ stk::SleepMs(ms); }
static void SleepMs(Timeout ms)
Put calling process into a sleep state.
Definition stk_helper.h:377

References stk::SleepMs().

Here is the call graph for this function:

◆ stk_sleep_until()

bool stk_sleep_until ( stk_tick_t ts)

Put current task to sleep (non-HRT kernels only).

Parameters
[in]tsAbsolute time (timestamp), a deadline for a sleep period.
Returns
True if sleep succeeded, false otherwise.
Note
Unlike stk_delay_ms(), this function does not spin and allows the kernel to idle the CPU. When KERNEL_TICKLESS is active and all tasks are sleeping, the SysTick is suppressed and the CPU enters a low-power WFI state until the nearest wake-up deadline.
Unsupported in KERNEL_HRT mode; in HRT mode tasks sleep automatically according to their periodicity and workload, use stk_yield instead.
See also
stk_sleep, stk_sleep_ms, stk_ticks
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 629 of file stk_c.cpp.

629{ return stk::SleepUntil(ts); }
static bool SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
Definition stk_helper.h:389

References stk::SleepUntil().

Here is the call graph for this function:

◆ stk_spinlock_create()

stk_spinlock_t * stk_spinlock_create ( stk_spinlock_mem_t *const membuf,
uint32_t membuf_size )

Create a recursive SpinLock.

Parameters
[in]membufPointer to static memory container.
[in]membuf_sizeSize of the container (must be >= sizeof(stk_spinlock_mem_t)).
Returns
SpinLock handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 93 of file stk_c_sync.cpp.

94{
95 STK_ASSERT(membuf != nullptr);
96 STK_ASSERT(membuf_size >= sizeof(stk_spinlock_t));
97
98 stk_spinlock_t *result = nullptr;
99 if (membuf_size >= sizeof(stk_spinlock_t))
100 {
101 result = new (membuf->data) stk_spinlock_t();
102 }
103
104 return result;
105}
struct stk_spinlock_t stk_spinlock_t
Opaque handle to a SpinLock instance.
Definition stk_c.h:905
stk_word_t data[(1)]
Definition stk_c.h:900

References stk_spinlock_mem_t::data, and STK_ASSERT.

◆ stk_spinlock_destroy()

void stk_spinlock_destroy ( stk_spinlock_t * slock)

Destroy the SpinLock.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 107 of file stk_c_sync.cpp.

108{
109 if (slock != nullptr)
110 {
111 slock->~stk_spinlock_t();
112 }
113}

◆ stk_spinlock_lock()

void stk_spinlock_lock ( stk_spinlock_t * slock)

Acquire the SpinLock (recursive).

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 115 of file stk_c_sync.cpp.

116{
117 STK_ASSERT(slock != nullptr);
118 slock->handle.Lock();
119}
void Lock()
Acquire the lock.
sync::SpinLock handle

References stk_spinlock_t::handle, stk::sync::SpinLock::Lock(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_spinlock_trylock()

bool stk_spinlock_trylock ( stk_spinlock_t * slock)

Attempt to acquire the SpinLock immediately.

Returns
True if locked successfully, False otherwise.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 121 of file stk_c_sync.cpp.

122{
123 STK_ASSERT(slock != nullptr);
124 return slock->handle.TryLock();
125}
bool TryLock()
Attempt to acquire the lock without blocking.

References stk_spinlock_t::handle, STK_ASSERT, and stk::sync::SpinLock::TryLock().

Here is the call graph for this function:

◆ stk_spinlock_unlock()

void stk_spinlock_unlock ( stk_spinlock_t * slock)

Release the SpinLock.

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 127 of file stk_c_sync.cpp.

128{
129 STK_ASSERT(slock != nullptr);
130 slock->handle.Unlock();
131}
void Unlock()
Release the lock or decrement the recursion counter.

References stk_spinlock_t::handle, STK_ASSERT, and stk::sync::SpinLock::Unlock().

Here is the call graph for this function:

◆ stk_sys_timer_count()

stk_cycle_t stk_sys_timer_count ( void )

Get raw system timer counter value.

Returns
64-bit hardware counter value. Useful for sub-tick timing measurements.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 620 of file stk_c.cpp.

620{ return stk::GetSysTimerCount(); }
static Cycles GetSysTimerCount()
Get system timer count value.
Definition stk_helper.h:344

References stk::GetSysTimerCount().

Here is the call graph for this function:

◆ stk_sys_timer_frequency()

uint32_t stk_sys_timer_frequency ( void )

Get system timer frequency in Hz.

Returns
Timer frequency (Hz). Divide stk_sys_timer_count() differences by this value to obtain elapsed time in seconds.
Note
ISR-safe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 621 of file stk_c.cpp.

621{ return stk::GetSysTimerFrequency(); }
static uint32_t GetSysTimerFrequency()
Get system timer frequency.
Definition stk_helper.h:353

References stk::GetSysTimerFrequency().

Here is the call graph for this function:

◆ stk_task_create_privileged()

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.

Parameters
[in]entryTask entry function.
[in]argArgument passed to entry function.
[in]stackPointer to stack buffer (array of stk_word_t).
[in]stack_sizeNumber of elements (words) in the stack buffer.
Returns
Task handle (static storage in static kernels, heap in dynamic).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 544 of file stk_c.cpp.

548{
549 STK_ASSERT(entry != nullptr);
550 STK_ASSERT(stack != nullptr);
551 STK_ASSERT(stack_size != 0);
552
553 return AllocateTask(entry, arg, stack, stack_size, ACCESS_PRIVILEGED);
554}
static stk_task_t * AllocateTask(stk_task_entry_t entry, void *arg, stk_word_t *stack, uint32_t stack_size, EAccessMode amode)
Definition stk_c.cpp:264
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
Definition stk_common.h:34

References stk::ACCESS_PRIVILEGED, AllocateTask(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_task_create_user()

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.

Parameters
[in]entryTask entry function.
[in]argArgument passed to entry function.
[in]stackPointer to stack buffer (array of stk_word_t).
[in]stack_sizeNumber of elements (words) in the stack buffer.
Returns
Task handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 556 of file stk_c.cpp.

560{
561 STK_ASSERT(entry != nullptr);
562 STK_ASSERT(stack != nullptr);
563 STK_ASSERT(stack_size != 0);
564
565 return AllocateTask(entry, arg, stack, stack_size, ACCESS_USER);
566}
@ ACCESS_USER
Unprivileged access mode (access to some hardware is restricted, see CPU manual for details).
Definition stk_common.h:33

References stk::ACCESS_USER, AllocateTask(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_task_destroy()

void stk_task_destroy ( stk_task_t * tsk)

Destroy dynamically created task object.

Parameters
[in]tskTask handle.
Note
Only valid for tasks created with dynamic creation functions. Task must no longer be scheduled (must have exited or been removed).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 605 of file stk_c.cpp.

606{
607 STK_ASSERT(tsk != nullptr);
608
609 FreeTask(tsk);
610}
static void FreeTask(const stk_task_t *tsk)
Definition stk_c.cpp:290

References FreeTask(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_task_get_id()

stk_tid_t stk_task_get_id ( const stk_task_t * tsk)

Get the unique identifier of a task.

Parameters
[in]tskTask handle.
Returns
Task identifier (stk_tid_t). Equivalent to the value stk_tid() returns when called from within that task.
Note
ISR-safe.
See also
stk_tid
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 598 of file stk_c.cpp.

599{
600 STK_ASSERT(tsk != nullptr);
601
602 return tsk->handle.GetId();
603}
TId GetId() const
Get task Id set by application.
Definition stk_helper.h:234

References stk::ITask::GetId(), stk_task_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_task_get_name()

const char * stk_task_get_name ( const stk_task_t * tsk)

Get human-readable task name previously set with stk_task_set_name().

Parameters
[in]tskTask handle.
Returns
Null-terminated name string, or NULL if not set.
Note
ISR-safe (reads a stored pointer, no kernel call).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 591 of file stk_c.cpp.

592{
593 STK_ASSERT(tsk != nullptr);
594
595 return tsk->handle.GetTraceName();
596}
const char * GetTraceName() const override
Get task trace name set by application.
Definition stk_c.cpp:90

References TaskWrapper::GetTraceName(), stk_task_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_task_set_name()

void stk_task_set_name ( stk_task_t * tsk,
const char * tname )

Assign human-readable task name (for tracing/debugging).

Parameters
[in]tskTask handle.
[in]tnameNull-terminated string (may be NULL).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 584 of file stk_c.cpp.

585{
586 STK_ASSERT(tsk != nullptr);
587
588 tsk->handle.SetName(tname);
589}
void SetName(const char *tname)
Definition stk_c.cpp:109

References stk_task_t::handle, TaskWrapper::SetName(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_task_set_priority()

void stk_task_set_priority ( stk_task_t * tsk,
uint8_t priority )

Set task priority (used only by Fixed Priority scheduler).

Parameters
[in]tskTask handle.
[in]priorityPriority level [0 = lowest … 31 = highest].
Note
Must be called before adding task to kernel.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 575 of file stk_c.cpp.

576{
577 STK_ASSERT(priority <= 31U);
578
579 const stk_weight_t weight = static_cast<stk_weight_t>(priority);
580
581 stk_task_set_weight(tsk, weight);
582}
void stk_task_set_weight(stk_task_t *tsk, stk_weight_t weight)
Set task weight (used only by Smooth Weighted Round Robin).
Definition stk_c.cpp:568
int32_t stk_weight_t
Task weight value.
Definition stk_c.h:122

References STK_ASSERT, and stk_task_set_weight().

Here is the call graph for this function:

◆ 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).

Parameters
[in]tskTask handle.
[in]weightPositive weight value (recommended 1–16777215).
Note
Must be called before adding task to kernel.
See also
SwitchStrategySmoothWeightedRoundRobin.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 568 of file stk_c.cpp.

569{
570 STK_ASSERT(tsk != nullptr);
571
572 tsk->handle.SetWeight(weight);
573}
void SetWeight(Weight weight)
Definition stk_c.cpp:108

References stk_task_t::handle, TaskWrapper::SetWeight(), and STK_ASSERT.

Referenced by stk_task_set_priority().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stk_tick_resolution()

uint32_t stk_tick_resolution ( void )

Returns how many microseconds correspond to one kernel tick.

Returns
Tick resolution in microseconds.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 617 of file stk_c.cpp.

617{ return stk::GetTickResolution(); }
static uint32_t GetTickResolution()
Get number of microseconds in one tick.
Definition stk_helper.h:253

References stk::GetTickResolution().

Referenced by stk_ms_from_ticks().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stk_ticks()

stk_tick_t stk_ticks ( void )

Returns number of ticks elapsed since kernel start.

Returns
Tick count (monotonically increasing).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 616 of file stk_c.cpp.

616{ return stk::GetTicks(); }
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:319

References stk::GetTicks().

Here is the call graph for this function:

◆ stk_ticks_from_ms()

stk_tick_t stk_ticks_from_ms ( stk_time_t msec)

Get ticks from milliseconds using current kernel tick resolution.

Parameters
[in]msecMilliseconds to convert.
Returns
Ticks.
Note
Equivalent to stk::GetTicksFromMsec(msec). Requires the kernel to be initialized before calling (stk_tick_resolution() must return a valid non-zero value).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 619 of file stk_c.cpp.

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.
Definition stk_c.h:629

References stk::GetTickResolution(), and stk_ticks_from_ms_r().

Here is the call graph for this function:

◆ stk_ticks_from_ms_r()

stk_tick_t stk_ticks_from_ms_r ( stk_time_t msec,
uint32_t resolution )
inlinestatic

Get ticks from milliseconds using an explicit tick resolution.

Parameters
[in]msecMilliseconds to convert.
[in]resolutionMicroseconds per tick (see stk_tick_resolution()).
Returns
Ticks.
Note
Equivalent to stk::GetTicksFromMsec(msec, resolution). Use this overload when the resolution is already cached to avoid a repeated call to stk_tick_resolution().
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 629 of file stk_c.h.

630{
631 stk_time_t result = 0LL;
632
633 if (resolution != 0U)
634 {
635 const stk_time_t total_scaled = msec * 1000LL;
636 result = total_scaled / STK_STATIC_CAST(stk_time_t, resolution);
637 }
638
639 return STK_STATIC_CAST(stk_tick_t, result);
640}

References STK_STATIC_CAST.

Referenced by stk_ticks_from_ms().

Here is the caller graph for this function:

◆ stk_tid()

stk_tid_t stk_tid ( void )

Returns current task/thread ID (the value set by stk_task_set_id).

Returns
Task identifier (0 if not set).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 615 of file stk_c.cpp.

615{ return stk::GetTid(); }
static TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:243

References stk::GetTid().

Here is the call graph for this function:

◆ stk_time_now_ms()

stk_time_t stk_time_now_ms ( void )

Returns current time in milliseconds since kernel start.

Returns
Time in milliseconds.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 618 of file stk_c.cpp.

618{ return stk::GetTimeNowMs(); }
static Time GetTimeNowMs()
Get current time in milliseconds since kernel start.
Definition stk_helper.h:330

References stk::GetTimeNowMs().

Here is the call graph for this function:

◆ stk_tls_get()

void * stk_tls_get ( void )

Get thread-local pointer (platform-specific slot).

Returns
Pointer previously stored with stk_tls_set() (NULL if never set).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

◆ stk_tls_set()

void stk_tls_set ( void * ptr)

Set thread-local pointer.

Parameters
[in]ptrPointer value to store for the current task/thread.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

◆ stk_yield()

void stk_yield ( void )

Voluntarily give up CPU to another ready task (cooperative yield).

Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 631 of file stk_c.cpp.

631{ stk::Yield(); }
static void Yield()
Notify scheduler to switch to the next runnable task.
Definition stk_helper.h:408

References stk::Yield().

Here is the call graph for this function: