Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
kernel.h File Reference

Public kernel APIs. More...

#include <kernel_includes.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <toolchain.h>
#include <tracing/tracing_macros.h>
#include <tracing/tracing.h>
#include <syscalls/kernel.h>

Go to the source code of this file.

Data Structures

struct  k_futex
 futex structure More...
 
struct  k_event
 
struct  k_fifo
 
struct  k_lifo
 
struct  k_mutex
 
struct  k_condvar
 
struct  k_work
 A structure used to submit work. More...
 
struct  k_work_delayable
 A structure used to submit work after a delay. More...
 
struct  k_work_sync
 A structure holding internal state for a pending synchronous operation on a work item or queue. More...
 
struct  k_work_queue_config
 A structure holding optional configuration items for a work queue. More...
 
struct  k_work_q
 A structure used to hold work until it can be processed. More...
 
struct  k_delayed_work
 
struct  k_msgq
 Message Queue Structure. More...
 
struct  k_msgq_attrs
 Message Queue Attributes. More...
 
struct  k_mbox_msg
 Mailbox Message Structure. More...
 
struct  k_mbox
 Mailbox Structure. More...
 
struct  k_pipe
 
struct  k_heap
 
struct  k_poll_signal
 
struct  k_poll_event
 Poll Event. More...
 

Macros

#define K_ANY   NULL
 
#define K_END   NULL
 
#define K_PRIO_COOP(x)   (-(CONFIG_NUM_COOP_PRIORITIES - (x)))
 
#define K_PRIO_PREEMPT(x)   (x)
 
#define K_HIGHEST_THREAD_PRIO   (-CONFIG_NUM_COOP_PRIORITIES)
 
#define K_LOWEST_THREAD_PRIO   CONFIG_NUM_PREEMPT_PRIORITIES
 
#define K_IDLE_PRIO   K_LOWEST_THREAD_PRIO
 
#define K_HIGHEST_APPLICATION_THREAD_PRIO   (K_HIGHEST_THREAD_PRIO)
 
#define K_LOWEST_APPLICATION_THREAD_PRIO   (K_LOWEST_THREAD_PRIO - 1)
 
#define K_ESSENTIAL   (BIT(0))
 system thread that must not abort More...
 
#define K_FP_REGS   (BIT(1))
 FPU registers are managed by context switch. More...
 
#define K_USER   (BIT(2))
 user mode thread More...
 
#define K_INHERIT_PERMS   (BIT(3))
 Inherit Permissions. More...
 
#define K_CALLBACK_STATE   (BIT(4))
 Callback item state. More...
 
#define k_thread_access_grant(thread, ...)    FOR_EACH_FIXED_ARG(k_object_access_grant, (;), thread, __VA_ARGS__)
 Grant a thread access to a set of kernel objects. More...
 
#define K_THREAD_DEFINE(name, stack_size, entry, p1, p2, p3, prio, options, delay)
 Statically define and initialize a thread. More...
 
#define K_NO_WAIT   Z_TIMEOUT_NO_WAIT
 Generate null timeout delay. More...
 
#define K_NSEC(t)   Z_TIMEOUT_NS(t)
 Generate timeout delay from nanoseconds. More...
 
#define K_USEC(t)   Z_TIMEOUT_US(t)
 Generate timeout delay from microseconds. More...
 
#define K_CYC(t)   Z_TIMEOUT_CYC(t)
 Generate timeout delay from cycles. More...
 
#define K_TICKS(t)   Z_TIMEOUT_TICKS(t)
 Generate timeout delay from system ticks. More...
 
#define K_MSEC(ms)   Z_TIMEOUT_MS(ms)
 Generate timeout delay from milliseconds. More...
 
#define K_SECONDS(s)   K_MSEC((s) * MSEC_PER_SEC)
 Generate timeout delay from seconds. More...
 
#define K_MINUTES(m)   K_SECONDS((m) * 60)
 Generate timeout delay from minutes. More...
 
#define K_HOURS(h)   K_MINUTES((h) * 60)
 Generate timeout delay from hours. More...
 
#define K_FOREVER   Z_FOREVER
 Generate infinite timeout delay. More...
 
#define K_TIMER_DEFINE(name, expiry_fn, stop_fn)
 Statically define and initialize a timer. More...
 
#define K_QUEUE_DEFINE(name)
 Statically define and initialize a queue. More...
 
#define K_EVENT_DEFINE(name)
 Statically define and initialize an event object. More...
 
#define k_fifo_init(fifo)
 Initialize a FIFO queue. More...
 
#define k_fifo_cancel_wait(fifo)
 Cancel waiting on a FIFO queue. More...
 
#define k_fifo_put(fifo, data)
 Add an element to a FIFO queue. More...
 
