SuperTinyKernel™ RTOS 1.05.3
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 (STK). More...

Classes

struct  stk_mutex_mem_t
 Opaque memory container for a Mutex instance. More...
struct  stk_spinlock_mem_t
 Opaque memory container for SpinLock object. More...
struct  stk_cv_mem_t
 Opaque memory container for a ConditionVariable instance. More...
struct  stk_event_mem_t
 Opaque memory container for an Event instance. More...
struct  stk_sem_mem_t
 Opaque memory container for a Semaphore instance. More...
struct  stk_ef_mem_t
 Opaque memory container for an EventFlags instance. More...
struct  stk_pipe_mem_t
 Opaque memory container for a Pipe instance. More...
struct  stk_rwmutex_mem_t
 Opaque memory container for an RWMutex instance. More...

Macros

#define STK_C_KERNEL_MAX_TASKS   (4)
 Maximum number of tasks per kernel instance (default: 4).
#define STK_C_CPU_COUNT   (1)
 Number of kernel instances / CPU cores supported (default: 1).
#define STK_SYNC_DEBUG_NAMES   (0)
 Enable names for synchronization primitives for debugging/tracing purpose.
#define STK_C_ASSERT(e)
 Assertion macro used inside STK C bindings.
#define __stk_c_stack_attr
 Stack attribute (applies required alignment).
#define STK_PERIODICITY_DEFAULT   (1000U)
 Default tick period (1 ms).
#define STK_WAIT_INFINITE   (INT32_MAX)
 Infinite timeout constant.
#define STK_NO_WAIT   (0)
 No timeout constant.
#define STK_TLS_GET(type)
 Typed helper for getting TLS value.
#define STK_TLS_SET(ptr)
 Typed helper for setting TLS value.
#define STK_MUTEX_IMPL_SIZE   (10 + (STK_SYNC_DEBUG_NAMES ? 1 : 0))
 A memory size (multiples of stk_word_t) required for Mutex instance.
#define STK_SPINLOCK_IMPL_SIZE   (1)
 A memory size (multiples of stk_word_t) required for SpinLock instance.
#define STK_CV_IMPL_SIZE   (7 + (STK_SYNC_DEBUG_NAMES ? 1 : 0))
 A memory size (multiples of stk_word_t) required for ConditionVariable instance.
#define STK_EVENT_IMPL_SIZE   (8 + (STK_SYNC_DEBUG_NAMES ? 1 : 0))
 A memory size (multiples of stk_word_t) required for Event instance.
#define STK_SEM_IMPL_SIZE   (8 + (STK_SYNC_DEBUG_NAMES ? 1 : 0))
 A memory size (multiples of stk_word_t) required for Semaphore instance.
#define STK_EF_OPT_WAIT_ANY   (0x00000000U)
 Options bitmask constants for stk_ef_wait() / stk_ef_trywait().
#define STK_EF_OPT_WAIT_ALL   (0x00000001U)
#define STK_EF_OPT_NO_CLEAR   (0x00000002U)
#define STK_EF_ERROR_PARAMETER   (0x80000001U)
 Return-value error sentinels (bit 31 set indicates an error).
#define STK_EF_ERROR_TIMEOUT   (0x80000002U)
#define STK_EF_ERROR_ISR   (0x80000004U)
#define STK_EF_ERROR_MASK   (0x80000000U)
#define STK_EF_IMPL_SIZE   (STK_CV_IMPL_SIZE + 1 + (STK_SYNC_DEBUG_NAMES ? 1 : 0))
 A memory size (multiples of stk_word_t) required for EventFlags instance.
#define STK_PIPE_SIZE   16
 Size of the Pipe: Pipe<stk_word_t, STK_PIPE_SIZE>.
#define STK_PIPE_IMPL_SIZE   ((27 + (STK_SYNC_DEBUG_NAMES ? 3 : 0)) + STK_PIPE_SIZE)
 A memory size (multiples of stk_word_t) required for Pipe instance.
#define STK_RWMUTEX_IMPL_SIZE   (17 + (STK_SYNC_DEBUG_NAMES ? 3 : 0))
 A memory size (multiples of stk_word_t) required for RWMutex instance.

Typedefs

typedef uintptr_t stk_word_t
 CPU register type.
typedef stk_word_t stk_tid_t
 Task id.
typedef 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 _EKernelState EKernelState
 Kernel state.
typedef struct stk_mutex_mem_t stk_mutex_mem_t
 Opaque memory container for a Mutex instance.
typedef struct stk_mutex_t stk_mutex_t
 Opaque handle to a Mutex instance.
typedef struct stk_spinlock_t stk_spinlock_t
 Opaque handle to a SpinLock instance.
typedef struct stk_cv_mem_t stk_cv_mem_t
 Opaque memory container for a ConditionVariable instance.
typedef struct stk_cv_t stk_cv_t
 Opaque handle to a Condition Variable instance.
typedef struct stk_event_mem_t stk_event_mem_t
 Opaque memory container for an Event instance.
typedef struct stk_event_t stk_event_t
 Opaque handle to an Event instance.
typedef struct stk_sem_mem_t stk_sem_mem_t
 Opaque memory container for a Semaphore instance.
typedef struct stk_sem_t stk_sem_t
 Opaque handle to a Semaphore instance.
typedef struct stk_ef_mem_t stk_ef_mem_t
 Opaque memory container for an EventFlags instance.
typedef struct stk_ef_t stk_ef_t
 Opaque handle to an EventFlags instance.
typedef struct stk_pipe_mem_t stk_pipe_mem_t
 Opaque memory container for a Pipe instance.
typedef struct stk_pipe_t stk_pipe_t
 Opaque handle to a Pipe instance.
typedef struct stk_rwmutex_mem_t stk_rwmutex_mem_t
 Opaque memory container for an RWMutex instance.
typedef struct stk_rwmutex_t stk_rwmutex_t
 Opaque handle to an RWMutex instance.

Enumerations

enum  _EKernelState {
  STK_KERNEL_STATE_INACTIVE = 0 ,
  STK_KERNEL_STATE_READY = 1 ,
  STK_KERNEL_STATE_RUNNING = 2
}
 Kernel state. More...

Functions

stk_kernel_tstk_kernel_create (uint8_t core_nr)
 Create kernel.
void stk_kernel_init (stk_kernel_t *k, uint32_t tick_period_us)
 Initialize kernel with given tick period.
void stk_kernel_add_task (stk_kernel_t *k, stk_task_t *task)
 Add task to non-HRT kernel (static or dynamic).
