µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os-c-api.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13/*
14 * The code was originally inspired by ARM CMSIS cmsis_os.h file, v1.02,
15 * and tries to remain functionally close to the CMSIS specifications.
16 */
17
18#ifndef CMSIS_PLUS_RTOS_OS_C_API_H_
19#define CMSIS_PLUS_RTOS_OS_C_API_H_
20
21// ----------------------------------------------------------------------------
22
23#if defined(OS_USE_OS_APP_CONFIG_H)
24#include <cmsis-plus/os-app-config.h>
25#endif
26
27// Include the µOS++ C API structures declarations.
29
31
32#include <stdint.h>
33#include <stddef.h>
34#include <stdbool.h>
35
36// ----------------------------------------------------------------------------
37
38#ifdef __cplusplus
39extern "C"
40{
41#endif
42
48 // --------------------------------------------------------------------------
57 enum
58 {
62 os_ok = 0
63 };
64
69 // --------------------------------------------------------------------------
93 int
94 os_main (int argc, char* argv[]);
95
100 // --------------------------------------------------------------------------
114 os_sched_initialize (void);
115
123 void
124 __attribute__((noreturn))
125 os_sched_start (void);
126
134 bool
135 os_sched_is_started (void);
136
144 os_sched_lock (void);
145
153 os_sched_unlock (void);
154
162
170 bool
171 os_sched_is_locked (void);
172
180 bool
182
188 bool
189 os_sched_set_preemptive (bool state);
190
195 // --------------------------------------------------------------------------
201#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
202
210
211#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
212
213#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
214
222
223#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
224
229 // --------------------------------------------------------------------------
242 bool
244
253
260 void
262
263 // --------------------------------------------------------------------------
264
273
280 void
282
283#if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
284
292 os_irq_get_stack (void);
293
294#endif
295
304 // --------------------------------------------------------------------------
322 os_this_thread (void);
323
331 void
333
340 void
341 __attribute__((noreturn))
342 os_this_thread_exit (void* exit_ptr);
343
360 os_flags_mode_t mode);
361
377 os_flags_mode_t mode);
378
398 os_clock_duration_t timeout,
399 os_flags_mask_t* oflags,
400 os_flags_mode_t mode);
401
413
425
430 // --------------------------------------------------------------------------
442 void
444
464 void
465 os_thread_construct (os_thread_t* thread, const char* name,
467 const os_thread_attr_t* attr);
468
475 void
477
487 os_thread_new (const char* name, os_thread_func_t func,
488 const os_thread_func_args_t args,
489 const os_thread_attr_t* attr);
490
497 void
499
505 bool
507
522 const char*
524
532
544
553
562 os_thread_join (os_thread_t* thread, void** exit_ptr);
563
570 void
572
585 os_flags_mask_t* oflags);
586
594
595#if defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) || defined(__DOXYGEN__)
596
602 os_thread_user_storage_t*
604
605#endif /* defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) */
606
614
619 // --------------------------------------------------------------------------
625#define os_thread_create os_thread_construct
626#define os_thread_destroy os_thread_destruct
627
632 // --------------------------------------------------------------------------
644 size_t
646
652 size_t
653 os_thread_stack_set_default_size (size_t size_bytes);
654
661 size_t
663
669 size_t
670 os_thread_stack_set_min_size (size_t size_bytes);
671
679
687
693 size_t
695
701 size_t
703
710 bool
712
719 bool
721
726 // --------------------------------------------------------------------------
732#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
733
741
742#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
743
744#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
745
753
754#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
755
760 // --------------------------------------------------------------------------
774
783
791
799
808 // --------------------------------------------------------------------------
824 const char*
826
835
843
855
866
878
886
895
902
909
916
917 // --------------------------------------------------------------------------
918
926 os_sysclock_now (void);
927
938
948
959
960#pragma GCC diagnostic push
961#if defined(__cplusplus)
962#pragma GCC diagnostic ignored "-Wold-style-cast"
963#endif
964
971 __attribute__((always_inline))
972 os_sysclock_ticks_cast (uint32_t microsec)
973 {
974#pragma GCC diagnostic push
975#if defined(__clang__)
976#elif defined(__GNUC__)
977#if defined(__cplusplus)
978#pragma GCC diagnostic ignored "-Wuseless-cast"
979#endif
980#endif
981 return (os_clock_duration_t) ((((microsec)
982 * ((uint32_t) OS_INTEGER_SYSTICK_FREQUENCY_HZ)) + (uint32_t) 1000000ul
983 - 1) / (uint32_t) 1000000ul);
984#pragma GCC diagnostic pop
985 }
986
993 __attribute__((always_inline))
994 os_sysclock_ticks_cast_long (uint64_t microsec)
995 {
996#pragma GCC diagnostic push
997#if defined(__clang__)
998#elif defined(__GNUC__)
999#if defined(__cplusplus)
1000#pragma GCC diagnostic ignored "-Wuseless-cast"
1001#endif
1002#endif
1003 return (os_clock_duration_t) ((((microsec)
1004 * ((uint64_t) OS_INTEGER_SYSTICK_FREQUENCY_HZ)) + (uint64_t) 1000000ul
1005 - 1) / (uint64_t) 1000000ul);
1006#pragma GCC diagnostic pop
1007 }
1008
1009#pragma GCC diagnostic pop
1010
1019 // --------------------------------------------------------------------------
1036 void
1038
1045 void
1047
1052 const os_timer_attr_t*
1054
1074 void
1075 os_timer_construct (os_timer_t* timer, const char* name,
1077 const os_timer_attr_t* attr);
1078
1085 void
1087
1096 os_timer_t*
1097 os_timer_new (const char* name, os_timer_func_t function,
1098 os_timer_func_args_t args, const os_timer_attr_t* attr);
1099
1106 void
1107 os_timer_delete (os_timer_t* timer);
1108
1123 const char*
1125
1136
1146 os_timer_stop (os_timer_t* timer);
1147
1152 // --------------------------------------------------------------------------
1158#define os_timer_create os_timer_construct
1159#define os_timer_destroy os_timer_destruct
1160
1169 // --------------------------------------------------------------------------
1186 void
1188
1195 void
1197
1202 const os_mutex_attr_t*
1204
1222 void
1223 os_mutex_construct (os_mutex_t* mutex, const char* name,
1224 const os_mutex_attr_t* attr);
1225
1234 void
1235 os_mutex_recursive_construct (os_mutex_t* mutex, const char* name,
1236 const os_mutex_attr_t* attr);
1237
1244 void
1246
1253 os_mutex_t*
1254 os_mutex_new (const char* name, const os_mutex_attr_t* attr);
1255
1262 os_mutex_t*
1263 os_mutex_recursive_new (const char* name, const os_mutex_attr_t* attr);
1264
1271 void
1272 os_mutex_delete (os_mutex_t* mutex);
1273
1288 const char*
1290
1312 os_mutex_lock (os_mutex_t* mutex);
1313
1338
1363
1375 os_mutex_unlock (os_mutex_t* mutex);
1376
1384
1396 os_thread_prio_t* old_prio_ceiling);
1397
1408
1416
1424
1432
1440
1447 os_mutex_reset (os_mutex_t* mutex);
1448
1453 // --------------------------------------------------------------------------
1459#define os_mutex_create os_mutex_construct
1460#define os_mutex_recursive_create os_mutex_recursive_construct
1461#define os_mutex_destroy os_mutex_destruct
1462
1471 // --------------------------------------------------------------------------
1488 void
1490
1517 void
1518 os_condvar_construct (os_condvar_t* condvar, const char* name,
1519 const os_condvar_attr_t* attr);
1520
1528 void
1530
1546 os_condvar_new (const char* name, const os_condvar_attr_t* attr);
1547
1555 void
1557
1572 const char*
1574
1585
1596
1616 os_condvar_wait (os_condvar_t* condvar, os_mutex_t* mutex);
1617
1640 os_clock_duration_t timeout);
1641
1646 // --------------------------------------------------------------------------
1652#define os_condvar_create os_condvar_construct
1653#define os_condvar_destroy os_condvar_destruct
1654
1663 // --------------------------------------------------------------------------
1680 void
1682
1690 void
1692 const os_semaphore_count_t initial_value);
1693
1700 void
1702 const os_semaphore_count_t max_value,
1703 const os_semaphore_count_t initial_value);
1704
1709 const os_semaphore_attr_t*
1711
1729 void
1730 os_semaphore_construct (os_semaphore_t* semaphore, const char* name,
1731 const os_semaphore_attr_t* attr);
1732
1741 void
1742 os_semaphore_binary_construct (os_semaphore_t* semaphore, const char* name,
1743 const os_semaphore_count_t initial_value);
1744
1755 void
1756 os_semaphore_counting_construct (os_semaphore_t* semaphore, const char* name,
1757 const os_semaphore_count_t max_value,
1758 const os_semaphore_count_t initial_value);
1759
1766 void
1768
1776 os_semaphore_new (const char* name, const os_semaphore_attr_t* attr);
1777
1785 os_semaphore_binary_new (const char* name,
1786 const os_semaphore_count_t initial_value);
1787
1796 os_semaphore_counting_new (const char* name,
1797 const os_semaphore_count_t max_value,
1798 const os_semaphore_count_t initial_value);
1799
1806 void
1808
1823 const char*
1825
1835 os_semaphore_post (os_semaphore_t* semaphore);
1836
1848 os_semaphore_wait (os_semaphore_t* semaphore);
1849
1863
1881 os_clock_duration_t timeout);
1882
1890
1899
1907
1915
1925#define os_semaphore_create os_semaphore_construct
1926#define os_semaphore_binary_create os_semaphore_binary_construct
1927#define os_semaphore_counting_create os_semaphore_counting_construct
1928#define os_semaphore_destroy os_semaphore_destruct
1929
1938 // --------------------------------------------------------------------------
1955 void
1957
1977 void
1978 os_mempool_construct (os_mempool_t* mempool, const char* name, size_t blocks,
1979 size_t block_size_bytes, const os_mempool_attr_t* attr);
1980
1987 void
1989
1999 os_mempool_new (const char* name, size_t blocks, size_t block_size_bytes,
2000 const os_mempool_attr_t* attr);
2001
2009 void
2011
2026 const char*
2028
2034 void*
2035 os_mempool_alloc (os_mempool_t* mempool);
2036
2042 void*
2044
2051 void*
2053
2062 os_mempool_free (os_mempool_t* mempool, void* block);
2063
2069 size_t
2071
2077 size_t
2079
2085 size_t
2087
2094 bool
2096
2103 bool
2105
2113 os_mempool_reset (os_mempool_t* mempool);
2114
2120 void*
2122
2132#define os_mempool_create os_mempool_construct
2133#define os_mempool_destroy os_mempool_destruct
2134
2143 // --------------------------------------------------------------------------
2160 void
2162
2182 void
2183 os_mqueue_construct (os_mqueue_t* mqueue, const char* name, size_t msgs,
2184 size_t msg_size_bytes, const os_mqueue_attr_t* attr);
2185
2192 void
2194
2204 os_mqueue_new (const char* name, size_t msgs, size_t msg_size_bytes,
2205 const os_mqueue_attr_t* attr);
2206
2214 void
2215 os_mqueue_delete (os_mqueue_t* mqueue);
2216
2231 const char*
2233
2251 os_mqueue_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2252 os_mqueue_prio_t mprio);
2253
2270 os_mqueue_try_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2271 os_mqueue_prio_t mprio);
2272
2293 os_mqueue_timed_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2294 os_clock_duration_t timeout, os_mqueue_prio_t mprio);
2295
2316 os_mqueue_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2317 os_mqueue_prio_t* mprio);
2318
2338 os_mqueue_try_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2339 os_mqueue_prio_t* mprio);
2340
2364 os_mqueue_timed_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2365 os_clock_duration_t timeout,
2366 os_mqueue_prio_t* mprio);
2367
2373 size_t
2375
2381 size_t
2383
2389 size_t
2391
2398 bool
2400
2407 bool
2409
2417 os_mqueue_reset (os_mqueue_t* mqueue);
2418
2428#define os_mqueue_create os_mqueue_construct
2429#define os_mqueue_destroy os_mqueue_destruct
2430
2439 // --------------------------------------------------------------------------
2456 void
2458
2476 void
2477 os_evflags_construct (os_evflags_t* evflags, const char* name,
2478 const os_evflags_attr_t* attr);
2479
2486 void
2488
2496 os_evflags_new (const char* name, const os_evflags_attr_t* attr);
2497
2505 void
2507
2522 const char*
2524
2542 os_flags_mask_t* oflags, os_flags_mode_t mode);
2543
2560 os_flags_mask_t* oflags, os_flags_mode_t mode);
2561
2582 os_clock_duration_t timeout, os_flags_mask_t* oflags,
2583 os_flags_mode_t mode);
2584
2597 os_flags_mask_t* oflags);
2598
2610 os_flags_mask_t* oflags);
2611
2622 os_flags_mode_t mode);
2623
2630 bool
2632
2642#define os_evflags_create os_evflags_construct
2643#define os_evflags_destroy os_evflags_destruct
2644
2653 // --------------------------------------------------------------------------
2669 os_memory_get_default (void);
2670
2677 void*
2678 os_memory_allocate (os_memory_t* memory, size_t bytes, size_t alignment);
2679
2687 void
2688 os_memory_deallocate (os_memory_t* memory, void* addr, size_t bytes,
2689 size_t alignment);
2690
2699 void
2700 os_memory_reset (os_memory_t* memory);
2701
2710 bool
2712
2718 size_t
2720
2726 size_t
2728
2734 size_t
2736
2742 size_t
2744
2750 size_t
2752
2761// --------------------------------------------------------------------------
2762#ifdef __cplusplus
2763}
2764#endif
2765
2766// ----------------------------------------------------------------------------
2767
2768#endif /* CMSIS_PLUS_RTOS_OS_C_API_H_ */
Standard thread.
#define OS_INTEGER_SYSTICK_FREQUENCY_HZ
Define the scheduler frequency, in Hz.
clock_t clock(void)
os_clock_timestamp_t os_clock_now(os_clock_t *clock)
Tell the current time, possibly adjusted for epoch.
os_result_t os_sysclock_wait_for(os_clock_duration_t timeout)
Timed wait for an event.
os_result_t os_clock_sleep_for(os_clock_t *clock, os_clock_duration_t duration)
Sleep for a relative duration.
const char * os_clock_get_name(os_clock_t *clock)
Get the clock name.
os_result_t os_clock_wait_for(os_clock_t *clock, os_clock_duration_t timeout)
Timed wait for an event.
os_clock_timestamp_t os_sysclock_now(void)
Tell the current time since startup.
os_clock_offset_t os_clock_get_offset(os_clock_t *clock)
Get adjustment offset.
os_clock_timestamp_t os_clock_steady_now(os_clock_t *clock)
Tell the current time since startup.
os_clock_t * os_clock_get_sysclock(void)
Get sysclock (the system clock).
os_result_t os_sysclock_sleep_until(os_clock_timestamp_t timestamp)
Sleep until an absolute timestamp.
os_clock_duration_t os_sysclock_ticks_cast_long(uint64_t microsec)
Convert microseconds to ticks.
Definition os-c-api.h:994
os_clock_t * os_clock_get_rtclock(void)
Get rtclock (the real-time clock).
os_result_t os_sysclock_sleep_for(os_clock_duration_t duration)
Sleep for a relative duration.
os_clock_duration_t os_sysclock_ticks_cast(uint32_t microsec)
Convert microseconds to ticks.
Definition os-c-api.h:972
os_clock_t * os_clock_get_hrclock(void)
Get hrclock (the high resolution clock).
os_clock_offset_t os_clock_set_offset(os_clock_t *clock, os_clock_offset_t offset)
Set adjustment offset.
os_result_t os_clock_sleep_until(os_clock_t *clock, os_clock_timestamp_t timestamp)
Sleep until an absolute timestamp.
os_result_t os_condvar_timed_wait(os_condvar_t *condvar, os_mutex_t *mutex, os_clock_duration_t timeout)
Timed wait for a condition variable to be notified.
void os_condvar_delete(os_condvar_t *condvar)
Destruct the condition variable object instance and deallocate it.
os_result_t os_condvar_signal(os_condvar_t *condvar)
Notify one thread waiting for a condition variable.
void os_condvar_construct(os_condvar_t *condvar, const char *name, const os_condvar_attr_t *attr)
Construct a statically allocated condition variable object instance.
void os_condvar_destruct(os_condvar_t *condvar)
Destruct the statically allocated condition variable object instance.
os_result_t os_condvar_wait(os_condvar_t *condvar, os_mutex_t *mutex)
Wait for a condition variable to be notified.
os_condvar_t * os_condvar_new(const char *name, const os_condvar_attr_t *attr)
Allocate a condition variable object instance and construct it.
const char * os_condvar_get_name(os_condvar_t *condvar)
Get the condition variable name.
os_result_t os_condvar_broadcast(os_condvar_t *condvar)
Notify all threads waiting for a condition variable.
void os_condvar_attr_init(os_condvar_attr_t *attr)
Initialise the condition variable attributes.
bool os_irq_in_handler_mode(void)
Check if the CPU is in handler mode.
void os_irq_uncritical_exit(os_irq_state_t state)
Exit the interrupts uncritical section.
bool os_sched_is_locked(void)
Check if the scheduler is locked.
os_irq_state_t os_irq_uncritical_enter(void)
Enter an interrupts uncritical section.
void os_sched_start(void)
Start the RTOS scheduler.
bool os_sched_is_started(void)
Check if the scheduler was started.
os_sched_state_t os_sched_set_locked(os_sched_state_t state)
Lock/unlock the scheduler.
bool os_sched_set_preemptive(bool state)
Set the scheduler preemptive mode.
os_result_t os_sched_initialize(void)
Initialise the RTOS scheduler.
os_statistics_duration_t os_sched_stat_get_cpu_cycles(void)
Get the total duration of all threads.
uint32_t os_flags_mask_t
Type of variables holding flags masks.
Definition os-c-decls.h:121
uint64_t os_statistics_counter_t
Type of variables holding context switches counters.
Definition os-c-decls.h:232
os_thread_stack_t * os_irq_get_stack(void)
Get the interrupts stack.
os_sched_state_t os_sched_unlock(void)
Unlock the scheduler.
os_sched_state_t os_sched_lock(void)
Lock the scheduler.
os_port_irq_state_t os_irq_state_t
Type of variables holding interrupts priority values.
Definition os-c-decls.h:171
void os_irq_critical_exit(os_irq_state_t state)
Exit the interrupts critical section.
uint32_t os_flags_mode_t
Type of variables holding flags modes.
Definition os-c-decls.h:108
os_statistics_counter_t os_sched_stat_get_context_switches(void)
Get the total number of context switches.
bool os_sched_is_preemptive(void)
Check if the scheduler is in preemptive mode.
os_port_scheduler_state_t os_sched_state_t
Type of variables holding scheduler state codes.
Definition os-c-decls.h:157
os_port_clock_offset_t os_clock_offset_t
Type of variables holding clock offsets.
Definition os-c-decls.h:209
void * os_iterator_t
Generic iterator, implemented as a pointer.
Definition os-c-decls.h:223
uint64_t os_statistics_duration_t
Type of variables holding durations in CPU cycles.
Definition os-c-decls.h:239
os_irq_state_t os_irq_critical_enter(void)
Enter an interrupts critical section.
os_port_clock_duration_t os_clock_duration_t
Type of variables holding clock durations.
Definition os-c-decls.h:197
os_port_clock_timestamp_t os_clock_timestamp_t
Type of variables holding clock time stamps.
Definition os-c-decls.h:186
uint32_t os_result_t
Type of values returned by RTOS functions.
Definition os-c-decls.h:95
@ os_ok
Function completed; no error or event occurred.
Definition os-c-api.h:62
os_result_t os_evflags_try_wait(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Try to wait for event flags.
os_result_t os_evflags_clear(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mask_t *oflags)
Clear event flags.
os_result_t os_evflags_wait(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Wait for event flags.
const char * os_evflags_get_name(os_evflags_t *evflags)
Get the event flags name.
bool os_evflags_are_waiting(os_evflags_t *evflags)
Check if there are threads waiting.
os_result_t os_evflags_raise(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mask_t *oflags)
Raise event flags.
void os_evflags_attr_init(os_evflags_attr_t *attr)
Initialise the event flags attributes.
os_flags_mask_t os_evflags_get(os_evflags_t *evflags, os_flags_mask_t mask, os_flags_mode_t mode)
Get (and possibly clear) event flags.
void os_evflags_delete(os_evflags_t *evflags)
Destruct the event flags object instance and deallocate it.
os_result_t os_evflags_timed_wait(os_evflags_t *evflags, os_flags_mask_t mask, os_clock_duration_t timeout, os_flags_mask_t *oflags, os_flags_mode_t mode)
Timed wait for event flags.
void os_evflags_destruct(os_evflags_t *evflags)
Destruct the statically allocated event flags object instance.
os_evflags_t * os_evflags_new(const char *name, const os_evflags_attr_t *attr)
Allocate an event flags object instance and construct it.
void os_evflags_construct(os_evflags_t *evflags, const char *name, const os_evflags_attr_t *attr)
Construct a statically allocated event flags object instance.
os_result_t os_mempool_free(os_mempool_t *mempool, void *block)
Free the memory block.
void os_mempool_construct(os_mempool_t *mempool, const char *name, size_t blocks, size_t block_size_bytes, const os_mempool_attr_t *attr)
Construct a statically allocated memory pool object instance.
void * os_mempool_get_pool(os_mempool_t *mempool)
Get the pool storage address.
void * os_mempool_alloc(os_mempool_t *mempool)
Allocate a memory block.
const char * os_mempool_get_name(os_mempool_t *mempool)
Get the memory pool name.
bool os_mempool_is_empty(os_mempool_t *mempool)
Check if the memory pool is empty.
void * os_mempool_timed_alloc(os_mempool_t *mempool, os_clock_duration_t timeout)
Allocate a memory block with timeout.
void os_mempool_attr_init(os_mempool_attr_t *attr)
Initialise the memory pool attributes.
void * os_mempool_try_alloc(os_mempool_t *mempool)
Try to allocate a memory block.
os_mempool_t * os_mempool_new(const char *name, size_t blocks, size_t block_size_bytes, const os_mempool_attr_t *attr)
Allocate a memory pool object instance and construct it.
os_result_t os_mempool_reset(os_mempool_t *mempool)
Reset the memory pool.
size_t os_mempool_get_count(os_mempool_t *mempool)
Get blocks count.
void os_mempool_delete(os_mempool_t *mempool)
Destruct the memory pool object instance and deallocate it.
void os_mempool_destruct(os_mempool_t *mempool)
Destruct the statically allocated memory pool object instance.
size_t os_mempool_get_block_size(os_mempool_t *mempool)
Get block size.
size_t os_mempool_get_capacity(os_mempool_t *mempool)
Get memory pool capacity.
bool os_mempool_is_full(os_mempool_t *mempool)
Check if the memory pool is full.
os_memory_t * os_memory_get_default(void)
Get the application default memory resource (free store).
size_t os_memory_get_free_bytes(os_memory_t *memory)
Get the total size of free chunks.
void os_memory_reset(os_memory_t *memory)
Reset the memory manager to the initial state.
size_t os_memory_get_allocated_bytes(os_memory_t *memory)
Get the total size of allocated chunks.
bool os_memory_coalesce(os_memory_t *memory)
Coalesce free blocks.
void * os_memory_allocate(os_memory_t *memory, size_t bytes, size_t alignment)
Allocate a block of memory.
size_t os_memory_get_total_bytes(os_memory_t *memory)
Get the total size of managed memory.
size_t os_memory_get_free_chunks(os_memory_t *memory)
Get the number of free chunks.
size_t os_memory_get_allocated_chunks(os_memory_t *memory)
Get the number of allocated chunks.
void os_memory_deallocate(os_memory_t *memory, void *addr, size_t bytes, size_t alignment)
Deallocate the previously allocated block of memory.
bool os_mqueue_is_full(os_mqueue_t *mqueue)
Check if the queue is full.
os_result_t os_mqueue_reset(os_mqueue_t *mqueue)
Reset the message queue.
os_result_t os_mqueue_timed_send(os_mqueue_t *mqueue, const void *msg, size_t nbytes, os_clock_duration_t timeout, os_mqueue_prio_t mprio)
Send a message to the queue with timeout.
os_result_t os_mqueue_receive(os_mqueue_t *mqueue, void *msg, size_t nbytes, os_mqueue_prio_t *mprio)
Receive a message from the queue.
os_result_t os_mqueue_try_receive(os_mqueue_t *mqueue, void *msg, size_t nbytes, os_mqueue_prio_t *mprio)
Try to receive a message from the queue.
void os_mqueue_delete(os_mqueue_t *mqueue)
Destruct the message queue object instance and deallocate it.
size_t os_mqueue_get_msg_size(os_mqueue_t *mqueue)
Get message size.
bool os_mqueue_is_empty(os_mqueue_t *mqueue)
Check if the queue is empty.
const char * os_mqueue_get_name(os_mqueue_t *mqueue)
Get the message queue name.
os_result_t os_mqueue_send(os_mqueue_t *mqueue, const void *msg, size_t nbytes, os_mqueue_prio_t mprio)
Send a message to the queue.
void os_mqueue_destruct(os_mqueue_t *mqueue)
Destruct the statically allocated message queue object instance.
size_t os_mqueue_get_capacity(os_mqueue_t *mqueue)
Get queue capacity.
os_mqueue_t * os_mqueue_new(const char *name, size_t msgs, size_t msg_size_bytes, const os_mqueue_attr_t *attr)
Allocate a message queue object instance and construct it.
size_t os_mqueue_get_length(os_mqueue_t *mqueue)
Get queue length.
void os_mqueue_attr_init(os_mqueue_attr_t *attr)
Initialise the message queue attributes.
void os_mqueue_construct(os_mqueue_t *mqueue, const char *name, size_t msgs, size_t msg_size_bytes, const os_mqueue_attr_t *attr)
Construct a statically allocated message queue object instance.
os_result_t os_mqueue_try_send(os_mqueue_t *mqueue, const void *msg, size_t nbytes, os_mqueue_prio_t mprio)
Try to send a message to the queue.
os_result_t os_mqueue_timed_receive(os_mqueue_t *mqueue, void *msg, size_t nbytes, os_clock_duration_t timeout, os_mqueue_prio_t *mprio)
Receive a message from the queue with timeout.
uint8_t os_mqueue_prio_t
Type of variables holding message queue priorities.
const char * os_mutex_get_name(os_mutex_t *mutex)
Get the mutex name.
void os_mutex_recursive_construct(os_mutex_t *mutex, const char *name, const os_mutex_attr_t *attr)
Construct a statically allocated recursive mutex object instance.
void os_mutex_attr_recursive_init(os_mutex_attr_t *attr)
Initialise the recursive mutex attributes.
os_mutex_type_t os_mutex_get_type(os_mutex_t *mutex)
Get the mutex type.
os_thread_prio_t os_mutex_get_prio_ceiling(os_mutex_t *mutex)
Get the priority ceiling of a mutex.
void os_mutex_destruct(os_mutex_t *mutex)
Destruct the statically allocated mutex object instance.
os_result_t os_mutex_set_prio_ceiling(os_mutex_t *mutex, os_thread_prio_t prio_ceiling, os_thread_prio_t *old_prio_ceiling)
Change the priority ceiling of a mutex.
void os_mutex_attr_init(os_mutex_attr_t *attr)
Initialise the mutex attributes.
os_result_t os_mutex_timed_lock(os_mutex_t *mutex, os_clock_duration_t timeout)
Timed attempt to lock/acquire the mutex.
os_result_t os_mutex_try_lock(os_mutex_t *mutex)
Try to lock/acquire the mutex.
os_mutex_protocol_t os_mutex_get_protocol(os_mutex_t *mutex)
Get the mutex protocol.
void os_mutex_delete(os_mutex_t *mutex)
Destruct the mutex object instance and deallocate it.
os_result_t os_mutex_unlock(os_mutex_t *mutex)
Unlock/release the mutex.
os_thread_t * os_mutex_get_owner(os_mutex_t *mutex)
Get the thread that owns the mutex.
os_mutex_t * os_mutex_recursive_new(const char *name, const os_mutex_attr_t *attr)
Allocated a recursive mutex object instance and construct it.
os_result_t os_mutex_mark_consistent(os_mutex_t *mutex)
Mark mutex as consistent.
os_result_t os_mutex_lock(os_mutex_t *mutex)
Lock/acquire the mutex.
os_mutex_robustness_t os_mutex_get_robustness(os_mutex_t *mutex)
Get the mutex robustness.
os_result_t os_mutex_reset(os_mutex_t *mutex)
Reset the mutex.
const os_mutex_attr_t * os_mutex_attr_get_recursive(void)
Get a recursive mutex attributes object instance.
os_mutex_t * os_mutex_new(const char *name, const os_mutex_attr_t *attr)
Allocate a mutex object instance and construct it.
void os_mutex_construct(os_mutex_t *mutex, const char *name, const os_mutex_attr_t *attr)
Construct a statically allocated mutex object instance.
os_semaphore_t * os_semaphore_counting_new(const char *name, const os_semaphore_count_t max_value, const os_semaphore_count_t initial_value)
Allocate a counting semaphore object instance and construct it.
os_result_t os_semaphore_timed_wait(os_semaphore_t *semaphore, os_clock_duration_t timeout)
Timed wait to lock the semaphore.
os_semaphore_t * os_semaphore_binary_new(const char *name, const os_semaphore_count_t initial_value)
Allocate a binary semaphore object instance and construct it.
os_semaphore_count_t os_semaphore_get_initial_value(os_semaphore_t *semaphore)
Get the semaphore initial count value.
const os_semaphore_attr_t * os_semaphore_attr_get_binary(void)
Get a binary semaphore attributes object instance.
const char * os_semaphore_get_name(os_semaphore_t *semaphore)
Get the semaphore name.
void os_semaphore_attr_binary_init(os_semaphore_attr_t *attr, const os_semaphore_count_t initial_value)
Initialise the binary semaphore attributes.
void os_semaphore_attr_counting_init(os_semaphore_attr_t *attr, const os_semaphore_count_t max_value, const os_semaphore_count_t initial_value)
Initialise the counting semaphore attributes.
os_result_t os_semaphore_post(os_semaphore_t *semaphore)
Post (unlock) the semaphore.
os_result_t os_semaphore_wait(os_semaphore_t *semaphore)
Lock the semaphore, possibly waiting.
os_semaphore_count_t os_semaphore_get_value(os_semaphore_t *semaphore)
Get the semaphore count value.
void os_semaphore_destruct(os_semaphore_t *semaphore)
Destruct the statically allocated semaphore object instance.
void os_semaphore_binary_construct(os_semaphore_t *semaphore, const char *name, const os_semaphore_count_t initial_value)
Construct a statically allocated binary semaphore object instance.
os_semaphore_count_t os_semaphore_get_max_value(os_semaphore_t *semaphore)
Get the semaphore maximum count value.
void os_semaphore_counting_construct(os_semaphore_t *semaphore, const char *name, const os_semaphore_count_t max_value, const os_semaphore_count_t initial_value)
Construct a statically allocated counting semaphore object instance.
void os_semaphore_delete(os_semaphore_t *semaphore)
Destruct the semaphore object instance.
os_result_t os_semaphore_reset(os_semaphore_t *semaphore)
Reset the semaphore.
os_semaphore_t * os_semaphore_new(const char *name, const os_semaphore_attr_t *attr)
Allocated a semaphore object instance and construct it.
void os_semaphore_attr_init(os_semaphore_attr_t *attr)
Initialise the counting semaphore attributes.
void os_semaphore_construct(os_semaphore_t *semaphore, const char *name, const os_semaphore_attr_t *attr)
Construct a statically allocated semaphore object instance.
int16_t os_semaphore_count_t
Type of variables holding semaphore counts.
os_result_t os_semaphore_try_wait(os_semaphore_t *semaphore)
Try to lock the semaphore.
void os_thread_attr_init(os_thread_attr_t *attr)
Initialise the thread attributes.
os_result_t os_this_thread_flags_timed_wait(os_flags_mask_t mask, os_clock_duration_t timeout, os_flags_mask_t *oflags, os_flags_mode_t mode)
Timed wait for thread event flags.
os_iterator_t os_children_threads_iter_next(os_iterator_t iterator)
Advance the iterator to the next position.
os_thread_user_storage_t * os_thread_get_user_storage(os_thread_t *thread)
Get the thread user storage.
bool os_thread_is_constructed(os_thread_t *thread)
Check if the thread is constructed.
os_flags_mask_t os_this_thread_flags_get(os_flags_mask_t mask, os_flags_mode_t mode)
Get/clear thread event flags.
const char * os_thread_get_name(os_thread_t *thread)
Get the thread name.
os_result_t os_this_thread_flags_wait(os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Wait for thread event flags.
void *(* os_thread_func_t)(os_thread_func_args_t args)
Type of thread function.
Definition os-c-decls.h:342
uint8_t os_thread_prio_t
Type of variables holding thread priorities.
Definition os-c-decls.h:363
os_thread_stack_element_t * os_thread_stack_get_bottom(os_thread_stack_t *stack)
Get the stack lowest reserved address.
size_t os_thread_stack_set_default_size(size_t size_bytes)
Set the default stack size.
void os_thread_construct(os_thread_t *thread, const char *name, os_thread_func_t func, const os_thread_func_args_t args, const os_thread_attr_t *attr)
Construct a statically allocated thread object instance.
void os_this_thread_suspend(void)
Suspend the current running thread to wait for an event.
os_statistics_counter_t os_thread_stat_get_context_switches(os_thread_t *thread)
Get the number of thread context switches.
void os_thread_resume(os_thread_t *thread)
Resume the thread.
void os_thread_delete(os_thread_t *thread)
Destruct the thread object instance and deallocate it.
os_result_t os_this_thread_flags_clear(os_flags_mask_t mask, os_flags_mask_t *oflags)
Clear thread event flags.
bool os_thread_stack_check_top_magic(os_thread_stack_t *stack)
Check if top magic word is still there.
os_result_t os_thread_join(os_thread_t *thread, void **exit_ptr)
Wait for thread termination.
os_thread_stack_element_t * os_thread_stack_get_top(os_thread_stack_t *stack)
Get the top stack address.
os_thread_state_t os_thread_get_state(os_thread_t *thread)
Get the thread scheduler state.
os_iterator_t os_children_threads_iter_begin(os_thread_t *thread)
Get the beginning of the list of children threads.
bool os_thread_stack_check_bottom_magic(os_thread_stack_t *stack)
Check if bottom magic word is still there.
os_port_thread_stack_element_t os_thread_stack_element_t
Type of variables holding stack words.
Definition os-c-decls.h:376
os_thread_prio_t os_thread_get_priority(os_thread_t *thread)
Get the thread current scheduling priority.
void * os_thread_func_args_t
Type of thread function arguments.
Definition os-c-decls.h:330
os_thread_t * os_this_thread(void)
Get the current running thread.
os_thread_stack_t * os_thread_get_stack(os_thread_t *thread)
Get the thread context stack.
os_result_t os_thread_kill(os_thread_t *thread)
Force thread termination.
os_thread_t * os_thread_new(const char *name, os_thread_func_t func, const os_thread_func_args_t args, const os_thread_attr_t *attr)
Allocate a thread object instance and construct it.
os_thread_t * os_children_threads_iter_get(os_iterator_t iterator)
Get the thread from the current iterator position.
size_t os_thread_stack_get_size(os_thread_stack_t *stack)
Get the stack size.
size_t os_thread_stack_get_min_size(void)
Get the min stack size.
size_t os_thread_stack_get_available(os_thread_stack_t *stack)
Compute how much available stack remains.
os_statistics_duration_t os_thread_stat_get_cpu_cycles(os_thread_t *thread)
Get the thread execution time.
os_result_t os_thread_set_priority(os_thread_t *thread, os_thread_prio_t prio)
Set the thread dynamic scheduling priority.
void os_this_thread_exit(void *exit_ptr)
Terminate the current running thread.
os_result_t os_this_thread_flags_try_wait(os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Try to wait for thread event flags.
uint8_t os_thread_state_t
Type of variables holding thread states.
Definition os-c-decls.h:349
size_t os_thread_stack_get_default_size(void)
Get the default stack size.
size_t os_thread_stack_set_min_size(size_t size_bytes)
Set the min stack size.
os_iterator_t os_children_threads_iter_end(os_thread_t *thread)
Get the end of the list of children threads.
os_result_t os_thread_flags_raise(os_thread_t *thread, os_flags_mask_t mask, os_flags_mask_t *oflags)
Raise thread event flags.
void os_thread_destruct(os_thread_t *thread)
Destruct the statically allocated thread object instance.
void(* os_timer_func_t)(os_timer_func_args_t args)
Type of timer function.
Definition os-c-decls.h:721
void * os_timer_func_args_t
Type of timer function arguments.
Definition os-c-decls.h:709
const char * os_timer_get_name(os_timer_t *timer)
Get the timer name.
os_result_t os_timer_stop(os_timer_t *timer)
Stop the timer.
void os_timer_destruct(os_timer_t *timer)
Destruct the statically allocated timer object instance.
void os_timer_attr_init(os_timer_attr_t *attr)
Initialise the single shot timer attributes.
os_timer_t * os_timer_new(const char *name, os_timer_func_t function, os_timer_func_args_t args, const os_timer_attr_t *attr)
Allocate a timer object instance and construct it.
os_result_t os_timer_start(os_timer_t *timer, os_clock_duration_t period)
Start or restart the timer.
void os_timer_attr_periodic_init(os_timer_attr_t *attr)
Initialise the periodic timer attributes.
void os_timer_construct(os_timer_t *timer, const char *name, os_timer_func_t function, os_timer_func_args_t args, const os_timer_attr_t *attr)
Construct a statically allocated timer object instance.
void os_timer_delete(os_timer_t *timer)
Destruct the timer object instance and deallocate it.
const os_timer_attr_t * os_timer_attr_get_periodic(void)
Get a periodic timer attributes object instance.
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.
uint8_t os_mutex_protocol_t
Definition os-c-decls.h:819
uint8_t os_mutex_type_t
Definition os-c-decls.h:818
uint8_t os_mutex_robustness_t
Definition os-c-decls.h:820
Clock object storage.
Definition os-c-decls.h:644
Condition variable attributes.
Condition variable object storage.
Event flags attributes.
Event flags object storage.
Memory resource object storage.
Memory pool attributes.
Memory pool object storage.
Message queue attributes.
Message queue object storage.
Mutex attributes.
Definition os-c-decls.h:924
Mutex object storage.
Definition os-c-decls.h:974
Semaphore attributes.
Semaphore object storage.
Thread attributes.
Definition os-c-decls.h:493
Thread object storage.
Definition os-c-decls.h:563
Thread stack.
Definition os-c-decls.h:406
Timer attributes.
Definition os-c-decls.h:755
Timer object storage.
Definition os-c-decls.h:785