#define k_fifo_alloc_put(fifo, data)
 Add an element to a FIFO queue. More...
 
#define k_fifo_put_list(fifo, head, tail)
 Atomically add a list of elements to a FIFO. More...
 
#define k_fifo_put_slist(fifo, list)
 Atomically add a list of elements to a FIFO queue. More...
 
#define k_fifo_get(fifo, timeout)
 Get an element from a FIFO queue. More...
 
#define k_fifo_is_empty(fifo)    k_queue_is_empty(&(fifo)->_queue)
 Query a FIFO queue to see if it has data available. More...
 
#define k_fifo_peek_head(fifo)
 Peek element at the head of a FIFO queue. More...
 
#define k_fifo_peek_tail(fifo)
 Peek element at the tail of FIFO queue. More...
 
#define K_FIFO_DEFINE(name)
 Statically define and initialize a FIFO queue. More...
 
#define k_lifo_init(lifo)
 Initialize a LIFO queue. More...
 
#define k_lifo_put(lifo, data)
 Add an element to a LIFO queue. More...
 
#define k_lifo_alloc_put(lifo, data)
 Add an element to a LIFO queue. More...
 
#define k_lifo_get(lifo, timeout)
 Get an element from a LIFO queue. More...
 
#define K_LIFO_DEFINE(name)
 Statically define and initialize a LIFO queue. More...
 
#define K_STACK_DEFINE(name, stack_num_entries)
 Statically define and initialize a stack. More...
 
#define K_MUTEX_DEFINE(name)
 Statically define and initialize a mutex. More...
 
#define K_CONDVAR_DEFINE(name)
 Statically define and initialize a condition variable. More...
 
#define K_SEM_MAX_LIMIT   UINT_MAX
 Maximum limit value allowed for a semaphore. More...
 
#define K_SEM_DEFINE(name, initial_count, count_limit)
 Statically define and initialize a semaphore. More...
 
#define K_WORK_DELAYABLE_DEFINE(work, work_handler)
 Initialize a statically-defined delayable work item. More...
 
#define K_WORK_USER_DEFINE(work, work_handler)    struct k_work_user work = Z_WORK_USER_INITIALIZER(work_handler)
 Initialize a statically-defined user work item. More...
 
#define K_WORK_DEFINE(work, work_handler)    struct k_work work = Z_WORK_INITIALIZER(work_handler)
 Initialize a statically-defined work item. More...
 
#define K_DELAYED_WORK_DEFINE(work, work_handler)
 Initialize a statically-defined delayed work item. More...
 
#define K_MSGQ_FLAG_ALLOC   BIT(0)
 
#define K_MSGQ_DEFINE(q_name, q_msg_size, q_max_msgs, q_align)
 Statically define and initialize a message queue. More...
 
#define K_MBOX_DEFINE(name)
 Statically define and initialize a mailbox. More...
 
#define K_PIPE_DEFINE(name, pipe_buffer_size, pipe_align)
 Statically define and initialize a pipe. More...
 
#define K_MEM_SLAB_DEFINE(name, slab_block_size, slab_num_blocks, slab_align)
 Statically define and initialize a memory slab. More...
 
#define K_HEAP_DEFINE(name, bytes)
 Define a static k_heap. More...
 
#define K_HEAP_DEFINE_NOCACHE(name, bytes)    Z_HEAP_DEFINE_IN_SECT(name, bytes, __nocache)
 Define a static k_heap in uncached memory. More...
 
#define K_POLL_TYPE_IGNORE   0
 
#define K_POLL_TYPE_SIGNAL   Z_POLL_TYPE_BIT(_POLL_TYPE_SIGNAL)
 
#define K_POLL_TYPE_SEM_AVAILABLE   Z_POLL_TYPE_BIT(_POLL_TYPE_SEM_AVAILABLE)
 
#define K_POLL_TYPE_DATA_AVAILABLE   Z_POLL_TYPE_BIT(_POLL_TYPE_DATA_AVAILABLE)
 
#define K_POLL_TYPE_FIFO_DATA_AVAILABLE   K_POLL_TYPE_DATA_AVAILABLE
 
#define K_POLL_TYPE_MSGQ_DATA_AVAILABLE   Z_POLL_TYPE_BIT(_POLL_TYPE_MSGQ_DATA_AVAILABLE)
 
#define K_POLL_STATE_NOT_READY   0
 
#define K_POLL_STATE_SIGNALED   Z_POLL_STATE_BIT(_POLL_STATE_SIGNALED)
 
#define K_POLL_STATE_SEM_AVAILABLE   Z_POLL_STATE_BIT(_POLL_STATE_SEM_AVAILABLE)
 
#define K_POLL_STATE_DATA_AVAILABLE   Z_POLL_STATE_BIT(_POLL_STATE_DATA_AVAILABLE)
 