void stk_kernel_add_task_hrt (stk_kernel_t *k, stk_task_t *task, 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 *task)
 Remove finished task from dynamic kernel.
void stk_kernel_start (stk_kernel_t *k)
 Start the scheduler - never returns.
EKernelState 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.
stk_task_tstk_task_create_privileged (stk_task_entry_t entry, void *arg, stk_word_t *stack, uint32_t stack_size)
 Create privileged-mode (kernel-mode) task.
stk_task_tstk_task_create_user (stk_task_entry_t entry, void *arg, stk_word_t *stack, uint32_t stack_size)
 Create user-mode task.
void stk_task_set_weight (stk_task_t *task, uint32_t weight)
 Set task weight (used only by Smooth Weighted Round Robin).
void stk_task_set_priority (stk_task_t *task, uint8_t priority)
 Set task priority (used only by Fixed Priority scheduler).
void stk_task_set_id (stk_task_t *task, uint32_t tid)
 Assign application-defined task ID (for tracing/debugging).
void stk_task_set_name (stk_task_t *task, const char *tname)
 Assign human-readable task name (for tracing/debugging).
stk_tid_t stk_tid (void)
 Returns current task/thread ID (the value set by stk_task_set_id).
int64_t stk_ticks (void)
 Returns number of ticks elapsed since kernel start.
int32_t stk_tick_resolution (void)
 Returns how many microseconds correspond to one kernel tick.
int64_t stk_ticks_from_ms (int64_t msec)
 Get ticks from milliseconds using current kernel tick resolution.
static int64_t stk_ticks_from_ms_r (int64_t msec, int32_t resolution)
 Get ticks from milliseconds using an explicit tick resolution.
int64_t stk_time_now_ms (void)
 Returns current time in milliseconds since kernel start.
void stk_delay (uint32_t ticks)
 Busy-wait delay (other tasks continue to run).
void stk_delay_ms (uint32_t ms)
 Busy-wait delay (other tasks continue to run).
void stk_sleep (uint32_t ticks)
 Put current task to sleep (non-HRT kernels only).
void stk_sleep_ms (uint32_t ms)
 Put current task to sleep (non-HRT kernels only).
