µ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-flags.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#include <cmsis-plus/rtos/os.h>
15
16// ----------------------------------------------------------------------------
17
18#if defined(__clang__)
19#pragma clang diagnostic ignored "-Wc++98-compat"
20#endif
21
22// ----------------------------------------------------------------------------
23
24namespace os
25{
26 namespace rtos
27 {
28 namespace internal
29 {
30 // ----------------------------------------------------------------------
31
34 {
35 os_assert_err (mask != 0, EINVAL);
36
37 assert (port::interrupts::is_priority_valid ());
38
39 {
40 // ----- Enter critical section -------------------------------------
42
43 if (oflags != nullptr)
44 {
45 *oflags = flags_mask_;
46 }
47
48#pragma GCC diagnostic push
49#if defined(__clang__)
50#pragma clang diagnostic ignored "-Wdeprecated-volatile"
51#elif defined(__GNUC__)
52#pragma GCC diagnostic ignored "-Wvolatile"
53#endif
54 flags_mask_ |= mask;
55#pragma GCC diagnostic pop
56
57 // ----- Exit critical section --------------------------------------
58 }
59 return result::ok;
60 }
61
62 bool
64 flags::mode_t mode)
65 {
66 if (mask == flags::any)
67 {
68 // Any flag will do it.
69 if (flags_mask_ != 0)
70 {
71 if (oflags != nullptr)
72 {
73 *oflags = flags_mask_;
74 }
75
76 if (mode & flags::mode::clear)
77 {
78 // Clear them all.
79 flags_mask_ = 0;
80 }
81 return true;
82 }
83 }
84 else if (((((mode & flags::mode::all) != 0))
85 && ((flags_mask_ & mask) == mask))
86 || (((mode & flags::mode::any) != 0)
87 && ((flags_mask_ & mask) != 0)))
88 {
89 if (oflags != nullptr)
90 {
91 *oflags = (flags_mask_ & mask);
92 }
93
94 if (mode & flags::mode::clear)
95 {
96#pragma GCC diagnostic push
97#if defined(__clang__)
98#pragma clang diagnostic ignored "-Wdeprecated-volatile"
99#elif defined(__GNUC__)
100#pragma GCC diagnostic ignored "-Wvolatile"
101#endif
102 // Clear desired flags.
103 flags_mask_ &= ~mask;
104#pragma GCC diagnostic pop
105 }
106 return true;
107 }
108
109 return false;
110 }
111
114 {
115 flags::mask_t ret;
116 {
117 // ----- Enter critical section -------------------------------------
119
120 if (mask == 0)
121 {
122 // Return the entire mask.
123 ret = flags_mask_;
124 }
125 else
126 {
127 ret = flags_mask_ & mask;
128 if ((mode & flags::mode::clear) != 0)
129 {
130#pragma GCC diagnostic push
131#if defined(__clang__)
132#pragma clang diagnostic ignored "-Wdeprecated-volatile"
133#elif defined(__GNUC__)
134#pragma GCC diagnostic ignored "-Wvolatile"
135#endif
136 // Clear the selected bits; leave the rest untouched.
137 flags_mask_ &= ~mask;
138#pragma GCC diagnostic pop
139 }
140 }
141 // ----- Exit critical section --------------------------------------
142 }
143
144 // Return the selected bits.
145 return ret;
146 }
147
150 {
151 os_assert_err (mask != 0, EINVAL);
152
153 {
154 // ----- Enter critical section -------------------------------------
156
157 if (oflags != nullptr)
158 {
159 *oflags = flags_mask_;
160 }
161
162#pragma GCC diagnostic push
163#if defined(__clang__)
164#pragma clang diagnostic ignored "-Wdeprecated-volatile"
165#elif defined(__GNUC__)
166#pragma GCC diagnostic ignored "-Wvolatile"
167#endif
168 // Clear the selected bits; leave the rest untouched.
169 flags_mask_ &= ~mask;
170#pragma GCC diagnostic pop
171
172 // ----- Exit critical section --------------------------------------
173 }
174
175 return result::ok;
176 }
177
178 // ----------------------------------------------------------------------
179
180 } /* namespace internal */
181 } /* namespace rtos */
182} /* namespace os */
183
184// ----------------------------------------------------------------------------
result_t raise(flags::mask_t mask, flags::mask_t *oflags)
Raise event flags.
Definition os-flags.cpp:33
flags::mask_t get(flags::mask_t mask, flags::mode_t mode)
Get (and possibly clear) event flags.
Definition os-flags.cpp:113
bool check_raised(flags::mask_t mask, flags::mask_t *oflags, flags::mode_t mode)
Check if expected flags are raised.
Definition os-flags.cpp:63
result_t clear(flags::mask_t mask, flags::mask_t *oflags)
Clear event flags.
Definition os-flags.cpp:149
flags::mask_t mask(void)
Get the flags mask.
Definition os-flags.h:189
Interrupts critical section RAII helper.
Definition os-sched.h:502
@ all
Return when all flags are set.
Definition os-decls.h:295
@ clear
Ask for flags to be cleared after read.
Definition os-decls.h:305
@ any
Return when at least one flag is set.
Definition os-decls.h:300
@ any
Special mask to represent any flag.
Definition os-decls.h:317
uint32_t mode_t
Type of variables holding flags modes.
Definition os-decls.h:277
uint32_t mask_t
Type of variables holding flags masks.
Definition os-decls.h:266
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:179
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:95
System namespace.
#define os_assert_err(__e, __er)
Assert or return an error.
Definition os-decls.h:1101
Single file µOS++ RTOS definitions.