#define K_POLL_STATE_FIFO_DATA_AVAILABLE   K_POLL_STATE_DATA_AVAILABLE
 
#define K_POLL_STATE_MSGQ_DATA_AVAILABLE   Z_POLL_STATE_BIT(_POLL_STATE_MSGQ_DATA_AVAILABLE)
 
#define K_POLL_STATE_CANCELLED   Z_POLL_STATE_BIT(_POLL_STATE_CANCELLED)
 
#define K_POLL_SIGNAL_INITIALIZER(obj)
 
#define K_POLL_EVENT_INITIALIZER(_event_type, _event_mode, _event_obj)
 
#define K_POLL_EVENT_STATIC_INITIALIZER(_event_type, _event_mode, _event_obj, event_tag)
 
#define k_oops()   z_except_reason(K_ERR_KERNEL_OOPS)
 Fatally terminate a thread. More...
 
#define k_panic()   z_except_reason(K_ERR_KERNEL_PANIC)
 Fatally terminate the system. More...
 

Typedefs

typedef void(* k_thread_user_cb_t) (const struct k_thread *thread, void *user_data)
 
typedef void(* k_timer_expiry_t) (struct k_timer *timer)
 Timer expiry function type. More...
 
typedef void(* k_timer_stop_t) (struct k_timer *timer)
 Timer stop function type. More...
 
typedef void(* k_work_handler_t) (struct k_work *work)
 The signature for a work item handler function. More...
 
typedef void(* k_work_user_handler_t) (struct k_work_user *work)
 Work item handler function type for user work queues. More...
 

Enumerations

enum  execution_context_types { K_ISR = 0 , K_COOP_THREAD , K_PREEMPT_THREAD }
 
enum  { K_WORK_RUNNING = BIT(K_WORK_RUNNING_BIT) , K_WORK_CANCELING = BIT(K_WORK_CANCELING_BIT) , K_WORK_QUEUED = BIT(K_WORK_QUEUED_BIT) , K_WORK_DELAYED = BIT(K_WORK_DELAYED_BIT) }
 
enum  k_poll_modes { K_POLL_MODE_NOTIFY_ONLY = 0 , K_POLL_NUM_MODES }
 

Functions

void k_thread_foreach (k_thread_user_cb_t user_cb, void *user_data)
 Iterate over all the threads in the system. More...
 
void k_thread_foreach_unlocked (k_thread_user_cb_t user_cb, void *user_data)
 Iterate over all the threads in the system without locking. More...
 
k_tid_t k_thread_create (struct k_thread *new_thread, k_thread_stack_t *stack, size_t stack_size, k_thread_entry_t entry, void *p1, void *p2, void *p3, int prio, uint32_t options, k_timeout_t delay)
 Create a thread. More...
 
FUNC_NORETURN void k_thread_user_mode_enter (k_thread_entry_t entry, void *p1, void *p2, void *p3)
 Drop a thread's privileges permanently to user mode. More...
 
static void k_thread_heap_assign (struct k_thread *thread, struct k_heap *heap)
 Assign a resource memory pool to a thread. More...
 
void k_thread_system_pool_assign (struct k_thread *thread)
 Assign the system heap as a thread's resource pool. More...
 
int k_thread_join (struct k_thread *thread, k_timeout_t timeout)
 Sleep until a thread exits. More...
 
int32_t k_sleep (k_timeout_t timeout)
 Put the current thread to sleep. More...
 
static int32_t k_msleep (int32_t ms)
 Put the current thread to sleep. More...
 
int32_t k_usleep (int32_t us)
 Put the current thread to sleep with microsecond resolution. More...
 
void k_busy_wait (uint32_t usec_to_wait)
 Cause the current thread to busy wait. More...
 
void k_yield (void)
 Yield the current thread. More...
 
void k_wakeup (k_tid_t thread)
 Wake up a sleeping thread. More...
 
static __attribute_const__ k_tid_t k_current_get (void)
 Get thread ID of the current thread. More...
 
void k_thread_abort (k_tid_t thread)
 Abort a thread. More...
 
void k_thread_start (k_tid_t thread)
 Start an inactive thread. More...
 
k_ticks_t k_thread_timeout_expires_ticks (const struct k_thread *t)
 Get time when a thread wakes up, in system ticks. More...
 
k_ticks_t k_thread_timeout_remaining_ticks (const struct k_thread *t)
 Get time remaining before a thread wakes up, in system ticks. More...
 
int k_thread_priority_get (k_tid_t thread)
 Get a thread's priority. More...
 
void k_thread_priority_set (k_tid_t thread, int prio)
 Set a thread's priority. More...
 
void k_thread_deadline_set (k_tid_t thread, int deadline)
 Set deadline expiration time for scheduler. More...
 