void stk_sleep_until (int64_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_kernel_destroy (stk_kernel_t *k)
 Destroy dynamic kernel instance (only when not running).
void stk_task_destroy (stk_task_t *task)
 Destroy dynamically created task object.
void * stk_tls_get (void)
 Get thread-local pointer (platform-specific slot).
void stk_tls_set (void *ptr)
 Set thread-local pointer.
void stk_critical_section_enter (void)
 Enter critical section — disable context switches on current core.
void stk_critical_section_exit (void)
 Leave critical section — re-enable context switches.
stk_mutex_tstk_mutex_create (stk_mutex_mem_t *memory, uint32_t memory_size)
 Create a Mutex (using provided memory).
void stk_mutex_destroy (stk_mutex_t *mtx)
 Destroy a Mutex.
void stk_mutex_lock (stk_mutex_t *mtx)
 Lock the mutex. Blocks until available.
bool stk_mutex_trylock (stk_mutex_t *mtx)
 Try locking the mutex. Does not block if already locked.
void stk_mutex_unlock (stk_mutex_t *mtx)
 Unlock the mutex.
bool stk_mutex_timed_lock (stk_mutex_t *mtx, int32_t timeout)
 Try to lock the mutex with a timeout.
stk_spinlock_tstk_spinlock_create (stk_spinlock_mem_t *memory, uint32_t memory_size)
 Create a recursive SpinLock.
void stk_spinlock_destroy (stk_spinlock_t *lock)
 Destroy the SpinLock.
void stk_spinlock_lock (stk_spinlock_t *lock)
 Acquire the SpinLock (recursive).
bool stk_spinlock_trylock (stk_spinlock_t *lock)
 Attempt to acquire the SpinLock immediately.
void stk_spinlock_unlock (stk_spinlock_t *lock)
 Release the SpinLock.
stk_cv_tstk_cv_create (stk_cv_mem_t *memory, uint32_t memory_size)
 Create a Condition Variable (using provided memory).
void stk_cv_destroy (stk_cv_t *cv)
 Destroy a Condition Variable.
bool stk_cv_wait (stk_cv_t *cv, stk_mutex_t *mtx, int32_t timeout)
 Wait for a signal on the condition variable.
void stk_cv_notify_one (stk_cv_t *cv)
 Wake one task waiting on the condition variable.
void stk_cv_notify_all (stk_cv_t *cv)
 Wake all tasks waiting on the condition variable.
stk_event_tstk_event_create (stk_event_mem_t *memory, uint32_t memory_size, bool manual_reset)
 Create an Event (using provided memory).
void stk_event_destroy (stk_event_t *ev)
 Destroy an Event.
bool stk_event_wait (stk_event_t *ev, int32_t timeout)
 Wait for the event to become signaled.
bool stk_event_trywait (stk_event_t *ev)
 Wait for the event to become signaled.
void stk_event_set (stk_event_t *ev)
 Set the event to signaled state.
void stk_event_reset (stk_event_t *ev)
 Reset the event to non-signaled state.
void stk_event_pulse (stk_event_t *ev)
 Pulse the event (signal then immediately reset).
stk_sem_tstk_sem_create (stk_sem_mem_t *memory, uint32_t memory_size, uint32_t initial_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, int32_t timeout)
 Wait for a semaphore resource.
void stk_sem_signal (stk_sem_t *sem)
 Signal/Release a semaphore resource.
static bool stk_ef_is_error (uint32_t result)
 Returns true if a value returned by stk_ef_set(), stk_ef_clear(), stk_ef_wait(), or stk_ef_trywait() is an error sentinel (bit 31 set).
stk_ef_tstk_ef_create (stk_ef_mem_t *memory, uint32_t memory_size, uint32_t initial_flags)
 Create an EventFlags object (using provided memory).
void stk_ef_destroy (stk_ef_t *ef)
 Destroy an EventFlags object.
uint32_t stk_ef_set (stk_ef_t *ef, uint32_t flags)
 Set one or more flags.
uint32_t stk_ef_clear (stk_ef_t *ef, uint32_t flags)
 Clear one or more flags.
uint32_t stk_ef_get (stk_ef_t *ef)
 Read the current flags word without modifying it.
uint32_t stk_ef_wait (stk_ef_t *ef, uint32_t flags, uint32_t options, int32_t timeout)
 Wait for one or more flags to be set.
uint32_t stk_ef_trywait (stk_ef_t *ef, uint32_t flags, uint32_t options)
 Non-blocking flag poll.
stk_pipe_tstk_pipe_create (stk_pipe_mem_t *memory, uint32_t memory_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, stk_word_t data, int32_t timeout)
 Write data to the pipe.
bool stk_pipe_read (stk_pipe_t *pipe, stk_word_t *data, int32_t timeout)
 Read data from the pipe.
size_t stk_pipe_write_bulk (stk_pipe_t *pipe, const stk_word_t *src, size_t count, int32_t timeout)
 Write multiple elements to the pipe.
size_t stk_pipe_read_bulk (stk_pipe_t *pipe, stk_word_t *dst, size_t count, int32_t timeout)
 Read multiple elements from the pipe.
size_t stk_pipe_get_size (stk_pipe_t *pipe)
 Get current number of elements in the pipe.
stk_rwmutex_tstk_rwmutex_create (stk_rwmutex_mem_t *memory, uint32_t memory_size)
 Create an RWMutex (using provided memory).
void stk_rwmutex_destroy (stk_rwmutex_t *rw)
 Destroy an RWMutex.
void stk_rwmutex_read_lock (stk_rwmutex_t *rw)
 Acquire the lock for shared reading. Blocks until available.
bool stk_rwmutex_try_read_lock (stk_rwmutex_t *rw)
 Try to acquire the read lock without blocking.
bool stk_rwmutex_timed_read_lock (stk_rwmutex_t *rw, int32_t timeout)
 Try to acquire the read lock with a timeout.
void stk_rwmutex_read_unlock (stk_rwmutex_t *rw)
 Release the shared reader lock.
void stk_rwmutex_lock (stk_rwmutex_t *rw)
 Acquire the lock for exclusive writing. Blocks until available.
bool stk_rwmutex_trylock (stk_rwmutex_t *rw)
 Try to acquire the write lock without blocking.
bool stk_rwmutex_timed_lock (stk_rwmutex_t *rw, int32_t timeout)
 Try to acquire the write lock with a timeout.
void stk_rwmutex_unlock (stk_rwmutex_t *rw)
 Release the exclusive writer lock.

Detailed Description

Pure C interface for C++ API of SuperTinyKernel (STK).

Macro Definition Documentation

◆ __stk_c_stack_attr

#define __stk_c_stack_attr

Stack attribute (applies required alignment).

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

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

◆ STK_C_CPU_COUNT

#define STK_C_CPU_COUNT   (1)

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

Note
Each core usually gets its own independent kernel instance.

Definition at line 51 of file stk_c.h.

Referenced by stk_timerhost_get().

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

◆ STK_CV_IMPL_SIZE

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

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 609 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 763 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 764 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 761 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 762 of file stk_c.h.

◆ STK_EF_IMPL_SIZE

#define STK_EF_IMPL_SIZE   (STK_CV_IMPL_SIZE + 1 + (STK_SYNC_DEBUG_NAMES ? 1 : 0))

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 775 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 757 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 756 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 755 of file stk_c.h.

◆ STK_EVENT_IMPL_SIZE

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

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

◆ STK_MUTEX_IMPL_SIZE

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

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

◆ STK_NO_WAIT

#define STK_NO_WAIT   (0)

No timeout constant.

Definition at line 116 of file stk_c.h.

◆ STK_PERIODICITY_DEFAULT

#define STK_PERIODICITY_DEFAULT   (1000U)

Default tick period (1 ms).

in microseconds

Definition at line 99 of file stk_c.h.

◆ STK_PIPE_IMPL_SIZE

#define STK_PIPE_IMPL_SIZE   ((27 + (STK_SYNC_DEBUG_NAMES ? 3 : 0)) + STK_PIPE_SIZE)

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

Note
Sized for Pipe<stk_word_t, 16>. Adjust if template parameters change.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 869 of file stk_c.h.

◆ STK_PIPE_SIZE

#define STK_PIPE_SIZE   16

Size of the Pipe: Pipe<stk_word_t, STK_PIPE_SIZE>.

Note
Adjust if larger or smaller pipe is needed.

Definition at line 864 of file stk_c.h.

◆ STK_RWMUTEX_IMPL_SIZE

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

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

◆ STK_SEM_IMPL_SIZE

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

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

◆ STK_SPINLOCK_IMPL_SIZE

#define STK_SPINLOCK_IMPL_SIZE   (1)

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

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

Definition at line 568 of file stk_c.h.

◆ STK_SYNC_DEBUG_NAMES

#define STK_SYNC_DEBUG_NAMES   (0)

Enable names for synchronization primitives for debugging/tracing purpose.

Definition at line 60 of file stk_c.h.

◆ STK_TLS_GET

#define STK_TLS_GET ( type)
Value:
((type *)stk_tls_get())
void * stk_tls_get(void)
Get thread-local pointer (platform-specific slot).
Definition stk_c.cpp:338

Typed helper for getting TLS value.

Note
Expands to ((type *)stk_tls_get())
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 473 of file stk_c.h.

◆ STK_TLS_SET

#define STK_TLS_SET ( ptr)
Value:
stk_tls_set((void *)(ptr))
void stk_tls_set(void *ptr)
Set thread-local pointer.
Definition stk_c.cpp:343

Typed helper for setting TLS value.

Note
Expands to stk_tls_set((void *)(ptr))
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 478 of file stk_c.h.

◆ STK_WAIT_INFINITE

#define STK_WAIT_INFINITE   (INT32_MAX)

Infinite timeout constant.

Definition at line 112 of file stk_c.h.

Typedef Documentation

◆ EKernelState

Kernel state.

Note
It is a direct match for IKernel::EState enum.
See also
stk_kernel_get_state()
Examples
D:/SVN/private/stk/interop/c/include/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 619 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 785 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_t

typedef struct stk_event_t stk_event_t

Opaque handle to an Event instance.

Definition at line 667 of file stk_c.h.

◆ 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 91 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 527 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 instance.

◆ stk_pipe_t

typedef struct stk_pipe_t stk_pipe_t

Opaque handle to a Pipe instance.

Definition at line 879 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 947 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 724 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 579 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 108 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 95 of file stk_c.h.

◆ stk_tid_t

Task id.

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

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

Enumeration Type Documentation

◆ _EKernelState

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

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

Definition at line 268 of file stk_c.h.

268 {
enum _EKernelState EKernelState
Kernel state.
@ STK_KERNEL_STATE_INACTIVE
not ready, stk_kernel_init() must be called
Definition stk_c.h:269
@ STK_KERNEL_STATE_READY
ready to start, stk_kernel_start() must be called
Definition stk_c.h:270
@ STK_KERNEL_STATE_RUNNING
initialized and running, stk_kernel_start() was called successfully
Definition stk_c.h:271

Function Documentation

◆ stk_critical_section_enter()

void stk_critical_section_enter ( void )

Enter critical section — disable context switches on current core.

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

Definition at line 351 of file stk_c.cpp.

352{
354}
static void Enter()
Enter a critical section.
Definition stktest.cpp:74

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

Here is the call graph for this function:

◆ stk_critical_section_exit()

void stk_critical_section_exit ( void )

Leave critical section — re-enable context switches.

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

Definition at line 356 of file stk_c.cpp.

357{
359}
static void Exit()
Exit a critical section.
Definition stktest.cpp:78

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 * memory,
uint32_t memory_size )

Create a Condition Variable (using provided memory).

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

Definition at line 131 of file stk_c_sync.cpp.

132{
133 STK_ASSERT(memory != nullptr);
134 STK_ASSERT(memory_size >= sizeof(stk_cv_t));
135 if (memory_size < sizeof(stk_cv_t))
136 return nullptr;
137
138 // construct in-place within the provided memory
139 return (stk_cv_t *)new (memory->data) stk_cv_t{};
140}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:330
stk_word_t data[(7+((0) ? 1 :0))]
Definition stk_c.h:614

References stk_cv_mem_t::data, and STK_ASSERT.

◆ stk_cv_destroy()

void stk_cv_destroy ( stk_cv_t * cv)

Destroy a Condition Variable.

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

Definition at line 142 of file stk_c_sync.cpp.

143{
144 if (cv != nullptr)
145 cv->~stk_cv_t();
146}

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

164{
165 STK_ASSERT(cv != nullptr);
166
167 cv->handle.NotifyAll();
168}
void NotifyAll()
Wake all waiting tasks.
ConditionVariable handle

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

Here is the call graph for this function:

◆ stk_cv_notify_one()

void stk_cv_notify_one ( stk_cv_t * cv)

Wake one task waiting on the condition variable.

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

Definition at line 156 of file stk_c_sync.cpp.

157{
158 STK_ASSERT(cv != nullptr);
159
160 cv->handle.NotifyOne();
161}
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,
int32_t timeout )

