µ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++ 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#include <cmsis-plus/rtos/os.h>
31
32// ----------------------------------------------------------------------------
33
34#if defined(__clang__)
35#pragma clang diagnostic ignored "-Wc++98-compat"
36#endif
37
38// ----------------------------------------------------------------------------
39
40namespace os
41{
42 namespace rtos
43 {
44 namespace internal
45 {
46 // ------------------------------------------------------------------------
47
50 {
51 os_assert_err(mask != 0, EINVAL);
52
53 assert(port::interrupts::is_priority_valid ());
54
55 {
56 // ----- Enter critical section -------------------------------------
58
59 if (oflags != nullptr)
60 {
61 *oflags = flags_mask_;
62 }
63
64#pragma GCC diagnostic push
65#if defined(__clang__)
66#pragma clang diagnostic ignored "-Wdeprecated-volatile"
67#endif
68 flags_mask_ |= mask;
69#pragma GCC diagnostic pop
70
71 // ----- Exit critical section --------------------------------------
72 }
73 return result::ok;
74 }
75
76 bool
78 flags::mode_t mode)
79 {
80 if (mask == flags::any)
81 {
82 // Any flag will do it.
83 if (flags_mask_ != 0)
84 {
85 if (oflags != nullptr)
86 {
87 *oflags = flags_mask_;
88 }
89
90 if (mode & flags::mode::clear)
91 {
92 // Clear them all.
93 flags_mask_ = 0;
94 }
95 return true;
96 }
97 }
98 else if (((((mode & flags::mode::all) != 0))
99 && ((flags_mask_ & mask) == mask))
100 || (((mode & flags::mode::any) != 0) && ((flags_mask_ & mask) != 0)))
101 {
102 if (oflags != nullptr)
103 {
104 *oflags = (flags_mask_ & mask);
105 }
106
107 if (mode & flags::mode::clear)
108 {
109#pragma GCC diagnostic push
110#if defined(__clang__)
111#pragma clang diagnostic ignored "-Wdeprecated-volatile"
112#endif
113 // Clear desired flags.
114 flags_mask_ &= ~mask;
115#pragma GCC diagnostic pop
116 }
117 return true;
118 }
119
120 return false;
121 }
122
125 {
126 flags::mask_t ret;
127 {
128 // ----- Enter critical section -------------------------------------
130
131 if (mask == 0)
132 {
133 // Return the entire mask.
134 ret = flags_mask_;
135 }
136 else
137 {
138 ret = flags_mask_ & mask;
139 if ((mode & flags::mode::clear) != 0)
140 {
141#pragma GCC diagnostic push
142#if defined(__clang__)
143#pragma clang diagnostic ignored "-Wdeprecated-volatile"
144#endif
145 // Clear the selected bits; leave the rest untouched.
146 flags_mask_ &= ~mask;
147#pragma GCC diagnostic pop
148 }
149 }
150 // ----- Exit critical section --------------------------------------
151 }
152
153 // Return the selected bits.
154 return ret;
155 }
156
159 {
160 os_assert_err(mask != 0, EINVAL);
161
162 {
163 // ----- Enter critical section -------------------------------------
165
166 if (oflags != nullptr)
167 {
168 *oflags = flags_mask_;
169 }
170
171#pragma GCC diagnostic push
172#if defined(__clang__)
173#pragma clang diagnostic ignored "-Wdeprecated-volatile"
174#endif
175 // Clear the selected bits; leave the rest untouched.
176 flags_mask_ &= ~mask;
177#pragma GCC diagnostic pop
178
179 // ----- Exit critical section --------------------------------------
180 }
181
182 return result::ok;
183 }
184
185 // --------------------------------------------------------------------------
186
187 } /* namespace internal */
188 } /* namespace rtos */
189} /* namespace os */
190
191// ----------------------------------------------------------------------------
result_t raise(flags::mask_t mask, flags::mask_t *oflags)
Raise event flags.
Definition os-flags.cpp:49
flags::mask_t get(flags::mask_t mask, flags::mode_t mode)
Get (and possibly clear) event flags.
Definition os-flags.cpp:124
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:77
result_t clear(flags::mask_t mask, flags::mask_t *oflags)
Clear event flags.
Definition os-flags.cpp:158
flags::mask_t mask(void)
Get the flags mask.
Definition os-flags.h:208
Interrupts critical section RAII helper.
Definition os-sched.h:524
@ 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
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:195
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:110
System namespace.
#define os_assert_err(__e, __er)
Assert or return an error.
Definition os-decls.h:1126
Single file µOS++ RTOS definitions.