int k_thread_cpu_mask_clear (k_tid_t thread)
 Sets all CPU enable masks to zero. More...
 
int k_thread_cpu_mask_enable_all (k_tid_t thread)
 Sets all CPU enable masks to one. More...
 
int k_thread_cpu_mask_enable (k_tid_t thread, int cpu)
 Enable thread to run on specified CPU. More...
 
int k_thread_cpu_mask_disable (k_tid_t thread, int cpu)
 Prevent thread to run on specified CPU. More...
 
void k_thread_suspend (k_tid_t thread)
 Suspend a thread. More...
 
void k_thread_resume (k_tid_t thread)
 Resume a suspended thread. More...
 
void k_sched_time_slice_set (int32_t slice, int prio)
 Set time-slicing period and scope. More...
 
bool k_is_in_isr (void)
 Determine if code is running at interrupt level. More...
 
int k_is_preempt_thread (void)
 Determine if code is running in a preemptible thread. More...
 
static bool k_is_pre_kernel (void)
 Test whether startup is in the before-main-task phase. More...
 
void k_sched_lock (void)
 Lock the scheduler. More...
 
void k_sched_unlock (void)
 Unlock the scheduler. More...
 
void k_thread_custom_data_set (void *value)
 Set current thread's custom data. More...
 
voidk_thread_custom_data_get (void)
 Get current thread's custom data. More...
 
int k_thread_name_set (k_tid_t thread, const char *str)
 Set current thread name. More...
 
const char * k_thread_name_get (k_tid_t thread)
 Get thread name. More...
 
int k_thread_name_copy (k_tid_t thread, char *buf, size_t size)
 Copy the thread name into a supplied buffer. More...
 
const char * k_thread_state_str (k_tid_t thread_id)
 Get thread state string. More...
 
void k_timer_init (struct k_timer *timer, k_timer_expiry_t expiry_fn, k_timer_stop_t stop_fn)
 Initialize a timer. More...
 
void k_timer_start (struct k_timer *timer, k_timeout_t duration, k_timeout_t period)
 Start a timer. More...
 
void k_timer_stop (struct k_timer *timer)
 Stop a timer. More...
 
uint32_t k_timer_status_get (struct k_timer *timer)
 Read timer status. More...
 
uint32_t k_timer_status_sync (struct k_timer *timer)
 Synchronize thread to timer expiration. More...
 
k_ticks_t k_timer_expires_ticks (const struct k_timer *timer)
 Get next expiration time of a timer, in system ticks. More...
 
k_ticks_t k_timer_remaining_ticks (const struct k_timer *timer)
 Get time remaining before a timer next expires, in system ticks. More...
 
static uint32_t k_timer_remaining_get (struct k_timer *timer)
 Get time remaining before a timer next expires. More...
 
void k_timer_user_data_set (struct k_timer *timer, void *user_data)
 Associate user-specific data with a timer. More...
 
voidk_timer_user_data_get (const struct k_timer *timer)
 Retrieve the user-specific data from a timer. More...
 
int64_t k_uptime_ticks (void)
 Get system uptime, in system ticks. More...
 
static int64_t k_uptime_get (void)
 Get system uptime. More...
 
static uint32_t k_uptime_get_32 (void)
 Get system uptime (32-bit version). More...
 
static int64_t k_uptime_delta (int64_t *reftime)
 Get elapsed time. More...
 
static uint32_t k_cycle_get_32 (void)
 Read the hardware clock. More...
 
void k_queue_init (struct k_queue *queue)
 Initialize a queue. More...
 
void k_queue_cancel_wait (struct k_queue *queue)
 Cancel waiting on a queue. More...
 
void k_queue_append (struct k_queue *queue, void *data)
 Append an element to the end of a queue. More...
 
int32_t k_queue_alloc_append (struct k_queue *queue, void *data)
 Append an element to a queue. More...
 
void k_queue_prepend (struct k_queue *queue, void *data)
 Prepend an element to a queue. More...
 
int32_t k_queue_alloc_prepend (struct k_queue *queue, void *data)
 Prepend an element to a queue. More...
 
void k_queue_insert (struct k_queue *queue, void *prev, void *data)
 Inserts an element to a queue. More...
 
int k_queue_append_list (struct k_queue *queue, void *head, void *tail)
 Atomically append a list of elements to a queue. More...
 
int k_queue_merge_slist (struct k_queue *queue, sys_slist_t *list)
 Atomically add a list of elements to a queue. More...
 
voidk_queue_get (struct k_queue *queue, k_timeout_t timeout)
 Get an element from a queue. More...
 
bool k_queue_remove (struct k_queue *queue, void *data)
 Remove an element from a queue. More...
 