Wait for a signal on the condition variable.

Atomically releases the mutex and suspends the task. The mutex is re-acquired before returning.

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

Definition at line 148 of file stk_c_sync.cpp.

149{
150 STK_ASSERT(cv != nullptr);
151 STK_ASSERT(mtx != nullptr);
152
153 return cv->handle.Wait(mtx->handle, timeout);
154}
bool Wait(IMutex &mutex, Timeout timeout=WAIT_INFINITE)
Wait for a signal.

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

Here is the call graph for this function:

◆ stk_delay()

void stk_delay ( uint32_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 328 of file stk_c.cpp.

328{ stk::Delay(ticks); }
void Delay(uint32_t ticks)
Delay calling process by busy-waiting until the deadline expires.
Definition stk_helper.h:342

References stk::Delay().

Here is the call graph for this function:

◆ stk_delay_ms()

void stk_delay_ms ( uint32_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 330 of file stk_c.cpp.

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

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

308{
309 STK_ASSERT(ef != nullptr);
310
311 return ef->handle.Clear(flags);
312}
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 * memory,
uint32_t memory_size,
uint32_t initial_flags )

Create an EventFlags object (using provided memory).

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

Definition at line 284 of file stk_c_sync.cpp.

285{
286 STK_ASSERT(memory != nullptr);
287 STK_ASSERT(memory_size >= sizeof(stk_ef_t));
288 if (memory_size < sizeof(stk_ef_t))
289 return nullptr;
290
291 return (stk_ef_t *)new (memory->data) stk_ef_t(initial_flags);
292}
struct stk_ef_t stk_ef_t
Opaque handle to an EventFlags instance.
Definition stk_c.h:785
stk_word_t data[((7+((0) ? 1 :0))+1+((0) ? 1 :0))]
Definition stk_c.h:780

References stk_ef_mem_t::data, and STK_ASSERT.

◆ stk_ef_destroy()

void stk_ef_destroy ( stk_ef_t * ef)

Destroy an EventFlags object.

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

Definition at line 294 of file stk_c_sync.cpp.

295{
296 if (ef != nullptr)
297 ef->~stk_ef_t();
298}

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

315{
316 STK_ASSERT(ef != nullptr);
317
318 return ef->handle.Get();
319}
uint32_t Get() const
Read the current flags word without modifying it.

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

Here is the call graph for this function:

◆ stk_ef_is_error()

bool stk_ef_is_error ( uint32_t result)
inlinestatic

Returns true if a value returned by stk_ef_set(), stk_ef_clear(), stk_ef_wait(), or stk_ef_trywait() is an error sentinel (bit 31 set).

< Mask for testing any error; bit 31 set means error

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

Definition at line 769 of file stk_c.h.

769{ return ((result & STK_EF_ERROR_MASK) != 0U); }
#define STK_EF_ERROR_MASK
Definition stk_c.h:764

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]ef:EventFlagshandle.
[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 300 of file stk_c_sync.cpp.

301{
302 STK_ASSERT(ef != nullptr);
303
304 return ef->handle.Set(flags);
305}
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 328 of file stk_c_sync.cpp.

329{
330 STK_ASSERT(ef != nullptr);
331
332 return ef->handle.TryWait(flags, options);
333}
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,
int32_t timeout )

Wait for one or more flags to be set.

Suspends the calling task until the requested flag condition is satisfied or the timeout expires. On success, matched bits are atomically cleared unless STK_EF_OPT_NO_CLEAR is set in options.

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

Definition at line 321 of file stk_c_sync.cpp.

322{
323 STK_ASSERT(ef != nullptr);
324
325 return ef->handle.Wait(flags, options, timeout);
326}
uint32_t Wait(uint32_t flags, uint32_t options=OPT_WAIT_ANY, Timeout timeout=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 * memory,
uint32_t memory_size,
bool manual_reset )

Create an Event (using provided memory).

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

Definition at line 181 of file stk_c_sync.cpp.

