µ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 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28/*
29 * The code was originally inspired by ARM CMSIS cmsis_os.h file, v1.02,
30 * and tries to remain functionally close to the CMSIS specifications.
31 */
32
33#ifndef CMSIS_PLUS_RTOS_OS_C_API_H_
34#define CMSIS_PLUS_RTOS_OS_C_API_H_
35
36// ----------------------------------------------------------------------------
37
38// Include the µOS++ C API structures declarations.
40
42
43#include <stdint.h>
44#include <stddef.h>
45#include <stdbool.h>
46
47// ----------------------------------------------------------------------------
48
49#ifdef __cplusplus
50extern "C"
51{
52#endif
53
59 // --------------------------------------------------------------------------
68 enum
69 {
73 os_ok = 0
74 };
75
80 // --------------------------------------------------------------------------
104 int
105 os_main (int argc, char* argv[]);
106
111 // --------------------------------------------------------------------------
125 os_sched_initialize (void);
126
134 void
135 __attribute__((noreturn))
136 os_sched_start (void);
137
145 bool
146 os_sched_is_started (void);
147
155 os_sched_lock (void);
156
164 os_sched_unlock (void);
165
173
181 bool
182 os_sched_is_locked (void);
183
191 bool
193
199 bool
200 os_sched_set_preemptive (bool state);
201
206 // --------------------------------------------------------------------------
212#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
213
221
222#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
223
224#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
225
233
234#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
235
240 // --------------------------------------------------------------------------
253 bool
255
264
271 void
273
274 // --------------------------------------------------------------------------
275
284
291 void
293
294#if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
295
303 os_irq_get_stack (void);
304
305#endif
306
315 // --------------------------------------------------------------------------
333 os_this_thread (void);
334
342 void
344
351 void
352 __attribute__((noreturn))
353 os_this_thread_exit (void* exit_ptr);
354
371 os_flags_mode_t mode);
372
388 os_flags_mode_t mode);
389
409 os_clock_duration_t timeout,
410 os_flags_mask_t* oflags,
411 os_flags_mode_t mode);
412
424
436
441 // --------------------------------------------------------------------------
453 void
455
475 void
476 os_thread_construct (os_thread_t* thread, const char* name,
478 const os_thread_attr_t* attr);
479
486 void
488
498 os_thread_new (const char* name, os_thread_func_t func,
499 const os_thread_func_args_t args,
500 const os_thread_attr_t* attr);
501
508 void
510
516 bool
518
533 const char*
535
543
555
564
573 os_thread_join (os_thread_t* thread, void** exit_ptr);
574
581 void
583
596 os_flags_mask_t* oflags);
597
605
606#if defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) || defined(__DOXYGEN__)
607
613 os_thread_user_storage_t*
615
616#endif /* defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) */
617
625
630 // --------------------------------------------------------------------------
636#define os_thread_create os_thread_construct
637#define os_thread_destroy os_thread_destruct
638
643 // --------------------------------------------------------------------------
655 size_t
657
663 size_t
664 os_thread_stack_set_default_size (size_t size_bytes);
665
672 size_t
674
680 size_t
681 os_thread_stack_set_min_size (size_t size_bytes);
682
690
698
704 size_t
706
712 size_t
714
721 bool
723
730 bool
732
737 // --------------------------------------------------------------------------
743#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
744
752
753#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
754
755#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
756
764
765#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
766
771 // --------------------------------------------------------------------------
785
794
802
810
819 // --------------------------------------------------------------------------
835 const char*
837
846
854
866
877
889
897
906
913
920
927
928 // --------------------------------------------------------------------------
929
937 os_sysclock_now (void);
938
949
959
970
971#pragma GCC diagnostic push
972#if defined(__cplusplus)
973#pragma GCC diagnostic ignored "-Wold-style-cast"
974#endif
975
982 __attribute__((always_inline))
983 os_sysclock_ticks_cast (uint32_t microsec)
984 {
985 return (os_clock_duration_t) ((((microsec)
986 * ((uint32_t) OS_INTEGER_SYSTICK_FREQUENCY_HZ)) + (uint32_t) 1000000ul
987 - 1) / (uint32_t) 1000000ul);
988 }
989
996 __attribute__((always_inline))
997 os_sysclock_ticks_cast_long (uint64_t microsec)
998 {
999 return (os_clock_duration_t) ((((microsec)
1000 * ((uint64_t) OS_INTEGER_SYSTICK_FREQUENCY_HZ)) + (uint64_t) 1000000ul
1001 - 1) / (uint64_t) 1000000ul);
1002 }
1003
1004#pragma GCC diagnostic pop
1005
1014 // --------------------------------------------------------------------------
1031 void
1033
1040 void
1042
1047 const os_timer_attr_t*
1049
1069 void
1070 os_timer_construct (os_timer_t* timer, const char* name,
1072 const os_timer_attr_t* attr);
1073
1080 void
1082
1091 os_timer_t*
1092 os_timer_new (const char* name, os_timer_func_t function,
1093 os_timer_func_args_t args, const os_timer_attr_t* attr);
1094
1101 void
1102 os_timer_delete (os_timer_t* timer);
1103
1118 const char*
1120
1131
1141 os_timer_stop (os_timer_t* timer);
1142
1147 // --------------------------------------------------------------------------
1153#define os_timer_create os_timer_construct
1154#define os_timer_destroy os_timer_destruct
1155
1164 // --------------------------------------------------------------------------
1181 void
1183
1190 void
1192
1197 const os_mutex_attr_t*
1199
1217 void
1218 os_mutex_construct (os_mutex_t* mutex, const char* name,
1219 const os_mutex_attr_t* attr);
1220
1229 void
1230 os_mutex_recursive_construct (os_mutex_t* mutex, const char* name,
1231 const os_mutex_attr_t* attr);
1232
1239 void
1241
1248 os_mutex_t*
1249 os_mutex_new (const char* name, const os_mutex_attr_t* attr);
1250
1257 os_mutex_t*
1258 os_mutex_recursive_new (const char* name, const os_mutex_attr_t* attr);
1259
1266 void
1267 os_mutex_delete (os_mutex_t* mutex);
1268
1283 const char*
1285
1307 os_mutex_lock (os_mutex_t* mutex);
1308
1333
1358
1370 os_mutex_unlock (os_mutex_t* mutex);
1371
1379
1391 os_thread_prio_t* old_prio_ceiling);
1392
1403
1411
1419
1427
1435
1442 os_mutex_reset (os_mutex_t* mutex);
1443
1448 // --------------------------------------------------------------------------
1454#define os_mutex_create os_mutex_construct
1455#define os_mutex_recursive_create os_mutex_recursive_construct
1456#define os_mutex_destroy os_mutex_destruct
1457
1466 // --------------------------------------------------------------------------
1483 void
1485
1512 void
1513 os_condvar_construct (os_condvar_t* condvar, const char* name,
1514 const os_condvar_attr_t* attr);
1515
1523 void
1525
1541 os_condvar_new (const char* name, const os_condvar_attr_t* attr);
1542
1550 void
1552
1567 const char*
1569
1580
1591
1611 os_condvar_wait (os_condvar_t* condvar, os_mutex_t* mutex);
1612
1635 os_clock_duration_t timeout);
1636
1641 // --------------------------------------------------------------------------
1647#define os_condvar_create os_condvar_construct
1648#define os_condvar_destroy os_condvar_destruct
1649
1658 // --------------------------------------------------------------------------
1675 void
1677
1685 void
1687 const os_semaphore_count_t initial_value);
1688
1695 void
1697 const os_semaphore_count_t max_value,
1698 const os_semaphore_count_t initial_value);
1699
1704 const os_semaphore_attr_t*
1706
1724 void
1725 os_semaphore_construct (os_semaphore_t* semaphore, const char* name,
1726 const os_semaphore_attr_t* attr);
1727
1736 void
1737 os_semaphore_binary_construct (os_semaphore_t* semaphore, const char* name,
1738 const os_semaphore_count_t initial_value);
1739
1750 void
1751 os_semaphore_counting_construct (os_semaphore_t* semaphore, const char* name,
1752 const os_semaphore_count_t max_value,
1753 const os_semaphore_count_t initial_value);
1754
1761 void
1763
1771 os_semaphore_new (const char* name, const os_semaphore_attr_t* attr);
1772
1780 os_semaphore_binary_new (const char* name,
1781 const os_semaphore_count_t initial_value);
1782
1791 os_semaphore_counting_new (const char* name,
1792 const os_semaphore_count_t max_value,
1793 const os_semaphore_count_t initial_value);
1794
1801 void
1803
1818 const char*
1820
1830 os_semaphore_post (os_semaphore_t* semaphore);
1831
1843 os_semaphore_wait (os_semaphore_t* semaphore);
1844
1858
1876 os_clock_duration_t timeout);
1877
1885
1894
1902
1910
1920#define os_semaphore_create os_semaphore_construct
1921#define os_semaphore_binary_create os_semaphore_binary_construct
1922#define os_semaphore_counting_create os_semaphore_counting_construct
1923#define os_semaphore_destroy os_semaphore_destruct
1924
1933 // --------------------------------------------------------------------------
1950 void
1952
1972 void
1973 os_mempool_construct (os_mempool_t* mempool, const char* name, size_t blocks,
1974 size_t block_size_bytes, const os_mempool_attr_t* attr);
1975
1982 void
1984
1994 os_mempool_new (const char* name, size_t blocks, size_t block_size_bytes,
1995 const os_mempool_attr_t* attr);
1996
2004 void
2006
2021 const char*
2023
2029 void*
2030 os_mempool_alloc (os_mempool_t* mempool);
2031
2037 void*
2039
2046 void*
2048
2057 os_mempool_free (os_mempool_t* mempool, void* block);
2058
2064 size_t
2066
2072 size_t
2074
2080 size_t
2082
2089 bool
2091
2098 bool
2100
2108 os_mempool_reset (os_mempool_t* mempool);
2109
2115 void*
2117
2127#define os_mempool_create os_mempool_construct
2128#define os_mempool_destroy os_mempool_destruct
2129
2138 // --------------------------------------------------------------------------
2155 void
2157
2177 void
2178 os_mqueue_construct (os_mqueue_t* mqueue, const char* name, size_t msgs,
2179 size_t msg_size_bytes, const os_mqueue_attr_t* attr);
2180
2187 void
2189
2199 os_mqueue_new (const char* name, size_t msgs, size_t msg_size_bytes,
2200 const os_mqueue_attr_t* attr);
2201
2209 void
2210 os_mqueue_delete (os_mqueue_t* mqueue);
2211
2226 const char*
2228
2246 os_mqueue_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2247 os_mqueue_prio_t mprio);
2248
2265 os_mqueue_try_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2266 os_mqueue_prio_t mprio);
2267
2288 os_mqueue_timed_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2289 os_clock_duration_t timeout, os_mqueue_prio_t mprio);
2290
2311 os_mqueue_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2312 os_mqueue_prio_t* mprio);
2313
2333 os_mqueue_try_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2334 os_mqueue_prio_t* mprio);
2335
2359 os_mqueue_timed_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2360 os_clock_duration_t timeout,
2361 os_mqueue_prio_t* mprio);
2362
2368 size_t
2370
2376 size_t
2378
2384 size_t
2386
2393 bool
2395
2402 bool
2404
2412 os_mqueue_reset (os_mqueue_t* mqueue);
2413
2423#define os_mqueue_create os_mqueue_construct
2424#define os_mqueue_destroy os_mqueue_destruct
2425
2434 // --------------------------------------------------------------------------
2451 void
2453
2471 void
2472 os_evflags_construct (os_evflags_t* evflags, const char* name,
2473 const os_evflags_attr_t* attr);
2474
2481 void
2483
2491 os_evflags_new (const char* name, const os_evflags_attr_t* attr);
2492
2500 void
2502
2517 const char*
2519
2537 os_flags_mask_t* oflags, os_flags_mode_t mode);
2538
2555 os_flags_mask_t* oflags, os_flags_mode_t mode);
2556
2577 os_clock_duration_t timeout, os_flags_mask_t* oflags,
2578 os_flags_mode_t mode);
2579
2592 os_flags_mask_t* oflags);
2593
2605 os_flags_mask_t* oflags);
2606
2617 os_flags_mode_t mode);
2618
2625 bool
2627
2637#define os_evflags_create os_evflags_construct
2638#define os_evflags_destroy os_evflags_destruct
2639
2648 // --------------------------------------------------------------------------
2664 os_memory_get_default (void);
2665
2672 void*
2673 os_memory_allocate (os_memory_t* memory, size_t bytes, size_t alignment);
2674
2682 void
2683 os_memory_deallocate (os_memory_t* memory, void* addr, size_t bytes,
2684 size_t alignment);
2685
2694 void
2695 os_memory_reset (os_memory_t* memory);
2696
2705 bool
2707
2713 size_t
2715
2721 size_t
2723
2729 size_t
2731
2737 size_t
2739
2745 size_t
2747
2756// --------------------------------------------------------------------------
2757#ifdef __cplusplus
2758}
2759#endif
2760
2761// ----------------------------------------------------------------------------
2762
2763#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:997
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:983
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:134
uint64_t os_statistics_counter_t
Type of variables holding context switches counters.
Definition os-c-decls.h:245
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:184
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:121
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:170
os_port_clock_offset_t os_clock_offset_t
Type of variables holding clock offsets.
Definition os-c-decls.h:222
void * os_iterator_t
Generic iterator, implemented as a pointer.
Definition os-c-decls.h:236
uint64_t os_statistics_duration_t
Type of variables holding durations in CPU cycles.
Definition os-c-decls.h:252
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:210
os_port_clock_timestamp_t os_clock_timestamp_t
Type of variables holding clock time stamps.
Definition os-c-decls.h:199
uint32_t os_result_t
Type of values returned by RTOS functions.
Definition os-c-decls.h:108
@ os_ok
Function completed; no error or event occurred.
Definition os-c-api.h:73
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:355
uint8_t os_thread_prio_t
Type of variables holding thread priorities.
Definition os-c-decls.h:376
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:389
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:343
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:362
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:722
void * os_timer_func_args_t
Type of timer function arguments.
Definition os-c-decls.h:710
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:816
uint8_t os_mutex_type_t
Definition os-c-decls.h:815
uint8_t os_mutex_robustness_t
Definition os-c-decls.h:817
Clock object storage.
Definition os-c-decls.h:649
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:917
Mutex object storage.
Definition os-c-decls.h:967
Semaphore attributes.
Semaphore object storage.
Thread attributes.
Definition os-c-decls.h:502
Thread object storage.
Definition os-c-decls.h:572
Thread stack.
Definition os-c-decls.h:415
Timer attributes.
Definition os-c-decls.h:752
Timer object storage.
Definition os-c-decls.h:782