bool k_queue_unique_append (struct k_queue *queue, void *data)
 Append an element to a queue only if it's not present already. More...
 
int k_queue_is_empty (struct k_queue *queue)
 Query a queue to see if it has data available. More...
 
voidk_queue_peek_head (struct k_queue *queue)
 Peek element at the head of queue. More...
 
voidk_queue_peek_tail (struct k_queue *queue)
 Peek element at the tail of queue. More...
 
int k_futex_wait (struct k_futex *futex, int expected, k_timeout_t timeout)
 Pend the current thread on a futex. More...
 
int k_futex_wake (struct k_futex *futex, bool wake_all)
 Wake one/all threads pending on a futex. More...
 
void k_event_init (struct k_event *event)
 Initialize an event object. More...
 
void k_event_post (struct k_event *event, uint32_t events)
 Post one or more events to an event object. More...
 
void k_event_set (struct k_event *event, uint32_t events)
 Set the events in an event object. More...
 
uint32_t k_event_wait (struct k_event *event, uint32_t events, bool reset, k_timeout_t timeout)
 Wait for any of the specified events. More...
 
uint32_t k_event_wait_all (struct k_event *event, uint32_t events, bool reset, k_timeout_t timeout)
 Wait for any of the specified events. More...
 
void k_stack_init (struct k_stack *stack, stack_data_t *buffer, uint32_t num_entries)
 Initialize a stack. More...
 
int32_t k_stack_alloc_init (struct k_stack *stack, uint32_t num_entries)
 Initialize a stack. More...
 
int k_stack_cleanup (struct k_stack *stack)
 Release a stack's allocated buffer. More...
 
int k_stack_push (struct k_stack *stack, stack_data_t data)
 Push an element onto a stack. More...
 
int k_stack_pop (struct k_stack *stack, stack_data_t *data, k_timeout_t timeout)
 Pop an element from a stack. More...
 
int k_mutex_init (struct k_mutex *mutex)
 Initialize a mutex. More...
 
int k_mutex_lock (struct k_mutex *mutex, k_timeout_t timeout)
 Lock a mutex. More...
 
int k_mutex_unlock (struct k_mutex *mutex)
 Unlock a mutex. More...
 
int k_condvar_init (struct k_condvar *condvar)
 Initialize a condition variable. More...
 
int k_condvar_signal (struct k_condvar *condvar)
 Signals one thread that is pending on the condition variable. More...
 
int k_condvar_broadcast (struct k_condvar *condvar)
 Unblock all threads that are pending on the condition variable. More...
 
int k_condvar_wait (struct k_condvar *condvar, struct k_mutex *mutex, k_timeout_t timeout)
 Waits on the condition variable releasing the mutex lock. More...
 
int k_sem_init (struct k_sem *sem, unsigned int initial_count, unsigned int limit)
 Initialize a semaphore. More...
 
int k_sem_take (struct k_sem *sem, k_timeout_t timeout)
 Take a semaphore. More...
 
void k_sem_give (struct k_sem *sem)
 Give a semaphore. More...
 
void k_sem_reset (struct k_sem *sem)
 Resets a semaphore's count to zero. More...
 
unsigned int k_sem_count_get (struct k_sem *sem)
 Get a semaphore's count. More...
 
void k_work_init (struct k_work *work, k_work_handler_t handler)
 Initialize a (non-delayable) work structure. More...
 
int k_work_busy_get (const struct k_work *work)
 Busy state flags from the work item. More...
 
static bool k_work_is_pending (const struct k_work *work)
 Test whether a work item is currently pending. More...
 
int k_work_submit_to_queue (struct k_work_q *queue, struct k_work *work)
 Submit a work item to a queue. More...
 
int k_work_submit (struct k_work *work)
 Submit a work item to the system queue. More...
 
bool k_work_flush (struct k_work *work, struct k_work_sync *sync)
 Wait for last-submitted instance to complete. More...
 
int k_work_cancel (struct k_work *work)
 Cancel a work item. More...
 
bool k_work_cancel_sync (struct k_work *work, struct k_work_sync *sync)
 Cancel a work item and wait for it to complete. More...
 
void k_work_queue_init (struct k_work_q *queue)
 Initialize a work queue structure. More...
 
void k_work_queue_start (struct k_work_q *queue, k_thread_stack_t *stack, size_t stack_size, int prio, const struct k_work_queue_config *cfg)
 Initialize a work queue. More...
 
static k_tid_t k_work_queue_thread_get (struct k_work_q *queue)
 Access the thread that animates a work queue. More...
 
int k_work_queue_drain (struct k_work_q *queue, bool plug)
 Wait until the work queue has drained, optionally plugging it. More...
 
int k_work_queue_unplug (struct k_work_q *queue)
 Release a work queue to accept new submissions. More...
 
