SuperTinyKernel™ RTOS 1.08.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...

Collaboration diagram for STK C API:

Namespaces

namespace  stk
 Namespace of STK package.

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_fastmutex_mem_t
 Opaque memory container for a FastMutex 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...
struct  stk_barrier_mem_t
 Opaque memory container for a Barrier instance. More...

Macros

#define STK_C_VERSION   (0x20261004)
 Interface version.
#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_DEFAULT_CS_SESSION   (0U)
 Default session value for stk_critical_section_enter_ex()/stk_critical_section_exit_ex(), letting the call auto-detect the calling context's privilege level.
#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_FASTMUTEX_IMPL_SIZE   (9U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))
 A memory size (multiples of stk_word_t) required for FastMutex instance.
#define STK_SPINLOCK_IMPL_SIZE   (6)
 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_CANCELED   (0x80000008U)
#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   (6U + (2U * STK_CV_IMPL_SIZE) + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))
 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.
#define STK_BARRIER_IMPL_SIZE   (STK_MUTEX_IMPL_SIZE + STK_CV_IMPL_SIZE + 4U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))
 A memory size (multiples of stk_word_t) required for Barrier 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_wait_result_t stk_wait_result_t
 Outcome of a cancellable, timed kernel wait (see stk_cv_wait_ex(), stk_mutex_timed_lock_ex(), stk_sem_wait_ex(), ...).
typedef enum stk_kernel_state_t stk_kernel_state_t
 Kernel state.
typedef struct stk_event_overrider_t stk_event_overrider_t
typedef uint8_t stk_cs_session_t
 Session of Critical Section.
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_fastmutex_mem_t stk_fastmutex_mem_t
 Opaque memory container for a FastMutex instance.
typedef struct stk_fastmutex_t stk_fastmutex_t
 Opaque handle to a FastMutex 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.
typedef struct stk_barrier_mem_t stk_barrier_mem_t
 Opaque memory container for a Barrier instance.
typedef struct stk_barrier_t stk_barrier_t
 Opaque handle to a Barrier instance.
typedef enum stk_barrier_result_t stk_barrier_result_t
 Outcome of a stk_barrier_wait_ex() call.

Enumerations

enum  stk_wait_result_t {
  STK_WAIT_RESULT_FAIL = -1 ,
  STK_WAIT_RESULT_SIGNAL = 0 ,
  STK_WAIT_RESULT_TIMEOUT = 1 ,
  STK_WAIT_RESULT_CANCELED = 2
}
 Outcome of a cancellable, timed kernel wait (see stk_cv_wait_ex(), stk_mutex_timed_lock_ex(), stk_sem_wait_ex(), ...). More...
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...
enum  stk_barrier_result_t {
  STK_BARRIER_RELEASED = 0 ,
  STK_BARRIER_LAST_ARRIVAL = 1 ,
  STK_BARRIER_CANCELED = 2
}
 Outcome of a stk_barrier_wait_ex() call. More...

Functions

stk_kernel_t * stk_kernel_create (uint8_t core_nr)
 Create kernel.
stk::IKernel * stk_kernel_get_instance (uint8_t core_nr)
 Get the underlying C++ stk::IKernel object for a given core.
void stk_kernel_init (stk_kernel_t *k, uint32_t tick_period_us)
 Initialize kernel with given tick period.
void stk_kernel_add_task (stk_kernel_t *k, stk_task_t *tsk)
 Add task to non-HRT kernel (static or dynamic).
void stk_kernel_add_task_hrt (stk_kernel_t *k, stk_task_t *tsk, int32_t periodicity_ticks, int32_t deadline_ticks, int32_t start_delay_ticks)
 Add task with HRT timing parameters (HRT kernels only).
void stk_kernel_remove_task (stk_kernel_t *k, stk_task_t *tsk)
 Remove finished task from dynamic kernel.
void stk_kernel_start (stk_kernel_t *k)
 Start the scheduler - never returns.
stk_kernel_state_t stk_kernel_get_state (const stk_kernel_t *k)
 Get state of the scheduler.
bool stk_kernel_is_schedulable (const stk_kernel_t *k)
 Test whether currently configured task set is schedulable.
bool stk_kernel_is_started (const stk_kernel_t *k)
 Check whether the scheduler is currently running (first task switch has occurred).
void stk_kernel_schedule_task_removal (stk_kernel_t *k, stk_task_t *task)
 Schedule removal of a running task from the kernel on the next tick.
void stk_kernel_suspend_task (stk_kernel_t *k, stk_task_t *task, bool *suspended)
 Suspend a task (prevent it from being scheduled).
void stk_kernel_resume_task (stk_kernel_t *k, stk_task_t *task)
 Resume a previously suspended task.
stk_timeout_t stk_kernel_suspend (stk_kernel_t *k)
 Suspend scheduling (tickless idle entry point).
void stk_kernel_resume (stk_kernel_t *k, stk_timeout_t elapsed_ticks)
 Resume scheduling after a prior stk_kernel_suspend() call.
size_t stk_kernel_enumerate_tasks (stk_kernel_t *k, stk_task_t **tasks, size_t max_count)
 Enumerate all currently active tasks.
void stk_kernel_process_tick (stk_kernel_t *k)
 Manually deliver one scheduler tick to the kernel.
void stk_kernel_process_hard_fault (stk_kernel_t *k)
 Trigger a kernel hard fault (safe-state handler).
void stk_kernel_set_event_overrider (stk_kernel_t *k, stk_event_overrider_t *overrider)
 Install a platform event overrider on the kernel.
stk_task_t * stk_task_create_privileged (stk_task_entry_t entry, void *arg, stk_word_t *stack, uint32_t stack_size)
 Create privileged-mode (kernel-mode) task.
stk_task_t * stk_task_create_user (stk_task_entry_t entry, void *arg, stk_word_t *stack, uint32_t stack_size)
 Create user-mode task.
void stk_task_set_weight (stk_task_t *tsk, stk_weight_t weight)
 Set task weight (used only by Smooth Weighted Round Robin).
void stk_task_set_priority (stk_task_t *tsk, uint8_t priority)
 Set task priority (used only by Fixed Priority scheduler).
void stk_task_set_name (stk_task_t *tsk, const char *tname)
 Assign human-readable task name (for tracing/debugging).
const char * stk_task_get_name (const stk_task_t *tsk)
 Get human-readable task name previously set with stk_task_set_name().
stk_tid_t stk_task_get_id (const stk_task_t *tsk)
 Get the unique identifier of a task.
stk::ITask * stk_task_get_instance (stk_task_t *tsk)
 Get the underlying C++ stk::ITask object wrapped by a stk_task_t handle.
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.
stk_timeout_t stk_ticks_from_ms_clamped_to_timeout (stk_timeout_t ms)
 Get ticks from milliseconds using current kernel tick resolution, clamped to the maximum value representable by stk_timeout_t (STK_WAIT_INFINITE).
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.
stk_cs_session_t stk_critical_section_enter_ex (stk_cs_session_t ses)
 Enter global critical section - disable context switches on current core.
void stk_critical_section_exit_ex (stk_cs_session_t ses)
 Leave global critical section - re-enable context switches.
void stk_critical_section_enter ()
 Enter global critical section - disable context switches on current core.
void stk_critical_section_exit ()
 Leave global critical section - re-enable context switches.
stk_mutex_t * stk_mutex_create (stk_mutex_mem_t *const membuf)
 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_wait_result_t stk_mutex_timed_lock_ex (stk_mutex_t *mtx, stk_timeout_t timeout)
 Try to lock the mutex with a timeout, preserving the full outcome.
stk::sync::Mutex * stk_mutex_get_instance (stk_mutex_t *mtx)
 Get the underlying C++ stk::sync::Mutex object wrapped by a stk_mutex_t handle.
stk_fastmutex_t * stk_fastmutex_create (stk_fastmutex_mem_t *const membuf)
 Create a FastMutex (using provided memory).
void stk_fastmutex_destroy (stk_fastmutex_t *mtx)
 Destroy a FastMutex.
void stk_fastmutex_lock (stk_fastmutex_t *mtx)
 Lock the mutex. Blocks until available.
bool stk_fastmutex_trylock (stk_fastmutex_t *mtx)
 Try locking the mutex. Does not block if already locked.
void stk_fastmutex_unlock (stk_fastmutex_t *mtx)
 Unlock the mutex.
bool stk_fastmutex_timed_lock (stk_fastmutex_t *mtx, stk_timeout_t timeout)
 Try to lock the mutex with a timeout.
stk_wait_result_t stk_fastmutex_timed_lock_ex (stk_fastmutex_t *mtx, stk_timeout_t timeout)
 Try to lock the FastMutex with a timeout, preserving the full outcome.
stk::sync::FastMutex * stk_fastmutex_get_instance (stk_fastmutex_t *mtx)
 Get the underlying C++ stk::sync::FastMutex object wrapped by a stk_fastmutex_t handle.
stk_spinlock_t * stk_spinlock_create (stk_spinlock_mem_t *const membuf)
 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::sync::SpinLock * stk_spinlock_get_instance (stk_spinlock_t *slock)
 Get the underlying C++ stk::sync::SpinLock object wrapped by a stk_spinlock_t handle.
stk_cv_t * stk_cv_create (stk_cv_mem_t *const membuf)
 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.
stk_wait_result_t stk_cv_wait_ex (stk_cv_t *cv, stk_mutex_t *mtx, stk_timeout_t timeout)
 Wait for a signal on the condition variable, preserving the full outcome.
bool stk_cv_wait_fastmutex (stk_cv_t *cv, stk_fastmutex_t *mtx, stk_timeout_t timeout)
 Wait for a signal on the condition variable, protected by a FastMutex.
stk_wait_result_t stk_cv_wait_ex_fastmutex (stk_cv_t *cv, stk_fastmutex_t *mtx, stk_timeout_t timeout)
 Wait for a signal on the condition variable protected by a FastMutex, preserving the full outcome.
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::sync::ConditionVariable * stk_cv_get_instance (stk_cv_t *cv)
 Get the underlying C++ stk::sync::ConditionVariable object wrapped by a stk_cv_t handle.
