Mistake on this page?
Report an issue in GitHub or email us
EventFlags.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2019 ARM Limited
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 #ifndef EVENT_FLAG_H
24 #define EVENT_FLAG_H
25 
26 #include <cstddef>
27 #include <stdint.h>
28 #include "rtos/Kernel.h"
29 #include "rtos/mbed_rtos_types.h"
30 #include "rtos/internal/mbed_rtos1_types.h"
31 #include "rtos/internal/mbed_rtos_storage.h"
32 
33 #include "platform/NonCopyable.h"
34 
35 namespace rtos {
36 /** \addtogroup rtos-public-api */
37 /** @{*/
38 
39 /**
40  * \defgroup rtos_EventFlags EventFlags class
41  * @{
42  */
43 
44 /** The EventFlags class is used to control event flags or wait for event flags other threads control.
45 
46  @note
47  EventFlags support 31 flags. The MSB flag is ignored. It is used to return an error code (@a osFlagsError).
48 
49  @note
50  Memory considerations: The EventFlags control structures will be created on the current thread's stack, both for the Mbed OS
51  and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
52 */
53 class EventFlags : private mbed::NonCopyable<EventFlags> {
54 public:
55  /** Create and initialize an EventFlags object.
56  *
57  * @note You cannot call this function from ISR context.
58  */
59  EventFlags();
60 
61  /** Create and initialize an EventFlags object.
62 
63  @param name name to be used for this EventFlags. It has to stay allocated for the lifetime of the thread.
64 
65  @note You cannot call this function from ISR context.
66  */
67  EventFlags(const char *name);
68 
69  /** Set the specified event flags.
70  @param flags the flags that will be set.
71  @return event flags after setting or error code if highest bit set (see @a osFlagsError for details).
72 
73  @note This function may be called from ISR context.
74  */
75  uint32_t set(uint32_t flags);
76 
77  /** Clear the specified event flags.
78  @param flags the flags that will be cleared (default: 0x7fffffff -- all flags).
79  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
80 
81  @note You may call this function from ISR context.
82  */
83  uint32_t clear(uint32_t flags = 0x7fffffff);
84 
85  /** Get the currently set event flags.
86  @return current event flags.
87 
88  @note You may call this function from ISR context.
89  */
90  uint32_t get() const;
91 
92  /** Wait for all of the specified event flags to become signaled.
93  @param flags the flags to wait for (default: 0 -- no flags).
94  @param millisec timeout value (default: osWaitForever).
95  @param clear clear specified event flags after waiting for them (default: true).
96  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
97 
98  @note You may call this function from ISR context if the millisec parameter is set to 0.
99  */
100  uint32_t wait_all(uint32_t flags = 0, uint32_t millisec = osWaitForever, bool clear = true);
101 
102  /** Wait for all of the specified event flags to become signaled.
103  @param flags the flags to wait for.
104  @param rel_time timeout value.
105  @param clear clear specified event flags after waiting for them (default: true).
106  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
107 
108  @note You may call this function from ISR context if the rel_time parameter is set to 0.
109  */
110  uint32_t wait_all_for(uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear = true);
111 
112  /** Wait for all of the specified event flags to become signaled.
113  @param flags the flags to wait for.
114  @param abs_time timeout value.
115  @param clear clear specified event flags after waiting for them (default: true).
116  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
117 
118  @note You cannot call this function from ISR context.
119  */
120  uint32_t wait_all_until(uint32_t flags, Kernel::Clock::time_point abs_time, bool clear = true);
121 
122  /** Wait for any of the specified event flags to become signaled.
123  @param flags the flags to wait for (default: 0 -- no flags).
124  @param millisec timeout value (default: osWaitForever).
125  @param clear clear specified event flags after waiting for them (default: true).
126  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
127 
128  @note This function may be called from ISR context if the millisec parameter is set to 0.
129  */
130  uint32_t wait_any(uint32_t flags = 0, uint32_t millisec = osWaitForever, bool clear = true);
131 
132  /** Wait for any of the specified event flags to become signaled.
133  @param flags the flags to wait for.
134  @param rel_time timeout value.
135  @param clear clear specified event flags after waiting for them (default: true).
136  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
137 
138  @note This function may be called from ISR context if the millisec parameter is set to 0.
139  */
140  uint32_t wait_any_for(uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear = true);
141 
142  /** Wait for any of the specified event flags to become signaled.
143  @param flags the flags to wait for.
144  @param abs_time timeout value.
145  @param clear clear specified event flags after waiting for them (default: true).
146  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
147 
148  @note You cannot call this function from ISR context.
149  */
150  uint32_t wait_any_until(uint32_t flags, Kernel::Clock::time_point abs_time, bool clear = true);
151 
152  /** EventFlags destructor.
153 
154  @note You cannot call this function from ISR context.
155  */
156  ~EventFlags();
157 
158 private:
159  void constructor(const char *name = nullptr);
160  uint32_t wait_for(uint32_t flags, uint32_t opt, Kernel::Clock::duration_u32 rel_time, bool clear);
161  uint32_t wait_until(uint32_t flags, uint32_t opt, Kernel::Clock::time_point abs_time, bool clear);
162 
163 #if MBED_CONF_RTOS_PRESENT
164  osEventFlagsId_t _id;
165  mbed_rtos_storage_event_flags_t _obj_mem;
166 #else
167  uint32_t _flags;
168 #endif
169 };
170 
171 /** @}*/
172 /** @}*/
173 
174 }
175 #endif
~EventFlags()
EventFlags destructor.
The EventFlags class is used to control event flags or wait for event flags other threads control...
Definition: EventFlags.h:53
uint32_t clear(uint32_t flags=0x7fffffff)
Clear the specified event flags.
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:162
uint32_t wait_all_for(uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear=true)
Wait for all of the specified event flags to become signaled.
uint32_t wait_any_until(uint32_t flags, Kernel::Clock::time_point abs_time, bool clear=true)
Wait for any of the specified event flags to become signaled.
uint32_t wait_all(uint32_t flags=0, uint32_t millisec=osWaitForever, bool clear=true)
Wait for all of the specified event flags to become signaled.
uint32_t wait_all_until(uint32_t flags, Kernel::Clock::time_point abs_time, bool clear=true)
Wait for all of the specified event flags to become signaled.
EventFlags()
Create and initialize an EventFlags object.
Definition: TaskBase.h:25
uint32_t wait_any_for(uint32_t flags, Kernel::Clock::duration_u32 rel_time, bool clear=true)
Wait for any of the specified event flags to become signaled.
uint32_t wait_any(uint32_t flags=0, uint32_t millisec=osWaitForever, bool clear=true)
Wait for any of the specified event flags to become signaled.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.