void k_work_init_delayable (struct k_work_delayable *dwork, k_work_handler_t handler)
 Initialize a delayable work structure. More...
 
static struct k_work_delayablek_work_delayable_from_work (struct k_work *work)
 Get the parent delayable work structure from a work pointer. More...
 
int k_work_delayable_busy_get (const struct k_work_delayable *dwork)
 Busy state flags from the delayable work item. More...
 
static bool k_work_delayable_is_pending (const struct k_work_delayable *dwork)
 Test whether a delayed work item is currently pending. More...
 
static k_ticks_t k_work_delayable_expires_get (const struct k_work_delayable *dwork)
 Get the absolute tick count at which a scheduled delayable work will be submitted. More...
 
static k_ticks_t k_work_delayable_remaining_get (const struct k_work_delayable *dwork)
 Get the number of ticks until a scheduled delayable work will be submitted. More...
 
int k_work_schedule_for_queue (struct k_work_q *queue, struct k_work_delayable *dwork, k_timeout_t delay)
 Submit an idle work item to a queue after a delay. More...
 
int k_work_schedule (struct k_work_delayable *dwork, k_timeout_t delay)
 Submit an idle work item to the system work queue after a delay. More...
 
int k_work_reschedule_for_queue (struct k_work_q *queue, struct k_work_delayable *dwork, k_timeout_t delay)
 Reschedule a work item to a queue after a delay. More...
 
int k_work_reschedule (struct k_work_delayable *dwork, k_timeout_t delay)
 Reschedule a work item to the system work queue after a delay. More...
 
bool k_work_flush_delayable (struct k_work_delayable *dwork, struct k_work_sync *sync)
 Flush delayable work. More...
 
int k_work_cancel_delayable (struct k_work_delayable *dwork)
 Cancel delayable work. More...
 
bool k_work_cancel_delayable_sync (struct k_work_delayable *dwork, struct k_work_sync *sync)
 Cancel delayable work and wait. More...
 
static bool k_work_pending (const struct k_work *work)
 
static void k_work_q_start (struct k_work_q *work_q, k_thread_stack_t *stack, size_t stack_size, int prio)
 
static void k_delayed_work_init (struct k_delayed_work *work, k_work_handler_t handler)
 
static int k_delayed_work_submit_to_queue (struct k_work_q *work_q, struct k_delayed_work *work, k_timeout_t delay)
 
static int k_delayed_work_submit (struct k_delayed_work *work, k_timeout_t delay)
 
static int k_delayed_work_cancel (struct k_delayed_work *work)
 
static bool k_delayed_work_pending (struct k_delayed_work *work)
 
static int32_t k_delayed_work_remaining_get (struct k_delayed_work *work)
 
static k_ticks_t k_delayed_work_expires_ticks (struct k_delayed_work *work)
 
static k_ticks_t k_delayed_work_remaining_ticks (struct k_delayed_work *work)
 
static void k_work_user_init (struct k_work_user *work, k_work_user_handler_t handler)
 Initialize a userspace work item. More...
 
static bool k_work_user_is_pending (struct k_work_user *work)
 Check if a userspace work item is pending. More...
 
static int k_work_user_submit_to_queue (struct k_work_user_q *work_q, struct k_work_user *work)
 Submit a work item to a user mode workqueue. More...
 
void k_work_user_queue_start (struct k_work_user_q *work_q, k_thread_stack_t *stack, size_t stack_size, int prio, const char *name)
 Start a workqueue in user mode. More...
 
void k_work_poll_init (struct k_work_poll *work, k_work_handler_t handler)
 Initialize a triggered work item. More...
 
int k_work_poll_submit_to_queue (struct k_work_q *work_q, struct k_work_poll *work, struct k_poll_event *events, int num_events, k_timeout_t timeout)
 Submit a triggered work item. More...
 
int k_work_poll_submit (struct k_work_poll *work, struct k_poll_event *events, int num_events, k_timeout_t timeout)
 Submit a triggered work item to the system workqueue. More...
 
int k_work_poll_cancel (struct k_work_poll *work)
 Cancel a triggered work item. More...
 
void k_msgq_init (struct k_msgq *msgq, char *buffer, size_t msg_size, uint32_t max_msgs)
 Initialize a message queue. More...
 
int k_msgq_alloc_init (struct k_msgq *msgq, size_t msg_size, uint32_t max_msgs)
 Initialize a message queue. More...
 
int k_msgq_cleanup (struct k_msgq *msgq)
 Release allocated buffer for a queue. More...
 
int k_msgq_put (struct k_msgq *msgq, const void *data, k_timeout_t timeout)
 Send a message to a message queue. More...
 
int k_msgq_get (struct k_msgq *msgq, void *data, k_timeout_t timeout)
 Receive a message from a message queue. More...
 