182{
183 STK_ASSERT(memory != nullptr);
184 STK_ASSERT(memory_size >= sizeof(stk_event_t));
185 if (memory_size < sizeof(stk_event_t))
186 return nullptr;
187
188 return (stk_event_t *)new (memory->data) stk_event_t(manual_reset);
189}
struct stk_event_t stk_event_t
Opaque handle to an Event instance.
Definition stk_c.h:667
stk_word_t data[(8+((0) ? 1 :0))]
Definition stk_c.h:662

References stk_event_mem_t::data, and STK_ASSERT.

◆ stk_event_destroy()

void stk_event_destroy ( stk_event_t * ev)

Destroy an Event.

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

Definition at line 191 of file stk_c_sync.cpp.

192{
193 if (ev != nullptr)
194 ev->~stk_event_t();
195}

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

226{
227 STK_ASSERT(ev != nullptr);
228
229 ev->handle.Pulse();
230}
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()

void stk_event_reset ( stk_event_t * ev)

Reset the event to non-signaled state.

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

Definition at line 218 of file stk_c_sync.cpp.

219{
220 STK_ASSERT(ev != nullptr);
221
222 ev->handle.Reset();
223}
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()

void stk_event_set ( stk_event_t * ev)

Set the event to signaled state.

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

Definition at line 211 of file stk_c_sync.cpp.

212{
213 STK_ASSERT(ev != nullptr);
214
215 ev->handle.Set();
216}
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 204 of file stk_c_sync.cpp.

205{
206 STK_ASSERT(ev != nullptr);
207
208 return ev->handle.TryWait();
209}
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,
int32_t timeout )

Wait for the event to become signaled.

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

Definition at line 197 of file stk_c_sync.cpp.

198{
199 STK_ASSERT(ev != nullptr);
200
201 return ev->handle.Wait(timeout);
202}
bool Wait(Timeout timeout=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_kernel_add_task()

void stk_kernel_add_task ( stk_kernel_t * k,
stk_task_t * task )

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

Parameters
[in]kKernel handle.
[in]taskTask 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 225 of file stk_c.cpp.

226{
227 STK_ASSERT(k != nullptr);
228 STK_ASSERT(task != nullptr);
229
230 reinterpret_cast<stk::IKernel *>(k)->AddTask(&task->handle);
231}
Interface for the implementation of the kernel of the scheduler. It supports Soft and Hard Real-Time ...
Definition stk_common.h:854
TaskWrapper handle
Definition stk_c.cpp:72

References stk_task_t::handle, and STK_ASSERT.

◆ stk_kernel_add_task_hrt()

void stk_kernel_add_task_hrt ( stk_kernel_t * k,
stk_task_t * task,
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]taskTask 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 241 of file stk_c.cpp.

246{
247 STK_ASSERT(k != nullptr);
248 STK_ASSERT(task != nullptr);
249
250 reinterpret_cast<stk::IKernel *>(k)->AddTask(
251 &task->handle,
252 periodicity_ticks,
253 deadline_ticks,
254 start_delay_ticks);
255}

References stk_task_t::handle, and STK_ASSERT.

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

154{
155 switch (core_nr)
156 {
157#ifdef STK_C_KERNEL_TYPE_CPU_0
159#endif
160#ifdef STK_C_KERNEL_TYPE_CPU_1
162#endif
163#ifdef STK_C_KERNEL_TYPE_CPU_2
165#endif
166#ifdef STK_C_KERNEL_TYPE_CPU_3
168#endif
169#ifdef STK_C_KERNEL_TYPE_CPU_4
171#endif
172#ifdef STK_C_KERNEL_TYPE_CPU_5
174#endif
175#ifdef STK_C_KERNEL_TYPE_CPU_6
177#endif
178#ifdef STK_C_KERNEL_TYPE_CPU_7
180#endif
181 default:
182 return nullptr;
183 }
184}
#define STK_KERNEL_CASE(X)
Definition stk_c.cpp:142

References STK_KERNEL_CASE.

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

187{
188 STK_ASSERT(k != nullptr);
189
190 reinterpret_cast<IKernel *>(k)->~IKernel();
191}

References STK_ASSERT.

◆ stk_kernel_get_state()

EKernelState stk_kernel_get_state ( const stk_kernel_t * k)

Get state of the scheduler.

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

Definition at line 210 of file stk_c.cpp.

211{
212 STK_ASSERT(k != nullptr);
213
214 return static_cast<EKernelState>(reinterpret_cast<const stk::IKernel *>(k)->GetState());
215}
virtual EState GetState() const =0
Get a snapshot of the kernel state.

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

197{
198 STK_ASSERT(k != nullptr);
199
200 reinterpret_cast<stk::IKernel *>(k)->Initialize(tick_period_us);
201}

References STK_ASSERT.

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

218{
219 STK_ASSERT(k != nullptr);
220
222 reinterpret_cast<stk::IKernel *>(const_cast<stk_kernel_t *>(k))->GetSwitchStrategy());
223}
struct stk_kernel_t stk_kernel_t
Opaque handle to a kernel instance.
Definition stk_c.h:91
static SchedulabilityCheckResult< _TaskCount > IsSchedulableWCRT(const ITaskSwitchStrategy *strategy)
Perform WCRT schedulability analysis on the task set registered with strategy.

References stk::SchedulabilityCheck::IsSchedulableWCRT(), 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 * task )

Remove finished task from dynamic kernel.

Parameters
[in]kKernel handle.
[in]taskTask 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 233 of file stk_c.cpp.

234{
235 STK_ASSERT(k != nullptr);
236 STK_ASSERT(task != nullptr);
237
238 reinterpret_cast<stk::IKernel *>(k)->RemoveTask(&task->handle);
239}

References stk_task_t::handle, and STK_ASSERT.

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

204{
205 STK_ASSERT(k != nullptr);
206
207 reinterpret_cast<stk::IKernel *>(k)->Start();
208}

References STK_ASSERT.

◆ stk_mutex_create()

stk_mutex_t * stk_mutex_create ( stk_mutex_mem_t * memory,
uint32_t memory_size )

Create a Mutex (using provided memory).

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

Definition at line 36 of file stk_c_sync.cpp.

37{
38 STK_ASSERT(memory != nullptr);
39 STK_ASSERT(memory_size >= sizeof(stk_mutex_t));
40 if (memory_size < sizeof(stk_mutex_t))
41 return nullptr;
42
43 // construct in-place within the provided memory
44 return (stk_mutex_t *)new (memory->data) stk_mutex_t{};
45}
stk_word_t data[(10+((0) ? 1 :0))]
Definition stk_c.h:522

