µ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-2023 Liviu Ionescu. All rights reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
13/*
14 * The code provides an implementation of the C API for the µOS++
15 * and legacy CMSIS, using the CMSIC++ RTOS definitions.
16 */
17
18#if defined(OS_USE_OS_APP_CONFIG_H)
19#include <cmsis-plus/os-app-config.h>
20#endif
21
22#include <cmsis-plus/rtos/os.h>
24
25// ----------------------------------------------------------------------------
26
27#if defined(__clang__)
28#pragma clang diagnostic ignored "-Wc++98-compat"
29#elif defined(__GNUC__)
30#pragma GCC diagnostic ignored "-Wuseless-cast"
31#endif
32
33// ----------------------------------------------------------------------------
34
35using namespace os;
36using namespace os::rtos;
37
38// ----------------------------------------------------------------------------
39
40// Validate C typedefs sizes & alignment.
41
42static_assert(sizeof(os_result_t) == sizeof(result_t), "adjust size of os_result_t");
43static_assert(alignof(os_result_t) == alignof(result_t), "adjust align of os_result_t");
44
45static_assert(sizeof(os_flags_mode_t) == sizeof(flags::mode_t), "adjust size of os_flags_mode_t");
46static_assert(alignof(os_flags_mode_t) == alignof(flags::mode_t), "adjust align of os_flags_mode_t");
47
48static_assert(sizeof(os_flags_mask_t) == sizeof(flags::mask_t), "adjust size of os_flags_mask_t");
49static_assert(alignof(os_flags_mask_t) == alignof(flags::mask_t), "adjust align of os_flags_mask_t");
50
51static_assert(sizeof(os_sched_state_t) == sizeof(scheduler::state_t), "adjust size of os_sched_state_t");
52static_assert(alignof(os_sched_state_t) == alignof(scheduler::state_t), "adjust align of os_sched_state_t");
53
54static_assert(sizeof(os_irq_state_t) == sizeof(interrupts::state_t), "adjust size of os_irq_state_t");
55static_assert(alignof(os_irq_state_t) == alignof(interrupts::state_t), "adjust align of os_irq_state_t");
56
57static_assert(sizeof(os_clock_timestamp_t) == sizeof(clock::timestamp_t), "adjust size of os_port_clock_timestamp_t");
58static_assert(alignof(os_clock_timestamp_t) == alignof(clock::timestamp_t), "adjust align of os_port_clock_timestamp_t");
59
60static_assert(sizeof(os_clock_duration_t) == sizeof(clock::duration_t), "adjust size of os_port_clock_duration_t");
61static_assert(alignof(os_clock_duration_t) == alignof(clock::duration_t), "adjust align of os_port_clock_duration_t");
62
63static_assert(sizeof(os_clock_offset_t) == sizeof(clock::offset_t), "adjust size of os_port_clock_offset_t");
64static_assert(alignof(os_clock_offset_t) == alignof(clock::offset_t), "adjust align of os_port_clock_offset_t");
65
66static_assert(sizeof(os_statistics_counter_t) == sizeof(statistics::counter_t), "adjust size of os_statistics_counter_t");
67static_assert(alignof(os_statistics_counter_t) == alignof(statistics::counter_t), "adjust align of os_statistics_counter_t");
68
69static_assert(sizeof(os_statistics_duration_t) == sizeof(statistics::duration_t), "adjust size of os_statistics_duration_t");
70static_assert(alignof(os_statistics_duration_t) == alignof(statistics::duration_t), "adjust align of os_statistics_duration_t");
71
72static_assert(sizeof(os_thread_func_args_t) == sizeof(thread::func_args_t), "adjust size of os_thread_func_args_t");
73static_assert(alignof(os_thread_func_args_t) == alignof(thread::func_args_t), "adjust align of os_thread_func_args_t");
74
75static_assert(sizeof(os_thread_func_t) == sizeof(thread::func_t), "adjust size of os_thread_func_t");
76static_assert(alignof(os_thread_func_t) == alignof(thread::func_t), "adjust align of os_thread_func_t");
77
78static_assert(sizeof(os_thread_state_t) == sizeof(thread::state_t), "adjust size of os_thread_state_t");
79static_assert(alignof(os_thread_state_t) == alignof(thread::state_t), "adjust align of os_thread_state_t");
80
81static_assert(sizeof(os_thread_prio_t) == sizeof(thread::priority_t), "adjust size of os_thread_prio_t");
82static_assert(alignof(os_thread_prio_t) == alignof(thread::priority_t), "adjust align of os_thread_prio_t");
83
84static_assert(sizeof(os_timer_func_args_t) == sizeof(timer::func_args_t), "adjust size of os_timer_func_args_t");
85static_assert(alignof(os_timer_func_args_t) == alignof(timer::func_args_t), "adjust align of os_timer_func_args_t");
86
87static_assert(sizeof(os_timer_func_t) == sizeof(timer::func_t), "adjust size of os_timer_func_t");
88static_assert(alignof(os_timer_func_t) == alignof(timer::func_t), "adjust align of os_timer_func_t");
89
90static_assert(sizeof(os_timer_type_t) == sizeof(timer::type_t), "adjust size of os_timer_type_t");
91static_assert(alignof(os_timer_type_t) == alignof(timer::type_t), "adjust align of os_timer_type_t");
92
93static_assert(sizeof(os_timer_state_t) == sizeof(timer::state_t), "adjust size of os_timer_state_t");
94static_assert(alignof(os_timer_state_t) == alignof(timer::state_t), "adjust align of os_timer_state_t");
95
96static_assert(sizeof(os_mutex_count_t) == sizeof(mutex::count_t), "adjust size of os_mutex_count_t");
97static_assert(alignof(os_mutex_count_t) == alignof(mutex::count_t), "adjust align of os_mutex_count_t");
98
99static_assert(sizeof(os_mutex_type_t) == sizeof(mutex::type_t), "adjust size of os_mutex_type_t");
100static_assert(alignof(os_mutex_type_t) == alignof(mutex::type_t), "adjust align of os_mutex_type_t");
101
102static_assert(sizeof(os_mutex_protocol_t) == sizeof(mutex::protocol_t), "adjust size of os_mutex_protocol_t");
103static_assert(alignof(os_mutex_protocol_t) == alignof(mutex::protocol_t), "adjust align of os_mutex_protocol_t");
104
105static_assert(sizeof(os_mutex_robustness_t) == sizeof(mutex::robustness_t), "adjust size of os_mutex_robustness_t");
106static_assert(alignof(os_mutex_robustness_t) == alignof(mutex::robustness_t), "adjust align of os_mutex_robustness_t");
107
108static_assert(sizeof(os_semaphore_count_t) == sizeof(semaphore::count_t), "adjust size of os_semaphore_count_t");
109static_assert(alignof(os_semaphore_count_t) == alignof(semaphore::count_t), "adjust align of os_semaphore_count_t");
110
111static_assert(sizeof(os_mempool_size_t) == sizeof(memory_pool::size_t), "adjust size of os_mempool_size_t");
112static_assert(alignof(os_mempool_size_t) == alignof(memory_pool::size_t), "adjust align of os_mempool_size_t");
113
114static_assert(sizeof(os_mqueue_size_t) == sizeof(message_queue::size_t), "adjust size of os_mqueue_size_t");
115static_assert(alignof(os_mqueue_size_t) == alignof(message_queue::size_t), "adjust align of os_mqueue_size_t");
116
117static_assert(sizeof(os_mqueue_msg_size_t) == sizeof(message_queue::msg_size_t), "adjust size of os_mqueue_msg_size_t");
118static_assert(alignof(os_mqueue_msg_size_t) == alignof(message_queue::msg_size_t), "adjust align of os_mqueue_msg_size_t");
119
120static_assert(sizeof(os_mqueue_index_t) == sizeof(message_queue::index_t), "adjust size of os_mqueue_index_t");
121static_assert(alignof(os_mqueue_index_t) == alignof(message_queue::index_t), "adjust align of os_mqueue_index_t");
122
123static_assert(sizeof(os_mqueue_prio_t) == sizeof(message_queue::priority_t), "adjust size of os_mqueue_prio_t");
124static_assert(alignof(os_mqueue_prio_t) == alignof(message_queue::priority_t), "adjust align of os_mqueue_prio_t");
125
126// ----------------------------------------------------------------------------
127
128// Validate C enumeration values
129
130#pragma GCC diagnostic push
131#if defined(__clang__)
132#pragma clang diagnostic ignored "-Wanon-enum-enum-conversion"
133#else
134#pragma GCC diagnostic ignored "-Wenum-compare"
135#pragma GCC diagnostic ignored "-Wsign-compare"
136#endif
137
138static_assert(os_thread_priority_idle == thread::priority::idle, "adjust os_thread_priority_idle");
139static_assert(os_thread_priority_low == thread::priority::low, "adjust os_thread_priority_low");
140static_assert(os_thread_priority_below_normal == thread::priority::below_normal, "adjust os_thread_priority_below_normal");
141static_assert(os_thread_priority_normal == thread::priority::normal, "adjust os_thread_priority_normal");
142static_assert(os_thread_priority_above_normal == thread::priority::above_normal, "adjust os_thread_priority_above_normal");
143static_assert(os_thread_priority_high == thread::priority::high, "adjust os_thread_priority_high");
144static_assert(os_thread_priority_realtime == thread::priority::realtime, "adjust os_thread_priority_realtime");
145static_assert(os_thread_priority_error == thread::priority::error, "adjust os_thread_priority_error");
146
147static_assert(os_flags_mode_all == flags::mode::all, "adjust os_flags_mode_all");
148static_assert(os_flags_mode_any == flags::mode::any, "adjust os_flags_mode_any");
149static_assert(os_flags_mode_clear == flags::mode::clear, "adjust os_flags_mode_clear");
150
151static_assert(os_thread_state_undefined == thread::state::undefined, "adjust os_thread_state_undefined");
152static_assert(os_thread_state_initialising == thread::state::initializing, "adjust os_thread_state_initializing");
153static_assert(os_thread_state_ready == thread::state::ready, "adjust os_thread_state_ready");
154static_assert(os_thread_state_running == thread::state::running, "adjust os_thread_state_running");
155static_assert(os_thread_state_suspended == thread::state::suspended, "adjust os_thread_state_suspended");
156static_assert(os_thread_state_terminated == thread::state::terminated, "adjust os_thread_state_terminated");
157static_assert(os_thread_state_destroyed == thread::state::destroyed, "adjust os_thread_state_destroyed");
158
159static_assert(os_timer_once == timer::run::once, "adjust os_timer_once");
160static_assert(os_timer_periodic == timer::run::periodic, "adjust os_timer_periodic");
161
162static_assert(os_mutex_protocol_none == mutex::protocol::none, "adjust os_mutex_protocol_none");
163static_assert(os_mutex_protocol_inherit == mutex::protocol::inherit, "adjust os_mutex_protocol_inherit");
164static_assert(os_mutex_protocol_protect == mutex::protocol::protect, "adjust os_mutex_protocol_protect");
165
166static_assert(os_mutex_robustness_stalled == mutex::robustness::stalled, "adjust os_mutex_robustness_stalled");
167static_assert(os_mutex_robustness_robust == mutex::robustness::robust, "adjust os_mutex_robustness_robust");
168
169static_assert(os_mutex_type_normal == mutex::type::normal, "adjust os_mutex_type_normal");
170static_assert(os_mutex_type_errorcheck == mutex::type::errorcheck, "adjust os_mutex_type_errorcheck");
171static_assert(os_mutex_type_recursive == mutex::type::recursive, "adjust os_mutex_type_recursive");
172static_assert(os_mutex_type_default == mutex::type::default_, "adjust os_mutex_type_default");
173
174#pragma GCC diagnostic pop
175
176// ----------------------------------------------------------------------------
177
178// Validate C structs sizes (should match the C++ objects sizes).
179// Validate offset of individual members (if needed, validate member size).
180
181#pragma GCC diagnostic push
182#if defined(__clang__)
183#elif defined(__GNUC__)
184#pragma GCC diagnostic ignored "-Winvalid-offsetof"
185#endif
186
187static_assert(sizeof(rtos::clock) == sizeof(os_clock_t), "adjust os_clock_t size");
188
189static_assert(sizeof(rtos::thread) == sizeof(os_thread_t), "adjust os_thread_t size");
190static_assert(sizeof(rtos::thread::attributes) == sizeof(os_thread_attr_t), "adjust os_thread_attr_t size");
191static_assert(offsetof(rtos::thread::attributes, th_stack_address) == offsetof(os_thread_attr_t, th_stack_address), "adjust os_thread_attr_t members");
192static_assert(offsetof(rtos::thread::attributes, th_stack_size_bytes) == offsetof(os_thread_attr_t, th_stack_size_bytes), "adjust os_thread_attr_t members");
193static_assert(offsetof(rtos::thread::attributes, th_priority) == offsetof(os_thread_attr_t, th_priority), "adjust os_thread_attr_t members");
194static_assert(offsetof(rtos::thread::attributes, th_enable_assert_reuse) == offsetof(os_thread_attr_t, th_enable_assert_reuse), "adjust os_thread_attr_t members");
195
196static_assert(sizeof(rtos::timer) == sizeof(os_timer_t), "adjust size of os_timer_t");
197static_assert(sizeof(rtos::timer::attributes) == sizeof(os_timer_attr_t), "adjust size of os_timer_attr_t");
198static_assert(offsetof(rtos::timer::attributes, tm_type) == offsetof(os_timer_attr_t, tm_type), "adjust os_timer_attr_t members");
199
200static_assert(sizeof(rtos::mutex) == sizeof(os_mutex_t), "adjust size of os_mutex_t");
201static_assert(sizeof(rtos::mutex::attributes) == sizeof(os_mutex_attr_t), "adjust size of os_mutex_attr_t");
202static_assert(offsetof(rtos::mutex::attributes, mx_priority_ceiling) == offsetof(os_mutex_attr_t, mx_priority_ceiling), "adjust os_mutex_attr_t members");
203static_assert(offsetof(rtos::mutex::attributes, mx_protocol) == offsetof(os_mutex_attr_t, mx_protocol), "adjust os_mutex_attr_t members");
204static_assert(offsetof(rtos::mutex::attributes, mx_robustness) == offsetof(os_mutex_attr_t, mx_robustness), "adjust os_mutex_attr_t members");
205static_assert(offsetof(rtos::mutex::attributes, mx_type) == offsetof(os_mutex_attr_t, mx_type), "adjust os_mutex_attr_t members");
206static_assert(offsetof(rtos::mutex::attributes, mx_max_count) == offsetof(os_mutex_attr_t, mx_max_count), "adjust os_mutex_attr_t members");
207
208static_assert(sizeof(rtos::condition_variable) == sizeof(os_condvar_t), "adjust size of os_condvar_t");
209static_assert(sizeof(rtos::condition_variable::attributes) == sizeof(os_condvar_attr_t), "adjust size of os_condvar_attr_t");
210
211static_assert(sizeof(rtos::semaphore) == sizeof(os_semaphore_t), "adjust size of os_semaphore_t");
212static_assert(sizeof(rtos::semaphore::attributes) == sizeof(os_semaphore_attr_t), "adjust size of os_semaphore_attr_t");
213static_assert(offsetof(rtos::semaphore::attributes, sm_initial_value) == offsetof(os_semaphore_attr_t, sm_initial_value), "adjust os_semaphore_attr_t members");
214static_assert(offsetof(rtos::semaphore::attributes, sm_max_value) == offsetof(os_semaphore_attr_t, sm_max_value), "adjust os_semaphore_attr_t members");
215
216static_assert(sizeof(rtos::memory_pool) == sizeof(os_mempool_t), "adjust size of os_mempool_t");
217static_assert(sizeof(rtos::memory_pool::attributes) == sizeof(os_mempool_attr_t), "adjust size of os_mempool_attr_t");
218static_assert(offsetof(rtos::memory_pool::attributes, mp_pool_address) == offsetof(os_mempool_attr_t, mp_pool_address), "adjust os_mempool_attr_t members");
219static_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");
220
221static_assert(sizeof(rtos::message_queue) == sizeof(os_mqueue_t), "adjust size of os_mqueue_t");
222static_assert(sizeof(rtos::message_queue::attributes) == sizeof(os_mqueue_attr_t), "adjust size of os_mqueue_attr_t");
223static_assert(offsetof(rtos::message_queue::attributes, mq_queue_address) == offsetof(os_mqueue_attr_t, mq_queue_addr), "adjust os_mqueue_attr_t members");
224static_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");
225
226static_assert(sizeof(rtos::event_flags) == sizeof(os_evflags_t), "adjust size of os_evflags_t");
227static_assert(sizeof(rtos::event_flags::attributes) == sizeof(os_evflags_attr_t), "adjust size of os_evflags_attr_t");
228
229static_assert(sizeof(class thread::stack) == sizeof(os_thread_stack_t), "adjust size of os_thread_stack_t");
230static_assert(sizeof(/* class */ thread::context) == sizeof(os_thread_context_t), "adjust size of os_thread_context_t");
231
232#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) \
233 || defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
234static_assert(sizeof(class thread::statistics) == sizeof(os_thread_statistics_t), "adjust size of os_thread_statistics_t");
235#endif
236
237static_assert(sizeof(internal::timer_node) == sizeof(os_internal_clock_timer_node_t), "adjust size of os_internal_clock_timer_node_t");
238
239#pragma GCC diagnostic pop
240
241#pragma GCC diagnostic push
242#if defined(__clang__)
243#pragma clang diagnostic ignored "-Wold-style-cast"
244#elif defined(__GNUC__)
245#pragma GCC diagnostic ignored "-Wold-style-cast"
246#endif
247
248// ----------------------------------------------------------------------------
249
258{
260}
261
268void
270{
272}
273
280bool
282{
283 return scheduler::started ();
284}
285
294{
295 return scheduler::lock ();
296}
297
306{
307 return scheduler::unlock ();
308}
309
318{
319 return scheduler::locked (state);
320}
321
328bool
330{
331 return scheduler::locked ();
332}
333
340bool
342{
343 return scheduler::preemptive ();
344}
345
352bool
354{
355 return scheduler::preemptive (state);
356}
357
358#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
359
368{
370}
371
372#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
373
374#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
375
384{
386}
387
388#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
389
390// ----------------------------------------------------------------------------
391
398bool
400{
402}
403
404// ----------------------------------------------------------------------------
405
414{
416}
417
424void
426{
428}
429
430// ----------------------------------------------------------------------------
431
440{
442}
443
450void
452{
454}
455
456#if defined(OS_HAS_INTERRUPTS_STACK) || defined(__DOXYGEN__)
457
467 {
468 return reinterpret_cast<os_thread_stack_t*> (rtos::interrupts::stack ());
469 }
470
471#endif
472
473// ----------------------------------------------------------------------------
474
483{
484 return (os_thread_t*) &this_thread::thread ();
485}
486
493void
495{
496 return this_thread::suspend ();
497}
498
505void
506os_this_thread_exit (void* exit_ptr)
507{
508 this_thread::exit (exit_ptr);
509}
510
519 os_flags_mode_t mode)
520{
521 return (os_result_t) this_thread::flags_wait (mask, oflags, mode);
522}
523
532 os_flags_mode_t mode)
533{
534 return (os_result_t) this_thread::flags_try_wait (mask, oflags, mode);
535}
536
545 os_clock_duration_t timeout,
546 os_flags_mask_t* oflags, os_flags_mode_t mode)
547{
548 return (os_result_t) this_thread::flags_timed_wait (mask, timeout, oflags,
549 mode);
550}
551
560{
561 return (os_result_t) this_thread::flags_clear (mask, oflags);
562}
563
572{
573 return (os_flags_mask_t) this_thread::flags_get (mask, mode);
574}
575
576// ----------------------------------------------------------------------------
577
584void
586{
587 assert (attr != nullptr);
588 new (attr) thread::attributes ();
589}
590
599void
602 const os_thread_attr_t* attr)
603{
604 assert (thread != nullptr);
605 if (attr == nullptr)
606 {
607 attr = (const os_thread_attr_t*) &thread::initializer;
608 }
609 new (thread) rtos::thread (name, (thread::func_t) func,
610 (thread::func_args_t) args,
611 (const thread::attributes&) *attr);
612}
613
622void
624{
625 assert (thread != nullptr);
626 (reinterpret_cast<rtos::thread&> (*thread)).~thread ();
627}
628
643os_thread_new (const char* name, os_thread_func_t func,
644 const os_thread_func_args_t args, const os_thread_attr_t* attr)
645{
646 if (attr == nullptr)
647 {
648 attr = (const os_thread_attr_t*) &thread::initializer;
649 }
650 return reinterpret_cast<os_thread_t*> (new rtos::thread (
651 name, (thread::func_t) func, (thread::func_args_t) args,
652 (const thread::attributes&) *attr));
653}
654
668void
670{
671 assert (thread != nullptr);
672 delete reinterpret_cast<rtos::thread*> (thread);
673}
674
681bool
683{
684 assert (thread != nullptr);
686 reinterpret_cast<rtos::thread&> (*thread));
687}
688
695const char*
697{
698 assert (thread != nullptr);
699 return (reinterpret_cast<rtos::thread&> (*thread)).name ();
700}
701
710{
711 assert (thread != nullptr);
712 return (os_thread_prio_t) (reinterpret_cast<rtos::thread&> (*thread)).priority ();
713}
714
723{
724 assert (thread != nullptr);
725 return (os_result_t) (reinterpret_cast<rtos::thread&> (*thread)).priority (
726 prio);
727}
728
737{
738 assert (thread != nullptr);
739 return (os_result_t) reinterpret_cast<rtos::thread&> (*thread).kill ();
740}
741
750{
751 assert (thread != nullptr);
752 return (os_result_t) reinterpret_cast<rtos::thread&> (*thread).join (exit_ptr);
753}
754
761void
763{
764 assert (thread != nullptr);
765 return (reinterpret_cast<rtos::thread&> (*thread)).resume ();
766}
767
776 os_flags_mask_t* oflags)
777{
778 assert (thread != nullptr);
779 return (os_result_t) (reinterpret_cast<rtos::thread&> (*thread)).flags_raise (
780 mask, oflags);
781}
782
791{
792 assert (thread != nullptr);
793 return reinterpret_cast<os_thread_state_t> ((reinterpret_cast<rtos::thread&> (*thread)).state ());
794}
795
796#if defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) || defined(__DOXYGEN__)
797
808os_thread_user_storage_t*
810 {
811 assert(thread != nullptr);
812 return (reinterpret_cast<rtos::thread&> (*thread)).user_storage ();
813 }
814
815#endif /* defined(OS_INCLUDE_RTOS_CUSTOM_THREAD_USER_STORAGE) */
816
825{
826 assert (thread != nullptr);
827 return reinterpret_cast<os_thread_stack_t*> (&(reinterpret_cast<rtos::thread&> (*thread)).stack ());
828}
829
830// ----------------------------------------------------------------------------
831
838size_t
840{
842}
843
850size_t
852{
853 return thread::stack::default_size (size_bytes);
854}
855
862size_t
864{
865 return thread::stack::min_size ();
866}
867
874size_t
876{
877 return thread::stack::min_size (size_bytes);
878}
879
888{
889 assert (stack != nullptr);
890 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).bottom ();
891}
892
901{
902 assert (stack != nullptr);
903 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).top ();
904}
905
912size_t
914{
915 assert (stack != nullptr);
916 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).size ();
917}
918
925size_t
927{
928 assert (stack != nullptr);
929 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).available ();
930}
931
938bool
940{
941 assert (stack != nullptr);
942 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).check_bottom_magic ();
943}
944
951bool
953{
954 assert (stack != nullptr);
955 return (reinterpret_cast<class rtos::thread::stack&> (*stack)).check_top_magic ();
956}
957
958// ----------------------------------------------------------------------------
959
960#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES)
961
970{
971 assert (thread != nullptr);
972 return static_cast<os_statistics_counter_t> ((reinterpret_cast<rtos::thread&> (*thread)).statistics ().context_switches ());
973}
974
975#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CONTEXT_SWITCHES) */
976
977#if defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES)
978
987{
988 assert (thread != nullptr);
989 return static_cast<os_statistics_duration_t> ((reinterpret_cast<rtos::thread&> (*thread)).statistics ().cpu_cycles ());
990}
991
992#endif /* defined(OS_INCLUDE_RTOS_STATISTICS_THREAD_CPU_CYCLES) */
993
994// ----------------------------------------------------------------------------
995
1006{
1007#pragma GCC diagnostic push
1008#if defined(__clang__)
1009#elif defined(__GNUC__)
1010#pragma GCC diagnostic ignored "-Waggregate-return"
1011#endif
1012 return reinterpret_cast<os_iterator_t> (scheduler::children_threads (
1013 reinterpret_cast<rtos::thread*> (thread)).begin ().get_iterator_pointer ());
1014#pragma GCC diagnostic pop
1015}
1016
1030{
1031#pragma GCC diagnostic push
1032#if defined(__clang__)
1033#elif defined(__GNUC__)
1034#pragma GCC diagnostic ignored "-Waggregate-return"
1035#endif
1036 return reinterpret_cast<os_iterator_t> (scheduler::children_threads (
1037 reinterpret_cast<rtos::thread*> (thread)).end ().get_iterator_pointer ());
1038#pragma GCC diagnostic pop
1039}
1040
1050{
1051 // Construct a local iterator object based on the pointer.
1052 thread::threads_list::iterator it
1053 { reinterpret_cast<utils::double_list_links*> (iterator) };
1054 return reinterpret_cast<os_thread_t*> (&(*it));
1055}
1056
1066{
1067 thread::threads_list::iterator it
1068 { reinterpret_cast<utils::double_list_links*> (iterator) };
1069 ++it;
1070
1071 return reinterpret_cast<os_iterator_t> (it.get_iterator_pointer ());
1072}
1073
1074// ----------------------------------------------------------------------------
1075
1082const char*
1084{
1085 assert (clock != nullptr);
1086 return (reinterpret_cast<rtos::clock&> (*clock)).name ();
1087}
1088
1097{
1098 assert (clock != nullptr);
1099 return (os_clock_timestamp_t) (reinterpret_cast<rtos::clock&> (*clock)).now ();
1100}
1101
1110{
1111 assert (clock != nullptr);
1112 return (os_clock_timestamp_t) (reinterpret_cast<rtos::clock&> (*clock)).steady_now ();
1113}
1114
1123{
1124 assert (clock != nullptr);
1125 return (os_result_t) (reinterpret_cast<rtos::clock&> (*clock)).sleep_for (
1126 duration);
1127}
1128
1137{
1138 assert (clock != nullptr);
1139 return (os_result_t) (reinterpret_cast<rtos::clock&> (*clock)).sleep_until (
1140 timestamp);
1141}
1142
1151{
1152 assert (clock != nullptr);
1153 return (os_result_t) (reinterpret_cast<rtos::clock&> (*clock)).wait_for (
1154 timeout);
1155}
1156
1165{
1166 assert (clock != nullptr);
1167 return (os_clock_offset_t) (reinterpret_cast<rtos::clock&> (*clock)).offset ();
1168
1169}
1170
1179{
1180 assert (clock != nullptr);
1181 assert (clock != nullptr);
1182 return (os_clock_offset_t) (reinterpret_cast<rtos::clock&> (*clock)).offset (
1183 (clock::offset_t) offset);
1184
1185}
1186
1195{
1196 return (os_clock_t*) &sysclock;
1197}
1198
1207{
1208 return (os_clock_t*) &rtclock;
1209}
1210
1219{
1220 return (os_clock_t*) &hrclock;
1221}
1222
1223// ----------------------------------------------------------------------------
1224
1233{
1234 return (os_clock_timestamp_t) sysclock.now ();
1235}
1236
1245{
1246 return (os_result_t) sysclock.sleep_for (duration);
1247}
1248
1257{
1258 return (os_result_t) sysclock.sleep_until (timestamp);
1259}
1260
1269{
1270 return (os_result_t) sysclock.wait_for (timeout);
1271}
1272
1273// ----------------------------------------------------------------------------
1274
1281void
1283{
1284 assert (attr != nullptr);
1285 new (attr) timer::attributes ();
1286}
1287
1294void
1296{
1297 assert (attr != nullptr);
1298 new (attr) timer::attributes_periodic ();
1299}
1300
1307const os_timer_attr_t*
1309{
1311}
1312
1321void
1324 const os_timer_attr_t* attr)
1325{
1326 assert (timer != nullptr);
1327 if (attr == nullptr)
1328 {
1330 }
1331 new (timer) rtos::timer (name, (timer::func_t) function,
1332 (timer::func_args_t) args,
1333 (const timer::attributes&) *attr);
1334}
1335
1344void
1346{
1347 assert (timer != nullptr);
1348 (reinterpret_cast<rtos::timer&> (*timer)).~timer ();
1349}
1350
1365os_timer_new (const char* name, os_timer_func_t function,
1366 os_timer_func_args_t args, const os_timer_attr_t* attr)
1367{
1368 if (attr == nullptr)
1369 {
1371 }
1372 return reinterpret_cast<os_timer_t*> (new rtos::timer (
1373 name, (timer::func_t) function, (timer::func_args_t) args,
1374 (const timer::attributes&) *attr));
1375}
1376
1390void
1392{
1393 assert (timer != nullptr);
1394 delete reinterpret_cast<rtos::timer*> (timer);
1395}
1396
1403const char*
1405{
1406 assert (timer != nullptr);
1407 return (reinterpret_cast<rtos::timer&> (*timer)).name ();
1408}
1409
1418{
1419 assert (timer != nullptr);
1420 return (os_result_t) (reinterpret_cast<rtos::timer&> (*timer)).start (period);
1421}
1422
1431{
1432 assert (timer != nullptr);
1433 return (os_result_t) (reinterpret_cast<rtos::timer&> (*timer)).stop ();
1434}
1435
1436// ----------------------------------------------------------------------------
1437
1444void
1446{
1447 assert (attr != nullptr);
1448 new (attr) mutex::attributes ();
1449}
1450
1457void
1459{
1460 assert (attr != nullptr);
1461 new (attr) mutex::attributes_recursive ();
1462}
1463
1470const os_mutex_attr_t*
1472{
1474}
1475
1484void
1486 const os_mutex_attr_t* attr)
1487{
1488 assert (mutex != nullptr);
1489 if (attr == nullptr)
1490 {
1492 }
1493 new (mutex) rtos::mutex (name, (const mutex::attributes&) *attr);
1494}
1495
1504void
1506 const os_mutex_attr_t* attr)
1507{
1508 assert (mutex != nullptr);
1509 if (attr == nullptr)
1510 {
1512 }
1513 new (mutex) rtos::mutex_recursive (name, (const mutex::attributes&) *attr);
1514}
1515
1525void
1527{
1528 assert (mutex != nullptr);
1529 (reinterpret_cast<rtos::mutex&> (*mutex)).~mutex ();
1530}
1531
1546os_mutex_new (const char* name, const os_mutex_attr_t* attr)
1547{
1548 if (attr == nullptr)
1549 {
1551 }
1552 return reinterpret_cast<os_mutex_t*> (new rtos::mutex (
1553 name, (const mutex::attributes&) *attr));
1554}
1555
1570os_mutex_recursive_new (const char* name, const os_mutex_attr_t* attr)
1571{
1572 if (attr == nullptr)
1573 {
1575 }
1576 return reinterpret_cast<os_mutex_t*> (new rtos::mutex_recursive (
1577 name, (const mutex::attributes&) *attr));
1578}
1579
1594void
1596{
1597 assert (mutex != nullptr);
1598 delete reinterpret_cast<rtos::mutex*> (mutex);
1599}
1600
1607const char*
1609{
1610 assert (mutex != nullptr);
1611 return (reinterpret_cast<rtos::mutex&> (*mutex)).name ();
1612}
1613
1622{
1623 assert (mutex != nullptr);
1624 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).lock ();
1625}
1626
1635{
1636 assert (mutex != nullptr);
1637 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).try_lock ();
1638}
1639
1648{
1649 assert (mutex != nullptr);
1650 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).timed_lock (
1651 timeout);
1652}
1653
1662{
1663 assert (mutex != nullptr);
1664 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).unlock ();
1665}
1666
1675{
1676 assert (mutex != nullptr);
1677 return (os_thread_prio_t) (reinterpret_cast<rtos::mutex&> (*mutex)).prio_ceiling ();
1678}
1679
1688 os_thread_prio_t* old_prio_ceiling)
1689{
1690 assert (mutex != nullptr);
1691 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).prio_ceiling (
1692 prio_ceiling, old_prio_ceiling);
1693}
1694
1703{
1704 assert (mutex != nullptr);
1705 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).consistent ();
1706}
1707
1716{
1717 assert (mutex != nullptr);
1718 return (os_thread_t*) (reinterpret_cast<rtos::mutex&> (*mutex)).owner ();
1719}
1720
1729{
1730 assert (mutex != nullptr);
1731 return (reinterpret_cast<rtos::mutex&> (*mutex)).type ();
1732}
1733
1742{
1743 assert (mutex != nullptr);
1744 return (reinterpret_cast<rtos::mutex&> (*mutex)).protocol ();
1745}
1746
1755{
1756 assert (mutex != nullptr);
1757 return (reinterpret_cast<rtos::mutex&> (*mutex)).robustness ();
1758}
1759
1768{
1769 assert (mutex != nullptr);
1770 return (os_result_t) (reinterpret_cast<rtos::mutex&> (*mutex)).reset ();
1771}
1772
1773// ----------------------------------------------------------------------------
1774
1781void
1783{
1784 assert (attr != nullptr);
1785 new (attr) condition_variable::attributes ();
1786}
1787
1796void
1797os_condvar_construct (os_condvar_t* condvar, const char* name,
1798 const os_condvar_attr_t* attr)
1799{
1800 assert (condvar != nullptr);
1801 if (attr == nullptr)
1802 {
1804 }
1805 new (condvar) condition_variable (name,
1806 (const condition_variable::attributes&) *attr);
1807}
1808
1817void
1819{
1820 assert (condvar != nullptr);
1821 (reinterpret_cast<condition_variable&> (*condvar)).~condition_variable ();
1822}
1823
1838os_condvar_new (const char* name, const os_condvar_attr_t* attr)
1839{
1840 if (attr == nullptr)
1841 {
1843 }
1844 return reinterpret_cast<os_condvar_t*> (new condition_variable (
1845 name, (const condition_variable::attributes&) *attr));
1846}
1847
1861void
1863{
1864 assert (condvar != nullptr);
1865 delete reinterpret_cast<condition_variable*> (condvar);
1866}
1867
1874const char*
1876{
1877 assert (condvar != nullptr);
1878 return (reinterpret_cast<condition_variable&> (*condvar)).name ();
1879}
1880
1889{
1890 assert (condvar != nullptr);
1891 return (os_result_t) (reinterpret_cast<condition_variable&> (*condvar)).signal ();
1892}
1893
1902{
1903 assert (condvar != nullptr);
1904 return (os_result_t) (reinterpret_cast<condition_variable&> (*condvar)).broadcast ();
1905}
1906
1915{
1916 assert (condvar != nullptr);
1917 return (os_result_t) (reinterpret_cast<condition_variable&> (*condvar)).wait (
1918 reinterpret_cast<rtos::mutex&> (*mutex));
1919}
1920
1929 os_clock_duration_t timeout)
1930{
1931 assert (condvar != nullptr);
1932 return (os_result_t) (reinterpret_cast<condition_variable&> (*condvar)).timed_wait (
1933 reinterpret_cast<rtos::mutex&> (*mutex), timeout);
1934}
1935
1936// ----------------------------------------------------------------------------
1937
1944void
1946{
1947 assert (attr != nullptr);
1948 new (attr) semaphore::attributes
1949 { };
1950}
1951
1958void
1960 const os_semaphore_count_t initial_value)
1961{
1962 assert (attr != nullptr);
1964 { initial_value };
1965}
1966
1973void
1975 const os_semaphore_count_t max_value,
1976 const os_semaphore_count_t initial_value)
1977{
1978 assert (attr != nullptr);
1980 { max_value, initial_value };
1981}
1982
1991{
1993}
1994
2003void
2005 const os_semaphore_attr_t* attr)
2006{
2007 assert (semaphore != nullptr);
2008 if (attr == nullptr)
2009 {
2011 }
2013 { name, (const semaphore::attributes&) *attr };
2014}
2015
2024void
2026 const os_semaphore_count_t initial_value)
2027{
2028 assert (semaphore != nullptr);
2030 { name, initial_value };
2031}
2032
2041void
2043 const os_semaphore_count_t max_value,
2044 const os_semaphore_count_t initial_value)
2045{
2046 assert (semaphore != nullptr);
2048 { name, max_value, initial_value };
2049}
2050
2060void
2062{
2063 assert (semaphore != nullptr);
2064 (reinterpret_cast<rtos::semaphore&> (*semaphore)).~semaphore ();
2065}
2066
2081os_semaphore_new (const char* name, const os_semaphore_attr_t* attr)
2082{
2083 if (attr == nullptr)
2084 {
2086 }
2087 return reinterpret_cast<os_semaphore_t*> (new rtos::semaphore
2088 { name, (const semaphore::attributes&) *attr });
2089}
2090
2105os_semaphore_binary_new (const char* name,
2106 const os_semaphore_count_t initial_value)
2107{
2108 return reinterpret_cast<os_semaphore_t*> (new rtos::semaphore_binary
2109 { name, initial_value });
2110}
2111
2127 const os_semaphore_count_t max_value,
2128 const os_semaphore_count_t initial_value)
2129{
2130 return reinterpret_cast<os_semaphore_t*> (new rtos::semaphore_counting
2131 { name, max_value, initial_value });
2132}
2133
2148void
2150{
2151 assert (semaphore != nullptr);
2152 delete reinterpret_cast<rtos::semaphore*> (semaphore);
2153}
2154
2161const char*
2163{
2164 assert (semaphore != nullptr);
2165 return (reinterpret_cast<rtos::semaphore&> (*semaphore)).name ();
2166}
2167
2176{
2177 assert (semaphore != nullptr);
2178 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).post ();
2179}
2180
2189{
2190 assert (semaphore != nullptr);
2191 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).wait ();
2192}
2193
2202{
2203 assert (semaphore != nullptr);
2204 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).try_wait ();
2205}
2206
2215{
2216 assert (semaphore != nullptr);
2217 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).timed_wait (
2218 timeout);
2219}
2220
2229{
2230 assert (semaphore != nullptr);
2231 return (os_semaphore_count_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).value ();
2232}
2233
2242{
2243 assert (semaphore != nullptr);
2244 return (os_result_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).reset ();
2245}
2246
2255{
2256 assert (semaphore != nullptr);
2257 return (os_semaphore_count_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).initial_value ();
2258}
2259
2268{
2269 assert (semaphore != nullptr);
2270 return (os_semaphore_count_t) (reinterpret_cast<rtos::semaphore&> (*semaphore)).max_value ();
2271}
2272
2273// ----------------------------------------------------------------------------
2274
2281void
2283{
2284 assert (attr != nullptr);
2285 new (attr) memory_pool::attributes ();
2286}
2287
2296void
2297os_mempool_construct (os_mempool_t* mempool, const char* name, size_t blocks,
2298 size_t block_size_bytes, const os_mempool_attr_t* attr)
2299{
2300 assert (mempool != nullptr);
2301 if (attr == nullptr)
2302 {
2304 }
2305 new (mempool) memory_pool (name, blocks, block_size_bytes,
2306 (const memory_pool::attributes&) *attr);
2307}
2308
2317void
2319{
2320 assert (mempool != nullptr);
2321 (reinterpret_cast<memory_pool&> (*mempool)).~memory_pool ();
2322}
2323
2338os_mempool_new (const char* name, size_t blocks, size_t block_size_bytes,
2339 const os_mempool_attr_t* attr)
2340{
2341 if (attr == nullptr)
2342 {
2344 }
2345 return reinterpret_cast<os_mempool_t*> (new memory_pool (
2346 name, blocks, block_size_bytes, (const memory_pool::attributes&) *attr));
2347}
2348
2362void
2364{
2365 assert (mempool != nullptr);
2366 delete reinterpret_cast<memory_pool*> (mempool);
2367}
2368
2375const char*
2377{
2378 assert (mempool != nullptr);
2379 return (reinterpret_cast<memory_pool&> (*mempool)).name ();
2380}
2381
2388void*
2390{
2391 assert (mempool != nullptr);
2392 return (reinterpret_cast<memory_pool&> (*mempool)).alloc ();
2393}
2394
2401void*
2403{
2404 assert (mempool != nullptr);
2405 return (reinterpret_cast<memory_pool&> (*mempool)).try_alloc ();
2406}
2407
2414void*
2416{
2417 assert (mempool != nullptr);
2418 return (reinterpret_cast<memory_pool&> (*mempool)).timed_alloc (timeout);
2419}
2420
2428os_mempool_free (os_mempool_t* mempool, void* block)
2429{
2430 assert (mempool != nullptr);
2431 return (os_result_t) (reinterpret_cast<memory_pool&> (*mempool)).free (block);
2432}
2433
2440size_t
2442{
2443 assert (mempool != nullptr);
2444 return (reinterpret_cast<memory_pool&> (*mempool)).capacity ();
2445}
2446
2453size_t
2455{
2456 assert (mempool != nullptr);
2457 return (reinterpret_cast<memory_pool&> (*mempool)).count ();
2458}
2459
2466size_t
2468{
2469 assert (mempool != nullptr);
2470 return (reinterpret_cast<memory_pool&> (*mempool)).block_size ();
2471}
2472
2479bool
2481{
2482 assert (mempool != nullptr);
2483 return (reinterpret_cast<memory_pool&> (*mempool)).empty ();
2484}
2485
2492bool
2494{
2495 assert (mempool != nullptr);
2496 return (reinterpret_cast<memory_pool&> (*mempool)).full ();
2497}
2498
2507{
2508 assert (mempool != nullptr);
2509 return (os_result_t) (reinterpret_cast<memory_pool&> (*mempool)).reset ();
2510}
2511
2518void*
2520{
2521 assert (mempool != nullptr);
2522 return (void*) (reinterpret_cast<memory_pool&> (*mempool)).pool ();
2523}
2524
2525// --------------------------------------------------------------------------
2526
2533void
2535{
2536 assert (attr != nullptr);
2537 new (attr) message_queue::attributes ();
2538}
2539
2548void
2549os_mqueue_construct (os_mqueue_t* mqueue, const char* name, size_t msgs,
2550 size_t msg_size_bytes, const os_mqueue_attr_t* attr)
2551{
2552 assert (mqueue != nullptr);
2553 if (attr == nullptr)
2554 {
2556 }
2557 new (mqueue) message_queue (name, msgs, msg_size_bytes,
2558 (const message_queue::attributes&) *attr);
2559}
2560
2569void
2571{
2572 assert (mqueue != nullptr);
2573 (reinterpret_cast<message_queue&> (*mqueue)).~message_queue ();
2574}
2575
2590os_mqueue_new (const char* name, size_t msgs, size_t msg_size_bytes,
2591 const os_mqueue_attr_t* attr)
2592{
2593 if (attr == nullptr)
2594 {
2596 }
2597 return reinterpret_cast<os_mqueue_t*> (new message_queue (
2598 name, msgs, msg_size_bytes, (const message_queue::attributes&) *attr));
2599}
2600
2614void
2616{
2617 assert (mqueue != nullptr);
2618 delete reinterpret_cast<message_queue*> (mqueue);
2619}
2620
2627const char*
2629{
2630 assert (mqueue != nullptr);
2631 return (reinterpret_cast<message_queue&> (*mqueue)).name ();
2632}
2633
2641os_mqueue_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2642 os_mqueue_prio_t mprio)
2643{
2644 assert (mqueue != nullptr);
2645 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).send (
2646 msg, nbytes, mprio);
2647}
2648
2656os_mqueue_try_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2657 os_mqueue_prio_t mprio)
2658{
2659 assert (mqueue != nullptr);
2660 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).try_send (
2661 msg, nbytes, mprio);
2662}
2663
2671os_mqueue_timed_send (os_mqueue_t* mqueue, const void* msg, size_t nbytes,
2673{
2674 assert (mqueue != nullptr);
2675 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).timed_send (
2676 msg, nbytes, timeout, mprio);
2677}
2678
2686os_mqueue_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2687 os_mqueue_prio_t* mprio)
2688{
2689 assert (mqueue != nullptr);
2690 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).receive (
2691 msg, nbytes, mprio);
2692}
2693
2701os_mqueue_try_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2702 os_mqueue_prio_t* mprio)
2703{
2704 assert (mqueue != nullptr);
2705 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).try_receive (
2706 msg, nbytes, mprio);
2707}
2708
2716os_mqueue_timed_receive (os_mqueue_t* mqueue, void* msg, size_t nbytes,
2717 os_clock_duration_t timeout, os_mqueue_prio_t* mprio)
2718{
2719 assert (mqueue != nullptr);
2720 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).timed_receive (
2721 msg, nbytes, timeout, mprio);
2722}
2723
2730size_t
2732{
2733 assert (mqueue != nullptr);
2734 return (reinterpret_cast<message_queue&> (*mqueue)).length ();
2735}
2736
2743size_t
2745{
2746 assert (mqueue != nullptr);
2747 return (reinterpret_cast<message_queue&> (*mqueue)).capacity ();
2748}
2749
2756size_t
2758{
2759 assert (mqueue != nullptr);
2760 return (reinterpret_cast<message_queue&> (*mqueue)).msg_size ();
2761}
2762
2769bool
2771{
2772 assert (mqueue != nullptr);
2773 return (reinterpret_cast<message_queue&> (*mqueue)).empty ();
2774}
2775
2782bool
2784{
2785 assert (mqueue != nullptr);
2786 return (reinterpret_cast<message_queue&> (*mqueue)).full ();
2787}
2788
2797{
2798 assert (mqueue != nullptr);
2799 return (os_result_t) (reinterpret_cast<message_queue&> (*mqueue)).reset ();
2800}
2801
2802// --------------------------------------------------------------------------
2803
2810void
2812{
2813 assert (attr != nullptr);
2814 new (attr) event_flags::attributes ();
2815}
2816
2825void
2826os_evflags_construct (os_evflags_t* evflags, const char* name,
2827 const os_evflags_attr_t* attr)
2828{
2829 assert (evflags != nullptr);
2830 if (attr == nullptr)
2831 {
2833 }
2834 new (evflags) event_flags (name, (const event_flags::attributes&) *attr);
2835}
2836
2845void
2847{
2848 assert (evflags != nullptr);
2849 (reinterpret_cast<event_flags&> (*evflags)).~event_flags ();
2850}
2851
2866os_evflags_new (const char* name, const os_evflags_attr_t* attr)
2867{
2868 if (attr == nullptr)
2869 {
2871 }
2872 return reinterpret_cast<os_evflags_t*> (new event_flags (
2873 name, (const event_flags::attributes&) *attr));
2874}
2875
2889void
2891{
2892 assert (evflags != nullptr);
2893 delete reinterpret_cast<event_flags*> (evflags);
2894}
2895
2902const char*
2904{
2905 assert (evflags != nullptr);
2906 return (reinterpret_cast<event_flags&> (*evflags)).name ();
2907}
2908
2917 os_flags_mask_t* oflags, os_flags_mode_t mode)
2918{
2919 assert (evflags != nullptr);
2920 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).wait (mask,
2921 oflags,
2922 mode);
2923}
2924
2933 os_flags_mask_t* oflags, os_flags_mode_t mode)
2934{
2935 assert (evflags != nullptr);
2936 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).try_wait (
2937 mask, oflags, mode);
2938}
2939
2948 os_clock_duration_t timeout, os_flags_mask_t* oflags,
2949 os_flags_mode_t mode)
2950{
2951 assert (evflags != nullptr);
2952 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).timed_wait (
2953 mask, timeout, oflags, mode);
2954}
2955
2964 os_flags_mask_t* oflags)
2965{
2966 assert (evflags != nullptr);
2967 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).raise (
2968 mask, oflags);
2969}
2970
2979 os_flags_mask_t* oflags)
2980{
2981 assert (evflags != nullptr);
2982 return (os_result_t) (reinterpret_cast<event_flags&> (*evflags)).clear (
2983 mask, oflags);
2984}
2985
2994 os_flags_mode_t mode)
2995{
2996 assert (evflags != nullptr);
2997 return (os_flags_mask_t) (reinterpret_cast<event_flags&> (*evflags)).get (
2998 mask, mode);
2999}
3000
3007bool
3009{
3010 assert (evflags != nullptr);
3011 return (reinterpret_cast<event_flags&> (*evflags)).waiting ();
3012}
3013
3014// --------------------------------------------------------------------------
3015
3024{
3025 return reinterpret_cast<os_memory_t*> (rtos::memory::get_default_resource ());
3026}
3027
3035void*
3036os_memory_allocate (os_memory_t* memory, size_t bytes, size_t alignment)
3037{
3038 assert (memory != nullptr);
3039#pragma GCC diagnostic push
3040#pragma GCC diagnostic ignored "-Wcast-align"
3041 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).allocate (
3042 bytes, alignment);
3043#pragma GCC diagnostic pop
3044}
3045
3053void
3054os_memory_deallocate (os_memory_t* memory, void* addr, size_t bytes,
3055 size_t alignment)
3056{
3057 assert (memory != nullptr);
3058#pragma GCC diagnostic push
3059#pragma GCC diagnostic ignored "-Wcast-align"
3060 (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).deallocate (
3061 addr, bytes, alignment);
3062#pragma GCC diagnostic pop
3063}
3064
3072void
3074{
3075 assert (memory != nullptr);
3076#pragma GCC diagnostic push
3077#pragma GCC diagnostic ignored "-Wcast-align"
3078 (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).reset ();
3079#pragma GCC diagnostic pop
3080}
3081
3089bool
3091{
3092 assert (memory != nullptr);
3093#pragma GCC diagnostic push
3094#pragma GCC diagnostic ignored "-Wcast-align"
3095 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).coalesce ();
3096#pragma GCC diagnostic pop
3097}
3098
3106size_t
3108{
3109 assert (memory != nullptr);
3110#pragma GCC diagnostic push
3111#pragma GCC diagnostic ignored "-Wcast-align"
3112 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).total_bytes ();
3113#pragma GCC diagnostic pop
3114}
3115
3123size_t
3125{
3126 assert (memory != nullptr);
3127#pragma GCC diagnostic push
3128#pragma GCC diagnostic ignored "-Wcast-align"
3129 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).allocated_bytes ();
3130#pragma GCC diagnostic pop
3131}
3132
3140size_t
3142{
3143 assert (memory != nullptr);
3144#pragma GCC diagnostic push
3145#pragma GCC diagnostic ignored "-Wcast-align"
3146 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).free_bytes ();
3147#pragma GCC diagnostic pop
3148}
3149
3157size_t
3159{
3160 assert (memory != nullptr);
3161#pragma GCC diagnostic push
3162#pragma GCC diagnostic ignored "-Wcast-align"
3163 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).allocated_chunks ();
3164#pragma GCC diagnostic pop
3165}
3166
3174size_t
3176{
3177 assert (memory != nullptr);
3178#pragma GCC diagnostic push
3179#pragma GCC diagnostic ignored "-Wcast-align"
3180 return (reinterpret_cast<rtos::memory::memory_resource&> (*memory)).free_chunks ();
3181#pragma GCC diagnostic pop
3182}
3183
3184// ****************************************************************************
3185// ***** Legacy CMSIS RTOS implementation *****
3186
3188
3189// ----------------------------------------------------------------------------
3190// ==== Kernel Control Functions ====
3191
3216{
3218 {
3219 return osErrorISR;
3220 }
3221
3223 return osOK;
3224}
3225
3238{
3240 // In µOS++ this does not return.
3241}
3242
3251int32_t
3253{
3254 return scheduler::started () ? 1 : 0;
3255}
3256
3257#if (defined (osFeature_SysTick) && (osFeature_SysTick != 0))
3258
3272uint32_t
3273osKernelSysTick (void)
3274{
3275 // Get the current SysTick timestamp down to cpu cycles.
3276 return static_cast<uint32_t> (hrclock.now ());
3277}
3278
3279#endif // System Timer available
3280
3281// ----------------------------------------------------------------------------
3282// ==== Thread Management ====
3283
3299osThreadCreate (const osThreadDef_t* thread_def, void* args)
3300{
3302 {
3303 return nullptr;
3304 }
3305
3306 if (thread_def == nullptr)
3307 {
3308 return nullptr;
3309 }
3310
3311 thread::attributes attr;
3312 attr.th_priority = thread_def->tpriority;
3313 attr.th_stack_size_bytes = thread_def->stacksize;
3314
3315 // Creating thread with invalid priority should fail (validator requirement).
3316 if (thread_def->tpriority >= osPriorityError)
3317 {
3318 return nullptr;
3319 }
3320
3321 // Find a free slot in the tread definitions array.
3322 for (uint32_t i = 0; i < thread_def->instances; ++i)
3323 {
3324 thread* th = (thread*) &thread_def->data[i];
3325 if (th->state () == thread::state::undefined
3326 || th->state () == thread::state::destroyed)
3327 {
3328 if (attr.th_stack_size_bytes > 0)
3329 {
3330 attr.th_stack_address = &thread_def->stack[(i)
3331 * ((thread_def->stacksize + sizeof(uint64_t) - 1)
3332 / sizeof(uint64_t))];
3333 }
3334#pragma GCC diagnostic push
3335#if defined(__clang__)
3336#pragma clang diagnostic ignored "-Wcast-function-type"
3337#elif defined(__GNUC__)
3338#pragma GCC diagnostic ignored "-Wcast-function-type"
3339#endif
3340 new (th) thread (thread_def->name,
3341 reinterpret_cast<thread::func_t> (thread_def->pthread), args, attr);
3342#pragma GCC diagnostic pop
3343
3344 // No need to yield here, already done by constructor.
3345 return reinterpret_cast<osThreadId> (th);
3346 }
3347 }
3348 return nullptr;
3349}
3350
3359{
3361 {
3362 return nullptr;
3363 }
3364
3365 return reinterpret_cast<osThreadId> (&this_thread::thread ());
3366}
3367
3381{
3383 {
3384 return osErrorISR;
3385 }
3386
3387 if (thread_id == nullptr)
3388 {
3389 return osErrorParameter;
3390 }
3391
3392 thread::state_t state =
3393 (reinterpret_cast<rtos::thread&> (*thread_id)).state ();
3394 if (state == thread::state::undefined)
3395 {
3396 return osErrorResource;
3397 }
3398
3399 if ((reinterpret_cast<thread*> (thread_id)) == &this_thread::thread ())
3400 {
3401 this_thread::exit ();
3402 /* NOTREACHED */
3403 }
3404 else
3405 {
3406 (reinterpret_cast<rtos::thread&> (*thread_id)).kill ();
3407 }
3408
3409 return osOK;
3410}
3411
3422{
3424 {
3425 return osErrorISR;
3426 }
3427
3429
3430 return osOK;
3431}
3432
3443{
3445 {
3446 return osErrorISR;
3447 }
3448
3449 if (thread_id == nullptr)
3450 {
3451 return osErrorParameter;
3452 }
3453
3454 thread::state_t state =
3455 (reinterpret_cast<rtos::thread&> (*thread_id)).state ();
3456 if (state == thread::state::undefined || state >= thread::state::destroyed)
3457 {
3458 return osErrorResource;
3459 }
3460
3461 if (priority < osPriorityIdle || priority >= osPriorityError)
3462 {
3463 return osErrorValue;
3464 }
3465
3466 // Call C++ mutator.
3467 thread::priority_t prio = static_cast<thread::priority_t> (priority);
3468 result_t res =
3469 ((reinterpret_cast<rtos::thread&> (*thread_id)).priority (prio));
3470
3471 // A mandatory yield is needed here, must be done
3472 // by the implementation.
3473
3474 if (res == result::ok)
3475 {
3476 return osOK;
3477 }
3478 else if (res == EINVAL)
3479 {
3480 return osErrorValue;
3481 }
3482 else
3483 {
3484 return osErrorOS;
3485 }
3486}
3487
3497{
3499 {
3500 return osPriorityError;
3501 }
3502
3503 if (thread_id == nullptr)
3504 {
3505 return osPriorityError;
3506 }
3507
3508 // Call C++ accessor.
3509 thread::priority_t prio =
3510 (reinterpret_cast<rtos::thread&> (*thread_id)).priority ();
3511 return static_cast<osPriority> (prio);
3512}
3513
3514// ----------------------------------------------------------------------------
3515// ==== Generic Wait Functions ====
3516
3531osDelay (uint32_t millisec)
3532{
3534 {
3535 return osErrorISR;
3536 }
3537
3539 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
3540
3541 if (res == ETIMEDOUT)
3542 {
3543 return osEventTimeout;
3544 }
3545 else
3546 {
3547 return osErrorOS;
3548 }
3549}
3550
3551#if (defined (osFeature_Wait) && (osFeature_Wait != 0))
3552
3553#pragma GCC diagnostic push
3554#if defined(__clang__)
3555#elif defined(__GNUC__)
3556#pragma GCC diagnostic ignored "-Waggregate-return"
3557#endif
3558
3576osEvent
3577osWait (uint32_t millisec)
3578{
3579 osEvent event;
3580
3582 {
3583 event.status = osErrorISR;
3584 return event;
3585 }
3586
3587 result_t res = sysclock.wait_for (
3588 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
3589
3590 // TODO: return events
3591 if (res == ETIMEDOUT)
3592 {
3593 event.status = osEventTimeout;
3594 }
3595 else
3596 {
3597 event.status = osErrorOS;
3598 }
3599
3600 return event;
3601}
3602
3603#pragma GCC diagnostic pop
3604
3605#endif // Generic Wait available
3606
3607// ----------------------------------------------------------------------------
3608// ==== Timer Management Functions ====
3609
3619osTimerCreate (const osTimerDef_t* timer_def, os_timer_type type, void* args)
3620{
3622 {
3623 return nullptr;
3624 }
3625
3626 if (timer_def == nullptr)
3627 {
3628 return nullptr;
3629 }
3630
3631 timer::attributes attr;
3632 attr.tm_type = (timer::type_t) type;
3633
3634 new ((void*) timer_def->data) timer (timer_def->name,
3635 (timer::func_t) timer_def->ptimer,
3636 (timer::func_args_t) args, attr);
3637
3638 return reinterpret_cast<osTimerId> (timer_def->data);
3639}
3640
3648osTimerStart (osTimerId timer_id, uint32_t millisec)
3649{
3651 {
3652 return osErrorISR;
3653 }
3654
3655 if (timer_id == nullptr)
3656 {
3657 return osErrorParameter;
3658 }
3659
3660 result_t res = (reinterpret_cast<rtos::timer&> (*timer_id)).start (
3661 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
3662
3663 if (res == result::ok)
3664 {
3665 return osOK;
3666 }
3667 else
3668 {
3669 return osErrorOS;
3670 }
3671}
3672
3678{
3680 {
3681 return osErrorISR;
3682 }
3683
3684 if (timer_id == nullptr)
3685 {
3686 return osErrorParameter;
3687 }
3688
3689 result_t res = (reinterpret_cast<rtos::timer&> (*timer_id)).stop ();
3690 if (res == result::ok)
3691 {
3692 return osOK;
3693 }
3694 else if (res == EAGAIN)
3695 {
3696 return osErrorResource;
3697 }
3698 else
3699 {
3700 return osErrorOS;
3701 }
3702}
3703
3712{
3714 {
3715 return osErrorISR;
3716 }
3717
3718 if (timer_id == nullptr)
3719 {
3720 return osErrorParameter;
3721 }
3722
3723 (reinterpret_cast<rtos::timer&> (*timer_id)).~timer ();
3724 return osOK;
3725}
3726
3727// ----------------------------------------------------------------------------
3728// ==== Signal Management ====
3729
3736int32_t
3737osSignalSet (osThreadId thread_id, int32_t signals)
3738{
3739 if (thread_id == nullptr)
3740 {
3741 return (int32_t) 0x80000000;
3742 }
3743
3744 if (signals == (int32_t) 0x80000000)
3745 {
3746 return (int32_t) 0x80000000;
3747 }
3748
3749 flags::mask_t osig;
3750 ((thread*) (thread_id))->flags_raise ((flags::mask_t) signals, &osig);
3751 return (int32_t) osig;
3752}
3753
3760int32_t
3761osSignalClear (osThreadId thread_id, int32_t signals)
3762{
3763 if (thread_id == nullptr)
3764 {
3765 return (int32_t) 0x80000000;
3766 }
3767
3768 if (interrupts::in_handler_mode () || (signals == 0))
3769 {
3770 return (int32_t) 0x80000000;
3771 }
3772
3773 flags::mask_t sig;
3774
3775#if defined(OS_INCLUDE_RTOS_THREAD_PUBLIC_FLAGS_CLEAR)
3776 ((thread*) (thread_id))->flags_clear ((flags::mask_t) signals, &sig);
3777#else
3778 assert(((thread* ) (thread_id)) == &this_thread::thread ());
3779 // IGNORE THREAD ID!
3780 this_thread::flags_clear ((flags::mask_t) signals, &sig);
3781#endif
3782 return (int32_t) sig;
3783}
3784
3785#pragma GCC diagnostic push
3786#if defined(__clang__)
3787#elif defined(__GNUC__)
3788#pragma GCC diagnostic ignored "-Waggregate-return"
3789#endif
3790
3813osEvent
3814osSignalWait (int32_t signals, uint32_t millisec)
3815{
3816 osEvent event;
3817
3819 {
3820 event.status = osErrorISR;
3821 return event;
3822 }
3823
3824 if ((uint32_t) signals & 0x80000000)
3825 {
3826 event.status = osErrorValue;
3827 return event;
3828 }
3829
3830 result_t res;
3831 if (millisec == osWaitForever)
3832 {
3833 res = this_thread::flags_wait ((flags::mask_t) signals,
3834 (flags::mask_t*) &event.value.signals);
3835 }
3836 else if (millisec == 0)
3837 {
3838 res = this_thread::flags_try_wait ((flags::mask_t) signals,
3839 (flags::mask_t*) &event.value.signals);
3840 }
3841 else
3842 {
3843 res = this_thread::flags_timed_wait (
3844 (flags::mask_t) signals,
3845 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)),
3846 (flags::mask_t*) &event.value.signals);
3847 }
3848
3849 if (res == result::ok)
3850 {
3851 event.status = osEventSignal;
3852 }
3853 else if (res == EWOULDBLOCK)
3854 {
3855 event.status = osOK; // Only for try_flags_wait().
3856 }
3857 else if (res == ETIMEDOUT)
3858 {
3859 event.status = osEventTimeout; // Only for timed_flags_wait().
3860 }
3861 else if (res == EPERM)
3862 {
3863 event.status = osErrorISR;
3864 }
3865 else if (res == EINVAL)
3866 {
3867 event.status = osErrorValue;
3868 }
3869 else
3870 {
3871 event.status = osErrorOS;
3872 }
3873
3874 return event;
3875}
3876
3877#pragma GCC diagnostic pop
3878
3879// ----------------------------------------------------------------------------
3880
3881// ==== Mutex Management ====
3882
3890osMutexCreate (const osMutexDef_t* mutex_def)
3891{
3893 {
3894 return nullptr;
3895 }
3896
3897 if (mutex_def == nullptr)
3898 {
3899 return nullptr;
3900 }
3901
3902 mutex::attributes attr;
3905
3906 new ((void*) mutex_def->data) mutex (mutex_def->name, attr);
3907
3908 return reinterpret_cast<osMutexId> (mutex_def->data);
3909}
3910
3930osMutexWait (osMutexId mutex_id, uint32_t millisec)
3931{
3933 {
3934 return osErrorISR;
3935 }
3936
3937 if (mutex_id == nullptr)
3938 {
3939 return osErrorParameter;
3940 }
3941
3942 result_t ret;
3943 if (millisec == osWaitForever)
3944 {
3945 ret = (reinterpret_cast<rtos::mutex&> (*mutex_id)).lock ();
3946 // osErrorResource:
3947 }
3948 else if (millisec == 0)
3949 {
3950 ret = (reinterpret_cast<rtos::mutex&> (*mutex_id)).try_lock ();
3951 }
3952 else
3953 {
3954 ret = (reinterpret_cast<rtos::mutex&> (*mutex_id)).timed_lock (
3955 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
3956 // osErrorTimeoutResource:
3957 }
3958
3959 if (ret == result::ok)
3960 {
3961 // osOK: the mutex has been obtained.
3962 return osOK;
3963 }
3964 else if (ret == EWOULDBLOCK)
3965 {
3966 // The mutex could not be obtained when no timeout was specified.
3967 // Only for try_lock().
3968 return osErrorResource;
3969 }
3970 else if (ret == ENOTRECOVERABLE)
3971 {
3972 // The mutex could not be obtained when no timeout was specified.
3973 // Only for lock().
3974 return osErrorResource;
3975 }
3976 else if (ret == ETIMEDOUT)
3977 {
3978 // The mutex could not be obtained in the given time.
3979 // Only for timed_lock().
3981 }
3982 else
3983 {
3984 return osErrorOS;
3985 }
3986
3987 /* NOTREACHED */
3988}
3989
4000{
4002 {
4003 return osErrorISR;
4004 }
4005
4006 if (mutex_id == nullptr)
4007 {
4008 return osErrorParameter;
4009 }
4010
4011 result_t res;
4012 res = (reinterpret_cast<rtos::mutex&> (*mutex_id)).unlock ();
4013
4014 if (res == result::ok)
4015 {
4016 return osOK;
4017 }
4018 else if ((res == EPERM) || (res == ENOTRECOVERABLE))
4019 {
4020 return osErrorResource;
4021 }
4022 else
4023 {
4024 return osErrorOS;
4025 }
4026}
4027
4039{
4041 {
4042 return osErrorISR;
4043 }
4044
4045 if (mutex_id == nullptr)
4046 {
4047 return osErrorParameter;
4048 }
4049
4050 (reinterpret_cast<rtos::mutex&> (*mutex_id)).~mutex ();
4051 return osOK;
4052}
4053
4054// ----------------------------------------------------------------------------
4055
4056// ==== Semaphore Management Functions ====
4057
4058#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0))
4059
4070osSemaphoreCreate (const osSemaphoreDef_t* semaphore_def, int32_t count)
4071{
4073 {
4074 return nullptr;
4075 }
4076
4077 if (semaphore_def == nullptr)
4078 {
4079 return nullptr;
4080 }
4081
4083 attr.sm_initial_value = (semaphore::count_t) count;
4084 // The logic is very strange, the CMSIS expects both the max-count to be the
4085 // same as count, and also to accept a count of 0, which leads to
4086 // useless semaphores. We patch this behaviour in the wrapper, the main
4087 // object uses a more realistic max_value.
4089 count == 0 ? osFeature_Semaphore : count);
4090
4091 new ((void*) semaphore_def->data) semaphore (semaphore_def->name, attr);
4092
4093 return reinterpret_cast<osSemaphoreId> (semaphore_def->data);
4094}
4095
4118int32_t
4119osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec)
4120{
4122 {
4123 return -1;
4124 }
4125
4126 if (semaphore_id == nullptr)
4127 {
4128 return -1;
4129 }
4130
4131 result_t res;
4132 if (millisec == osWaitForever)
4133 {
4134 res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).wait ();
4135 }
4136 else if (millisec == 0)
4137 {
4138 res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).try_wait ();
4139 if (res == EWOULDBLOCK)
4140 {
4141 return 0;
4142 }
4143 }
4144 else
4145 {
4146 res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).timed_wait (
4147 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
4148 if (res == ETIMEDOUT)
4149 {
4150 return 0;
4151 }
4152 }
4153
4154 if (res == 0)
4155 {
4156 int count =
4157 (int32_t) (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).value ();
4158 return count + 1;
4159 }
4160 else
4161 {
4162 return -1;
4163 }
4164}
4165
4174osSemaphoreRelease (osSemaphoreId semaphore_id)
4175{
4176 if (semaphore_id == nullptr)
4177 {
4178 return osErrorParameter;
4179 }
4180
4181 if ((reinterpret_cast<rtos::semaphore&> (*semaphore_id)).initial_value ()
4182 == 0)
4183 {
4184 return osErrorResource;
4185 }
4186
4187 result_t res = (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).post ();
4188
4189 if (res == result::ok)
4190 {
4191 return osOK;
4192 }
4193 else if (res == EAGAIN)
4194 {
4195 return osErrorResource;
4196 }
4197 else
4198 {
4199 return osErrorOS;
4200 }
4201}
4202
4213osSemaphoreDelete (osSemaphoreId semaphore_id)
4214{
4216 {
4217 return osErrorISR;
4218 }
4219
4220 if (semaphore_id == nullptr)
4221 {
4222 return osErrorParameter;
4223 }
4224
4225 (reinterpret_cast<rtos::semaphore&> (*semaphore_id)).~semaphore ();
4226 return osOK;
4227}
4228
4229#endif /* Semaphore available */
4230
4231// ----------------------------------------------------------------------------
4232// ==== Memory Pool Management Functions ====
4233
4234#if (defined (osFeature_Pool) && (osFeature_Pool != 0))
4235
4243osPoolCreate (const osPoolDef_t* pool_def)
4244{
4246 {
4247 return nullptr;
4248 }
4249
4250 if (pool_def == nullptr)
4251 {
4252 return nullptr;
4253 }
4254
4256 attr.mp_pool_address = pool_def->pool;
4257 attr.mp_pool_size_bytes = pool_def->pool_sz;
4258
4259 new ((void*) pool_def->data) memory_pool (pool_def->name,
4260 (std::size_t) pool_def->items,
4261 (std::size_t) pool_def->item_sz,
4262 attr);
4263
4264 return reinterpret_cast<osPoolId> (pool_def->data);
4265}
4266
4273void*
4274osPoolAlloc (osPoolId pool_id)
4275{
4276 if (pool_id == nullptr)
4277 {
4278 return nullptr;
4279 }
4280
4281 return (reinterpret_cast<memory_pool&> (*pool_id)).try_alloc ();
4282}
4283
4290void*
4291osPoolCAlloc (osPoolId pool_id)
4292{
4293 if (pool_id == nullptr)
4294 {
4295 return nullptr;
4296 }
4297
4298 void* ret;
4299 ret = (reinterpret_cast<memory_pool&> (*pool_id)).try_alloc ();
4300 if (ret != nullptr)
4301 {
4302 memset (ret, 0,
4303 (reinterpret_cast<memory_pool&> (*pool_id)).block_size ());
4304 }
4305
4306 return ret;
4307}
4308
4316osPoolFree (osPoolId pool_id, void* block)
4317{
4318 if (pool_id == nullptr)
4319 {
4320 return osErrorParameter;
4321 }
4322
4323 if (block == nullptr)
4324 {
4325 return osErrorParameter;
4326 }
4327
4328 result_t res;
4329 res = (reinterpret_cast<memory_pool&> (*pool_id)).free (block);
4330
4331 if (res == result::ok)
4332 {
4333 return osOK;
4334 }
4335 else if (res == EINVAL)
4336 {
4337 return osErrorValue;
4338 }
4339 else
4340 {
4341 return osErrorOS;
4342 }
4343}
4344
4345#endif /* Memory Pool Management available */
4346
4347// ----------------------------------------------------------------------------
4348// ==== Message Queue Management Functions ====
4349
4350#if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0))
4351
4359osMessageCreate (const osMessageQDef_t* queue_def,
4360 osThreadId thread_id __attribute__((unused)))
4361{
4363 {
4364 return nullptr;
4365 }
4366
4367 if (queue_def == nullptr)
4368 {
4369 return nullptr;
4370 }
4371
4373 attr.mq_queue_address = queue_def->queue;
4374 attr.mq_queue_size_bytes = queue_def->queue_sz;
4375
4376 new ((void*) queue_def->data) message_queue (queue_def->name,
4377 (std::size_t) queue_def->items,
4378 (std::size_t) queue_def->item_sz,
4379 attr);
4380
4381 return reinterpret_cast<osMessageQId> (queue_def->data);
4382}
4383
4401osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec)
4402{
4403#pragma GCC diagnostic push
4404#if defined ( __clang__ )
4405#pragma clang diagnostic ignored "-Wint-to-pointer-cast"
4406#endif
4407
4408 if (queue_id == nullptr)
4409 {
4410 return osErrorParameter;
4411 }
4412
4413 result_t res;
4414 if (millisec == osWaitForever)
4415 {
4417 {
4418 return osErrorParameter;
4419 }
4420 res = (reinterpret_cast<message_queue&> (*queue_id)).send (
4421 (const char*) &info, sizeof(uint32_t), 0);
4422 // osOK, osErrorResource, osErrorParameter
4423 }
4424 else if (millisec == 0)
4425 {
4426 res = (reinterpret_cast<message_queue&> (*queue_id)).try_send (
4427 (const char*) &info, sizeof(uint32_t), 0);
4428 // osOK, osErrorResource, osErrorParameter
4429 }
4430 else
4431 {
4433 {
4434 return osErrorParameter;
4435 }
4436 res = (reinterpret_cast<message_queue&> (*queue_id)).timed_send (
4437 (const char*) &info, sizeof(uint32_t),
4438 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)), 0);
4439 // osOK, osErrorTimeoutResource, osErrorParameter
4440 }
4441
4442 if (res == result::ok)
4443 {
4444 // The message was put into the queue.
4445 return osOK;
4446 }
4447 else if (res == EWOULDBLOCK)
4448 {
4449 // No memory in the queue was available
4450 return osErrorResource;
4451 }
4452 else if (res == ETIMEDOUT)
4453 {
4454 // No memory in the queue was available during the given time limit.
4456 }
4457 else if (res == EINVAL || res == EMSGSIZE)
4458 {
4459 // A parameter is invalid or outside of a permitted range.
4460 return osErrorParameter;
4461 }
4462 else
4463 {
4464 return osErrorOS;
4465 }
4466
4467#pragma GCC diagnostic pop
4468}
4469
4470#pragma GCC diagnostic push
4471#if defined(__clang__)
4472#elif defined(__GNUC__)
4473#pragma GCC diagnostic ignored "-Waggregate-return"
4474#endif
4475
4494osEvent
4495osMessageGet (osMessageQId queue_id, uint32_t millisec)
4496{
4497 osEvent event;
4498 result_t res;
4499
4500 if (queue_id == nullptr)
4501 {
4502 event.status = osErrorParameter;
4503 return event;
4504 }
4505
4506 if (millisec == osWaitForever)
4507 {
4509 {
4510 event.status = osErrorParameter;
4511 return event;
4512 }
4513 res = (reinterpret_cast<message_queue&> (*queue_id)).receive (
4514 (char*) &event.value.v, sizeof(uint32_t), nullptr);
4515 // result::event_message;
4516 }
4517 else if (millisec == 0)
4518 {
4519 res = (reinterpret_cast<message_queue&> (*queue_id)).try_receive (
4520 (char*) &event.value.v, sizeof(uint32_t), nullptr);
4521 // result::event_message when message;
4522 // result::ok when no meessage
4523 }
4524 else
4525 {
4527 {
4528 event.status = osErrorParameter;
4529 return event;
4530 }
4531 res = (reinterpret_cast<message_queue&> (*queue_id)).timed_receive (
4532 (char*) &event.value.v, sizeof(uint32_t),
4533 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)), nullptr);
4534 // result::event_message when message;
4535 // result::event_timeout when timeout;
4536 }
4537
4538 if (res == result::ok)
4539 {
4540 // Message received, value.p contains the pointer to message.
4541 event.status = osEventMessage;
4542 }
4543 else if (res == ETIMEDOUT)
4544 {
4545 // No message has arrived during the given timeout period.
4546 event.status = osEventTimeout;
4547 }
4548 else if (res == EINVAL || res == EMSGSIZE)
4549 {
4550 // A parameter is invalid or outside of a permitted range.
4551 event.status = osErrorParameter;
4552 }
4553 else if (res == EWOULDBLOCK)
4554 {
4555 // No message is available in the queue and no timeout was specified.
4556 event.status = osOK;
4557 }
4558 else
4559 {
4560 event.status = osErrorOS;
4561 }
4562
4563 return event;
4564}
4565
4566#pragma GCC diagnostic pop
4567
4568#endif /* Message Queues available */
4569
4570// ----------------------------------------------------------------------------
4571// ==== Mail Queue Management Functions ====
4572
4573#if (defined (osFeature_MailQ) && (osFeature_MailQ != 0))
4574
4582osMailCreate (const osMailQDef_t* mail_def,
4583 osThreadId thread_id __attribute__((unused)))
4584{
4586 {
4587 return nullptr;
4588 }
4589
4590 if (mail_def == nullptr)
4591 {
4592 return nullptr;
4593 }
4594
4595 memory_pool::attributes pool_attr;
4596 pool_attr.mp_pool_address = mail_def->pool;
4597 pool_attr.mp_pool_size_bytes = mail_def->pool_sz;
4598 new ((void*) &mail_def->data->pool) memory_pool (
4599 mail_def->name, (std::size_t) mail_def->items,
4600 (std::size_t) mail_def->pool_item_sz, pool_attr);
4601
4602 message_queue::attributes queue_attr;
4603 queue_attr.mq_queue_address = mail_def->queue;
4604 queue_attr.mq_queue_size_bytes = mail_def->queue_sz;
4605 new ((void*) &mail_def->data->queue) message_queue (
4606 mail_def->name, (std::size_t) mail_def->items,
4607 (std::size_t) mail_def->queue_item_sz, queue_attr);
4608
4609 return (osMailQId) (mail_def->data);
4610}
4611
4635void*
4636osMailAlloc (osMailQId mail_id, uint32_t millisec)
4637{
4638 if (mail_id == nullptr)
4639 {
4640 return nullptr;
4641 }
4642
4643 void* ret = nullptr;
4644
4645#pragma GCC diagnostic push
4646#if defined(__clang__)
4647#elif defined(__GNUC__)
4648#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4649#endif
4650 if (millisec == osWaitForever)
4651 {
4653 {
4654 return nullptr;
4655 }
4656 ret = (reinterpret_cast<memory_pool&> (mail_id->pool)).alloc ();
4657 }
4658 else if (millisec == 0)
4659 {
4660 ret = (reinterpret_cast<memory_pool&> (mail_id->pool)).try_alloc ();
4661 }
4662 else
4663 {
4665 {
4666 return nullptr;
4667 }
4668 ret = (reinterpret_cast<memory_pool&> (mail_id->pool)).timed_alloc (
4669 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)));
4670 }
4671#pragma GCC diagnostic pop
4672 return ret;
4673}
4674
4698void*
4699osMailCAlloc (osMailQId mail_id, uint32_t millisec)
4700{
4701 void* ret = osMailAlloc (mail_id, millisec);
4702 if (ret != nullptr)
4703 {
4704#pragma GCC diagnostic push
4705#if defined(__clang__)
4706#elif defined(__GNUC__)
4707#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4708#endif
4709 memset (ret, 0,
4710 (reinterpret_cast<memory_pool&> (mail_id->pool)).block_size ());
4711#pragma GCC diagnostic pop
4712 }
4713 return ret;
4714}
4715
4724osMailPut (osMailQId mail_id, void* mail)
4725{
4726 if (mail_id == nullptr)
4727 {
4728 return osErrorParameter;
4729 }
4730 if (mail == nullptr)
4731 {
4732 return osErrorValue;
4733 }
4734
4735 // Validate pointer.
4736 memory_pool* pool = reinterpret_cast<memory_pool*> (&mail_id->pool);
4737 if (((char*) mail < (char*) (pool->pool ()))
4738 || (((char*) mail)
4739 >= ((char*) (pool->pool ()) + pool->capacity () * pool->block_size ())))
4740 {
4741 return osErrorValue;
4742 }
4743
4744 result_t res;
4745#pragma GCC diagnostic push
4746#if defined(__clang__)
4747#elif defined(__GNUC__)
4748#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4749#endif
4750 res = (reinterpret_cast<message_queue&> (mail_id->queue)).try_send (
4751 (const char*) &mail, sizeof(void*), 0);
4752#pragma GCC diagnostic pop
4753 if (res == result::ok)
4754 {
4755 return osOK;
4756 }
4757 else
4758 {
4759 return osErrorOS;
4760 }
4761}
4762
4763#pragma GCC diagnostic push
4764#if defined(__clang__)
4765#elif defined(__GNUC__)
4766#pragma GCC diagnostic ignored "-Waggregate-return"
4767#endif
4768#pragma GCC diagnostic ignored "-Wstrict-aliasing"
4769
4788osEvent
4789osMailGet (osMailQId mail_id, uint32_t millisec)
4790{
4791 osEvent event;
4792 result_t res;
4793
4794 if (mail_id == nullptr)
4795 {
4796 event.status = osErrorParameter;
4797 return event;
4798 }
4799
4800 if (millisec == osWaitForever)
4801 {
4803 {
4804 event.status = osErrorParameter;
4805 return event;
4806 }
4807 res = (reinterpret_cast<message_queue&> ((mail_id->queue))).receive (
4808 (char*) &event.value.p, sizeof(void*), nullptr);
4809 // osEventMail for ok,
4810 }
4811 else if (millisec == 0)
4812 {
4813 res = (reinterpret_cast<message_queue&> (mail_id->queue)).try_receive (
4814 (char*) &event.value.p, sizeof(void*), nullptr);
4815 // osEventMail for ok,
4816 }
4817 else
4818 {
4820 {
4821 event.status = osErrorParameter;
4822 return event;
4823 }
4824 res = (reinterpret_cast<message_queue&> (mail_id->queue)).timed_receive (
4825 (char*) &event.value.p, sizeof(void*),
4826 clock_systick::ticks_cast ((uint64_t) (millisec * 1000u)), nullptr);
4827 // osEventMail for ok, osEventTimeout
4828 }
4829
4830 if (res == result::ok)
4831 {
4832 // Mail received, value.p contains the pointer to mail content.
4833 event.status = osEventMail;
4834 }
4835 else if (res == EWOULDBLOCK)
4836 {
4837 // No mail is available in the queue and no timeout was specified.
4838 event.status = osOK;
4839 }
4840 else if (res == EINVAL || res == EMSGSIZE)
4841 {
4842 // A parameter is invalid or outside of a permitted range.
4843 event.status = osErrorParameter;
4844 }
4845 else if (res == ETIMEDOUT)
4846 {
4847 // No mail has arrived during the given timeout period.
4848 event.status = osEventTimeout;
4849 }
4850 else
4851 {
4852 event.status = osErrorOS;
4853 }
4854
4855 return event;
4856}
4857
4858#pragma GCC diagnostic pop
4859
4867osMailFree (osMailQId mail_id, void* mail)
4868{
4869 if (mail_id == nullptr)
4870 {
4871 return osErrorParameter;
4872 }
4873 if (mail == nullptr)
4874 {
4875 return osErrorValue;
4876 }
4877
4878 return osPoolFree (&(mail_id->pool), mail);
4879}
4880
4881#endif /* Mail Queues available */
4882
4883// ----------------------------------------------------------------------------
4884
4885#pragma GCC diagnostic pop
4886
4887// ----------------------------------------------------------------------------
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:59
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:57
POSIX compliant condition variable.
Definition os-condvar.h:46
Event flags attributes.
Definition os-evflags.h:69
Synchronised event flags.
Definition os-evflags.h:58
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:1148
static state_t enter(void)
Enter an interrupts critical section.
Definition os-sched.h:1138
static state_t enter(void)
Enter interrupts uncritical section.
Definition os-sched.h:1180
static void exit(state_t state)
Exit interrupts uncritical section.
Definition os-sched.h:1190
Memory resource manager (abstract class).
Definition os-memory.h:160
Memory pool attributes.
Definition os-mempool.h:99
void * mp_pool_address
Address of the user defined storage for the memory pool.
Definition os-mempool.h:144
std::size_t mp_pool_size_bytes
Size of the user defined storage for the memory pool.
Definition os-mempool.h:149
Synchronised memory pool, using the default RTOS allocator.
Definition os-mempool.h:68
std::size_t block_size(void) const
Get block size.
Definition os-mempool.h:931
std::size_t capacity(void) const
Get memory pool capacity.
Definition os-mempool.h:922
void * pool(void)
Get the pool storage address.
Definition os-mempool.h:967
Message queue attributes.
Definition os-mqueue.h:152
void * mq_queue_address
Address of the user defined storage for the message queue.
Definition os-mqueue.h:197
std::size_t mq_queue_size_bytes
Size of the user defined storage for the message queue.
Definition os-mqueue.h:202
POSIX compliant message queue, using the default RTOS allocator.
Definition os-mqueue.h:68
Recursive mutex attributes.
Definition os-mutex.h:311
Mutex attributes.
Definition os-mutex.h:207
type_t mx_type
Attribute with the mutex type.
Definition os-mutex.h:282
protocol_t mx_protocol
Attribute with the mutex protocol.
Definition os-mutex.h:272
POSIX compliant recursive mutex.
Definition os-mutex.h:715
POSIX compliant mutex.
Definition os-mutex.h:53
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:798
std::size_t th_stack_size_bytes
Size of the user defined storage for the thread stack, in bytes.
Definition os-thread.h:858
priority_t th_priority
Thread initial priority.
Definition os-thread.h:869
void * th_stack_address
Address of the user defined storage for the thread stack.
Definition os-thread.h:845
static std::size_t default_size(void)
Get the default stack size.
Definition os-thread.h:2216
static std::size_t min_size(void)
Get the min stack size.
Definition os-thread.h:2196
Thread statistics.
Definition os-thread.h:890
POSIX compliant thread, using the default RTOS allocator.
Definition os-thread.h:250
result_t kill(void)
Force thread termination.
uint8_t state_t
Type of variables holding thread states.
Definition os-thread.h:356
void *(*)(func_args_t args) func_t
Type of thread function.
Definition os-thread.h:420
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:412
static bool is_constructed(const thread &thread)
Check if the thread is constructed.
Periodic timer attributes.
Definition os-timer.h:216
Timer attributes.
Definition os-timer.h:135
type_t tm_type
Timer type attribute.
Definition os-timer.h:195
User single-shot or periodic timer.
Definition os-timer.h:57
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:112
void * osMailAlloc(osMailQId mail_id, uint32_t millisec)
Allocate a memory block from a mail.
osPriority
Definition cmsis_os.h:132
@ osPriorityError
system cannot determine priority or thread has illegal priority
Definition cmsis_os.h:140
void * osMailCAlloc(osMailQId mail_id, uint32_t millisec)
Allocate and clear a memory block from a mail.
osEvent osWait(uint32_t millisec)
Wait for Signal, Message, Mail, or Timeout.
osSemaphoreId osSemaphoreCreate(const osSemaphoreDef_t *semaphore_def, int32_t count)
Create a semaphore.
#define osWaitForever
Timeout value.
Definition cmsis_os.h:147
void * osPoolCAlloc(osPoolId pool_id)
Allocate and clear a memory block.
void * osPoolAlloc(osPoolId pool_id)
Allocate a memory block.
osStatus osMailFree(osMailQId mail_id, void *mail)
Free a memory block from a mail.
osStatus osSemaphoreRelease(osSemaphoreId semaphore_id)
Release the semaphore.
osMailQId osMailCreate(const osMailQDef_t *mail_def, osThreadId thread_id)
Create a mail queue.
osStatus osSemaphoreDelete(osSemaphoreId semaphore_id)
Delete the semaphore.
osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
Put a message to a queue.
int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec)
Wait until a Semaphore token becomes available.
uint32_t osKernelSysTick(void)
Get the system timer counter.
os_timer_type
Timer type value for the timer definition.
Definition cmsis_os.h:177
osStatus
Status code values returned by CMSIS-RTOS functions.
Definition cmsis_os.h:154
@ osEventMail
function completed; mail event occurred.
Definition cmsis_os.h:158
@ osErrorISR
not allowed in ISR context: the function cannot be called from interrupt service routines.
Definition cmsis_os.h:163
@ osErrorTimeoutResource
resource not available within given time: a specified resource was not available within the timeout p...
Definition cmsis_os.h:162
@ osErrorValue
value of a parameter is out of range.
Definition cmsis_os.h:167
@ osEventSignal
function completed; signal event occurred.
Definition cmsis_os.h:156
@ osErrorOS
unspecified RTOS error: run-time error but no other error message fits.
Definition cmsis_os.h:168
@ osEventTimeout
function completed; timeout occurred.
Definition cmsis_os.h:159
@ osErrorResource
resource not available: a specified resource was not available.
Definition cmsis_os.h:161
@ osOK
function completed; no error or event occurred.
Definition cmsis_os.h:155
@ osErrorParameter
parameter error: a mandatory parameter was missing or specified an incorrect object.
Definition cmsis_os.h:160
@ osEventMessage
function completed; message event occurred.
Definition cmsis_os.h:157
osMessageQId osMessageCreate(const osMessageQDef_t *queue_def, osThreadId thread_id)
Create a message queue.
int raise(int sig)
pid_t wait(int *stat_loc)
int kill(pid_t pid, int sig)
ssize_t send(int socket, const void *buffer, size_t length, int flags)
os_clock_timestamp_t os_clock_now(os_clock_t *clock)
Tell the current time, possibly adjusted for epoch.
os_result_t os_sysclock_wait_for(os_clock_duration_t timeout)
Timed wait for an event.
os_result_t os_clock_sleep_for(os_clock_t *clock, os_clock_duration_t duration)
Sleep for a relative duration.
const char * os_clock_get_name(os_clock_t *clock)
Get the clock name.
os_result_t os_clock_wait_for(os_clock_t *clock, os_clock_duration_t timeout)
Timed wait for an event.
os_clock_timestamp_t os_sysclock_now(void)
Tell the current time since startup.
os_clock_offset_t os_clock_get_offset(os_clock_t *clock)
Get adjustment offset.
os_clock_timestamp_t os_clock_steady_now(os_clock_t *clock)
Tell the current time since startup.
os_clock_t * os_clock_get_sysclock(void)
Get sysclock (the system clock).
os_result_t os_sysclock_sleep_until(os_clock_timestamp_t timestamp)
Sleep until an absolute timestamp.
os_clock_t * os_clock_get_rtclock(void)
Get rtclock (the real-time clock).
os_result_t os_sysclock_sleep_for(os_clock_duration_t duration)
Sleep for a relative duration.
os_clock_t * os_clock_get_hrclock(void)
Get hrclock (the high resolution clock).
os_clock_offset_t os_clock_set_offset(os_clock_t *clock, os_clock_offset_t offset)
Set adjustment offset.
os_result_t os_clock_sleep_until(os_clock_t *clock, os_clock_timestamp_t timestamp)
Sleep until an absolute timestamp.
os_result_t os_condvar_timed_wait(os_condvar_t *condvar, os_mutex_t *mutex, os_clock_duration_t timeout)
Timed wait for a condition variable to be notified.
void os_condvar_delete(os_condvar_t *condvar)
Destruct the condition variable object instance and deallocate it.
os_result_t os_condvar_signal(os_condvar_t *condvar)
Notify one thread waiting for a condition variable.
void os_condvar_construct(os_condvar_t *condvar, const char *name, const os_condvar_attr_t *attr)
Construct a statically allocated condition variable object instance.
void os_condvar_destruct(os_condvar_t *condvar)
Destruct the statically allocated condition variable object instance.
os_result_t os_condvar_wait(os_condvar_t *condvar, os_mutex_t *mutex)
Wait for a condition variable to be notified.
os_condvar_t * os_condvar_new(const char *name, const os_condvar_attr_t *attr)
Allocate a condition variable object instance and construct it.
const char * os_condvar_get_name(os_condvar_t *condvar)
Get the condition variable name.
os_result_t os_condvar_broadcast(os_condvar_t *condvar)
Notify all threads waiting for a condition variable.
void os_condvar_attr_init(os_condvar_attr_t *attr)
Initialise the condition variable attributes.
bool os_irq_in_handler_mode(void)
Check if the CPU is in handler mode.
void os_irq_uncritical_exit(os_irq_state_t state)
Exit the interrupts uncritical section.
bool os_sched_is_locked(void)
Check if the scheduler is locked.
os_irq_state_t os_irq_uncritical_enter(void)
Enter an interrupts uncritical section.
void os_sched_start(void)
Start the RTOS scheduler.
bool os_sched_is_started(void)
Check if the scheduler was started.
os_sched_state_t os_sched_set_locked(os_sched_state_t state)
Lock/unlock the scheduler.
bool os_sched_set_preemptive(bool state)
Set the scheduler preemptive mode.
os_result_t os_sched_initialize(void)
Initialise the RTOS scheduler.
os_statistics_duration_t os_sched_stat_get_cpu_cycles(void)
Get the total duration of all threads.
uint32_t os_flags_mask_t
Type of variables holding flags masks.
Definition os-c-decls.h:121
uint64_t os_statistics_counter_t
Type of variables holding context switches counters.
Definition os-c-decls.h:232
os_thread_stack_t * os_irq_get_stack(void)
Get the interrupts stack.
os_sched_state_t os_sched_unlock(void)
Unlock the scheduler.
os_sched_state_t os_sched_lock(void)
Lock the scheduler.
os_port_irq_state_t os_irq_state_t
Type of variables holding interrupts priority values.
Definition os-c-decls.h:171
void os_irq_critical_exit(os_irq_state_t state)
Exit the interrupts critical section.
uint32_t os_flags_mode_t
Type of variables holding flags modes.
Definition os-c-decls.h:108
os_statistics_counter_t os_sched_stat_get_context_switches(void)
Get the total number of context switches.
bool os_sched_is_preemptive(void)
Check if the scheduler is in preemptive mode.
os_port_scheduler_state_t os_sched_state_t
Type of variables holding scheduler state codes.
Definition os-c-decls.h:157
os_port_clock_offset_t os_clock_offset_t
Type of variables holding clock offsets.
Definition os-c-decls.h:209
void * os_iterator_t
Generic iterator, implemented as a pointer.
Definition os-c-decls.h:223
uint64_t os_statistics_duration_t
Type of variables holding durations in CPU cycles.
Definition os-c-decls.h:239
os_irq_state_t os_irq_critical_enter(void)
Enter an interrupts critical section.
os_port_clock_duration_t os_clock_duration_t
Type of variables holding clock durations.
Definition os-c-decls.h:197
os_port_clock_timestamp_t os_clock_timestamp_t
Type of variables holding clock time stamps.
Definition os-c-decls.h:186
uint32_t os_result_t
Type of values returned by RTOS functions.
Definition os-c-decls.h:95
@ os_flags_mode_clear
Definition os-c-decls.h:132
@ os_flags_mode_all
Definition os-c-decls.h:130
@ os_flags_mode_any
Definition os-c-decls.h:131
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:341
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:842
@ os_mutex_protocol_protect
Execute at the highest priority.
Definition os-c-decls.h:847
@ os_mutex_protocol_none
Priority and scheduling not affected by mutex ownership.
Definition os-c-decls.h:837
@ os_mutex_type_recursive
Recursive mutex behaviour.
Definition os-c-decls.h:898
@ os_mutex_type_errorcheck
Check mutex behaviour.
Definition os-c-decls.h:893
@ os_mutex_type_default
Default mutex type.
Definition os-c-decls.h:903
@ os_mutex_type_normal
Normal mutex behaviour.
Definition os-c-decls.h:888
@ os_mutex_robustness_robust
Enhanced robustness at thread termination.
Definition os-c-decls.h:870
@ os_mutex_robustness_stalled
Normal robustness.
Definition os-c-decls.h:865
os_semaphore_t * os_semaphore_counting_new(const char *name, const os_semaphore_count_t max_value, const os_semaphore_count_t initial_value)
Allocate a counting semaphore object instance and construct it.
os_result_t os_semaphore_timed_wait(os_semaphore_t *semaphore, os_clock_duration_t timeout)
Timed wait to lock the semaphore.
os_semaphore_t * os_semaphore_binary_new(const char *name, const os_semaphore_count_t initial_value)
Allocate a binary semaphore object instance and construct it.
os_semaphore_count_t os_semaphore_get_initial_value(os_semaphore_t *semaphore)
Get the semaphore initial count value.
const os_semaphore_attr_t * os_semaphore_attr_get_binary(void)
Get a binary semaphore attributes object instance.
const char * os_semaphore_get_name(os_semaphore_t *semaphore)
Get the semaphore name.
void os_semaphore_attr_binary_init(os_semaphore_attr_t *attr, const os_semaphore_count_t initial_value)
Initialise the binary semaphore attributes.
void os_semaphore_attr_counting_init(os_semaphore_attr_t *attr, const os_semaphore_count_t max_value, const os_semaphore_count_t initial_value)
Initialise the counting semaphore attributes.
os_result_t os_semaphore_post(os_semaphore_t *semaphore)
Post (unlock) the semaphore.
os_result_t os_semaphore_wait(os_semaphore_t *semaphore)
Lock the semaphore, possibly waiting.
os_semaphore_count_t os_semaphore_get_value(os_semaphore_t *semaphore)
Get the semaphore count value.
void os_semaphore_destruct(os_semaphore_t *semaphore)
Destruct the statically allocated semaphore object instance.
void os_semaphore_binary_construct(os_semaphore_t *semaphore, const char *name, const os_semaphore_count_t initial_value)
Construct a statically allocated binary semaphore object instance.
os_semaphore_count_t os_semaphore_get_max_value(os_semaphore_t *semaphore)
Get the semaphore maximum count value.
void os_semaphore_counting_construct(os_semaphore_t *semaphore, const char *name, const os_semaphore_count_t max_value, const os_semaphore_count_t initial_value)
Construct a statically allocated counting semaphore object instance.
void os_semaphore_delete(os_semaphore_t *semaphore)
Destruct the semaphore object instance.
os_result_t os_semaphore_reset(os_semaphore_t *semaphore)
Reset the semaphore.
os_semaphore_t * os_semaphore_new(const char *name, const os_semaphore_attr_t *attr)
Allocated a semaphore object instance and construct it.
void os_semaphore_attr_init(os_semaphore_attr_t *attr)
Initialise the counting semaphore attributes.
void os_semaphore_construct(os_semaphore_t *semaphore, const char *name, const os_semaphore_attr_t *attr)
Construct a statically allocated semaphore object instance.
int16_t os_semaphore_count_t
Type of variables holding semaphore counts.
os_result_t os_semaphore_try_wait(os_semaphore_t *semaphore)
Try to lock the semaphore.
void os_thread_attr_init(os_thread_attr_t *attr)
Initialise the thread attributes.
os_result_t os_this_thread_flags_timed_wait(os_flags_mask_t mask, os_clock_duration_t timeout, os_flags_mask_t *oflags, os_flags_mode_t mode)
Timed wait for thread event flags.
os_iterator_t os_children_threads_iter_next(os_iterator_t iterator)
Advance the iterator to the next position.
os_thread_user_storage_t * os_thread_get_user_storage(os_thread_t *thread)
Get the thread user storage.
bool os_thread_is_constructed(os_thread_t *thread)
Check if the thread is constructed.
os_flags_mask_t os_this_thread_flags_get(os_flags_mask_t mask, os_flags_mode_t mode)
Get/clear thread event flags.
const char * os_thread_get_name(os_thread_t *thread)
Get the thread name.
os_result_t os_this_thread_flags_wait(os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Wait for thread event flags.
void *(* os_thread_func_t)(os_thread_func_args_t args)
Type of thread function.
Definition os-c-decls.h:342
uint8_t os_thread_prio_t
Type of variables holding thread priorities.
Definition os-c-decls.h:363
os_thread_stack_element_t * os_thread_stack_get_bottom(os_thread_stack_t *stack)
Get the stack lowest reserved address.
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:376
os_thread_prio_t os_thread_get_priority(os_thread_t *thread)
Get the thread current scheduling priority.
void * os_thread_func_args_t
Type of thread function arguments.
Definition os-c-decls.h:330
os_thread_t * os_this_thread(void)
Get the current running thread.
os_thread_stack_t * os_thread_get_stack(os_thread_t *thread)
Get the thread context stack.
os_result_t os_thread_kill(os_thread_t *thread)
Force thread termination.
os_thread_t * os_thread_new(const char *name, os_thread_func_t func, const os_thread_func_args_t args, const os_thread_attr_t *attr)
Allocate a thread object instance and construct it.
os_thread_t * os_children_threads_iter_get(os_iterator_t iterator)
Get the thread from the current iterator position.
size_t os_thread_stack_get_size(os_thread_stack_t *stack)
Get the stack size.
size_t os_thread_stack_get_min_size(void)
Get the min stack size.
size_t os_thread_stack_get_available(os_thread_stack_t *stack)
Compute how much available stack remains.
os_statistics_duration_t os_thread_stat_get_cpu_cycles(os_thread_t *thread)
Get the thread execution time.
os_result_t os_thread_set_priority(os_thread_t *thread, os_thread_prio_t prio)
Set the thread dynamic scheduling priority.
void os_this_thread_exit(void *exit_ptr)
Terminate the current running thread.
os_result_t os_this_thread_flags_try_wait(os_flags_mask_t mask, os_flags_mask_t *oflags, os_flags_mode_t mode)
Try to wait for thread event flags.
uint8_t os_thread_state_t
Type of variables holding thread states.
Definition os-c-decls.h:349
size_t os_thread_stack_get_default_size(void)
Get the default stack size.
size_t os_thread_stack_set_min_size(size_t size_bytes)
Set the min stack size.
os_iterator_t os_children_threads_iter_end(os_thread_t *thread)
Get the end of the list of children threads.
os_result_t os_thread_flags_raise(os_thread_t *thread, os_flags_mask_t mask, os_flags_mask_t *oflags)
Raise thread event flags.
void os_thread_destruct(os_thread_t *thread)
Destruct the statically allocated thread object instance.
@ os_thread_state_terminated
No longer usable, but resources not yet released.
Definition os-c-decls.h:311
@ os_thread_state_suspended
Not present in the READY list, waiting for an event.
Definition os-c-decls.h:307
@ os_thread_state_undefined
Used to catch uninitialised threads.
Definition os-c-decls.h:295
@ os_thread_state_ready
Present in the READY list and competing for CPU.
Definition os-c-decls.h:299
@ os_thread_state_initialising
Used to check reused threads.
Definition os-c-decls.h:319
@ os_thread_state_destroyed
Terminated and resources (like stack) released.
Definition os-c-decls.h:315
@ os_thread_state_running
Has the CPU and runs.
Definition os-c-decls.h:303
@ os_thread_priority_error
Definition os-c-decls.h:282
@ os_thread_priority_below_normal
Definition os-c-decls.h:275
@ os_thread_priority_high
Definition os-c-decls.h:278
@ os_thread_priority_realtime
Definition os-c-decls.h:279
@ os_thread_priority_idle
Definition os-c-decls.h:272
@ os_thread_priority_normal
Definition os-c-decls.h:276
@ os_thread_priority_low
Definition os-c-decls.h:274
@ os_thread_priority_above_normal
Definition os-c-decls.h:277
uint8_t os_timer_type_t
Type of variables holding timer types.
Definition os-c-decls.h:728
void(* os_timer_func_t)(os_timer_func_args_t args)
Type of timer function.
Definition os-c-decls.h:721
void * os_timer_func_args_t
Type of timer function arguments.
Definition os-c-decls.h:709
const char * os_timer_get_name(os_timer_t *timer)
Get the timer name.
os_result_t os_timer_stop(os_timer_t *timer)
Stop the timer.
void os_timer_destruct(os_timer_t *timer)
Destruct the statically allocated timer object instance.
uint8_t os_timer_state_t
Type of variables holding timer states.
Definition os-c-decls.h:735
void os_timer_attr_init(os_timer_attr_t *attr)
Initialise the single shot timer attributes.
os_timer_t * os_timer_new(const char *name, os_timer_func_t function, os_timer_func_args_t args, const os_timer_attr_t *attr)
Allocate a timer object instance and construct it.
os_result_t os_timer_start(os_timer_t *timer, os_clock_duration_t period)
Start or restart the timer.
void os_timer_attr_periodic_init(os_timer_attr_t *attr)
Initialise the periodic timer attributes.
void os_timer_construct(os_timer_t *timer, const char *name, os_timer_func_t function, os_timer_func_args_t args, const os_timer_attr_t *attr)
Construct a statically allocated timer object instance.
void os_timer_delete(os_timer_t *timer)
Destruct the timer object instance and deallocate it.
const os_timer_attr_t * os_timer_attr_get_periodic(void)
Get a periodic timer attributes object instance.
@ os_timer_once
Definition os-c-decls.h:696
@ os_timer_periodic
Definition os-c-decls.h:697
port::clock::duration_t duration_t
Type of variables holding clock durations.
Definition os-clocks.h:76
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:85
clock_systick sysclock
The system clock object instance.
port::clock::offset_t offset_t
Type of variables holding clock offsets.
Definition os-clocks.h:95
static const attributes initializer
Default condition variable initialiser.
Definition os-condvar.h:110
class thread::stack * stack(void)
Get the interrupts stack.
Definition os-core.cpp:571
static const attributes initializer
Default event flags initialiser.
Definition os-evflags.h:122
uint16_t size_t
Type of memory pool size storage.
Definition os-mempool.h:80
static const attributes initializer
Default memory pool initialiser.
Definition os-mempool.h:163
memory_resource * get_default_resource(void) noexcept
Get the default RTOS system memory manager.
Definition os-memory.h:1133
uint8_t priority_t
Type of message priority storage.
Definition os-mqueue.h:125
message_queue::size_t index_t
Type of list index storage.
Definition os-mqueue.h:109
static const attributes initializer
Default message queue initialiser.
Definition os-mqueue.h:216
uint8_t size_t
Type of a queue size storage.
Definition os-mqueue.h:84
uint16_t msg_size_t
Type of message size storage.
Definition os-mqueue.h:97
uint8_t type_t
Type of variables holding mutex behaviours.
Definition os-mutex.h:147
uint16_t count_t
Type of variables holding mutex recursion counters.
Definition os-mutex.h:191
static const attributes_recursive initializer_recursive
Default recursive mutex initialiser.
Definition os-mutex.h:350
uint8_t protocol_t
Type of variables holding mutex protocols.
Definition os-mutex.h:60
uint8_t robustness_t
Type of variables holding mutex robustness.
Definition os-mutex.h:106
static const attributes initializer_normal
Default normal mutex initialiser.
Definition os-mutex.h:301
static const attributes_binary initializer_binary
Default binary semaphore initialiser.
int16_t count_t
Type of semaphore counter storage.
uint8_t priority_t
Type of variables holding thread priorities.
Definition os-thread.h:271
void * func_args_t
Timer call back function arguments.
Definition os-timer.h:64
void(*)(func_args_t args) func_t
Entry point of a timer call back function.
Definition os-timer.h:70
uint8_t type_t
Type of of variables holding timer run types.
Definition os-timer.h:76
uint8_t state_t
Type of of variables holding timer states.
Definition os-timer.h:103
static const attributes_periodic periodic_initializer
Default periodic timer initialiser.
Definition os-timer.h:255
@ all
Return when all flags are set.
Definition os-decls.h:293
@ clear
Ask for flags to be cleared after read.
Definition os-decls.h:303
@ any
Return when at least one flag is set.
Definition os-decls.h:298
uint32_t mode_t
Type of variables holding flags modes.
Definition os-decls.h:275
uint32_t mask_t
Type of variables holding flags masks.
Definition os-decls.h:265
port::interrupts::state_t state_t
Type of variables holding interrupts statu codes.
Definition os-decls.h:243
bool in_handler_mode(void)
Check if the CPU is in handler mode.
Definition os-sched.h:1108
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:181
rtos::statistics::duration_t cpu_cycles(void)
Get the total duration of all threads.
Definition os-sched.h:1059
rtos::statistics::counter_t context_switches(void)
Get the total number of context switches.
Definition os-sched.h:1034
port::scheduler::state_t state_t
Type of variables holding scheduler state codes.
Definition os-decls.h:202
state_t unlock(void)
Unlock the scheduler.
Definition os-sched.h:882
void start(void)
Start the RTOS scheduler.
Definition os-core.cpp:189
bool started(void)
Check if the scheduler was started.
Definition os-sched.h:827
thread::threads_list & children_threads(thread *th)
Get the children threads.
Definition os-core.cpp:261
state_t lock(void)
Lock the scheduler.
Definition os-sched.h:869
result_t initialize(void)
Initialise the RTOS scheduler.
Definition os-core.cpp:160
bool preemptive(void)
Check if the scheduler is in preemptive mode.
Definition os-sched.h:839
bool locked(void)
Check if the scheduler is locked.
Definition os-sched.h:856
uint64_t duration_t
Type of variables holding durations in CPU cycles.
Definition os-decls.h:222
uint64_t counter_t
Type of variables holding context switches counters.
Definition os-decls.h:217
RTOS namespace.
Definition os-flags.h:38
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:96
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:819
uint8_t os_mutex_type_t
Definition os-c-decls.h:818
uint8_t os_mqueue_size_t
uint8_t os_mutex_robustness_t
Definition os-c-decls.h:820
uint16_t os_mempool_size_t
int16_t os_mutex_count_t
Definition os-c-decls.h:817
uint16_t os_mqueue_msg_size_t
osStatus osMutexRelease(osMutexId mutex_id)
Release the mutex.
osStatus osDelay(uint32_t millisec)
Time Delay.
osStatus osThreadSetPriority(osThreadId thread_id, osPriority priority)
Change thread priority.
osTimerId osTimerCreate(const osTimerDef_t *timer_def, os_timer_type type, void *args)
Create a timer.
osStatus osTimerStart(osTimerId timer_id, uint32_t millisec)
Start the timer.
osEvent osSignalWait(int32_t signals, uint32_t millisec)
Wait for one or more Signal Flags to become signaled for the current RUNNING thread.
int32_t osKernelRunning(void)
Check if the RTOS scheduler is started.
int32_t osSignalSet(osThreadId thread_id, int32_t signals)
Set signal flags.
osPriority osThreadGetPriority(osThreadId thread_id)
Get thread priority.
osStatus osKernelInitialize(void)
Initialize the RTOS.
osStatus osTimerStop(osTimerId timer_id)
Stop the timer.
osMutexId osMutexCreate(const osMutexDef_t *mutex_def)
Create a mutex.
osStatus osMutexWait(osMutexId mutex_id, uint32_t millisec)
Wait for mutex.
osStatus osTimerDelete(osTimerId timer_id)
Delete the timer.
int32_t osSignalClear(osThreadId thread_id, int32_t signals)
Clear the specified Signal Flags of an active thread.
osThreadId osThreadCreate(const osThreadDef_t *thread_def, void *args)
Create a thread.
osStatus osKernelStart(void)
osThreadId osThreadGetId(void)
Get the current thread.
osStatus osMutexDelete(osMutexId mutex_id)
Delete the mutex.
osStatus osThreadTerminate(osThreadId thread_id)
Terminate a thread.
osStatus osThreadYield(void)
Yield control.
Single file µOS++ RTOS definitions.
Event structure contains detailed information about an event.
Definition cmsis_os.h:378
osStatus status
status code: event or error information
Definition cmsis_os.h:379
int32_t signals
signal flags
Definition cmsis_os.h:384
union osEvent::@0 value
event value
@ none
Priority and scheduling not affected by mutex ownership.
Definition os-mutex.h:78
@ inherit
Inherit priority from highest priority thread.
Definition os-mutex.h:83
@ protect
Execute at the highest priority.
Definition os-mutex.h:88
@ stalled
Normal robustness.
Definition os-mutex.h:124
@ robust
Enhanced robustness at thread termination.
Definition os-mutex.h:129
@ normal
Normal mutex behaviour.
Definition os-mutex.h:165
@ default_
Default value.
Definition os-mutex.h:178
@ errorcheck
Check mutex behaviour.
Definition os-mutex.h:169
@ recursive
Recursive mutex behaviour.
Definition os-mutex.h:173
@ running
Has the CPU and runs.
Definition os-thread.h:385
@ destroyed
Terminated and resources (like stack) released.
Definition os-thread.h:397
@ initializing
Used to check reused threads.
Definition os-thread.h:401
@ terminated
No longer usable, but resources not yet released.
Definition os-thread.h:393
@ ready
Present in the READY list and competing for CPU.
Definition os-thread.h:381
@ undefined
Used to catch uninitialised threads.
Definition os-thread.h:377
@ suspended
Not present in the READY list, waiting for an event.
Definition os-thread.h:389
@ once
Run only once.
Definition os-timer.h:90
@ periodic
Run periodically.
Definition os-timer.h:95
Clock object storage.
Definition os-c-decls.h:644
Condition variable attributes.
Condition variable object storage.
Event flags attributes.
Event flags object storage.
Definition structure for mail queue.
Definition cmsis_os.h:360
osMailQ * data
Definition cmsis_os.h:369
uint32_t items
number of elements in the queue
Definition cmsis_os.h:362
uint32_t queue_sz
Definition cmsis_os.h:368
void * queue
pointer to memory array for queue
Definition cmsis_os.h:367
uint32_t queue_item_sz
size of a queue item
Definition cmsis_os.h:364
uint32_t pool_sz
Definition cmsis_os.h:366
uint32_t pool_item_sz
size of a pool item
Definition cmsis_os.h:363
void * pool
pointer to memory array for pool
Definition cmsis_os.h:365
const char * name
Definition cmsis_os.h:361
os_mqueue_t queue
Definition cmsis_os.h:218
os_mempool_t pool
Definition cmsis_os.h:217
Memory resource object storage.
Memory pool attributes.
Memory pool object storage.
Definition structure for message queue.
Definition cmsis_os.h:346
void * queue
pointer to memory array for messages
Definition cmsis_os.h:350
osMessageQ * data
Definition cmsis_os.h:352
uint32_t items
number of elements in the queue
Definition cmsis_os.h:348
const char * name
Definition cmsis_os.h:347
uint32_t item_sz
size of an item
Definition cmsis_os.h:349
uint32_t queue_sz
Definition cmsis_os.h:351
Message queue attributes.
Message queue object storage.
Mutex attributes.
Definition os-c-decls.h:924
Mutex definition structure contains setup information for a mutex.
Definition cmsis_os.h:305
osMutex * data
Definition cmsis_os.h:307
const char * name
Definition cmsis_os.h:306
Mutex object storage.
Definition os-c-decls.h:974
Definition structure for memory block allocation.
Definition cmsis_os.h:332
osPool * data
Definition cmsis_os.h:338
const char * name
Definition cmsis_os.h:333
uint32_t pool_sz
Definition cmsis_os.h:337
uint32_t item_sz
size of an item
Definition cmsis_os.h:335
void * pool
pointer to memory for pool
Definition cmsis_os.h:336
uint32_t items
number of items (elements) in the pool
Definition cmsis_os.h:334
Semaphore attributes.
Semaphore definition structure contains setup information for a semaphore.
Definition cmsis_os.h:315
const char * name
Definition cmsis_os.h:316
osSemaphore * data
Definition cmsis_os.h:317
Semaphore object storage.
Thread attributes.
Definition os-c-decls.h:493
Thread context.
Definition os-c-decls.h:431
Thread definition structure contains startup information of a thread.
Definition cmsis_os.h:277
os_pthread pthread
start address of thread function
Definition cmsis_os.h:279
uint64_t * stack
Definition cmsis_os.h:284
const char * name
Definition cmsis_os.h:278
osPriority tpriority
initial thread priority
Definition cmsis_os.h:280
uint32_t stacksize
stack size requirements in bytes; 0 is default stack size
Definition cmsis_os.h:282
osThread * data
Definition cmsis_os.h:283
uint32_t instances
maximum number of instances of that thread function
Definition cmsis_os.h:281
Thread object storage.
Definition os-c-decls.h:563
Thread stack.
Definition os-c-decls.h:406
Timer attributes.
Definition os-c-decls.h:755
Timer definition structure contains timer parameters.
Definition cmsis_os.h:294
const char * name
Definition cmsis_os.h:295
osTimer * data
Definition cmsis_os.h:297
os_ptimer ptimer
start address of a timer function
Definition cmsis_os.h:296
Timer object storage.
Definition os-c-decls.h:785