int k_msgq_peek (struct k_msgq *msgq, void *data)
 Peek/read a message from a message queue. More...
 
void k_msgq_purge (struct k_msgq *msgq)
 Purge a message queue. More...
 
uint32_t k_msgq_num_free_get (struct k_msgq *msgq)
 Get the amount of free space in a message queue. More...
 
void k_msgq_get_attrs (struct k_msgq *msgq, struct k_msgq_attrs *attrs)
 Get basic attributes of a message queue. More...
 
uint32_t k_msgq_num_used_get (struct k_msgq *msgq)
 Get the number of messages in a message queue. More...
 
void k_mbox_init (struct k_mbox *mbox)
 Initialize a mailbox. More...
 
int k_mbox_put (struct k_mbox *mbox, struct k_mbox_msg *tx_msg, k_timeout_t timeout)
 Send a mailbox message in a synchronous manner. More...
 
void k_mbox_async_put (struct k_mbox *mbox, struct k_mbox_msg *tx_msg, struct k_sem *sem)
 Send a mailbox message in an asynchronous manner. More...
 
int k_mbox_get (struct k_mbox *mbox, struct k_mbox_msg *rx_msg, void *buffer, k_timeout_t timeout)
 Receive a mailbox message. More...
 
void k_mbox_data_get (struct k_mbox_msg *rx_msg, void *buffer)
 Retrieve mailbox message data into a buffer. More...
 
void k_pipe_init (struct k_pipe *pipe, unsigned char *buffer, size_t size)
 Initialize a pipe. More...
 
int k_pipe_cleanup (struct k_pipe *pipe)
 Release a pipe's allocated buffer. More...
 
int k_pipe_alloc_init (struct k_pipe *pipe, size_t size)
 Initialize a pipe and allocate a buffer for it. More...
 
int k_pipe_put (struct k_pipe *pipe, void *data, size_t bytes_to_write, size_t *bytes_written, size_t min_xfer, k_timeout_t timeout)
 Write data to a pipe. More...
 
int k_pipe_get (struct k_pipe *pipe, void *data, size_t bytes_to_read, size_t *bytes_read, size_t min_xfer, k_timeout_t timeout)
 Read data from a pipe. More...
 
size_t k_pipe_read_avail (struct k_pipe *pipe)
 Query the number of bytes that may be read from pipe. More...
 
size_t k_pipe_write_avail (struct k_pipe *pipe)
 Query the number of bytes that may be written to pipe. More...
 
int k_mem_slab_init (struct k_mem_slab *slab, void *buffer, size_t block_size, uint32_t num_blocks)
 Initialize a memory slab. More...
 
int k_mem_slab_alloc (struct k_mem_slab *slab, void **mem, k_timeout_t timeout)
 Allocate memory from a memory slab. More...
 
void k_mem_slab_free (struct k_mem_slab *slab, void **mem)
 Free memory allocated from a memory slab. More...
 
static uint32_t k_mem_slab_num_used_get (struct k_mem_slab *slab)
 Get the number of used blocks in a memory slab. More...
 
static uint32_t k_mem_slab_max_used_get (struct k_mem_slab *slab)
 Get the number of maximum used blocks so far in a memory slab. More...
 
static uint32_t k_mem_slab_num_free_get (struct k_mem_slab *slab)
 Get the number of unused blocks in a memory slab. More...
 
void k_heap_init (struct k_heap *h, void *mem, size_t bytes)
 Initialize a k_heap. More...
 
voidk_heap_aligned_alloc (struct k_heap *h, size_t align, size_t bytes, k_timeout_t timeout)
 Allocate aligned memory from a k_heap. More...
 
voidk_heap_alloc (struct k_heap *h, size_t bytes, k_timeout_t timeout)
 Allocate memory from a k_heap. More...
 
void k_heap_free (struct k_heap *h, void *mem)
 Free memory allocated by k_heap_alloc() More...
 
voidk_aligned_alloc (size_t align, size_t size)
 Allocate memory from the heap with a specified alignment. More...
 
voidk_malloc (size_t size)
 Allocate memory from the heap. More...
 
void k_free (void *ptr)
 Free memory allocated from heap. More...
 
voidk_calloc (size_t nmemb, size_t size)
 Allocate memory from heap, array style. More...
 
void k_poll_event_init (struct k_poll_event *event, uint32_t type, int mode, void *obj)
 Initialize one struct k_poll_event instance. More...
 
int k_poll (struct k_poll_event *events, int num_events, k_timeout_t timeout)
 Wait for one or many of multiple poll events to occur. More...
 
void k_poll_signal_init (struct k_poll_signal *sig)
 Initialize a poll signal object. More...
 
void k_poll_signal_reset (struct k_poll_signal *sig)
 