References stk_mutex_mem_t::data, and STK_ASSERT.

◆ stk_mutex_destroy()

void stk_mutex_destroy ( stk_mutex_t * mtx)

Destroy a Mutex.

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

Definition at line 47 of file stk_c_sync.cpp.

48{
49 if (mtx != NULL)
50 mtx->~stk_mutex_t();
51}

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

54{
55 STK_ASSERT(mtx != NULL);
56
57 mtx->handle.Lock();
58}
void Lock()
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,
int32_t timeout )

Try to lock the mutex with a timeout.

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

Definition at line 74 of file stk_c_sync.cpp.

75{
76 STK_ASSERT(mtx != NULL);
77
78 return mtx->handle.TimedLock(timeout);
79}
bool TimedLock(Timeout timeout)
Acquire lock.

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

Here is the call graph for this function:

◆ stk_mutex_trylock()

bool stk_mutex_trylock ( stk_mutex_t * mtx)

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

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

Definition at line 60 of file stk_c_sync.cpp.

61{
62 STK_ASSERT(mtx != NULL);
63
64 return mtx->handle.TryLock();
65}
bool TryLock()
Acquire the lock.

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

Here is the call graph for this function:

◆ stk_mutex_unlock()

void stk_mutex_unlock ( stk_mutex_t * mtx)

Unlock the mutex.

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

Definition at line 67 of file stk_c_sync.cpp.

68{
69 STK_ASSERT(mtx != NULL);
70
71 mtx->handle.Unlock();
72}
void Unlock()
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 * memory,
uint32_t memory_size )

Create a Pipe (using provided memory).

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

Definition at line 345 of file stk_c_sync.cpp.

346{
347 STK_ASSERT(memory != nullptr);
348 STK_ASSERT(memory_size >= sizeof(stk_pipe_t));
349 if (memory_size < sizeof(stk_pipe_t))
350 return nullptr;
351
352 return (stk_pipe_t *)new (memory->data) stk_pipe_t{};
353}
stk_word_t data[((27+((0) ? 3 :0))+16)]
Definition stk_c.h:874

References stk_pipe_mem_t::data, and STK_ASSERT.

◆ stk_pipe_destroy()

void stk_pipe_destroy ( stk_pipe_t * pipe)

Destroy a Pipe.

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

Definition at line 355 of file stk_c_sync.cpp.

356{
357 if (pipe != nullptr)
358 pipe->~stk_pipe_t();
359}

◆ stk_pipe_get_size()

size_t stk_pipe_get_size ( stk_pipe_t * pipe)

Get current number of elements in the pipe.

Parameters
[in]pipePipe handle.
Returns
Current element count.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 390 of file stk_c_sync.cpp.

391{
392 STK_ASSERT(pipe != nullptr);
393
394 return pipe->handle.GetSize();
395}
size_t GetSize() const
Get the current number of elements in the pipe.

References stk::sync::Pipe< T, N >::GetSize(), stk_pipe_t::handle, and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_read()

bool stk_pipe_read ( stk_pipe_t * pipe,
stk_word_t * data,
int32_t timeout )

Read data from the pipe.

Parameters
[in]pipePipe handle.
[out]dataPointer to variable receiving the data.
[in]timeoutMax time to wait in milliseconds.
Returns
True if successful, False on timeout.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 368 of file stk_c_sync.cpp.

369{
370 STK_ASSERT(pipe != nullptr);
371 STK_ASSERT(data != nullptr);
372
373 return pipe->handle.Read(*data, timeout);
374}
bool Read(T &data, Timeout timeout=WAIT_INFINITE)
Read data from the pipe.

References stk_pipe_t::handle, stk::sync::Pipe< T, N >::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,
stk_word_t * dst,
size_t count,
int32_t timeout )

Read multiple elements from the pipe.

Parameters
[in]pipePipe handle.
[out]dstPointer to destination array.
[in]countNumber of elements to read.
[in]timeoutMax time to wait in milliseconds.
Returns
Number of elements actually read.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 383 of file stk_c_sync.cpp.

384{
385 STK_ASSERT(pipe != nullptr);
386
387 return pipe->handle.ReadBulk(dst, count, timeout);
388}
size_t ReadBulk(T *dst, size_t count, Timeout timeout=WAIT_INFINITE)
Read multiple elements from the pipe.

References stk_pipe_t::handle, stk::sync::Pipe< T, N >::ReadBulk(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_pipe_write()

bool stk_pipe_write ( stk_pipe_t * pipe,
stk_word_t data,
int32_t timeout )

Write data to the pipe.

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

Definition at line 361 of file stk_c_sync.cpp.

362{
363 STK_ASSERT(pipe != nullptr);
364
365 return pipe->handle.Write(data, timeout);
366}
bool Write(const T &data, Timeout timeout=WAIT_INFINITE)
Write data to the pipe.

References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe< T, N >::Write().

Here is the call graph for this function:

◆ stk_pipe_write_bulk()

size_t stk_pipe_write_bulk ( stk_pipe_t * pipe,
const stk_word_t * src,
size_t count,
int32_t timeout )

Write multiple elements to the pipe.

Parameters
[in]pipePipe handle.
[in]srcPointer to source array.
[in]countNumber of elements to write.
[in]timeoutMax time to wait in milliseconds.
Returns
Number of elements actually written.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 376 of file stk_c_sync.cpp.

377{
378 STK_ASSERT(pipe != nullptr);
379
380 return pipe->handle.WriteBulk(src, count, timeout);
381}
size_t WriteBulk(const T *src, size_t count, Timeout timeout=WAIT_INFINITE)
Write multiple elements to the pipe.

References stk_pipe_t::handle, STK_ASSERT, and stk::sync::Pipe< T, N >::WriteBulk().

Here is the call graph for this function:

◆ stk_rwmutex_create()

stk_rwmutex_t * stk_rwmutex_create ( stk_rwmutex_mem_t * memory,
uint32_t memory_size )

Create an RWMutex (using provided memory).

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

Definition at line 405 of file stk_c_sync.cpp.

406{
407 STK_ASSERT(memory != nullptr);
408 STK_ASSERT(memory_size >= sizeof(stk_rwmutex_t));
409 if (memory_size < sizeof(stk_rwmutex_t))
410 return nullptr;
411
412 return (stk_rwmutex_t *)new (memory->data) stk_rwmutex_t{};
413}
stk_word_t data[(17+((0) ? 3 :0))]
Definition stk_c.h:942

References stk_rwmutex_mem_t::data, and STK_ASSERT.

◆ stk_rwmutex_destroy()

void stk_rwmutex_destroy ( stk_rwmutex_t * rw)

Destroy an RWMutex.

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

Definition at line 415 of file stk_c_sync.cpp.

416{
417 if (rw != nullptr)
418 rw->~stk_rwmutex_t();
419}

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

450{
451 STK_ASSERT(rw != nullptr);
452
453 rw->handle.Lock();
454}
void Lock()
Acquire the lock for exclusive writing (IMutex interface).
sync::RWMutex handle

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

Here is the call graph for this function:

◆ stk_rwmutex_read_lock()

void stk_rwmutex_read_lock ( stk_rwmutex_t * rw)

Acquire the lock for shared reading. Blocks until available.

Blocks if a writer is currently active or writers are waiting (Writer Preference Policy).

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

Definition at line 421 of file stk_c_sync.cpp.

422{
423 STK_ASSERT(rw != nullptr);
424
425 rw->handle.ReadLock();
426}
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 442 of file stk_c_sync.cpp.

443{
444 STK_ASSERT(rw != nullptr);
445
446 rw->handle.ReadUnlock();
447}
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,
int32_t timeout )

