µ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-wrapper.cpp
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 provides an implementation of the C API for the µOS++
14 * and legacy CMSIS, using the CMSIC++ RTOS definitions.
15 */
16
17#if defined(OS_USE_OS_APP_CONFIG_H)
18#include <cmsis-plus/os-app-config.h>
19#endif
20
21#include <cmsis-plus/rtos/os.h>
23
24// ----------------------------------------------------------------------------
25
26#if defined(__clang__)
27#pragma clang diagnostic ignored "-Wc++98-compat"
28#elif defined(__GNUC__)
29#pragma GCC diagnostic ignored "-Wuseless-cast"
30#endif
31
32// ----------------------------------------------------------------------------
33
34using namespace os;
35using namespace os::rtos;
36
37// ----------------------------------------------------------------------------
38
39// Validate C typedefs sizes & alignment.
40
41static_assert (sizeof (os_result_t) == sizeof (result_t),
42 "adjust size of os_result_t");
43static_assert (alignof (os_result_t) == alignof (result_t),
44 "adjust align of os_result_t");
45
46static_assert (sizeof (os_flags_mode_t) == sizeof (flags::mode_t),
47 "adjust size of os_flags_mode_t");
48static_assert (alignof (os_flags_mode_t) == alignof (flags::mode_t),
49 "adjust align of os_flags_mode_t");
50
51static_assert (sizeof (os_flags_mask_t) == sizeof (flags::mask_t),
52 "adjust size of os_flags_mask_t");
53static_assert (alignof (os_flags_mask_t) == alignof (flags::mask_t),
54 "adjust align of os_flags_mask_t");
55
56static_assert (sizeof (os_sched_state_t) == sizeof (scheduler::state_t),
57 "adjust size of os_sched_state_t");
58static_assert (alignof (os_sched_state_t) == alignof (scheduler::state_t),
59 "adjust align of os_sched_state_t");
60
61static_assert (sizeof (os_irq_state_t) == sizeof (interrupts::state_t),
62 "adjust size of os_irq_state_t");
63static_assert (alignof (os_irq_state_t) == alignof (interrupts::state_t),
64 "adjust align of os_irq_state_t");
65
66static_assert (sizeof (os_clock_timestamp_t) == sizeof (clock::timestamp_t),
67 "adjust size of os_port_clock_timestamp_t");
68static_assert (alignof (os_clock_timestamp_t) == alignof (clock::timestamp_t),
69 "adjust align of os_port_clock_timestamp_t");
70
71static_assert (sizeof (os_clock_duration_t) == sizeof (clock::duration_t),
72 "adjust size of os_port_clock_duration_t");
73static_assert (alignof (os_clock_duration_t) == alignof (clock::duration_t),
74 "adjust align of os_port_clock_duration_t");
75
76static_assert (sizeof (os_clock_offset_t) == sizeof (clock::offset_t),
77 "adjust size of os_port_clock_offset_t");
78static_assert (alignof (os_clock_offset_t) == alignof (clock::offset_t),
79 "adjust align of os_port_clock_offset_t");
80
81static_assert (sizeof (os_statistics_counter_t)
82 == sizeof (statistics::counter_t),
83 "adjust size of os_statistics_counter_t");
84static_assert (alignof (os_statistics_counter_t)
85 == alignof (statistics::counter_t),
86 "adjust align of os_statistics_counter_t");
87
88static_assert (sizeof (os_statistics_duration_t)
89 == sizeof (statistics::duration_t),
90 "adjust size of os_statistics_duration_t");
91static_assert (alignof (os_statistics_duration_t)
92 == alignof (statistics::duration_t),
93 "adjust align of os_statistics_duration_t");
94
95static_assert (sizeof (os_thread_func_args_t) == sizeof (thread::func_args_t),
96 "adjust size of os_thread_func_args_t");
97static_assert (alignof (os_thread_func_args_t)
98 == alignof (thread::func_args_t),
99 "adjust align of os_thread_func_args_t");
100
101static_assert (sizeof (os_thread_func_t) == sizeof (thread::func_t),
102 "adjust size of os_thread_func_t");
103static_assert (alignof (os_thread_func_t) == alignof (thread::func_t),
104 "adjust align of os_thread_func_t");
105
106static_assert (sizeof (os_thread_state_t) == sizeof (thread::state_t),
107 "adjust size of os_thread_state_t");
108static_assert (alignof (os_thread_state_t) == alignof (thread::state_t),
109 "adjust align of os_thread_state_t");
110
111static_assert (sizeof (os_thread_prio_t) == sizeof (thread::priority_t),
112 "adjust size of os_thread_prio_t");
113static_assert (alignof (os_thread_prio_t) == alignof (thread::priority_t),
114 "adjust align of os_thread_prio_t");
115
116static_assert (sizeof (os_timer_func_args_t) == sizeof (timer::func_args_t),
117 "adjust size of os_timer_func_args_t");
118static_assert (alignof (os_timer_func_args_t) == alignof (timer::func_args_t),
119 "adjust align of os_timer_func_args_t");
120
121static_assert (sizeof (os_timer_func_t) == sizeof (timer::func_t),
122 "adjust size of os_timer_func_t");
123static_assert (alignof (os_timer_func_t) == alignof (timer::func_t),
124 "adjust align of os_timer_func_t");
125
126static_assert (sizeof (os_timer_type_t) == sizeof (timer::type_t),
127 "adjust size of os_timer_type_t");
128static_assert (alignof (os_timer_type_t) == alignof (timer::type_t),
129 "adjust align of os_timer_type_t");
130
131static_assert (sizeof (os_timer_state_t) == sizeof (timer::state_t),
132 "adjust size of os_timer_state_t");
133static_assert (alignof (os_timer_state_t) == alignof (timer::state_t),
134 "adjust align of os_timer_state_t");
135
136static_assert (sizeof (os_mutex_count_t) == sizeof (mutex::count_t),
137 "adjust size of os_mutex_count_t");
138static_assert (alignof (os_mutex_count_t) == alignof (mutex::count_t),
139 "adjust align of os_mutex_count_t");
140
141static_assert (sizeof (os_mutex_type_t) == sizeof (mutex::type_t),
142 "adjust size of os_mutex_type_t");
143static_assert (alignof (os_mutex_type_t) == alignof (mutex::type_t),
144 "adjust align of os_mutex_type_t");
145
146static_assert (sizeof (os_mutex_protocol_t) == sizeof (mutex::protocol_t),
147 "adjust size of os_mutex_protocol_t");
148static_assert (alignof (os_mutex_protocol_t) == alignof (mutex::protocol_t),
149 "adjust align of os_mutex_protocol_t");
150
151static_assert (sizeof (os_mutex_robustness_t) == sizeof (mutex::robustness_t),
152 "adjust size of os_mutex_robustness_t");
153static_assert (alignof (os_mutex_robustness_t)
154 == alignof (mutex::robustness_t),
155 "adjust align of os_mutex_robustness_t");
156
157static_assert (sizeof (os_semaphore_count_t) == sizeof (semaphore::count_t),
158 "adjust size of os_semaphore_count_t");
159static_assert (alignof (os_semaphore_count_t) == alignof (semaphore::count_t),
160 "adjust align of os_semaphore_count_t");
161
162static_assert (sizeof (os_mempool_size_t) == sizeof (memory_pool::size_t),
163 "adjust size of os_mempool_size_t");
164static_assert (alignof (os_mempool_size_t) == alignof (memory_pool::size_t),
165 "adjust align of os_mempool_size_t");
166
167static_assert (sizeof (os_mqueue_size_t) == sizeof (message_queue::size_t),
168 "adjust size of os_mqueue_size_t");
169static_assert (alignof (os_mqueue_size_t) == alignof (message_queue::size_t),
170 "adjust align of os_mqueue_size_t");
171
172static_assert (sizeof (os_mqueue_msg_size_t)
173 == sizeof (message_queue::msg_size_t),
174 "adjust size of os_mqueue_msg_size_t");
175static_assert (alignof (os_mqueue_msg_size_t)
176 == alignof (message_queue::msg_size_t),
177 "adjust align of os_mqueue_msg_size_t");
178
179static_assert (sizeof (os_mqueue_index_t) == sizeof (message_queue::index_t),
180 "adjust size of os_mqueue_index_t");
181static_assert (alignof (os_mqueue_index_t) == alignof (message_queue::index_t),
182 "adjust align of os_mqueue_index_t");
183
184static_assert (sizeof (os_mqueue_prio_t) == sizeof (message_queue::priority_t),
185 "adjust size of os_mqueue_prio_t");
186static_assert (alignof (os_mqueue_prio_t)
187 == alignof (message_queue::priority_t),
188 "adjust align of os_mqueue_prio_t");
189
190// ----------------------------------------------------------------------------
191
192// Validate C enumeration values
193
194#pragma GCC diagnostic push
195#if defined(__clang__)
196#pragma clang diagnostic ignored "-Wanon-enum-enum-conversion"
197#else
198#pragma GCC diagnostic ignored "-Wenum-compare"
199#pragma GCC diagnostic ignored "-Wsign-compare"
200#endif
201
203 "adjust os_thread_priority_idle");
205 "adjust os_thread_priority_low");
208 "adjust os_thread_priority_below_normal");
210 "adjust os_thread_priority_normal");
213 "adjust os_thread_priority_above_normal");
215 "adjust os_thread_priority_high");
217 "adjust os_thread_priority_realtime");
219 "adjust os_thread_priority_error");
220
221static_assert (os_flags_mode_all == flags::mode::all,
222 "adjust os_flags_mode_all");
223static_assert (os_flags_mode_any == flags::mode::any,
224 "adjust os_flags_mode_any");
226 "adjust os_flags_mode_clear");
227
229 "adjust os_thread_state_undefined");
231 "adjust os_thread_state_initializing");
233 "adjust os_thread_state_ready");
235 "adjust os_thread_state_running");
237 "adjust os_thread_state_suspended");
239 "adjust os_thread_state_terminated");
241 "adjust os_thread_state_destroyed");
242
243static_assert (os_timer_once == timer::run::once, "adjust os_timer_once");
245 "adjust os_timer_periodic");
246
248 "adjust os_mutex_protocol_none");
250 "adjust os_mutex_protocol_inherit");
252 "adjust os_mutex_protocol_protect");
253
255 "adjust os_mutex_robustness_stalled");
257 "adjust os_mutex_robustness_robust");
258
260 "adjust os_mutex_type_normal");
262 "adjust os_mutex_type_errorcheck");
264 "adjust os_mutex_type_recursive");
266 "adjust os_mutex_type_default");
267
268#pragma GCC diagnostic pop
269
270// ----------------------------------------------------------------------------
271
272// Validate C structs sizes (should match the C++ objects sizes).
273// Validate offset of individual members (if needed, validate member size).
274
275#pragma GCC diagnostic push
276#if defined(__clang__)
277#pragma clang diagnostic ignored "-Winvalid-offsetof"
278#elif defined(__GNUC__)
279#pragma GCC diagnostic ignored "-Winvalid-offsetof"
280#endif
281
282static_assert (sizeof (rtos::clock) == sizeof (os_clock_t),
283 "adjust os_clock_t size");
284
285static_assert (sizeof (rtos::thread) == sizeof (os_thread_t),
286 "adjust os_thread_t size");
287static_assert (sizeof (rtos::thread::attributes) == sizeof (os_thread_attr_t),
288 "adjust os_thread_attr_t size");
289static_assert (offsetof (rtos::thread::attributes, th_stack_address)
290 == offsetof (os_thread_attr_t, th_stack_address),
291 "adjust os_thread_attr_t members");
292static_assert (offsetof (rtos::thread::attributes, th_stack_size_bytes)
293 == offsetof (os_thread_attr_t, th_stack_size_bytes),
294 "adjust os_thread_attr_t members");
295static_assert (offsetof (rtos::thread::attributes, th_priority)
296 == offsetof (os_thread_attr_t, th_priority),
297 "adjust os_thread_attr_t members");
298static_assert (offsetof (rtos::thread::attributes, th_enable_assert_reuse)
299 == offsetof (os_thread_attr_t, th_enable_assert_reuse),
300 "adjust os_thread_attr_t members");
301
302static_assert (sizeof (rtos::timer) == sizeof (os_timer_t),
303 "adjust size of os_timer_t");
304static_assert (sizeof (rtos::timer::attributes) == sizeof (os_timer_attr_t),
305 "adjust size of os_timer_attr_t");
306static_assert (offsetof (rtos::timer::attributes, tm_type)
307 == offsetof (os_timer_attr_t, tm_type),
308 "adjust os_timer_attr_t members");
309
310static_assert (sizeof (rtos::mutex) == sizeof (os_mutex_t),
311 "adjust size of os_mutex_t");
312static_assert (sizeof (rtos::mutex::attributes) == sizeof (os_mutex_attr_t),
313 "adjust size of os_mutex_attr_t");
314static_assert (offsetof (rtos::mutex::attributes, mx_priority_ceiling)
315 == offsetof (os_mutex_attr_t, mx_priority_ceiling),
316 "adjust os_mutex_attr_t members");
317static_assert (offsetof (rtos::mutex::attributes, mx_protocol)
318 == offsetof (os_mutex_attr_t, mx_protocol),
319 "adjust os_mutex_attr_t members");
320static_assert (offsetof (rtos::mutex::attributes, mx_robustness)
321 == offsetof (os_mutex_attr_t, mx_robustness),
322 "adjust os_mutex_attr_t members");
323static_assert (offsetof (rtos::mutex::attributes, mx_type)
324 == offsetof (os_mutex_attr_t, mx_type),
325 "adjust os_mutex_attr_t members");
326static_assert (offsetof (rtos::mutex::attributes, mx_max_count)
327 == offsetof (os_mutex_attr_t, mx_max_count),
328 "adjust os_mutex_attr_t members");
329
330static_assert (sizeof (rtos::condition_variable) == sizeof (os_condvar_t),
331 "adjust size of os_condvar_t");
332static_assert (sizeof (rtos::condition_variable::attributes)
333 == sizeof (os_condvar_attr_t),
334 "adjust size of os_condvar_attr_t");
335
336static_assert (sizeof (rtos::semaphore) == sizeof (os_semaphore_t),
337 "adjust size of os_semaphore_t");
338static_assert (sizeof (rtos::semaphore::attributes)
339 == sizeof (os_semaphore_attr_t),
340 "adjust size of os_semaphore_attr_t");
341static_assert (offsetof (rtos::semaphore::attributes, sm_initial_value)
342 == offsetof (os_semaphore_attr_t, sm_initial_value),
343 "adjust os_semaphore_attr_t members");
344static_assert (offsetof (rtos::semaphore::attributes, sm_max_value)
345 == offsetof (os_semaphore_attr_t, sm_max_value),
346 "adjust os_semaphore_attr_t members");
347
348static_assert (sizeof (rtos::memory_pool) == sizeof (os_mempool_t),
349 "adjust size of os_mempool_t");
350static_assert (sizeof (rtos::memory_pool::attributes)
351 == sizeof (os_mempool_attr_t),
352 "adjust size of os_mempool_attr_t");
353static_assert (offsetof (rtos::memory_pool::attributes, mp_pool_address)
354 == offsetof (os_mempool_attr_t, mp_pool_address),
355 "adjust os_mempool_attr_t members");
356static_assert (offsetof (rtos::memory_pool::attributes, mp_pool_size_bytes)
357 == offsetof (os_mempool_attr_t, mp_pool_size_bytes),
358 "adjust os_mempool_attr_t members");
359
360static_assert (sizeof (rtos::message_queue) == sizeof (os_mqueue_t),
361 "adjust size of os_mqueue_t");
362static_assert (sizeof (rtos::message_queue::attributes)
363 == sizeof (os_mqueue_attr_t),
364 "adjust size of os_mqueue_attr_t");
365static_assert (offsetof (rtos::message_queue::attributes, mq_queue_address)
366 == offsetof (os_mqueue_attr_t, mq_queue_addr),
367 "adjust os_mqueue_attr_t members");
368static_assert (offsetof (rtos::message_queue::attributes, mq_queue_size_bytes)
369 == offsetof (os_mqueue_attr_t, mq_queue_size_bytes),
370 "adjust os_mqueue_attr_t members");
371
372static_assert (sizeof (rtos::event_flags) == sizeof (os_evflags_t),
373 "adjust size of os_evflags_t");
374static_assert (sizeof (rtos::event_flags::attributes)
375 == sizeof (os_evflags_attr_t),
376 "adjust size of os_evflags_attr_t");
377
378static_assert (sizeof (class thread::stack) == sizeof (os_thread_stack_t),
379 "adjust size of os_thread_stack_t");
380static_assert (sizeof (/* class */ thread::context)
381 == sizeof (os_thread_context_t),
382 "adjust size of os_thread_context_t");
383
384#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) \
385 || defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
386static_assert (sizeof (class thread::statistics)
387 == sizeof (os_thread_statistics_t),
388 "adjust size of os_thread_statistics_t");
389#endif
390
391static_assert (sizeof (internal::timer_node)
393 "adjust size of os_internal_clock_timer_node_t");
394
395#pragma GCC diagnostic pop
396
397#pragma GCC diagnostic push
398#if defined(__clang__)
399#pragma clang diagnostic ignored "-Wold-style-cast"
400#elif defined(__GNUC__)
401#pragma GCC diagnostic ignored "-Wold-style-cast"
402#endif
403
404// ----------------------------------------------------------------------------
405
414{
416}
417
424void
426{
428}
429
436bool
438{
439 return scheduler::started ();
440}
441
450{
451 return scheduler::lock ();
452}
453
462{
463 return scheduler::unlock ();
464}
465
474{
475 return scheduler::locked (state);
476}
477
484bool
486{
487 return scheduler::locked ();
488}
489
496bool
498{
499 return scheduler::preemptive ();
500}
501
508bool
510{
511 return scheduler::preemptive (state);
512}
513
514#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
515
524{
525 return static_cast<os_statistics_counter_t> (
527}
528
529#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
530
531#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
532
541{
542 return static_cast<os_statistics_duration_t> (
544}
545
546#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
547
548// ----------------------------------------------------------------------------
549
556bool
558{
560}
561
562// ----------------------------------------------------------------------------
563
572{
574}
575
582void
584{
586}
587
588// ----------------------------------------------------------------------------
589
598{
600}
601
608void
610{
612}
613
614#if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
615
625{
626 return reinterpret_cast<os_thread_stack_t*> (rtos::interrupts::stack ());
627}
628
629#endif
630
631// ----------------------------------------------------------------------------
632
641{
642 return (os_thread_t*)&this_thread::thread ();
643}
644
651void
653{
654 return this_thread::suspend ();
655}
656
663void
664os_this_thread_exit (void* exit_ptr)
665{
666 this_thread::exit (exit_ptr);
667}
668
677 os_flags_mode_t mode)
678{
679 return (os_result_t)this_thread::flags_wait (mask, oflags, mode);
680}
681
690 os_flags_mode_t mode)
691{
692 return (os_result_t)this_thread::flags_try_wait (mask, oflags, mode);
693}
694
703 os_clock_duration_t timeout,
704 os_flags_mask_t* oflags, os_flags_mode_t mode)
705{
706 return (os_result_t)this_thread::flags_timed_wait (mask, timeout, oflags,
707 mode);
708}
709
718{
719 return (os_result_t)this_thread::flags_clear (mask, oflags);
720}
721
730{
731 return (os_flags_mask_t)this_thread::flags_get (mask, mode);
732}
733
734// ----------------------------------------------------------------------------
735
742void
744{
745 assert (attr != nullptr);
746 new (attr) thread::attributes ();
747}
748
757void
760 const os_thread_attr_t* attr)
761{
762 assert (thread != nullptr);
763 if (attr == nullptr)
764 {
765 attr = (const os_thread_attr_t*)&thread::initializer;
766 }
767 new (thread)
769 (const thread::attributes&)*attr);
770}
771
780void
782{
783 assert (thread != nullptr);
784 (reinterpret_cast<rtos::thread&> (*thread)).~thread ();
785}
786
801os_thread_new (const char* name, os_thread_func_t func,
802 const os_thread_func_args_t args, const os_thread_attr_t* attr)
803{
804 if (attr == nullptr)
805 {
806 attr = (const os_thread_attr_t*)&thread::initializer;
807 }
808 return reinterpret_cast<os_thread_t*> (
809 new rtos::thread (name, (thread::func_t)func, (thread::func_args_t)args,
810 (const thread::attributes&)*attr));
811}
812
826void
828{
829 assert (thread != nullptr);
830 delete reinterpret_cast<rtos::thread*> (thread);
831}
832
839bool
841{
842 assert (thread != nullptr);
844 reinterpret_cast<rtos::thread&> (*thread));
845}
846
853const char*
855{
856 assert (thread != nullptr);
857 return (reinterpret_cast<rtos::thread&> (*thread)).name ();
858}
859
868{
869 assert (thread != nullptr);
870 return (os_thread_prio_t)(reinterpret_cast<rtos::thread&> (*thread))
871 .priority ();
872}
873
882{
883 assert (thread != nullptr);
884 return (os_result_t)(reinterpret_cast<rtos::thread&> (*thread))
885 .priority (prio);
886}
887
896{
897 assert (thread != nullptr);
898 return (os_result_t) reinterpret_cast<rtos::thread&> (*thread).kill ();
899}
900
909{
910 assert (thread != nullptr);
911 return (os_result_t) reinterpret_cast<rtos::thread&> (*thread).join (
912 exit_ptr);
913}
914
921void
923{
924 assert (thread != nullptr);
925 return (reinterpret_cast<rtos::thread&> (*thread)).resume ();
926}
927
936 os_flags_mask_t* oflags)
937{
938 assert (thread != nullptr);
939 return (os_result_t)(reinterpret_cast<rtos::thread&> (*thread))
940 .flags_raise (mask, oflags);
941}
942
951{
952 assert (thread != nullptr);
953 return reinterpret_cast<os_thread_state_t> (
954 (reinterpret_cast<rtos::thread&> (*thread)).state ());
955}
956
957#if defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) || defined(__DOXYGEN__)
958
969os_thread_user_storage_t*
971{
972 assert (thread != nullptr);
973 return (reinterpret_cast<rtos::thread&> (*thread)).user_storage ();
974}
975
976#endif /* defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) */
977
986{
987 assert (thread != nullptr);
988 return reinterpret_cast<os_thread_stack_t*> (
989 &(reinterpret_cast<rtos::thread&> (*thread)).stack ());
990}
991
992// ----------------------------------------------------------------------------
993
1000size_t
1002{
1004}
1005
1012size_t
1014{
1015 return thread::stack::default_size (size_bytes);
1016}
1017
1024size_t
1026{
1027 return thread::stack::min_size ();
1028}
1029
1036size_t
1038{
1039 return thread::stack::min_size (size_bytes);
1040}
1041
1050{
1051 assert (stack != nullptr);
1052 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).bottom ();
1053}
1054
1063{
1064 assert (stack != nullptr);
1065 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).top ();
1066}
1067
1074size_t
1076{
1077 assert (stack != nullptr);
1078 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).size ();
1079}
1080
1087size_t
1089{
1090 assert (stack != nullptr);
1091 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).available ();
1092}
1093
1100bool
1102{
1103 assert (stack != nullptr);
1104 return (reinterpret_cast<class rtos::thread::stack&> (*stack))
1105 .check_bottom_magic ();
1106}
1107
1114bool
1116{
1117 assert (stack != nullptr);
1118 return (reinterpret_cast<class rtos::thread::stack&> (*stack))
1119 .check_top_magic ();
1120}
1121
1122// ----------------------------------------------------------------------------
1123
1124#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
1125
1134{
1135 assert (thread != nullptr);
1136 return static_cast<os_statistics_counter_t> (
1137 (reinterpret_cast<rtos::thread&> (*thread))
1138 .statistics ()
1139 .context_switches ());
1140}
1141
1142#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
1143
1144#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
1145
1154{
1155 assert (thread != nullptr);
1156 return static_cast<os_statistics_duration_t> (
1157 (reinterpret_cast<rtos::thread&> (*thread)).statistics ().cpu_cycles ());
1158}
1159
1160#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
1161
1162// ----------------------------------------------------------------------------
1163
1174{
1175#pragma GCC diagnostic push
1176#if defined(__clang__)
1177#elif defined(__GNUC__)
1178#pragma GCC diagnostic ignored "-Waggregate-return"
1179#endif
1180 return reinterpret_cast<os_iterator_t> (
1181 scheduler::children_threads (reinterpret_cast<rtos::thread*> (thread))
1182 .begin ()
1183 .get_iterator_pointer ());
1184#pragma GCC diagnostic pop
1185}
1186
1200{
1201#pragma GCC diagnostic push
1202#if defined(__clang__)
1203#elif defined(__GNUC__)
1204#pragma GCC diagnostic ignored "-Waggregate-return"
1205#endif
1206 return reinterpret_cast<os_iterator_t> (
1207 scheduler::children_threads (reinterpret_cast<rtos::thread*> (thread))
1208 .end ()
1209 .get_iterator_pointer ());
1210#pragma GCC diagnostic pop
1211}
1212
1222{
1223 // Construct a local iterator object based on the pointer.
1224 thread::threads_list::iterator it{
1225 reinterpret_cast<utils::double_list_links*> (iterator)
1226 };
1227 return reinterpret_cast<os_thread_t*> (&(*it));
1228}
1229
1239{
1240 thread::threads_list::iterator it{
1241 reinterpret_cast<utils::double_list_links*> (iterator)
1242 };
1243 ++it;
1244
1245 return reinterpret_cast<os_iterator_t> (it.get_iterator_pointer ());
1246}
1247
1248// ----------------------------------------------------------------------------
1249
1256const char*
1258{
1259 assert (clock != nullptr);
1260 return (reinterpret_cast<rtos::clock&> (*clock)).name ();
1261}
1262
1271{
1272 assert (clock != nullptr);
1273 return (os_clock_timestamp_t)(reinterpret_cast<rtos::clock&> (*clock))
1274 .now ();
1275}
1276
1285{
1286 assert (clock != nullptr);
1287 return (os_clock_timestamp_t)(reinterpret_cast<rtos::clock&> (*clock))
1288 .steady_now ();
1289}
1290
1299{
1300 assert (clock != nullptr);
1301 return (os_result_t)(reinterpret_cast<rtos::clock&> (*clock))
1302 .sleep_for (duration);
1303}
1304
1313{
1314 assert (clock != nullptr);
1315 return (os_result_t)(reinterpret_cast<rtos::clock&> (*clock))
1316 .sleep_until (timestamp);
1317}
1318
1327{
1328 assert (clock != nullptr);
1329 return (os_result_t)(reinterpret_cast<rtos::clock&> (*clock))
1330 .wait_for (timeout);
1331}
1332
1341{
1342 assert (clock != nullptr);
1343 return (os_clock_offset_t)(reinterpret_cast<rtos::clock&> (*clock))
1344 .offset ();
1345}
1346
1347// error unable to resolve reference to
1348// 'os::rtos::adjustable_clock::offset(os::rtos::clock::offset_t)' for \ref
1349// command
1358{
1359 assert (clock != nullptr);
1360 assert (clock != nullptr);
1361 return (os_clock_offset_t)(reinterpret_cast<rtos::clock&> (*clock))
1362 .offset ((clock::offset_t)offset);
1363}
1364
1373{
1374 return (os_clock_t*)&sysclock;
1375}
1376
1385{
1386 return (os_clock_t*)&rtclock;
1387}
1388
1397{
1398 return (os_clock_t*)&hrclock;
1399}
1400
1401// ----------------------------------------------------------------------------
1402
1411{
1413}
1414
1423{
1424 return (os_result_t)sysclock.sleep_for (duration);
1425}
1426
1435{
1436 return (os_result_t)sysclock.sleep_until (timestamp);
1437}
1438
1447{
1448 return (os_result_t)sysclock.wait_for (timeout);
1449}
1450
1451// ----------------------------------------------------------------------------
1452
1459void
1461{
1462 assert (attr != nullptr);
1463 new (attr) timer::attributes ();
1464}
1465
1472void
1474{
1475 assert (attr != nullptr);
1476 new (attr) timer::attributes_periodic ();
1477}
1478
1485const os_timer_attr_t*
1487{
1489}
1490
1499void
1502 const os_timer_attr_t* attr)
1503{
1504 assert (timer != nullptr);
1505 if (attr == nullptr)
1506 {
1508 }
1509 new (timer)
1510 rtos::timer (name, (timer::func_t)function, (timer::func_args_t)args,
1511 (const timer::attributes&)*attr);
1512}
1513
1522void
1524{
1525 assert (timer != nullptr);
1526 (reinterpret_cast<rtos::timer&> (*timer)).~timer ();
1527}
1528
1543os_timer_new (const char* name, os_timer_func_t function,
1544 os_timer_func_args_t args, const os_timer_attr_t* attr)
1545{
1546 if (attr == nullptr)
1547 {
1549 }
1550 return reinterpret_cast<os_timer_t*> (
1551 new rtos::timer (name, (timer::func_t)function, (timer::func_args_t)args,
1552 (const timer::attributes&)*attr));
1553}
1554
1568void
1570{
1571 assert (timer != nullptr);
1572 delete reinterpret_cast<rtos::timer*> (timer);
1573}
1574
1581const char*
1583{
1584 assert (timer != nullptr);
1585 return (reinterpret_cast<rtos::timer&> (*timer)).name ();
1586}
1587
1596{
1597 assert (timer != nullptr);
1598 return (os_result_t)(reinterpret_cast<rtos::timer&> (*timer)).start (period);
1599}
1600
1609{
1610 assert (timer != nullptr);
1611 return (os_result_t)(reinterpret_cast<rtos::timer&> (*timer)).stop ();
1612}
1613
1614// ----------------------------------------------------------------------------
1615
1622void
1624{
1625 assert (attr != nullptr);
1626 new (attr) mutex::attributes ();
1627}
1628
1635void
1637{
1638 assert (attr != nullptr);
1639 new (attr) mutex::attributes_recursive ();
1640}
1641
1648const os_mutex_attr_t*
1650{
1652}
1653
1662void
1664 const os_mutex_attr_t* attr)
1665{
1666 assert (mutex != nullptr);
1667 if (attr == nullptr)
1668 {
1670 }
1671 new (mutex) rtos::mutex (name, (const mutex::attributes&)*attr);
1672}
1673
1682void
1684 const os_mutex_attr_t* attr)
1685{
1686 assert (mutex != nullptr);
1687 if (attr == nullptr)
1688 {
1690 }
1691 new (mutex) rtos::mutex_recursive (name, (const mutex::attributes&)*attr);
1692}
1693
1703void
1705{
1706 assert (mutex != nullptr);
1707 (reinterpret_cast<rtos::mutex&> (*mutex)).~mutex ();
1708}
1709
1724os_mutex_new (const char* name, const os_mutex_attr_t* attr)
1725{
1726 if (attr == nullptr)
1727 {
1729 }
1730 return reinterpret_cast<os_mutex_t*> (
1731 new rtos::mutex (name, (const mutex::attributes&)*attr));
1732}
1733
1748os_mutex_recursive_new (const char* name, const os_mutex_attr_t* attr)
1749{
1750 if (attr == nullptr)
1751 {
1753 }
1754 return reinterpret_cast<os_mutex_t*> (
1755 new rtos::mutex_recursive (name, (const mutex::attributes&)*attr));
1756}
1757
1772void
1774{
1775 assert (mutex != nullptr);
1776 delete reinterpret_cast<rtos::mutex*> (mutex);
1777}
1778
1785const char*
1787{
1788 assert (mutex != nullptr);
1789 return (reinterpret_cast<rtos::mutex&> (*mutex)).name ();
1790}
1791
1800{
1801 assert (mutex != nullptr);
1802 return (os_result_t)(reinterpret_cast<rtos::mutex&> (*mutex)).lock ();
1803}
1804
1813{
1814 assert (mutex != nullptr);
1815 return (os_result_t)(reinterpret_cast<rtos::mutex&> (*mutex)).try_lock ();
1816}
1817
1826{
1827 assert (mutex != nullptr);
1828 return (os_result_t)(reinterpret_cast<rtos::mutex&> (*mutex))
1829 .timed_lock (timeout);
1830}
1831
1840{
1841 assert (mutex != nullptr);
1842 return (os_result_t)(reinterpret_cast<rtos::mutex&> (*mutex)).unlock ();
1843}
1844
1853{
1854 assert (mutex != nullptr);
1855 return (os_thread_prio_t)(reinterpret_cast<rtos::mutex&> (*mutex))
1856 .prio_ceiling ();
1857}
1858
1868 os_thread_prio_t* old_prio_ceiling)
1869{
1870 assert (mutex != nullptr);
1871 return (os_result_t)(reinterpret_cast<rtos::mutex&> (*mutex))
1872 .prio_ceiling (prio_ceiling, old_prio_ceiling);
1873}
1874
1883{
1884 assert (mutex != nullptr);
1885 return (os_result_t)(reinterpret_cast<rtos::mutex&> (*mutex)).consistent ();
1886}
1887
1896{
1897 assert (mutex != nullptr);
1898 return (os_thread_t*)(reinterpret_cast<rtos::mutex&> (*mutex)).owner ();
1899}
1900
1909{
1910 assert (mutex != nullptr);
1911 return (reinterpret_cast<rtos::mutex&> (*mutex)).type ();
1912}
1913
1922{
1923 assert (mutex != nullptr);
1924 return (reinterpret_cast<rtos::mutex&> (*mutex)).protocol ();
1925}
1926
1935{
1936 assert (mutex != nullptr);
1937 return (reinterpret_cast<rtos::mutex&> (*mutex)).robustness ();
1938}
1939
1948{
1949 assert (mutex != nullptr);
1950 return (os_result_t)(reinterpret_cast<rtos::mutex&> (*mutex)).reset ();
1951}
1952
1953// ----------------------------------------------------------------------------
1954
1961void
1963{
1964 assert (attr != nullptr);
1965 new (attr) condition_variable::attributes ();
1966}
1967
1976void
1977os_condvar_construct (os_condvar_t* condvar, const char* name,
1978 const os_condvar_attr_t* attr)
1979{
1980 assert (condvar != nullptr);
1981 if (attr == nullptr)
1982 {
1984 }
1985 new (condvar)
1987}
1988
1997void
1999{
2000 assert (condvar != nullptr);
2001 (reinterpret_cast<condition_variable&> (*condvar)).~condition_variable ();
2002}
2003
2018os_condvar_new (const char* name, const os_condvar_attr_t* attr)
2019{
2020 if (attr == nullptr)
2021 {
2023 }
2024 return reinterpret_cast<os_condvar_t*> (new condition_variable (
2025 name, (const condition_variable::attributes&)*attr));
2026}
2027
2041void
2043{
2044 assert (condvar != nullptr);
2045 delete reinterpret_cast<condition_variable*> (condvar);
2046}
2047
2054const char*
2056{
2057 assert (condvar != nullptr);
2058 return (reinterpret_cast<condition_variable&> (*condvar)).name ();
2059}
2060
2069{
2070 assert (condvar != nullptr);
2071 return (os_result_t)(reinterpret_cast<condition_variable&> (*condvar))
2072 .signal ();
2073}
2074
2083{
2084 assert (condvar != nullptr);
2085 return (os_result_t)(reinterpret_cast<condition_variable&> (*condvar))
2086 .broadcast ();
2087}
2088
2097{
2098 assert (condvar != nullptr);
2099 return (os_result_t)(reinterpret_cast<condition_variable&> (*condvar))
2100 .wait (reinterpret_cast<rtos::mutex&> (*mutex));
2101}
2102
2111 os_clock_duration_t timeout)
2112{
2113 assert (condvar != nullptr);
2114 return (os_result_t)(reinterpret_cast<condition_variable&> (*condvar))
2115 .timed_wait (reinterpret_cast<rtos::mutex&> (*mutex), timeout);
2116}
2117
2118// ----------------------------------------------------------------------------
2119
2126void
2128{
2129 assert (attr != nullptr);
2130 new (attr) semaphore::attributes{};
2131}
2132
2139void
2141 const os_semaphore_count_t initial_value)
2142{
2143 assert (attr != nullptr);
2144 new (attr) semaphore::attributes_binary{ initial_value };
2145}
2146
2153void
2155 const os_semaphore_count_t max_value,
2156 const os_semaphore_count_t initial_value)
2157{
2158 assert (attr != nullptr);
2159 new (attr) semaphore::attributes_counting{ max_value, initial_value };
2160}
2161
2170{
2172}
2173
2182void
2184 const os_semaphore_attr_t* attr)
2185{
2186 assert (semaphore != nullptr);
2187 if (attr == nullptr)
2188 {
2190 }
2191 new (semaphore) rtos::semaphore{ name, (const semaphore::attributes&)*attr };
2192}
2193
2202void
2204 const os_semaphore_count_t initial_value)
2205{
2206 assert (semaphore != nullptr);
2207 new (semaphore) rtos::semaphore_binary{ name, initial_value };
2208}
2209
2218void
2220 const os_semaphore_count_t max_value,
2221 const os_semaphore_count_t initial_value)
2222{
2223 assert (semaphore != nullptr);
2224 new (semaphore) rtos::semaphore_counting{ name, max_value, initial_value };
2225}
2226
2236void
2238{
2239 assert (semaphore != nullptr);
2240 (reinterpret_cast<rtos::semaphore&> (*semaphore)).~semaphore ();
2241}
2242
2257os_semaphore_new (const char* name, const os_semaphore_attr_t* attr)
2258{
2259 if (attr == nullptr)
2260 {
2262 }
2263 return reinterpret_cast<os_semaphore_t*> (
2264 new rtos::semaphore{ name, (const semaphore::attributes&)*attr });
2265}
2266
2281os_semaphore_binary_new (const char* name,
2282 const os_semaphore_count_t initial_value)
2283{
2284 return reinterpret_cast<os_semaphore_t*> (
2285 new rtos::semaphore_binary{ name, initial_value });
2286}
2287
2303 const os_semaphore_count_t max_value,
2304 const os_semaphore_count_t initial_value)
2305{
2306 return reinterpret_cast<os_semaphore_t*> (
2307 new rtos::semaphore_counting{ name, max_value, initial_value });
2308}
2309
2324void
2326{
2327 assert (semaphore != nullptr);
2328 delete reinterpret_cast<rtos::semaphore*> (semaphore);
2329}
2330
2337const char*
2339{
2340 assert (semaphore != nullptr);
2341 return (reinterpret_cast<rtos::semaphore&> (*semaphore)).name ();
2342}
2343
2352{
2353 assert (semaphore != nullptr);
2354 return (os_result_t)(reinterpret_cast<rtos::semaphore&> (*semaphore))
2355 .post ();
2356}
2357
2366{
2367 assert (semaphore != nullptr);
2368 return (os_result_t)(reinterpret_cast<rtos::semaphore&> (*semaphore))
2369 .wait ();
2370}
2371
2380{
2381 assert (semaphore != nullptr);
2382 return (os_result_t)(reinterpret_cast<rtos::semaphore&> (*semaphore))
2383 .try_wait ();
2384}
2385
2394 os_clock_duration_t timeout)
2395{
2396 assert (semaphore != nullptr);
2397 return (os_result_t)(reinterpret_cast<rtos::semaphore&> (*semaphore))
2398 .timed_wait (timeout);
2399}
2400
2409{
2410 assert (semaphore != nullptr);
2411 return (os_semaphore_count_t)(reinterpret_cast<rtos::semaphore&> (
2412 *semaphore))
2413 .value ();
2414}
2415
2424{
2425 assert (semaphore != nullptr);
2426 return (os_result_t)(reinterpret_cast<rtos::semaphore&> (*semaphore))
2427 .reset ();
2428}
2429
2438{
2439 assert (semaphore != nullptr);
2440 return (os_semaphore_count_t)(reinterpret_cast<rtos::semaphore&> (
2441 *semaphore))
2442 .initial_value ();
2443}
2444
2453{
2454 assert (semaphore != nullptr);
2455 return (os_semaphore_count_t)(reinterpret_cast<rtos::semaphore&> (
2456 *semaphore))
2457 .max_value ();
2458}
2459
2460// ----------------------------------------------------------------------------
2461
2468void
2470{
2471 assert (attr != nullptr);
2472 new (attr) memory_pool::attributes ();
2473}
2474
2483void
2484os_mempool_construct (os_mempool_t* mempool, const char* name, size_t blocks,
2485 size_t block_size_bytes, const os_mempool_attr_t* attr)
2486{
2487 assert (mempool != nullptr);
2488 if (attr == nullptr)
2489 {
2491 }
2492 new (mempool) memory_pool (name, blocks, block_size_bytes,
2493 (const memory_pool::attributes&)*attr);
2494}
2495
2504void
2506{
2507 assert (mempool != nullptr);
2508 (reinterpret_cast<memory_pool&> (*mempool)).~memory_pool ();
2509}
2510
2525os_mempool_new (const char* name, size_t blocks, size_t block_size_bytes,
2526 const os_mempool_attr_t* attr)
2527{
2528 if (attr == nullptr)
2529 {
2531 }
2532 return reinterpret_cast<os_mempool_t*> (new memory_pool (
2533 name, blocks, block_size_bytes, (const memory_pool::attributes&)*attr));
2534}
2535
2549void
2551{
2552 assert (mempool != nullptr);
2553 delete reinterpret_cast<memory_pool*> (mempool);
2554}
2555
2562const char*
2564{
2565 assert (mempool != nullptr);
2566 return (reinterpret_cast<memory_pool&> (*mempool)).name ();
2567}
2568
2575void*
2577{
2578 assert (mempool != nullptr);
2579 return (reinterpret_cast<memory_pool&> (*mempool)).alloc ();
2580}
2581
2588void*
2590{
2591 assert (mempool != nullptr);
2592 return (reinterpret_cast<memory_pool&> (*mempool)).try_alloc ();
2593}
2594
2601void*
2603{
2604 assert (mempool != nullptr);
2605 return (reinterpret_cast<memory_pool&> (*mempool)).timed_alloc (timeout);
2606}
2607
2615os_mempool_free (os_mempool_t* mempool, void* block)
2616{
2617 assert (mempool != nullptr);
2618 return (os_result_t)(reinterpret_cast<memory_pool&> (*mempool)).free (block);
2619}
2620
2627size_t
2629{
2630 assert (mempool != nullptr);
2631 return (reinterpret_cast<memory_pool&> (*mempool)).capacity ();
2632}
2633
2640size_t
2642{
2643 assert (mempool != nullptr);
2644 return (reinterpret_cast<memory_pool&> (*mempool)).count ();
2645}
2646
2653size_t
2655{
2656 assert (mempool != nullptr);
2657 return (reinterpret_cast<memory_pool&> (*mempool)).block_size ();
2658}
2659
2666bool
2668{
2669 assert (mempool != nullptr);
2670 return (reinterpret_cast<memory_pool&> (*mempool)).empty ();
2671}
2672
2679bool
2681{
2682 assert (mempool != nullptr);
2683 return (reinterpret_cast<memory_pool&> (*mempool)).full ();
2684}
2685
2694{
2695 assert (mempool != nullptr);
2696 return (os_result_t)(reinterpret_cast<memory_pool&> (*mempool)).reset ();
2697}
2698
2705void*
2707{
2708 assert (mempool != nullptr);
2709 return (void*)(reinterpret_cast<memory_pool&> (*mempool)).pool ();
2710}
2711
2712// --------------------------------------------------------------------------
2713
2720void
2722{
2723 assert (attr != nullptr);
2724 new (attr) message_queue::attributes ();
2725}
2726
2735void
2736os_mqueue_construct (os_mqueue_t* mqueue, const char* name, size_t msgs,
2737 size_t msg_size_bytes, const os_mqueue_attr_t* attr)
2738{
2739 assert (mqueue != nullptr);
2740 if (attr == nullptr)
2741 {
2743 }
2744 new (mqueue) message_queue (name, msgs, msg_size_bytes,
2745 (const message_queue::attributes&)*attr);
2746}
2747
2756void
2758{
2759 assert (mqueue != nullptr);
2760 (reinterpret_cast<message_queue&> (*mqueue)).~message_queue ();
2761}
2762
2777os_mqueue_new (const char* name, size_t msgs, size_t msg_size_bytes,
2778 const os_mqueue_attr_t* attr)
2779{
2780 if (attr == nullptr)
2781 {
2783 }
2784 return reinterpret_cast<os_mqueue_t*> (new message_queue (
2785 name, msgs, msg_size_bytes, (const message_queue::attributes&)*attr));
2786}
2787
2801void
2803{
2804 assert (mqueue != nullptr);
2805 delete reinterpret_cast<message_queue*> (mqueue);
2806}
2807
2814const char*
2816{
2817 assert (mqueue != nullptr);
2818 return (reinterpret_cast<message_queue&> (*mqueue)).name ();
2819}
2820
2828os_mqueue_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2829 os_mqueue_prio_t mprio)
2830{
2831 assert (mqueue != nullptr);
2832 return (os_result_t)(reinterpret_cast<message_queue&> (*mqueue))
2833 .send (msg, nbytes, mprio);
2834}
2835
2843os_mqueue_try_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2844 os_mqueue_prio_t mprio)
2845{
2846 assert (mqueue != nullptr);
2847 return (os_result_t)(reinterpret_cast<message_queue&> (*mqueue))
2848 .try_send (msg, nbytes, mprio);
2849}
2850
2858os_mqueue_timed_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2860{
2861 assert (mqueue != nullptr);
2862 return (os_result_t)(reinterpret_cast<message_queue&> (*mqueue))
2863 .timed_send (msg, nbytes, timeout, mprio);
2864}
2865
2873os_mqueue_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2874 os_mqueue_prio_t* mprio)
2875{
2876 assert (mqueue != nullptr);
2877 return (os_result_t)(reinterpret_cast<message_queue&> (*mqueue))
2878 .receive (msg, nbytes, mprio);
2879}
2880
2888os_mqueue_try_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2889 os_mqueue_prio_t* mprio)
2890{
2891 assert (mqueue != nullptr);
2892 return (os_result_t)(reinterpret_cast<message_queue&> (*mqueue))
2893 .try_receive (msg, nbytes, mprio);
2894}
2895
2903os_mqueue_timed_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2904 os_clock_duration_t timeout, os_mqueue_prio_t* mprio)
2905{
2906 assert (mqueue != nullptr);
2907 return (os_result_t)(reinterpret_cast<message_queue&> (*mqueue))
2908 .timed_receive (msg, nbytes, timeout, mprio);
2909}
2910
2917size_t
2919{
2920 assert (mqueue != nullptr);
2921 return (reinterpret_cast<message_queue&> (*mqueue)).length ();
2922}
2923
2930size_t
2932{
2933 assert (mqueue != nullptr);
2934 return (reinterpret_cast<message_queue&> (*mqueue)).capacity ();
2935}
2936
2943size_t
2945{
2946 assert (mqueue != nullptr);
2947 return (reinterpret_cast<message_queue&> (*mqueue)).msg_size ();
2948}
2949
2956bool
2958{
2959 assert (mqueue != nullptr);
2960 return (reinterpret_cast<message_queue&> (*mqueue)).empty ();
2961}
2962
2969bool
2971{
2972 assert (mqueue != nullptr);
2973 return (reinterpret_cast<message_queue&> (*mqueue)).full ();
2974}
2975
2984{
2985 assert (mqueue != nullptr);
2986 return (os_result_t)(reinterpret_cast<message_queue&> (*mqueue)).reset ();
2987}
2988
2989// --------------------------------------------------------------------------
2990
2997void
2999{
3000 assert (attr != nullptr);
3001 new (attr) event_flags::attributes ();
3002}
3003
3012void
3013os_evflags_construct (os_evflags_t* evflags, const char* name,
3014 const os_evflags_attr_t* attr)
3015{
3016 assert (evflags != nullptr);
3017 if (attr == nullptr)
3018 {
3020 }
3021 new (evflags) event_flags (name, (const event_flags::attributes&)*attr);
3022}
3023
3032void
3034{
3035 assert (evflags != nullptr);
3036 (reinterpret_cast<event_flags&> (*evflags)).~event_flags ();
3037}
3038
3053os_evflags_new (const char* name, const os_evflags_attr_t* attr)
3054{
3055 if (attr == nullptr)
3056 {
3058 }
3059 return reinterpret_cast<os_evflags_t*> (
3060 new event_flags (name, (const event_flags::attributes&)*attr));
3061}
3062
3076void
3078{
3079 assert (evflags != nullptr);
3080 delete reinterpret_cast<event_flags*> (evflags);
3081}
3082
3089const char*
3091{
3092 assert (evflags != nullptr);
3093 return (reinterpret_cast<event_flags&> (*evflags)).name ();
3094}
3095
3104 os_flags_mask_t* oflags, os_flags_mode_t mode)
3105{
3106 assert (evflags != nullptr);
3107 return (os_result_t)(reinterpret_cast<event_flags&> (*evflags))
3108 .wait (mask, oflags, mode);
3109}
3110
3119 os_flags_mask_t* oflags, os_flags_mode_t mode)
3120{
3121 assert (evflags != nullptr);
3122 return (os_result_t)(reinterpret_cast<event_flags&> (*evflags))
3123 .try_wait (mask, oflags, mode);
3124}
3125
3134 os_clock_duration_t timeout, os_flags_mask_t* oflags,
3135 os_flags_mode_t mode)
3136{
3137 assert (evflags != nullptr);
3138 return (os_result_t)(reinterpret_cast<event_flags&> (*evflags))
3139 .timed_wait (mask, timeout, oflags, mode);
3140}
3141
3150 os_flags_mask_t* oflags)
3151{
3152 assert (evflags != nullptr);
3153 return (os_result_t)(reinterpret_cast<event_flags&> (*evflags))
3154 .raise (mask, oflags);
3155}
3156
3165 os_flags_mask_t* oflags)
3166{
3167 assert (evflags != nullptr);
3168 return (os_result_t)(reinterpret_cast<event_flags&> (*evflags))
3169 .clear (mask, oflags);
3170}
3171
3180 os_flags_mode_t mode)
3181{
3182 assert (evflags != nullptr);
3183 return (os_flags_mask_t)(reinterpret_cast<event_flags&> (*evflags))
3184 .get (mask, mode);
3185}
3186
3193bool
3195{
3196 assert (evflags != nullptr);
3197 return (reinterpret_cast<event_flags&> (*evflags)).waiting ();
3198}
3199
3200// --------------------------------------------------------------------------
3201
3210{
3211 return reinterpret_cast<os_memory_t*> (
3213}
3214
3222void*
3223os_memory_allocate (os_memory_t* memory, size_t bytes, size_t alignment)
3224{
3225 assert (memory != nullptr);
3226#pragma GCC diagnostic push
3227#pragma GCC diagnostic ignored "-Wcast-align"
3228 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory))
3229 .allocate (bytes, alignment);
3230#pragma GCC diagnostic pop
3231}
3232
3240void
3241os_memory_deallocate (os_memory_t* memory, void* addr, size_t bytes,
3242 size_t alignment)
3243{
3244 assert (memory != nullptr);
3245#pragma GCC diagnostic push
3246#pragma GCC diagnostic ignored "-Wcast-align"
3247 (reinterpret_cast<rtos::memory::memory_resource&> (*memory))
3248 .deallocate (addr, bytes, alignment);
3249#pragma GCC diagnostic pop
3250}
3251
3259void
3261{
3262 assert (memory != nullptr);
3263#pragma GCC diagnostic push
3264#pragma GCC diagnostic ignored "-Wcast-align"
3265 (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).reset ();
3266#pragma GCC diagnostic pop
3267}
3268
3276bool
3278{
3279 assert (memory != nullptr);
3280#pragma GCC diagnostic push
3281#pragma GCC diagnostic ignored "-Wcast-align"
3282 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory))
3283 .coalesce ();
3284#pragma GCC diagnostic pop
3285}
3286
3294size_t
3296{
3297 assert (memory != nullptr);
3298#pragma GCC diagnostic push
3299#pragma GCC diagnostic ignored "-Wcast-align"
3300 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory))
3301 .total_bytes ();
3302#pragma GCC diagnostic pop
3303}
3304
3312size_t
3314{
3315 assert (memory != nullptr);
3316#pragma GCC diagnostic push
3317#pragma GCC diagnostic ignored "-Wcast-align"
3318 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory))
3319 .allocated_bytes ();
3320#pragma GCC diagnostic pop
3321}
3322
3330size_t
3332{
3333 assert (memory != nullptr);
3334#pragma GCC diagnostic push
3335#pragma GCC diagnostic ignored "-Wcast-align"
3336 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory))
3337 .free_bytes ();
3338#pragma GCC diagnostic pop
3339}
3340
3348size_t
3350{
3351 assert (memory != nullptr);
3352#pragma GCC diagnostic push
3353#pragma GCC diagnostic ignored "-Wcast-align"
3354 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory))
3355 .allocated_chunks ();
3356#pragma GCC diagnostic pop
3357}
3358
3366size_t
3368{
3369 assert (memory != nullptr);
3370#pragma GCC diagnostic push
3371#pragma GCC diagnostic ignored "-Wcast-align"
3372 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory))
3373 .free_chunks ();
3374#pragma GCC diagnostic pop
3375}
3376
3377// ****************************************************************************
3378// ***** Legacy CMSIS RTOS implementation *****
3379
3381
3382// ----------------------------------------------------------------------------
3383// ==== Kernel Control Functions ====
3384
3410{
3412 {
3413 return osErrorISR;
3414 }
3415
3417 return osOK;
3418}
3419
3432{
3434 // In µOS++ this does not return.
3435}
3436
3445int32_t
3447{
3448 return scheduler::started () ? 1 : 0;
3449}
3450
3451#if (defined(osFeature_SysTick) && (osFeature_SysTick != 0))
3452
3466uint32_t
3467osKernelSysTick (void)
3468{
3469 // Get the current SysTick timestamp down to cpu cycles.
3470 return static_cast<uint32_t> (hrclock.now ());
3471}
3472
3473#endif // System Timer available
3474
3475// ----------------------------------------------------------------------------
3476// ==== Thread Management ====
3477
3493osThreadCreate (const osThreadDef_t* thread_def, void* args)
3494{
3496 {
3497 return nullptr;
3498 }
3499
3500 if (thread_def == nullptr)
3501 {
3502 return nullptr;
3503 }
3504
3505 thread::attributes attr;
3506 attr.th_priority = thread_def->tpriority;
3507 attr.th_stack_size_bytes = thread_def->stacksize;
3508
3509 // Creating thread with invalid priority should fail (validator requirement).
3510 if (thread_def->tpriority >= osPriorityError)
3511 {
3512 return nullptr;
3513 }
3514
3515 // Find a free slot in the tread definitions array.
3516 for (uint32_t i = 0; i < thread_def->instances; ++i)
3517 {
3518#pragma GCC diagnostic push
3519#if defined(__clang__)
3520#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
3521#endif
3522 thread* th = (thread*)&thread_def->data[i];
3523 if (th->state () == thread::state::undefined
3524 || th->state () == thread::state::destroyed)
3525 {
3526 if (attr.th_stack_size_bytes > 0)
3527 {
3528 attr.th_stack_address
3529 = &thread_def->stack[(i)
3530 * ((thread_def->stacksize
3531 + sizeof (uint64_t) - 1)
3532 / sizeof (uint64_t))];
3533 }
3534#pragma GCC diagnostic push
3535#if defined(__clang__)
3536#pragma clang diagnostic ignored "-Wcast-function-type"
3537#elif defined(__GNUC__)
3538#pragma GCC diagnostic ignored "-Wcast-function-type"
3539#endif
3540 new (th)
3541 thread (thread_def->name,
3542 reinterpret_cast<thread::func_t> (thread_def->pthread),
3543 args, attr);
3544#pragma GCC diagnostic pop
3545
3546 // No need to yield here, already done by constructor.
3547 return reinterpret_cast<osThreadId> (th);
3548 }
3549#pragma GCC diagnostic pop
3550 }
3551 return nullptr;
3552}
3553
3562{
3564 {
3565 return nullptr;
3566 }
3567
3568 return reinterpret_cast<osThreadId> (&this_thread::thread ());
3569}
3570
3584{
3586 {
3587 return osErrorISR;
3588 }
3589
3590 if (thread_id == nullptr)
3591 {
3592 return osErrorParameter;
3593 }
3594
3595 thread::state_t state
3596 = (reinterpret_cast<rtos::thread&> (*thread_id)).state ();
3597 if (state == thread::state::undefined)
3598 {
3599 return osErrorResource;
3600 }
3601
3602 if ((reinterpret_cast<thread*> (thread_id)) == &this_thread::thread ())
3603 {
3604 this_thread::exit ();
3605 /* NOTREACHED */
3606 }
3607 else
3608 {
3609 (reinterpret_cast<rtos::thread&> (*thread_id)).kill ();
3610 }
3611
3612 return osOK;
3613}
3614
3625{
3627 {
3628 return osErrorISR;
3629 }
3630
3632
3633 return osOK;
3634}
3635
3646{
3648 {
3649 return osErrorISR;
3650 }
3651
3652 if (thread_id == nullptr)
3653 {
3654 return osErrorParameter;
3655 }
3656
3657 thread::state_t state
3658 = (reinterpret_cast<rtos::thread&> (*thread_id)).state ();
3659 if (state == thread::state::undefined || state >= thread::state::destroyed)
3660 {
3661 return osErrorResource;
3662 }
3663
3664 if (priority < osPriorityIdle || priority >= osPriorityError)
3665 {
3666 return osErrorValue;
3667 }
3668
3669 // Call C++ mutator.
3670 thread::priority_t prio = static_cast<thread::priority_t> (priority);
3671 result_t res
3672 = ((reinterpret_cast<rtos::thread&> (*thread_id)).priority (prio));
3673
3674 // A mandatory yield is needed here, must be done
3675 // by the implementation.
3676
3677 if (res == result::ok)
3678 {
3679 return osOK;
3680 }
3681 else if (res == EINVAL)
3682 {
3683 return osErrorValue;
3684 }
3685 else
3686 {
3687 return osErrorOS;
3688 }
3689}
3690
3700{
3702 {
3703 return osPriorityError;
3704 }
3705
3706 if (thread_id == nullptr)
3707 {
3708 return osPriorityError;
3709 }
3710
3711 // Call C++ accessor.
3713 = (reinterpret_cast<rtos::thread&> (*thread_id)).priority ();
3714 return static_cast<osPriority> (prio);
3715}
3716
3717// ----------------------------------------------------------------------------
3718// ==== Generic Wait Functions ====
3719
3734osDelay (uint32_t millisec)
3735{
3737 {
3738 return osErrorISR;
3739 }
3740
3742 clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)));
3743
3744 if (res == ETIMEDOUT)
3745 {
3746 return osEventTimeout;
3747 }
3748 else
3749 {
3750 return osErrorOS;
3751 }
3752}
3753
3754#if (defined(osFeature_Wait) && (osFeature_Wait != 0))
3755
3756#pragma GCC diagnostic push
3757#if defined(__clang__)
3758#elif defined(__GNUC__)
3759#pragma GCC diagnostic ignored "-Waggregate-return"
3760#endif
3761
3779osEvent
3780osWait (uint32_t millisec)
3781{
3782 osEvent event;
3783
3785 {
3786 event.status = osErrorISR;
3787 return event;
3788 }
3789
3790 result_t res = sysclock.wait_for (
3791 clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)));
3792
3793 // TODO: return events
3794 if (res == ETIMEDOUT)
3795 {
3796 event.status = osEventTimeout;
3797 }
3798 else
3799 {
3800 event.status = osErrorOS;
3801 }
3802
3803 return event;
3804}
3805
3806#pragma GCC diagnostic pop
3807
3808#endif // Generic Wait available
3809
3810// ----------------------------------------------------------------------------
3811// ==== Timer Management Functions ====
3812
3822osTimerCreate (const osTimerDef_t* timer_def, os_timer_type type, void* args)
3823{
3825 {
3826 return nullptr;
3827 }
3828
3829 if (timer_def == nullptr)
3830 {
3831 return nullptr;
3832 }
3833
3834 timer::attributes attr;
3835 attr.tm_type = (timer::type_t)type;
3836
3837#pragma GCC diagnostic push
3838#if defined(__clang__)
3839#pragma clang diagnostic ignored "-Wcast-function-type-strict"
3840#endif
3841 new ((void*)timer_def->data)
3842 timer (timer_def->name, (timer::func_t)timer_def->ptimer,
3843 (timer::func_args_t)args, attr);
3844#pragma GCC diagnostic pop
3845
3846 return reinterpret_cast<osTimerId> (timer_def->data);
3847}
3848
3856osTimerStart (osTimerId timer_id, uint32_t millisec)
3857{
3859 {
3860 return osErrorISR;
3861 }
3862
3863 if (timer_id == nullptr)
3864 {
3865 return osErrorParameter;
3866 }
3867
3868 result_t res
3869 = (reinterpret_cast<rtos::timer&> (*timer_id))
3870 .start (clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)));
3871
3872 if (res == result::ok)
3873 {
3874 return osOK;
3875 }
3876 else
3877 {
3878 return osErrorOS;
3879 }
3880}
3881
3887{
3889 {
3890 return osErrorISR;
3891 }
3892
3893 if (timer_id == nullptr)
3894 {
3895 return osErrorParameter;
3896 }
3897
3898 result_t res = (reinterpret_cast<rtos::timer&> (*timer_id)).stop ();
3899 if (res == result::ok)
3900 {
3901 return osOK;
3902 }
3903 else if (res == EAGAIN)
3904 {
3905 return osErrorResource;
3906 }
3907 else
3908 {
3909 return osErrorOS;
3910 }
3911}
3912
3921{
3923 {
3924 return osErrorISR;
3925 }
3926
3927 if (timer_id == nullptr)
3928 {
3929 return osErrorParameter;
3930 }
3931
3932 (reinterpret_cast<rtos::timer&> (*timer_id)).~timer ();
3933 return osOK;
3934}
3935
3936// ----------------------------------------------------------------------------
3937// ==== Signal Management ====
3938
3945int32_t
3946osSignalSet (osThreadId thread_id, int32_t signals)
3947{
3948 if (thread_id == nullptr)
3949 {
3950 return (int32_t)0x80000000;
3951 }
3952
3953 if (signals == (int32_t)0x80000000)
3954 {
3955 return (int32_t)0x80000000;
3956 }
3957
3958 flags::mask_t osig;
3959 ((thread*)(thread_id))->flags_raise ((flags::mask_t)signals, &osig);
3960 return (int32_t)osig;
3961}
3962
3969int32_t
3970osSignalClear (osThreadId thread_id, int32_t signals)
3971{
3972 if (thread_id == nullptr)
3973 {
3974 return (int32_t)0x80000000;
3975 }
3976
3977 if (interrupts::in_handler_mode () || (signals == 0))
3978 {
3979 return (int32_t)0x80000000;
3980 }
3981
3982 flags::mask_t sig;
3983
3984#if defined(OS_INCLUDE_RTOS_THREAD_PUBLIC_FLAGS_CLEAR)
3985 ((thread*)(thread_id))->flags_clear ((flags::mask_t)signals, &sig);
3986#else
3987 assert (((thread*)(thread_id)) == &this_thread::thread ());
3988 // IGNORE THREAD ID!
3989 this_thread::flags_clear ((flags::mask_t)signals, &sig);
3990#endif
3991 return (int32_t)sig;
3992}
3993
3994#pragma GCC diagnostic push
3995#if defined(__clang__)
3996#elif defined(__GNUC__)
3997#pragma GCC diagnostic ignored "-Waggregate-return"
3998#endif
3999
4022osEvent
4023osSignalWait (int32_t signals, uint32_t millisec)
4024{
4025 osEvent event;
4026
4028 {
4029 event.status = osErrorISR;
4030 return event;
4031 }
4032
4033 if ((uint32_t)signals & 0x80000000)
4034 {
4035 event.status = osErrorValue;
4036 return event;
4037 }
4038
4039 result_t res;
4040 if (millisec == osWaitForever)
4041 {
4042 res = this_thread::flags_wait ((flags::mask_t)signals,
4043 (flags::mask_t*)&event.value.signals);
4044 }
4045 else if (millisec == 0)
4046 {
4047 res = this_thread::flags_try_wait ((flags::mask_t)signals,
4048 (flags::mask_t*)&event.value.signals);
4049 }
4050 else
4051 {
4052 res = this_thread::flags_timed_wait (
4053 (flags::mask_t)signals,
4054 clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)),
4055 (flags::mask_t*)&event.value.signals);
4056 }
4057
4058 if (res == result::ok)
4059 {
4060 event.status = osEventSignal;
4061 }
4062 else if (res == EWOULDBLOCK)
4063 {
4064 event.status = osOK; // Only for try_flags_wait().
4065 }
4066 else if (res == ETIMEDOUT)
4067 {
4068 event.status = osEventTimeout; // Only for timed_flags_wait().
4069 }
4070 else if (res == EPERM)
4071 {
4072 event.status = osErrorISR;
4073 }
4074 else if (res == EINVAL)
4075 {
4076 event.status = osErrorValue;
4077 }
4078 else
4079 {
4080 event.status = osErrorOS;
4081 }
4082
4083 return event;
4084}
4085
4086#pragma GCC diagnostic pop
4087
4088// ----------------------------------------------------------------------------
4089
4090// ==== Mutex Management ====
4091
4099osMutexCreate (const osMutexDef_t* mutex_def)
4100{
4102 {
4103 return nullptr;
4104 }
4105
4106 if (mutex_def == nullptr)
4107 {
4108 return nullptr;
4109 }
4110
4111 mutex::attributes attr;
4114
4115 new ((void*)mutex_def->data) mutex (mutex_def->name, attr);
4116
4117 return reinterpret_cast<osMutexId> (mutex_def->data);
4118}
4119
4139osMutexWait (osMutexId mutex_id, uint32_t millisec)
4140{
4142 {
4143 return osErrorISR;
4144 }
4145
4146 if (mutex_id == nullptr)
4147 {
4148 return osErrorParameter;
4149 }
4150
4151 result_t ret;
4152 if (millisec == osWaitForever)
4153 {
4154 ret = (reinterpret_cast<rtos::mutex&> (*mutex_id)).lock ();
4155 // osErrorResource:
4156 }
4157 else if (millisec == 0)
4158 {
4159 ret = (reinterpret_cast<rtos::mutex&> (*mutex_id)).try_lock ();
4160 }
4161 else
4162 {
4163 ret = (reinterpret_cast<rtos::mutex&> (*mutex_id))
4164 .timed_lock (
4165 clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)));
4166 // osErrorTimeoutResource:
4167 }
4168
4169 if (ret == result::ok)
4170 {
4171 // osOK: the mutex has been obtained.
4172 return osOK;
4173 }
4174 else if (ret == EWOULDBLOCK)
4175 {
4176 // The mutex could not be obtained when no timeout was specified.
4177 // Only for try_lock().
4178 return osErrorResource;
4179 }
4180 else if (ret == ENOTRECOVERABLE)
4181 {
4182 // The mutex could not be obtained when no timeout was specified.
4183 // Only for lock().
4184 return osErrorResource;
4185 }
4186 else if (ret == ETIMEDOUT)
4187 {
4188 // The mutex could not be obtained in the given time.
4189 // Only for timed_lock().
4191 }
4192 else
4193 {
4194 return osErrorOS;
4195 }
4196
4197 /* NOTREACHED */
4198}
4199
4210{
4212 {
4213 return osErrorISR;
4214 }
4215
4216 if (mutex_id == nullptr)
4217 {
4218 return osErrorParameter;
4219 }
4220
4221 result_t res;
4222 res = (reinterpret_cast<rtos::mutex&> (*mutex_id)).unlock ();
4223
4224 if (res == result::ok)
4225 {
4226 return osOK;
4227 }
4228 else if ((res == EPERM) || (res == ENOTRECOVERABLE))
4229 {
4230 return osErrorResource;
4231 }
4232 else
4233 {
4234 return osErrorOS;
4235 }
4236}
4237
4249{
4251 {
4252 return osErrorISR;
4253 }
4254
4255 if (mutex_id == nullptr)
4256 {
4257 return osErrorParameter;
4258 }
4259
4260 (reinterpret_cast<rtos::mutex&> (*mutex_id)).~mutex ();
4261 return osOK;
4262}
4263
4264// ----------------------------------------------------------------------------
4265
4266// ==== Semaphore Management Functions ====
4267
4268#if (defined(osFeature_Semaphore) && (osFeature_Semaphore != 0))
4269
4280osSemaphoreCreate (const osSemaphoreDef_t* semaphore_def, int32_t count)
4281{
4283 {
4284 return nullptr;
4285 }
4286
4287 if (semaphore_def == nullptr)
4288 {
4289 return nullptr;
4290 }
4291
4294 // The logic is very strange, the CMSIS expects both the max-count to be the
4295 // same as count, and also to accept a count of 0, which leads to
4296 // useless semaphores. We patch this behaviour in the wrapper, the main
4297 // object uses a more realistic max_value.
4298 attr.sm_max_value
4299 = (semaphore::count_t)(count == 0 ? osFeature_Semaphore : count);
4300
4301 new ((void*)semaphore_def->data) semaphore (semaphore_def->name, attr);
4302
4303 return reinterpret_cast<osSemaphoreId> (semaphore_def->data);
4304}
4305
4328int32_t
4329osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec)
4330{
4332 {
4333 return -1;
4334 }
4335
4336 if (semaphore_id == nullptr)
4337 {
4338 return -1;
4339 }
4340
4341 result_t res;
4342 if (millisec == osWaitForever)
4343 {
4344 res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).wait ();
4345 }
4346 else if (millisec == 0)
4347 {
4348 res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).try_wait ();
4349 if (res == EWOULDBLOCK)
4350 {
4351 return 0;
4352 }
4353 }
4354 else
4355 {
4356 res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id))
4357 .timed_wait (
4358 clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)));
4359 if (res == ETIMEDOUT)
4360 {
4361 return 0;
4362 }
4363 }
4364
4365 if (res == 0)
4366 {
4367 int count = (int32_t)(reinterpret_cast<rtos::semaphore&> (*semaphore_id))
4368 .value ();
4369 return count + 1;
4370 }
4371 else
4372 {
4373 return -1;
4374 }
4375}
4376
4385osSemaphoreRelease (osSemaphoreId semaphore_id)
4386{
4387 if (semaphore_id == nullptr)
4388 {
4389 return osErrorParameter;
4390 }
4391
4392 if ((reinterpret_cast<rtos::semaphore&> (*semaphore_id)).initial_value ()
4393 == 0)
4394 {
4395 return osErrorResource;
4396 }
4397
4398 result_t res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).post ();
4399
4400 if (res == result::ok)
4401 {
4402 return osOK;
4403 }
4404 else if (res == EAGAIN)
4405 {
4406 return osErrorResource;
4407 }
4408 else
4409 {
4410 return osErrorOS;
4411 }
4412}
4413
4424osSemaphoreDelete (osSemaphoreId semaphore_id)
4425{
4427 {
4428 return osErrorISR;
4429 }
4430
4431 if (semaphore_id == nullptr)
4432 {
4433 return osErrorParameter;
4434 }
4435
4436 (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).~semaphore ();
4437 return osOK;
4438}
4439
4440#endif /* Semaphore available */
4441
4442// ----------------------------------------------------------------------------
4443// ==== Memory Pool Management Functions ====
4444
4445#if (defined(osFeature_Pool) && (osFeature_Pool != 0))
4446
4454osPoolCreate (const osPoolDef_t* pool_def)
4455{
4457 {
4458 return nullptr;
4459 }
4460
4461 if (pool_def == nullptr)
4462 {
4463 return nullptr;
4464 }
4465
4467 attr.mp_pool_address = pool_def->pool;
4468 attr.mp_pool_size_bytes = pool_def->pool_sz;
4469
4470 new ((void*)pool_def->data)
4471 memory_pool (pool_def->name, (std::size_t)pool_def->items,
4472 (std::size_t)pool_def->item_sz, attr);
4473
4474 return reinterpret_cast<osPoolId> (pool_def->data);
4475}
4476
4483void*
4484osPoolAlloc (osPoolId pool_id)
4485{
4486 if (pool_id == nullptr)
4487 {
4488 return nullptr;
4489 }
4490
4491 return (reinterpret_cast<memory_pool&> (*pool_id)).try_alloc ();
4492}
4493
4500void*
4501osPoolCAlloc (osPoolId pool_id)
4502{
4503 if (pool_id == nullptr)
4504 {
4505 return nullptr;
4506 }
4507
4508 void* ret;
4509 ret = (reinterpret_cast<memory_pool&> (*pool_id)).try_alloc ();
4510 if (ret != nullptr)
4511 {
4512 memset (ret, 0,
4513 (reinterpret_cast<memory_pool&> (*pool_id)).block_size ());
4514 }
4515
4516 return ret;
4517}
4518
4526osPoolFree (osPoolId pool_id, void* block)
4527{
4528 if (pool_id == nullptr)
4529 {
4530 return osErrorParameter;
4531 }
4532
4533 if (block == nullptr)
4534 {
4535 return osErrorParameter;
4536 }
4537
4538 result_t res;
4539 res = (reinterpret_cast<memory_pool&> (*pool_id)).free (block);
4540
4541 if (res == result::ok)
4542 {
4543 return osOK;
4544 }
4545 else if (res == EINVAL)
4546 {
4547 return osErrorValue;
4548 }
4549 else
4550 {
4551 return osErrorOS;
4552 }
4553}
4554
4555#endif /* Memory Pool Management available */
4556
4557// ----------------------------------------------------------------------------
4558// ==== Message Queue Management Functions ====
4559
4560#if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0))
4561
4569osMessageCreate (const osMessageQDef_t* queue_def,
4570 osThreadId thread_id __attribute__ ((unused)))
4571{
4573 {
4574 return nullptr;
4575 }
4576
4577 if (queue_def == nullptr)
4578 {
4579 return nullptr;
4580 }
4581
4583 attr.mq_queue_address = queue_def->queue;
4584 attr.mq_queue_size_bytes = queue_def->queue_sz;
4585
4586 new ((void*)queue_def->data)
4587 message_queue (queue_def->name, (std::size_t)queue_def->items,
4588 (std::size_t)queue_def->item_sz, attr);
4589
4590 return reinterpret_cast<osMessageQId> (queue_def->data);
4591}
4592
4610osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec)
4611{
4612#pragma GCC diagnostic push
4613#if defined(__clang__)
4614#pragma clang diagnostic ignored "-Wint-to-pointer-cast"
4615#endif
4616
4617 if (queue_id == nullptr)
4618 {
4619 return osErrorParameter;
4620 }
4621
4622 result_t res;
4623 if (millisec == osWaitForever)
4624 {
4626 {
4627 return osErrorParameter;
4628 }
4629 res = (reinterpret_cast<message_queue&> (*queue_id))
4630 .send ((const char*)&info, sizeof (uint32_t), 0);
4631 // osOK, osErrorResource, osErrorParameter
4632 }
4633 else if (millisec == 0)
4634 {
4635 res = (reinterpret_cast<message_queue&> (*queue_id))
4636 .try_send ((const char*)&info, sizeof (uint32_t), 0);
4637 // osOK, osErrorResource, osErrorParameter
4638 }
4639 else
4640 {
4642 {
4643 return osErrorParameter;
4644 }
4645 res = (reinterpret_cast<message_queue&> (*queue_id))
4646 .timed_send (
4647 (const char*)&info, sizeof (uint32_t),
4648 clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)),
4649 0);
4650 // osOK, osErrorTimeoutResource, osErrorParameter
4651 }
4652
4653 if (res == result::ok)
4654 {
4655 // The message was put into the queue.
4656 return osOK;
4657 }
4658 else if (res == EWOULDBLOCK)
4659 {
4660 // No memory in the queue was available
4661 return osErrorResource;
4662 }
4663 else if (res == ETIMEDOUT)
4664 {
4665 // No memory in the queue was available during the given time limit.
4667 }
4668 else if (res == EINVAL || res == EMSGSIZE)
4669 {
4670 // A parameter is invalid or outside of a permitted range.
4671 return osErrorParameter;
4672 }
4673 else
4674 {
4675 return osErrorOS;
4676 }
4677
4678#pragma GCC diagnostic pop
4679}
4680
4681#pragma GCC diagnostic push
4682#if defined(__clang__)
4683#elif defined(__GNUC__)
4684#pragma GCC diagnostic ignored "-Waggregate-return"
4685#endif
4686
4705osEvent
4706osMessageGet (osMessageQId queue_id, uint32_t millisec)
4707{
4708 osEvent event;
4709 result_t res;
4710
4711 if (queue_id == nullptr)
4712 {
4713 event.status = osErrorParameter;
4714 return event;
4715 }
4716
4717 if (millisec == osWaitForever)
4718 {
4720 {
4721 event.status = osErrorParameter;
4722 return event;
4723 }
4724 res = (reinterpret_cast<message_queue&> (*queue_id))
4725 .receive ((char*)&event.value.v, sizeof (uint32_t), nullptr);
4726 // result::event_message;
4727 }
4728 else if (millisec == 0)
4729 {
4730 res = (reinterpret_cast<message_queue&> (*queue_id))
4731 .try_receive ((char*)&event.value.v, sizeof (uint32_t),
4732 nullptr);
4733 // result::event_message when message;
4734 // result::ok when no meessage
4735 }
4736 else
4737 {
4739 {
4740 event.status = osErrorParameter;
4741 return event;
4742 }
4743 res = (reinterpret_cast<message_queue&> (*queue_id))
4744 .timed_receive (
4745 (char*)&event.value.v, sizeof (uint32_t),
4746 clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)),
4747 nullptr);
4748 // result::event_message when message;
4749 // result::event_timeout when timeout;
4750 }
4751
4752 if (res == result::ok)
4753 {
4754 // Message received, value.p contains the pointer to message.
4755 event.status = osEventMessage;
4756 }
4757 else if (res == ETIMEDOUT)
4758 {
4759 // No message has arrived during the given timeout period.
4760 event.status = osEventTimeout;
4761 }
4762 else if (res == EINVAL || res == EMSGSIZE)
4763 {
4764 // A parameter is invalid or outside of a permitted range.
4765 event.status = osErrorParameter;
4766 }
4767 else if (res == EWOULDBLOCK)
4768 {
4769 // No message is available in the queue and no timeout was specified.
4770 event.status = osOK;
4771 }
4772 else
4773 {
4774 event.status = osErrorOS;
4775 }
4776
4777 return event;
4778}
4779
4780#pragma GCC diagnostic pop
4781
4782#endif /* Message Queues available */
4783
4784// ----------------------------------------------------------------------------
4785// ==== Mail Queue Management Functions ====
4786
4787#if (defined(osFeature_MailQ) && (osFeature_MailQ != 0))
4788
4796osMailCreate (const osMailQDef_t* mail_def,
4797 osThreadId thread_id __attribute__ ((unused)))
4798{
4800 {
4801 return nullptr;
4802 }
4803
4804 if (mail_def == nullptr)
4805 {
4806 return nullptr;
4807 }
4808
4809 memory_pool::attributes pool_attr;
4810 pool_attr.mp_pool_address = mail_def->pool;
4811 pool_attr.mp_pool_size_bytes = mail_def->pool_sz;
4812 new ((void*)&mail_def->data->pool)
4813 memory_pool (mail_def->name, (std::size_t)mail_def->items,
4814 (std::size_t)mail_def->pool_item_sz, pool_attr);
4815
4816 message_queue::attributes queue_attr;
4817 queue_attr.mq_queue_address = mail_def->queue;
4818 queue_attr.mq_queue_size_bytes = mail_def->queue_sz;
4819 new ((void*)&mail_def->data->queue)
4820 message_queue (mail_def->name, (std::size_t)mail_def->items,
4821 (std::size_t)mail_def->queue_item_sz, queue_attr);
4822
4823 return (osMailQId)(mail_def->data);
4824}
4825
4849void*
4850osMailAlloc (osMailQId mail_id, uint32_t millisec)
4851{
4852 if (mail_id == nullptr)
4853 {
4854 return nullptr;
4855 }
4856
4857 void* ret = nullptr;
4858
4859#pragma GCC diagnostic push
4860#if defined(__clang__)
4861#elif defined(__GNUC__)
4862#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4863#endif
4864 if (millisec == osWaitForever)
4865 {
4867 {
4868 return nullptr;
4869 }
4870 ret = (reinterpret_cast<memory_pool&> (mail_id->pool)).alloc ();
4871 }
4872 else if (millisec == 0)
4873 {
4874 ret = (reinterpret_cast<memory_pool&> (mail_id->pool)).try_alloc ();
4875 }
4876 else
4877 {
4879 {
4880 return nullptr;
4881 }
4882 ret = (reinterpret_cast<memory_pool&> (mail_id->pool))
4883 .timed_alloc (
4884 clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)));
4885 }
4886#pragma GCC diagnostic pop
4887 return ret;
4888}
4889
4913void*
4914osMailCAlloc (osMailQId mail_id, uint32_t millisec)
4915{
4916 void* ret = osMailAlloc (mail_id, millisec);
4917 if (ret != nullptr)
4918 {
4919#pragma GCC diagnostic push
4920#if defined(__clang__)
4921#elif defined(__GNUC__)
4922#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4923#endif
4924 memset (ret, 0,
4925 (reinterpret_cast<memory_pool&> (mail_id->pool)).block_size ());
4926#pragma GCC diagnostic pop
4927 }
4928 return ret;
4929}
4930
4939osMailPut (osMailQId mail_id, void* mail)
4940{
4941 if (mail_id == nullptr)
4942 {
4943 return osErrorParameter;
4944 }
4945 if (mail == nullptr)
4946 {
4947 return osErrorValue;
4948 }
4949
4950 // Validate pointer.
4951 memory_pool* pool = reinterpret_cast<memory_pool*> (&mail_id->pool);
4952#pragma GCC diagnostic push
4953#if defined(__clang__)
4954#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
4955#endif
4956 if (((char*)mail < (char*)(pool->pool ()))
4957 || (((char*)mail) >= ((char*)(pool->pool ())
4958 + pool->capacity () * pool->block_size ())))
4959 {
4960 return osErrorValue;
4961 }
4962#pragma GCC diagnostic pop
4963
4964 result_t res;
4965#pragma GCC diagnostic push
4966#if defined(__clang__)
4967#elif defined(__GNUC__)
4968#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4969#endif
4970 res = (reinterpret_cast<message_queue&> (mail_id->queue))
4971 .try_send ((const char*)&mail, sizeof (void*), 0);
4972#pragma GCC diagnostic pop
4973 if (res == result::ok)
4974 {
4975 return osOK;
4976 }
4977 else
4978 {
4979 return osErrorOS;
4980 }
4981}
4982
4983#pragma GCC diagnostic push
4984#if defined(__clang__)
4985#elif defined(__GNUC__)
4986#pragma GCC diagnostic ignored "-Waggregate-return"
4987#endif
4988#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4989
5008osEvent
5009osMailGet (osMailQId mail_id, uint32_t millisec)
5010{
5011 osEvent event;
5012 result_t res;
5013
5014 if (mail_id == nullptr)
5015 {
5016 event.status = osErrorParameter;
5017 return event;
5018 }
5019
5020 if (millisec == osWaitForever)
5021 {
5023 {
5024 event.status = osErrorParameter;
5025 return event;
5026 }
5027 res = (reinterpret_cast<message_queue&> ((mail_id->queue)))
5028 .receive ((char*)&event.value.p, sizeof (void*), nullptr);
5029 // osEventMail for ok,
5030 }
5031 else if (millisec == 0)
5032 {
5033 res = (reinterpret_cast<message_queue&> (mail_id->queue))
5034 .try_receive ((char*)&event.value.p, sizeof (void*), nullptr);
5035 // osEventMail for ok,
5036 }
5037 else
5038 {
5040 {
5041 event.status = osErrorParameter;
5042 return event;
5043 }
5044 res = (reinterpret_cast<message_queue&> (mail_id->queue))
5045 .timed_receive (
5046 (char*)&event.value.p, sizeof (void*),
5047 clock_systick::ticks_cast ((uint64_t)(millisec * 1000u)),
5048 nullptr);
5049 // osEventMail for ok, osEventTimeout
5050 }
5051
5052 if (res == result::ok)
5053 {
5054 // Mail received, value.p contains the pointer to mail content.
5055 event.status = osEventMail;
5056 }
5057 else if (res == EWOULDBLOCK)
5058 {
5059 // No mail is available in the queue and no timeout was specified.
5060 event.status = osOK;
5061 }
5062 else if (res == EINVAL || res == EMSGSIZE)
5063 {
5064 // A parameter is invalid or outside of a permitted range.
5065 event.status = osErrorParameter;
5066 }
5067 else if (res == ETIMEDOUT)
5068 {
5069 // No mail has arrived during the given timeout period.
5070 event.status = osEventTimeout;
5071 }
5072 else
5073 {
5074 event.status = osErrorOS;
5075 }
5076
5077 return event;
5078}
5079
5080#pragma GCC diagnostic pop
5081
5089osMailFree (osMailQId mail_id, void* mail)
5090{
5091 if (mail_id == nullptr)
5092 {
5093 return osErrorParameter;
5094 }
5095 if (mail == nullptr)
5096 {
5097 return osErrorValue;
5098 }
5099
5100 return osPoolFree (&(mail_id->pool), mail);
5101}
5102
5103#endif /* Mail Queues available */
5104
5105// ----------------------------------------------------------------------------
5106
5107#pragma GCC diagnostic pop
5108
5109// ----------------------------------------------------------------------------
virtual timestamp_t now(void) override
Tell the current time.
static constexpr clock::duration_t ticks_cast(Rep_T microsec)
Convert microseconds to ticks.
Generic clock.
Definition os-clocks.h:61
result_t wait_for(duration_t timeout)
Timed wait for an event.
virtual result_t sleep_until(timestamp_t timestamp)
Sleep until an absolute timestamp.
virtual timestamp_t now(void)
Tell the current time, possibly adjusted for epoch.
result_t sleep_for(duration_t duration)
Sleep for a relative duration.
Condition variable attributes.
Definition os-condvar.h:55
POSIX compliant condition variable.
Definition os-condvar.h:45
Event flags attributes.
Definition os-evflags.h:67
Synchronised event flags.
Definition os-evflags.h:57
Double linked list node, with time stamp and timer.
Definition os-lists.h:311
static void exit(state_t state)
Exit the interrupts critical section.
Definition os-sched.h:1137
static state_t enter(void)
Enter an interrupts critical section.
Definition os-sched.h:1128
static state_t enter(void)
Enter interrupts uncritical section.
Definition os-sched.h:1166
static void exit(state_t state)
Exit interrupts uncritical section.
Definition os-sched.h:1175
Memory resource manager (abstract class).
Definition os-memory.h:159
Memory pool attributes.
Definition os-mempool.h:99
void * mp_pool_address
Address of the user defined storage for the memory pool.
Definition os-mempool.h:143
std::size_t mp_pool_size_bytes
Size of the user defined storage for the memory pool.
Definition os-mempool.h:148
Synchronised memory pool, using the default RTOS allocator.
Definition os-mempool.h:67
std::size_t block_size(void) const
Get block size.
Definition os-mempool.h:923
std::size_t capacity(void) const
Get memory pool capacity.
Definition os-mempool.h:914
void * pool(void)
Get the pool storage address.
Definition os-mempool.h:959
Message queue attributes.
Definition os-mqueue.h:154
void * mq_queue_address
Address of the user defined storage for the message queue.
Definition os-mqueue.h:198
std::size_t mq_queue_size_bytes
Size of the user defined storage for the message queue.
Definition os-mqueue.h:203
POSIX compliant message queue, using the default RTOS allocator.
Definition os-mqueue.h:67
Recursive mutex attributes.
Definition os-mutex.h:302
Mutex attributes.
Definition os-mutex.h:202
type_t mx_type
Attribute with the mutex type.
Definition os-mutex.h:273
protocol_t mx_protocol
Attribute with the mutex protocol.
Definition os-mutex.h:263
POSIX compliant recursive mutex.
Definition os-mutex.h:703
POSIX compliant mutex.
Definition os-mutex.h:52
Binary semaphore attributes.
Counting semaphore attributes.
Semaphore attributes.
count_t sm_max_value
Semaphore max count value.
count_t sm_initial_value
Semaphore initial count value.
POSIX compliant binary semaphore.
POSIX compliant counting semaphore.
POSIX compliant semaphore.
Thread attributes.
Definition os-thread.h:800
std::size_t th_stack_size_bytes
Size of the user defined storage for the thread stack, in bytes.
Definition os-thread.h:861
priority_t th_priority
Thread initial priority.
Definition os-thread.h:873
void * th_stack_address
Address of the user defined storage for the thread stack.
Definition os-thread.h:847
static std::size_t default_size(void)
Get the default stack size.
Definition os-thread.h:2222
static std::size_t min_size(void)
Get the min stack size.
Definition os-thread.h:2202
Thread statistics.
Definition os-thread.h:894
POSIX compliant thread, using the default RTOS allocator.
Definition os-thread.h:251
result_t kill(void)
Force thread termination.
uint8_t state_t
Type of variables holding thread states.
Definition os-thread.h:357
result_t join(void **exit_ptr=nullptr)
Wait for thread termination.
void *(*)(func_args_t args) func_t
Type of thread function.
Definition os-thread.h:423
_func_args_t func_args_t
Type of thread function arguments.
Definition os-thread.h:414
static bool is_constructed(const thread &thread)
Check if the thread is constructed.
Periodic timer attributes.
Definition os-timer.h:211
Timer attributes.
Definition os-timer.h:131
type_t tm_type
Timer type attribute.
Definition os-timer.h:187
User single-shot or periodic timer.
Definition os-timer.h:56
Standard thread.
osEvent osMailGet(osMailQId mail_id, uint32_t millisec)
Get a mail from a queue.
osPoolId osPoolCreate(const osPoolDef_t *pool_def)
Create a memory pool.
osStatus osMailPut(osMailQId mail_id, void *mail)
Put a mail to a queue.
osStatus osPoolFree(osPoolId pool_id, void *block)
Free a memory block.
osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec)
Get a message or Wait for a Message from a Queue.
#define osFeature_Semaphore
Definition cmsis_os.h:112
void * osMailAlloc(osMailQId mail_id, uint32_t millisec)
Allocate a memory block from a mail.
osPriority
Definition cmsis_os.h:132
@ osPriorityError
Definition cmsis_os.h:140
void * osMailCAlloc(osMailQId mail_id, uint32_t millisec)
Allocate and clear a memory block from a mail.
osEvent osWait(uint32_t millisec)
Wait for Signal, Message, Mail, or Timeout.
osSemaphoreId osSemaphoreCreate(const osSemaphoreDef_t *semaphore_def, int32_t count)
Create a semaphore.
#define osWaitForever
Timeout value.
Definition cmsis_os.h:147
void * osPoolCAlloc(osPoolId pool_id)
Allocate and clear a memory block.
void * osPoolAlloc(osPoolId pool_id)
Allocate a memory block.
osStatus osMailFree(osMailQId mail_id, void *mail)
Free a memory block from a mail.
osStatus osSemaphoreRelease(osSemaphoreId semaphore_id)
Release the semaphore.
osMailQId osMailCreate(const osMailQDef_t *mail_def, osThreadId thread_id)
Create a mail queue.
osStatus osSemaphoreDelete(osSemaphoreId semaphore_id)
Delete the semaphore.
osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
Put a message to a queue.
int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec)
Wait until a Semaphore token becomes available.
uint32_t osKernelSysTick(void)
Get the system timer counter.
os_timer_type
Timer type value for the timer definition.
Definition cmsis_os.h:177
osStatus
Status code values returned by CMSIS-RTOS functions.
Definition cmsis_os.h:154
@ osEventMail
Definition cmsis_os.h:158
@ osErrorISR
Definition cmsis_os.h:163
@ osErrorTimeoutResource
Definition cmsis_os.h:162
@ osErrorValue
Definition cmsis_os.h:167
@ osEventSignal
Definition cmsis_os.h:156
@ osErrorOS
Definition cmsis_os.h:168
@ osEventTimeout
Definition cmsis_os.h:159
@ osErrorResource
Definition cmsis_os.h:161
@ osOK
Definition cmsis_os.h:155
@ osErrorParameter
Definition cmsis_os.h:160
@ osEventMessage
Definition cmsis_os.h:157
osMessageQId osMessageCreate(const osMessageQDef_t *queue_def, osThreadId thread_id)
Create a message queue.
int raise(int sig)
pid_t wait(int *stat_loc)
int kill(pid_t pid, int sig)
ssize_t send(int socket, const void *buffer, size_t length, int flags)
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_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_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_flags_mode_clear
Definition os-c-decls.h:131
@ os_flags_mode_all
Definition os-c-decls.h:129
@ os_flags_mode_any
Definition os-c-decls.h:130
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 free(void *ptr)
Free the allocated memory block.
Definition malloc.cpp:347
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_mutex_protocol_inherit
Inherit priority from highest priority thread.
Definition os-c-decls.h:841
@ os_mutex_protocol_protect
Execute at the highest priority.
Definition os-c-decls.h:846
@ os_mutex_protocol_none
Priority and scheduling not affected by mutex ownership.
Definition os-c-decls.h:836
@ os_mutex_type_recursive
Recursive mutex behaviour.
Definition os-c-decls.h:897
@ os_mutex_type_errorcheck
Check mutex behaviour.
Definition os-c-decls.h:892
@ os_mutex_type_default
Default mutex type.
Definition os-c-decls.h:902
@ os_mutex_type_normal
Normal mutex behaviour.
Definition os-c-decls.h:887
@ os_mutex_robustness_robust
Enhanced robustness at thread termination.
Definition os-c-decls.h:869
@ os_mutex_robustness_stalled
Normal robustness.
Definition os-c-decls.h:864
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.
struct os_thread_statistics_s os_thread_statistics_t
Thread statistics.
struct os_thread_stack_s os_thread_stack_t
Thread stack.
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.
@ os_thread_state_terminated
No longer usable, but resources not yet released.
Definition os-c-decls.h:310
@ os_thread_state_suspended
Not present in the READY list, waiting for an event.
Definition os-c-decls.h:306
@ os_thread_state_undefined
Used to catch uninitialised threads.
Definition os-c-decls.h:294
@ os_thread_state_ready
Present in the READY list and competing for CPU.
Definition os-c-decls.h:298
@ os_thread_state_initialising
Used to check reused threads.
Definition os-c-decls.h:318
@ os_thread_state_destroyed
Terminated and resources (like stack) released.
Definition os-c-decls.h:314
@ os_thread_state_running
Has the CPU and runs.
Definition os-c-decls.h:302
@ os_thread_priority_error
Definition os-c-decls.h:281
@ os_thread_priority_below_normal
Definition os-c-decls.h:274
@ os_thread_priority_high
Definition os-c-decls.h:277
@ os_thread_priority_realtime
Definition os-c-decls.h:278
@ os_thread_priority_idle
Definition os-c-decls.h:271
@ os_thread_priority_normal
Definition os-c-decls.h:275
@ os_thread_priority_low
Definition os-c-decls.h:273
@ os_thread_priority_above_normal
Definition os-c-decls.h:276
uint8_t os_timer_type_t
Type of variables holding timer types.
Definition os-c-decls.h:727
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.
uint8_t os_timer_state_t
Type of variables holding timer states.
Definition os-c-decls.h:734
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.
@ os_timer_once
Definition os-c-decls.h:696
@ os_timer_periodic
Definition os-c-decls.h:697
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:78
clock_highres hrclock
The high resolution clock object instance.
clock_rtc rtclock
The real time clock object instance.
port::clock::timestamp_t timestamp_t
Type of variables holding clock time stamps.
Definition os-clocks.h:88
clock_systick sysclock
The system clock object instance.
port::clock::offset_t offset_t
Type of variables holding clock offsets.
Definition os-clocks.h:99
static const attributes initializer
Default condition variable initialiser.
Definition os-condvar.h:107
class thread::stack * stack(void)
Get the interrupts stack.
Definition os-core.cpp:583
static const attributes initializer
Default event flags initialiser.
Definition os-evflags.h:119
uint16_t size_t
Type of memory pool size storage.
Definition os-mempool.h:79
static const attributes initializer
Default memory pool initialiser.
Definition os-mempool.h:162
memory_resource * get_default_resource(void) noexcept
Get the default RTOS system memory manager.
Definition os-memory.h:1136
uint8_t priority_t
Type of message priority storage.
Definition os-mqueue.h:125
message_queue::size_t index_t
Type of list index storage.
Definition os-mqueue.h:108
static const attributes initializer
Default message queue initialiser.
Definition os-mqueue.h:217
uint8_t size_t
Type of a queue size storage.
Definition os-mqueue.h:83
uint16_t msg_size_t
Type of message size storage.
Definition os-mqueue.h:96
uint8_t type_t
Type of variables holding mutex behaviours.
Definition os-mutex.h:143
uint16_t count_t
Type of variables holding mutex recursion counters.
Definition os-mutex.h:186
static const attributes_recursive initializer_recursive
Default recursive mutex initialiser.
Definition os-mutex.h:341
uint8_t protocol_t
Type of variables holding mutex protocols.
Definition os-mutex.h:58
uint8_t robustness_t
Type of variables holding mutex robustness.
Definition os-mutex.h:103
static const attributes initializer_normal
Default normal mutex initialiser.
Definition os-mutex.h:292
static const attributes_binary initializer_binary
Default binary semaphore initialiser.
int16_t count_t
Type of semaphore counter storage.
uint8_t priority_t
Type of variables holding thread priorities.
Definition os-thread.h:271
void * func_args_t
Timer call back function arguments.
Definition os-timer.h:62
void(*)(func_args_t args) func_t
Entry point of a timer call back function.
Definition os-timer.h:68
uint8_t type_t
Type of of variables holding timer run types.
Definition os-timer.h:74
uint8_t state_t
Type of of variables holding timer states.
Definition os-timer.h:100
static const attributes_periodic periodic_initializer
Default periodic timer initialiser.
Definition os-timer.h:250
@ all
Return when all flags are set.
Definition os-decls.h:295
@ clear
Ask for flags to be cleared after read.
Definition os-decls.h:305
@ any
Return when at least one flag is set.
Definition os-decls.h:300
uint32_t mode_t
Type of variables holding flags modes.
Definition os-decls.h:277
uint32_t mask_t
Type of variables holding flags masks.
Definition os-decls.h:266
port::interrupts::state_t state_t
Type of variables holding interrupts status codes.
Definition os-decls.h:242
bool in_handler_mode(void)
Check if the CPU is in handler mode.
Definition os-sched.h:1101
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:179
rtos::statistics::duration_t cpu_cycles(void)
Get the total duration of all threads.
Definition os-sched.h:1052
rtos::statistics::counter_t context_switches(void)
Get the total number of context switches.
Definition os-sched.h:1027
port::scheduler::state_t state_t
Type of variables holding scheduler state codes.
Definition os-decls.h:200
state_t unlock(void)
Unlock the scheduler.
Definition os-sched.h:884
void start(void)
Start the RTOS scheduler.
Definition os-core.cpp:193
bool started(void)
Check if the scheduler was started.
Definition os-sched.h:829
thread::threads_list & children_threads(thread *th)
Get the children threads.
Definition os-core.cpp:265
state_t lock(void)
Lock the scheduler.
Definition os-sched.h:871
result_t initialize(void)
Initialise the RTOS scheduler.
Definition os-core.cpp:164
bool preemptive(void)
Check if the scheduler is in preemptive mode.
Definition os-sched.h:841
bool locked(void)
Check if the scheduler is locked.
Definition os-sched.h:858
uint64_t duration_t
Type of variables holding durations in CPU cycles.
Definition os-decls.h:220
uint64_t counter_t
Type of variables holding context switches counters.
Definition os-decls.h:215
RTOS namespace.
Definition os-flags.h:37
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:95
System namespace.
void yield() noexcept
Yield the CPU to the next ready thread.
os_mqueue_size_t os_mqueue_index_t
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_mqueue_size_t
uint8_t os_mutex_robustness_t
Definition os-c-decls.h:819
uint16_t os_mempool_size_t
int16_t os_mutex_count_t
Definition os-c-decls.h:816
uint16_t os_mqueue_msg_size_t
osStatus osMutexRelease(osMutexId mutex_id)
Release the mutex.
osStatus osDelay(uint32_t millisec)
Time Delay.
osStatus osThreadSetPriority(osThreadId thread_id, osPriority priority)
Change thread priority.
osTimerId osTimerCreate(const osTimerDef_t *timer_def, os_timer_type type, void *args)
Create a timer.
osStatus osTimerStart(osTimerId timer_id, uint32_t millisec)
Start the timer.
osEvent osSignalWait(int32_t signals, uint32_t millisec)
Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
int32_t osKernelRunning(void)
Check if the RTOS scheduler is started.
int32_t osSignalSet(osThreadId thread_id, int32_t signals)
Set signal flags.
osPriority osThreadGetPriority(osThreadId thread_id)
Get thread priority.
osStatus osKernelInitialize(void)
Initialize the RTOS.
osStatus osTimerStop(osTimerId timer_id)
Stop the timer.
osMutexId osMutexCreate(const osMutexDef_t *mutex_def)
Create a mutex.
osStatus osMutexWait(osMutexId mutex_id, uint32_t millisec)
Wait for mutex.
osStatus osTimerDelete(osTimerId timer_id)
Delete the timer.
int32_t osSignalClear(osThreadId thread_id, int32_t signals)
Clear the specified Signal Flags of an active thread.
osThreadId osThreadCreate(const osThreadDef_t *thread_def, void *args)
Create a thread.
osStatus osKernelStart(void)
osThreadId osThreadGetId(void)
Get the current thread.
osStatus osMutexDelete(osMutexId mutex_id)
Delete the mutex.
osStatus osThreadTerminate(osThreadId thread_id)
Terminate a thread.
osStatus osThreadYield(void)
Yield control.
Single file µOS++ RTOS definitions.
Event structure contains detailed information about an event.
Definition cmsis_os.h:378
osStatus status
Definition cmsis_os.h:379
int32_t signals
Definition cmsis_os.h:384
union osEvent::@0 value
@ none
Priority and scheduling not affected by mutex ownership.
Definition os-mutex.h:75
@ inherit
Inherit priority from highest priority thread.
Definition os-mutex.h:80
@ protect
Execute at the highest priority.
Definition os-mutex.h:85
@ stalled
Normal robustness.
Definition os-mutex.h:120
@ robust
Enhanced robustness at thread termination.
Definition os-mutex.h:125
@ normal
Normal mutex behaviour.
Definition os-mutex.h:160
@ default_
Default value.
Definition os-mutex.h:173
@ errorcheck
Check mutex behaviour.
Definition os-mutex.h:164
@ recursive
Recursive mutex behaviour.
Definition os-mutex.h:168
@ running
Has the CPU and runs.
Definition os-thread.h:386
@ destroyed
Terminated and resources (like stack) released.
Definition os-thread.h:398
@ initializing
Used to check reused threads.
Definition os-thread.h:402
@ terminated
No longer usable, but resources not yet released.
Definition os-thread.h:394
@ ready
Present in the READY list and competing for CPU.
Definition os-thread.h:382
@ undefined
Used to catch uninitialised threads.
Definition os-thread.h:378
@ suspended
Not present in the READY list, waiting for an event.
Definition os-thread.h:390
@ once
Run only once.
Definition os-timer.h:87
@ periodic
Run periodically.
Definition os-timer.h:92
Clock object storage.
Definition os-c-decls.h:644
Condition variable attributes.
Condition variable object storage.
Event flags attributes.
Event flags object storage.
Definition structure for mail queue.
Definition cmsis_os.h:360
osMailQ * data
Definition cmsis_os.h:369
uint32_t items
Definition cmsis_os.h:362
uint32_t queue_sz
Definition cmsis_os.h:368
void * queue
Definition cmsis_os.h:367
uint32_t queue_item_sz
Definition cmsis_os.h:364
uint32_t pool_sz
Definition cmsis_os.h:366
uint32_t pool_item_sz
Definition cmsis_os.h:363
void * pool
Definition cmsis_os.h:365
const char * name
Definition cmsis_os.h:361
os_mqueue_t queue
Definition cmsis_os.h:218
os_mempool_t pool
Definition cmsis_os.h:217
Memory resource object storage.
Memory pool attributes.
Memory pool object storage.
Definition structure for message queue.
Definition cmsis_os.h:346
osMessageQ * data
Definition cmsis_os.h:352
uint32_t items
Definition cmsis_os.h:348
const char * name
Definition cmsis_os.h:347
uint32_t item_sz
Definition cmsis_os.h:349
uint32_t queue_sz
Definition cmsis_os.h:351
Message queue attributes.
Message queue object storage.
Mutex attributes.
Definition os-c-decls.h:923
Mutex definition structure contains setup information for a mutex.
Definition cmsis_os.h:305
osMutex * data
Definition cmsis_os.h:307
const char * name
Definition cmsis_os.h:306
Mutex object storage.
Definition os-c-decls.h:973
Definition structure for memory block allocation.
Definition cmsis_os.h:332
osPool * data
Definition cmsis_os.h:338
const char * name
Definition cmsis_os.h:333
uint32_t pool_sz
Definition cmsis_os.h:337
uint32_t item_sz
Definition cmsis_os.h:335
void * pool
Definition cmsis_os.h:336
uint32_t items
Definition cmsis_os.h:334
Semaphore attributes.
Semaphore definition structure contains setup information for a semaphore.
Definition cmsis_os.h:315
const char * name
Definition cmsis_os.h:316
osSemaphore * data
Definition cmsis_os.h:317
Semaphore object storage.
Thread attributes.
Definition os-c-decls.h:493
Thread context.
Definition os-c-decls.h:431
Thread definition structure contains startup information of a thread.
Definition cmsis_os.h:277
os_pthread pthread
Definition cmsis_os.h:279
uint64_t * stack
Definition cmsis_os.h:284
const char * name
Definition cmsis_os.h:278
osPriority tpriority
Definition cmsis_os.h:280
uint32_t stacksize
Definition cmsis_os.h:282
osThread * data
Definition cmsis_os.h:283
uint32_t instances
Definition cmsis_os.h:281
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 definition structure contains timer parameters.
Definition cmsis_os.h:294
const char * name
Definition cmsis_os.h:295
osTimer * data
Definition cmsis_os.h:297
os_ptimer ptimer
Definition cmsis_os.h:296
Timer object storage.
Definition os-c-decls.h:784