void k_poll_signal_check (struct k_poll_signal *sig, unsigned int *signaled, int *result)
 Fetch the signaled state and result value of a poll signal. More...
 
int k_poll_signal_raise (struct k_poll_signal *sig, int result)
 Signal a poll signal object. More...
 
static void k_cpu_idle (void)
 Make the CPU idle. More...
 
static void k_cpu_atomic_idle (unsigned int key)
 Make the CPU idle in an atomic fashion. More...
 
int k_float_disable (struct k_thread *thread)
 Disable preservation of floating point context information. More...
 
int k_float_enable (struct k_thread *thread, unsigned int options)
 Enable preservation of floating point context information. More...
 

Detailed Description

Public kernel APIs.

Macro Definition Documentation

◆ K_ANY

#define K_ANY   NULL

◆ K_END

#define K_END   NULL

◆ K_HIGHEST_APPLICATION_THREAD_PRIO

#define K_HIGHEST_APPLICATION_THREAD_PRIO   (K_HIGHEST_THREAD_PRIO)

◆ K_HIGHEST_THREAD_PRIO

#define K_HIGHEST_THREAD_PRIO   (-CONFIG_NUM_COOP_PRIORITIES)

◆ K_IDLE_PRIO

#define K_IDLE_PRIO   K_LOWEST_THREAD_PRIO

◆ K_LOWEST_APPLICATION_THREAD_PRIO

#define K_LOWEST_APPLICATION_THREAD_PRIO   (K_LOWEST_THREAD_PRIO - 1)

◆ K_LOWEST_THREAD_PRIO

#define K_LOWEST_THREAD_PRIO   CONFIG_NUM_PREEMPT_PRIORITIES

◆ k_oops

#define k_oops ( )    z_except_reason(K_ERR_KERNEL_OOPS)

Fatally terminate a thread.

This should be called when a thread has encountered an unrecoverable runtime condition and needs to terminate. What this ultimately means is determined by the _fatal_error_handler() implementation, which will be called will reason code K_ERR_KERNEL_OOPS.

If this is called from ISR context, the default system fatal error handler will treat it as an unrecoverable system error, just like k_panic().

◆ k_panic

#define k_panic ( )    z_except_reason(K_ERR_KERNEL_PANIC)

Fatally terminate the system.

This should be called when the Zephyr kernel has encountered an unrecoverable runtime condition and needs to terminate. What this ultimately means is determined by the _fatal_error_handler() implementation, which will be called will reason code K_ERR_KERNEL_PANIC.

◆ K_PRIO_COOP

#define K_PRIO_COOP (   x)    (-(CONFIG_NUM_COOP_PRIORITIES - (x)))

◆ K_PRIO_PREEMPT

#define K_PRIO_PREEMPT (   x)    (x)

Enumeration Type Documentation

◆ execution_context_types

Enumerator
K_ISR 
K_COOP_THREAD 
K_PREEMPT_THREAD 

Function Documentation

◆ k_float_disable()

int k_float_disable ( struct k_thread thread)

Disable preservation of floating point context information.

This routine informs the kernel that the specified thread will no longer be using the floating point registers.

Warning
Some architectures apply restrictions on how the disabling of floating point preservation may be requested, see arch_float_disable.
This routine should only be used to disable floating point support for a thread that currently has such support enabled.
Parameters
threadID of thread.
Return values
0On success.
-ENOTSUPIf the floating point disabling is not implemented. -EINVAL If the floating point disabling could not be performed.

◆ k_float_enable()

int k_float_enable ( struct k_thread thread,
unsigned int  options 
)

Enable preservation of floating point context information.

This routine informs the kernel that the specified thread will use the floating point registers.

Invoking this routine initializes the thread's floating point context info to that of an FPU that has been reset. The next time the thread is scheduled by z_swap() it will either inherit an FPU that is guaranteed to be in a "sane" state (if the most recent user of the FPU was cooperatively swapped out) or the thread's own floating point context will be loaded (if the most recent user of the FPU was preempted, or if this thread is the first user of the FPU). Thereafter, the kernel will protect the thread's FP context so that it is not altered during a preemptive context switch.

The options parameter indicates which floating point register sets will be used by the specified thread.

For x86 options:

  • K_FP_REGS indicates x87 FPU and MMX registers only
  • K_SSE_REGS indicates SSE registers (and also x87 FPU and MMX registers)
Warning
Some architectures apply restrictions on how the enabling of floating point preservation may be requested, see arch_float_enable.
This routine should only be used to enable floating point support for a thread that currently has such support enabled.
Parameters
threadID of thread.
optionsarchitecture dependent options
Return values
0On success.
-ENOTSUPIf the floating point enabling is not implemented. -EINVAL If the floating point enabling could not be performed.