Try to acquire the write lock with a timeout.

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

Definition at line 463 of file stk_c_sync.cpp.

464{
465 STK_ASSERT(rw != nullptr);
466
467 return rw->handle.TimedLock(timeout);
468}
bool TimedLock(Timeout timeout)
Acquire the lock for exclusive writing with a timeout.

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

Here is the call graph for this function:

◆ stk_rwmutex_timed_read_lock()

bool stk_rwmutex_timed_read_lock ( stk_rwmutex_t * rw,
int32_t timeout )

Try to acquire the read lock with a timeout.

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

Definition at line 435 of file stk_c_sync.cpp.

436{
437 STK_ASSERT(rw != nullptr);
438
439 return rw->handle.TimedReadLock(timeout);
440}
bool TimedReadLock(Timeout timeout)
Acquire the lock for shared reading with a timeout.

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

Here is the call graph for this function:

◆ stk_rwmutex_try_read_lock()

bool stk_rwmutex_try_read_lock ( stk_rwmutex_t * rw)

Try to acquire the read lock without blocking.

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

Definition at line 428 of file stk_c_sync.cpp.

429{
430 STK_ASSERT(rw != nullptr);
431
432 return rw->handle.TryReadLock();
433}
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 456 of file stk_c_sync.cpp.

457{
458 STK_ASSERT(rw != nullptr);
459
460 return rw->handle.TryLock();
461}
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 470 of file stk_c_sync.cpp.

471{
472 STK_ASSERT(rw != nullptr);
473
474 rw->handle.Unlock();
475}
void Unlock()
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 * memory,
uint32_t memory_size,
uint32_t initial_count )

Create a Semaphore (using provided memory).

Parameters
[in]memoryPointer to static memory container.
[in]memory_sizeSize of the container (must be >= sizeof(stk_sem_mem_t)).
[in]initial_countStarting value of the resource counter.
Returns
Semaphore handle.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 243 of file stk_c_sync.cpp.

244{
245 STK_ASSERT(memory != nullptr);
246 STK_ASSERT(memory_size >= sizeof(stk_sem_t));
247 if (memory_size < sizeof(stk_sem_t))
248 return nullptr;
249
250 return (stk_sem_t *)new (memory->data) stk_sem_t(initial_count);
251}
struct stk_sem_t stk_sem_t
Opaque handle to a Semaphore instance.
Definition stk_c.h:724
stk_word_t data[(8+((0) ? 1 :0))]
Definition stk_c.h:719

References stk_sem_mem_t::data, and STK_ASSERT.

◆ stk_sem_destroy()

void stk_sem_destroy ( stk_sem_t * sem)

Destroy a Semaphore.

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

Definition at line 253 of file stk_c_sync.cpp.

254{
255 if (sem != nullptr)
256 sem->~stk_sem_t();
257}

◆ stk_sem_signal()

void stk_sem_signal ( stk_sem_t * sem)

Signal/Release a semaphore resource.

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

Definition at line 266 of file stk_c_sync.cpp.

267{
268 STK_ASSERT(sem != nullptr);
269
270 sem->handle.Signal();
271}
void Signal()
Post a signal (increment counter).
Semaphore handle

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

Here is the call graph for this function:

◆ stk_sem_wait()

bool stk_sem_wait ( stk_sem_t * sem,
int32_t timeout )

Wait for a semaphore resource.

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

Definition at line 259 of file stk_c_sync.cpp.

260{
261 STK_ASSERT(sem != nullptr);
262
263 return sem->handle.Wait(timeout);
264}
bool Wait(Timeout timeout=WAIT_INFINITE)
Wait for a signal (decrement counter).

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

Here is the call graph for this function:

◆ stk_sleep()

void stk_sleep ( uint32_t ticks)

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

Parameters
[in]msTicks 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 329 of file stk_c.cpp.

329{ stk::Sleep(ticks); }
void Sleep(uint32_t ticks)
Put calling process into a sleep state.
Definition stk_helper.h:298

References stk::Sleep().

Here is the call graph for this function:

◆ stk_sleep_ms()

void stk_sleep_ms ( uint32_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 331 of file stk_c.cpp.

331{ stk::SleepMs(ms); }
static void SleepMs(uint32_t ms)
Put calling process into a sleep state.
Definition stk_helper.h:311

References stk::SleepMs().

Here is the call graph for this function:

◆ stk_sleep_until()

void stk_sleep_until ( int64_t ts)

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

Parameters
[in]tsAbsolute time, a deadline for a sleep period.
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 332 of file stk_c.cpp.

332{ stk::SleepUntil(ts); }
void SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
Definition stk_helper.h:322

References stk::SleepUntil().

Here is the call graph for this function:

◆ stk_spinlock_create()

stk_spinlock_t * stk_spinlock_create ( stk_spinlock_mem_t * memory,
uint32_t memory_size )

Create a recursive SpinLock.

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

Definition at line 89 of file stk_c_sync.cpp.

90{
91 STK_ASSERT(memory != nullptr);
92 STK_ASSERT(memory_size >= sizeof(stk_spinlock_t));
93 if (memory_size < sizeof(stk_spinlock_t))
94 return nullptr;
95
96 return (stk_spinlock_t *)new (memory->data) stk_spinlock_t();
97}
struct stk_spinlock_t stk_spinlock_t
Opaque handle to a SpinLock instance.
Definition stk_c.h:579
stk_word_t data[(1)]
Definition stk_c.h:574

References stk_spinlock_mem_t::data, and STK_ASSERT.

◆ stk_spinlock_destroy()

void stk_spinlock_destroy ( stk_spinlock_t * lock)

Destroy the SpinLock.

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

Definition at line 99 of file stk_c_sync.cpp.

100{
101 if (lock != nullptr)
102 lock->~stk_spinlock_t();
103}

◆ stk_spinlock_lock()

void stk_spinlock_lock ( stk_spinlock_t * lock)

Acquire the SpinLock (recursive).

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

Definition at line 105 of file stk_c_sync.cpp.

106{
107 STK_ASSERT(lock != nullptr);
108 lock->handle.Lock();
109}
void Lock()
Acquire the lock.
sync::SpinLock handle

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

Here is the call graph for this function:

◆ stk_spinlock_trylock()

bool stk_spinlock_trylock ( stk_spinlock_t * lock)

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

112{
113 STK_ASSERT(lock != nullptr);
114 return lock->handle.TryLock();
115}
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 * lock)