stk_event_t * stk_event_create (stk_event_mem_t *const membuf, 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.
stk_wait_result_t stk_event_wait_ex (stk_event_t *ev, stk_timeout_t timeout)
 Wait for the event to become signaled, preserving the full outcome.
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::sync::Event * stk_event_get_instance (stk_event_t *ev)
 Get the underlying C++ stk::sync::Event object wrapped by a stk_event_t handle.
stk_sem_t * stk_sem_create (stk_sem_mem_t *const membuf, 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.
stk_wait_result_t stk_sem_wait_ex (stk_sem_t *sem, stk_timeout_t timeout)
 Wait for a semaphore resource, preserving the full outcome.
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.
bool stk_sem_trysignal (stk_sem_t *sem)
 Try to signal/release a semaphore resource without exceeding max_count.
uint16_t stk_sem_get_count (const stk_sem_t *sem)
 Get the current counter value.
stk::sync::Semaphore * stk_sem_get_instance (stk_sem_t *sem)
 Get the underlying C++ stk::sync::Semaphore object wrapped by a stk_sem_t handle.
static bool stk_ef_is_error (uint32_t result)
 Returns true if a value returned by stk_ef_set(), stk_ef_clear(), stk_ef_wait(), or stk_ef_trywait() is an error sentinel (bit 31 set).
stk_ef_t * stk_ef_create (stk_ef_mem_t *const membuf, uint32_t 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::sync::EventFlags * stk_ef_get_instance (stk_ef_t *ef)
 Get the underlying C++ stk::sync::EventFlags object wrapped by a stk_ef_t handle.
stk_pipe_t * stk_pipe_create (stk_pipe_mem_t *const membuf, 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.
stk_wait_result_t stk_pipe_write_ex (stk_pipe_t *pipe, const void *data, stk_timeout_t timeout)
 Write a single element to the pipe, preserving the full outcome.
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.
stk_wait_result_t stk_pipe_read_ex (stk_pipe_t *pipe, void *data, stk_timeout_t timeout)
 Read a single element from the pipe, preserving the full outcome.
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.
stk_wait_result_t stk_pipe_write_bulk_ex (stk_pipe_t *pipe, const void *src, size_t count, size_t *written, stk_timeout_t timeout)
 Write multiple elements to the pipe, preserving the full outcome.
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.
stk_wait_result_t stk_pipe_read_bulk_ex (stk_pipe_t *pipe, void *dst, size_t count, size_t *read_count, stk_timeout_t timeout)
 Read multiple elements from the pipe, preserving the full outcome.
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.
stk_wait_result_t stk_pipe_read_bulk_triggered_ex (stk_pipe_t *pipe, void *dst, size_t trigger, size_t max_count, size_t *read_count, stk_timeout_t timeout)
 Read at least trigger elements, then drain up to max_count, preserving the full outcome.
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::sync::Pipe * stk_pipe_get_instance (stk_pipe_t *pipe)
 Get the underlying C++ stk::sync::Pipe object wrapped by a stk_pipe_t handle.
stk_msgq_t * stk_msgq_create (stk_msgq_mem_t *const membuf, 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.
stk_wait_result_t stk_msgq_put_ex (stk_msgq_t *mq, const void *msg, stk_timeout_t timeout)
 Put a message into the queue, preserving the full outcome.
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).
stk_wait_result_t stk_msgq_putfront_ex (stk_msgq_t *mq, const void *msg, stk_timeout_t timeout)
 Put a message into the front of the queue, preserving the full outcome.
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.
stk_wait_result_t stk_msgq_get_ex (stk_msgq_t *mq, void *msg, stk_timeout_t timeout)
 Get a message from the queue, preserving the full outcome.
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.
stk_wait_result_t stk_msgq_peek_ex (stk_msgq_t *mq, void *msg, stk_timeout_t timeout)
 Peek at the next message without removing it, preserving the full outcome.
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.
stk_wait_result_t stk_msgq_peekfront_ex (stk_msgq_t *mq, void *msg, stk_timeout_t timeout)
 Peek at the front-inserted message without removing it, preserving the full outcome.
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::sync::MessageQueue * stk_msgq_get_instance (stk_msgq_t *mq)
 Get the underlying C++ stk::sync::MessageQueue object wrapped by a stk_msgq_t handle.
stk_rwmutex_t * stk_rwmutex_create (stk_rwmutex_mem_t *const membuf)
 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.
stk_wait_result_t stk_rwmutex_timed_read_lock_ex (stk_rwmutex_t *rw, stk_timeout_t timeout)
 Try to acquire the read lock with a timeout, preserving the full outcome.
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.
stk_wait_result_t stk_rwmutex_timed_lock_ex (stk_rwmutex_t *rw, stk_timeout_t timeout)
 Try to acquire the write lock with a timeout, preserving the full outcome.
void stk_rwmutex_unlock (stk_rwmutex_t *rw)
 Release the exclusive writer lock.
stk::sync::RWMutex * stk_rwmutex_get_instance (stk_rwmutex_t *rw)
 Get the underlying C++ stk::sync::RWMutex object wrapped by a stk_rwmutex_t handle.
stk_barrier_t * stk_barrier_create (stk_barrier_mem_t *const membuf, uint32_t count)
 Create a Barrier (using provided memory).
void stk_barrier_destroy (stk_barrier_t *barrier)
 Destroy a Barrier.
bool stk_barrier_wait (stk_barrier_t *barrier)
 Block the calling task until count tasks have called stk_barrier_wait().
stk_barrier_result_t stk_barrier_wait_ex (stk_barrier_t *barrier)
 Block the calling task until count tasks have arrived, preserving the full outcome.
uint32_t stk_barrier_get_threshold (const stk_barrier_t *barrier)
 Get the number of tasks required to trip the barrier.
stk::sync::Barrier * stk_barrier_get_instance (stk_barrier_t *barrier)
 Get the underlying C++ stk::sync::Barrier object wrapped by a stk_barrier_t handle.

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 226 of file stk_c.h.

◆ __stk_c_stack

#define __stk_c_stack

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

Definition at line 217 of file stk_c.h.

◆ STK_ALIGN_MASK

#define STK_ALIGN_MASK   (STK_ALIGN_SIZE - 1U)

Alignment mask.

Definition at line 174 of file stk_c.h.

Referenced by pthread_attr_setstack().

◆ STK_ALIGN_SIZE

#define STK_ALIGN_SIZE   sizeof(stk_word_t)

Memory buffer alignment.

Definition at line 170 of file stk_c.h.

◆ STK_BARRIER_IMPL_SIZE

#define STK_BARRIER_IMPL_SIZE   (STK_MUTEX_IMPL_SIZE + STK_CV_IMPL_SIZE + 4U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))

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

Note
Composed of one Mutex (STK_MUTEX_IMPL_SIZE), one ConditionVariable (STK_CV_IMPL_SIZE), three uint32_t counters (threshold, count, generation), plus Barrier's own debug name if enabled.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 2492 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 80 of file stk_c.h.

Referenced by stk::pthread::EnqueueReap(), stk::pthread::EnsureReaper(), pthread_create(), pthread_exit(), stk::pthread::ReaperEntry(), and stk_pthread_bind_kernel().

◆ 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 65 of file stk_c.h.

Referenced by SetEventOverrider(), stk_kernel_create(), stk_kernel_get_instance(), 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 57 of file stk_c.h.

◆ STK_C_VERSION

#define STK_C_VERSION   (0x20261004)

Interface version.

Definition at line 45 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 1178 of file stk_c.h.

◆ STK_DEFAULT_CS_SESSION

#define STK_DEFAULT_CS_SESSION   (0U)

Default session value for stk_critical_section_enter_ex()/stk_critical_section_exit_ex(), letting the call auto-detect the calling context's privilege level.

Definition at line 902 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:217
uintptr_t stk_word_t
CPU register type.
Definition stk_c.h:99

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 196 of file stk_c.h.

196#define STK_DEFINE_STACK_POOL(name, max_tasks, stack_size) \
197 static stk_word_t name[max_tasks][stack_size] __stk_c_stack

◆ STK_EF_ERROR_CANCELED

#define STK_EF_ERROR_CANCELED   (0x80000008U)

Wait was cancelled before the flag condition was met

Definition at line 1498 of file stk_c.h.

◆ STK_EF_ERROR_ISR

#define STK_EF_ERROR_ISR   (0x80000004U)

Wait called from an ISR with a blocking timeout

Definition at line 1497 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 1499 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 1495 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 1496 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 1513 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 1491 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 1490 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 1489 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 1289 of file stk_c.h.

◆ STK_FASTMUTEX_IMPL_SIZE

#define STK_FASTMUTEX_IMPL_SIZE   (9U + (STK_SYNC_DEBUG_NAMES ? 1U : 0U))

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

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

Definition at line 1037 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 205 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,
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:2031
stk_msgq_t * stk_msgq_create(stk_msgq_mem_t *const membuf, 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:2012
Opaque memory container for a MessageQueue instance.
Definition stk_c.h:2006

Definition at line 2031 of file stk_c.h.

◆ STK_MSGQ_IMPL_SIZE

#define STK_MSGQ_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 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 2002 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 957 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 166 of file stk_c.h.

◆ STK_PERIODICITY_DEFAULT

#define STK_PERIODICITY_DEFAULT   (1000U)

Default tick period (1 ms).

in microseconds

Definition at line 139 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:174

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,
s_pipe_buf, sizeof(s_pipe_buf),
MY_PIPE_CAP, MY_ELEM_SIZE);
stk_pipe_t * stk_pipe_create(stk_pipe_mem_t *const membuf, uint8_t *buf, uint32_t buf_size, size_t capacity, size_t element_size)
Create a Pipe (using provided memory).
#define STK_PIPE_BUF_SIZE(capacity, element_size)
Compute the required data-buffer size (in bytes) for a Pipe.
Definition stk_c.h:1652
#define __stk_c_aligned
Memory buffer alignment attribute.
Definition stk_c.h:226
struct stk_pipe_t stk_pipe_t
Opaque handle to a Pipe instance.
Definition stk_c.h:1633
Opaque memory container for a Pipe control-block.
Definition stk_c.h:1627

Definition at line 1652 of file stk_c.h.

1652#define STK_PIPE_BUF_SIZE(capacity, element_size) \
1653 ((((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 1623 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 2358 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 1380 of file stk_c.h.

◆ STK_SPINLOCK_IMPL_SIZE

#define STK_SPINLOCK_IMPL_SIZE   (6)

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 1127 of file stk_c.h.

◆ STK_STACK_MEMORY_ALIGN

#define STK_STACK_MEMORY_ALIGN   (4U)

Stack memory alignment.

Definition at line 185 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 88 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 74 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 877 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 882 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 162 of file stk_c.h.

Typedef Documentation

◆ stk_barrier_mem_t

typedef struct stk_barrier_mem_t stk_barrier_mem_t

Opaque memory container for a Barrier instance.

◆ stk_barrier_result_t

Outcome of a stk_barrier_wait_ex() call.

Note
It is a direct match for stk::sync::Barrier::EResult.

◆ stk_barrier_t

typedef struct stk_barrier_t stk_barrier_t

Opaque handle to a Barrier instance.

Definition at line 2502 of file stk_c.h.

◆ stk_cs_session_t

typedef uint8_t stk_cs_session_t

Session of Critical Section.

Opaque token returned by stk_critical_section_enter_ex() that carries the state which must be restored by the matching stk_critical_section_exit_ex() (e.g. the previous interrupt masking level, such as BASEPRI on ARM Cortex-M, and the privilege-level handling path that was selected on entry).

Note
Do not modify or interpret the value, pass it unchanged to stk_critical_section_exit_ex().
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 897 of file stk_c.h.

◆ 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 1188 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 123 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 1523 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 1299 of file stk_c.h.

◆ stk_fastmutex_mem_t

typedef struct stk_fastmutex_mem_t stk_fastmutex_mem_t

Opaque memory container for a FastMutex instance.

◆ stk_fastmutex_t

typedef struct stk_fastmutex_t stk_fastmutex_t

Opaque handle to a FastMutex instance.

Note
Non-recursive (binary) mutex: a task that already owns it must not lock it again. Doing so is an unrecoverable contract violation: the kernel panics with KERNEL_PANIC_SYNC_DEADLOCK in all build configurations. Use stk_mutex_t if recursive locking is needed.

Definition at line 1051 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 131 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 2012 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 967 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 1633 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 2368 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 1390 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 1138 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 148 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 135 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 108 of file stk_c.h.

◆ stk_tid_t

Task id.

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

Definition at line 103 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 113 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 118 of file stk_c.h.

◆ stk_wait_result_t

Outcome of a cancellable, timed kernel wait (see stk_cv_wait_ex(), stk_mutex_timed_lock_ex(), stk_sem_wait_ex(), ...).

Note
It is a direct match for stk::EWaitResult.

◆ 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 127 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 99 of file stk_c.h.

Enumeration Type Documentation

◆ stk_barrier_result_t

Outcome of a stk_barrier_wait_ex() call.

Note
It is a direct match for stk::sync::Barrier::EResult.
Enumerator
STK_BARRIER_RELEASED 

Released because the barrier tripped; this task was not the last arrival.

STK_BARRIER_LAST_ARRIVAL 

This task was the last arrival and tripped the barrier.

STK_BARRIER_CANCELED 

Wait was cancelled before the barrier tripped; this task's arrival was rolled back and does not count toward the generation it was waiting on.

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

Definition at line 2520 of file stk_c.h.

2520 {
stk_barrier_result_t
Outcome of a stk_barrier_wait_ex() call.
Definition stk_c.h:2520
@ STK_BARRIER_CANCELED
Definition stk_c.h:2523
@ STK_BARRIER_RELEASED
Released because the barrier tripped; this task was not the last arrival.
Definition stk_c.h:2521
@ STK_BARRIER_LAST_ARRIVAL
This task was the last arrival and tripped the barrier.
Definition stk_c.h:2522

◆ 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 394 of file stk_c.h.

394 {
stk_kernel_state_t
Kernel state.
Definition stk_c.h:394
@ STK_KERNEL_STATE_INACTIVE
not ready, stk_kernel_init() must be called
Definition stk_c.h:395
@ STK_KERNEL_STATE_READY
ready to start, stk_kernel_start() must be called
Definition stk_c.h:396
@ STK_KERNEL_STATE_RUNNING
initialized and running, stk_kernel_start() was called successfully
Definition stk_c.h:397
@ STK_KERNEL_STATE_SUSPENDED
scheduling suspended via stk_kernel_service_suspend() (tickless idle)
Definition stk_c.h:398

◆ stk_wait_result_t

Outcome of a cancellable, timed kernel wait (see stk_cv_wait_ex(), stk_mutex_timed_lock_ex(), stk_sem_wait_ex(), ...).

Note
It is a direct match for stk::EWaitResult.
Enumerator
STK_WAIT_RESULT_FAIL 

The kernel returned an error without actually waiting.

STK_WAIT_RESULT_SIGNAL 

The wake was caused by a signal.

STK_WAIT_RESULT_TIMEOUT 

The wake was caused by a timeout expiry.

STK_WAIT_RESULT_CANCELED 

The wait was cancelled by another task, independent of signal/timeout.

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

Definition at line 153 of file stk_c.h.

153 {
stk_wait_result_t
Outcome of a cancellable, timed kernel wait (see stk_cv_wait_ex(), stk_mutex_timed_lock_ex(),...
Definition stk_c.h:153
@ STK_WAIT_RESULT_TIMEOUT
The wake was caused by a timeout expiry.
Definition stk_c.h:156
@ STK_WAIT_RESULT_SIGNAL
The wake was caused by a signal.
Definition stk_c.h:155
@ STK_WAIT_RESULT_CANCELED
The wait was cancelled by another task, independent of signal/timeout.
Definition stk_c.h:157
@ STK_WAIT_RESULT_FAIL
The kernel returned an error without actually waiting.
Definition stk_c.h:154

Function Documentation

◆ stk_barrier_create()

stk_barrier_t * stk_barrier_create ( stk_barrier_mem_t *const membuf,
uint32_t count )

Create a Barrier (using provided memory).

Parameters
[in]membufPointer to static memory container.
[in]countNumber of tasks that must call stk_barrier_wait() before any of them is released. Must not be 0.
Returns
Barrier handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1162 of file stk_c_sync.cpp.

1164{
1165 STK_ASSERT(membuf != nullptr);
1166 STK_ASSERT(count != 0U);
1167
1168 stk_barrier_t *result = nullptr;
1169 if ((membuf != nullptr) && (count != 0U))
1170 {
1171 result = ConstructIn<stk_barrier_t>(*membuf, count);
1172 }
1173
1174 return result;
1175}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:516
static T * ConstructIn(Mem &mem, Args &&... args)
Construct object T in-place inside a C memory container.
Definition stk_c.h:2581

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_barrier_destroy()

void stk_barrier_destroy ( stk_barrier_t * barrier)

Destroy a Barrier.

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

Definition at line 1177 of file stk_c_sync.cpp.

1178{
1179 if (barrier != nullptr)
1180 {
1181 barrier->~stk_barrier_t();
1182 }
1183}

◆ stk_barrier_get_instance()

stk::sync::Barrier * stk_barrier_get_instance ( stk_barrier_t * barrier)

Get the underlying C++ stk::sync::Barrier object wrapped by a stk_barrier_t handle.

Parameters
[in]barrierBarrier handle obtained via stk_barrier_create().
Returns
Pointer to the wrapped stk::sync::Barrier instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1215 of file stk_c_sync.cpp.

1216{
1217 STK_ASSERT(barrier != nullptr);
1218
1219 return &barrier->handle;
1220}

References stk_barrier_t::handle, and STK_ASSERT.

◆ stk_barrier_get_threshold()

uint32_t stk_barrier_get_threshold ( const stk_barrier_t * barrier)

Get the number of tasks required to trip the barrier.

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

Definition at line 1208 of file stk_c_sync.cpp.

1209{
1210 STK_ASSERT(barrier != nullptr);
1211
1212 return barrier->handle.GetThreshold();
1213}
uint32_t GetThreshold() const
Get the number of tasks required to trip the barrier.

References stk::sync::Barrier::GetThreshold(), stk_barrier_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_barrier_wait()

bool stk_barrier_wait ( stk_barrier_t * barrier)

Block the calling task until count tasks have called stk_barrier_wait().

Once the last task arrives, all currently waiting tasks are woken up and the barrier resets itself so it can be reused for the next round.

Parameters
[in]barrierBarrier handle.
Note
Cannot report a cancellation - returns False the same as a normal (non-last) release. Use stk_barrier_wait_ex() to tell the two apart.
Warning
ISR-unsafe.
Returns
True if the calling task was the last one to arrive (and thus released the others), False if the calling task was one of the released waiters.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1185 of file stk_c_sync.cpp.

1186{
1187 STK_ASSERT(barrier != nullptr);
1188
1189 return barrier->handle.Wait();
1190}
bool Wait()
Block the calling task until count tasks have called Wait().

References stk_barrier_t::handle, STK_ASSERT, and stk::sync::Barrier::Wait().

Here is the call graph for this function:

◆ stk_barrier_wait_ex()

stk_barrier_result_t stk_barrier_wait_ex ( stk_barrier_t * barrier)

Block the calling task until count tasks have arrived, preserving the full outcome.

Identical to stk_barrier_wait(), except the caller can distinguish a normal release, being the last arrival, and a cancellation.

Parameters
[in]barrierBarrier handle.
Returns
STK_BARRIER_LAST_ARRIVAL, STK_BARRIER_RELEASED, or STK_BARRIER_CANCELED.
Warning
ISR-unsafe.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1192 of file stk_c_sync.cpp.

1193{
1194 STK_ASSERT(barrier != nullptr);
1195
1196 stk_barrier_result_t result;
1197
1198 switch (barrier->handle.WaitEx())
1199 {
1201 case Barrier::BARRIER_CANCELED: result = STK_BARRIER_CANCELED; break;
1202 default: result = STK_BARRIER_RELEASED; break;
1203 }
1204
1205 return result;
1206}
@ BARRIER_LAST_ARRIVAL
This task was the last arrival and tripped the barrier.
EResult WaitEx()
Block the calling task until count tasks have called Wait(), preserving the full outcome.

References stk::sync::Barrier::BARRIER_CANCELED, stk::sync::Barrier::BARRIER_LAST_ARRIVAL, stk_barrier_t::handle, STK_ASSERT, STK_BARRIER_CANCELED, STK_BARRIER_LAST_ARRIVAL, STK_BARRIER_RELEASED, and stk::sync::Barrier::WaitEx().

Here is the call graph for this function:

◆ stk_critical_section_enter()

void stk_critical_section_enter ( )

Enter global critical section - disable context switches on current core.

Warning
Can be used from a Privileged thread ONLY. When called from a User thread the section cannot be left properly: the matching stk_critical_section_exit() has no session to restore, and in User privilege it is not permitted to clear the interrupt masking (e.g. BASEPRI on ARM Cortex-M) that was set on entry. Use stk_critical_section_enter_ex() / stk_critical_section_exit_ex() in code that may run in a User thread (e.g. shared library or middleware code).
Note
Misuse is caught by STK_ASSERT(IsPrivilegedContext()) when assertions are enabled; with assertions disabled the call is not checked and the behavior is undefined.
Supports nesting (number of enter calls must match number of exit calls).
See also
stk_critical_section_enter_ex
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 681 of file stk_c.cpp.

682{
684
686}
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:715
bool IsPrivilegedContext()
Check if caller context is Privileged.
static constexpr Session DEFAULT_SESSION
Default session value passed to Enter()/Exit() when the caller does not need to force a specific hand...
Definition stk_arch.h:478
static Session Enter(const Session ses=DEFAULT_SESSION)
Enter a critical section.

References stk::hw::CriticalSection::DEFAULT_SESSION, stk::hw::CriticalSection::Enter(), stk::hw::IsPrivilegedContext(), STK_ASSERT, and STK_UNUSED.

Here is the call graph for this function:

◆ stk_critical_section_enter_ex()

stk_cs_session_t stk_critical_section_enter_ex ( stk_cs_session_t ses)

Enter global critical section - disable context switches on current core.

Preferred API for entering a critical section. It works from both Privileged and User thread contexts: the returned session preserves the state of the entry, so that the matching stk_critical_section_exit_ex() can restore it correctly regardless of the privilege level the caller is running at.

Note
Supports nesting (number of enter calls must match number of exit calls). Every call must be paired with stk_critical_section_exit_ex() using the session returned by that very call, and nested sections must be left in reverse (LIFO) order.
Keep the section as short as possible: context switches on the current core are disabled until the matching exit.
Parameters
[in]sesSTK_DEFAULT_CS_SESSION to auto-detect the calling context's privilege level, or an explicit session value to force a specific handling path.
Returns
Session value that must be supplied to the matching stk_critical_section_exit_ex().
See also
stk_critical_section_exit_ex
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 671 of file stk_c.cpp.

672{
673 return hw::CriticalSection::Enter(ses);
674}

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

Here is the call graph for this function:

◆ stk_critical_section_exit()

void stk_critical_section_exit ( )

Leave global critical section - re-enable context switches.

Warning
Can be used from a Privileged thread ONLY, see the warning of stk_critical_section_enter(). Use stk_critical_section_exit_ex() in code that may run in a User thread.
Note
Must be called once for each previous stk_critical_section_enter().
See also
stk_critical_section_exit_ex
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 688 of file stk_c.cpp.

689{
691}
static void Exit(const Session ses=DEFAULT_SESSION)
Exit a critical section.

References stk::hw::CriticalSection::DEFAULT_SESSION, and stk::hw::CriticalSection::Exit().

Here is the call graph for this function:

◆ stk_critical_section_exit_ex()

void stk_critical_section_exit_ex ( stk_cs_session_t ses)

Leave global critical section - re-enable context switches.

Restores the state captured by the matching stk_critical_section_enter_ex().

Note
Must be called exactly once for each previous stk_critical_section_enter_ex(), with the session value returned by that call.
Parameters
[in]sesSession value returned by the matching stk_critical_section_enter_ex() call.
See also
stk_critical_section_enter_ex
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 676 of file stk_c.cpp.

677{
679}

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)

Create a Condition Variable (using provided memory).

Parameters
[in]membufPointer to static memory container.
Returns
CV handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 246 of file stk_c_sync.cpp.

247{
248 STK_ASSERT(membuf != nullptr);
249
250 stk_cv_t *result = nullptr;
251 if (membuf != nullptr)
252 {
253 result = ConstructIn<stk_cv_t>(*membuf);
254 }
255
256 return result;
257}

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ 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 259 of file stk_c_sync.cpp.

260{
261 if (cv != nullptr)
262 {
263 cv->~stk_cv_t();
264 }
265}

◆ stk_cv_get_instance()

stk::sync::ConditionVariable * stk_cv_get_instance ( stk_cv_t * cv)

Get the underlying C++ stk::sync::ConditionVariable object wrapped by a stk_cv_t handle.

Parameters
[in]cvCV handle obtained via stk_cv_create().
Returns
Pointer to the wrapped stk::sync::ConditionVariable instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 313 of file stk_c_sync.cpp.

314{
315 STK_ASSERT(cv != nullptr);
316
317 return &cv->handle;
318}
ConditionVariable handle

References stk_cv_t::handle, and STK_ASSERT.

◆ 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 306 of file stk_c_sync.cpp.

307{
308 STK_ASSERT(cv != nullptr);
309
310 cv->handle.NotifyAll();
311}
void NotifyAll()
Wake all waiting tasks.

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 299 of file stk_c_sync.cpp.

300{
301 STK_ASSERT(cv != nullptr);
302
303 cv->handle.NotifyOne();
304}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
True if signaled, False if the wait did not end in a signal (timeout or an externally cancelled wait).
Note
Collapses the distinction between timeout and cancellation. Use stk_cv_wait_ex() if the caller needs to tell them apart.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 267 of file stk_c_sync.cpp.

268{
269 STK_ASSERT(cv != nullptr);
270 STK_ASSERT(mtx != nullptr);
271
272 return cv->handle.Wait(mtx->handle, timeout);
273}
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_cv_wait_ex()

stk_wait_result_t stk_cv_wait_ex ( stk_cv_t * cv,
stk_mutex_t * mtx,
stk_timeout_t timeout )

Wait for a signal on the condition variable, preserving the full outcome.

Identical to stk_cv_wait(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool, so a cancellation can be distinguished from a timeout.

Parameters
[in]cvCV handle.
[in]mtxLocked mutex handle protecting the state.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, or STK_WAIT_RESULT_CANCELED.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 275 of file stk_c_sync.cpp.

276{
277 STK_ASSERT(cv != nullptr);
278 STK_ASSERT(mtx != nullptr);
279
280 return ToCWaitResult(cv->handle.WaitEx(mtx->handle, timeout));
281}
static stk_wait_result_t ToCWaitResult(EWaitResult wr)
EWaitResult WaitEx(IMutex &mutex, Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal, preserving the full wait outcome.

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

Here is the call graph for this function:

◆ stk_cv_wait_ex_fastmutex()

stk_wait_result_t stk_cv_wait_ex_fastmutex ( stk_cv_t * cv,
stk_fastmutex_t * mtx,
stk_timeout_t timeout )

Wait for a signal on the condition variable protected by a FastMutex, preserving the full outcome.

Identical to stk_cv_wait_fastmutex(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool, so a cancellation can be distinguished from a timeout.

Parameters
[in]cvCV handle.
[in]mtxLocked FastMutex handle protecting the state.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, or STK_WAIT_RESULT_CANCELED.
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 291 of file stk_c_sync.cpp.

292{
293 STK_ASSERT(cv != nullptr);
294 STK_ASSERT(mtx != nullptr);
295
296 return ToCWaitResult(cv->handle.WaitEx(mtx->handle, timeout));
297}

References stk_cv_t::handle, stk_fastmutex_t::handle, STK_ASSERT, ToCWaitResult(), and stk::sync::ConditionVariable::WaitEx().

Here is the call graph for this function:

◆ stk_cv_wait_fastmutex()

bool stk_cv_wait_fastmutex ( stk_cv_t * cv,
stk_fastmutex_t * mtx,
stk_timeout_t timeout )

Wait for a signal on the condition variable, protected by a FastMutex.

Same as stk_cv_wait(), but the lock protecting the state is a stk_fastmutex_t. Atomically releases the mutex and suspends the task. The mutex is re-acquired before returning.

Parameters
[in]cvCV handle.
[in]mtxLocked FastMutex handle protecting the state.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
True if signaled, False if the wait did not end in a signal (timeout or an externally cancelled wait).
Note
The calling task must own mtx exactly once (FastMutex is not recursive).
Collapses the distinction between timeout and cancellation. Use stk_cv_wait_ex_fastmutex() if the caller needs to tell them apart.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 283 of file stk_c_sync.cpp.

284{
285 STK_ASSERT(cv != nullptr);
286 STK_ASSERT(mtx != nullptr);
287
288 return cv->handle.Wait(mtx->handle, timeout);
289}

References stk_cv_t::handle, stk_fastmutex_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 644 of file stk_c.cpp.

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

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 646 of file stk_c.cpp.

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

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 529 of file stk_c_sync.cpp.

530{
531 STK_ASSERT(ef != nullptr);
532
533 return ef->handle.Clear(flags);
534}
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 initial_flags )

Create an EventFlags object (using provided memory).

Parameters
[in]membufPointer to static memory container.
[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.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 500 of file stk_c_sync.cpp.

502{
503 STK_ASSERT(membuf != nullptr);
504
505 stk_ef_t *result = nullptr;
506 if (membuf != nullptr)
507 {
508 result = ConstructIn<stk_ef_t>(*membuf, initial_flags);
509 }
510
511 return result;
512}

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ 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 514 of file stk_c_sync.cpp.

515{
516 if (ef != nullptr)
517 {
518 ef->~stk_ef_t();
519 }
520}

◆ 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 536 of file stk_c_sync.cpp.

537{
538 STK_ASSERT(ef != nullptr);
539
540 return ef->handle.Get();
541}
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_get_instance()

stk::sync::EventFlags * stk_ef_get_instance ( stk_ef_t * ef)

Get the underlying C++ stk::sync::EventFlags object wrapped by a stk_ef_t handle.

Parameters
[in]efEventFlags handle obtained via stk_ef_create().
Returns
Pointer to the wrapped stk::sync::EventFlags instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 557 of file stk_c_sync.cpp.

558{
559 STK_ASSERT(ef != nullptr);
560
561 return &ef->handle;
562}

References stk_ef_t::handle, and STK_ASSERT.

◆ 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 1504 of file stk_c.h.

1505{
1506 return ((result & STK_EF_ERROR_MASK) != 0U);
1507}
#define STK_EF_ERROR_MASK
Definition stk_c.h:1499

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 522 of file stk_c_sync.cpp.

523{
524 STK_ASSERT(ef != nullptr);
525
526 return ef->handle.Set(flags);
527}
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 550 of file stk_c_sync.cpp.

551{
552 STK_ASSERT(ef != nullptr);
553
554 return ef->handle.TryWait(flags, options);
555}
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 in OS ticks or STK_WAIT_INFINITE. Use 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.
Returns STK_EF_ERROR_CANCELED, not STK_EF_ERROR_TIMEOUT, if the wait was cancelled before either the flag condition was met or the deadline expired.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 543 of file stk_c_sync.cpp.

544{
545 STK_ASSERT(ef != nullptr);
546
547 return ef->handle.Wait(flags, options, timeout);
548}
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,
bool manual_reset )

Create an Event (using provided memory).

Parameters
[in]membufPointer to static memory container.
[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 331 of file stk_c_sync.cpp.

333{
334 STK_ASSERT(membuf != nullptr);
335
336 stk_event_t *result = nullptr;
337 if (membuf != nullptr)
338 {
339 result = ConstructIn<stk_event_t>(*membuf, manual_reset);
340 }
341
342 return result;
343}

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ 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 345 of file stk_c_sync.cpp.

346{
347 if (ev != nullptr)
348 {
349 ev->~stk_event_t();
350 }
351}

◆ stk_event_get_instance()

stk::sync::Event * stk_event_get_instance ( stk_event_t * ev)

Get the underlying C++ stk::sync::Event object wrapped by a stk_event_t handle.

Parameters
[in]evEvent handle obtained via stk_event_create().
Returns
Pointer to the wrapped stk::sync::Event instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 395 of file stk_c_sync.cpp.

396{
397 STK_ASSERT(ev != nullptr);
398
399 return &ev->handle;
400}

References stk_event_t::handle, and STK_ASSERT.

◆ 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 388 of file stk_c_sync.cpp.

389{
390 STK_ASSERT(ev != nullptr);
391
392 ev->handle.Pulse();
393}
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 381 of file stk_c_sync.cpp.

382{
383 STK_ASSERT(ev != nullptr);
384
385 return ev->handle.Reset();
386}
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 374 of file stk_c_sync.cpp.

375{
376 STK_ASSERT(ev != nullptr);
377
378 return ev->handle.Set();
379}
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 367 of file stk_c_sync.cpp.

368{
369 STK_ASSERT(ev != nullptr);
370
371 return ev->handle.TryWait();
372}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
True if signaled, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 353 of file stk_c_sync.cpp.

354{
355 STK_ASSERT(ev != nullptr);
356
357 return ev->handle.Wait(timeout);
358}
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_event_wait_ex()

stk_wait_result_t stk_event_wait_ex ( stk_event_t * ev,
stk_timeout_t timeout )

Wait for the event to become signaled, preserving the full outcome.

Identical to stk_event_wait(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool, so a cancellation can be distinguished from a timeout.

Parameters
[in]evEvent handle.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
A cancelled wait does not consume the event state.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 360 of file stk_c_sync.cpp.

361{
362 STK_ASSERT(ev != nullptr);
363
364 return ToCWaitResult(ev->handle.WaitEx(timeout));
365}
EWaitResult WaitEx(Timeout timeout_ticks=WAIT_INFINITE)
Wait until event becomes signaled or the timeout expires, preserving the full wait outcome.

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

Here is the call graph for this function:

◆ stk_fastmutex_create()

stk_fastmutex_t * stk_fastmutex_create ( stk_fastmutex_mem_t *const membuf)

Create a FastMutex (using provided memory).

Parameters
[in]membufPointer to static memory container.
Returns
FastMutex handle.
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(membuf != nullptr);
124
125 stk_fastmutex_t *result = nullptr;
126 if (membuf != nullptr)
127 {
128 result = ConstructIn<stk_fastmutex_t>(*membuf);
129 }
130
131 return result;
132}

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_fastmutex_destroy()

void stk_fastmutex_destroy ( stk_fastmutex_t * mtx)

Destroy a FastMutex.

Parameters
[in]mtxFastMutex handle.
Note
Must not be destroyed while tasks are waiting on it.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 134 of file stk_c_sync.cpp.

135{
136 if (mtx != nullptr)
137 {
138 mtx->~stk_fastmutex_t();
139 }
140}

◆ stk_fastmutex_get_instance()

stk::sync::FastMutex * stk_fastmutex_get_instance ( stk_fastmutex_t * mtx)

Get the underlying C++ stk::sync::FastMutex object wrapped by a stk_fastmutex_t handle.

Parameters
[in]mtxFastMutex handle obtained via stk_fastmutex_create().
Returns
Pointer to the wrapped stk::sync::FastMutex instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 177 of file stk_c_sync.cpp.

178{
179 STK_ASSERT(mtx != nullptr);
180
181 return &mtx->handle;
182}

References stk_fastmutex_t::handle, and STK_ASSERT.

◆ stk_fastmutex_lock()

void stk_fastmutex_lock ( stk_fastmutex_t * mtx)

Lock the mutex. Blocks until available.

Parameters
[in]mtxFastMutex handle.
Warning
Must not be called by the task that already owns the mutex (kernel panic KERNEL_PANIC_SYNC_DEADLOCK).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 142 of file stk_c_sync.cpp.

143{
144 STK_ASSERT(mtx != nullptr);
145
146 mtx->handle.Lock();
147}
void Lock() override
Acquire lock.

References stk_fastmutex_t::handle, stk::sync::FastMutex::Lock(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_fastmutex_timed_lock()

bool stk_fastmutex_timed_lock ( stk_fastmutex_t * mtx,
stk_timeout_t timeout )

Try to lock the mutex with a timeout.

Parameters
[in]mtxFastMutex handle.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
True if locked successfully, False on timeout.
Warning
Panics (KERNEL_PANIC_SYNC_DEADLOCK) if the caller already owns the mutex.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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(mtx != nullptr);
166
167 return mtx->handle.TimedLock(timeout);
168}
bool TimedLock(Timeout timeout_ticks)
Acquire lock.

References stk_fastmutex_t::handle, STK_ASSERT, and stk::sync::FastMutex::TimedLock().

Here is the call graph for this function:

◆ stk_fastmutex_timed_lock_ex()

stk_wait_result_t stk_fastmutex_timed_lock_ex ( stk_fastmutex_t * mtx,
stk_timeout_t timeout )

Try to lock the FastMutex with a timeout, preserving the full outcome.

Identical to stk_fastmutex_timed_lock(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]mtxFastMutex handle.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
STK_WAIT_RESULT_SIGNAL means "lock acquired". A busy mutex with STK_NO_WAIT is reported as STK_WAIT_RESULT_TIMEOUT.
Warning
Panics (KERNEL_PANIC_SYNC_DEADLOCK) if the caller already owns the mutex.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 170 of file stk_c_sync.cpp.

171{
172 STK_ASSERT(mtx != nullptr);
173
174 return ToCWaitResult(mtx->handle.TimedLockEx(timeout));
175}
EWaitResult TimedLockEx(Timeout timeout_ticks)
Acquire lock, preserving the full wait outcome.

References stk_fastmutex_t::handle, STK_ASSERT, stk::sync::FastMutex::TimedLockEx(), and ToCWaitResult().

Here is the call graph for this function:

◆ stk_fastmutex_trylock()

bool stk_fastmutex_trylock ( stk_fastmutex_t * mtx)

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

Parameters
[in]mtxFastMutex handle.
Returns
True if locked successfully, False if locked by another task.
Warning
Panics (KERNEL_PANIC_SYNC_DEADLOCK) if the caller already owns the mutex.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 149 of file stk_c_sync.cpp.

150{
151 STK_ASSERT(mtx != nullptr);
152
153 return mtx->handle.TryLock();
154}
bool TryLock()
Try to acquire the lock without blocking.

References stk_fastmutex_t::handle, STK_ASSERT, and stk::sync::FastMutex::TryLock().

Here is the call graph for this function:

◆ stk_fastmutex_unlock()

void stk_fastmutex_unlock ( stk_fastmutex_t * mtx)

Unlock the mutex.

Parameters
[in]mtxFastMutex handle.
Note
Must be called by the owner. Ownership is passed directly to the first waiter (FIFO).
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 156 of file stk_c_sync.cpp.

157{
158 STK_ASSERT(mtx != nullptr);
159
160 mtx->handle.Unlock();
161}
void Unlock() override
Release lock.

References stk_fastmutex_t::handle, STK_ASSERT, and stk::sync::FastMutex::Unlock().

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 641 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 642 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 643 of file stk_c.cpp.

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

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 428 of file stk_c.cpp.

429{
430 STK_ASSERT(k != nullptr);
431 STK_ASSERT(tsk != nullptr);
432
434}
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:126

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

Referenced by stk::pthread::EnsureReaper().

Here is the call graph for this function:
Here is the caller 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 536 of file stk_c.cpp.

541{
542 STK_ASSERT(k != nullptr);
543 STK_ASSERT(tsk != nullptr);
544
546 &tsk->handle,
547 periodicity_ticks,
548 deadline_ticks,
549 start_delay_ticks);
550}

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 331 of file stk_c.cpp.

332{
333 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
334 STK_ASSERT(core_nr < STK_C_CPU_COUNT);
335
336 IKernel *k;
337
338 switch (core_nr)
339 {
340#ifdef STK_C_KERNEL_TYPE_CPU_0
342#endif
343#ifdef STK_C_KERNEL_TYPE_CPU_1
345#endif
346#ifdef STK_C_KERNEL_TYPE_CPU_2
348#endif
349#ifdef STK_C_KERNEL_TYPE_CPU_3
351#endif
352#ifdef STK_C_KERNEL_TYPE_CPU_4
354#endif
355#ifdef STK_C_KERNEL_TYPE_CPU_5
357#endif
358#ifdef STK_C_KERNEL_TYPE_CPU_6
360#endif
361#ifdef STK_C_KERNEL_TYPE_CPU_7
363#endif
364 default: {
365 k = nullptr;
366 break; }
367 }
368
370}
#define STK_STATIC_ASSERT(X)
Compile-time assertion. Produces a compilation error if X is false.
Definition stk_defs.h:553
static stk_kernel_t * CastCppKernelInterfaceToC(IKernel *const k)
Definition stk_c.cpp:55
#define STK_KERNEL_CASE(X)
Definition stk_c.cpp:318
#define STK_C_CPU_COUNT
Number of kernel instances / CPU cores supported (default: 1).
Definition stk_c.h:65
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 385 of file stk_c.cpp.

386{
387 STK_ASSERT(k != nullptr);
388
389 // Detach the event overrider and clear the registry entry BEFORE calling
390 // the destructor: the platform teardown inside ~IKernel() may still invoke
391 // GetPlatform() paths, and we must not leave a dangling overrider pointer
392 // registered at that point.
394}
static void UnregisterKernel(const IKernel *k)
Definition stk_c.cpp:225

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 477 of file stk_c.cpp.

478{
479 STK_ASSERT(k != nullptr);
480 STK_ASSERT(tasks != nullptr);
481
482 stk::ITask *itasks[STK_C_TASKS_MAX] = {};
483
484 // Determine the safe upper bound for the temporary buffer
485 const size_t requested_size = (max_count < static_cast<size_t>(STK_C_TASKS_MAX)) ? max_count :
486 static_cast<size_t>(STK_C_TASKS_MAX);
487
488 // Pass via ArrayView temporary object
489 const size_t ret_count = CastCToKernelInterface(k)->EnumerateTasks(
490 ArrayView<stk::ITask *>(itasks, requested_size));
491
492 ArrayView<stk_task_t *> output_view(tasks, max_count);
493 for (size_t i = 0U; i < ret_count; ++i)
494 {
495 output_view[i] = CastCppTaskInterfaceToC(itasks[i]);
496 }
497
498 return ret_count;
499}
static stk_task_t * CastCppTaskInterfaceToC(ITask *const t)
Definition stk_c.cpp:140
#define STK_C_TASKS_MAX
Definition stk_c.cpp:37
Lightweight, non-owning view over a contiguous sequence of elements.
Definition stk_common.h:277
Interface for a user task.
Definition stk_common.h:824
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_instance()

stk::IKernel * stk_kernel_get_instance ( uint8_t core_nr)

Get the underlying C++ stk::IKernel object for a given core.

Parameters
[in]core_nrCore id (0U = first core, ...). Must be < STK_C_CPU_COUNT.
Returns
Pointer to the stk::IKernel instance registered for core_nr. Never NULL.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Warning
core_nr must refer to a kernel already created via stk_kernel_create() and not yet destroyed via stk_kernel_destroy(), otherwise this triggers an assertion failure.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 372 of file stk_c.cpp.

373{
374 STK_ASSERT(core_nr < STK_C_CPU_COUNT);
375
376 IKernel *const k = s_KernelMap[core_nr].kernel;
377
378 // Kernel not found: stk_kernel_get_instance() called before
379 // stk_kernel_create() or after stk_kernel_destroy().
380 STK_ASSERT(k != nullptr);
381
382 return k;
383}
static KernelRegistryEntry s_KernelMap[(1)]
Definition stk_c.cpp:216

References s_KernelMap, STK_ASSERT, and STK_C_CPU_COUNT.

◆ 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 413 of file stk_c.cpp.

414{
415 STK_ASSERT(k != nullptr);
416
418}
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 399 of file stk_c.cpp.

400{
401 STK_ASSERT(k != nullptr);
402
403 CastCToKernelInterface(k)->Initialize(tick_period_us);
404}
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 420 of file stk_c.cpp.

421{
422 STK_ASSERT(k != nullptr);
423
425 const_cast<IKernel *>(CastCToKernelInterfaceConst(k))->GetSwitchStrategy());
426}
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 444 of file stk_c.cpp.

445{
446 STK_ASSERT(k != nullptr);
447
450}
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 522 of file stk_c.cpp.

523{
524 STK_ASSERT(k != nullptr);
525
527}
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 515 of file stk_c.cpp.

516{
517 STK_ASSERT(k != nullptr);
518
520}
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 436 of file stk_c.cpp.

437{
438 STK_ASSERT(k != nullptr);
439 STK_ASSERT(tsk != nullptr);
440
442}
virtual void RemoveTask(ITask *user_task)=0
Remove a previously added task from the kernel when it is not started.

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 508 of file stk_c.cpp.

509{
510 STK_ASSERT(k != nullptr);
511
512 CastCToKernelInterface(k)->GetPlatform()->Resume(static_cast<stk::Timeout>(elapsed_ticks));
513}
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:170
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 469 of file stk_c.cpp.

470{
471 STK_ASSERT(k != nullptr);
472 STK_ASSERT(tsk != nullptr);
473
474 CastCToKernelInterface(k)->ResumeTask(&tsk->handle);
475}
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 452 of file stk_c.cpp.

453{
454 STK_ASSERT(k != nullptr);
455 STK_ASSERT(tsk != nullptr);
456
458}
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 529 of file stk_c.cpp.

530{
531 STK_ASSERT(k != nullptr);
532
534}
static void SetEventOverrider(IKernel *k, stk_event_overrider_t *overrider)
Definition stk_c.cpp:238

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 406 of file stk_c.cpp.

407{
408 STK_ASSERT(k != nullptr);
409
411}
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 501 of file stk_c.cpp.

502{
503 STK_ASSERT(k != nullptr);
504
505 return static_cast<stk_timeout_t>(CastCToKernelInterface(k)->GetPlatform()->Suspend());
506}
int32_t stk_timeout_t
Timeout value.
Definition stk_c.h:118
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 460 of file stk_c.cpp.

461{
462 STK_ASSERT(k != nullptr);
463 STK_ASSERT(tsk != nullptr);
464 STK_ASSERT(suspended != nullptr);
465
466 CastCToKernelInterface(k)->SuspendTask(&tsk->handle, *suspended);
467}
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 725 of file stk_c.h.

726{
728}
uint32_t stk_tick_resolution(void)
Returns how many microseconds correspond to one kernel tick.
Definition stk_c.cpp:635
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:714

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 714 of file stk_c.h.

715{
716 const stk_tick_t total_ticks = ticks * STK_STATIC_CAST(stk_tick_t, resolution);
717 return STK_STATIC_CAST(stk_time_t, total_ticks / 1000LL);
718}
#define STK_STATIC_CAST(type, val)
Convenience wrapper for static_cast and C-style cast.
Definition stk_c.h:88
int64_t stk_tick_t
Ticks value.
Definition stk_c.h:108
int64_t stk_time_t
Time value.
Definition stk_c.h:113

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,
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.
[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 826 of file stk_c_sync.cpp.

831{
832 STK_ASSERT(membuf != nullptr);
833 STK_ASSERT(buf != nullptr);
834 STK_ASSERT(capacity >= 1U);
835 STK_ASSERT(msg_size >= 1U);
836 STK_ASSERT(buf_size >= capacity * msg_size);
837
838 stk_msgq_t *result = nullptr;
839 if ((membuf != nullptr) && (buf_size >= (capacity * msg_size)))
840 {
841 result = ConstructIn<stk_msgq_t>(*membuf, buf, capacity, msg_size);
842 }
843
844 return result;
845}

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ 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 847 of file stk_c_sync.cpp.

848{
849 if (mq != nullptr)
850 {
851 mq->~stk_msgq_t();
852 }
853}

◆ 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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
True if a message was retrieved, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 903 of file stk_c_sync.cpp.

904{
905 STK_ASSERT(mq != nullptr);
906 STK_ASSERT(msg != nullptr);
907
908 return mq->handle.Get(msg, timeout);
909}
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 1024 of file stk_c_sync.cpp.

1025{
1026 STK_ASSERT(mq != nullptr);
1027
1028 return mq->handle.GetBuffer();
1029}
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 982 of file stk_c_sync.cpp.

983{
984 STK_ASSERT(mq != nullptr);
985
986 return mq->handle.GetCapacity();
987}
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 996 of file stk_c_sync.cpp.

997{
998 STK_ASSERT(mq != nullptr);
999
1000 return mq->handle.GetCount();
1001}
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_ex()

stk_wait_result_t stk_msgq_get_ex ( stk_msgq_t * mq,
void * msg,
stk_timeout_t timeout )

Get a message from the queue, preserving the full outcome.

Identical to stk_msgq_get(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]mqMessageQueue handle.
[out]msgDestination buffer (must be >= msg_size bytes).
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
Nothing is copied on a non-signal result.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 911 of file stk_c_sync.cpp.

912{
913 STK_ASSERT(mq != nullptr);
914 STK_ASSERT(msg != nullptr);
915
916 return ToCWaitResult(mq->handle.GetEx(msg, timeout));
917}
EWaitResult GetEx(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Get a message from the queue, preserving the full wait outcome.

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

Here is the call graph for this function:

◆ stk_msgq_get_instance()

stk::sync::MessageQueue * stk_msgq_get_instance ( stk_msgq_t * mq)

Get the underlying C++ stk::sync::MessageQueue object wrapped by a stk_msgq_t handle.

Parameters
[in]mqMessageQueue handle obtained via stk_msgq_create().
Returns
Pointer to the wrapped stk::sync::MessageQueue instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1038 of file stk_c_sync.cpp.

1039{
1040 STK_ASSERT(mq != nullptr);
1041
1042 return &mq->handle;
1043}

References stk_msgq_t::handle, and STK_ASSERT.

◆ 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 989 of file stk_c_sync.cpp.

990{
991 STK_ASSERT(mq != nullptr);
992
993 return mq->handle.GetMsgSize();
994}
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 1003 of file stk_c_sync.cpp.

1004{
1005 STK_ASSERT(mq != nullptr);
1006
1007 return mq->handle.GetSpace();
1008}
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 1010 of file stk_c_sync.cpp.

1011{
1012 STK_ASSERT(mq != nullptr);
1013
1014 return mq->handle.IsEmpty();
1015}
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 1017 of file stk_c_sync.cpp.

1018{
1019 STK_ASSERT(mq != nullptr);
1020
1021 return mq->handle.IsFull();
1022}
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 1031 of file stk_c_sync.cpp.

1032{
1033 STK_ASSERT(mq != nullptr);
1034
1035 return mq->handle.IsStorageValid();
1036}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
True if a message was peeked, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 927 of file stk_c_sync.cpp.

928{
929 STK_ASSERT(mq != nullptr);
930 STK_ASSERT(msg != nullptr);
931
932 return mq->handle.Peek(msg, timeout);
933}
bool Peek(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Peek at the next message to be delivered (the one Get() returns next) 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_peek_ex()

stk_wait_result_t stk_msgq_peek_ex ( stk_msgq_t * mq,
void * msg,
stk_timeout_t timeout )

Peek at the next message without removing it, preserving the full outcome.

Identical to stk_msgq_peek(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]mqMessageQueue handle.
[out]msgDestination buffer (must be >= msg_size bytes).
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
Nothing is copied on a non-signal result.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 935 of file stk_c_sync.cpp.

936{
937 STK_ASSERT(mq != nullptr);
938 STK_ASSERT(msg != nullptr);
939
940 return ToCWaitResult(mq->handle.PeekEx(msg, timeout));
941}
EWaitResult PeekEx(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Peek at the next message to be delivered without removing it, preserving the full wait outcome.

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

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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
True if a message was peeked, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 951 of file stk_c_sync.cpp.

952{
953 STK_ASSERT(mq != nullptr);
954 STK_ASSERT(msg != nullptr);
955
956 return mq->handle.PeekFront(msg, timeout);
957}
bool PeekFront(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Peek at the front of the queue (the message Get() returns next) 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_peekfront_ex()

stk_wait_result_t stk_msgq_peekfront_ex ( stk_msgq_t * mq,
void * msg,
stk_timeout_t timeout )

Peek at the front-inserted message without removing it, preserving the full outcome.

Identical to stk_msgq_peekfront(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]mqMessageQueue handle.
[out]msgDestination buffer (must be >= msg_size bytes).
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
Nothing is copied on a non-signal result.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 959 of file stk_c_sync.cpp.

960{
961 STK_ASSERT(mq != nullptr);
962 STK_ASSERT(msg != nullptr);
963
964 return ToCWaitResult(mq->handle.PeekFrontEx(msg, timeout));
965}
EWaitResult PeekFrontEx(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Peek at the front of the queue without removing it, preserving the full wait outcome.

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

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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
True if the message was enqueued, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 855 of file stk_c_sync.cpp.

856{
857 STK_ASSERT(mq != nullptr);
858 STK_ASSERT(msg != nullptr);
859
860 return mq->handle.Put(msg, timeout);
861}
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_put_ex()

stk_wait_result_t stk_msgq_put_ex ( stk_msgq_t * mq,
const void * msg,
stk_timeout_t timeout )

Put a message into the queue, preserving the full outcome.

Identical to stk_msgq_put(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]mqMessageQueue handle.
[in]msgPointer to the message payload (must be >= msg_size bytes).
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
Nothing is enqueued on a non-signal result.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 863 of file stk_c_sync.cpp.

864{
865 STK_ASSERT(mq != nullptr);
866 STK_ASSERT(msg != nullptr);
867
868 return ToCWaitResult(mq->handle.PutEx(msg, timeout));
869}
EWaitResult PutEx(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the back of the queue (FIFO order), preserving the full wait outcome.

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

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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
True if the message was enqueued at the front, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 879 of file stk_c_sync.cpp.

880{
881 STK_ASSERT(mq != nullptr);
882 STK_ASSERT(msg != nullptr);
883
884 return mq->handle.PutFront(msg, timeout);
885}
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_putfront_ex()

stk_wait_result_t stk_msgq_putfront_ex ( stk_msgq_t * mq,
const void * msg,
stk_timeout_t timeout )

Put a message into the front of the queue, preserving the full outcome.

Identical to stk_msgq_putfront(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]mqMessageQueue handle.
[in]msgPointer to the message payload (must be >= msg_size bytes).
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
Nothing is enqueued on a non-signal result.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 887 of file stk_c_sync.cpp.

888{
889 STK_ASSERT(mq != nullptr);
890 STK_ASSERT(msg != nullptr);
891
892 return ToCWaitResult(mq->handle.PutFrontEx(msg, timeout));
893}
EWaitResult PutFrontEx(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the front of the queue (LIFO / priority-insert order), preserving the full wait ou...

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

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 975 of file stk_c_sync.cpp.

976{
977 STK_ASSERT(mq != nullptr);
978
979 mq->handle.Reset();
980}
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 919 of file stk_c_sync.cpp.

920{
921 STK_ASSERT(mq != nullptr);
922 STK_ASSERT(msg != nullptr);
923
924 return mq->handle.TryGet(msg);
925}
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 943 of file stk_c_sync.cpp.

944{
945 STK_ASSERT(mq != nullptr);
946 STK_ASSERT(msg != nullptr);
947
948 return mq->handle.TryPeek(msg);
949}
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 967 of file stk_c_sync.cpp.

968{
969 STK_ASSERT(mq != nullptr);
970 STK_ASSERT(msg != nullptr);
971
972 return mq->handle.TryPeekFront(msg);
973}
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 871 of file stk_c_sync.cpp.

872{
873 STK_ASSERT(mq != nullptr);
874 STK_ASSERT(msg != nullptr);
875
876 return mq->handle.TryPut(msg);
877}
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 895 of file stk_c_sync.cpp.

896{
897 STK_ASSERT(mq != nullptr);
898 STK_ASSERT(msg != nullptr);
899
900 return mq->handle.TryPutFront(msg);
901}
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)

Create a Mutex (using provided memory).

Parameters
[in]membufPointer to static memory container.
Returns
Mutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 50 of file stk_c_sync.cpp.

51{
52 STK_ASSERT(membuf != nullptr);
53
54 stk_mutex_t *result = nullptr;
55 if (membuf != nullptr)
56 {
57 result = ConstructIn<stk_mutex_t>(*membuf);
58 }
59
60 return result;
61}

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ 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 63 of file stk_c_sync.cpp.

64{
65 if (mtx != nullptr)
66 {
67 mtx->~stk_mutex_t();
68 }
69}

◆ stk_mutex_get_instance()

stk::sync::Mutex * stk_mutex_get_instance ( stk_mutex_t * mtx)

Get the underlying C++ stk::sync::Mutex object wrapped by a stk_mutex_t handle.

Parameters
[in]mtxMutex handle obtained via stk_mutex_create().
Returns
Pointer to the wrapped stk::sync::Mutex instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 106 of file stk_c_sync.cpp.

107{
108 STK_ASSERT(mtx != nullptr);
109
110 return &mtx->handle;
111}

References stk_mutex_t::handle, and STK_ASSERT.

◆ 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 71 of file stk_c_sync.cpp.

72{
73 STK_ASSERT(mtx != nullptr);
74
75 mtx->handle.Lock();
76}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
True if locked successfully, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 92 of file stk_c_sync.cpp.

93{
94 STK_ASSERT(mtx != nullptr);
95
96 return mtx->handle.TimedLock(timeout);
97}
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_timed_lock_ex()

stk_wait_result_t stk_mutex_timed_lock_ex ( stk_mutex_t * mtx,
stk_timeout_t timeout )

Try to lock the mutex with a timeout, preserving the full outcome.

Identical to stk_mutex_timed_lock(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]mtxMutex handle.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
STK_WAIT_RESULT_SIGNAL means "lock acquired" (including the immediate and recursive paths). A busy mutex with STK_NO_WAIT is reported as STK_WAIT_RESULT_TIMEOUT.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 99 of file stk_c_sync.cpp.

100{
101 STK_ASSERT(mtx != nullptr);
102
103 return ToCWaitResult(mtx->handle.TimedLockEx(timeout));
104}
EWaitResult TimedLockEx(Timeout timeout_ticks)
Acquire lock, preserving the full wait outcome.

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

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 78 of file stk_c_sync.cpp.

79{
80 STK_ASSERT(mtx != nullptr);
81
82 return mtx->handle.TryLock();
83}
bool TryLock()
Try to acquire the lock without blocking.

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 85 of file stk_c_sync.cpp.

86{
87 STK_ASSERT(mtx != nullptr);
88
89 mtx->handle.Unlock();
90}
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,
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.
[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 576 of file stk_c_sync.cpp.

581{
582 STK_ASSERT(membuf != nullptr);
583 STK_ASSERT(buf != nullptr);
584 STK_ASSERT(capacity >= 1U);
585 STK_ASSERT(element_size >= 1U);
586 STK_ASSERT(buf_size >= capacity * element_size);
587
588 stk_pipe_t *result = nullptr;
589 if ((membuf != nullptr) && (buf_size >= (capacity * element_size)))
590 {
591 result = ConstructIn<stk_pipe_t>(*membuf, buf, capacity, element_size);
592 }
593
594 return result;
595}

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ 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 597 of file stk_c_sync.cpp.

598{
599 if (pipe != nullptr)
600 {
601 pipe->~stk_pipe_t();
602 }
603}

◆ 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 758 of file stk_c_sync.cpp.

759{
760 STK_ASSERT(pipe != nullptr);
761
762 return pipe->handle.GetCapacity();
763}
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 772 of file stk_c_sync.cpp.

773{
774 STK_ASSERT(pipe != nullptr);
775
776 return pipe->handle.GetCount();
777}
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 765 of file stk_c_sync.cpp.

766{
767 STK_ASSERT(pipe != nullptr);
768
769 return pipe->handle.GetElementSize();
770}
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_instance()

stk::sync::Pipe * stk_pipe_get_instance ( stk_pipe_t * pipe)

Get the underlying C++ stk::sync::Pipe object wrapped by a stk_pipe_t handle.

Parameters
[in]pipePipe handle obtained via stk_pipe_create().
Returns
Pointer to the wrapped stk::sync::Pipe instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
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(pipe != nullptr);
810
811 return &pipe->handle;
812}

References stk_pipe_t::handle, and STK_ASSERT.

◆ 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 779 of file stk_c_sync.cpp.

780{
781 STK_ASSERT(pipe != nullptr);
782
783 return pipe->handle.GetSpace();
784}
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 786 of file stk_c_sync.cpp.

787{
788 STK_ASSERT(pipe != nullptr);
789
790 return pipe->handle.IsEmpty();
791}
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 793 of file stk_c_sync.cpp.

794{
795 STK_ASSERT(pipe != nullptr);
796
797 return pipe->handle.IsFull();
798}
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 800 of file stk_c_sync.cpp.

801{
802 STK_ASSERT(pipe != nullptr);
803
804 return pipe->handle.IsStorageValid();
805}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
True if an element was read, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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(pipe != nullptr);
632 STK_ASSERT(data != nullptr);
633
634 return pipe->handle.Read(data, timeout);
635}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
Number of elements actually read. Equal to count unless a timeout occurred.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 683 of file stk_c_sync.cpp.

684{
685 STK_ASSERT(pipe != nullptr);
686
687 return pipe->handle.ReadBulk(dst, count, timeout);
688}
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_ex()

stk_wait_result_t stk_pipe_read_bulk_ex ( stk_pipe_t * pipe,
void * dst,
size_t count,
size_t * read_count,
stk_timeout_t timeout )

Read multiple elements from the pipe, preserving the full outcome.

Identical to stk_pipe_read_bulk(), except the caller gets the raw stk_wait_result_t and the number of elements read is returned through read_count.

Parameters
[in]pipePipe handle.
[out]dstPointer to the destination array (must hold at least count elements).
[in]countNumber of elements to read.
[out]read_countNumber of elements actually read (may be NULL if not needed). Always set; holds the partial count on any non-signal result.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
STK_WAIT_RESULT_FAIL is also returned if dst is NULL.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 690 of file stk_c_sync.cpp.

692{
693 STK_ASSERT(pipe != nullptr);
694
695 size_t n = 0U;
696 const EWaitResult wr = pipe->handle.ReadBulkEx(dst, count, n, timeout);
697
698 if (read_count != nullptr)
699 {
700 *read_count = n;
701 }
702
703 return ToCWaitResult(wr);
704}
EWaitResult
Wait result (see IKernelService::Wait).
Definition stk_common.h:137
EWaitResult ReadBulkEx(void *dst, size_t count, size_t &read_count, Timeout timeout_ticks=WAIT_INFINITE)
Read multiple elements from the pipe, preserving the full wait outcome.

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

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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
Number of elements actually read (0 if timeout fired before trigger was reached).
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 713 of file stk_c_sync.cpp.

718{
719 STK_ASSERT(pipe != nullptr);
720
721 return pipe->handle.ReadBulkTriggered(dst, trigger, max_count, timeout);
722}
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_read_bulk_triggered_ex()

stk_wait_result_t stk_pipe_read_bulk_triggered_ex ( stk_pipe_t * pipe,
void * dst,
size_t trigger,
size_t max_count,
size_t * read_count,
stk_timeout_t timeout )

Read at least trigger elements, then drain up to max_count, preserving the full outcome.

Identical to stk_pipe_read_bulk_triggered(), except the caller gets the raw stk_wait_result_t and the number of elements read is returned through read_count.

Parameters
[in]pipePipe handle.
[out]dstDestination buffer; must hold at least max_count elements.
[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.
[out]read_countNumber of elements actually read (may be NULL if not needed). On a timeout or cancellation holds the (possibly zero) number of elements drained.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
STK_WAIT_RESULT_FAIL is also returned if dst is NULL.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 724 of file stk_c_sync.cpp.

730{
731 STK_ASSERT(pipe != nullptr);
732
733 size_t n = 0U;
734 const EWaitResult wr = pipe->handle.ReadBulkTriggeredEx(dst, trigger, max_count, n, timeout);
735
736 if (read_count != nullptr)
737 {
738 *read_count = n;
739 }
740
741 return ToCWaitResult(wr);
742}
EWaitResult ReadBulkTriggeredEx(void *dst, size_t trigger, size_t max_count, size_t &read_count, Timeout timeout_ticks=WAIT_INFINITE)
Read at least trigger elements, then drain up to max_count without blocking, preserving the full wait...

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

Here is the call graph for this function:

◆ stk_pipe_read_ex()

stk_wait_result_t stk_pipe_read_ex ( stk_pipe_t * pipe,
void * data,
stk_timeout_t timeout )

Read a single element from the pipe, preserving the full outcome.

Identical to stk_pipe_read(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]pipePipe handle.
[out]dataDestination buffer (must be >= element_size bytes).
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 637 of file stk_c_sync.cpp.

638{
639 STK_ASSERT(pipe != nullptr);
640 STK_ASSERT(data != nullptr);
641
642 return ToCWaitResult(pipe->handle.ReadEx(data, timeout));
643}
EWaitResult ReadEx(void *data, Timeout timeout_ticks=WAIT_INFINITE)
Read a single element from the pipe, preserving the full wait outcome.

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

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 751 of file stk_c_sync.cpp.

752{
753 STK_ASSERT(pipe != nullptr);
754
755 pipe->handle.Reset();
756}
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 645 of file stk_c_sync.cpp.

646{
647 STK_ASSERT(pipe != nullptr);
648 STK_ASSERT(data != nullptr);
649
650 return pipe->handle.TryRead(data);
651}
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 706 of file stk_c_sync.cpp.

707{
708 STK_ASSERT(pipe != nullptr);
709
710 return pipe->handle.TryReadBulk(dst, count);
711}
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 744 of file stk_c_sync.cpp.

745{
746 STK_ASSERT(pipe != nullptr);
747
748 return pipe->handle.TryReadBulkTriggered(dst, max_count);
749}
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 621 of file stk_c_sync.cpp.

622{
623 STK_ASSERT(pipe != nullptr);
624 STK_ASSERT(data != nullptr);
625
626 return pipe->handle.TryWrite(data);
627}
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 676 of file stk_c_sync.cpp.

677{
678 STK_ASSERT(pipe != nullptr);
679
680 return pipe->handle.TryWriteBulk(src, count);
681}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
True if the element was written, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 605 of file stk_c_sync.cpp.

606{
607 STK_ASSERT(pipe != nullptr);
608 STK_ASSERT(data != nullptr);
609
610 return pipe->handle.Write(data, timeout);
611}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for a non-blocking attempt.
Returns
Number of elements actually written. Equal to count unless a timeout occurred.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Warning
ISR-safe only with timeout = STK_NO_WAIT.
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(pipe != nullptr);
656
657 return pipe->handle.WriteBulk(src, count, timeout);
658}
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_pipe_write_bulk_ex()

stk_wait_result_t stk_pipe_write_bulk_ex ( stk_pipe_t * pipe,
const void * src,
size_t count,
size_t * written,
stk_timeout_t timeout )

Write multiple elements to the pipe, preserving the full outcome.

Identical to stk_pipe_write_bulk(), except the caller gets the raw stk_wait_result_t and the number of elements written is returned through written.

Parameters
[in]pipePipe handle.
[in]srcPointer to the source array (must hold at least count elements).
[in]countNumber of elements to write.
[out]writtenNumber of elements actually written (may be NULL if not needed). Always set; holds the partial count on any non-signal result.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
STK_WAIT_RESULT_FAIL is also returned if src is NULL.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 660 of file stk_c_sync.cpp.

662{
663 STK_ASSERT(pipe != nullptr);
664
665 size_t n = 0U;
666 const EWaitResult wr = pipe->handle.WriteBulkEx(src, count, n, timeout);
667
668 if (written != nullptr)
669 {
670 *written = n;
671 }
672
673 return ToCWaitResult(wr);
674}
EWaitResult WriteBulkEx(const void *src, size_t count, size_t &written, Timeout timeout_ticks=WAIT_INFINITE)
Write multiple elements to the pipe, preserving the full wait outcome.

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

Here is the call graph for this function:

◆ stk_pipe_write_ex()

stk_wait_result_t stk_pipe_write_ex ( stk_pipe_t * pipe,
const void * data,
stk_timeout_t timeout )

Write a single element to the pipe, preserving the full outcome.

Identical to stk_pipe_write(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]pipePipe handle.
[in]dataPointer to the element payload (must be >= element_size bytes).
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 613 of file stk_c_sync.cpp.

614{
615 STK_ASSERT(pipe != nullptr);
616 STK_ASSERT(data != nullptr);
617
618 return ToCWaitResult(pipe->handle.WriteEx(data, timeout));
619}
EWaitResult WriteEx(const void *data, Timeout timeout_ticks=WAIT_INFINITE)
Write a single element to the pipe, preserving the full wait outcome.

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

Here is the call graph for this function:

◆ stk_rwmutex_create()

stk_rwmutex_t * stk_rwmutex_create ( stk_rwmutex_mem_t *const membuf)

Create an RWMutex (using provided memory).

Parameters
[in]membufPointer to static memory container.
Returns
RWMutex handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1053 of file stk_c_sync.cpp.

1054{
1055 STK_ASSERT(membuf != nullptr);
1056
1057 stk_rwmutex_t *result = nullptr;
1058 if (membuf != nullptr)
1059 {
1060 result = ConstructIn<stk_rwmutex_t>(*membuf);
1061 }
1062
1063 return result;
1064}

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ 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 1066 of file stk_c_sync.cpp.

1067{
1068 if (rw != nullptr)
1069 {
1070 rw->~stk_rwmutex_t();
1071 }
1072}

◆ stk_rwmutex_get_instance()

stk::sync::RWMutex * stk_rwmutex_get_instance ( stk_rwmutex_t * rw)

Get the underlying C++ stk::sync::RWMutex object wrapped by a stk_rwmutex_t handle.

Parameters
[in]rwRWMutex handle obtained via stk_rwmutex_create().
Returns
Pointer to the wrapped stk::sync::RWMutex instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1144 of file stk_c_sync.cpp.

1145{
1146 STK_ASSERT(rw != nullptr);
1147
1148 return &rw->handle;
1149}
sync::RWMutex handle

References stk_rwmutex_t::handle, and STK_ASSERT.

◆ 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 1109 of file stk_c_sync.cpp.

1110{
1111 STK_ASSERT(rw != nullptr);
1112
1113 rw->handle.Lock();
1114}
void Lock() override
Acquire the lock for exclusive writing (IMutex interface).

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 1074 of file stk_c_sync.cpp.

1075{
1076 STK_ASSERT(rw != nullptr);
1077
1078 rw->handle.ReadLock();
1079}
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 1102 of file stk_c_sync.cpp.

1103{
1104 STK_ASSERT(rw != nullptr);
1105
1106 rw->handle.ReadUnlock();
1107}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for non-blocking.
Returns
True if acquired, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1123 of file stk_c_sync.cpp.

1124{
1125 STK_ASSERT(rw != nullptr);
1126
1127 return rw->handle.TimedLock(timeout);
1128}
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_lock_ex()

stk_wait_result_t stk_rwmutex_timed_lock_ex ( stk_rwmutex_t * rw,
stk_timeout_t timeout )

Try to acquire the write lock with a timeout, preserving the full outcome.

Identical to stk_rwmutex_timed_lock(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]rwRWMutex handle.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for non-blocking.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
STK_WAIT_RESULT_SIGNAL means "lock acquired".
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 1130 of file stk_c_sync.cpp.

1131{
1132 STK_ASSERT(rw != nullptr);
1133
1134 return ToCWaitResult(rw->handle.TimedLockEx(timeout));
1135}
EWaitResult TimedLockEx(Timeout timeout_ticks)
Acquire the lock for exclusive writing with a timeout, preserving the full wait outcome.

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

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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for non-blocking.
Returns
True if acquired, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 1088 of file stk_c_sync.cpp.

1089{
1090 STK_ASSERT(rw != nullptr);
1091
1092 return rw->handle.TimedReadLock(timeout);
1093}
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_timed_read_lock_ex()

stk_wait_result_t stk_rwmutex_timed_read_lock_ex ( stk_rwmutex_t * rw,
stk_timeout_t timeout )

Try to acquire the read lock with a timeout, preserving the full outcome.

Identical to stk_rwmutex_timed_read_lock(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]rwRWMutex handle.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE. Use STK_NO_WAIT for non-blocking.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
STK_WAIT_RESULT_SIGNAL means "lock acquired".
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 1095 of file stk_c_sync.cpp.

1096{
1097 STK_ASSERT(rw != nullptr);
1098
1099 return ToCWaitResult(rw->handle.TimedReadLockEx(timeout));
1100}
EWaitResult TimedReadLockEx(Timeout timeout_ticks)
Acquire the lock for shared reading with a timeout, preserving the full wait outcome.

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

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 1081 of file stk_c_sync.cpp.

1082{
1083 STK_ASSERT(rw != nullptr);
1084
1085 return rw->handle.TryReadLock();
1086}
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 1116 of file stk_c_sync.cpp.

1117{
1118 STK_ASSERT(rw != nullptr);
1119
1120 return rw->handle.TryLock();
1121}
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 1137 of file stk_c_sync.cpp.

1138{
1139 STK_ASSERT(rw != nullptr);
1140
1141 rw->handle.Unlock();
1142}
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 initial_count,
uint32_t max_count )

Create a Semaphore (using provided memory).

Parameters
[in]membufPointer to static memory container.
[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 415 of file stk_c_sync.cpp.

418{
419 STK_ASSERT(membuf != nullptr);
420
421 const uint32_t effective_max = ((max_count == 0U) ? Semaphore::COUNT_MAX : max_count);
422
423 stk_sem_t *result = nullptr;
424 if (membuf != nullptr)
425 {
426 result = ConstructIn<stk_sem_t>(*membuf, initial_count, effective_max);
427 }
428
429 return result;
430}
static const uint16_t COUNT_MAX
Max count value supported.

References stk::ConstructIn(), stk::sync::Semaphore::COUNT_MAX, and STK_ASSERT.

Here is the call graph for this function:

◆ 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 432 of file stk_c_sync.cpp.

433{
434 if (sem != nullptr)
435 {
436 sem->~stk_sem_t();
437 }
438}

◆ 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 475 of file stk_c_sync.cpp.

476{
477 STK_ASSERT(sem != nullptr);
478
479 return sem->handle.GetCount();
480}
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_get_instance()

stk::sync::Semaphore * stk_sem_get_instance ( stk_sem_t * sem)

Get the underlying C++ stk::sync::Semaphore object wrapped by a stk_sem_t handle.

Parameters
[in]semSemaphore handle obtained via stk_sem_create().
Returns
Pointer to the wrapped stk::sync::Semaphore instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
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(sem != nullptr);
485
486 return &sem->handle;
487}

References stk_sem_t::handle, and STK_ASSERT.

◆ stk_sem_signal()

void stk_sem_signal ( stk_sem_t * sem)

Signal/Release a semaphore resource.

Parameters
[in]semSemaphore handle.
Warning
API contract: the counter must not already be at max_count with no task waiting. Violating this triggers an assertion in a debug build. Use stk_sem_trysignal() instead if a signal that would exceed max_count should be tolerated (e.g. a redundant signal) rather than treated as a caller error.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 461 of file stk_c_sync.cpp.

462{
463 STK_ASSERT(sem != nullptr);
464
465 sem->handle.Signal();
466}
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_trysignal()

bool stk_sem_trysignal ( stk_sem_t * sem)

Try to signal/release a semaphore resource without exceeding max_count.

Identical to stk_sem_signal(), except that if the counter is already at max_count and no task is waiting, this returns false instead of asserting. The check and the increment (or hand-off to a waiter) happen atomically, so this is safe to call from multiple concurrent signalers without racing each other the way a separate stk_sem_get_count() check followed by stk_sem_signal() would.

Parameters
[in]semSemaphore handle.
Returns
True if signaled (incremented, or handed directly to a waiter), False if the counter was already at max_count and nobody was waiting.
Warning
ISR-safe.
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(sem != nullptr);
471
472 return sem->handle.TrySignal();
473}
bool TrySignal()
Try to post a signal without exceeding max_count.

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

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 454 of file stk_c_sync.cpp.

455{
456 STK_ASSERT(sem != nullptr);
457
458 return sem->handle.TryWait();
459}
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]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
True if resource acquired, False on timeout.
Note
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 440 of file stk_c_sync.cpp.

441{
442 STK_ASSERT(sem != nullptr);
443
444 return sem->handle.Wait(timeout);
445}
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_sem_wait_ex()

stk_wait_result_t stk_sem_wait_ex ( stk_sem_t * sem,
stk_timeout_t timeout )

Wait for a semaphore resource, preserving the full outcome.

Identical to stk_sem_wait(), except the caller gets the raw stk_wait_result_t instead of a collapsed bool.

Parameters
[in]semSemaphore handle.
[in]timeoutMaximum time to wait in OS ticks or STK_WAIT_INFINITE.
Returns
STK_WAIT_RESULT_SIGNAL, STK_WAIT_RESULT_TIMEOUT, STK_WAIT_RESULT_CANCELED, or STK_WAIT_RESULT_FAIL.
Note
A non-signal result never consumes a token.
If OS tick rate is 1 kHz then 1 tick = 1 ms. Use stk_ticks_from_ms() to convert a millisecond value to ticks for best portability across different tick rates.
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 447 of file stk_c_sync.cpp.

448{
449 STK_ASSERT(sem != nullptr);
450
451 return ToCWaitResult(sem->handle.WaitEx(timeout));
452}
EWaitResult WaitEx(Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal (decrement counter), preserving the full wait outcome.

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

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 645 of file stk_c.cpp.

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

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 649 of file stk_c.cpp.

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

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 647 of file stk_c.cpp.

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

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 648 of file stk_c.cpp.

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

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)

Create a recursive SpinLock.

Parameters
[in]membufPointer to static memory container.
Returns
SpinLock handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 192 of file stk_c_sync.cpp.

193{
194 STK_ASSERT(membuf != nullptr);
195
196 stk_spinlock_t *result = nullptr;
197 if (membuf != nullptr)
198 {
199 result = ConstructIn<stk_spinlock_t>(*membuf);
200 }
201
202 return result;
203}

References stk::ConstructIn(), and STK_ASSERT.

Here is the call graph for this function:

◆ 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 205 of file stk_c_sync.cpp.

206{
207 if (slock != nullptr)
208 {
209 slock->~stk_spinlock_t();
210 }
211}

◆ stk_spinlock_get_instance()

stk::sync::SpinLock * stk_spinlock_get_instance ( stk_spinlock_t * slock)

Get the underlying C++ stk::sync::SpinLock object wrapped by a stk_spinlock_t handle.

Parameters
[in]slockSpinLock handle obtained via stk_spinlock_create().
Returns
Pointer to the wrapped stk::sync::SpinLock instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 231 of file stk_c_sync.cpp.

232{
233 STK_ASSERT(slock != nullptr);
234
235 return &slock->handle;
236}
sync::SpinLock handle

References stk_spinlock_t::handle, and STK_ASSERT.

◆ 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 213 of file stk_c_sync.cpp.

214{
215 STK_ASSERT(slock != nullptr);
216 slock->handle.Lock();
217}
void Lock()
Acquire the lock.

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 219 of file stk_c_sync.cpp.

220{
221 STK_ASSERT(slock != nullptr);
222 return slock->handle.TryLock();
223}
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 225 of file stk_c_sync.cpp.

226{
227 STK_ASSERT(slock != nullptr);
228 slock->handle.Unlock();
229}
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 639 of file stk_c.cpp.

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

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 640 of file stk_c.cpp.

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

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 555 of file stk_c.cpp.

559{
560 STK_ASSERT(entry != nullptr);
561 STK_ASSERT(stack != nullptr);
562 STK_ASSERT(stack_size != 0);
563
564 return AllocateTask(entry, arg, stack, stack_size, ACCESS_PRIVILEGED);
565}
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:262
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
Definition stk_common.h:38

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 567 of file stk_c.cpp.

571{
572 STK_ASSERT(entry != nullptr);
573 STK_ASSERT(stack != nullptr);
574 STK_ASSERT(stack_size != 0);
575
576 return AllocateTask(entry, arg, stack, stack_size, ACCESS_USER);
577}
@ ACCESS_USER
Unprivileged access mode (access to some hardware is restricted, see CPU manual for details)....
Definition stk_common.h:37

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

Referenced by stk::pthread::EnsureReaper().

Here is the call graph for this function:
Here is the caller 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 623 of file stk_c.cpp.

624{
625 STK_ASSERT(tsk != nullptr);
626
627 FreeTask(tsk);
628}
static void FreeTask(const stk_task_t *tsk)
Definition stk_c.cpp:288

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 609 of file stk_c.cpp.

610{
611 STK_ASSERT(tsk != nullptr);
612
613 return stk::GetTidFromUserTask(&tsk->handle);
614}
static constexpr TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
Definition stk_arch.h:716

References stk::GetTidFromUserTask(), stk_task_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_task_get_instance()

stk::ITask * stk_task_get_instance ( stk_task_t * tsk)

Get the underlying C++ stk::ITask object wrapped by a stk_task_t handle.

Gateway for mixed C/C++ code: lets C++ callers linked against the C API reach the real polymorphic task object (e.g. to pass it to a C++-only API) without duplicating task bookkeeping.

Parameters
[in]tskTask handle obtained via stk_task_create_privileged() or stk_task_create_user().
Returns
Pointer to the wrapped stk::ITask instance. Never NULL for a valid handle.
Note
C++ callers only (guarded by __cplusplus); not part of the C ABI.
Warning
The returned pointer is only valid for the lifetime of tsk.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 616 of file stk_c.cpp.

617{
618 STK_ASSERT(tsk != nullptr);
619
620 return &tsk->handle;
621}

References stk_task_t::handle, and STK_ASSERT.

◆ 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 602 of file stk_c.cpp.

603{
604 STK_ASSERT(tsk != nullptr);
605
606 return tsk->handle.GetTraceName();
607}
const char * GetTraceName() const override
Get task trace name set by application.
Definition stk_c.cpp:89

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 595 of file stk_c.cpp.

596{
597 STK_ASSERT(tsk != nullptr);
598
599 tsk->handle.SetName(tname);
600}
void SetName(const char *tname)
Definition stk_c.cpp:107

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

Referenced by stk::pthread::EnsureReaper().

Here is the call graph for this function:
Here is the caller 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 586 of file stk_c.cpp.

587{
588 STK_ASSERT(priority <= 31U);
589
590 const stk_weight_t weight = static_cast<stk_weight_t>(priority);
591
592 stk_task_set_weight(tsk, weight);
593}
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:579
int32_t stk_weight_t
Task weight value.
Definition stk_c.h:127

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 579 of file stk_c.cpp.

580{
581 STK_ASSERT(tsk != nullptr);
582
583 tsk->handle.SetWeight(weight);
584}
void SetWeight(Weight weight)
Definition stk_c.cpp:106

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 635 of file stk_c.cpp.

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

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 634 of file stk_c.cpp.

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

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 637 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:690

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

Here is the call graph for this function:

◆ stk_ticks_from_ms_clamped_to_timeout()

stk_timeout_t stk_ticks_from_ms_clamped_to_timeout ( stk_timeout_t ms)

Get ticks from milliseconds using current kernel tick resolution, clamped to the maximum value representable by stk_timeout_t (STK_WAIT_INFINITE).

Parameters
[in]msMilliseconds to convert.
Returns
Equivalent tick count, clamped to STK_WAIT_INFINITE if it would otherwise overflow.
Note
Equivalent to stk::GetTicksFromMsClampedToTimeout(ms). Prefer this over stk_ticks_from_ms() when the result is passed directly as a timeout argument (e.g. to stk_mutex_timed_lock()), so a large millisecond value can never wrap into an unintended (or negative) timeout.
If tick rate is 1 kHz then 1 tick = 1 ms.
ISR-unsafe (internally calls stk_tick_resolution() which accesses the kernel service).
See also
stk_ticks_from_ms, STK_WAIT_INFINITE
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 638 of file stk_c.cpp.

638{ return static_cast<stk_timeout_t>(stk::GetTicksFromMsClampedToTimeout(static_cast<stk::Timeout>(ms))); }
static Timeout GetTicksFromMsClampedToTimeout(Timeout ms)
Convert milliseconds to ticks and clamp the result to a Timeout type.
Definition stk_helper.h:437

References stk::GetTicksFromMsClampedToTimeout().

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 690 of file stk_c.h.

691{
692 stk_time_t result = 0LL;
693
694 if (resolution != 0U)
695 {
696 const stk_time_t total_scaled = msec * 1000LL;
697 result = total_scaled / STK_STATIC_CAST(stk_time_t, resolution);
698 }
699
700 return STK_STATIC_CAST(stk_tick_t, result);
701}

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 633 of file stk_c.cpp.

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

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 636 of file stk_c.cpp.

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

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 650 of file stk_c.cpp.

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

References stk::Yield().

Here is the call graph for this function: