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  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 #ifndef EVENT_FLAG_H
23 #define EVENT_FLAG_H
24 
25 #include <cstddef>
26 #include <stdint.h>
27 #include "rtos/mbed_rtos_types.h"
28 #include "rtos/mbed_rtos1_types.h"
29 #include "rtos/mbed_rtos_storage.h"
30 
31 #include "platform/NonCopyable.h"
32 
33 namespace rtos {
34 /** \addtogroup rtos-public-api */
35 /** @{*/
36 
37 /**
38  * \defgroup rtos_EventFlags EventFlags class
39  * @{
40  */
41 
42 /** The EventFlags class is used to control event flags or wait for event flags other threads control.
43 
44  @note
45  EventFlags support 31 flags. The MSB flag is ignored. It is used to return an error code (@a osFlagsError).
46 
47  @note
48  Memory considerations: The EventFlags control structures will be created on the current thread's stack, both for the Mbed OS
49  and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
50 */
51 class EventFlags : private mbed::NonCopyable<EventFlags> {
52 public:
53  /** Create and initialize an EventFlags object.
54  *
55  * @note You cannot call this function from ISR context.
56  */
57  EventFlags();
58 
59  /** Create and initialize an EventFlags object.
60 
61  @param name name to be used for this EventFlags. It has to stay allocated for the lifetime of the thread.
62 
63  @note You cannot call this function from ISR context.
64  */
65  EventFlags(const char *name);
66 
67  /** Set the specified event flags.
68  @param flags the flags that will be set.
69  @return event flags after setting or error code if highest bit set (see @a osFlagsError for details).
70 
71  @note This function may be called from ISR context.
72  */
73  uint32_t set(uint32_t flags);
74 
75  /** Clear the specified event flags.
76  @param flags the flags that will be cleared (default: 0x7fffffff -- all flags).
77  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
78 
79  @note You may call this function from ISR context.
80  */
81  uint32_t clear(uint32_t flags = 0x7fffffff);
82 
83  /** Get the currently set event flags.
84  @return current event flags.
85 
86  @note You may call this function from ISR context.
87  */
88  uint32_t get() const;
89 
90  /** Wait for all of the specified event flags to become signaled.
91  @param flags the flags to wait for (default: 0 -- no flags).
92  @param millisec timeout value (default: osWaitForever).
93  @param clear clear specified event flags after waiting for them (default: true).
94  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
95 
96  @note You may call this function from ISR context if the millisec parameter is set to 0.
97  */
98  uint32_t wait_all(uint32_t flags = 0, uint32_t millisec = osWaitForever, bool clear = true);
99 
100  /** Wait for any of the specified event flags to become signaled.
101  @param flags the flags to wait for (default: 0 -- no flags).
102  @param millisec timeout value (default: osWaitForever).
103  @param clear clear specified event flags after waiting for them (default: true).
104  @return event flags before clearing or error code if highest bit set (see @a osFlagsError for details).
105 
106  @note This function may be called from ISR context if the millisec parameter is set to 0.
107  */
108  uint32_t wait_any(uint32_t flags = 0, uint32_t millisec = osWaitForever, bool clear = true);
109 
110  /** EventFlags destructor.
111 
112  @note You cannot call this function from ISR context.
113  */
114  ~EventFlags();
115 
116 private:
117  void constructor(const char *name = nullptr);
118  uint32_t wait(uint32_t flags, uint32_t opt, uint32_t millisec, bool clear);
119 #if MBED_CONF_RTOS_PRESENT
120  osEventFlagsId_t _id;
122 #else
123  uint32_t _flags;
124 #endif
125 };
126 
127 /** @}*/
128 /** @}*/
129 
130 }
131 #endif
~EventFlags()
EventFlags destructor.
The EventFlags class is used to control event flags or wait for event flags other threads control...
Definition: EventFlags.h:51
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:169
Event Flags Control Block.
Definition: rtx_os.h:166
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.
EventFlags()
Create and initialize an EventFlags object.
Definition: TaskBase.h:25
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.