Release the SpinLock.

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

Definition at line 117 of file stk_c_sync.cpp.

118{
119 STK_ASSERT(lock != nullptr);
120 lock->handle.Unlock();
121}
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_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 260 of file stk_c.cpp.

264{
265 STK_ASSERT(entry != nullptr);
266 STK_ASSERT(stack != nullptr);
267 STK_ASSERT(stack_size != 0);
268
269 return reinterpret_cast<stk_task_t *>(AllocateTask(entry, arg, stack, stack_size, ACCESS_PRIVILEGED));
270}
static stk_task_t * AllocateTask(stk_task_entry_t entry, void *arg, stk_word_t *stack, uint32_t stack_size, EAccessMode mode)
Definition stk_c.cpp:92
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
Definition stk_common.h:33

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

276{
277 STK_ASSERT(entry != nullptr);
278 STK_ASSERT(stack != nullptr);
279 STK_ASSERT(stack_size != 0);
280
281 return reinterpret_cast<stk_task_t *>(AllocateTask(entry, arg, stack, stack_size, ACCESS_USER));
282}
@ ACCESS_USER
Unprivileged access mode (access to some hardware is restricted, see CPU manual for details).
Definition stk_common.h:32

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

Here is the call graph for this function:

◆ stk_task_destroy()

void stk_task_destroy ( stk_task_t * task)

Destroy dynamically created task object.

Parameters
[in]taskTask 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 313 of file stk_c.cpp.

314{
315 STK_ASSERT(task != nullptr);
316
317 FreeTask(task);
318}
static void FreeTask(const stk_task_t *task)
Definition stk_c.cpp:118

References FreeTask(), and STK_ASSERT.

Here is the call graph for this function:

◆ stk_task_set_id()

void stk_task_set_id ( stk_task_t * task,
uint32_t tid )

Assign application-defined task ID (for tracing/debugging).

Parameters
[in]taskTask handle.
[in]tidArbitrary 32-bit task identifier.
Examples
D:/SVN/private/stk/interop/c/include/stk_c.h.

Definition at line 299 of file stk_c.cpp.

300{
301 STK_ASSERT(task != nullptr);
302
303 task->handle.SetId(tid);
304}
void SetId(stk_tid_t tid)
Definition stk_c.cpp:54

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

Here is the call graph for this function:

◆ stk_task_set_name()

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

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

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

Definition at line 306 of file stk_c.cpp.

307{
308 STK_ASSERT(task != nullptr);
309
310 task->handle.SetName(tname);
311}
void SetName(const char *tname)
Definition stk_c.cpp:55

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

Here is the call graph for this function:

◆ stk_task_set_priority()

void stk_task_set_priority ( stk_task_t * task,
uint8_t priority )

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

Parameters
[in]taskTask 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 292 of file stk_c.cpp.

293{
294 STK_ASSERT(priority <= 31);
295
296 stk_task_set_weight(task, priority);
297}
void stk_task_set_weight(stk_task_t *task, uint32_t weight)
Set task weight (used only by Smooth Weighted Round Robin).
Definition stk_c.cpp:284

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 * task,
uint32_t weight )

Set task weight (used only by Smooth Weighted Round Robin).

Parameters
[in]taskTask 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 284 of file stk_c.cpp.

285{
286 STK_ASSERT(task != nullptr);
287 STK_ASSERT(weight != 0);
288
289 task->handle.SetWeight(weight);
290}
void SetWeight(int32_t weight)
Definition stk_c.cpp:53

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

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

325{ return stk::GetTickResolution(); }
int32_t GetTickResolution()
Get number of microseconds in one tick.
Definition stk_helper.h:258

References stk::GetTickResolution().

Here is the call graph for this function:

◆ stk_ticks()

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

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

References stk::GetTicks().

Here is the call graph for this function:

◆ stk_ticks_from_ms()

int64_t stk_ticks_from_ms ( int64_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 327 of file stk_c.cpp.

static int64_t stk_ticks_from_ms_r(int64_t msec, int32_t resolution)
Get ticks from milliseconds using an explicit tick resolution.
Definition stk_c.h:378

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

Here is the call graph for this function:

◆ stk_ticks_from_ms_r()

int64_t stk_ticks_from_ms_r ( int64_t msec,
int32_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 378 of file stk_c.h.

379{
380 return msec * 1000 / resolution;
381}

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

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

References stk::GetTid().

Here is the call graph for this function:

◆ stk_time_now_ms()

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

326{ return stk::GetTimeNowMs(); }
static int64_t GetTimeNowMs()
Get current time in milliseconds since kernel start.
Definition stk_helper.h:281

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.

Definition at line 338 of file stk_c.cpp.

339{
340 return hw::GetTlsPtr<void *>();
341}
__stk_forceinline _TyTls * GetTlsPtr()
Type-safe wrapper around GetTls() that casts the raw TP value to a typed pointer.
Definition stk_arch.h:158

References stk::hw::GetTlsPtr().

Here is the call graph for this function:

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

Definition at line 343 of file stk_c.cpp.

344{
345 hw::SetTlsPtr(ptr);
346}
__stk_forceinline void SetTlsPtr(const _TyTls *tp)
Type-safe wrapper around SetTls() that stores a typed pointer as the raw TP value.
Definition stk_arch.h:170

References stk::hw::SetTlsPtr().

Here is the call graph for this function:

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

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

References stk::Yield().

Here is the call graph for this function: