µ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++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12/*
13 * The code was originally inspired by ARM CMSIS cmsis_os.h file, v1.02,
14 * and tries to remain functionally close to the CMSIS specifications.
15 */
16
17#ifndef CMSIS_PLUS_RTOS_OS_C_API_H_
18#define CMSIS_PLUS_RTOS_OS_C_API_H_
19
20// ----------------------------------------------------------------------------
21
22#if defined(OS_USE_OS_APP_CONFIG_H)
23#include <cmsis-plus/os-app-config.h>
24#endif
25
26// Include the µOS++ C API structures declarations.
28
30
31#include <stdint.h>
32#include <stddef.h>
33#include <stdbool.h>
34
35// ----------------------------------------------------------------------------
36
37#ifdef __cplusplus
38extern "C"
39{
40#endif
41
47 // --------------------------------------------------------------------------
56 enum
57 {
61 os_ok = 0
62 };
63
68 // --------------------------------------------------------------------------
92 int
93 os_main (int argc, char* argv[]);
94
99 // --------------------------------------------------------------------------
113 os_sched_initialize (void);
114
122 void __attribute__ ((noreturn))
123 os_sched_start (void);
124
132 bool
133 os_sched_is_started (void);
134
142 os_sched_lock (void);
143
151 os_sched_unlock (void);
152
160
168 bool
169 os_sched_is_locked (void);
170
178 bool
180
186 bool
187 os_sched_set_preemptive (bool state);
188
193 // --------------------------------------------------------------------------
199#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
200
208
209#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
210
211#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
212
220
221#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
222
227 // --------------------------------------------------------------------------
240 bool
242
251
258 void
260
261 // --------------------------------------------------------------------------
262
271
278 void
280
281#if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
282
290 os_irq_get_stack (void);
291
292#endif
293
302 // --------------------------------------------------------------------------
320 os_this_thread (void);
321
329 void
331
338 void __attribute__ ((noreturn))
339 os_this_thread_exit (void* exit_ptr);
340
357 os_flags_mode_t mode);
358
374 os_flags_mode_t mode);
375
395 os_clock_duration_t timeout,
396 os_flags_mask_t* oflags,
397 os_flags_mode_t mode);
398
410
422
427 // --------------------------------------------------------------------------
439 void
441
461 void
462 os_thread_construct (os_thread_t* thread, const char* name,
464 const os_thread_attr_t* attr);
465
472 void
474
484 os_thread_new (const char* name, os_thread_func_t func,
485 const os_thread_func_args_t args,
486 const os_thread_attr_t* attr);
487
495 void
497
503 bool
505
520 const char*
522
530
542
551
560 os_thread_join (os_thread_t* thread, void** exit_ptr);
561
568 void
570
583 os_flags_mask_t* oflags);
584
592
593#if defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) || defined(__DOXYGEN__)
594
600 os_thread_user_storage_t*
602
603#endif /* defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) */
604
612
617 // --------------------------------------------------------------------------
623#define os_thread_create os_thread_construct
624#define os_thread_destroy os_thread_destruct
625
630 // --------------------------------------------------------------------------
642 size_t
644
650 size_t
651 os_thread_stack_set_default_size (size_t size_bytes);
652
659 size_t
661
667 size_t
668 os_thread_stack_set_min_size (size_t size_bytes);
669
677
685
691 size_t
693
699 size_t
701
708 bool
710
717 bool
719
724 // --------------------------------------------------------------------------
730#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
731
739
740#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
741
742#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
743
751
752#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
753
758 // --------------------------------------------------------------------------
772
781
789
797
806 // --------------------------------------------------------------------------
822 const char*
824
833
841
853
864
876
884
893
900
907
914
915 // --------------------------------------------------------------------------
916
924 os_sysclock_now (void);
925
936
946
957
958#pragma GCC diagnostic push
959#if defined(__cplusplus)
960#pragma GCC diagnostic ignored "-Wold-style-cast"
961#endif
962
968 inline os_clock_duration_t __attribute__ ((always_inline))
969 os_sysclock_ticks_cast (uint32_t microsec)
970 {
971#pragma GCC diagnostic push
972#if defined(__clang__)
973#elif defined(__GNUC__)
974#if defined(__cplusplus)
975#pragma GCC diagnostic ignored "-Wuseless-cast"
976#endif
977#endif
978 return (
979 os_clock_duration_t)((((microsec)
981 + (uint32_t)1000000ul - 1)
982 / (uint32_t)1000000ul);
983#pragma GCC diagnostic pop
984 }
985
991 inline os_clock_duration_t __attribute__ ((always_inline))
992 os_sysclock_ticks_cast_long (uint64_t microsec)
993 {
994#pragma GCC diagnostic push
995#if defined(__clang__)
996#elif defined(__GNUC__)
997#if defined(__cplusplus)
998#pragma GCC diagnostic ignored "-Wuseless-cast"
999#endif
1000#endif
1001 return (
1002 os_clock_duration_t)((((microsec)
1003 * ((uint64_t)OS_INTEGER_SYSTICK_FREQUENCY_HZ))
1004 + (uint64_t)1000000ul - 1)
1005 / (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,
1980 const os_mempool_attr_t* attr);
1981
1988 void
1990
2000 os_mempool_new (const char* name, size_t blocks, size_t block_size_bytes,
2001 const os_mempool_attr_t* attr);
2002
2010 void
2012
2027 const char*
2029
2035 void*
2036 os_mempool_alloc (os_mempool_t* mempool);
2037
2043 void*
2045
2052 void*
2054
2063 os_mempool_free (os_mempool_t* mempool, void* block);
2064
2070 size_t
2072
2078 size_t
2080
2086 size_t
2088
2095 bool
2097
2104 bool
2106
2114 os_mempool_reset (os_mempool_t* mempool);
2115
2121 void*
2123
2133#define os_mempool_create os_mempool_construct
2134#define os_mempool_destroy os_mempool_destruct
2135
2144 // --------------------------------------------------------------------------
2161 void
2163
2183 void
2184 os_mqueue_construct (os_mqueue_t* mqueue, const char* name, size_t msgs,
2185 size_t msg_size_bytes, const os_mqueue_attr_t* attr);
2186
2193 void
2195
2205 os_mqueue_new (const char* name, size_t msgs, size_t msg_size_bytes,
2206 const os_mqueue_attr_t* attr);
2207
2215 void
2216 os_mqueue_delete (os_mqueue_t* mqueue);
2217
2232 const char*
2234
2253 os_mqueue_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2254 os_mqueue_prio_t mprio);
2255
2273 os_mqueue_try_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2274 os_mqueue_prio_t mprio);
2275
2297 os_mqueue_timed_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2298 os_clock_duration_t timeout, os_mqueue_prio_t mprio);
2299
2320 os_mqueue_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2321 os_mqueue_prio_t* mprio);
2322
2342 os_mqueue_try_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2343 os_mqueue_prio_t* mprio);
2344
2368 os_mqueue_timed_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2369 os_clock_duration_t timeout,
2370 os_mqueue_prio_t* mprio);
2371
2377 size_t
2379
2385 size_t
2387
2393 size_t
2395
2402 bool
2404
2411 bool
2413
2421 os_mqueue_reset (os_mqueue_t* mqueue);
2422
2432#define os_mqueue_create os_mqueue_construct
2433#define os_mqueue_destroy os_mqueue_destruct
2434
2443 // --------------------------------------------------------------------------
2460 void
2462
2480 void
2481 os_evflags_construct (os_evflags_t* evflags, const char* name,
2482 const os_evflags_attr_t* attr);
2483
2490 void
2492
2500 os_evflags_new (const char* name, const os_evflags_attr_t* attr);
2501
2509 void
2511
2526 const char*
2528
2546 os_flags_mask_t* oflags, os_flags_mode_t mode);
2547
2564 os_flags_mask_t* oflags, os_flags_mode_t mode);
2565
2586 os_clock_duration_t timeout, os_flags_mask_t* oflags,
2587 os_flags_mode_t mode);
2588
2601 os_flags_mask_t* oflags);
2602
2614 os_flags_mask_t* oflags);
2615
2626 os_flags_mode_t mode);
2627
2634 bool
2636
2646#define os_evflags_create os_evflags_construct
2647#define os_evflags_destroy os_evflags_destruct
2648
2657 // --------------------------------------------------------------------------
2673 os_memory_get_default (void);
2674
2681 void*
2682 os_memory_allocate (os_memory_t* memory, size_t bytes, size_t alignment);
2683
2691 void
2692 os_memory_deallocate (os_memory_t* memory, void* addr, size_t bytes,
2693 size_t alignment);
2694
2703 void
2704 os_memory_reset (os_memory_t* memory);
2705
2714 bool
2716
2722 size_t
2724
2730 size_t
2732
2738 size_t
2740
2746 size_t
2748
2754 size_t
2756
2765// --------------------------------------------------------------------------
2766#ifdef __cplusplus
2767}
2768#endif
2769
2770// ----------------------------------------------------------------------------
2771
2772#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:992
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:969
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:120
uint64_t os_statistics_counter_t
Type of variables holding context switches counters.
Definition os-c-decls.h:231
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:170
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:107
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:156
os_port_clock_offset_t os_clock_offset_t
Type of variables holding clock offsets.
Definition os-c-decls.h:208
void * os_iterator_t
Generic iterator, implemented as a pointer.
Definition os-c-decls.h:222
uint64_t os_statistics_duration_t
Type of variables holding durations in CPU cycles.
Definition os-c-decls.h:238
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:196
os_port_clock_timestamp_t os_clock_timestamp_t
Type of variables holding clock time stamps.
Definition os-c-decls.h:185
uint32_t os_result_t
Type of values returned by RTOS functions.
Definition os-c-decls.h:94
@ os_ok
Function completed; no error or event occurred.
Definition os-c-api.h:61
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:341
uint8_t os_thread_prio_t
Type of variables holding thread priorities.
Definition os-c-decls.h:362
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:375
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:348
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:720
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:818
uint8_t os_mutex_type_t
Definition os-c-decls.h:817
uint8_t os_mutex_robustness_t
Definition os-c-decls.h:819
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:923
Mutex object storage.
Definition os-c-decls.h:973
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:754
Timer object storage.
Definition os-c-decls.h:784