EtcPal  0.4.1
ETC Platform Abstraction Layer (EtcPal)
View other versions:
event_group.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2022 ETC Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************
16  * This file is a part of EtcPal. For more information, go to:
17  * https://github.com/ETCLabs/EtcPal
18  ******************************************************************************/
19 
22 
23 #ifndef ETCPAL_CPP_EVENT_GROUP_H_
24 #define ETCPAL_CPP_EVENT_GROUP_H_
25 
26 #include "etcpal/cpp/common.h"
27 #include "etcpal/event_group.h"
28 
29 namespace etcpal
30 {
36 
39 
88 {
89 public:
90  EventGroup();
91  ~EventGroup();
92 
93  EventGroup(const EventGroup& other) = delete;
94  EventGroup& operator=(const EventGroup& other) = delete;
95  EventGroup(EventGroup&& other) = delete;
96  EventGroup& operator=(EventGroup&& other) = delete;
97 
98  EventBits Wait(EventBits bits, int flags = 0);
99  EventBits TryWait(EventBits bits, int flags = 0, int timeout_ms = 0);
100  void SetBits(EventBits bits_to_set);
101  EventBits GetBits();
102  void ClearBits(EventBits bits_to_clear);
103  void SetBitsFromIsr(EventBits bits_to_set);
105  void ClearBitsFromIsr(EventBits bits_to_clear);
106 
108 
109 private:
110  etcpal_event_group_t event_group_{};
111 };
112 
115 {
116  (void)etcpal_event_group_create(&event_group_);
117 }
118 
121 {
122  etcpal_event_group_destroy(&event_group_);
123 }
124 
129 inline EventBits EventGroup::Wait(EventBits bits, int flags)
130 {
131  return etcpal_event_group_wait(&event_group_, bits, flags);
132 }
133 
145 inline EventBits EventGroup::TryWait(EventBits bits, int flags, int timeout_ms)
146 {
147  return etcpal_event_group_timed_wait(&event_group_, bits, flags, timeout_ms);
148 }
149 
155 inline void EventGroup::SetBits(EventBits bits_to_set)
156 {
157  etcpal_event_group_set_bits(&event_group_, bits_to_set);
158 }
159 
162 {
163  return etcpal_event_group_get_bits(&event_group_);
164 }
165 
168 inline void EventGroup::ClearBits(EventBits bits_to_clear)
169 {
170  etcpal_event_group_clear_bits(&event_group_, bits_to_clear);
171 }
172 
180 inline void EventGroup::SetBitsFromIsr(EventBits bits_to_set)
181 {
182  etcpal_event_group_set_bits_from_isr(&event_group_, bits_to_set);
183 }
184 
191 {
192  return etcpal_event_group_get_bits_from_isr(&event_group_);
193 }
194 
202 inline void EventGroup::ClearBitsFromIsr(EventBits bits_to_clear)
203 {
204  etcpal_event_group_clear_bits_from_isr(&event_group_, bits_to_clear);
205 }
206 
209 {
210  return event_group_;
211 }
212 
213 }; // namespace etcpal
214 
215 #endif // ETCPAL_CPP_EVENT_GROUP_H_
A wrapper class for the EtcPal event group type.
Definition: event_group.h:88
void ClearBits(EventBits bits_to_clear)
Clear one or more bits in an event group.
Definition: event_group.h:168
EventBits Wait(EventBits bits, int flags=0)
Wait for one or more bits in an event group.
Definition: event_group.h:129
EventGroup()
Create a new event group.
Definition: event_group.h:114
EventBits GetBitsFromIsr()
Get the current bitfield from an event group from an interrupt context.
Definition: event_group.h:190
void SetBitsFromIsr(EventBits bits_to_set)
Set one or more bits in an event group from an interrupt context.
Definition: event_group.h:180
void ClearBitsFromIsr(EventBits bits_to_clear)
Clear one or more bits in an event group from an interrupt context.
Definition: event_group.h:202
etcpal_event_group_t & get()
Get a reference to the underlying etcpal_event_group_t type.
Definition: event_group.h:208
void SetBits(EventBits bits_to_set)
Set one or more bits in an event group.
Definition: event_group.h:155
EventBits GetBits()
Get the current bitfield from an event group.
Definition: event_group.h:161
~EventGroup()
Destroy the event group.
Definition: event_group.h:120
EventBits TryWait(EventBits bits, int flags=0, int timeout_ms=0)
Wait for one or more bits in an event group until a timeout expires.
Definition: event_group.h:145
Common definitions used by EtcPal C++ wrappers.
etcpal_event_bits_t EventBits
The type that holds the event bitfield.
Definition: event_group.h:38
void etcpal_event_group_clear_bits_from_isr(etcpal_event_group_t *id, etcpal_event_bits_t bits_to_clear)
Clear one or more bits in an event group from an interrupt context.
etcpal_event_bits_t etcpal_event_group_wait(etcpal_event_group_t *id, etcpal_event_bits_t bits, int flags)
Wait for one or more bits in an event group.
void etcpal_event_group_set_bits_from_isr(etcpal_event_group_t *id, etcpal_event_bits_t bits_to_set)
Set one or more bits in an event group from an interrupt context.
void etcpal_event_group_destroy(etcpal_event_group_t *id)
Destroy an event group.
etcpal_event_bits_t etcpal_event_group_get_bits(etcpal_event_group_t *id)
Get the current bitfield from an event group.
PLATFORM_DEFINED etcpal_event_bits_t
The type that holds the event bitfield.
Definition: event_group.dox:104
bool etcpal_event_group_create(etcpal_event_group_t *id)
Create a new event group.
void etcpal_event_group_clear_bits(etcpal_event_group_t *id, etcpal_event_bits_t bits_to_clear)
Clear one or more bits in an event group.
void etcpal_event_group_set_bits(etcpal_event_group_t *id, etcpal_event_bits_t bits_to_set)
Set one or more bits in an event group.
PLATFORM_DEFINED etcpal_event_group_t
The event group identifier.
Definition: event_group.dox:95
etcpal_event_bits_t etcpal_event_group_get_bits_from_isr(etcpal_event_group_t *id)
Get the current bitfield from an event group from an interrupt context.
etcpal_event_bits_t etcpal_event_group_timed_wait(etcpal_event_group_t *id, etcpal_event_bits_t bits, int flags, int timeout_ms)
Wait for one or more bits in an event group, giving up after a timeout.