µ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-decls.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016-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#ifndef CMSIS_PLUS_RTOS_OS_DECLS_H_
14#define CMSIS_PLUS_RTOS_OS_DECLS_H_
15
16// ----------------------------------------------------------------------------
17
19
20// Include the application specific definitions.
21#if defined(OS_USE_OS_APP_CONFIG_H)
22#include <cmsis-plus/os-app-config.h>
23#endif
24// Include the non-portable portable types, enums and constants declarations.
25#include <cmsis-plus/rtos/port/os-decls.h>
26
28
29// ----------------------------------------------------------------------------
30
31#if defined(__cplusplus)
32
33// ----------------------------------------------------------------------------
34
35#include <cstdint>
36#include <cstddef>
37#include <cerrno>
38#include <cstring>
39
40// ----------------------------------------------------------------------------
41
42#pragma GCC diagnostic push
43#if defined(__clang__)
44#pragma clang diagnostic ignored "-Wc++98-compat"
45#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
46#endif
47
48// ----------------------------------------------------------------------------
49
54namespace os
55{
59 namespace rtos
60 {
61 // ========================================================================
62
63 // Forward references.
64 class clock;
65 class clock_rtc;
66 class clock_systick;
67
68 class condition_variable;
69 class event_flags;
70 class memory_pool;
71 class message_queue;
72 class mutex;
73 class semaphore;
74 class thread;
75 class timer;
76
77 // ------------------------------------------------------------------------
78
79 namespace memory
80 {
81 template<typename T>
83 } /* namespace memory */
84
85 // ------------------------------------------------------------------------
86
96 using result_t = uint32_t;
97
160 namespace result
161 {
175 enum
176 : result_t
177 {
181 ok = 0
182
183 };
184 } /* namespace result */
185
186 // ------------------------------------------------------------------------
187
192 namespace scheduler
193 {
202 using state_t = port::scheduler::state_t;
203
204 } /* namespace scheduler */
205
206 // ------------------------------------------------------------------------
207
212 namespace statistics
213 {
217 using counter_t = uint64_t;
218
222 using duration_t = uint64_t;
223
224 } /* namespace statistics */
225
226 // ------------------------------------------------------------------------
227
232 namespace interrupts
233 {
243 using state_t = port::interrupts::state_t;
244
245 } /* namespace interrupts */
246
247 // ------------------------------------------------------------------------
248
255 namespace flags
256 {
265 using mask_t = uint32_t;
266
275 using mode_t = uint32_t;
276
282 namespace mode
283 {
287 enum
288 : mode_t
289 {
293 all = 1,
294
298 any = 2,
299
303 clear = 4
304 };
305 } /* namespace mode */
306
310 enum
311 : mask_t
312 {
316 any = 0,
317
321 all = 0xFFFFFFFF
322 };
323
324 } /* namespace flags */
325
326 // ------------------------------------------------------------------------
327
332 namespace this_thread
333 {
334 }
335
336 // ------------------------------------------------------------------------
337
341 namespace internal
342 {
343
344 // ======================================================================
345
351 {
352 public:
353
362 object_named ();
363
369 object_named (const char* name);
370
374 object_named (const object_named&) = default;
375 object_named (object_named&&) = default;
376 // object_named&
377 // operator= (const object_named&) = default;
378 // object_named&
379 // operator= (object_named&&) = default;
387 ~object_named () = default;
388
393 public:
394
406 const char*
407 name (void) const;
408
413 protected:
414
427 const char* const name_ = "-";
428
436 };
437
438 // ======================================================================
439
445 {
446 public:
447
457
463 object_named_system (const char* name);
464
468 object_named_system (const object_named_system&) = default;
470 // object_named_system&
471 // operator= (const object_named_system&) = default;
472 // object_named_system&
473 // operator= (object_named_system&&) = default;
482
498 static void*
499 operator new (std::size_t bytes);
500
507 static void*
508 operator new[] (std::size_t bytes);
509
516 static void*
517 operator new (std::size_t bytes, void* ptr);
518
525 static void*
526 operator new[] (std::size_t bytes, void* ptr);
527
536 static void
537 operator delete (void* ptr, std::size_t bytes);
538
547 static void
548 operator delete[] (void* ptr, std::size_t bytes);
549
554 };
555
556 // ======================================================================
557
563 {
564 public:
565
576 constexpr
578
582 attributes_clocked (const attributes_clocked&) = default;
585 operator= (const attributes_clocked&) = default;
587 operator= (attributes_clocked&&) = default;
596
615 rtos::clock* clock = nullptr;
616
621 protected:
622
631 };
632 } /* namespace internal */
633
634 // ========================================================================
635
644 {
645 public:
646
658 constexpr
660
665 null_locker (const null_locker&) = delete;
666 null_locker (null_locker&&) = delete;
668 operator= (const null_locker&) = delete;
670 operator= (null_locker&&) = delete;
671
679 ~null_locker ();
680
685 public:
686
699 void
700 lock (void);
701
709 void
710 unlock (void);
711
716 };
717
718 // ==========================================================================
719 } /* namespace rtos */
720} /* namespace os */
721
722// ===== Inline & template implementations ====================================
723
724namespace os
725{
726 namespace rtos
727 {
728 // ========================================================================
729
730 inline
732 {
733 }
734
735 inline void
737 {
738 // Does nothing.
739 }
740
741 inline void
743 {
744 // Does nothing.
745 }
746
747 namespace internal
748 {
749 // ======================================================================
750
758 inline const char*
760 {
761 return name_;
762 }
763
764 // ======================================================================
765
766 inline
768 {
769 }
770
771 inline
773 object_named (name)
774 {
775 }
776
777 // ======================================================================
778
782 constexpr
784 {
785 }
786
787 // ========================================================================
788 } /* namespace internal */
789 } /* namespace rtos */
790} /* namespace os */
791
792// ===== Port related definitions =============================================
793
794namespace os
795{
796 namespace rtos
797 {
798 namespace port
799 {
800 class thread;
801 class timer;
802 class mutex;
803
804 class condition_variable;
805 class semaphore;
806 class memory_pool;
807 class message_queue;
808 class event_flags;
809
810 // ======================================================================
811
812 namespace clock
813 {
820 using duration_t = uint32_t;
821
828 using timestamp_t = uint64_t;
829
830 using offset_t = int64_t;
831 } /* namespace clock */
832
833 // ----------------------------------------------------------------------
834
835 namespace interrupts
836 {
837
838 bool
840
841 // ====================================================================
842
844 {
845 public:
846
847 critical_section () = delete;
848
849 // Enter an IRQ critical section
851 enter (void);
852
853 // Exit an IRQ critical section
854 static void
856
857 };
858
859 // ====================================================================
860
862 {
863 public:
864
866
867 // Enter an IRQ uncritical section
869 enter (void);
870
871 // Exit an IRQ uncritical section
872 static void
874
875 };
876
877 } /* namespace interrupts */
878
879 // ----------------------------------------------------------------------
880
881 namespace scheduler
882 {
883
884 void
885 greeting (void);
886
889
890 [[noreturn]] void
891 start (void);
892
893 port::scheduler::state_t
894 lock (void);
895
896 port::scheduler::state_t
897 unlock (void);
898
899 port::scheduler::state_t
900 locked (port::scheduler::state_t state);
901
902 bool
903 locked (void);
904
905 void
907
908 stack::element_t*
909 switch_stacks (stack::element_t* sp);
910
911 void
913
914 bool
916
917 bool
919
920 } /* namespace scheduler */
921
922 // ----------------------------------------------------------------------
923
924 namespace this_thread
925 {
926
927 void
929
930 void
931 yield (void);
932
933 } /* namespace this_thread */
934
935 // ====================================================================
936
938 {
939 public:
940
941 context () = delete;
942
943 // Used to avoid a complex casts below,
944 // that might confuse the Eclipse formatter.
945 typedef void
946 (*func_t) (void);
947
948 static void
949 create (void* context, void* func, void* args);
950
951 };
952 /* class context */
953
954 // ======================================================================
955 class thread
956 {
957 public:
958
959 thread () = delete;
960
961#if defined(OS_USE_RTOS_PORT_SCHEDULER)
962
963 static void
964 create (rtos::thread* obj);
965
966 [[noreturn]]
967 static void
968 destroy_this (rtos::thread* obj);
969
970 static void
971 destroy_other (rtos::thread* obj);
972
973 static void
974 resume (rtos::thread* obj);
975
976 // TODO: move it to port
977 using priority_t = uint8_t;
978
979 static priority_t
980 priority (rtos::thread* obj);
981
982 static result_t
983 priority (rtos::thread* obj, priority_t prio);
984
985 static result_t
986 detach (rtos::thread* obj);
987
988#endif
989
990 };
991 /* class thread */
992
993 // ======================================================================
995 {
996 public:
997
998 clock_systick () = delete;
999
1000 static void
1001 start (void);
1002
1003 static result_t
1005
1012 static void
1014
1015 };
1016
1017 // ======================================================================
1018
1020 {
1021 public:
1022
1023 clock_rtc () = delete;
1024
1031 static void
1033
1034 };
1035
1036 // ======================================================================
1037
1039 {
1040 public:
1041
1042 clock_highres () = delete;
1043
1044 static void
1045 start (void);
1046
1047 static uint32_t
1049
1050 static uint32_t
1052
1053 static uint32_t
1055 };
1056
1057 // ========================================================================
1058
1059 } /* namespace port */
1060 } /* namespace rtos */
1061} /* namespace os */
1062
1063#pragma GCC diagnostic pop
1064
1065// ----------------------------------------------------------------------------
1066
1067#pragma GCC diagnostic push
1068#if defined(__clang__)
1069#elif defined(__GNUC__)
1070#pragma GCC diagnostic ignored "-Waggregate-return"
1071#endif
1072// Must be included after the declarations
1074#pragma GCC diagnostic pop
1075
1076// ----------------------------------------------------------------------------
1077
1078extern "C"
1079{
1080
1085 // os-c-api.h
1086 // int
1087 // os_main (int argc, char* argv[]);
1088
1093}
1094
1095// ----------------------------------------------------------------------------
1096
1098
1099// ----------------------------------------------------------------------------
1100
1101// Required by os_assert_throw()
1103
1111#ifdef NDEBUG /* ANSI standard */
1112#define os_assert_err(__e, __er) \
1113 do { if (!(__e)) return __er; } while (false)
1114#else
1115#define os_assert_err(__e, __er) assert(__e)
1116#endif
1117
1126#ifdef NDEBUG /* ANSI standard */
1127#define os_assert_throw(__e, __er) \
1128 do { if (!(__e)) os::estd::__throw_system_error(__er, #__e); } while (false)
1129#else
1130#define os_assert_throw(__e, __er) assert(__e)
1131#endif
1132
1133#endif /* __cplusplus */
1134
1135// ----------------------------------------------------------------------------
1136
1137// Default definitions for various configuration macros.
1138// Redefine them in `<os-app-config.h>` to the actual values.
1139
1140#if !defined(OS_INTEGER_SYSTICK_FREQUENCY_HZ)
1141#define OS_INTEGER_SYSTICK_FREQUENCY_HZ (1000)
1142#endif
1143
1144// ----------------------------------------------------------------------------
1145
1146#if !defined(OS_INTEGER_RTOS_MAIN_STACK_SIZE_BYTES)
1147#define OS_INTEGER_RTOS_MAIN_STACK_SIZE_BYTES (os::rtos::port::stack::default_size_bytes)
1148#endif
1149
1150#if !defined(OS_INTEGER_RTOS_IDLE_STACK_SIZE_BYTES)
1151#define OS_INTEGER_RTOS_IDLE_STACK_SIZE_BYTES (os::rtos::port::stack::default_size_bytes)
1152#endif
1153
1154#if !defined(OS_BOOL_RTOS_SCHEDULER_PREEMPTIVE)
1155#define OS_BOOL_RTOS_SCHEDULER_PREEMPTIVE (true)
1156#endif
1157
1158#if !defined(OS_INTEGER_RTOS_REUSE_MAGIC)
1159#define OS_INTEGER_RTOS_REUSE_MAGIC (0xA55AAA55)
1160#endif
1161
1162// ----------------------------------------------------------------------------
1163
1164#endif /* CMSIS_PLUS_RTOS_OS_DECLS_H_ */
Generic clock.
Definition os-clocks.h:59
POSIX compliant condition variable.
Definition os-condvar.h:46
Synchronised event flags.
Definition os-evflags.h:58
Base class for attributes.
Definition os-decls.h:563
~attributes_clocked()=default
Destruct the named object instance.
constexpr attributes_clocked()
Construct a named object instance.
Definition os-decls.h:783
Base class for named system objects.
Definition os-decls.h:445
object_named_system()
Construct a named system object instance.
Definition os-decls.h:767
~object_named_system()=default
Destruct the named system object instance.
Base class for named objects.
Definition os-decls.h:351
object_named()
Construct a named object instance.
Definition os-core.cpp:606
const char * name(void) const
Get object name.
Definition os-decls.h:759
~object_named()=default
Destruct the named object instance.
Standard allocator based on the RTOS system default memory manager.
Definition os-memory.h:540
Synchronised memory pool, using the default RTOS allocator.
Definition os-mempool.h:68
POSIX compliant message queue, using the default RTOS allocator.
Definition os-mqueue.h:68
POSIX compliant mutex.
Definition os-mutex.h:53
constexpr null_locker()
Construct a null lockable object instance.
~null_locker()
Destruct the null lockable object instance.
Definition os-decls.h:731
void unlock(void)
Pretend to unlock the scheduler.
Definition os-decls.h:742
void lock(void)
Pretend to lock scheduler.
Definition os-decls.h:736
static uint32_t cycles_since_tick(void)
static uint32_t input_clock_frequency_hz(void)
static uint32_t cycles_per_tick(void)
static void internal_interrupt_service_routine(void)
RTC implementation hook.
static result_t wait_for(clock::duration_t ticks)
static void internal_interrupt_service_routine(void)
SysTick implementation hook.
void(* func_t)(void)
Definition os-decls.h:946
static void create(void *context, void *func, void *args)
static rtos::interrupts::state_t enter(void)
static void exit(rtos::interrupts::state_t state)
static void exit(rtos::interrupts::state_t state)
static rtos::interrupts::state_t enter(void)
POSIX compliant semaphore.
POSIX compliant thread, using the default RTOS allocator.
Definition os-thread.h:250
User single-shot or periodic timer.
Definition os-timer.h:57
Standard thread.
clock_t clock(void)
@ 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
@ any
Special mask to represent any flag.
Definition os-decls.h:316
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
uint32_t duration_t
Type of variables holding timer durations.
Definition os-decls.h:820
uint64_t timestamp_t
Type of variables holding time stamps.
Definition os-decls.h:828
port::scheduler::state_t unlock(void)
port::scheduler::state_t lock(void)
result_t initialize(void)
stack::element_t * switch_stacks(stack::element_t *sp)
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:181
port::scheduler::state_t state_t
Type of variables holding scheduler state codes.
Definition os-decls.h:202
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
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:96
System namespace.
A namespace for functions applying to the current thread.