52#define PT_CHECK(call) do { int rc_ = (call); STK_C_ASSERT(rc_ == 0); (void)rc_; } while (0)
56 const uint32_t
id = (uint32_t)(uintptr_t)arg;
57 const uint32_t next = (
id + 1U) %
LED_MAX;
103 for (uint32_t i = 0; i <
LED_MAX; i++)
110 sizeof(g_ThreadStack[i])));
120 for (uint32_t i = 0; i <
LED_MAX; i++)
void Led_InitAll(bool state)
void Led_SwitchOnExclusive(LedId led)
C language binding/interface for SuperTinyKernel RTOS.
POSIX-named entry point for the STK pthread shim (stk_c_pthread.h).
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.
#define STK_GET_STACK_FROM_POOL(name, task_id)
Retrieves the base stack pointer for a specific task ID from a stack pool.
stk_tick_t stk_ticks_from_ms(stk_time_t msec)
Get ticks from milliseconds using current kernel tick resolution.
struct stk_kernel_t stk_kernel_t
Opaque handle to a kernel instance.
void stk_kernel_start(stk_kernel_t *k)
Start the scheduler - never returns.
stk_add_result_t stk_kernel_add_task(stk_kernel_t *k, stk_task_t *tsk)
Add task to non-HRT kernel (static or dynamic).
#define STK_DEFINE_STACK_POOL(name, max_tasks, stack_size)
Allocates a statically bound, multi-dimensional stack pool for tasks.
#define STK_PERIODICITY_DEFAULT
Default tick period (1 ms).
void stk_kernel_init(stk_kernel_t *k, uint32_t tick_period_us)
Initialize kernel with given tick period.
stk_tick_t stk_ticks(void)
Returns number of ticks elapsed since kernel start.
void stk_critical_section_enter()
Enter global critical section - disable context switches on current core.
int64_t stk_tick_t
Ticks value.
stk_kernel_t * stk_kernel_create(uint8_t core_nr)
Create kernel.
#define STK_C_ASSERT(e)
Assertion macro used inside STK C bindings.
bool stk_sleep_until(stk_tick_t ts)
Put current task to sleep (non-HRT kernels only).
void stk_critical_section_exit()
Leave global critical section - re-enable context switches.
int pthread_attr_init(pthread_attr_t *attr)
Initialize a thread attributes object with default values (default stack size, no external stack,...
int pthread_mutex_lock(pthread_mutex_t *mutex)
Lock a mutex, blocking until it becomes available.
int pthread_join(pthread_t thread, void **retval)
Block until the given joinable thread finishes, then reclaim its resources.
#define PTHREAD_CREATE_PRIVILEGED_NP
int pthread_attr_destroy(pthread_attr_t *attr)
Destroy a thread attributes object (no-op; no owned resources).
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Initialize a mutex.
int pthread_attr_setprivileged_np(pthread_attr_t *attr, int mode)
Non-portable: select the STK access mode of threads created with attr.
struct pthread_stk_ctrl_t * pthread_t
Opaque thread handle.
#define PTHREAD_MUTEX_INITIALIZER
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
Atomically unlock mutex and wait for a signal; re-locks mutex before returning.
int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize)
Supply an external, caller-owned stack buffer for the thread.
int pthread_mutex_unlock(pthread_mutex_t *mutex)
Unlock a mutex held by the calling thread.
#define PTHREAD_COND_INITIALIZER
void stk_pthread_bind_kernel(void *kernel)
Bind the STK kernel instance that pthread_create() will add new threads to.
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
Initialize a condition variable.
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
Create and start a new thread.
int pthread_cond_broadcast(pthread_cond_t *cond)
Wake all threads waiting on cond (no effect if none is waiting).
Thread creation attributes.
A pthread condition variable.
static stk::Ticks g_Timeline
static void MainTask(void *arg)
static void * LedThread(void *arg)
static pthread_mutex_t g_Lock
static pthread_t g_Threads[LED_MAX]
static pthread_cond_t g_Turn