µ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 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#ifndef CMSIS_PLUS_RTOS_OS_DECLS_H_
29#define CMSIS_PLUS_RTOS_OS_DECLS_H_
30
31// ----------------------------------------------------------------------------
32
34
35// Include the application specific definitions.
36#include <cmsis-plus/os-app-config.h>
37// Include the non-portable portable types, enums and constants declarations.
38#include <cmsis-plus/rtos/port/os-decls.h>
39
41
42// ----------------------------------------------------------------------------
43
44#if defined(__cplusplus)
45
46// ----------------------------------------------------------------------------
47
48#include <cstdint>
49#include <cstddef>
50#include <cerrno>
51#include <cstring>
52
53// ----------------------------------------------------------------------------
54
55#pragma GCC diagnostic push
56
57#if defined(__clang__)
58#pragma clang diagnostic ignored "-Wc++98-compat"
59#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
60#endif
61
62// ----------------------------------------------------------------------------
63
68namespace os
69{
73 namespace rtos
74 {
75 // ========================================================================
76
77 // Forward references.
78 class clock;
79 class clock_rtc;
80 class clock_systick;
81
82 class condition_variable;
83 class event_flags;
84 class memory_pool;
85 class message_queue;
86 class mutex;
87 class semaphore;
88 class thread;
89 class timer;
90
91 // ------------------------------------------------------------------------
92
93 namespace memory
94 {
95 template<typename T>
97 } /* namespace memory */
98
99 // ------------------------------------------------------------------------
100
110 using result_t = uint32_t;
111
174 namespace result
175 {
189 enum
190 : result_t
191 {
195 ok = 0
196
197 };
198 } /* namespace result */
199
200 // ------------------------------------------------------------------------
201
206 namespace scheduler
207 {
216 using state_t = port::scheduler::state_t;
217
218 } /* namespace scheduler */
219
220 // ------------------------------------------------------------------------
221
226 namespace statistics
227 {
231 using counter_t = uint64_t;
232
236 using duration_t = uint64_t;
237
238 } /* namespace statistics */
239
240 // ------------------------------------------------------------------------
241
246 namespace interrupts
247 {
257 using state_t = port::interrupts::state_t;
258
259 } /* namespace interrupts */
260
261 // ------------------------------------------------------------------------
262
269 namespace flags
270 {
279 using mask_t = uint32_t;
280
289 using mode_t = uint32_t;
290
296 namespace mode
297 {
301 enum
302 : mode_t
303 {
307 all = 1,
308
312 any = 2,
313
317 clear = 4
318 };
319 } /* namespace mode */
320
324 enum
325 : mask_t
326 {
330 any = 0,
331
335 all = 0xFFFFFFFF
336 };
337
338 } /* namespace flags */
339
340 // ------------------------------------------------------------------------
341
346 namespace this_thread
347 {
348 }
349
350 // ------------------------------------------------------------------------
351
355 namespace internal
356 {
357
358 // ======================================================================
359
365 {
366 public:
367
376 object_named ();
377
383 object_named (const char* name);
384
388 object_named (const object_named&) = default;
389 object_named (object_named&&) = default;
390 // object_named&
391 // operator= (const object_named&) = default;
392 // object_named&
393 // operator= (object_named&&) = default;
401 ~object_named () = default;
402
407 public:
408
420 const char*
421 name (void) const;
422
427 protected:
428
441 const char* const name_ = "-";
442
450 };
451
452 // ======================================================================
453
459 {
460 public:
461
471
477 object_named_system (const char* name);
478
482 object_named_system (const object_named_system&) = default;
484 // object_named_system&
485 // operator= (const object_named_system&) = default;
486 // object_named_system&
487 // operator= (object_named_system&&) = default;
496
512 static void*
513 operator new (std::size_t bytes);
514
521 static void*
522 operator new[] (std::size_t bytes);
523
530 static void*
531 operator new (std::size_t bytes, void* ptr);
532
539 static void*
540 operator new[] (std::size_t bytes, void* ptr);
541
550 static void
551 operator delete (void* ptr, std::size_t bytes);
552
561 static void
562 operator delete[] (void* ptr, std::size_t bytes);
563
568 };
569
570 // ======================================================================
571
577 {
578 public:
579
590 constexpr
592
596 attributes_clocked (const attributes_clocked&) = default;
599 operator= (const attributes_clocked&) = default;
601 operator= (attributes_clocked&&) = default;
610
629 rtos::clock* clock = nullptr;
630
635 protected:
636
645 };
646 } /* namespace internal */
647
648 // ========================================================================
649
658 {
659 public:
660
672 constexpr
674
679 null_locker (const null_locker&) = delete;
680 null_locker (null_locker&&) = delete;
682 operator= (const null_locker&) = delete;
684 operator= (null_locker&&) = delete;
685
693 ~null_locker ();
694
699 public:
700
713 void
714 lock (void);
715
723 void
724 unlock (void);
725
730 };
731
732 // ==========================================================================
733 } /* namespace rtos */
734} /* namespace os */
735
736// ===== Inline & template implementations ====================================
737
738namespace os
739{
740 namespace rtos
741 {
742 // ========================================================================
743
744 inline
746 {
747 ;
748 }
749
750 inline void
752 {
753 ; // Does nothing.
754 }
755
756 inline void
758 {
759 ; // Does nothing.
760 }
761
762 namespace internal
763 {
764 // ======================================================================
765
773 inline const char*
775 {
776 return name_;
777 }
778
779 // ======================================================================
780
781 inline
783 {
784 ;
785 }
786
787 inline
789 object_named (name)
790 {
791 ;
792 }
793
794 // ======================================================================
795
799 constexpr
801 {
802 ;
803 }
804
805 // ========================================================================
806 } /* namespace internal */
807 } /* namespace rtos */
808} /* namespace os */
809
810// ===== Port related definitions =============================================
811
812namespace os
813{
814 namespace rtos
815 {
816 namespace port
817 {
818 class thread;
819 class timer;
820 class mutex;
821
822 class condition_variable;
823 class semaphore;
824 class memory_pool;
825 class message_queue;
826 class event_flags;
827
828 // ======================================================================
829
830 namespace clock
831 {
838 using duration_t = uint32_t;
839
846 using timestamp_t = uint64_t;
847
848 using offset_t = int64_t;
849 } /* namespace clock */
850
851 // ----------------------------------------------------------------------
852
853 namespace interrupts
854 {
855
856 bool
858
859 // ====================================================================
860
862 {
863 public:
864
865 critical_section () = delete;
866
867 // Enter an IRQ critical section
869 enter (void);
870
871 // Exit an IRQ critical section
872 static void
874
875 };
876
877 // ====================================================================
878
880 {
881 public:
882
884
885 // Enter an IRQ uncritical section
887 enter (void);
888
889 // Exit an IRQ uncritical section
890 static void
892
893 };
894
895 } /* namespace interrupts */
896
897 // ----------------------------------------------------------------------
898
899 namespace scheduler
900 {
901
902 void
903 greeting (void);
904
907
908 [[noreturn]] void
909 start (void);
910
911 port::scheduler::state_t
912 lock (void);
913
914 port::scheduler::state_t
915 unlock (void);
916
917 port::scheduler::state_t
918 locked (port::scheduler::state_t state);
919
920 bool
921 locked (void);
922
923 void
925
926 stack::element_t*
927 switch_stacks (stack::element_t* sp);
928
929 void
931
932 bool
934
935 bool
937
938 } /* namespace scheduler */
939
940 // ----------------------------------------------------------------------
941
942 namespace this_thread
943 {
944
945 void
947
948 void
949 yield (void);
950
951 } /* namespace this_thread */
952
953 // ====================================================================
954
956 {
957 public:
958
959 context () = delete;
960
961 // Used to avoid a complex casts below,
962 // that might confuse the Eclipse formatter.
963 typedef void
964 (*func_t) (void);
965
966 static void
967 create (void* context, void* func, void* args);
968
969 };
970 /* class context */
971
972 // ======================================================================
973 class thread
974 {
975 public:
976
977 thread () = delete;
978
979#if defined(OS_USE_RTOS_PORT_SCHEDULER)
980
981 static void
982 create (rtos::thread* obj);
983
984 [[noreturn]]
985 static void
986 destroy_this (rtos::thread* obj);
987
988 static void
989 destroy_other (rtos::thread* obj);
990
991 static void
992 resume (rtos::thread* obj);
993
994 // TODO: move it to port
995 using priority_t = uint8_t;
996
997 static priority_t
998 priority (rtos::thread* obj);
999
1000 static result_t
1001 priority (rtos::thread* obj, priority_t prio);
1002
1003 static result_t
1004 detach (rtos::thread* obj);
1005
1006#endif
1007
1008 };
1009 /* class thread */
1010
1011 // ======================================================================
1013 {
1014 public:
1015
1016 clock_systick () = delete;
1017
1018 static void
1019 start (void);
1020
1021 static result_t
1023
1030 static void
1032
1033 };
1034
1035 // ======================================================================
1036
1038 {
1039 public:
1040
1041 clock_rtc () = delete;
1042
1049 static void
1051
1052 };
1053
1054 // ======================================================================
1055
1057 {
1058 public:
1059
1060 clock_highres () = delete;
1061
1062 static void
1063 start (void);
1064
1065 static uint32_t
1067
1068 static uint32_t
1070
1071 static uint32_t
1073 };
1074
1075 // ========================================================================
1076
1077 } /* namespace port */
1078 } /* namespace rtos */
1079} /* namespace os */
1080
1081#pragma GCC diagnostic pop
1082
1083// ----------------------------------------------------------------------------
1084
1085// Must be included after the declarations
1087
1088// ----------------------------------------------------------------------------
1089
1090extern "C"
1091{
1092
1097 int
1098 os_main (int argc, char* argv[]);
1099
1104}
1105
1106// ----------------------------------------------------------------------------
1107
1109
1110// ----------------------------------------------------------------------------
1111
1112// Required by os_assert_throw()
1114
1122#ifdef NDEBUG /* ANSI standard */
1123#define os_assert_err(__e, __er) \
1124 do { if (!(__e)) return __er; } while (false)
1125#else
1126#define os_assert_err(__e, __er) assert(__e)
1127#endif
1128
1137#ifdef NDEBUG /* ANSI standard */
1138#define os_assert_throw(__e, __er) \
1139 do { if (!(__e)) os::estd::__throw_system_error(__er, #__e); } while (false)
1140#else
1141#define os_assert_throw(__e, __er) assert(__e)
1142#endif
1143
1144#endif /* __cplusplus */
1145
1146// ----------------------------------------------------------------------------
1147
1148// Default definitions for various configuration macros.
1149// Redefine them in `<os-app-config.h>` to the actual values.
1150
1151#if !defined(OS_INTEGER_SYSTICK_FREQUENCY_HZ)
1152#define OS_INTEGER_SYSTICK_FREQUENCY_HZ (1000)
1153#endif
1154
1155// ----------------------------------------------------------------------------
1156
1157#if !defined(OS_INTEGER_RTOS_MAIN_STACK_SIZE_BYTES)
1158#define OS_INTEGER_RTOS_MAIN_STACK_SIZE_BYTES (os::rtos::port::stack::default_size_bytes)
1159#endif
1160
1161#if !defined(OS_INTEGER_RTOS_IDLE_STACK_SIZE_BYTES)
1162#define OS_INTEGER_RTOS_IDLE_STACK_SIZE_BYTES (os::rtos::port::stack::default_size_bytes)
1163#endif
1164
1165#if !defined(OS_BOOL_RTOS_SCHEDULER_PREEMPTIVE)
1166#define OS_BOOL_RTOS_SCHEDULER_PREEMPTIVE (true)
1167#endif
1168
1169#if !defined(OS_INTEGER_RTOS_REUSE_MAGIC)
1170#define OS_INTEGER_RTOS_REUSE_MAGIC (0xA55AAA55)
1171#endif
1172
1173// ----------------------------------------------------------------------------
1174
1175#endif /* CMSIS_PLUS_RTOS_OS_DECLS_H_ */
Generic clock.
Definition os-clocks.h:66
POSIX compliant condition variable.
Definition os-condvar.h:62
Synchronised event flags.
Definition os-evflags.h:66
Base class for attributes.
Definition os-decls.h:577
~attributes_clocked()=default
Destruct the named object instance.
constexpr attributes_clocked()
Construct a named object instance.
Definition os-decls.h:800
Base class for named system objects.
Definition os-decls.h:459
object_named_system()
Construct a named system object instance.
Definition os-decls.h:782
~object_named_system()=default
Destruct the named system object instance.
Base class for named objects.
Definition os-decls.h:365
object_named()
Construct a named object instance.
Definition os-core.cpp:599
const char * name(void) const
Get object name.
Definition os-decls.h:774
~object_named()=default
Destruct the named object instance.
Standard allocator based on the RTOS system default memory manager.
Definition os-memory.h:544
Synchronised memory pool, using the default RTOS allocator.
Definition os-mempool.h:70
POSIX compliant message queue, using the default RTOS allocator.
Definition os-mqueue.h:70
POSIX compliant mutex.
Definition os-mutex.h:65
constexpr null_locker()
Construct a null lockable object instance.
~null_locker()
Destruct the null lockable object instance.
Definition os-decls.h:745
void unlock(void)
Pretend to unlock the scheduler.
Definition os-decls.h:757
void lock(void)
Pretend to lock scheduler.
Definition os-decls.h:751
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:964
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:247
User single-shot or periodic timer.
Definition os-timer.h:65
Standard thread.
clock_t clock(void)
int os_main(int argc, char *argv[])
Application entry point, running on the main thread context.
@ all
Return when all flags are set.
Definition os-decls.h:307
@ clear
Ask for flags to be cleared after read.
Definition os-decls.h:317
@ any
Return when at least one flag is set.
Definition os-decls.h:312
@ any
Special mask to represent any flag.
Definition os-decls.h:330
uint32_t mode_t
Type of variables holding flags modes.
Definition os-decls.h:289
uint32_t mask_t
Type of variables holding flags masks.
Definition os-decls.h:279
port::interrupts::state_t state_t
Type of variables holding interrupts statu codes.
Definition os-decls.h:257
uint32_t duration_t
Type of variables holding timer durations.
Definition os-decls.h:838
uint64_t timestamp_t
Type of variables holding time stamps.
Definition os-decls.h:846
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:195
port::scheduler::state_t state_t
Type of variables holding scheduler state codes.
Definition os-decls.h:216
uint64_t duration_t
Type of variables holding durations in CPU cycles.
Definition os-decls.h:236
uint64_t counter_t
Type of variables holding context switches counters.
Definition os-decls.h:231
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:110
System namespace.
A namespace for functions applying to the current thread.