Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
kernel.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016, Wind River Systems, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13#ifndef ZEPHYR_INCLUDE_KERNEL_H_
14#define ZEPHYR_INCLUDE_KERNEL_H_
15
16#if !defined(_ASMLANGUAGE)
18#include <errno.h>
19#include <limits.h>
20#include <stdbool.h>
21#include <zephyr/toolchain.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*
31 * Zephyr currently assumes the size of a couple standard types to simplify
32 * print string formats. Let's make sure this doesn't change without notice.
33 */
34BUILD_ASSERT(sizeof(int32_t) == sizeof(int));
35BUILD_ASSERT(sizeof(int64_t) == sizeof(long long));
36BUILD_ASSERT(sizeof(intptr_t) == sizeof(long));
37
47#define K_ANY NULL
48
49#if (CONFIG_NUM_COOP_PRIORITIES + CONFIG_NUM_PREEMPT_PRIORITIES) == 0
50#error Zero available thread priorities defined!
51#endif
52
53#define K_PRIO_COOP(x) (-(CONFIG_NUM_COOP_PRIORITIES - (x)))
54#define K_PRIO_PREEMPT(x) (x)
55
56#define K_HIGHEST_THREAD_PRIO (-CONFIG_NUM_COOP_PRIORITIES)
57#define K_LOWEST_THREAD_PRIO CONFIG_NUM_PREEMPT_PRIORITIES
58#define K_IDLE_PRIO K_LOWEST_THREAD_PRIO
59#define K_HIGHEST_APPLICATION_THREAD_PRIO (K_HIGHEST_THREAD_PRIO)
60#define K_LOWEST_APPLICATION_THREAD_PRIO (K_LOWEST_THREAD_PRIO - 1)
61
62#ifdef CONFIG_POLL
63#define Z_POLL_EVENT_OBJ_INIT(obj) \
64 .poll_events = SYS_DLIST_STATIC_INIT(&obj.poll_events),
65#define Z_DECL_POLL_EVENT sys_dlist_t poll_events;
66#else
67#define Z_POLL_EVENT_OBJ_INIT(obj)
68#define Z_DECL_POLL_EVENT
69#endif
70
71struct k_thread;
72struct k_mutex;
73struct k_sem;
74struct k_msgq;
75struct k_mbox;
76struct k_pipe;
77struct k_queue;
78struct k_fifo;
79struct k_lifo;
80struct k_stack;
81struct k_mem_slab;
82struct k_timer;
83struct k_poll_event;
84struct k_poll_signal;
85struct k_mem_domain;
86struct k_mem_partition;
87struct k_futex;
88struct k_event;
89
95
96/* private, used by k_poll and k_work_poll */
97struct k_work_poll;
98typedef int (*_poller_cb_t)(struct k_poll_event *event, uint32_t state);
99
105typedef void (*k_thread_user_cb_t)(const struct k_thread *thread,
106 void *user_data);
107
123void k_thread_foreach(k_thread_user_cb_t user_cb, void *user_data);
124
143#ifdef CONFIG_SMP
144void k_thread_foreach_filter_by_cpu(unsigned int cpu,
145 k_thread_user_cb_t user_cb, void *user_data);
146#else
147static inline
148void k_thread_foreach_filter_by_cpu(unsigned int cpu,
149 k_thread_user_cb_t user_cb, void *user_data)
150{
151 __ASSERT(cpu == 0, "cpu filter out of bounds");
152 ARG_UNUSED(cpu);
153 k_thread_foreach(user_cb, user_data);
154}
155#endif
156
185 k_thread_user_cb_t user_cb, void *user_data);
186
218#ifdef CONFIG_SMP
220 k_thread_user_cb_t user_cb, void *user_data);
221#else
222static inline
223void k_thread_foreach_unlocked_filter_by_cpu(unsigned int cpu,
224 k_thread_user_cb_t user_cb, void *user_data)
225{
226 __ASSERT(cpu == 0, "cpu filter out of bounds");
227 ARG_UNUSED(cpu);
228 k_thread_foreach_unlocked(user_cb, user_data);
229}
230#endif
231
240#endif /* !_ASMLANGUAGE */
241
242
243/*
244 * Thread user options. May be needed by assembly code. Common part uses low
245 * bits, arch-specific use high bits.
246 */
247
251#define K_ESSENTIAL (BIT(0))
252
253#define K_FP_IDX 1
263#define K_FP_REGS (BIT(K_FP_IDX))
264
271#define K_USER (BIT(2))
272
281#define K_INHERIT_PERMS (BIT(3))
282
292#define K_CALLBACK_STATE (BIT(4))
293
303#define K_DSP_IDX 6
304#define K_DSP_REGS (BIT(K_DSP_IDX))
305
314#define K_AGU_IDX 7
315#define K_AGU_REGS (BIT(K_AGU_IDX))
316
326#define K_SSE_REGS (BIT(7))
327
328/* end - thread options */
329
330#if !defined(_ASMLANGUAGE)
345__syscall k_thread_stack_t *k_thread_stack_alloc(size_t size, int flags);
346
360
409__syscall k_tid_t k_thread_create(struct k_thread *new_thread,
410 k_thread_stack_t *stack,
411 size_t stack_size,
413 void *p1, void *p2, void *p3,
414 int prio, uint32_t options, k_timeout_t delay);
415
438 void *p1, void *p2,
439 void *p3);
440
454#define k_thread_access_grant(thread, ...) \
455 FOR_EACH_FIXED_ARG(k_object_access_grant, (;), (thread), __VA_ARGS__)
456
471static inline void k_thread_heap_assign(struct k_thread *thread,
472 struct k_heap *heap)
473{
474 thread->resource_pool = heap;
475}
476
477#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_STACK_INFO)
498__syscall int k_thread_stack_space_get(const struct k_thread *thread,
499 size_t *unused_ptr);
500#endif
501
502#if (K_HEAP_MEM_POOL_SIZE > 0)
515void k_thread_system_pool_assign(struct k_thread *thread);
516#endif /* (K_HEAP_MEM_POOL_SIZE > 0) */
517
537__syscall int k_thread_join(struct k_thread *thread, k_timeout_t timeout);
538
553__syscall int32_t k_sleep(k_timeout_t timeout);
554
566static inline int32_t k_msleep(int32_t ms)
567{
568 return k_sleep(Z_TIMEOUT_MS(ms));
569}
570
588
605__syscall void k_busy_wait(uint32_t usec_to_wait);
606
618bool k_can_yield(void);
619
627__syscall void k_yield(void);
628
638__syscall void k_wakeup(k_tid_t thread);
639
653__attribute_const__
655
662__attribute_const__
663static inline k_tid_t k_current_get(void)
664{
665#ifdef CONFIG_CURRENT_THREAD_USE_TLS
666
667 /* Thread-local cache of current thread ID, set in z_thread_entry() */
668 extern Z_THREAD_LOCAL k_tid_t z_tls_current;
669
670 return z_tls_current;
671#else
673#endif
674}
675
695__syscall void k_thread_abort(k_tid_t thread);
696
697
707__syscall void k_thread_start(k_tid_t thread);
708
709k_ticks_t z_timeout_expires(const struct _timeout *timeout);
710k_ticks_t z_timeout_remaining(const struct _timeout *timeout);
711
712#ifdef CONFIG_SYS_CLOCK_EXISTS
713
721__syscall k_ticks_t k_thread_timeout_expires_ticks(const struct k_thread *thread);
722
723static inline k_ticks_t z_impl_k_thread_timeout_expires_ticks(
724 const struct k_thread *thread)
725{
726 return z_timeout_expires(&thread->base.timeout);
727}
728
737
738static inline k_ticks_t z_impl_k_thread_timeout_remaining_ticks(
739 const struct k_thread *thread)
740{
741 return z_timeout_remaining(&thread->base.timeout);
742}
743
744#endif /* CONFIG_SYS_CLOCK_EXISTS */
745
750struct _static_thread_data {
751 struct k_thread *init_thread;
752 k_thread_stack_t *init_stack;
753 unsigned int init_stack_size;
755 void *init_p1;
756 void *init_p2;
757 void *init_p3;
758 int init_prio;
759 uint32_t init_options;
760 const char *init_name;
761#ifdef CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME
762 int32_t init_delay_ms;
763#else
764 k_timeout_t init_delay;
765#endif
766};
767
768#ifdef CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME
769#define Z_THREAD_INIT_DELAY_INITIALIZER(ms) .init_delay_ms = (ms)
770#define Z_THREAD_INIT_DELAY(thread) SYS_TIMEOUT_MS((thread)->init_delay_ms)
771#else
772#define Z_THREAD_INIT_DELAY_INITIALIZER(ms) .init_delay = SYS_TIMEOUT_MS(ms)
773#define Z_THREAD_INIT_DELAY(thread) (thread)->init_delay
774#endif
775
776#define Z_THREAD_INITIALIZER(thread, stack, stack_size, \
777 entry, p1, p2, p3, \
778 prio, options, delay, tname) \
779 { \
780 .init_thread = (thread), \
781 .init_stack = (stack), \
782 .init_stack_size = (stack_size), \
783 .init_entry = (k_thread_entry_t)entry, \
784 .init_p1 = (void *)p1, \
785 .init_p2 = (void *)p2, \
786 .init_p3 = (void *)p3, \
787 .init_prio = (prio), \
788 .init_options = (options), \
789 .init_name = STRINGIFY(tname), \
790 Z_THREAD_INIT_DELAY_INITIALIZER(delay) \
791 }
792
793/*
794 * Refer to K_THREAD_DEFINE() and K_KERNEL_THREAD_DEFINE() for
795 * information on arguments.
796 */
797#define Z_THREAD_COMMON_DEFINE(name, stack_size, \
798 entry, p1, p2, p3, \
799 prio, options, delay) \
800 struct k_thread _k_thread_obj_##name; \
801 STRUCT_SECTION_ITERABLE(_static_thread_data, \
802 _k_thread_data_##name) = \
803 Z_THREAD_INITIALIZER(&_k_thread_obj_##name, \
804 _k_thread_stack_##name, stack_size,\
805 entry, p1, p2, p3, prio, options, \
806 delay, name); \
807 const k_tid_t name = (k_tid_t)&_k_thread_obj_##name
808
844#define K_THREAD_DEFINE(name, stack_size, \
845 entry, p1, p2, p3, \
846 prio, options, delay) \
847 K_THREAD_STACK_DEFINE(_k_thread_stack_##name, stack_size); \
848 Z_THREAD_COMMON_DEFINE(name, stack_size, entry, p1, p2, p3, \
849 prio, options, delay)
850
881#define K_KERNEL_THREAD_DEFINE(name, stack_size, \
882 entry, p1, p2, p3, \
883 prio, options, delay) \
884 K_KERNEL_STACK_DEFINE(_k_thread_stack_##name, stack_size); \
885 Z_THREAD_COMMON_DEFINE(name, stack_size, entry, p1, p2, p3, \
886 prio, options, delay)
887
897__syscall int k_thread_priority_get(k_tid_t thread);
898
924__syscall void k_thread_priority_set(k_tid_t thread, int prio);
925
926
927#ifdef CONFIG_SCHED_DEADLINE
960__syscall void k_thread_deadline_set(k_tid_t thread, int deadline);
961#endif
962
963#ifdef CONFIG_SCHED_CPU_MASK
977
991
1005
1019
1030int k_thread_cpu_pin(k_tid_t thread, int cpu);
1031#endif
1032
1053__syscall void k_thread_suspend(k_tid_t thread);
1054
1065__syscall void k_thread_resume(k_tid_t thread);
1066
1093void k_sched_time_slice_set(int32_t slice, int prio);
1094
1133void k_thread_time_slice_set(struct k_thread *th, int32_t slice_ticks,
1134 k_thread_timeslice_fn_t expired, void *data);
1135
1154bool k_is_in_isr(void);
1155
1172__syscall int k_is_preempt_thread(void);
1173
1185static inline bool k_is_pre_kernel(void)
1186{
1187 extern bool z_sys_post_kernel; /* in init.c */
1188
1189 return !z_sys_post_kernel;
1190}
1191
1226void k_sched_lock(void);
1227
1236
1249__syscall void k_thread_custom_data_set(void *value);
1250
1258__syscall void *k_thread_custom_data_get(void);
1259
1273__syscall int k_thread_name_set(k_tid_t thread, const char *str);
1274
1283const char *k_thread_name_get(k_tid_t thread);
1284
1296__syscall int k_thread_name_copy(k_tid_t thread, char *buf,
1297 size_t size);
1298
1311const char *k_thread_state_str(k_tid_t thread_id, char *buf, size_t buf_size);
1312
1330#define K_NO_WAIT Z_TIMEOUT_NO_WAIT
1331
1344#define K_NSEC(t) Z_TIMEOUT_NS(t)
1345
1358#define K_USEC(t) Z_TIMEOUT_US(t)
1359
1370#define K_CYC(t) Z_TIMEOUT_CYC(t)
1371
1382#define K_TICKS(t) Z_TIMEOUT_TICKS(t)
1383
1394#define K_MSEC(ms) Z_TIMEOUT_MS(ms)
1395
1406#define K_SECONDS(s) K_MSEC((s) * MSEC_PER_SEC)
1407
1418#define K_MINUTES(m) K_SECONDS((m) * 60)
1419
1430#define K_HOURS(h) K_MINUTES((h) * 60)
1431
1440#define K_FOREVER Z_FOREVER
1441
1442#ifdef CONFIG_TIMEOUT_64BIT
1443
1455#define K_TIMEOUT_ABS_TICKS(t) \
1456 Z_TIMEOUT_TICKS(Z_TICK_ABS((k_ticks_t)MAX(t, 0)))
1457
1469#define K_TIMEOUT_ABS_MS(t) K_TIMEOUT_ABS_TICKS(k_ms_to_ticks_ceil64(t))
1470
1483#define K_TIMEOUT_ABS_US(t) K_TIMEOUT_ABS_TICKS(k_us_to_ticks_ceil64(t))
1484
1497#define K_TIMEOUT_ABS_NS(t) K_TIMEOUT_ABS_TICKS(k_ns_to_ticks_ceil64(t))
1498
1511#define K_TIMEOUT_ABS_CYC(t) K_TIMEOUT_ABS_TICKS(k_cyc_to_ticks_ceil64(t))
1512
1513#endif
1514
1523struct k_timer {
1524 /*
1525 * _timeout structure must be first here if we want to use
1526 * dynamic timer allocation. timeout.node is used in the double-linked
1527 * list of free timers
1528 */
1529 struct _timeout timeout;
1530
1531 /* wait queue for the (single) thread waiting on this timer */
1532 _wait_q_t wait_q;
1533
1534 /* runs in ISR context */
1535 void (*expiry_fn)(struct k_timer *timer);
1536
1537 /* runs in the context of the thread that calls k_timer_stop() */
1538 void (*stop_fn)(struct k_timer *timer);
1539
1540 /* timer period */
1541 k_timeout_t period;
1542
1543 /* timer status */
1544 uint32_t status;
1545
1546 /* user-specific data, also used to support legacy features */
1547 void *user_data;
1548
1550
1551#ifdef CONFIG_OBJ_CORE_TIMER
1552 struct k_obj_core obj_core;
1553#endif
1554};
1555
1556#define Z_TIMER_INITIALIZER(obj, expiry, stop) \
1557 { \
1558 .timeout = { \
1559 .node = {},\
1560 .fn = z_timer_expiration_handler, \
1561 .dticks = 0, \
1562 }, \
1563 .wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
1564 .expiry_fn = expiry, \
1565 .stop_fn = stop, \
1566 .status = 0, \
1567 .user_data = 0, \
1568 }
1569
1590typedef void (*k_timer_expiry_t)(struct k_timer *timer);
1591
1606typedef void (*k_timer_stop_t)(struct k_timer *timer);
1607
1619#define K_TIMER_DEFINE(name, expiry_fn, stop_fn) \
1620 STRUCT_SECTION_ITERABLE(k_timer, name) = \
1621 Z_TIMER_INITIALIZER(name, expiry_fn, stop_fn)
1622
1632void k_timer_init(struct k_timer *timer,
1633 k_timer_expiry_t expiry_fn,
1634 k_timer_stop_t stop_fn);
1635
1650__syscall void k_timer_start(struct k_timer *timer,
1651 k_timeout_t duration, k_timeout_t period);
1652
1669__syscall void k_timer_stop(struct k_timer *timer);
1670
1683__syscall uint32_t k_timer_status_get(struct k_timer *timer);
1684
1702__syscall uint32_t k_timer_status_sync(struct k_timer *timer);
1703
1704#ifdef CONFIG_SYS_CLOCK_EXISTS
1705
1716__syscall k_ticks_t k_timer_expires_ticks(const struct k_timer *timer);
1717
1718static inline k_ticks_t z_impl_k_timer_expires_ticks(
1719 const struct k_timer *timer)
1720{
1721 return z_timeout_expires(&timer->timeout);
1722}
1723
1734__syscall k_ticks_t k_timer_remaining_ticks(const struct k_timer *timer);
1735
1736static inline k_ticks_t z_impl_k_timer_remaining_ticks(
1737 const struct k_timer *timer)
1738{
1739 return z_timeout_remaining(&timer->timeout);
1740}
1741
1752static inline uint32_t k_timer_remaining_get(struct k_timer *timer)
1753{
1755}
1756
1757#endif /* CONFIG_SYS_CLOCK_EXISTS */
1758
1771__syscall void k_timer_user_data_set(struct k_timer *timer, void *user_data);
1772
1776static inline void z_impl_k_timer_user_data_set(struct k_timer *timer,
1777 void *user_data)
1778{
1779 timer->user_data = user_data;
1780}
1781
1789__syscall void *k_timer_user_data_get(const struct k_timer *timer);
1790
1791static inline void *z_impl_k_timer_user_data_get(const struct k_timer *timer)
1792{
1793 return timer->user_data;
1794}
1795
1813__syscall int64_t k_uptime_ticks(void);
1814
1828static inline int64_t k_uptime_get(void)
1829{
1831}
1832
1852static inline uint32_t k_uptime_get_32(void)
1853{
1854 return (uint32_t)k_uptime_get();
1855}
1856
1865static inline uint32_t k_uptime_seconds(void)
1866{
1868}
1869
1881static inline int64_t k_uptime_delta(int64_t *reftime)
1882{
1883 int64_t uptime, delta;
1884
1885 uptime = k_uptime_get();
1886 delta = uptime - *reftime;
1887 *reftime = uptime;
1888
1889 return delta;
1890}
1891
1900static inline uint32_t k_cycle_get_32(void)
1901{
1902 return arch_k_cycle_get_32();
1903}
1904
1915static inline uint64_t k_cycle_get_64(void)
1916{
1917 if (!IS_ENABLED(CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER)) {
1918 __ASSERT(0, "64-bit cycle counter not enabled on this platform. "
1919 "See CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER");
1920 return 0;
1921 }
1922
1923 return arch_k_cycle_get_64();
1924}
1925
1930struct k_queue {
1933 _wait_q_t wait_q;
1934
1935 Z_DECL_POLL_EVENT
1936
1938};
1939
1944#define Z_QUEUE_INITIALIZER(obj) \
1945 { \
1946 .data_q = SYS_SFLIST_STATIC_INIT(&obj.data_q), \
1947 .lock = { }, \
1948 .wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
1949 Z_POLL_EVENT_OBJ_INIT(obj) \
1950 }
1951
1969__syscall void k_queue_init(struct k_queue *queue);
1970
1984__syscall void k_queue_cancel_wait(struct k_queue *queue);
1985
1998void k_queue_append(struct k_queue *queue, void *data);
1999
2016__syscall int32_t k_queue_alloc_append(struct k_queue *queue, void *data);
2017
2030void k_queue_prepend(struct k_queue *queue, void *data);
2031
2048__syscall int32_t k_queue_alloc_prepend(struct k_queue *queue, void *data);
2049
2063void k_queue_insert(struct k_queue *queue, void *prev, void *data);
2064
2083int k_queue_append_list(struct k_queue *queue, void *head, void *tail);
2084
2100int k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list);
2101
2119__syscall void *k_queue_get(struct k_queue *queue, k_timeout_t timeout);
2120
2137bool k_queue_remove(struct k_queue *queue, void *data);
2138
2153bool k_queue_unique_append(struct k_queue *queue, void *data);
2154
2168__syscall int k_queue_is_empty(struct k_queue *queue);
2169
2170static inline int z_impl_k_queue_is_empty(struct k_queue *queue)
2171{
2172 return sys_sflist_is_empty(&queue->data_q) ? 1 : 0;
2173}
2174
2184__syscall void *k_queue_peek_head(struct k_queue *queue);
2185
2195__syscall void *k_queue_peek_tail(struct k_queue *queue);
2196
2206#define K_QUEUE_DEFINE(name) \
2207 STRUCT_SECTION_ITERABLE(k_queue, name) = \
2208 Z_QUEUE_INITIALIZER(name)
2209
2212#ifdef CONFIG_USERSPACE
2222struct k_futex {
2224};
2225
2233struct z_futex_data {
2234 _wait_q_t wait_q;
2235 struct k_spinlock lock;
2236};
2237
2238#define Z_FUTEX_DATA_INITIALIZER(obj) \
2239 { \
2240 .wait_q = Z_WAIT_Q_INIT(&obj.wait_q) \
2241 }
2242
2268__syscall int k_futex_wait(struct k_futex *futex, int expected,
2269 k_timeout_t timeout);
2270
2285__syscall int k_futex_wake(struct k_futex *futex, bool wake_all);
2286
2288#endif
2289
2301struct k_event {
2302 _wait_q_t wait_q;
2305
2307
2308#ifdef CONFIG_OBJ_CORE_EVENT
2309 struct k_obj_core obj_core;
2310#endif
2311
2312};
2313
2314#define Z_EVENT_INITIALIZER(obj) \
2315 { \
2316 .wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
2317 .events = 0 \
2318 }
2319
2327__syscall void k_event_init(struct k_event *event);
2328
2344__syscall uint32_t k_event_post(struct k_event *event, uint32_t events);
2345
2361__syscall uint32_t k_event_set(struct k_event *event, uint32_t events);
2362
2377__syscall uint32_t k_event_set_masked(struct k_event *event, uint32_t events,
2378 uint32_t events_mask);
2379
2390__syscall uint32_t k_event_clear(struct k_event *event, uint32_t events);
2391
2413__syscall uint32_t k_event_wait(struct k_event *event, uint32_t events,
2414 bool reset, k_timeout_t timeout);
2415
2437__syscall uint32_t k_event_wait_all(struct k_event *event, uint32_t events,
2438 bool reset, k_timeout_t timeout);
2439
2448static inline uint32_t k_event_test(struct k_event *event, uint32_t events_mask)
2449{
2450 return k_event_wait(event, events_mask, false, K_NO_WAIT);
2451}
2452
2462#define K_EVENT_DEFINE(name) \
2463 STRUCT_SECTION_ITERABLE(k_event, name) = \
2464 Z_EVENT_INITIALIZER(name);
2465
2468struct k_fifo {
2469 struct k_queue _queue;
2470#ifdef CONFIG_OBJ_CORE_FIFO
2471 struct k_obj_core obj_core;
2472#endif
2473};
2474
2478#define Z_FIFO_INITIALIZER(obj) \
2479 { \
2480 ._queue = Z_QUEUE_INITIALIZER(obj._queue) \
2481 }
2482
2500#define k_fifo_init(fifo) \
2501 ({ \
2502 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, init, fifo); \
2503 k_queue_init(&(fifo)->_queue); \
2504 K_OBJ_CORE_INIT(K_OBJ_CORE(fifo), _obj_type_fifo); \
2505 K_OBJ_CORE_LINK(K_OBJ_CORE(fifo)); \
2506 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, init, fifo); \
2507 })
2508
2520#define k_fifo_cancel_wait(fifo) \
2521 ({ \
2522 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, cancel_wait, fifo); \
2523 k_queue_cancel_wait(&(fifo)->_queue); \
2524 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, cancel_wait, fifo); \
2525 })
2526
2539#define k_fifo_put(fifo, data) \
2540 ({ \
2541 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, put, fifo, data); \
2542 k_queue_append(&(fifo)->_queue, data); \
2543 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, put, fifo, data); \
2544 })
2545
2562#define k_fifo_alloc_put(fifo, data) \
2563 ({ \
2564 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, alloc_put, fifo, data); \
2565 int fap_ret = k_queue_alloc_append(&(fifo)->_queue, data); \
2566 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, alloc_put, fifo, data, fap_ret); \
2567 fap_ret; \
2568 })
2569
2584#define k_fifo_put_list(fifo, head, tail) \
2585 ({ \
2586 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, put_list, fifo, head, tail); \
2587 k_queue_append_list(&(fifo)->_queue, head, tail); \
2588 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, put_list, fifo, head, tail); \
2589 })
2590
2604#define k_fifo_put_slist(fifo, list) \
2605 ({ \
2606 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, put_slist, fifo, list); \
2607 k_queue_merge_slist(&(fifo)->_queue, list); \
2608 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, put_slist, fifo, list); \
2609 })
2610
2628#define k_fifo_get(fifo, timeout) \
2629 ({ \
2630 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, get, fifo, timeout); \
2631 void *fg_ret = k_queue_get(&(fifo)->_queue, timeout); \
2632 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, get, fifo, timeout, fg_ret); \
2633 fg_ret; \
2634 })
2635
2649#define k_fifo_is_empty(fifo) \
2650 k_queue_is_empty(&(fifo)->_queue)
2651
2665#define k_fifo_peek_head(fifo) \
2666 ({ \
2667 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, peek_head, fifo); \
2668 void *fph_ret = k_queue_peek_head(&(fifo)->_queue); \
2669 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, peek_head, fifo, fph_ret); \
2670 fph_ret; \
2671 })
2672
2684#define k_fifo_peek_tail(fifo) \
2685 ({ \
2686 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, peek_tail, fifo); \
2687 void *fpt_ret = k_queue_peek_tail(&(fifo)->_queue); \
2688 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, peek_tail, fifo, fpt_ret); \
2689 fpt_ret; \
2690 })
2691
2701#define K_FIFO_DEFINE(name) \
2702 STRUCT_SECTION_ITERABLE(k_fifo, name) = \
2703 Z_FIFO_INITIALIZER(name)
2704
2707struct k_lifo {
2708 struct k_queue _queue;
2709#ifdef CONFIG_OBJ_CORE_LIFO
2710 struct k_obj_core obj_core;
2711#endif
2712};
2713
2718#define Z_LIFO_INITIALIZER(obj) \
2719 { \
2720 ._queue = Z_QUEUE_INITIALIZER(obj._queue) \
2721 }
2722
2740#define k_lifo_init(lifo) \
2741 ({ \
2742 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, init, lifo); \
2743 k_queue_init(&(lifo)->_queue); \
2744 K_OBJ_CORE_INIT(K_OBJ_CORE(lifo), _obj_type_lifo); \
2745 K_OBJ_CORE_LINK(K_OBJ_CORE(lifo)); \
2746 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, init, lifo); \
2747 })
2748
2761#define k_lifo_put(lifo, data) \
2762 ({ \
2763 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, put, lifo, data); \
2764 k_queue_prepend(&(lifo)->_queue, data); \
2765 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, put, lifo, data); \
2766 })
2767
2784#define k_lifo_alloc_put(lifo, data) \
2785 ({ \
2786 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, alloc_put, lifo, data); \
2787 int lap_ret = k_queue_alloc_prepend(&(lifo)->_queue, data); \
2788 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, alloc_put, lifo, data, lap_ret); \
2789 lap_ret; \
2790 })
2791
2809#define k_lifo_get(lifo, timeout) \
2810 ({ \
2811 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, get, lifo, timeout); \
2812 void *lg_ret = k_queue_get(&(lifo)->_queue, timeout); \
2813 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, get, lifo, timeout, lg_ret); \
2814 lg_ret; \
2815 })
2816
2826#define K_LIFO_DEFINE(name) \
2827 STRUCT_SECTION_ITERABLE(k_lifo, name) = \
2828 Z_LIFO_INITIALIZER(name)
2829
2835#define K_STACK_FLAG_ALLOC ((uint8_t)1) /* Buffer was allocated */
2836
2837typedef uintptr_t stack_data_t;
2838
2839struct k_stack {
2840 _wait_q_t wait_q;
2841 struct k_spinlock lock;
2842 stack_data_t *base, *next, *top;
2843
2844 uint8_t flags;
2845
2847
2848#ifdef CONFIG_OBJ_CORE_STACK
2849 struct k_obj_core obj_core;
2850#endif
2851};
2852
2853#define Z_STACK_INITIALIZER(obj, stack_buffer, stack_num_entries) \
2854 { \
2855 .wait_q = Z_WAIT_Q_INIT(&(obj).wait_q), \
2856 .base = (stack_buffer), \
2857 .next = (stack_buffer), \
2858 .top = (stack_buffer) + (stack_num_entries), \
2859 }
2860
2880void k_stack_init(struct k_stack *stack,
2881 stack_data_t *buffer, uint32_t num_entries);
2882
2883
2898__syscall int32_t k_stack_alloc_init(struct k_stack *stack,
2899 uint32_t num_entries);
2900
2912int k_stack_cleanup(struct k_stack *stack);
2913
2927__syscall int k_stack_push(struct k_stack *stack, stack_data_t data);
2928
2949__syscall int k_stack_pop(struct k_stack *stack, stack_data_t *data,
2950 k_timeout_t timeout);
2951
2962#define K_STACK_DEFINE(name, stack_num_entries) \
2963 stack_data_t __noinit \
2964 _k_stack_buf_##name[stack_num_entries]; \
2965 STRUCT_SECTION_ITERABLE(k_stack, name) = \
2966 Z_STACK_INITIALIZER(name, _k_stack_buf_##name, \
2967 stack_num_entries)
2968
2975struct k_work;
2976struct k_work_q;
2977struct k_work_queue_config;
2978extern struct k_work_q k_sys_work_q;
2979
2994struct k_mutex {
2996 _wait_q_t wait_q;
2999
3002
3005
3007
3008#ifdef CONFIG_OBJ_CORE_MUTEX
3009 struct k_obj_core obj_core;
3010#endif
3011};
3012
3016#define Z_MUTEX_INITIALIZER(obj) \
3017 { \
3018 .wait_q = Z_WAIT_Q_INIT(&(obj).wait_q), \
3019 .owner = NULL, \
3020 .lock_count = 0, \
3021 .owner_orig_prio = K_LOWEST_APPLICATION_THREAD_PRIO, \
3022 }
3023
3037#define K_MUTEX_DEFINE(name) \
3038 STRUCT_SECTION_ITERABLE(k_mutex, name) = \
3039 Z_MUTEX_INITIALIZER(name)
3040
3053__syscall int k_mutex_init(struct k_mutex *mutex);
3054
3055
3077__syscall int k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout);
3078
3099__syscall int k_mutex_unlock(struct k_mutex *mutex);
3100
3107 _wait_q_t wait_q;
3108
3109#ifdef CONFIG_OBJ_CORE_CONDVAR
3110 struct k_obj_core obj_core;
3111#endif
3112};
3113
3114#define Z_CONDVAR_INITIALIZER(obj) \
3115 { \
3116 .wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
3117 }
3118
3131__syscall int k_condvar_init(struct k_condvar *condvar);
3132
3139__syscall int k_condvar_signal(struct k_condvar *condvar);
3140
3148__syscall int k_condvar_broadcast(struct k_condvar *condvar);
3149
3167__syscall int k_condvar_wait(struct k_condvar *condvar, struct k_mutex *mutex,
3168 k_timeout_t timeout);
3169
3180#define K_CONDVAR_DEFINE(name) \
3181 STRUCT_SECTION_ITERABLE(k_condvar, name) = \
3182 Z_CONDVAR_INITIALIZER(name)
3191struct k_sem {
3192 _wait_q_t wait_q;
3193 unsigned int count;
3194 unsigned int limit;
3195
3196 Z_DECL_POLL_EVENT
3197
3199
3200#ifdef CONFIG_OBJ_CORE_SEM
3201 struct k_obj_core obj_core;
3202#endif
3203};
3204
3205#define Z_SEM_INITIALIZER(obj, initial_count, count_limit) \
3206 { \
3207 .wait_q = Z_WAIT_Q_INIT(&(obj).wait_q), \
3208 .count = (initial_count), \
3209 .limit = (count_limit), \
3210 Z_POLL_EVENT_OBJ_INIT(obj) \
3211 }
3212
3231#define K_SEM_MAX_LIMIT UINT_MAX
3232
3248__syscall int k_sem_init(struct k_sem *sem, unsigned int initial_count,
3249 unsigned int limit);
3250
3269__syscall int k_sem_take(struct k_sem *sem, k_timeout_t timeout);
3270
3281__syscall void k_sem_give(struct k_sem *sem);
3282
3292__syscall void k_sem_reset(struct k_sem *sem);
3293
3303__syscall unsigned int k_sem_count_get(struct k_sem *sem);
3304
3308static inline unsigned int z_impl_k_sem_count_get(struct k_sem *sem)
3309{
3310 return sem->count;
3311}
3312
3324#define K_SEM_DEFINE(name, initial_count, count_limit) \
3325 STRUCT_SECTION_ITERABLE(k_sem, name) = \
3326 Z_SEM_INITIALIZER(name, initial_count, count_limit); \
3327 BUILD_ASSERT(((count_limit) != 0) && \
3328 ((initial_count) <= (count_limit)) && \
3329 ((count_limit) <= K_SEM_MAX_LIMIT));
3330
3337struct k_work_delayable;
3338struct k_work_sync;
3339
3356typedef void (*k_work_handler_t)(struct k_work *work);
3357
3371void k_work_init(struct k_work *work,
3373
3388int k_work_busy_get(const struct k_work *work);
3389
3403static inline bool k_work_is_pending(const struct k_work *work);
3404
3426 struct k_work *work);
3427
3436int k_work_submit(struct k_work *work);
3437
3462bool k_work_flush(struct k_work *work,
3463 struct k_work_sync *sync);
3464
3484int k_work_cancel(struct k_work *work);
3485
3516bool k_work_cancel_sync(struct k_work *work, struct k_work_sync *sync);
3517
3528
3549 k_thread_stack_t *stack, size_t stack_size,
3550 int prio, const struct k_work_queue_config *cfg);
3551
3561static inline k_tid_t k_work_queue_thread_get(struct k_work_q *queue);
3562
3586int k_work_queue_drain(struct k_work_q *queue, bool plug);
3587
3602
3618
3630static inline struct k_work_delayable *
3632
3647
3662static inline bool k_work_delayable_is_pending(
3663 const struct k_work_delayable *dwork);
3664
3679 const struct k_work_delayable *dwork);
3680
3695 const struct k_work_delayable *dwork);
3696
3725 struct k_work_delayable *dwork,
3726 k_timeout_t delay);
3727
3742 k_timeout_t delay);
3743
3780 struct k_work_delayable *dwork,
3781 k_timeout_t delay);
3782
3796 k_timeout_t delay);
3797
3823 struct k_work_sync *sync);
3824
3846
3876 struct k_work_sync *sync);
3877
3878enum {
3883 /* The atomic API is used for all work and queue flags fields to
3884 * enforce sequential consistency in SMP environments.
3885 */
3886
3887 /* Bits that represent the work item states. At least nine of the
3888 * combinations are distinct valid stable states.
3889 */
3890 K_WORK_RUNNING_BIT = 0,
3891 K_WORK_CANCELING_BIT = 1,
3892 K_WORK_QUEUED_BIT = 2,
3893 K_WORK_DELAYED_BIT = 3,
3894 K_WORK_FLUSHING_BIT = 4,
3895
3896 K_WORK_MASK = BIT(K_WORK_DELAYED_BIT) | BIT(K_WORK_QUEUED_BIT)
3897 | BIT(K_WORK_RUNNING_BIT) | BIT(K_WORK_CANCELING_BIT) | BIT(K_WORK_FLUSHING_BIT),
3898
3899 /* Static work flags */
3900 K_WORK_DELAYABLE_BIT = 8,
3901 K_WORK_DELAYABLE = BIT(K_WORK_DELAYABLE_BIT),
3902
3903 /* Dynamic work queue flags */
3904 K_WORK_QUEUE_STARTED_BIT = 0,
3905 K_WORK_QUEUE_STARTED = BIT(K_WORK_QUEUE_STARTED_BIT),
3906 K_WORK_QUEUE_BUSY_BIT = 1,
3907 K_WORK_QUEUE_BUSY = BIT(K_WORK_QUEUE_BUSY_BIT),
3908 K_WORK_QUEUE_DRAIN_BIT = 2,
3909 K_WORK_QUEUE_DRAIN = BIT(K_WORK_QUEUE_DRAIN_BIT),
3910 K_WORK_QUEUE_PLUGGED_BIT = 3,
3911 K_WORK_QUEUE_PLUGGED = BIT(K_WORK_QUEUE_PLUGGED_BIT),
3912
3913 /* Static work queue flags */
3914 K_WORK_QUEUE_NO_YIELD_BIT = 8,
3915 K_WORK_QUEUE_NO_YIELD = BIT(K_WORK_QUEUE_NO_YIELD_BIT),
3916
3920 /* Transient work flags */
3921
3927 K_WORK_RUNNING = BIT(K_WORK_RUNNING_BIT),
3928
3933 K_WORK_CANCELING = BIT(K_WORK_CANCELING_BIT),
3934
3940 K_WORK_QUEUED = BIT(K_WORK_QUEUED_BIT),
3941
3947 K_WORK_DELAYED = BIT(K_WORK_DELAYED_BIT),
3948
3953 K_WORK_FLUSHING = BIT(K_WORK_FLUSHING_BIT),
3954};
3955
3957struct k_work {
3958 /* All fields are protected by the work module spinlock. No fields
3959 * are to be accessed except through kernel API.
3960 */
3961
3962 /* Node to link into k_work_q pending list. */
3964
3965 /* The function to be invoked by the work queue thread. */
3967
3968 /* The queue on which the work item was last submitted. */
3970
3971 /* State of the work item.
3972 *
3973 * The item can be DELAYED, QUEUED, and RUNNING simultaneously.
3974 *
3975 * It can be RUNNING and CANCELING simultaneously.
3976 */
3978};
3979
3980#define Z_WORK_INITIALIZER(work_handler) { \
3981 .handler = (work_handler), \
3982}
3983
3986 /* The work item. */
3987 struct k_work work;
3988
3989 /* Timeout used to submit work after a delay. */
3990 struct _timeout timeout;
3991
3992 /* The queue to which the work should be submitted. */
3994};
3995
3996#define Z_WORK_DELAYABLE_INITIALIZER(work_handler) { \
3997 .work = { \
3998 .handler = (work_handler), \
3999 .flags = K_WORK_DELAYABLE, \
4000 }, \
4001}
4002
4019#define K_WORK_DELAYABLE_DEFINE(work, work_handler) \
4020 struct k_work_delayable work \
4021 = Z_WORK_DELAYABLE_INITIALIZER(work_handler)
4022
4027/* Record used to wait for work to flush.
4028 *
4029 * The work item is inserted into the queue that will process (or is
4030 * processing) the item, and will be processed as soon as the item
4031 * completes. When the flusher is processed the semaphore will be
4032 * signaled, releasing the thread waiting for the flush.
4033 */
4034struct z_work_flusher {
4035 struct k_work work;
4036 struct k_sem sem;
4037};
4038
4039/* Record used to wait for work to complete a cancellation.
4040 *
4041 * The work item is inserted into a global queue of pending cancels.
4042 * When a cancelling work item goes idle any matching waiters are
4043 * removed from pending_cancels and are woken.
4044 */
4045struct z_work_canceller {
4046 sys_snode_t node;
4047 struct k_work *work;
4048 struct k_sem sem;
4049};
4050
4069 union {
4070 struct z_work_flusher flusher;
4071 struct z_work_canceller canceller;
4072 };
4073};
4074
4086 const char *name;
4087
4101
4106};
4107
4109struct k_work_q {
4110 /* The thread that animates the work. */
4112
4113 /* All the following fields must be accessed only while the
4114 * work module spinlock is held.
4115 */
4116
4117 /* List of k_work items to be worked. */
4119
4120 /* Wait queue for idle work thread. */
4121 _wait_q_t notifyq;
4122
4123 /* Wait queue for threads waiting for the queue to drain. */
4124 _wait_q_t drainq;
4125
4126 /* Flags describing queue state. */
4128};
4129
4130/* Provide the implementation for inline functions declared above */
4131
4132static inline bool k_work_is_pending(const struct k_work *work)
4133{
4134 return k_work_busy_get(work) != 0;
4135}
4136
4137static inline struct k_work_delayable *
4142
4144 const struct k_work_delayable *dwork)
4145{
4146 return k_work_delayable_busy_get(dwork) != 0;
4147}
4148
4150 const struct k_work_delayable *dwork)
4151{
4152 return z_timeout_expires(&dwork->timeout);
4153}
4154
4156 const struct k_work_delayable *dwork)
4157{
4158 return z_timeout_remaining(&dwork->timeout);
4159}
4160
4162{
4163 return &queue->thread;
4164}
4165
4168struct k_work_user;
4169
4184typedef void (*k_work_user_handler_t)(struct k_work_user *work);
4185
4190struct k_work_user_q {
4191 struct k_queue queue;
4192 struct k_thread thread;
4193};
4194
4195enum {
4196 K_WORK_USER_STATE_PENDING, /* Work item pending state */
4197};
4198
4199struct k_work_user {
4200 void *_reserved; /* Used by k_queue implementation. */
4201 k_work_user_handler_t handler;
4203};
4204
4209#if defined(__cplusplus) && ((__cplusplus - 0) < 202002L)
4210#define Z_WORK_USER_INITIALIZER(work_handler) { NULL, work_handler, 0 }
4211#else
4212#define Z_WORK_USER_INITIALIZER(work_handler) \
4213 { \
4214 ._reserved = NULL, \
4215 .handler = (work_handler), \
4216 .flags = 0 \
4217 }
4218#endif
4219
4231#define K_WORK_USER_DEFINE(work, work_handler) \
4232 struct k_work_user work = Z_WORK_USER_INITIALIZER(work_handler)
4233
4243static inline void k_work_user_init(struct k_work_user *work,
4244 k_work_user_handler_t handler)
4245{
4246 *work = (struct k_work_user)Z_WORK_USER_INITIALIZER(handler);
4247}
4248
4265static inline bool k_work_user_is_pending(struct k_work_user *work)
4266{
4267 return atomic_test_bit(&work->flags, K_WORK_USER_STATE_PENDING);
4268}
4269
4288static inline int k_work_user_submit_to_queue(struct k_work_user_q *work_q,
4289 struct k_work_user *work)
4290{
4291 int ret = -EBUSY;
4292
4293 if (!atomic_test_and_set_bit(&work->flags,
4294 K_WORK_USER_STATE_PENDING)) {
4295 ret = k_queue_alloc_append(&work_q->queue, work);
4296
4297 /* Couldn't insert into the queue. Clear the pending bit
4298 * so the work item can be submitted again
4299 */
4300 if (ret != 0) {
4301 atomic_clear_bit(&work->flags,
4302 K_WORK_USER_STATE_PENDING);
4303 }
4304 }
4305
4306 return ret;
4307}
4308
4328void k_work_user_queue_start(struct k_work_user_q *work_q,
4329 k_thread_stack_t *stack,
4330 size_t stack_size, int prio,
4331 const char *name);
4332
4343static inline k_tid_t k_work_user_queue_thread_get(struct k_work_user_q *work_q)
4344{
4345 return &work_q->thread;
4346}
4347
4354struct k_work_poll {
4355 struct k_work work;
4356 struct k_work_q *workq;
4357 struct z_poller poller;
4358 struct k_poll_event *events;
4359 int num_events;
4360 k_work_handler_t real_handler;
4361 struct _timeout timeout;
4362 int poll_result;
4363};
4364
4385#define K_WORK_DEFINE(work, work_handler) \
4386 struct k_work work = Z_WORK_INITIALIZER(work_handler)
4387
4397void k_work_poll_init(struct k_work_poll *work,
4398 k_work_handler_t handler);
4399
4435 struct k_work_poll *work,
4436 struct k_poll_event *events,
4437 int num_events,
4438 k_timeout_t timeout);
4439
4471int k_work_poll_submit(struct k_work_poll *work,
4472 struct k_poll_event *events,
4473 int num_events,
4474 k_timeout_t timeout);
4475
4490int k_work_poll_cancel(struct k_work_poll *work);
4491
4503struct k_msgq {
4505 _wait_q_t wait_q;
4509 size_t msg_size;
4522
4523 Z_DECL_POLL_EVENT
4524
4527
4529
4530#ifdef CONFIG_OBJ_CORE_MSGQ
4531 struct k_obj_core obj_core;
4532#endif
4533};
4539#define Z_MSGQ_INITIALIZER(obj, q_buffer, q_msg_size, q_max_msgs) \
4540 { \
4541 .wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
4542 .msg_size = q_msg_size, \
4543 .max_msgs = q_max_msgs, \
4544 .buffer_start = q_buffer, \
4545 .buffer_end = q_buffer + (q_max_msgs * q_msg_size), \
4546 .read_ptr = q_buffer, \
4547 .write_ptr = q_buffer, \
4548 .used_msgs = 0, \
4549 Z_POLL_EVENT_OBJ_INIT(obj) \
4550 }
4551
4557#define K_MSGQ_FLAG_ALLOC BIT(0)
4558
4570
4571
4590#define K_MSGQ_DEFINE(q_name, q_msg_size, q_max_msgs, q_align) \
4591 static char __noinit __aligned(q_align) \
4592 _k_fifo_buf_##q_name[(q_max_msgs) * (q_msg_size)]; \
4593 STRUCT_SECTION_ITERABLE(k_msgq, q_name) = \
4594 Z_MSGQ_INITIALIZER(q_name, _k_fifo_buf_##q_name, \
4595 (q_msg_size), (q_max_msgs))
4596
4611void k_msgq_init(struct k_msgq *msgq, char *buffer, size_t msg_size,
4612 uint32_t max_msgs);
4613
4633__syscall int k_msgq_alloc_init(struct k_msgq *msgq, size_t msg_size,
4634 uint32_t max_msgs);
4635
4646int k_msgq_cleanup(struct k_msgq *msgq);
4647
4668__syscall int k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t timeout);
4669
4690__syscall int k_msgq_get(struct k_msgq *msgq, void *data, k_timeout_t timeout);
4691
4706__syscall int k_msgq_peek(struct k_msgq *msgq, void *data);
4707
4724__syscall int k_msgq_peek_at(struct k_msgq *msgq, void *data, uint32_t idx);
4725
4735__syscall void k_msgq_purge(struct k_msgq *msgq);
4736
4747__syscall uint32_t k_msgq_num_free_get(struct k_msgq *msgq);
4748
4757__syscall void k_msgq_get_attrs(struct k_msgq *msgq,
4758 struct k_msgq_attrs *attrs);
4759
4760
4761static inline uint32_t z_impl_k_msgq_num_free_get(struct k_msgq *msgq)
4762{
4763 return msgq->max_msgs - msgq->used_msgs;
4764}
4765
4775__syscall uint32_t k_msgq_num_used_get(struct k_msgq *msgq);
4776
4777static inline uint32_t z_impl_k_msgq_num_used_get(struct k_msgq *msgq)
4778{
4779 return msgq->used_msgs;
4780}
4781
4796 size_t size;
4800 void *tx_data;
4806 k_tid_t _syncing_thread;
4807#if (CONFIG_NUM_MBOX_ASYNC_MSGS > 0)
4809 struct k_sem *_async_sem;
4810#endif
4811};
4816struct k_mbox {
4818 _wait_q_t tx_msg_queue;
4820 _wait_q_t rx_msg_queue;
4822
4824
4825#ifdef CONFIG_OBJ_CORE_MAILBOX
4826 struct k_obj_core obj_core;
4827#endif
4828};
4833#define Z_MBOX_INITIALIZER(obj) \
4834 { \
4835 .tx_msg_queue = Z_WAIT_Q_INIT(&obj.tx_msg_queue), \
4836 .rx_msg_queue = Z_WAIT_Q_INIT(&obj.rx_msg_queue), \
4837 }
4838
4852#define K_MBOX_DEFINE(name) \
4853 STRUCT_SECTION_ITERABLE(k_mbox, name) = \
4854 Z_MBOX_INITIALIZER(name) \
4855
4863void k_mbox_init(struct k_mbox *mbox);
4864
4884int k_mbox_put(struct k_mbox *mbox, struct k_mbox_msg *tx_msg,
4885 k_timeout_t timeout);
4886
4900void k_mbox_async_put(struct k_mbox *mbox, struct k_mbox_msg *tx_msg,
4901 struct k_sem *sem);
4902
4920int k_mbox_get(struct k_mbox *mbox, struct k_mbox_msg *rx_msg,
4921 void *buffer, k_timeout_t timeout);
4922
4936void k_mbox_data_get(struct k_mbox_msg *rx_msg, void *buffer);
4937
4947struct k_pipe {
4948 unsigned char *buffer;
4949 size_t size;
4950 size_t bytes_used;
4951 size_t read_index;
4955 struct {
4956 _wait_q_t readers;
4957 _wait_q_t writers;
4960 Z_DECL_POLL_EVENT
4961
4965
4966#ifdef CONFIG_OBJ_CORE_PIPE
4967 struct k_obj_core obj_core;
4968#endif
4969};
4970
4974#define K_PIPE_FLAG_ALLOC BIT(0)
4976#define Z_PIPE_INITIALIZER(obj, pipe_buffer, pipe_buffer_size) \
4977 { \
4978 .buffer = pipe_buffer, \
4979 .size = pipe_buffer_size, \
4980 .bytes_used = 0, \
4981 .read_index = 0, \
4982 .write_index = 0, \
4983 .lock = {}, \
4984 .wait_q = { \
4985 .readers = Z_WAIT_Q_INIT(&obj.wait_q.readers), \
4986 .writers = Z_WAIT_Q_INIT(&obj.wait_q.writers) \
4987 }, \
4988 Z_POLL_EVENT_OBJ_INIT(obj) \
4989 .flags = 0, \
4990 }
4991
5009#define K_PIPE_DEFINE(name, pipe_buffer_size, pipe_align) \
5010 static unsigned char __noinit __aligned(pipe_align) \
5011 _k_pipe_buf_##name[pipe_buffer_size]; \
5012 STRUCT_SECTION_ITERABLE(k_pipe, name) = \
5013 Z_PIPE_INITIALIZER(name, _k_pipe_buf_##name, pipe_buffer_size)
5014
5026void k_pipe_init(struct k_pipe *pipe, unsigned char *buffer, size_t size);
5027
5039int k_pipe_cleanup(struct k_pipe *pipe);
5040
5056__syscall int k_pipe_alloc_init(struct k_pipe *pipe, size_t size);
5057
5076__syscall int k_pipe_put(struct k_pipe *pipe, const void *data,
5077 size_t bytes_to_write, size_t *bytes_written,
5078 size_t min_xfer, k_timeout_t timeout);
5079
5099__syscall int k_pipe_get(struct k_pipe *pipe, void *data,
5100 size_t bytes_to_read, size_t *bytes_read,
5101 size_t min_xfer, k_timeout_t timeout);
5102
5111__syscall size_t k_pipe_read_avail(struct k_pipe *pipe);
5112
5121__syscall size_t k_pipe_write_avail(struct k_pipe *pipe);
5122
5133__syscall void k_pipe_flush(struct k_pipe *pipe);
5134
5146__syscall void k_pipe_buffer_flush(struct k_pipe *pipe);
5147
5154struct k_mem_slab_info {
5155 uint32_t num_blocks;
5156 size_t block_size;
5157 uint32_t num_used;
5158#ifdef CONFIG_MEM_SLAB_TRACE_MAX_UTILIZATION
5159 uint32_t max_used;
5160#endif
5161};
5162
5163struct k_mem_slab {
5164 _wait_q_t wait_q;
5165 struct k_spinlock lock;
5166 char *buffer;
5167 char *free_list;
5168 struct k_mem_slab_info info;
5169
5171
5172#ifdef CONFIG_OBJ_CORE_MEM_SLAB
5173 struct k_obj_core obj_core;
5174#endif
5175};
5176
5177#define Z_MEM_SLAB_INITIALIZER(_slab, _slab_buffer, _slab_block_size, \
5178 _slab_num_blocks) \
5179 { \
5180 .wait_q = Z_WAIT_Q_INIT(&(_slab).wait_q), \
5181 .lock = {}, \
5182 .buffer = _slab_buffer, \
5183 .free_list = NULL, \
5184 .info = {_slab_num_blocks, _slab_block_size, 0} \
5185 }
5186
5187
5221#define K_MEM_SLAB_DEFINE(name, slab_block_size, slab_num_blocks, slab_align) \
5222 char __noinit_named(k_mem_slab_buf_##name) \
5223 __aligned(WB_UP(slab_align)) \
5224 _k_mem_slab_buf_##name[(slab_num_blocks) * WB_UP(slab_block_size)]; \
5225 STRUCT_SECTION_ITERABLE(k_mem_slab, name) = \
5226 Z_MEM_SLAB_INITIALIZER(name, _k_mem_slab_buf_##name, \
5227 WB_UP(slab_block_size), slab_num_blocks)
5228
5243#define K_MEM_SLAB_DEFINE_STATIC(name, slab_block_size, slab_num_blocks, slab_align) \
5244 static char __noinit_named(k_mem_slab_buf_##name) \
5245 __aligned(WB_UP(slab_align)) \
5246 _k_mem_slab_buf_##name[(slab_num_blocks) * WB_UP(slab_block_size)]; \
5247 static STRUCT_SECTION_ITERABLE(k_mem_slab, name) = \
5248 Z_MEM_SLAB_INITIALIZER(name, _k_mem_slab_buf_##name, \
5249 WB_UP(slab_block_size), slab_num_blocks)
5250
5272int k_mem_slab_init(struct k_mem_slab *slab, void *buffer,
5273 size_t block_size, uint32_t num_blocks);
5274
5297int k_mem_slab_alloc(struct k_mem_slab *slab, void **mem,
5298 k_timeout_t timeout);
5299
5309void k_mem_slab_free(struct k_mem_slab *slab, void *mem);
5310
5321static inline uint32_t k_mem_slab_num_used_get(struct k_mem_slab *slab)
5322{
5323 return slab->info.num_used;
5324}
5325
5336static inline uint32_t k_mem_slab_max_used_get(struct k_mem_slab *slab)
5337{
5338#ifdef CONFIG_MEM_SLAB_TRACE_MAX_UTILIZATION
5339 return slab->info.max_used;
5340#else
5341 ARG_UNUSED(slab);
5342 return 0;
5343#endif
5344}
5345
5356static inline uint32_t k_mem_slab_num_free_get(struct k_mem_slab *slab)
5357{
5358 return slab->info.num_blocks - slab->info.num_used;
5359}
5360
5373int k_mem_slab_runtime_stats_get(struct k_mem_slab *slab, struct sys_memory_stats *stats);
5374
5386int k_mem_slab_runtime_stats_reset_max(struct k_mem_slab *slab);
5387
5395/* kernel synchronized heap struct */
5396
5397struct k_heap {
5399 _wait_q_t wait_q;
5401};
5402
5416void k_heap_init(struct k_heap *h, void *mem,
5417 size_t bytes) __attribute_nonnull(1);
5418
5439void *k_heap_aligned_alloc(struct k_heap *h, size_t align, size_t bytes,
5440 k_timeout_t timeout) __attribute_nonnull(1);
5441
5463void *k_heap_alloc(struct k_heap *h, size_t bytes,
5464 k_timeout_t timeout) __attribute_nonnull(1);
5465
5489void *k_heap_realloc(struct k_heap *h, void *ptr, size_t bytes, k_timeout_t timeout)
5490 __attribute_nonnull(1);
5491
5502void k_heap_free(struct k_heap *h, void *mem) __attribute_nonnull(1);
5503
5504/* Hand-calculated minimum heap sizes needed to return a successful
5505 * 1-byte allocation. See details in lib/os/heap.[ch]
5506 */
5507#define Z_HEAP_MIN_SIZE ((sizeof(void *) > 4) ? 56 : 44)
5508
5525#define Z_HEAP_DEFINE_IN_SECT(name, bytes, in_section) \
5526 char in_section \
5527 __aligned(8) /* CHUNK_UNIT */ \
5528 kheap_##name[MAX(bytes, Z_HEAP_MIN_SIZE)]; \
5529 STRUCT_SECTION_ITERABLE(k_heap, name) = { \
5530 .heap = { \
5531 .init_mem = kheap_##name, \
5532 .init_bytes = MAX(bytes, Z_HEAP_MIN_SIZE), \
5533 }, \
5534 }
5535
5550#define K_HEAP_DEFINE(name, bytes) \
5551 Z_HEAP_DEFINE_IN_SECT(name, bytes, \
5552 __noinit_named(kheap_buf_##name))
5553
5568#define K_HEAP_DEFINE_NOCACHE(name, bytes) \
5569 Z_HEAP_DEFINE_IN_SECT(name, bytes, __nocache)
5570
5599void *k_aligned_alloc(size_t align, size_t size);
5600
5612void *k_malloc(size_t size);
5613
5624void k_free(void *ptr);
5625
5637void *k_calloc(size_t nmemb, size_t size);
5638
5656void *k_realloc(void *ptr, size_t size);
5657
5660/* polling API - PRIVATE */
5661
5662#ifdef CONFIG_POLL
5663#define _INIT_OBJ_POLL_EVENT(obj) do { (obj)->poll_event = NULL; } while (false)
5664#else
5665#define _INIT_OBJ_POLL_EVENT(obj) do { } while (false)
5666#endif
5667
5668/* private - types bit positions */
5669enum _poll_types_bits {
5670 /* can be used to ignore an event */
5671 _POLL_TYPE_IGNORE,
5672
5673 /* to be signaled by k_poll_signal_raise() */
5674 _POLL_TYPE_SIGNAL,
5675
5676 /* semaphore availability */
5677 _POLL_TYPE_SEM_AVAILABLE,
5678
5679 /* queue/FIFO/LIFO data availability */
5680 _POLL_TYPE_DATA_AVAILABLE,
5681
5682 /* msgq data availability */
5683 _POLL_TYPE_MSGQ_DATA_AVAILABLE,
5684
5685 /* pipe data availability */
5686 _POLL_TYPE_PIPE_DATA_AVAILABLE,
5687
5688 _POLL_NUM_TYPES
5689};
5690
5691#define Z_POLL_TYPE_BIT(type) (1U << ((type) - 1U))
5692
5693/* private - states bit positions */
5694enum _poll_states_bits {
5695 /* default state when creating event */
5696 _POLL_STATE_NOT_READY,
5697
5698 /* signaled by k_poll_signal_raise() */
5699 _POLL_STATE_SIGNALED,
5700
5701 /* semaphore is available */
5702 _POLL_STATE_SEM_AVAILABLE,
5703
5704 /* data is available to read on queue/FIFO/LIFO */
5705 _POLL_STATE_DATA_AVAILABLE,
5706
5707 /* queue/FIFO/LIFO wait was cancelled */
5708 _POLL_STATE_CANCELLED,
5709
5710 /* data is available to read on a message queue */
5711 _POLL_STATE_MSGQ_DATA_AVAILABLE,
5712
5713 /* data is available to read from a pipe */
5714 _POLL_STATE_PIPE_DATA_AVAILABLE,
5715
5716 _POLL_NUM_STATES
5717};
5718
5719#define Z_POLL_STATE_BIT(state) (1U << ((state) - 1U))
5720
5721#define _POLL_EVENT_NUM_UNUSED_BITS \
5722 (32 - (0 \
5723 + 8 /* tag */ \
5724 + _POLL_NUM_TYPES \
5725 + _POLL_NUM_STATES \
5726 + 1 /* modes */ \
5727 ))
5728
5729/* end of polling API - PRIVATE */
5730
5731
5738/* Public polling API */
5739
5740/* public - values for k_poll_event.type bitfield */
5741#define K_POLL_TYPE_IGNORE 0
5742#define K_POLL_TYPE_SIGNAL Z_POLL_TYPE_BIT(_POLL_TYPE_SIGNAL)
5743#define K_POLL_TYPE_SEM_AVAILABLE Z_POLL_TYPE_BIT(_POLL_TYPE_SEM_AVAILABLE)
5744#define K_POLL_TYPE_DATA_AVAILABLE Z_POLL_TYPE_BIT(_POLL_TYPE_DATA_AVAILABLE)
5745#define K_POLL_TYPE_FIFO_DATA_AVAILABLE K_POLL_TYPE_DATA_AVAILABLE
5746#define K_POLL_TYPE_MSGQ_DATA_AVAILABLE Z_POLL_TYPE_BIT(_POLL_TYPE_MSGQ_DATA_AVAILABLE)
5747#define K_POLL_TYPE_PIPE_DATA_AVAILABLE Z_POLL_TYPE_BIT(_POLL_TYPE_PIPE_DATA_AVAILABLE)
5748
5749/* public - polling modes */
5751 /* polling thread does not take ownership of objects when available */
5753
5756
5757/* public - values for k_poll_event.state bitfield */
5758#define K_POLL_STATE_NOT_READY 0
5759#define K_POLL_STATE_SIGNALED Z_POLL_STATE_BIT(_POLL_STATE_SIGNALED)
5760#define K_POLL_STATE_SEM_AVAILABLE Z_POLL_STATE_BIT(_POLL_STATE_SEM_AVAILABLE)
5761#define K_POLL_STATE_DATA_AVAILABLE Z_POLL_STATE_BIT(_POLL_STATE_DATA_AVAILABLE)
5762#define K_POLL_STATE_FIFO_DATA_AVAILABLE K_POLL_STATE_DATA_AVAILABLE
5763#define K_POLL_STATE_MSGQ_DATA_AVAILABLE Z_POLL_STATE_BIT(_POLL_STATE_MSGQ_DATA_AVAILABLE)
5764#define K_POLL_STATE_PIPE_DATA_AVAILABLE Z_POLL_STATE_BIT(_POLL_STATE_PIPE_DATA_AVAILABLE)
5765#define K_POLL_STATE_CANCELLED Z_POLL_STATE_BIT(_POLL_STATE_CANCELLED)
5766
5767/* public - poll signal object */
5771
5776 unsigned int signaled;
5777
5780};
5781
5782#define K_POLL_SIGNAL_INITIALIZER(obj) \
5783 { \
5784 .poll_events = SYS_DLIST_STATIC_INIT(&obj.poll_events), \
5785 .signaled = 0, \
5786 .result = 0, \
5787 }
5794 sys_dnode_t _node;
5795
5797 struct z_poller *poller;
5798
5801
5803 uint32_t type:_POLL_NUM_TYPES;
5804
5806 uint32_t state:_POLL_NUM_STATES;
5807
5810
5812 uint32_t unused:_POLL_EVENT_NUM_UNUSED_BITS;
5813
5815 union {
5816 /* The typed_* fields below are used by K_POLL_EVENT_*INITIALIZER() macros to ensure
5817 * type safety of polled objects.
5818 */
5819 void *obj, *typed_K_POLL_TYPE_IGNORE;
5820 struct k_poll_signal *signal, *typed_K_POLL_TYPE_SIGNAL;
5821 struct k_sem *sem, *typed_K_POLL_TYPE_SEM_AVAILABLE;
5822 struct k_fifo *fifo, *typed_K_POLL_TYPE_FIFO_DATA_AVAILABLE;
5823 struct k_queue *queue, *typed_K_POLL_TYPE_DATA_AVAILABLE;
5824 struct k_msgq *msgq, *typed_K_POLL_TYPE_MSGQ_DATA_AVAILABLE;
5825#ifdef CONFIG_PIPES
5826 struct k_pipe *pipe, *typed_K_POLL_TYPE_PIPE_DATA_AVAILABLE;
5827#endif
5828 };
5829};
5830
5831#define K_POLL_EVENT_INITIALIZER(_event_type, _event_mode, _event_obj) \
5832 { \
5833 .poller = NULL, \
5834 .type = _event_type, \
5835 .state = K_POLL_STATE_NOT_READY, \
5836 .mode = _event_mode, \
5837 .unused = 0, \
5838 { \
5839 .typed_##_event_type = _event_obj, \
5840 }, \
5841 }
5842
5843#define K_POLL_EVENT_STATIC_INITIALIZER(_event_type, _event_mode, _event_obj, \
5844 event_tag) \
5845 { \
5846 .tag = event_tag, \
5847 .type = _event_type, \
5848 .state = K_POLL_STATE_NOT_READY, \
5849 .mode = _event_mode, \
5850 .unused = 0, \
5851 { \
5852 .typed_##_event_type = _event_obj, \
5853 }, \
5854 }
5855
5871void k_poll_event_init(struct k_poll_event *event, uint32_t type,
5872 int mode, void *obj);
5873
5917__syscall int k_poll(struct k_poll_event *events, int num_events,
5918 k_timeout_t timeout);
5919
5928__syscall void k_poll_signal_init(struct k_poll_signal *sig);
5929
5935__syscall void k_poll_signal_reset(struct k_poll_signal *sig);
5936
5947__syscall void k_poll_signal_check(struct k_poll_signal *sig,
5948 unsigned int *signaled, int *result);
5949
5974__syscall int k_poll_signal_raise(struct k_poll_signal *sig, int result);
5975
5996static inline void k_cpu_idle(void)
5997{
5998 arch_cpu_idle();
5999}
6000
6015static inline void k_cpu_atomic_idle(unsigned int key)
6016{
6018}
6019
6028#ifdef ARCH_EXCEPT
6029/* This architecture has direct support for triggering a CPU exception */
6030#define z_except_reason(reason) ARCH_EXCEPT(reason)
6031#else
6032
6033#if !defined(CONFIG_ASSERT_NO_FILE_INFO)
6034#define __EXCEPT_LOC() __ASSERT_PRINT("@ %s:%d\n", __FILE__, __LINE__)
6035#else
6036#define __EXCEPT_LOC()
6037#endif
6038
6039/* NOTE: This is the implementation for arches that do not implement
6040 * ARCH_EXCEPT() to generate a real CPU exception.
6041 *
6042 * We won't have a real exception frame to determine the PC value when
6043 * the oops occurred, so print file and line number before we jump into
6044 * the fatal error handler.
6045 */
6046#define z_except_reason(reason) do { \
6047 __EXCEPT_LOC(); \
6048 z_fatal_error(reason, NULL); \
6049 } while (false)
6050
6051#endif /* _ARCH__EXCEPT */
6067#define k_oops() z_except_reason(K_ERR_KERNEL_OOPS)
6068
6077#define k_panic() z_except_reason(K_ERR_KERNEL_PANIC)
6078
6083/*
6084 * private APIs that are utilized by one or more public APIs
6085 */
6086
6090void z_timer_expiration_handler(struct _timeout *timeout);
6095#ifdef CONFIG_PRINTK
6103__syscall void k_str_out(char *c, size_t n);
6104#endif
6105
6132__syscall int k_float_disable(struct k_thread *thread);
6133
6172__syscall int k_float_enable(struct k_thread *thread, unsigned int options);
6173
6187
6195
6204
6215
6226
6235
6244
6245#ifdef __cplusplus
6246}
6247#endif
6248
6249#include <zephyr/tracing/tracing.h>
6250#include <zephyr/syscalls/kernel.h>
6251
6252#endif /* !_ASMLANGUAGE */
6253
6254#endif /* ZEPHYR_INCLUDE_KERNEL_H_ */
static uint32_t arch_k_cycle_get_32(void)
Definition misc.h:26
static uint64_t arch_k_cycle_get_64(void)
Definition misc.h:33
void(* k_thread_entry_t)(void *p1, void *p2, void *p3)
Thread entry point function type.
Definition arch_interface.h:48
struct z_thread_stack_element k_thread_stack_t
Typedef of struct z_thread_stack_element.
Definition arch_interface.h:46
long atomic_t
Definition atomic_types.h:15
System error numbers.
void arch_cpu_atomic_idle(unsigned int key)
Atomically re-enable interrupts and enter low power mode.
void arch_cpu_idle(void)
Power save idle routine.
static bool atomic_test_bit(const atomic_t *target, int bit)
Atomically get and test a bit.
Definition atomic.h:127
static void atomic_clear_bit(atomic_t *target, int bit)
Atomically clear a bit.
Definition atomic.h:191
static bool atomic_test_and_set_bit(atomic_t *target, int bit)
Atomically set a bit and test it.
Definition atomic.h:170
static uint32_t k_cycle_get_32(void)
Read the hardware clock.
Definition kernel.h:1900
#define K_NO_WAIT
Generate null timeout delay.
Definition kernel.h:1330
int64_t k_uptime_ticks(void)
Get system uptime, in system ticks.
static uint32_t k_uptime_get_32(void)
Get system uptime (32-bit version).
Definition kernel.h:1852
uint32_t k_ticks_t
Tick precision used in timeout APIs.
Definition sys_clock.h:48
static int64_t k_uptime_delta(int64_t *reftime)
Get elapsed time.
Definition kernel.h:1881
static uint32_t k_uptime_seconds(void)
Get system uptime in seconds.
Definition kernel.h:1865
static uint64_t k_cycle_get_64(void)
Read the 64-bit hardware clock.
Definition kernel.h:1915
static int64_t k_uptime_get(void)
Get system uptime.
Definition kernel.h:1828
int k_condvar_signal(struct k_condvar *condvar)
Signals one thread that is pending on the condition variable.
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.
int k_condvar_init(struct k_condvar *condvar)
Initialize a condition variable.
int k_condvar_broadcast(struct k_condvar *condvar)
Unblock all threads that are pending on the condition variable.
static void k_cpu_idle(void)
Make the CPU idle.
Definition kernel.h:5996
static void k_cpu_atomic_idle(unsigned int key)
Make the CPU idle in an atomic fashion.
Definition kernel.h:6015
struct _dnode sys_dnode_t
Doubly-linked list node structure.
Definition dlist.h:54
struct _dnode sys_dlist_t
Doubly-linked list structure.
Definition dlist.h:50
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.
uint32_t k_event_set_masked(struct k_event *event, uint32_t events, uint32_t events_mask)
Set or clear the events in an event object.
static uint32_t k_event_test(struct k_event *event, uint32_t events_mask)
Test the events currently tracked in the event object.
Definition kernel.h:2448
uint32_t k_event_set(struct k_event *event, uint32_t events)
Set the events in an event object.
uint32_t k_event_post(struct k_event *event, uint32_t events)
Post one or more events to an event object.
void k_event_init(struct k_event *event)
Initialize an event object.
uint32_t k_event_clear(struct k_event *event, uint32_t events)
Clear the events in an event object.
uint32_t k_event_wait_all(struct k_event *event, uint32_t events, bool reset, k_timeout_t timeout)
Wait for all of the specified events.
struct _sflist sys_sflist_t
Flagged single-linked list structure.
Definition sflist.h:54
static bool sys_sflist_is_empty(sys_sflist_t *list)
Test if the given list is empty.
Definition sflist.h:336
int k_float_disable(struct k_thread *thread)
Disable preservation of floating point context information.
int k_float_enable(struct k_thread *thread, unsigned int options)
Enable preservation of floating point context information.
int k_futex_wait(struct k_futex *futex, int expected, k_timeout_t timeout)
Pend the current thread on a futex.
int k_futex_wake(struct k_futex *futex, bool wake_all)
Wake one/all threads pending on a futex.
void * k_heap_alloc(struct k_heap *h, size_t bytes, k_timeout_t timeout)
Allocate memory from a k_heap.
void k_heap_free(struct k_heap *h, void *mem)
Free memory allocated by k_heap_alloc()
void k_free(void *ptr)
Free memory allocated from heap.
void * k_realloc(void *ptr, size_t size)
Expand the size of an existing allocation.
void k_heap_init(struct k_heap *h, void *mem, size_t bytes)
Initialize a k_heap.
void * k_malloc(size_t size)
Allocate memory from the heap.
void * k_heap_realloc(struct k_heap *h, void *ptr, size_t bytes, k_timeout_t timeout)
Reallocate memory from a k_heap.
void * k_calloc(size_t nmemb, size_t size)
Allocate memory from heap, array style.
void * k_aligned_alloc(size_t align, size_t size)
Allocate memory from the heap with a specified alignment.
void * k_heap_aligned_alloc(struct k_heap *h, size_t align, size_t bytes, k_timeout_t timeout)
Allocate aligned memory from a k_heap.
bool k_is_in_isr(void)
Determine if code is running at interrupt level.
int k_is_preempt_thread(void)
Determine if code is running in a preemptible thread.
static bool k_is_pre_kernel(void)
Test whether startup is in the before-main-task phase.
Definition kernel.h:1185
int k_mbox_get(struct k_mbox *mbox, struct k_mbox_msg *rx_msg, void *buffer, k_timeout_t timeout)
Receive a mailbox message.
void k_mbox_data_get(struct k_mbox_msg *rx_msg, void *buffer)
Retrieve mailbox message data into a buffer.
void k_mbox_init(struct k_mbox *mbox)
Initialize a mailbox.
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.
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.
int k_mem_slab_init(struct k_mem_slab *slab, void *buffer, size_t block_size, uint32_t num_blocks)
Initialize a memory slab.
void k_mem_slab_free(struct k_mem_slab *slab, void *mem)
Free memory allocated from a memory slab.
int k_mem_slab_runtime_stats_get(struct k_mem_slab *slab, struct sys_memory_stats *stats)
Get the memory stats for a memory slab.
int k_mem_slab_runtime_stats_reset_max(struct k_mem_slab *slab)
Reset the maximum memory usage for a slab.
int k_mem_slab_alloc(struct k_mem_slab *slab, void **mem, k_timeout_t timeout)
Allocate memory from a memory slab.
static uint32_t k_mem_slab_num_used_get(struct k_mem_slab *slab)
Get the number of used blocks in a memory slab.
Definition kernel.h:5321
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.
Definition kernel.h:5336
static uint32_t k_mem_slab_num_free_get(struct k_mem_slab *slab)
Get the number of unused blocks in a memory slab.
Definition kernel.h:5356
int k_msgq_peek(struct k_msgq *msgq, void *data)
Peek/read a message from a message queue.
uint32_t k_msgq_num_used_get(struct k_msgq *msgq)
Get the number of messages in a message queue.
void k_msgq_init(struct k_msgq *msgq, char *buffer, size_t msg_size, uint32_t max_msgs)
Initialize a message queue.
int k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t timeout)
Send a message to a message queue.
int k_msgq_peek_at(struct k_msgq *msgq, void *data, uint32_t idx)
Peek/read a message from a message queue at the specified index.
uint32_t k_msgq_num_free_get(struct k_msgq *msgq)
Get the amount of free space in a message queue.
void k_msgq_get_attrs(struct k_msgq *msgq, struct k_msgq_attrs *attrs)
Get basic attributes of a message queue.
void k_msgq_purge(struct k_msgq *msgq)
Purge a message queue.
int k_msgq_alloc_init(struct k_msgq *msgq, size_t msg_size, uint32_t max_msgs)
Initialize a message queue.
int k_msgq_get(struct k_msgq *msgq, void *data, k_timeout_t timeout)
Receive a message from a message queue.
int k_msgq_cleanup(struct k_msgq *msgq)
Release allocated buffer for a queue.
int k_mutex_unlock(struct k_mutex *mutex)
Unlock a mutex.
int k_mutex_init(struct k_mutex *mutex)
Initialize a mutex.
int k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout)
Lock a mutex.
size_t k_pipe_read_avail(struct k_pipe *pipe)
Query the number of bytes that may be read from pipe.
int k_pipe_alloc_init(struct k_pipe *pipe, size_t size)
Initialize a pipe and allocate a buffer for it.
void k_pipe_flush(struct k_pipe *pipe)
Flush the pipe of write data.
void k_pipe_buffer_flush(struct k_pipe *pipe)
Flush the pipe's internal buffer.
int k_pipe_cleanup(struct k_pipe *pipe)
Release a pipe's allocated buffer.
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.
void k_pipe_init(struct k_pipe *pipe, unsigned char *buffer, size_t size)
Initialize a pipe.
size_t k_pipe_write_avail(struct k_pipe *pipe)
Query the number of bytes that may be written to pipe.
int k_pipe_put(struct k_pipe *pipe, const void *data, size_t bytes_to_write, size_t *bytes_written, size_t min_xfer, k_timeout_t timeout)
Write data to a pipe.
void k_poll_signal_reset(struct k_poll_signal *sig)
Reset a poll signal object's state to unsignaled.
k_poll_modes
Definition kernel.h:5750
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.
void k_poll_event_init(struct k_poll_event *event, uint32_t type, int mode, void *obj)
Initialize one struct k_poll_event instance.
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.
int k_poll_signal_raise(struct k_poll_signal *sig, int result)
Signal a poll signal object.
void k_poll_signal_init(struct k_poll_signal *sig)
Initialize a poll signal object.
@ K_POLL_MODE_NOTIFY_ONLY
Definition kernel.h:5752
@ K_POLL_NUM_MODES
Definition kernel.h:5754
void k_queue_init(struct k_queue *queue)
Initialize a queue.
void * k_queue_get(struct k_queue *queue, k_timeout_t timeout)
Get an element from a queue.
void * k_queue_peek_tail(struct k_queue *queue)
Peek element at the tail of queue.
bool k_queue_unique_append(struct k_queue *queue, void *data)
Append an element to a queue only if it's not present already.
bool k_queue_remove(struct k_queue *queue, void *data)
Remove an element from a queue.
int k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list)
Atomically add a list of elements to a queue.
int32_t k_queue_alloc_append(struct k_queue *queue, void *data)
Append an element to a queue.
void k_queue_cancel_wait(struct k_queue *queue)
Cancel waiting on a queue.
void * k_queue_peek_head(struct k_queue *queue)
Peek element at the head of queue.
void k_queue_prepend(struct k_queue *queue, void *data)
Prepend an element to a queue.
int k_queue_append_list(struct k_queue *queue, void *head, void *tail)
Atomically append a list of elements to a queue.
void k_queue_append(struct k_queue *queue, void *data)
Append an element to the end of a queue.
int32_t k_queue_alloc_prepend(struct k_queue *queue, void *data)
Prepend an element to a queue.
void k_queue_insert(struct k_queue *queue, void *prev, void *data)
Inserts an element to a queue.
int k_queue_is_empty(struct k_queue *queue)
Query a queue to see if it has data available.
void k_sem_reset(struct k_sem *sem)
Resets a semaphore's count to zero.
unsigned int k_sem_count_get(struct k_sem *sem)
Get a semaphore's count.
void k_sem_give(struct k_sem *sem)
Give a semaphore.
int k_sem_take(struct k_sem *sem, k_timeout_t timeout)
Take a semaphore.
int k_sem_init(struct k_sem *sem, unsigned int initial_count, unsigned int limit)
Initialize a semaphore.
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:49
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
int k_stack_pop(struct k_stack *stack, stack_data_t *data, k_timeout_t timeout)
Pop an element from a stack.
void k_stack_init(struct k_stack *stack, stack_data_t *buffer, uint32_t num_entries)
Initialize a stack.
int k_stack_cleanup(struct k_stack *stack)
Release a stack's allocated buffer.
int k_stack_push(struct k_stack *stack, stack_data_t data)
Push an element onto a stack.
int32_t k_stack_alloc_init(struct k_stack *stack, uint32_t num_entries)
Initialize a stack.
#define SYS_PORT_TRACING_TRACKING_FIELD(type)
Field added to kernel objects so they are tracked.
Definition tracing_macros.h:366
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:140
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define CONTAINER_OF(ptr, type, field)
Get a pointer to a structure containing the element.
Definition util.h:284
#define EBUSY
Mount device busy.
Definition errno.h:54
int k_thread_name_copy(k_tid_t thread, char *buf, size_t size)
Copy the thread name into a supplied buffer.
void k_yield(void)
Yield the current thread.
const char * k_thread_state_str(k_tid_t thread_id, char *buf, size_t buf_size)
Get thread state string.
void k_thread_resume(k_tid_t thread)
Resume a suspended thread.
void * k_thread_custom_data_get(void)
Get current thread's custom data.
void k_thread_abort(k_tid_t thread)
Abort a thread.
int k_thread_name_set(k_tid_t thread, const char *str)
Set current thread name.
void k_thread_priority_set(k_tid_t thread, int prio)
Set a thread's priority.
int k_thread_cpu_mask_enable(k_tid_t thread, int cpu)
Enable thread to run on specified CPU.
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.
bool k_can_yield(void)
Check whether it is possible to yield in the current context.
int k_thread_priority_get(k_tid_t thread)
Get a thread's priority.
static void k_thread_heap_assign(struct k_thread *thread, struct k_heap *heap)
Assign a resource memory pool to a thread.
Definition kernel.h:471
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.
int k_thread_join(struct k_thread *thread, k_timeout_t timeout)
Sleep until a thread exits.
k_ticks_t k_thread_timeout_remaining_ticks(const struct k_thread *thread)
Get time remaining before a thread wakes up, in system ticks.
void k_thread_custom_data_set(void *value)
Set current thread's custom data.
int32_t k_sleep(k_timeout_t timeout)
Put the current thread to sleep.
void k_sched_lock(void)
Lock the scheduler.
static int32_t k_msleep(int32_t ms)
Put the current thread to sleep.
Definition kernel.h:566
void k_busy_wait(uint32_t usec_to_wait)
Cause the current thread to busy wait.
void k_thread_time_slice_set(struct k_thread *th, int32_t slice_ticks, k_thread_timeslice_fn_t expired, void *data)
Set thread time slice.
void k_thread_suspend(k_tid_t thread)
Suspend a thread.
void k_sched_unlock(void)
Unlock the scheduler.
static __attribute_const__ k_tid_t k_current_get(void)
Get thread ID of the current thread.
Definition kernel.h:663
int k_thread_cpu_mask_clear(k_tid_t thread)
Sets all CPU enable masks to zero.
void k_thread_foreach_filter_by_cpu(unsigned int cpu, k_thread_user_cb_t user_cb, void *user_data)
Iterate over all the threads in running on specified cpu.
void k_sched_time_slice_set(int32_t slice, int prio)
Set time-slicing period and scope.
void k_thread_start(k_tid_t thread)
Start an inactive thread.
int k_thread_cpu_mask_disable(k_tid_t thread, int cpu)
Prevent thread to run on specified CPU.
void k_wakeup(k_tid_t thread)
Wake up a sleeping thread.
int k_thread_stack_free(k_thread_stack_t *stack)
Free a dynamically allocated thread stack.
k_ticks_t k_thread_timeout_expires_ticks(const struct k_thread *thread)
Get time when a thread wakes up, in system ticks.
__attribute_const__ k_tid_t k_sched_current_thread_query(void)
Query thread ID of the current thread.
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.
void k_thread_deadline_set(k_tid_t thread, int deadline)
Set deadline expiration time for scheduler.
void k_thread_foreach_unlocked_filter_by_cpu(unsigned int cpu, k_thread_user_cb_t user_cb, void *user_data)
Iterate over the threads in running on current cpu without locking.
const char * k_thread_name_get(k_tid_t thread)
Get thread name.
void k_thread_foreach(k_thread_user_cb_t user_cb, void *user_data)
Iterate over all the threads in the system.
int k_thread_cpu_pin(k_tid_t thread, int cpu)
Pin a thread to a CPU.
int32_t k_usleep(int32_t us)
Put the current thread to sleep with microsecond resolution.
int k_thread_cpu_mask_enable_all(k_tid_t thread)
Sets all CPU enable masks to one.
void(* k_thread_user_cb_t)(const struct k_thread *thread, void *user_data)
Definition kernel.h:105
k_thread_stack_t * k_thread_stack_alloc(size_t size, int flags)
Dynamically allocate a thread stack.
k_ticks_t k_timer_expires_ticks(const struct k_timer *timer)
Get next expiration time of a timer, in system ticks.
void(* k_timer_stop_t)(struct k_timer *timer)
Timer stop function type.
Definition kernel.h:1606
k_ticks_t k_timer_remaining_ticks(const struct k_timer *timer)
Get time remaining before a timer next expires, in system ticks.
void * k_timer_user_data_get(const struct k_timer *timer)
Retrieve the user-specific data from a timer.
void(* k_timer_expiry_t)(struct k_timer *timer)
Timer expiry function type.
Definition kernel.h:1590
void k_timer_init(struct k_timer *timer, k_timer_expiry_t expiry_fn, k_timer_stop_t stop_fn)
Initialize a timer.
void k_timer_start(struct k_timer *timer, k_timeout_t duration, k_timeout_t period)
Start a timer.
static uint32_t k_timer_remaining_get(struct k_timer *timer)
Get time remaining before a timer next expires.
Definition kernel.h:1752
uint32_t k_timer_status_sync(struct k_timer *timer)
Synchronize thread to timer expiration.
void k_timer_stop(struct k_timer *timer)
Stop a timer.
uint32_t k_timer_status_get(struct k_timer *timer)
Read timer status.
void k_timer_user_data_set(struct k_timer *timer, void *user_data)
Associate user-specific data with a timer.
#define k_ticks_to_ms_floor32(t)
Convert ticks to milliseconds.
Definition time_units.h:1701
#define k_ticks_to_sec_floor32(t)
Convert ticks to seconds.
Definition time_units.h:1605
#define k_ticks_to_ms_floor64(t)
Convert ticks to milliseconds.
Definition time_units.h:1717
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.
static k_tid_t k_work_queue_thread_get(struct k_work_q *queue)
Access the thread that animates a work queue.
Definition kernel.h:4161
static bool k_work_is_pending(const struct k_work *work)
Test whether a work item is currently pending.
Definition kernel.h:4132
int k_work_queue_drain(struct k_work_q *queue, bool plug)
Wait until the work queue has drained, optionally plugging it.
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.
Definition kernel.h:4149
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.
int k_work_delayable_busy_get(const struct k_work_delayable *dwork)
Busy state flags from the delayable work item.
void k_work_init_delayable(struct k_work_delayable *dwork, k_work_handler_t handler)
Initialize a delayable work structure.
int k_work_poll_cancel(struct k_work_poll *work)
Cancel a triggered work item.
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.
void k_work_poll_init(struct k_work_poll *work, k_work_handler_t handler)
Initialize a triggered work item.
int k_work_cancel(struct k_work *work)
Cancel a work item.
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.
Definition kernel.h:4288
int k_work_submit_to_queue(struct k_work_q *queue, struct k_work *work)
Submit a work item to a queue.
static bool k_work_user_is_pending(struct k_work_user *work)
Check if a userspace work item is pending.
Definition kernel.h:4265
void(* k_work_handler_t)(struct k_work *work)
The signature for a work item handler function.
Definition kernel.h:3356
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.
static bool k_work_delayable_is_pending(const struct k_work_delayable *dwork)
Test whether a delayed work item is currently pending.
Definition kernel.h:4143
bool k_work_cancel_delayable_sync(struct k_work_delayable *dwork, struct k_work_sync *sync)
Cancel delayable work and wait.
int k_work_cancel_delayable(struct k_work_delayable *dwork)
Cancel delayable work.
static void k_work_user_init(struct k_work_user *work, k_work_user_handler_t handler)
Initialize a userspace work item.
Definition kernel.h:4243
int k_work_queue_unplug(struct k_work_q *queue)
Release a work queue to accept new submissions.
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.
void(* k_work_user_handler_t)(struct k_work_user *work)
Work item handler function type for user work queues.
Definition kernel.h:4184
bool k_work_cancel_sync(struct k_work *work, struct k_work_sync *sync)
Cancel a work item and wait for it to complete.
static k_tid_t k_work_user_queue_thread_get(struct k_work_user_q *work_q)
Access the user mode thread that animates a work queue.
Definition kernel.h:4343
int k_work_busy_get(const struct k_work *work)
Busy state flags from the work item.
static struct k_work_delayable * k_work_delayable_from_work(struct k_work *work)
Get the parent delayable work structure from a work pointer.
Definition kernel.h:4138
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.
Definition kernel.h:4155
bool k_work_flush(struct k_work *work, struct k_work_sync *sync)
Wait for last-submitted instance to complete.
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.
int k_work_submit(struct k_work *work)
Submit a work item to the system queue.
bool k_work_flush_delayable(struct k_work_delayable *dwork, struct k_work_sync *sync)
Flush delayable work.
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.
void k_work_queue_init(struct k_work_q *queue)
Initialize a work queue structure.
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.
void k_work_init(struct k_work *work, k_work_handler_t handler)
Initialize a (non-delayable) work structure.
@ K_WORK_CANCELING
Flag indicating a work item that is being canceled.
Definition kernel.h:3933
@ K_WORK_QUEUED
Flag indicating a work item that has been submitted to a queue but has not started running.
Definition kernel.h:3940
@ K_WORK_DELAYED
Flag indicating a delayed work item that is scheduled for submission to a queue.
Definition kernel.h:3947
@ K_WORK_RUNNING
Flag indicating a work item that is running under a work queue thread.
Definition kernel.h:3927
@ K_WORK_FLUSHING
Flag indicating a synced work item that is being flushed.
Definition kernel.h:3953
void k_sys_runtime_stats_disable(void)
Disable gathering of system runtime statistics.
int k_thread_runtime_stats_enable(k_tid_t thread)
Enable gathering of runtime statistics for specified thread.
void k_sys_runtime_stats_enable(void)
Enable gathering of system runtime statistics.
int k_thread_runtime_stats_get(k_tid_t thread, k_thread_runtime_stats_t *stats)
Get the runtime statistics of a thread.
execution_context_types
Definition kernel.h:90
@ K_ISR
Definition kernel.h:91
@ K_COOP_THREAD
Definition kernel.h:92
@ K_PREEMPT_THREAD
Definition kernel.h:93
int k_thread_runtime_stats_all_get(k_thread_runtime_stats_t *stats)
Get the runtime statistics of all threads.
int k_thread_runtime_stats_disable(k_tid_t thread)
Disable gathering of runtime statistics for specified thread.
int k_thread_runtime_stats_cpu_get(int cpu, k_thread_runtime_stats_t *stats)
Get the runtime statistics of all threads on specified cpu.
Header files included by kernel.h.
void(* k_thread_timeslice_fn_t)(struct k_thread *thread, void *data)
Definition kernel_structs.h:307
Memory Statistics.
flags
Definition parser.h:96
state
Definition parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INTPTR_TYPE__ intptr_t
Definition stdint.h:104
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__INT64_TYPE__ int64_t
Definition stdint.h:75
Structure to store initialization entry information.
Definition init.h:103
Definition kernel.h:3106
_wait_q_t wait_q
Definition kernel.h:3107
Event Structure.
Definition kernel.h:2301
struct k_spinlock lock
Definition kernel.h:2304
uint32_t events
Definition kernel.h:2303
_wait_q_t wait_q
Definition kernel.h:2302
Definition kernel.h:2468
futex structure
Definition kernel.h:2222
atomic_t val
Definition kernel.h:2223
Definition kernel.h:5397
struct k_spinlock lock
Definition kernel.h:5400
struct sys_heap heap
Definition kernel.h:5398
_wait_q_t wait_q
Definition kernel.h:5399
Definition kernel.h:2707
Mailbox Message Structure.
Definition kernel.h:4794
k_tid_t tx_target_thread
target thread id
Definition kernel.h:4804
void * tx_data
sender's message data buffer
Definition kernel.h:4800
k_tid_t rx_source_thread
source thread id
Definition kernel.h:4802
uint32_t info
application-defined information value
Definition kernel.h:4798
size_t size
size of message (in bytes)
Definition kernel.h:4796
Mailbox Structure.
Definition kernel.h:4816
_wait_q_t tx_msg_queue
Transmit messages queue.
Definition kernel.h:4818
struct k_spinlock lock
Definition kernel.h:4821
_wait_q_t rx_msg_queue
Receive message queue.
Definition kernel.h:4820
Memory Domain.
Definition mem_domain.h:80
Memory Partition.
Definition mem_domain.h:55
Message Queue Attributes.
Definition kernel.h:4562
uint32_t used_msgs
Used messages.
Definition kernel.h:4568
size_t msg_size
Message Size.
Definition kernel.h:4564
uint32_t max_msgs
Maximal number of messages.
Definition kernel.h:4566
Message Queue Structure.
Definition kernel.h:4503
size_t msg_size
Message size.
Definition kernel.h:4509
char * read_ptr
Read pointer.
Definition kernel.h:4517
uint32_t used_msgs
Number of used messages.
Definition kernel.h:4521
char * buffer_end
End of message buffer.
Definition kernel.h:4515
struct k_spinlock lock
Lock.
Definition kernel.h:4507
char * write_ptr
Write pointer.
Definition kernel.h:4519
char * buffer_start
Start of message buffer.
Definition kernel.h:4513
uint8_t flags
Message queue.
Definition kernel.h:4526
_wait_q_t wait_q
Message queue wait queue.
Definition kernel.h:4505
uint32_t max_msgs
Maximal number of messages.
Definition kernel.h:4511
Mutex Structure.
Definition kernel.h:2994
uint32_t lock_count
Current lock count.
Definition kernel.h:3001
_wait_q_t wait_q
Mutex wait queue.
Definition kernel.h:2996
int owner_orig_prio
Original thread priority.
Definition kernel.h:3004
struct k_thread * owner
Mutex owner.
Definition kernel.h:2998
Object core structure.
Definition obj_core.h:121
Pipe Structure.
Definition kernel.h:4947
struct k_pipe::@311 wait_q
uint8_t flags
Wait queue.
Definition kernel.h:4962
_wait_q_t readers
Reader wait queue.
Definition kernel.h:4956
size_t write_index
Where in buffer to write.
Definition kernel.h:4952
size_t bytes_used
Number of bytes used in buffer.
Definition kernel.h:4950
struct k_spinlock lock
Synchronization lock.
Definition kernel.h:4953
_wait_q_t writers
Writer wait queue.
Definition kernel.h:4957
size_t size
Buffer size.
Definition kernel.h:4949
unsigned char * buffer
Pipe buffer: may be NULL.
Definition kernel.h:4948
size_t read_index
Where in buffer to read from.
Definition kernel.h:4951
Poll Event.
Definition kernel.h:5792
struct k_poll_signal * signal
Definition kernel.h:5820
uint32_t tag
optional user-specified tag, opaque, untouched by the API
Definition kernel.h:5800
struct k_fifo * fifo
Definition kernel.h:5822
struct k_msgq * msgq
Definition kernel.h:5824
struct k_queue * queue
Definition kernel.h:5823
uint32_t unused
unused bits in 32-bit word
Definition kernel.h:5812
uint32_t type
bitfield of event types (bitwise-ORed K_POLL_TYPE_xxx values)
Definition kernel.h:5803
struct k_sem * sem
Definition kernel.h:5821
uint32_t state
bitfield of event states (bitwise-ORed K_POLL_STATE_xxx values)
Definition kernel.h:5806
uint32_t mode
mode of operation, from enum k_poll_modes
Definition kernel.h:5809
struct z_poller * poller
PRIVATE - DO NOT TOUCH.
Definition kernel.h:5797
void * obj
Definition kernel.h:5819
Definition kernel.h:5768
sys_dlist_t poll_events
PRIVATE - DO NOT TOUCH.
Definition kernel.h:5770
int result
custom result value passed to k_poll_signal_raise() if needed
Definition kernel.h:5779
unsigned int signaled
1 if the event has been signaled, 0 otherwise.
Definition kernel.h:5776
Definition kernel.h:1930
struct k_spinlock lock
Definition kernel.h:1932
_wait_q_t wait_q
Definition kernel.h:1933
sys_sflist_t data_q
Definition kernel.h:1931
Kernel Spin Lock.
Definition spinlock.h:45
Definition thread.h:207
Thread Structure.
Definition thread.h:259
struct _thread_base base
Definition thread.h:261
struct k_heap * resource_pool
resource pool
Definition thread.h:349
struct __thread_entry entry
thread entry and parameters description
Definition thread.h:288
Kernel timeout type.
Definition sys_clock.h:65
A structure used to submit work after a delay.
Definition kernel.h:3985
struct _timeout timeout
Definition kernel.h:3990
struct k_work_q * queue
Definition kernel.h:3993
struct k_work work
Definition kernel.h:3987
A structure used to hold work until it can be processed.
Definition kernel.h:4109
sys_slist_t pending
Definition kernel.h:4118
_wait_q_t drainq
Definition kernel.h:4124
_wait_q_t notifyq
Definition kernel.h:4121
uint32_t flags
Definition kernel.h:4127
struct k_thread thread
Definition kernel.h:4111
A structure holding optional configuration items for a work queue.
Definition kernel.h:4081
const char * name
The name to be given to the work queue thread.
Definition kernel.h:4086
bool essential
Control whether the work queue thread should be marked as essential thread.
Definition kernel.h:4105
bool no_yield
Control whether the work queue thread should yield between items.
Definition kernel.h:4100
A structure holding internal state for a pending synchronous operation on a work item or queue.
Definition kernel.h:4068
struct z_work_canceller canceller
Definition kernel.h:4071
struct z_work_flusher flusher
Definition kernel.h:4070
A structure used to submit work.
Definition kernel.h:3957
k_work_handler_t handler
Definition kernel.h:3966
uint32_t flags
Definition kernel.h:3977
struct k_work_q * queue
Definition kernel.h:3969
sys_snode_t node
Definition kernel.h:3963
Definition sys_heap.h:57
Definition mem_stats.h:24
Macros to abstract toolchain specific capabilities.