µ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-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#include <cmsis-plus/rtos/os.h>
16
17// ----------------------------------------------------------------------------
18
19#if defined(__clang__)
20#pragma clang diagnostic ignored "-Wc++98-compat"
21#endif
22
23// ----------------------------------------------------------------------------
24
25namespace os
26{
27 namespace rtos
28 {
29 namespace internal
30 {
31 // ------------------------------------------------------------------------
32
35 {
36 os_assert_err(mask != 0, EINVAL);
37
38 assert(port::interrupts::is_priority_valid ());
39
40 {
41 // ----- Enter critical section -------------------------------------
43
44 if (oflags != nullptr)
45 {
46 *oflags = flags_mask_;
47 }
48
49#pragma GCC diagnostic push
50#if defined(__clang__)
51#pragma clang diagnostic ignored "-Wdeprecated-volatile"
52#elif defined(__GNUC__)
53#pragma GCC diagnostic ignored "-Wvolatile"
54#endif
55 flags_mask_ |= mask;
56#pragma GCC diagnostic pop
57
58 // ----- Exit critical section --------------------------------------
59 }
60 return result::ok;
61 }
62
63 bool
65 flags::mode_t mode)
66 {
67 if (mask == flags::any)
68 {
69 // Any flag will do it.
70 if (flags_mask_ != 0)
71 {
72 if (oflags != nullptr)
73 {
74 *oflags = flags_mask_;
75 }
76
77 if (mode & flags::mode::clear)
78 {
79 // Clear them all.
80 flags_mask_ = 0;
81 }
82 return true;
83 }
84 }
85 else if (((((mode & flags::mode::all) != 0))
86 && ((flags_mask_ & mask) == mask))
87 || (((mode & flags::mode::any) != 0) && ((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:34
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:64
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:192
Interrupts critical section RAII helper.
Definition os-sched.h:498
@ 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
@ ok
Function completed; no errors or events occurred.
Definition os-decls.h:181
uint32_t result_t
Type of values returned by RTOS functions.
Definition os-decls.h:96
System namespace.
#define os_assert_err(__e, __er)
Assert or return an error.
Definition os-decls.h:1115
Single file µOS++ RTOS definitions.