µ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++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28/*
29 * The code provides an implementation of the C API for the µOS++
30 * and legacy CMSIS, using the CMSIC++ RTOS definitions.
31 */
32
33#include <cmsis-plus/rtos/os.h>
35
36// ----------------------------------------------------------------------------
37
38#if defined(__clang__)
39#pragma clang diagnostic ignored "-Wc++98-compat"
40#endif
41
42// ----------------------------------------------------------------------------
43
44using namespace os;
45using namespace os::rtos;
46
47// ----------------------------------------------------------------------------
48
49// Validate C typedefs sizes & alignment.
50
51static_assert(sizeof(os_result_t) == sizeof(result_t), "adjust size of os_result_t");
52static_assert(alignof(os_result_t) == alignof(result_t), "adjust align of os_result_t");
53
54static_assert(sizeof(os_flags_mode_t) == sizeof(flags::mode_t), "adjust size of os_flags_mode_t");
55static_assert(alignof(os_flags_mode_t) == alignof(flags::mode_t), "adjust align of os_flags_mode_t");
56
57static_assert(sizeof(os_flags_mask_t) == sizeof(flags::mask_t), "adjust size of os_flags_mask_t");
58static_assert(alignof(os_flags_mask_t) == alignof(flags::mask_t), "adjust align of os_flags_mask_t");
59
60static_assert(sizeof(os_sched_state_t) == sizeof(scheduler::state_t), "adjust size of os_sched_state_t");
61static_assert(alignof(os_sched_state_t) == alignof(scheduler::state_t), "adjust align of os_sched_state_t");
62
63static_assert(sizeof(os_irq_state_t) == sizeof(interrupts::state_t), "adjust size of os_irq_state_t");
64static_assert(alignof(os_irq_state_t) == alignof(interrupts::state_t), "adjust align of os_irq_state_t");
65
66static_assert(sizeof(os_clock_timestamp_t) == sizeof(clock::timestamp_t), "adjust size of os_port_clock_timestamp_t");
67static_assert(alignof(os_clock_timestamp_t) == alignof(clock::timestamp_t), "adjust align of os_port_clock_timestamp_t");
68
69static_assert(sizeof(os_clock_duration_t) == sizeof(clock::duration_t), "adjust size of os_port_clock_duration_t");
70static_assert(alignof(os_clock_duration_t) == alignof(clock::duration_t), "adjust align of os_port_clock_duration_t");
71
72static_assert(sizeof(os_clock_offset_t) == sizeof(clock::offset_t), "adjust size of os_port_clock_offset_t");
73static_assert(alignof(os_clock_offset_t) == alignof(clock::offset_t), "adjust align of os_port_clock_offset_t");
74
75static_assert(sizeof(os_statistics_counter_t) == sizeof(statistics::counter_t), "adjust size of os_statistics_counter_t");
76static_assert(alignof(os_statistics_counter_t) == alignof(statistics::counter_t), "adjust align of os_statistics_counter_t");
77
78static_assert(sizeof(os_statistics_duration_t) == sizeof(statistics::duration_t), "adjust size of os_statistics_duration_t");
79static_assert(alignof(os_statistics_duration_t) == alignof(statistics::duration_t), "adjust align of os_statistics_duration_t");
80
81static_assert(sizeof(os_thread_func_args_t) == sizeof(thread::func_args_t), "adjust size of os_thread_func_args_t");
82static_assert(alignof(os_thread_func_args_t) == alignof(thread::func_args_t), "adjust align of os_thread_func_args_t");
83
84static_assert(sizeof(os_thread_func_t) == sizeof(thread::func_t), "adjust size of os_thread_func_t");
85static_assert(alignof(os_thread_func_t) == alignof(thread::func_t), "adjust align of os_thread_func_t");
86
87static_assert(sizeof(os_thread_state_t) == sizeof(thread::state_t), "adjust size of os_thread_state_t");
88static_assert(alignof(os_thread_state_t) == alignof(thread::state_t), "adjust align of os_thread_state_t");
89
90static_assert(sizeof(os_thread_prio_t) == sizeof(thread::priority_t), "adjust size of os_thread_prio_t");
91static_assert(alignof(os_thread_prio_t) == alignof(thread::priority_t), "adjust align of os_thread_prio_t");
92
93static_assert(sizeof(os_timer_func_args_t) == sizeof(timer::func_args_t), "adjust size of os_timer_func_args_t");
94static_assert(alignof(os_timer_func_args_t) == alignof(timer::func_args_t), "adjust align of os_timer_func_args_t");
95
96static_assert(sizeof(os_timer_func_t) == sizeof(timer::func_t), "adjust size of os_timer_func_t");
97static_assert(alignof(os_timer_func_t) == alignof(timer::func_t), "adjust align of os_timer_func_t");
98
99static_assert(sizeof(os_timer_type_t) == sizeof(timer::type_t), "adjust size of os_timer_type_t");
100static_assert(alignof(os_timer_type_t) == alignof(timer::type_t), "adjust align of os_timer_type_t");
101
102static_assert(sizeof(os_timer_state_t) == sizeof(timer::state_t), "adjust size of os_timer_state_t");
103static_assert(alignof(os_timer_state_t) == alignof(timer::state_t), "adjust align of os_timer_state_t");
104
105static_assert(sizeof(os_mutex_count_t) == sizeof(mutex::count_t), "adjust size of os_mutex_count_t");
106static_assert(alignof(os_mutex_count_t) == alignof(mutex::count_t), "adjust align of os_mutex_count_t");
107
108static_assert(sizeof(os_mutex_type_t) == sizeof(mutex::type_t), "adjust size of os_mutex_type_t");
109static_assert(alignof(os_mutex_type_t) == alignof(mutex::type_t), "adjust align of os_mutex_type_t");
110
111static_assert(sizeof(os_mutex_protocol_t) == sizeof(mutex::protocol_t), "adjust size of os_mutex_protocol_t");
112static_assert(alignof(os_mutex_protocol_t) == alignof(mutex::protocol_t), "adjust align of os_mutex_protocol_t");
113
114static_assert(sizeof(os_mutex_robustness_t) == sizeof(mutex::robustness_t), "adjust size of os_mutex_robustness_t");
115static_assert(alignof(os_mutex_robustness_t) == alignof(mutex::robustness_t), "adjust align of os_mutex_robustness_t");
116
117static_assert(sizeof(os_semaphore_count_t) == sizeof(semaphore::count_t), "adjust size of os_semaphore_count_t");
118static_assert(alignof(os_semaphore_count_t) == alignof(semaphore::count_t), "adjust align of os_semaphore_count_t");
119
120static_assert(sizeof(os_mempool_size_t) == sizeof(memory_pool::size_t), "adjust size of os_mempool_size_t");
121static_assert(alignof(os_mempool_size_t) == alignof(memory_pool::size_t), "adjust align of os_mempool_size_t");
122
123static_assert(sizeof(os_mqueue_size_t) == sizeof(message_queue::size_t), "adjust size of os_mqueue_size_t");
124static_assert(alignof(os_mqueue_size_t) == alignof(message_queue::size_t), "adjust align of os_mqueue_size_t");
125
126static_assert(sizeof(os_mqueue_msg_size_t) == sizeof(message_queue::msg_size_t), "adjust size of os_mqueue_msg_size_t");
127static_assert(alignof(os_mqueue_msg_size_t) == alignof(message_queue::msg_size_t), "adjust align of os_mqueue_msg_size_t");
128
129static_assert(sizeof(os_mqueue_index_t) == sizeof(message_queue::index_t), "adjust size of os_mqueue_index_t");
130static_assert(alignof(os_mqueue_index_t) == alignof(message_queue::index_t), "adjust align of os_mqueue_index_t");
131
132static_assert(sizeof(os_mqueue_prio_t) == sizeof(message_queue::priority_t), "adjust size of os_mqueue_prio_t");
133static_assert(alignof(os_mqueue_prio_t) == alignof(message_queue::priority_t), "adjust align of os_mqueue_prio_t");
134
135// ----------------------------------------------------------------------------
136
137// Validate C enumeration values
138
139#pragma GCC diagnostic push
140#pragma GCC diagnostic ignored "-Wenum-compare"
141#if defined(__clang__)
142#pragma clang diagnostic ignored "-Wanon-enum-enum-conversion"
143#else
144#pragma GCC diagnostic ignored "-Wsign-compare"
145#endif
146
147static_assert(os_thread_priority_idle == thread::priority::idle, "adjust os_thread_priority_idle");
148static_assert(os_thread_priority_low == thread::priority::low, "adjust os_thread_priority_low");
149static_assert(os_thread_priority_below_normal == thread::priority::below_normal, "adjust os_thread_priority_below_normal");
150static_assert(os_thread_priority_normal == thread::priority::normal, "adjust os_thread_priority_normal");
151static_assert(os_thread_priority_above_normal == thread::priority::above_normal, "adjust os_thread_priority_above_normal");
152static_assert(os_thread_priority_high == thread::priority::high, "adjust os_thread_priority_high");
153static_assert(os_thread_priority_realtime == thread::priority::realtime, "adjust os_thread_priority_realtime");
154static_assert(os_thread_priority_error == thread::priority::error, "adjust os_thread_priority_error");
155
156static_assert(os_flags_mode_all == flags::mode::all, "adjust os_flags_mode_all");
157static_assert(os_flags_mode_any == flags::mode::any, "adjust os_flags_mode_any");
158static_assert(os_flags_mode_clear == flags::mode::clear, "adjust os_flags_mode_clear");
159
160static_assert(os_thread_state_undefined == thread::state::undefined, "adjust os_thread_state_undefined");
161static_assert(os_thread_state_initialising == thread::state::initializing, "adjust os_thread_state_initializing");
162static_assert(os_thread_state_ready == thread::state::ready, "adjust os_thread_state_ready");
163static_assert(os_thread_state_running == thread::state::running, "adjust os_thread_state_running");
164static_assert(os_thread_state_suspended == thread::state::suspended, "adjust os_thread_state_suspended");
165static_assert(os_thread_state_terminated == thread::state::terminated, "adjust os_thread_state_terminated");
166static_assert(os_thread_state_destroyed == thread::state::destroyed, "adjust os_thread_state_destroyed");
167
168static_assert(os_timer_once == timer::run::once, "adjust os_timer_once");
169static_assert(os_timer_periodic == timer::run::periodic, "adjust os_timer_periodic");
170
171static_assert(os_mutex_protocol_none == mutex::protocol::none, "adjust os_mutex_protocol_none");
172static_assert(os_mutex_protocol_inherit == mutex::protocol::inherit, "adjust os_mutex_protocol_inherit");
173static_assert(os_mutex_protocol_protect == mutex::protocol::protect, "adjust os_mutex_protocol_protect");
174
175static_assert(os_mutex_robustness_stalled == mutex::robustness::stalled, "adjust os_mutex_robustness_stalled");
176static_assert(os_mutex_robustness_robust == mutex::robustness::robust, "adjust os_mutex_robustness_robust");
177
178static_assert(os_mutex_type_normal == mutex::type::normal, "adjust os_mutex_type_normal");
179static_assert(os_mutex_type_errorcheck == mutex::type::errorcheck, "adjust os_mutex_type_errorcheck");
180static_assert(os_mutex_type_recursive == mutex::type::recursive, "adjust os_mutex_type_recursive");
181static_assert(os_mutex_type_default == mutex::type::default_, "adjust os_mutex_type_default");
182
183#pragma GCC diagnostic pop
184
185// ----------------------------------------------------------------------------
186
187// Validate C structs sizes (should match the C++ objects sizes).
188// Validate offset of individual members (if needed, validate member size).
189
190#pragma GCC diagnostic push
191#pragma GCC diagnostic ignored "-Winvalid-offsetof"
192
193static_assert(sizeof(rtos::clock) == sizeof(os_clock_t), "adjust os_clock_t size");
194
195static_assert(sizeof(rtos::thread) == sizeof(os_thread_t), "adjust os_thread_t size");
196static_assert(sizeof(rtos::thread::attributes) == sizeof(os_thread_attr_t), "adjust os_thread_attr_t size");
197static_assert(offsetof(rtos::thread::attributes, th_stack_address) == offsetof(os_thread_attr_t, th_stack_address), "adjust os_thread_attr_t members");
198static_assert(offsetof(rtos::thread::attributes, th_stack_size_bytes) == offsetof(os_thread_attr_t, th_stack_size_bytes), "adjust os_thread_attr_t members");
199static_assert(offsetof(rtos::thread::attributes, th_priority) == offsetof(os_thread_attr_t, th_priority), "adjust os_thread_attr_t members");
200static_assert(offsetof(rtos::thread::attributes, th_enable_assert_reuse) == offsetof(os_thread_attr_t, th_enable_assert_reuse), "adjust os_thread_attr_t members");
201
202static_assert(sizeof(rtos::timer) == sizeof(os_timer_t), "adjust size of os_timer_t");
203static_assert(sizeof(rtos::timer::attributes) == sizeof(os_timer_attr_t), "adjust size of os_timer_attr_t");
204static_assert(offsetof(rtos::timer::attributes, tm_type) == offsetof(os_timer_attr_t, tm_type), "adjust os_timer_attr_t members");
205
206static_assert(sizeof(rtos::mutex) == sizeof(os_mutex_t), "adjust size of os_mutex_t");
207static_assert(sizeof(rtos::mutex::attributes) == sizeof(os_mutex_attr_t), "adjust size of os_mutex_attr_t");
208static_assert(offsetof(rtos::mutex::attributes, mx_priority_ceiling) == offsetof(os_mutex_attr_t, mx_priority_ceiling), "adjust os_mutex_attr_t members");
209static_assert(offsetof(rtos::mutex::attributes, mx_protocol) == offsetof(os_mutex_attr_t, mx_protocol), "adjust os_mutex_attr_t members");
210static_assert(offsetof(rtos::mutex::attributes, mx_robustness) == offsetof(os_mutex_attr_t, mx_robustness), "adjust os_mutex_attr_t members");
211static_assert(offsetof(rtos::mutex::attributes, mx_type) == offsetof(os_mutex_attr_t, mx_type), "adjust os_mutex_attr_t members");
212static_assert(offsetof(rtos::mutex::attributes, mx_max_count) == offsetof(os_mutex_attr_t, mx_max_count), "adjust os_mutex_attr_t members");
213
214static_assert(sizeof(rtos::condition_variable) == sizeof(os_condvar_t), "adjust size of os_condvar_t");
215static_assert(sizeof(rtos::condition_variable::attributes) == sizeof(os_condvar_attr_t), "adjust size of os_condvar_attr_t");
216
217static_assert(sizeof(rtos::semaphore) == sizeof(os_semaphore_t), "adjust size of os_semaphore_t");
218static_assert(sizeof(rtos::semaphore::attributes) == sizeof(os_semaphore_attr_t), "adjust size of os_semaphore_attr_t");
219static_assert(offsetof(rtos::semaphore::attributes, sm_initial_value) == offsetof(os_semaphore_attr_t, sm_initial_value), "adjust os_semaphore_attr_t members");
220static_assert(offsetof(rtos::semaphore::attributes, sm_max_value) == offsetof(os_semaphore_attr_t, sm_max_value), "adjust os_semaphore_attr_t members");
221
222static_assert(sizeof(rtos::memory_pool) == sizeof(os_mempool_t), "adjust size of os_mempool_t");
223static_assert(sizeof(rtos::memory_pool::attributes) == sizeof(os_mempool_attr_t), "adjust size of os_mempool_attr_t");
224static_assert(offsetof(rtos::memory_pool::attributes, mp_pool_address) == offsetof(os_mempool_attr_t, mp_pool_address), "adjust os_mempool_attr_t members");
225static_assert(offsetof(rtos::memory_pool::attributes, mp_pool_size_bytes) == offsetof(os_mempool_attr_t, mp_pool_size_bytes), "adjust os_mempool_attr_t members");
226
227static_assert(sizeof(rtos::message_queue) == sizeof(os_mqueue_t), "adjust size of os_mqueue_t");
228static_assert(sizeof(rtos::message_queue::attributes) == sizeof(os_mqueue_attr_t), "adjust size of os_mqueue_attr_t");
229static_assert(offsetof(rtos::message_queue::attributes, mq_queue_address) == offsetof(os_mqueue_attr_t, mq_queue_addr), "adjust os_mqueue_attr_t members");
230static_assert(offsetof(rtos::message_queue::attributes, mq_queue_size_bytes) == offsetof(os_mqueue_attr_t, mq_queue_size_bytes), "adjust os_mqueue_attr_t members");
231
232static_assert(sizeof(rtos::event_flags) == sizeof(os_evflags_t), "adjust size of os_evflags_t");
233static_assert(sizeof(rtos::event_flags::attributes) == sizeof(os_evflags_attr_t), "adjust size of os_evflags_attr_t");
234
235static_assert(sizeof(class thread::stack) == sizeof(os_thread_stack_t), "adjust size of os_thread_stack_t");
236static_assert(sizeof(class thread::context) == sizeof(os_thread_context_t), "adjust size of os_thread_context_t");
237
238#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) \
239 || defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
240static_assert(sizeof(class thread::statistics) == sizeof(os_thread_statistics_t), "adjust size of os_thread_statistics_t");
241#endif
242
243static_assert(sizeof(internal::timer_node) == sizeof(os_internal_clock_timer_node_t), "adjust size of os_internal_clock_timer_node_t");
244
245#pragma GCC diagnostic pop
246
247#pragma GCC diagnostic push
248#pragma GCC diagnostic ignored "-Wold-style-cast"
249
250// ----------------------------------------------------------------------------
251
260{
262}
263
270void
272{
274}
275
282bool
284{
285 return scheduler::started ();
286}
287
296{
297 return scheduler::lock ();
298}
299
308{
309 return scheduler::unlock ();
310}
311
320{
321 return scheduler::locked (state);
322}
323
330bool
332{
333 return scheduler::locked ();
334}
335
342bool
344{
345 return scheduler::preemptive ();
346}
347
354bool
356{
357 return scheduler::preemptive (state);
358}
359
360#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
361
370{
372}
373
374#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
375
376#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
377
386{
388}
389
390#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
391
392// ----------------------------------------------------------------------------
393
400bool
402{
404}
405
406// ----------------------------------------------------------------------------
407
416{
418}
419
426void
428{
430}
431
432// ----------------------------------------------------------------------------
433
442{
444}
445
452void
454{
456}
457
458#if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
459
469 {
470 return reinterpret_cast<os_thread_stack_t*> (rtos::interrupts::stack ());
471 }
472
473#endif
474
475// ----------------------------------------------------------------------------
476
485{
486 return (os_thread_t*) &this_thread::thread ();
487}
488
495void
497{
498 return this_thread::suspend ();
499}
500
507void
508os_this_thread_exit (void* exit_ptr)
509{
510 this_thread::exit (exit_ptr);
511}
512
521 os_flags_mode_t mode)
522{
523 return (os_result_t) this_thread::flags_wait (mask, oflags, mode);
524}
525
534 os_flags_mode_t mode)
535{
536 return (os_result_t) this_thread::flags_try_wait (mask, oflags, mode);
537}
538
547 os_clock_duration_t timeout,
548 os_flags_mask_t* oflags, os_flags_mode_t mode)
549{
550 return (os_result_t) this_thread::flags_timed_wait (mask, timeout, oflags,
551 mode);
552}
553
562{
563 return (os_result_t) this_thread::flags_clear (mask, oflags);
564}
565
574{
575 return (os_flags_mask_t) this_thread::flags_get (mask, mode);
576}
577
578// ----------------------------------------------------------------------------
579
586void
588{
589 assert (attr != nullptr);
590 new (attr) thread::attributes ();
591}
592
601void
604 const os_thread_attr_t* attr)
605{
606 assert (thread != nullptr);
607 if (attr == nullptr)
608 {
609 attr = (const os_thread_attr_t*) &thread::initializer;
610 }
611 new (thread) rtos::thread (name, (thread::func_t) func,
612 (thread::func_args_t) args,
613 (const thread::attributes&) *attr);
614}
615
624void
626{
627 assert (thread != nullptr);
628 (reinterpret_cast<rtos::thread&> (*thread)).~thread ();
629}
630
645os_thread_new (const char* name, os_thread_func_t func,
646 const os_thread_func_args_t args, const os_thread_attr_t* attr)
647{
648 if (attr == nullptr)
649 {
650 attr = (const os_thread_attr_t*) &thread::initializer;
651 }
652 return reinterpret_cast<os_thread_t*> (new rtos::thread (
653 name, (thread::func_t) func, (thread::func_args_t) args,
654 (const thread::attributes&) *attr));
655}
656
670void
672{
673 assert (thread != nullptr);
674 delete reinterpret_cast<rtos::thread*> (thread);
675}
676
683bool
685{
686 assert (thread != nullptr);
688 reinterpret_cast<rtos::thread&> (*thread));
689}
690
697const char*
699{
700 assert (thread != nullptr);
701 return (reinterpret_cast<rtos::thread&> (*thread)).name ();
702}
703
712{
713 assert (thread != nullptr);
714 return (os_thread_prio_t) (reinterpret_cast<rtos::thread&> (*thread)).priority ();
715}
716
725{
726 assert (thread != nullptr);
727 return (os_result_t) (reinterpret_cast<rtos::thread&> (*thread)).priority (
728 prio);
729}
730
739{
740 assert (thread != nullptr);
741 return (os_result_t) reinterpret_cast<rtos::thread&> (*thread).kill ();
742}
743
752{
753 assert (thread != nullptr);
754 return (os_result_t) reinterpret_cast<rtos::thread&> (*thread).join (exit_ptr);
755}
756
763void
765{
766 assert (thread != nullptr);
767 return (reinterpret_cast<rtos::thread&> (*thread)).resume ();
768}
769
778 os_flags_mask_t* oflags)
779{
780 assert (thread != nullptr);
781 return (os_result_t) (reinterpret_cast<rtos::thread&> (*thread)).flags_raise (
782 mask, oflags);
783}
784
793{
794 assert (thread != nullptr);
795 return reinterpret_cast<os_thread_state_t> ((reinterpret_cast<rtos::thread&> (*thread)).state ());
796}
797
798#if defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) || defined(__DOXYGEN__)
799
810os_thread_user_storage_t*
812 {
813 assert(thread != nullptr);
814 return (reinterpret_cast<rtos::thread&> (*thread)).user_storage ();
815 }
816
817#endif /* defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) */
818
827{
828 assert (thread != nullptr);
829 return reinterpret_cast<os_thread_stack_t*> (&(reinterpret_cast<rtos::thread&> (*thread)).stack ());
830}
831
832// ----------------------------------------------------------------------------
833
840size_t
842{
844}
845
852size_t
854{
855 return thread::stack::default_size (size_bytes);
856}
857
864size_t
866{
867 return thread::stack::min_size ();
868}
869
876size_t
878{
879 return thread::stack::min_size (size_bytes);
880}
881
890{
891 assert (stack != nullptr);
892 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).bottom ();
893}
894
903{
904 assert (stack != nullptr);
905 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).top ();
906}
907
914size_t
916{
917 assert (stack != nullptr);
918 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).size ();
919}
920
927size_t
929{
930 assert (stack != nullptr);
931 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).available ();
932}
933
940bool
942{
943 assert (stack != nullptr);
944 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).check_bottom_magic ();
945}
946
953bool
955{
956 assert (stack != nullptr);
957 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).check_top_magic ();
958}
959
960// ----------------------------------------------------------------------------
961
962#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
963
972{
973 assert (thread != nullptr);
974 return static_cast<os_statistics_counter_t> ((reinterpret_cast<rtos::thread&> (*thread)).statistics ().context_switches ());
975}
976
977#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
978
979#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
980
989{
990 assert (thread != nullptr);
991 return static_cast<os_statistics_duration_t> ((reinterpret_cast<rtos::thread&> (*thread)).statistics ().cpu_cycles ());
992}
993
994#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
995
996// ----------------------------------------------------------------------------
997
1008{
1009 return reinterpret_cast<os_iterator_t> (scheduler::children_threads (
1010 reinterpret_cast<rtos::thread*> (thread)).begin ().get_iterator_pointer ());
1011}
1012
1026{
1027 return reinterpret_cast<os_iterator_t> (scheduler::children_threads (
1028 reinterpret_cast<rtos::thread*> (thread)).end ().get_iterator_pointer ());
1029}
1030
1040{
1041 // Construct a local iterator object based on the pointer.
1042 thread::threads_list::iterator it
1043 { reinterpret_cast<utils::double_list_links*> (iterator) };
1044 return reinterpret_cast<os_thread_t*> (&(*it));
1045}
1046
1056{
1057 thread::threads_list::iterator it
1058 { reinterpret_cast<utils::double_list_links*> (iterator) };
1059 ++it;
1060
1061 return reinterpret_cast<os_iterator_t> (it.get_iterator_pointer ());
1062}
1063
1064// ----------------------------------------------------------------------------
1065
1072const char*
1074{
1075 assert (clock != nullptr);
1076 return (reinterpret_cast<rtos::clock&> (*clock)).name ();
1077}
1078
1087{
1088 assert (clock != nullptr);
1089 return (os_clock_timestamp_t) (reinterpret_cast<rtos::clock&> (*clock)).now ();
1090}
1091
1100{
1101 assert (clock != nullptr);
1102 return (os_clock_timestamp_t) (reinterpret_cast<rtos::clock&> (*clock)).steady_now ();
1103}
1104
1113{
1114 assert (clock != nullptr);
1115 return (os_result_t) (reinterpret_cast<rtos::clock&> (*clock)).sleep_for (
1116 duration);
1117}
1118
1127{
1128 assert (clock != nullptr);
1129 return (os_result_t) (reinterpret_cast<rtos::clock&> (*clock)).sleep_until (
1130 timestamp);
1131}
1132
1141{
1142 assert (clock != nullptr);
1143 return (os_result_t) (reinterpret_cast<rtos::clock&> (*clock)).wait_for (
1144 timeout);
1145}
1146
1155{
1156 assert (clock != nullptr);
1157 return (os_clock_offset_t) (reinterpret_cast<rtos::clock&> (*clock)).offset ();
1158
1159}
1160
1169{
1170 assert (clock != nullptr);
1171 assert (clock != nullptr);
1172 return (os_clock_offset_t) (reinterpret_cast<rtos::clock&> (*clock)).offset (
1173 (clock::offset_t) offset);
1174
1175}
1176
1185{
1186 return (os_clock_t*) &sysclock;
1187}
1188
1197{
1198 return (os_clock_t*) &rtclock;
1199}
1200
1209{
1210 return (os_clock_t*) &hrclock;
1211}
1212
1213// ----------------------------------------------------------------------------
1214
1223{
1224 return (os_clock_timestamp_t) sysclock.now ();
1225}
1226
1235{
1236 return (os_result_t) sysclock.sleep_for (duration);
1237}
1238
1247{
1248 return (os_result_t) sysclock.sleep_until (timestamp);
1249}
1250
1259{
1260 return (os_result_t) sysclock.wait_for (timeout);
1261}
1262
1263// ----------------------------------------------------------------------------
1264
1271void
1273{
1274 assert (attr != nullptr);
1275 new (attr) timer::attributes ();
1276}
1277
1284void
1286{
1287 assert (attr != nullptr);
1288 new (attr) timer::attributes_periodic ();
1289}
1290
1297const os_timer_attr_t*
1299{
1301}
1302
1311void
1314 const os_timer_attr_t* attr)
1315{
1316 assert (timer != nullptr);
1317 if (attr == nullptr)
1318 {
1320 }
1321 new (timer) rtos::timer (name, (timer::func_t) function,
1322 (timer::func_args_t) args,
1323 (const timer::attributes&) *attr);
1324}
1325
1334void
1336{
1337 assert (timer != nullptr);
1338 (reinterpret_cast<rtos::timer&> (*timer)).~timer ();
1339}
1340
1355os_timer_new (const char* name, os_timer_func_t function,
1356 os_timer_func_args_t args, const os_timer_attr_t* attr)
1357{
1358 if (attr == nullptr)
1359 {
1361 }
1362 return reinterpret_cast<os_timer_t*> (new rtos::timer (
1363 name, (timer::func_t) function, (timer::func_args_t) args,
1364 (const timer::attributes&) *attr));
1365}
1366
1380void
1382{
1383 assert (timer != nullptr);
1384 delete reinterpret_cast<rtos::timer*> (timer);
1385}
1386
1393const char*
1395{
1396 assert (timer != nullptr);
1397 return (reinterpret_cast<rtos::timer&> (*timer)).name ();
1398}
1399
1408{
1409 assert (timer != nullptr);
1410 return (os_result_t) (reinterpret_cast<rtos::timer&> (*timer)).start (period);
1411}
1412
1421{
1422 assert (timer != nullptr);
1423 return (os_result_t) (reinterpret_cast<rtos::timer&> (*timer)).stop ();
1424}
1425
1426// ----------------------------------------------------------------------------
1427
1434void
1436{
1437 assert (attr != nullptr);
1438 new (attr) mutex::attributes ();
1439}
1440
1447void
1449{
1450 assert (attr != nullptr);
1451 new (attr) mutex::attributes_recursive ();
1452}
1453
1460const os_mutex_attr_t*
1462{
1464}
1465
1474void
1476 const os_mutex_attr_t* attr)
1477{
1478 assert (mutex != nullptr);
1479 if (attr == nullptr)
1480 {
1482 }
1483 new (mutex) rtos::mutex (name, (const mutex::attributes&) *attr);
1484}
1485
1494void
1496 const os_mutex_attr_t* attr)
1497{
1498 assert (mutex != nullptr);
1499 if (attr == nullptr)
1500 {
1502 }
1503 new (mutex) rtos::mutex_recursive (name, (const mutex::attributes&) *attr);
1504}
1505
1515void
1517{
1518 assert (mutex != nullptr);
1519 (reinterpret_cast<rtos::mutex&> (*mutex)).~mutex ();
1520}
1521
1536os_mutex_new (const char* name, const os_mutex_attr_t* attr)
1537{
1538 if (attr == nullptr)
1539 {
1541 }
1542 return reinterpret_cast<os_mutex_t*> (new rtos::mutex (
1543 name, (const mutex::attributes&) *attr));
1544}
1545
1560os_mutex_recursive_new (const char* name, const os_mutex_attr_t* attr)
1561{
1562 if (attr == nullptr)
1563 {
1565 }
1566 return reinterpret_cast<os_mutex_t*> (new rtos::mutex_recursive (
1567 name, (const mutex::attributes&) *attr));
1568}
1569
1584void
1586{
1587 assert (mutex != nullptr);
1588 delete reinterpret_cast<rtos::mutex*> (mutex);
1589}
1590
1597const char*
1599{
1600 assert (mutex != nullptr);
1601 return (reinterpret_cast<rtos::mutex&> (*mutex)).name ();
1602}
1603
1612{
1613 assert (mutex != nullptr);
1614 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).lock ();
1615}
1616
1625{
1626 assert (mutex != nullptr);
1627 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).try_lock ();
1628}
1629
1638{
1639 assert (mutex != nullptr);
1640 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).timed_lock (
1641 timeout);
1642}
1643
1652{
1653 assert (mutex != nullptr);
1654 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).unlock ();
1655}
1656
1665{
1666 assert (mutex != nullptr);
1667 return (os_thread_prio_t) (reinterpret_cast<rtos::mutex&> (*mutex)).prio_ceiling ();
1668}
1669
1678 os_thread_prio_t* old_prio_ceiling)
1679{
1680 assert (mutex != nullptr);
1681 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).prio_ceiling (
1682 prio_ceiling, old_prio_ceiling);
1683}
1684
1693{
1694 assert (mutex != nullptr);
1695 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).consistent ();
1696}
1697
1706{
1707 assert (mutex != nullptr);
1708 return (os_thread_t*) (reinterpret_cast<rtos::mutex&> (*mutex)).owner ();
1709}
1710
1719{
1720 assert (mutex != nullptr);
1721 return (reinterpret_cast<rtos::mutex&> (*mutex)).type ();
1722}
1723
1732{
1733 assert (mutex != nullptr);
1734 return (reinterpret_cast<rtos::mutex&> (*mutex)).protocol ();
1735}
1736
1745{
1746 assert (mutex != nullptr);
1747 return (reinterpret_cast<rtos::mutex&> (*mutex)).robustness ();
1748}
1749
1758{
1759 assert (mutex != nullptr);
1760 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).reset ();
1761}
1762
1763// ----------------------------------------------------------------------------
1764
1771void
1773{
1774 assert (attr != nullptr);
1775 new (attr) condition_variable::attributes ();
1776}
1777
1786void
1787os_condvar_construct (os_condvar_t* condvar, const char* name,
1788 const os_condvar_attr_t* attr)
1789{
1790 assert (condvar != nullptr);
1791 if (attr == nullptr)
1792 {
1794 }
1795 new (condvar) condition_variable (name,
1796 (const condition_variable::attributes&) *attr);
1797}
1798
1807void
1809{
1810 assert (condvar != nullptr);
1811 (reinterpret_cast<condition_variable&> (*condvar)).~condition_variable ();
1812}
1813
1828os_condvar_new (const char* name, const os_condvar_attr_t* attr)
1829{
1830 if (attr == nullptr)
1831 {
1833 }
1834 return reinterpret_cast<os_condvar_t*> (new condition_variable (
1835 name, (const condition_variable::attributes&) *attr));
1836}
1837
1851void
1853{
1854 assert (condvar != nullptr);
1855 delete reinterpret_cast<condition_variable*> (condvar);
1856}
1857
1864const char*
1866{
1867 assert (condvar != nullptr);
1868 return (reinterpret_cast<condition_variable&> (*condvar)).name ();
1869}
1870
1879{
1880 assert (condvar != nullptr);
1881 return (os_result_t) (reinterpret_cast<condition_variable&> (*condvar)).signal ();
1882}
1883
1892{
1893 assert (condvar != nullptr);
1894 return (os_result_t) (reinterpret_cast<condition_variable&> (*condvar)).broadcast ();
1895}
1896
1905{
1906 assert (condvar != nullptr);
1907 return (os_result_t) (reinterpret_cast<condition_variable&> (*condvar)).wait (
1908 reinterpret_cast<rtos::mutex&> (*mutex));
1909}
1910
1919 os_clock_duration_t timeout)
1920{
1921 assert (condvar != nullptr);
1922 return (os_result_t) (reinterpret_cast<condition_variable&> (*condvar)).timed_wait (
1923 reinterpret_cast<rtos::mutex&> (*mutex), timeout);
1924}
1925
1926// ----------------------------------------------------------------------------
1927
1934void
1936{
1937 assert (attr != nullptr);
1938 new (attr) semaphore::attributes
1939 { };
1940}
1941
1948void
1950 const os_semaphore_count_t initial_value)
1951{
1952 assert (attr != nullptr);
1954 { initial_value };
1955}
1956
1963void
1965 const os_semaphore_count_t max_value,
1966 const os_semaphore_count_t initial_value)
1967{
1968 assert (attr != nullptr);
1970 { max_value, initial_value };
1971}
1972
1981{
1983}
1984
1993void
1995 const os_semaphore_attr_t* attr)
1996{
1997 assert (semaphore != nullptr);
1998 if (attr == nullptr)
1999 {
2001 }
2003 { name, (const semaphore::attributes&) *attr };
2004}
2005
2014void
2016 const os_semaphore_count_t initial_value)
2017{
2018 assert (semaphore != nullptr);
2020 { name, initial_value };
2021}
2022
2031void
2033 const os_semaphore_count_t max_value,
2034 const os_semaphore_count_t initial_value)
2035{
2036 assert (semaphore != nullptr);
2038 { name, max_value, initial_value };
2039}
2040
2050void
2052{
2053 assert (semaphore != nullptr);
2054 (reinterpret_cast<rtos::semaphore&> (*semaphore)).~semaphore ();
2055}
2056
2071os_semaphore_new (const char* name, const os_semaphore_attr_t* attr)
2072{
2073 if (attr == nullptr)
2074 {
2076 }
2077 return reinterpret_cast<os_semaphore_t*> (new rtos::semaphore
2078 { name, (const semaphore::attributes&) *attr });
2079}
2080
2095os_semaphore_binary_new (const char* name,
2096 const os_semaphore_count_t initial_value)
2097{
2098 return reinterpret_cast<os_semaphore_t*> (new rtos::semaphore_binary
2099 { name, initial_value });
2100}
2101
2117 const os_semaphore_count_t max_value,
2118 const os_semaphore_count_t initial_value)
2119{
2120 return reinterpret_cast<os_semaphore_t*> (new rtos::semaphore_counting
2121 { name, max_value, initial_value });
2122}
2123
2138void
2140{
2141 assert (semaphore != nullptr);
2142 delete reinterpret_cast<rtos::semaphore*> (semaphore);
2143}
2144
2151const char*
2153{
2154 assert (semaphore != nullptr);
2155 return (reinterpret_cast<rtos::semaphore&> (*semaphore)).name ();
2156}
2157
2166{
2167 assert (semaphore != nullptr);
2168 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).post ();
2169}
2170
2179{
2180 assert (semaphore != nullptr);
2181 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).wait ();
2182}
2183
2192{
2193 assert (semaphore != nullptr);
2194 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).try_wait ();
2195}
2196
2205{
2206 assert (semaphore != nullptr);
2207 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).timed_wait (
2208 timeout);
2209}
2210
2219{
2220 assert (semaphore != nullptr);
2221 return (os_semaphore_count_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).value ();
2222}
2223
2232{
2233 assert (semaphore != nullptr);
2234 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).reset ();
2235}
2236
2245{
2246 assert (semaphore != nullptr);
2247 return (os_semaphore_count_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).initial_value ();
2248}
2249
2258{
2259 assert (semaphore != nullptr);
2260 return (os_semaphore_count_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).max_value ();
2261}
2262
2263// ----------------------------------------------------------------------------
2264
2271void
2273{
2274 assert (attr != nullptr);
2275 new (attr) memory_pool::attributes ();
2276}
2277
2286void
2287os_mempool_construct (os_mempool_t* mempool, const char* name, size_t blocks,
2288 size_t block_size_bytes, const os_mempool_attr_t* attr)
2289{
2290 assert (mempool != nullptr);
2291 if (attr == nullptr)
2292 {
2294 }
2295 new (mempool) memory_pool (name, blocks, block_size_bytes,
2296 (const memory_pool::attributes&) *attr);
2297}
2298
2307void
2309{
2310 assert (mempool != nullptr);
2311 (reinterpret_cast<memory_pool&> (*mempool)).~memory_pool ();
2312}
2313
2328os_mempool_new (const char* name, size_t blocks, size_t block_size_bytes,
2329 const os_mempool_attr_t* attr)
2330{
2331 if (attr == nullptr)
2332 {
2334 }
2335 return reinterpret_cast<os_mempool_t*> (new memory_pool (
2336 name, blocks, block_size_bytes, (const memory_pool::attributes&) *attr));
2337}
2338
2352void
2354{
2355 assert (mempool != nullptr);
2356 delete reinterpret_cast<memory_pool*> (mempool);
2357}
2358
2365const char*
2367{
2368 assert (mempool != nullptr);
2369 return (reinterpret_cast<memory_pool&> (*mempool)).name ();
2370}
2371
2378void*
2380{
2381 assert (mempool != nullptr);
2382 return (reinterpret_cast<memory_pool&> (*mempool)).alloc ();
2383}
2384
2391void*
2393{
2394 assert (mempool != nullptr);
2395 return (reinterpret_cast<memory_pool&> (*mempool)).try_alloc ();
2396}
2397
2404void*
2406{
2407 assert (mempool != nullptr);
2408 return (reinterpret_cast<memory_pool&> (*mempool)).timed_alloc (timeout);
2409}
2410
2418os_mempool_free (os_mempool_t* mempool, void* block)
2419{
2420 assert (mempool != nullptr);
2421 return (os_result_t) (reinterpret_cast<memory_pool&> (*mempool)).free (block);
2422}
2423
2430size_t
2432{
2433 assert (mempool != nullptr);
2434 return (reinterpret_cast<memory_pool&> (*mempool)).capacity ();
2435}
2436
2443size_t
2445{
2446 assert (mempool != nullptr);
2447 return (reinterpret_cast<memory_pool&> (*mempool)).count ();
2448}
2449
2456size_t
2458{
2459 assert (mempool != nullptr);
2460 return (reinterpret_cast<memory_pool&> (*mempool)).block_size ();
2461}
2462
2469bool
2471{
2472 assert (mempool != nullptr);
2473 return (reinterpret_cast<memory_pool&> (*mempool)).empty ();
2474}
2475
2482bool
2484{
2485 assert (mempool != nullptr);
2486 return (reinterpret_cast<memory_pool&> (*mempool)).full ();
2487}
2488
2497{
2498 assert (mempool != nullptr);
2499 return (os_result_t) (reinterpret_cast<memory_pool&> (*mempool)).reset ();
2500}
2501
2508void*
2510{
2511 assert (mempool != nullptr);
2512 return (void*) (reinterpret_cast<memory_pool&> (*mempool)).pool ();
2513}
2514
2515// --------------------------------------------------------------------------
2516
2523void
2525{
2526 assert (attr != nullptr);
2527 new (attr) message_queue::attributes ();
2528}
2529
2538void
2539os_mqueue_construct (os_mqueue_t* mqueue, const char* name, size_t msgs,
2540 size_t msg_size_bytes, const os_mqueue_attr_t* attr)
2541{
2542 assert (mqueue != nullptr);
2543 if (attr == nullptr)
2544 {
2546 }
2547 new (mqueue) message_queue (name, msgs, msg_size_bytes,
2548 (const message_queue::attributes&) *attr);
2549}
2550
2559void
2561{
2562 assert (mqueue != nullptr);
2563 (reinterpret_cast<message_queue&> (*mqueue)).~message_queue ();
2564}
2565
2580os_mqueue_new (const char* name, size_t msgs, size_t msg_size_bytes,
2581 const os_mqueue_attr_t* attr)
2582{
2583 if (attr == nullptr)
2584 {
2586 }
2587 return reinterpret_cast<os_mqueue_t*> (new message_queue (
2588 name, msgs, msg_size_bytes, (const message_queue::attributes&) *attr));
2589}
2590
2604void
2606{
2607 assert (mqueue != nullptr);
2608 delete reinterpret_cast<message_queue*> (mqueue);
2609}
2610
2617const char*
2619{
2620 assert (mqueue != nullptr);
2621 return (reinterpret_cast<message_queue&> (*mqueue)).name ();
2622}
2623
2631os_mqueue_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2632 os_mqueue_prio_t mprio)
2633{
2634 assert (mqueue != nullptr);
2635 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).send (
2636 msg, nbytes, mprio);
2637}
2638
2646os_mqueue_try_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2647 os_mqueue_prio_t mprio)
2648{
2649 assert (mqueue != nullptr);
2650 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).try_send (
2651 msg, nbytes, mprio);
2652}
2653
2661os_mqueue_timed_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2663{
2664 assert (mqueue != nullptr);
2665 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).timed_send (
2666 msg, nbytes, timeout, mprio);
2667}
2668
2676os_mqueue_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2677 os_mqueue_prio_t* mprio)
2678{
2679 assert (mqueue != nullptr);
2680 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).receive (
2681 msg, nbytes, mprio);
2682}
2683
2691os_mqueue_try_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2692 os_mqueue_prio_t* mprio)
2693{
2694 assert (mqueue != nullptr);
2695 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).try_receive (
2696 msg, nbytes, mprio);
2697}
2698
2706os_mqueue_timed_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2707 os_clock_duration_t timeout, os_mqueue_prio_t* mprio)
2708{
2709 assert (mqueue != nullptr);
2710 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).timed_receive (
2711 msg, nbytes, timeout, mprio);
2712}
2713
2720size_t
2722{
2723 assert (mqueue != nullptr);
2724 return (reinterpret_cast<message_queue&> (*mqueue)).length ();
2725}
2726
2733size_t
2735{
2736 assert (mqueue != nullptr);
2737 return (reinterpret_cast<message_queue&> (*mqueue)).capacity ();
2738}
2739
2746size_t
2748{
2749 assert (mqueue != nullptr);
2750 return (reinterpret_cast<message_queue&> (*mqueue)).msg_size ();
2751}
2752
2759bool
2761{
2762 assert (mqueue != nullptr);
2763 return (reinterpret_cast<message_queue&> (*mqueue)).empty ();
2764}
2765
2772bool
2774{
2775 assert (mqueue != nullptr);
2776 return (reinterpret_cast<message_queue&> (*mqueue)).full ();
2777}
2778
2787{
2788 assert (mqueue != nullptr);
2789 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).reset ();
2790}
2791
2792// --------------------------------------------------------------------------
2793
2800void
2802{
2803 assert (attr != nullptr);
2804 new (attr) event_flags::attributes ();
2805}
2806
2815void
2816os_evflags_construct (os_evflags_t* evflags, const char* name,
2817 const os_evflags_attr_t* attr)
2818{
2819 assert (evflags != nullptr);
2820 if (attr == nullptr)
2821 {
2823 }
2824 new (evflags) event_flags (name, (const event_flags::attributes&) *attr);
2825}
2826
2835void
2837{
2838 assert (evflags != nullptr);
2839 (reinterpret_cast<event_flags&> (*evflags)).~event_flags ();
2840}
2841
2856os_evflags_new (const char* name, const os_evflags_attr_t* attr)
2857{
2858 if (attr == nullptr)
2859 {
2861 }
2862 return reinterpret_cast<os_evflags_t*> (new event_flags (
2863 name, (const event_flags::attributes&) *attr));
2864}
2865
2879void
2881{
2882 assert (evflags != nullptr);
2883 delete reinterpret_cast<event_flags*> (evflags);
2884}
2885
2892const char*
2894{
2895 assert (evflags != nullptr);
2896 return (reinterpret_cast<event_flags&> (*evflags)).name ();
2897}
2898
2907 os_flags_mask_t* oflags, os_flags_mode_t mode)
2908{
2909 assert (evflags != nullptr);
2910 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).wait (mask,
2911 oflags,
2912 mode);
2913}
2914
2923 os_flags_mask_t* oflags, os_flags_mode_t mode)
2924{
2925 assert (evflags != nullptr);
2926 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).try_wait (
2927 mask, oflags, mode);
2928}
2929
2938 os_clock_duration_t timeout, os_flags_mask_t* oflags,
2939 os_flags_mode_t mode)
2940{
2941 assert (evflags != nullptr);
2942 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).timed_wait (
2943 mask, timeout, oflags, mode);
2944}
2945
2954 os_flags_mask_t* oflags)
2955{
2956 assert (evflags != nullptr);
2957 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).raise (
2958 mask, oflags);
2959}
2960
2969 os_flags_mask_t* oflags)
2970{
2971 assert (evflags != nullptr);
2972 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).clear (
2973 mask, oflags);
2974}
2975
2984 os_flags_mode_t mode)
2985{
2986 assert (evflags != nullptr);
2987 return (os_flags_mask_t) (reinterpret_cast<event_flags&> (*evflags)).get (
2988 mask, mode);
2989}
2990
2997bool
2999{
3000 assert (evflags != nullptr);
3001 return (reinterpret_cast<event_flags&> (*evflags)).waiting ();
3002}
3003
3004// --------------------------------------------------------------------------
3005
3014{
3015 return reinterpret_cast<os_memory_t*> (rtos::memory::get_default_resource ());
3016}
3017
3025void*
3026os_memory_allocate (os_memory_t* memory, size_t bytes, size_t alignment)
3027{
3028 assert (memory != nullptr);
3029 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).allocate (
3030 bytes, alignment);
3031}
3032
3040void
3041os_memory_deallocate (os_memory_t* memory, void* addr, size_t bytes,
3042 size_t alignment)
3043{
3044 assert (memory != nullptr);
3045 (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).deallocate (
3046 addr, bytes, alignment);
3047}
3048
3056void
3058{
3059 assert (memory != nullptr);
3060 (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).reset ();
3061}
3062
3070bool
3072{
3073 assert (memory != nullptr);
3074 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).coalesce ();
3075}
3076
3084size_t
3086{
3087 assert (memory != nullptr);
3088 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).total_bytes ();
3089}
3090
3098size_t
3100{
3101 assert (memory != nullptr);
3102 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).allocated_bytes ();
3103}
3104
3112size_t
3114{
3115 assert (memory != nullptr);
3116 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).free_bytes ();
3117}
3118
3126size_t
3128{
3129 assert (memory != nullptr);
3130 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).allocated_chunks ();
3131}
3132
3140size_t
3142{
3143 assert (memory != nullptr);
3144 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).free_chunks ();
3145}
3146
3147// ****************************************************************************
3148// ***** Legacy CMSIS RTOS implementation *****
3149
3151
3152// ----------------------------------------------------------------------------
3153// ==== Kernel Control Functions ====
3154
3179{
3181 {
3182 return osErrorISR;
3183 }
3184
3186 return osOK;
3187}
3188
3201{
3203 // In µOS++ this does not return.
3204}
3205
3214int32_t
3216{
3217 return scheduler::started () ? 1 : 0;
3218}
3219
3220#if (defined (osFeature_SysTick) && (osFeature_SysTick != 0))
3221
3235uint32_t
3236osKernelSysTick (void)
3237{
3238 // Get the current SysTick timestamp down to cpu cycles.
3239 return static_cast<uint32_t> (hrclock.now ());
3240}
3241
3242#endif // System Timer available
3243
3244// ----------------------------------------------------------------------------
3245// ==== Thread Management ====
3246
3262osThreadCreate (const osThreadDef_t* thread_def, void* args)
3263{
3265 {
3266 return nullptr;
3267 }
3268
3269 if (thread_def == nullptr)
3270 {
3271 return nullptr;
3272 }
3273
3274 thread::attributes attr;
3275 attr.th_priority = thread_def->tpriority;
3276 attr.th_stack_size_bytes = thread_def->stacksize;
3277
3278 // Creating thread with invalid priority should fail (validator requirement).
3279 if (thread_def->tpriority >= osPriorityError)
3280 {
3281 return nullptr;
3282 }
3283
3284 // Find a free slot in the tread definitions array.
3285 for (uint32_t i = 0; i < thread_def->instances; ++i)
3286 {
3287 thread* th = (thread*) &thread_def->data[i];
3288 if (th->state () == thread::state::undefined
3289 || th->state () == thread::state::destroyed)
3290 {
3291 if (attr.th_stack_size_bytes > 0)
3292 {
3293 attr.th_stack_address = &thread_def->stack[(i)
3294 * ((thread_def->stacksize + sizeof(uint64_t) - 1)
3295 / sizeof(uint64_t))];
3296 }
3297#pragma GCC diagnostic push
3298#pragma GCC diagnostic ignored "-Wcast-function-type"
3299 new (th) thread (thread_def->name,
3300 reinterpret_cast<thread::func_t> (thread_def->pthread), args, attr);
3301#pragma GCC diagnostic pop
3302
3303 // No need to yield here, already done by constructor.
3304 return reinterpret_cast<osThreadId> (th);
3305 }
3306 }
3307 return nullptr;
3308}
3309
3318{
3320 {
3321 return nullptr;
3322 }
3323
3324 return reinterpret_cast<osThreadId> (&this_thread::thread ());
3325}
3326
3340{
3342 {
3343 return osErrorISR;
3344 }
3345
3346 if (thread_id == nullptr)
3347 {
3348 return osErrorParameter;
3349 }
3350
3351 thread::state_t state =
3352 (reinterpret_cast<rtos::thread&> (*thread_id)).state ();
3353 if (state == thread::state::undefined)
3354 {
3355 return osErrorResource;
3356 }
3357
3358 if ((reinterpret_cast<thread*> (thread_id)) == &this_thread::thread ())
3359 {
3360 this_thread::exit ();
3361 /* NOTREACHED */
3362 }
3363 else
3364 {
3365 (reinterpret_cast<rtos::thread&> (*thread_id)).kill ();
3366 }
3367
3368 return osOK;
3369}
3370
3381{
3383 {
3384 return osErrorISR;
3385 }
3386
3388
3389 return osOK;
3390}
3391
3402{
3404 {
3405 return osErrorISR;
3406 }
3407
3408 if (thread_id == nullptr)
3409 {
3410 return osErrorParameter;
3411 }
3412
3413 thread::state_t state =
3414 (reinterpret_cast<rtos::thread&> (*thread_id)).state ();
3415 if (state == thread::state::undefined || state >= thread::state::destroyed)
3416 {
3417 return osErrorResource;
3418 }
3419
3420 if (priority < osPriorityIdle || priority >= osPriorityError)
3421 {
3422 return osErrorValue;
3423 }
3424
3425 // Call C++ mutator.
3426 thread::priority_t prio = static_cast<thread::priority_t> (priority);
3427 result_t res =
3428 ((reinterpret_cast<rtos::thread&> (*thread_id)).priority (prio));
3429
3430 // A mandatory yield is needed here, must be done
3431 // by the implementation.
3432
3433 if (res == result::ok)
3434 {
3435 return osOK;
3436 }
3437 else if (res == EINVAL)
3438 {
3439 return osErrorValue;
3440 }
3441 else
3442 {
3443 return osErrorOS;
3444 }
3445}
3446
3456{
3458 {
3459 return osPriorityError;
3460 }
3461
3462 if (thread_id == nullptr)
3463 {
3464 return osPriorityError;
3465 }
3466
3467 // Call C++ accessor.
3468 thread::priority_t prio =
3469 (reinterpret_cast<rtos::thread&> (*thread_id)).priority ();
3470 return static_cast<osPriority> (prio);
3471}
3472
3473// ----------------------------------------------------------------------------
3474// ==== Generic Wait Functions ====
3475
3490osDelay (uint32_t millisec)
3491{
3493 {
3494 return osErrorISR;
3495 }
3496
3498 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
3499
3500 if (res == ETIMEDOUT)
3501 {
3502 return osEventTimeout;
3503 }
3504 else
3505 {
3506 return osErrorOS;
3507 }
3508}
3509
3510#if (defined (osFeature_Wait) && (osFeature_Wait != 0))
3511
3512#pragma GCC diagnostic push
3513#pragma GCC diagnostic ignored "-Waggregate-return"
3514
3532osEvent
3533osWait (uint32_t millisec)
3534{
3535 osEvent event;
3536
3538 {
3539 event.status = osErrorISR;
3540 return event;
3541 }
3542
3543 result_t res = sysclock.wait_for (
3544 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
3545
3546 // TODO: return events
3547 if (res == ETIMEDOUT)
3548 {
3549 event.status = osEventTimeout;
3550 }
3551 else
3552 {
3553 event.status = osErrorOS;
3554 }
3555
3556 return event;
3557}
3558
3559#pragma GCC diagnostic pop
3560
3561#endif // Generic Wait available
3562
3563// ----------------------------------------------------------------------------
3564// ==== Timer Management Functions ====
3565
3575osTimerCreate (const osTimerDef_t* timer_def, os_timer_type type, void* args)
3576{
3578 {
3579 return nullptr;
3580 }
3581
3582 if (timer_def == nullptr)
3583 {
3584 return nullptr;
3585 }
3586
3587 timer::attributes attr;
3588 attr.tm_type = (timer::type_t) type;
3589
3590 new ((void*) timer_def->data) timer (timer_def->name,
3591 (timer::func_t) timer_def->ptimer,
3592 (timer::func_args_t) args, attr);
3593
3594 return reinterpret_cast<osTimerId> (timer_def->data);
3595}
3596
3604osTimerStart (osTimerId timer_id, uint32_t millisec)
3605{
3607 {
3608 return osErrorISR;
3609 }
3610
3611 if (timer_id == nullptr)
3612 {
3613 return osErrorParameter;
3614 }
3615
3616 result_t res = (reinterpret_cast<rtos::timer&> (*timer_id)).start (
3617 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
3618
3619 if (res == result::ok)
3620 {
3621 return osOK;
3622 }
3623 else
3624 {
3625 return osErrorOS;
3626 }
3627}
3628
3634{
3636 {
3637 return osErrorISR;
3638 }
3639
3640 if (timer_id == nullptr)
3641 {
3642 return osErrorParameter;
3643 }
3644
3645 result_t res = (reinterpret_cast<rtos::timer&> (*timer_id)).stop ();
3646 if (res == result::ok)
3647 {
3648 return osOK;
3649 }
3650 else if (res == EAGAIN)
3651 {
3652 return osErrorResource;
3653 }
3654 else
3655 {
3656 return osErrorOS;
3657 }
3658}
3659
3668{
3670 {
3671 return osErrorISR;
3672 }
3673
3674 if (timer_id == nullptr)
3675 {
3676 return osErrorParameter;
3677 }
3678
3679 (reinterpret_cast<rtos::timer&> (*timer_id)).~timer ();
3680 return osOK;
3681}
3682
3683// ----------------------------------------------------------------------------
3684// ==== Signal Management ====
3685
3692int32_t
3693osSignalSet (osThreadId thread_id, int32_t signals)
3694{
3695 if (thread_id == nullptr)
3696 {
3697 return (int32_t) 0x80000000;
3698 }
3699
3700 if (signals == (int32_t) 0x80000000)
3701 {
3702 return (int32_t) 0x80000000;
3703 }
3704
3705 flags::mask_t osig;
3706 ((thread*) (thread_id))->flags_raise ((flags::mask_t) signals, &osig);
3707 return (int32_t) osig;
3708}
3709
3716int32_t
3717osSignalClear (osThreadId thread_id, int32_t signals)
3718{
3719 if (thread_id == nullptr)
3720 {
3721 return (int32_t) 0x80000000;
3722 }
3723
3724 if (interrupts::in_handler_mode () || (signals == 0))
3725 {
3726 return (int32_t) 0x80000000;
3727 }
3728
3729 flags::mask_t sig;
3730
3731#if defined(OS_INCLUDE_RTOS_THREAD_PUBLIC_FLAGS_CLEAR)
3732 ((thread*) (thread_id))->flags_clear ((flags::mask_t) signals, &sig);
3733#else
3734 assert(((thread* ) (thread_id)) == &this_thread::thread ());
3735 // IGNORE THREAD ID!
3736 this_thread::flags_clear ((flags::mask_t) signals, &sig);
3737#endif
3738 return (int32_t) sig;
3739}
3740
3741#pragma GCC diagnostic push
3742#pragma GCC diagnostic ignored "-Waggregate-return"
3743
3766osEvent
3767osSignalWait (int32_t signals, uint32_t millisec)
3768{
3769 osEvent event;
3770
3772 {
3773 event.status = osErrorISR;
3774 return event;
3775 }
3776
3777 if ((uint32_t) signals & 0x80000000)
3778 {
3779 event.status = osErrorValue;
3780 return event;
3781 }
3782
3783 result_t res;
3784 if (millisec == osWaitForever)
3785 {
3786 res = this_thread::flags_wait ((flags::mask_t) signals,
3787 (flags::mask_t*) &event.value.signals);
3788 }
3789 else if (millisec == 0)
3790 {
3791 res = this_thread::flags_try_wait ((flags::mask_t) signals,
3792 (flags::mask_t*) &event.value.signals);
3793 }
3794 else
3795 {
3796 res = this_thread::flags_timed_wait (
3797 (flags::mask_t) signals,
3798 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)),
3799 (flags::mask_t*) &event.value.signals);
3800 }
3801
3802 if (res == result::ok)
3803 {
3804 event.status = osEventSignal;
3805 }
3806 else if (res == EWOULDBLOCK)
3807 {
3808 event.status = osOK; // Only for try_flags_wait().
3809 }
3810 else if (res == ETIMEDOUT)
3811 {
3812 event.status = osEventTimeout; // Only for timed_flags_wait().
3813 }
3814 else if (res == EPERM)
3815 {
3816 event.status = osErrorISR;
3817 }
3818 else if (res == EINVAL)
3819 {
3820 event.status = osErrorValue;
3821 }
3822 else
3823 {
3824 event.status = osErrorOS;
3825 }
3826
3827 return event;
3828}
3829
3830#pragma GCC diagnostic pop
3831
3832// ----------------------------------------------------------------------------
3833
3834// ==== Mutex Management ====
3835
3843osMutexCreate (const osMutexDef_t* mutex_def)
3844{
3846 {
3847 return nullptr;
3848 }
3849
3850 if (mutex_def == nullptr)
3851 {
3852 return nullptr;
3853 }
3854
3855 mutex::attributes attr;
3858
3859 new ((void*) mutex_def->data) mutex (mutex_def->name, attr);
3860
3861 return reinterpret_cast<osMutexId> (mutex_def->data);
3862}
3863
3883osMutexWait (osMutexId mutex_id, uint32_t millisec)
3884{
3886 {
3887 return osErrorISR;
3888 }
3889
3890 if (mutex_id == nullptr)
3891 {
3892 return osErrorParameter;
3893 }
3894
3895 result_t ret;
3896 if (millisec == osWaitForever)
3897 {
3898 ret = (reinterpret_cast<rtos::mutex&> (*mutex_id)).lock ();
3899 // osErrorResource:
3900 }
3901 else if (millisec == 0)
3902 {
3903 ret = (reinterpret_cast<rtos::mutex&> (*mutex_id)).try_lock ();
3904 }
3905 else
3906 {
3907 ret = (reinterpret_cast<rtos::mutex&> (*mutex_id)).timed_lock (
3908 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
3909 // osErrorTimeoutResource:
3910 }
3911
3912 if (ret == result::ok)
3913 {
3914 // osOK: the mutex has been obtained.
3915 return osOK;
3916 }
3917 else if (ret == EWOULDBLOCK)
3918 {
3919 // The mutex could not be obtained when no timeout was specified.
3920 // Only for try_lock().
3921 return osErrorResource;
3922 }
3923 else if (ret == ENOTRECOVERABLE)
3924 {
3925 // The mutex could not be obtained when no timeout was specified.
3926 // Only for lock().
3927 return osErrorResource;
3928 }
3929 else if (ret == ETIMEDOUT)
3930 {
3931 // The mutex could not be obtained in the given time.
3932 // Only for timed_lock().
3934 }
3935 else
3936 {
3937 return osErrorOS;
3938 }
3939
3940 /* NOTREACHED */
3941}
3942
3953{
3955 {
3956 return osErrorISR;
3957 }
3958
3959 if (mutex_id == nullptr)
3960 {
3961 return osErrorParameter;
3962 }
3963
3964 result_t res;
3965 res = (reinterpret_cast<rtos::mutex&> (*mutex_id)).unlock ();
3966
3967 if (res == result::ok)
3968 {
3969 return osOK;
3970 }
3971 else if ((res == EPERM) || (res == ENOTRECOVERABLE))
3972 {
3973 return osErrorResource;
3974 }
3975 else
3976 {
3977 return osErrorOS;
3978 }
3979}
3980
3992{
3994 {
3995 return osErrorISR;
3996 }
3997
3998 if (mutex_id == nullptr)
3999 {
4000 return osErrorParameter;
4001 }
4002
4003 (reinterpret_cast<rtos::mutex&> (*mutex_id)).~mutex ();
4004 return osOK;
4005}
4006
4007// ----------------------------------------------------------------------------
4008
4009// ==== Semaphore Management Functions ====
4010
4011#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0))
4012
4023osSemaphoreCreate (const osSemaphoreDef_t* semaphore_def, int32_t count)
4024{
4026 {
4027 return nullptr;
4028 }
4029
4030 if (semaphore_def == nullptr)
4031 {
4032 return nullptr;
4033 }
4034
4036 attr.sm_initial_value = (semaphore::count_t) count;
4037 // The logic is very strange, the CMSIS expects both the max-count to be the
4038 // same as count, and also to accept a count of 0, which leads to
4039 // useless semaphores. We patch this behaviour in the wrapper, the main
4040 // object uses a more realistic max_value.
4042 count == 0 ? osFeature_Semaphore : count);
4043
4044 new ((void*) semaphore_def->data) semaphore (semaphore_def->name, attr);
4045
4046 return reinterpret_cast<osSemaphoreId> (semaphore_def->data);
4047}
4048
4071int32_t
4072osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec)
4073{
4075 {
4076 return -1;
4077 }
4078
4079 if (semaphore_id == nullptr)
4080 {
4081 return -1;
4082 }
4083
4084 result_t res;
4085 if (millisec == osWaitForever)
4086 {
4087 res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).wait ();
4088 }
4089 else if (millisec == 0)
4090 {
4091 res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).try_wait ();
4092 if (res == EWOULDBLOCK)
4093 {
4094 return 0;
4095 }
4096 }
4097 else
4098 {
4099 res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).timed_wait (
4100 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
4101 if (res == ETIMEDOUT)
4102 {
4103 return 0;
4104 }
4105 }
4106
4107 if (res == 0)
4108 {
4109 int count =
4110 (int32_t) (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).value ();
4111 return count + 1;
4112 }
4113 else
4114 {
4115 return -1;
4116 }
4117}
4118
4127osSemaphoreRelease (osSemaphoreId semaphore_id)
4128{
4129 if (semaphore_id == nullptr)
4130 {
4131 return osErrorParameter;
4132 }
4133
4134 if ((reinterpret_cast<rtos::semaphore&> (*semaphore_id)).initial_value ()
4135 == 0)
4136 {
4137 return osErrorResource;
4138 }
4139
4140 result_t res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).post ();
4141
4142 if (res == result::ok)
4143 {
4144 return osOK;
4145 }
4146 else if (res == EAGAIN)
4147 {
4148 return osErrorResource;
4149 }
4150 else
4151 {
4152 return osErrorOS;
4153 }
4154}
4155
4166osSemaphoreDelete (osSemaphoreId semaphore_id)
4167{
4169 {
4170 return osErrorISR;
4171 }
4172
4173 if (semaphore_id == nullptr)
4174 {
4175 return osErrorParameter;
4176 }
4177
4178 (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).~semaphore ();
4179 return osOK;
4180}
4181
4182#endif /* Semaphore available */
4183
4184// ----------------------------------------------------------------------------
4185// ==== Memory Pool Management Functions ====
4186
4187#if (defined (osFeature_Pool) && (osFeature_Pool != 0))
4188
4196osPoolCreate (const osPoolDef_t* pool_def)
4197{
4199 {
4200 return nullptr;
4201 }
4202
4203 if (pool_def == nullptr)
4204 {
4205 return nullptr;
4206 }
4207
4209 attr.mp_pool_address = pool_def->pool;
4210 attr.mp_pool_size_bytes = pool_def->pool_sz;
4211
4212 new ((void*) pool_def->data) memory_pool (pool_def->name,
4213 (std::size_t) pool_def->items,
4214 (std::size_t) pool_def->item_sz,
4215 attr);
4216
4217 return reinterpret_cast<osPoolId> (pool_def->data);
4218}
4219
4226void*
4227osPoolAlloc (osPoolId pool_id)
4228{
4229 if (pool_id == nullptr)
4230 {
4231 return nullptr;
4232 }
4233
4234 return (reinterpret_cast<memory_pool&> (*pool_id)).try_alloc ();
4235}
4236
4243void*
4244osPoolCAlloc (osPoolId pool_id)
4245{
4246 if (pool_id == nullptr)
4247 {
4248 return nullptr;
4249 }
4250
4251 void* ret;
4252 ret = (reinterpret_cast<memory_pool&> (*pool_id)).try_alloc ();
4253 if (ret != nullptr)
4254 {
4255 memset (ret, 0,
4256 (reinterpret_cast<memory_pool&> (*pool_id)).block_size ());
4257 }
4258
4259 return ret;
4260}
4261
4269osPoolFree (osPoolId pool_id, void* block)
4270{
4271 if (pool_id == nullptr)
4272 {
4273 return osErrorParameter;
4274 }
4275
4276 if (block == nullptr)
4277 {
4278 return osErrorParameter;
4279 }
4280
4281 result_t res;
4282 res = (reinterpret_cast<memory_pool&> (*pool_id)).free (block);
4283
4284 if (res == result::ok)
4285 {
4286 return osOK;
4287 }
4288 else if (res == EINVAL)
4289 {
4290 return osErrorValue;
4291 }
4292 else
4293 {
4294 return osErrorOS;
4295 }
4296}
4297
4298#endif /* Memory Pool Management available */
4299
4300// ----------------------------------------------------------------------------
4301// ==== Message Queue Management Functions ====
4302
4303#if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0))
4304
4312osMessageCreate (const osMessageQDef_t* queue_def,
4313 osThreadId thread_id __attribute__((unused)))
4314{
4316 {
4317 return nullptr;
4318 }
4319
4320 if (queue_def == nullptr)
4321 {
4322 return nullptr;
4323 }
4324
4326 attr.mq_queue_address = queue_def->queue;
4327 attr.mq_queue_size_bytes = queue_def->queue_sz;
4328
4329 new ((void*) queue_def->data) message_queue (queue_def->name,
4330 (std::size_t) queue_def->items,
4331 (std::size_t) queue_def->item_sz,
4332 attr);
4333
4334 return reinterpret_cast<osMessageQId> (queue_def->data);
4335}
4336
4354osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec)
4355{
4356#pragma GCC diagnostic push
4357#if defined ( __clang__ )
4358#pragma clang diagnostic ignored "-Wint-to-pointer-cast"
4359#endif
4360
4361 if (queue_id == nullptr)
4362 {
4363 return osErrorParameter;
4364 }
4365
4366 result_t res;
4367 if (millisec == osWaitForever)
4368 {
4370 {
4371 return osErrorParameter;
4372 }
4373 res = (reinterpret_cast<message_queue&> (*queue_id)).send (
4374 (const char*) &info, sizeof(uint32_t), 0);
4375 // osOK, osErrorResource, osErrorParameter
4376 }
4377 else if (millisec == 0)
4378 {
4379 res = (reinterpret_cast<message_queue&> (*queue_id)).try_send (
4380 (const char*) &info, sizeof(uint32_t), 0);
4381 // osOK, osErrorResource, osErrorParameter
4382 }
4383 else
4384 {
4386 {
4387 return osErrorParameter;
4388 }
4389 res = (reinterpret_cast<message_queue&> (*queue_id)).timed_send (
4390 (const char*) &info, sizeof(uint32_t),
4391 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)), 0);
4392 // osOK, osErrorTimeoutResource, osErrorParameter
4393 }
4394
4395 if (res == result::ok)
4396 {
4397 // The message was put into the queue.
4398 return osOK;
4399 }
4400 else if (res == EWOULDBLOCK)
4401 {
4402 // No memory in the queue was available
4403 return osErrorResource;
4404 }
4405 else if (res == ETIMEDOUT)
4406 {
4407 // No memory in the queue was available during the given time limit.
4409 }
4410 else if (res == EINVAL || res == EMSGSIZE)
4411 {
4412 // A parameter is invalid or outside of a permitted range.
4413 return osErrorParameter;
4414 }
4415 else
4416 {
4417 return osErrorOS;
4418 }
4419
4420#pragma GCC diagnostic pop
4421}
4422
4423#pragma GCC diagnostic push
4424#pragma GCC diagnostic ignored "-Waggregate-return"
4425
4444osEvent
4445osMessageGet (osMessageQId queue_id, uint32_t millisec)
4446{
4447 osEvent event;
4448 result_t res;
4449
4450 if (queue_id == nullptr)
4451 {
4452 event.status = osErrorParameter;
4453 return event;
4454 }
4455
4456 if (millisec == osWaitForever)
4457 {
4459 {
4460 event.status = osErrorParameter;
4461 return event;
4462 }
4463 res = (reinterpret_cast<message_queue&> (*queue_id)).receive (
4464 (char*) &event.value.v, sizeof(uint32_t), nullptr);
4465 // result::event_message;
4466 }
4467 else if (millisec == 0)
4468 {
4469 res = (reinterpret_cast<message_queue&> (*queue_id)).try_receive (
4470 (char*) &event.value.v, sizeof(uint32_t), nullptr);
4471 // result::event_message when message;
4472 // result::ok when no meessage
4473 }
4474 else
4475 {
4477 {
4478 event.status = osErrorParameter;
4479 return event;
4480 }
4481 res = (reinterpret_cast<message_queue&> (*queue_id)).timed_receive (
4482 (char*) &event.value.v, sizeof(uint32_t),
4483 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)), nullptr);
4484 // result::event_message when message;
4485 // result::event_timeout when timeout;
4486 }
4487
4488 if (res == result::ok)
4489 {
4490 // Message received, value.p contains the pointer to message.
4491 event.status = osEventMessage;
4492 }
4493 else if (res == ETIMEDOUT)
4494 {
4495 // No message has arrived during the given timeout period.
4496 event.status = osEventTimeout;
4497 }
4498 else if (res == EINVAL || res == EMSGSIZE)
4499 {
4500 // A parameter is invalid or outside of a permitted range.
4501 event.status = osErrorParameter;
4502 }
4503 else if (res == EWOULDBLOCK)
4504 {
4505 // No message is available in the queue and no timeout was specified.
4506 event.status = osOK;
4507 }
4508 else
4509 {
4510 event.status = osErrorOS;
4511 }
4512
4513 return event;
4514}
4515
4516#pragma GCC diagnostic pop
4517
4518#endif /* Message Queues available */
4519
4520// ----------------------------------------------------------------------------
4521// ==== Mail Queue Management Functions ====
4522
4523#if (defined (osFeature_MailQ) && (osFeature_MailQ != 0))
4524
4532osMailCreate (const osMailQDef_t* mail_def,
4533 osThreadId thread_id __attribute__((unused)))
4534{
4536 {
4537 return nullptr;
4538 }
4539
4540 if (mail_def == nullptr)
4541 {
4542 return nullptr;
4543 }
4544
4545 memory_pool::attributes pool_attr;
4546 pool_attr.mp_pool_address = mail_def->pool;
4547 pool_attr.mp_pool_size_bytes = mail_def->pool_sz;
4548 new ((void*) &mail_def->data->pool) memory_pool (
4549 mail_def->name, (std::size_t) mail_def->items,
4550 (std::size_t) mail_def->pool_item_sz, pool_attr);
4551
4552 message_queue::attributes queue_attr;
4553 queue_attr.mq_queue_address = mail_def->queue;
4554 queue_attr.mq_queue_size_bytes = mail_def->queue_sz;
4555 new ((void*) &mail_def->data->queue) message_queue (
4556 mail_def->name, (std::size_t) mail_def->items,
4557 (std::size_t) mail_def->queue_item_sz, queue_attr);
4558
4559 return (osMailQId) (mail_def->data);
4560}
4561
4585void*
4586osMailAlloc (osMailQId mail_id, uint32_t millisec)
4587{
4588 if (mail_id == nullptr)
4589 {
4590 return nullptr;
4591 }
4592
4593 void* ret = nullptr;
4594
4595#pragma GCC diagnostic push
4596#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4597 if (millisec == osWaitForever)
4598 {
4600 {
4601 return nullptr;
4602 }
4603 ret = (reinterpret_cast<memory_pool&> (mail_id->pool)).alloc ();
4604 }
4605 else if (millisec == 0)
4606 {
4607 ret = (reinterpret_cast<memory_pool&> (mail_id->pool)).try_alloc ();
4608 }
4609 else
4610 {
4612 {
4613 return nullptr;
4614 }
4615 ret = (reinterpret_cast<memory_pool&> (mail_id->pool)).timed_alloc (
4616 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
4617 }
4618#pragma GCC diagnostic pop
4619 return ret;
4620}
4621
4645void*
4646osMailCAlloc (osMailQId mail_id, uint32_t millisec)
4647{
4648 void* ret = osMailAlloc (mail_id, millisec);
4649 if (ret != nullptr)
4650 {
4651#pragma GCC diagnostic push
4652#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4653 memset (ret, 0,
4654 (reinterpret_cast<memory_pool&> (mail_id->pool)).block_size ());
4655#pragma GCC diagnostic pop
4656 }
4657 return ret;
4658}
4659
4668osMailPut (osMailQId mail_id, void* mail)
4669{
4670 if (mail_id == nullptr)
4671 {
4672 return osErrorParameter;
4673 }
4674 if (mail == nullptr)
4675 {
4676 return osErrorValue;
4677 }
4678
4679 // Validate pointer.
4680 memory_pool* pool = reinterpret_cast<memory_pool*> (&mail_id->pool);
4681 if (((char*) mail < (char*) (pool->pool ()))
4682 || (((char*) mail)
4683 >= ((char*) (pool->pool ()) + pool->capacity () * pool->block_size ())))
4684 {
4685 return osErrorValue;
4686 }
4687
4688 result_t res;
4689#pragma GCC diagnostic push
4690#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4691 res = (reinterpret_cast<message_queue&> (mail_id->queue)).try_send (
4692 (const char*) &mail, sizeof(void*), 0);
4693#pragma GCC diagnostic pop
4694 if (res == result::ok)
4695 {
4696 return osOK;
4697 }
4698 else
4699 {
4700 return osErrorOS;
4701 }
4702}
4703
4704#pragma GCC diagnostic push
4705#pragma GCC diagnostic ignored "-Waggregate-return"
4706#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4707
4726osEvent
4727osMailGet (osMailQId mail_id, uint32_t millisec)
4728{
4729 osEvent event;
4730 result_t res;
4731
4732 if (mail_id == nullptr)
4733 {
4734 event.status = osErrorParameter;
4735 return event;
4736 }
4737
4738 if (millisec == osWaitForever)
4739 {
4741 {
4742 event.status = osErrorParameter;
4743 return event;
4744 }
4745 res = (reinterpret_cast<message_queue&> ((mail_id->queue))).receive (
4746 (char*) &event.value.p, sizeof(void*), nullptr);
4747 // osEventMail for ok,
4748 }
4749 else if (millisec == 0)
4750 {
4751 res = (reinterpret_cast<message_queue&> (mail_id->queue)).try_receive (
4752 (char*) &event.value.p, sizeof(void*), nullptr);
4753 // osEventMail for ok,
4754 }
4755 else
4756 {
4758 {
4759 event.status = osErrorParameter;
4760 return event;
4761 }
4762 res = (reinterpret_cast<message_queue&> (mail_id->queue)).timed_receive (
4763 (char*) &event.value.p, sizeof(void*),
4764 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)), nullptr);
4765 // osEventMail for ok, osEventTimeout
4766 }
4767
4768 if (res == result::ok)
4769 {
4770 // Mail received, value.p contains the pointer to mail content.
4771 event.status = osEventMail;
4772 }
4773 else if (res == EWOULDBLOCK)
4774 {
4775 // No mail is available in the queue and no timeout was specified.
4776 event.status = osOK;
4777 }
4778 else if (res == EINVAL || res == EMSGSIZE)
4779 {
4780 // A parameter is invalid or outside of a permitted range.
4781 event.status = osErrorParameter;
4782 }
4783 else if (res == ETIMEDOUT)
4784 {
4785 // No mail has arrived during the given timeout period.
4786 event.status = osEventTimeout;
4787 }
4788 else
4789 {
4790 event.status = osErrorOS;
4791 }
4792
4793 return event;
4794}
4795
4796#pragma GCC diagnostic pop
4797
4805osMailFree (osMailQId mail_id, void* mail)
4806{
4807 if (mail_id == nullptr)
4808 {
4809 return osErrorParameter;
4810 }
4811 if (mail == nullptr)
4812 {
4813 return osErrorValue;
4814 }
4815
4816 return osPoolFree (&(mail_id->pool), mail);
4817}
4818
4819#endif /* Mail Queues available */
4820
4821// ----------------------------------------------------------------------------
4822
4823#pragma GCC diagnostic pop
4824
4825// ----------------------------------------------------------------------------
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:66
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:73
POSIX compliant condition variable.
Definition os-condvar.h:62
Event flags attributes.
Definition os-evflags.h:77
Synchronised event flags.
Definition os-evflags.h:66
Double linked list node, with time stamp and timer.
Definition os-lists.h:316
static void exit(state_t state)
Exit the interrupts critical section.
Definition os-sched.h:1177
static state_t enter(void)
Enter an interrupts critical section.
Definition os-sched.h:1167
static state_t enter(void)
Enter interrupts uncritical section.
Definition os-sched.h:1210
static void exit(state_t state)
Exit interrupts uncritical section.
Definition os-sched.h:1220
Memory resource manager (abstract class).
Definition os-memory.h:165
Memory pool attributes.
Definition os-mempool.h:101
void * mp_pool_address
Address of the user defined storage for the memory pool.
Definition os-mempool.h:146
std::size_t mp_pool_size_bytes
Size of the user defined storage for the memory pool.
Definition os-mempool.h:151
Synchronised memory pool, using the default RTOS allocator.
Definition os-mempool.h:70
std::size_t block_size(void) const
Get block size.
Definition os-mempool.h:926
std::size_t capacity(void) const
Get memory pool capacity.
Definition os-mempool.h:917
void * pool(void)
Get the pool storage address.
Definition os-mempool.h:962
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:199
std::size_t mq_queue_size_bytes
Size of the user defined storage for the message queue.
Definition os-mqueue.h:204
POSIX compliant message queue, using the default RTOS allocator.
Definition os-mqueue.h:70
Recursive mutex attributes.
Definition os-mutex.h:323
Mutex attributes.
Definition os-mutex.h:219
type_t mx_type
Attribute with the mutex type.
Definition os-mutex.h:294
protocol_t mx_protocol
Attribute with the mutex protocol.
Definition os-mutex.h:284
POSIX compliant recursive mutex.
Definition os-mutex.h:727
POSIX compliant mutex.
Definition os-mutex.h:65
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:791
std::size_t th_stack_size_bytes
Size of the user defined storage for the thread stack, in bytes.
Definition os-thread.h:851
priority_t th_priority
Thread initial priority.
Definition os-thread.h:862
void * th_stack_address
Address of the user defined storage for the thread stack.
Definition os-thread.h:838
static std::size_t default_size(void)
Get the default stack size.
Definition os-thread.h:2209
static std::size_t min_size(void)
Get the min stack size.
Definition os-thread.h:2189
Thread statistics.
Definition os-thread.h:883
POSIX compliant thread, using the default RTOS allocator.
Definition os-thread.h:247
result_t kill(void)
Force thread termination.
uint8_t state_t
Type of variables holding thread states.
Definition os-thread.h:353
void *(*)(func_args_t args) func_t
Type of thread function.
Definition os-thread.h:417
result_t join(void **exit_ptr=nullptr)
Wait for thread termination.
_func_args_t func_args_t
Type of thread function arguments.
Definition os-thread.h:409
static bool is_constructed(const thread &thread)
Check if the thread is constructed.
Periodic timer attributes.
Definition os-timer.h:224
Timer attributes.
Definition os-timer.h:143
type_t tm_type
Timer type attribute.
Definition os-timer.h:203
User single-shot or periodic timer.
Definition os-timer.h:65
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
maximum count for osSemaphoreCreate function
Definition cmsis_os.h:117
void * osMailAlloc(osMailQId mail_id, uint32_t millisec)
Allocate a memory block from a mail.
osPriority
Definition cmsis_os.h:137
@ osPriorityError
system cannot determine priority or thread has illegal priority
Definition cmsis_os.h:145
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:152
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:182
osStatus
Status code values returned by CMSIS-RTOS functions.
Definition cmsis_os.h:159
@ osEventMail
function completed; mail event occurred.
Definition cmsis_os.h:163
@ osErrorISR
not allowed in ISR context: the function cannot be called from interrupt service routines.
Definition cmsis_os.h:168
@ osErrorTimeoutResource
resource not available within given time: a specified resource was not available within the timeout p...
Definition cmsis_os.h:167
@ osErrorValue
value of a parameter is out of range.
Definition cmsis_os.h:172
@ osEventSignal
function completed; signal event occurred.
Definition cmsis_os.h:161
@ osErrorOS
unspecified RTOS error: run-time error but no other error message fits.
Definition cmsis_os.h:173
@ osEventTimeout
function completed; timeout occurred.
Definition cmsis_os.h:164
@ osErrorResource
resource not available: a specified resource was not available.
Definition cmsis_os.h:166
@ osOK
function completed; no error or event occurred.
Definition cmsis_os.h:160
@ osErrorParameter
parameter error: a mandatory parameter was missing or specified an incorrect object.
Definition cmsis_os.h:165
@ osEventMessage
function completed; message event occurred.
Definition cmsis_os.h:162
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:134
uint64_t os_statistics_counter_t
Type of variables holding context switches counters.
Definition os-c-decls.h:245
os_thread_stack_t * os_irq_get_stack(void)
Get the interrupts stack.
os_sched_state_t os_sched_unlock(void)
Unlock the scheduler.
os_sched_state_t os_sched_lock(void)
Lock the scheduler.
os_port_irq_state_t os_irq_state_t
Type of variables holding interrupts priority values.
Definition os-c-decls.h:184
void os_irq_critical_exit(os_irq_state_t state)
Exit the interrupts critical section.
uint32_t os_flags_mode_t
Type of variables holding flags modes.
Definition os-c-decls.h:121
os_statistics_counter_t os_sched_stat_get_context_switches(void)
Get the total number of context switches.
bool os_sched_is_preemptive(void)
Check if the scheduler is in preemptive mode.
os_port_scheduler_state_t os_sched_state_t
Type of variables holding scheduler state codes.
Definition os-c-decls.h:170
os_port_clock_offset_t os_clock_offset_t
Type of variables holding clock offsets.
Definition os-c-decls.h:222
void * os_iterator_t
Generic iterator, implemented as a pointer.
Definition os-c-decls.h:236
uint64_t os_statistics_duration_t
Type of variables holding durations in CPU cycles.
Definition os-c-decls.h:252
os_irq_state_t os_irq_critical_enter(void)
Enter an interrupts critical section.
os_port_clock_duration_t os_clock_duration_t
Type of variables holding clock durations.
Definition os-c-decls.h:210
os_port_clock_timestamp_t os_clock_timestamp_t
Type of variables holding clock time stamps.
Definition os-c-decls.h:199
uint32_t os_result_t
Type of values returned by RTOS functions.
Definition os-c-decls.h:108
@ os_flags_mode_clear
Definition os-c-decls.h:145
@ os_flags_mode_all
Definition os-c-decls.h:143
@ os_flags_mode_any
Definition os-c-decls.h:144
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:352
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:839
@ os_mutex_protocol_protect
Execute at the highest priority.
Definition os-c-decls.h:844
@ os_mutex_protocol_none
Priority and scheduling not affected by mutex ownership.
Definition os-c-decls.h:834
@ os_mutex_type_recursive
Recursive mutex behaviour.
Definition os-c-decls.h:895
@ os_mutex_type_errorcheck
Check mutex behaviour.
Definition os-c-decls.h:890
@ os_mutex_type_default
Default mutex type.
Definition os-c-decls.h:900
@ os_mutex_type_normal
Normal mutex behaviour.
Definition os-c-decls.h:885
@ os_mutex_robustness_robust
Enhanced robustness at thread termination.
Definition os-c-decls.h:867
@ os_mutex_robustness_stalled
Normal robustness.
Definition os-c-decls.h:862
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.
struct os_thread_context_s os_thread_context_t
Thread context.
os_result_t os_this_thread_flags_timed_wait(os_flags_mask_t mask, os_clock_duration_t timeout, os_flags_mask_t *oflags, os_flags_mode_t mode)
Timed wait for thread event flags.
os_iterator_t os_children_threads_iter_next(os_iterator_t iterator)
Advance the iterator to the next position.
os_thread_user_storage_t * os_thread_get_user_storage(os_thread_t *thread)
Get the thread user storage.
bool os_thread_is_constructed(os_thread_t *thread)
Check if the thread is constructed.
os_flags_mask_t os_this_thread_flags_get(os_flags_mask_t mask, os_flags_mode_t mode)
Get/clear thread event flags.
const char * os_thread_get_name(os_thread_t *thread)
Get the thread name.
os_result_t os_this_thread_flags_wait(os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Wait for thread event flags.
void *(* os_thread_func_t)(os_thread_func_args_t args)
Type of thread function.
Definition os-c-decls.h:355
uint8_t os_thread_prio_t
Type of variables holding thread priorities.
Definition os-c-decls.h:376
os_thread_stack_element_t * os_thread_stack_get_bottom(os_thread_stack_t *stack)
Get the stack lowest reserved address.
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:389
os_thread_prio_t os_thread_get_priority(os_thread_t *thread)
Get the thread current scheduling priority.
void * os_thread_func_args_t
Type of thread function arguments.
Definition os-c-decls.h:343
os_thread_t * os_this_thread(void)
Get the current running thread.
os_thread_stack_t * os_thread_get_stack(os_thread_t *thread)
Get the thread context stack.
os_result_t os_thread_kill(os_thread_t *thread)
Force thread termination.
os_thread_t * os_thread_new(const char *name, os_thread_func_t func, const os_thread_func_args_t args, const os_thread_attr_t *attr)
Allocate a thread object instance and construct it.
os_thread_t * os_children_threads_iter_get(os_iterator_t iterator)
Get the thread from the current iterator position.
size_t os_thread_stack_get_size(os_thread_stack_t *stack)
Get the stack size.
size_t os_thread_stack_get_min_size(void)
Get the min stack size.
size_t os_thread_stack_get_available(os_thread_stack_t *stack)
Compute how much available stack remains.
os_statistics_duration_t os_thread_stat_get_cpu_cycles(os_thread_t *thread)
Get the thread execution time.
os_result_t os_thread_set_priority(os_thread_t *thread, os_thread_prio_t prio)
Set the thread dynamic scheduling priority.
void os_this_thread_exit(void *exit_ptr)
Terminate the current running thread.
os_result_t os_this_thread_flags_try_wait(os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Try to wait for thread event flags.
uint8_t os_thread_state_t
Type of variables holding thread states.
Definition os-c-decls.h:362
size_t os_thread_stack_get_default_size(void)
Get the default stack size.
size_t os_thread_stack_set_min_size(size_t size_bytes)
Set the min stack size.
os_iterator_t os_children_threads_iter_end(os_thread_t *thread)
Get the end of the list of children threads.
os_result_t os_thread_flags_raise(os_thread_t *thread, os_flags_mask_t mask, os_flags_mask_t *oflags)
Raise thread event flags.
void os_thread_destruct(os_thread_t *thread)
Destruct the statically allocated thread object instance.
@ os_thread_state_terminated
No longer usable, but resources not yet released.
Definition os-c-decls.h:324
@ os_thread_state_suspended
Not present in the READY list, waiting for an event.
Definition os-c-decls.h:320
@ os_thread_state_undefined
Used to catch uninitialised threads.
Definition os-c-decls.h:308
@ os_thread_state_ready
Present in the READY list and competing for CPU.
Definition os-c-decls.h:312
@ os_thread_state_initialising
Used to check reused threads.
Definition os-c-decls.h:332
@ os_thread_state_destroyed
Terminated and resources (like stack) released.
Definition os-c-decls.h:328
@ os_thread_state_running
Has the CPU and runs.
Definition os-c-decls.h:316
@ os_thread_priority_error
Definition os-c-decls.h:295
@ os_thread_priority_below_normal
Definition os-c-decls.h:288
@ os_thread_priority_high
Definition os-c-decls.h:291
@ os_thread_priority_realtime
Definition os-c-decls.h:292
@ os_thread_priority_idle
Definition os-c-decls.h:285
@ os_thread_priority_normal
Definition os-c-decls.h:289
@ os_thread_priority_low
Definition os-c-decls.h:287
@ os_thread_priority_above_normal
Definition os-c-decls.h:290
uint8_t os_timer_type_t
Type of variables holding timer types.
Definition os-c-decls.h:729
void(* os_timer_func_t)(os_timer_func_args_t args)
Type of timer function.
Definition os-c-decls.h:722
void * os_timer_func_args_t
Type of timer function arguments.
Definition os-c-decls.h:710
const char * os_timer_get_name(os_timer_t *timer)
Get the timer name.
os_result_t os_timer_stop(os_timer_t *timer)
Stop the timer.
void os_timer_destruct(os_timer_t *timer)
Destruct the statically allocated timer object instance.
uint8_t os_timer_state_t
Type of variables holding timer states.
Definition os-c-decls.h:736
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:697
@ os_timer_periodic
Definition os-c-decls.h:698
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:83
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:92
clock_systick sysclock
The system clock object instance.
port::clock::offset_t offset_t
Type of variables holding clock offsets.
Definition os-clocks.h:102
static const attributes initializer
Default condition variable initialiser.
Definition os-condvar.h:126
class thread::stack * stack(void)
Get the interrupts stack.
Definition os-core.cpp:564
static const attributes initializer
Default event flags initialiser.
Definition os-evflags.h:130
uint16_t size_t
Type of memory pool size storage.
Definition os-mempool.h:82
static const attributes initializer
Default memory pool initialiser.
Definition os-mempool.h:165
memory_resource * get_default_resource(void) noexcept
Get the default RTOS system memory manager.
Definition os-memory.h:1137
uint8_t priority_t
Type of message priority storage.
Definition os-mqueue.h:127
message_queue::size_t index_t
Type of list index storage.
Definition os-mqueue.h:111
static const attributes initializer
Default message queue initialiser.
Definition os-mqueue.h:218
uint8_t size_t
Type of a queue size storage.
Definition os-mqueue.h:86
uint16_t msg_size_t
Type of message size storage.
Definition os-mqueue.h:99
uint8_t type_t
Type of variables holding mutex behaviours.
Definition os-mutex.h:159
uint16_t count_t
Type of variables holding mutex recursion counters.
Definition os-mutex.h:203
static const attributes_recursive initializer_recursive
Default recursive mutex initialiser.
Definition os-mutex.h:362
uint8_t protocol_t
Type of variables holding mutex protocols.
Definition os-mutex.h:72
uint8_t robustness_t
Type of variables holding mutex robustness.
Definition os-mutex.h:118
static const attributes initializer_normal
Default normal mutex initialiser.
Definition os-mutex.h:313
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:268
void * func_args_t
Timer call back function arguments.
Definition os-timer.h:72
void(*)(func_args_t args) func_t
Entry point of a timer call back function.
Definition os-timer.h:78
uint8_t type_t
Type of of variables holding timer run types.
Definition os-timer.h:84
uint8_t state_t
Type of of variables holding timer states.
Definition os-timer.h:111
static const attributes_periodic periodic_initializer
Default periodic timer initialiser.
Definition os-timer.h:263
@ all
Return when all flags are set.
Definition os-decls.h:307
@ clear
Ask for flags to be cleared after read.
Definition os-decls.h:317
@ any
Return when at least one flag is set.
Definition os-decls.h:312
uint32_t mode_t
Type of variables holding flags modes.
Definition os-decls.h:289
uint32_t mask_t
Type of variables holding flags masks.
Definition os-decls.h:279
port::interrupts::state_t state_t
Type of variables holding interrupts statu codes.
Definition os-decls.h:257
bool in_handler_mode(void)
Check if the CPU is in handler mode.
Definition os-sched.h:1136
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:195
rtos::statistics::duration_t cpu_cycles(void)
Get the total duration of all threads.
Definition os-sched.h:1087
rtos::statistics::counter_t context_switches(void)
Get the total number of context switches.
Definition os-sched.h:1062
port::scheduler::state_t state_t
Type of variables holding scheduler state codes.
Definition os-decls.h:216
state_t unlock(void)
Unlock the scheduler.
Definition os-sched.h:908
void start(void)
Start the RTOS scheduler.
Definition os-core.cpp:190
bool started(void)
Check if the scheduler was started.
Definition os-sched.h:853
thread::threads_list & children_threads(thread *th)
Get the children threads.
Definition os-core.cpp:262
state_t lock(void)
Lock the scheduler.
Definition os-sched.h:895
result_t initialize(void)
Initialise the RTOS scheduler.
Definition os-core.cpp:161
bool preemptive(void)
Check if the scheduler is in preemptive mode.
Definition os-sched.h:865
bool locked(void)
Check if the scheduler is locked.
Definition os-sched.h:882
uint64_t duration_t
Type of variables holding durations in CPU cycles.
Definition os-decls.h:236
uint64_t counter_t
Type of variables holding context switches counters.
Definition os-decls.h:231
RTOS namespace.
Definition os-flags.h:54
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:110
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:816
uint8_t os_mutex_type_t
Definition os-c-decls.h:815
uint8_t os_mqueue_size_t
uint8_t os_mutex_robustness_t
Definition os-c-decls.h:817
uint16_t os_mempool_size_t
int16_t os_mutex_count_t
Definition os-c-decls.h:814
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:375
osStatus status
status code: event or error information
Definition cmsis_os.h:376
int32_t signals
signal flags
Definition cmsis_os.h:381
union osEvent::@0 value
event value
@ none
Priority and scheduling not affected by mutex ownership.
Definition os-mutex.h:90
@ inherit
Inherit priority from highest priority thread.
Definition os-mutex.h:95
@ protect
Execute at the highest priority.
Definition os-mutex.h:100
@ stalled
Normal robustness.
Definition os-mutex.h:136
@ robust
Enhanced robustness at thread termination.
Definition os-mutex.h:141
@ normal
Normal mutex behaviour.
Definition os-mutex.h:177
@ default_
Default value.
Definition os-mutex.h:190
@ errorcheck
Check mutex behaviour.
Definition os-mutex.h:181
@ recursive
Recursive mutex behaviour.
Definition os-mutex.h:185
@ running
Has the CPU and runs.
Definition os-thread.h:382
@ destroyed
Terminated and resources (like stack) released.
Definition os-thread.h:394
@ initializing
Used to check reused threads.
Definition os-thread.h:398
@ terminated
No longer usable, but resources not yet released.
Definition os-thread.h:390
@ ready
Present in the READY list and competing for CPU.
Definition os-thread.h:378
@ undefined
Used to catch uninitialised threads.
Definition os-thread.h:374
@ suspended
Not present in the READY list, waiting for an event.
Definition os-thread.h:386
@ once
Run only once.
Definition os-timer.h:98
@ periodic
Run periodically.
Definition os-timer.h:103
Clock object storage.
Definition os-c-decls.h:649
Condition variable attributes.
Condition variable object storage.
Event flags attributes.
Event flags object storage.
Definition structure for mail queue.
Definition cmsis_os.h:357
osMailQ * data
Definition cmsis_os.h:366
uint32_t items
number of elements in the queue
Definition cmsis_os.h:359
uint32_t queue_sz
Definition cmsis_os.h:365
void * queue
pointer to memory array for queue
Definition cmsis_os.h:364
uint32_t queue_item_sz
size of a queue item
Definition cmsis_os.h:361
uint32_t pool_sz
Definition cmsis_os.h:363
uint32_t pool_item_sz
size of a pool item
Definition cmsis_os.h:360
void * pool
pointer to memory array for pool
Definition cmsis_os.h:362
const char * name
Definition cmsis_os.h:358
os_mqueue_t queue
Definition cmsis_os.h:223
os_mempool_t pool
Definition cmsis_os.h:222
Memory resource object storage.
Memory pool attributes.
Memory pool object storage.
Definition structure for message queue.
Definition cmsis_os.h:343
void * queue
pointer to memory array for messages
Definition cmsis_os.h:347
osMessageQ * data
Definition cmsis_os.h:349
uint32_t items
number of elements in the queue
Definition cmsis_os.h:345
const char * name
Definition cmsis_os.h:344
uint32_t item_sz
size of an item
Definition cmsis_os.h:346
uint32_t queue_sz
Definition cmsis_os.h:348
Message queue attributes.
Message queue object storage.
Mutex attributes.
Definition os-c-decls.h:917
Mutex definition structure contains setup information for a mutex.
Definition cmsis_os.h:306
osMutex * data
Definition cmsis_os.h:308
const char * name
Definition cmsis_os.h:307
Mutex object storage.
Definition os-c-decls.h:967
Definition structure for memory block allocation.
Definition cmsis_os.h:329
osPool * data
Definition cmsis_os.h:335
const char * name
Definition cmsis_os.h:330
uint32_t pool_sz
Definition cmsis_os.h:334
uint32_t item_sz
size of an item
Definition cmsis_os.h:332
void * pool
pointer to memory for pool
Definition cmsis_os.h:333
uint32_t items
number of items (elements) in the pool
Definition cmsis_os.h:331
Semaphore attributes.
Semaphore definition structure contains setup information for a semaphore.
Definition cmsis_os.h:316
const char * name
Definition cmsis_os.h:317
osSemaphore * data
Definition cmsis_os.h:318
Semaphore object storage.
Thread attributes.
Definition os-c-decls.h:502
Thread definition structure contains startup information of a thread.
Definition cmsis_os.h:278
os_pthread pthread
start address of thread function
Definition cmsis_os.h:280
uint64_t * stack
Definition cmsis_os.h:285
const char * name
Definition cmsis_os.h:279
osPriority tpriority
initial thread priority
Definition cmsis_os.h:281
uint32_t stacksize
stack size requirements in bytes; 0 is default stack size
Definition cmsis_os.h:283
osThread * data
Definition cmsis_os.h:284
uint32_t instances
maximum number of instances of that thread function
Definition cmsis_os.h:282
Thread object storage.
Definition os-c-decls.h:572
Thread stack.
Definition os-c-decls.h:415
Timer attributes.
Definition os-c-decls.h:752
Timer definition structure contains timer parameters.
Definition cmsis_os.h:295
const char * name
Definition cmsis_os.h:296
osTimer * data
Definition cmsis_os.h:298
os_ptimer ptimer
start address of a timer function
Definition cmsis_os.h:297
Timer object storage.
Definition os-c-decls.h:782