EtcPal  0.4.1
ETC Platform Abstraction Layer (EtcPal)
View other versions:
EventGroup Class Reference

Overview

A wrapper class for the EtcPal event group type.

Example usage:

etcpal::EventGroup event_group;
constexpr etcpal::EventBits kEventMessageReceived = 0x1;
constexpr etcpal::EventBits kEventMessageError = 0x2;
void event_handler_thread()
{
while (keep_running)
{
etcpal::EventBits event = event_group.Wait(kEventMessageReceived | kEventMessageError,
if (event & kEventMessageReceived)
{
// Handle message received...
}
// Note: Depending on the user implementation, kEventMessageReceived and kEventMessageError
// could be set at the same time.
if (event & kEventMessageError)
{
// Handle message error...
}
// Since we passed ETCPAL_EVENT_GROUP_AUTO_CLEAR to Wait(), the event bits do not need to
// be explicitly cleared before the next iteration.
}
}
void message_listener_thread()
{
while (keep_running)
{
// Get message...
etcpal::EventBits event_bits = kEventMessageReceived;
if (message_error)
{
event_bits |= kEventMessageError;
}
event_group.SetBits(event_bits);
}
}
A wrapper class for the EtcPal event group type.
Definition: event_group.h:88
EventBits Wait(EventBits bits, int flags=0)
Wait for one or more bits in an event group.
Definition: event_group.h:129
void SetBits(EventBits bits_to_set)
Set one or more bits in an event group.
Definition: event_group.h:155
etcpal_event_bits_t EventBits
The type that holds the event bitfield.
Definition: event_group.h:38
#define ETCPAL_EVENT_GROUP_AUTO_CLEAR
Clear bits automatically when they are returned from a wait function.
Definition: event_group.h:40

See event_group (Event Groups) for more information.

Public Member Functions

 EventGroup ()
 Create a new event group.
 
 ~EventGroup ()
 Destroy the event group.
 
 EventGroup (const EventGroup &other)=delete
 
EventGroupoperator= (const EventGroup &other)=delete
 
 EventGroup (EventGroup &&other)=delete
 
EventGroupoperator= (EventGroup &&other)=delete
 
EventBits Wait (EventBits bits, int flags=0)
 Wait for one or more bits in an event group. More...
 
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. More...
 
void SetBits (EventBits bits_to_set)
 Set one or more bits in an event group. More...
 
EventBits GetBits ()
 Get the current bitfield from an event group.
 
void ClearBits (EventBits bits_to_clear)
 Clear one or more bits in an event group. More...
 
void SetBitsFromIsr (EventBits bits_to_set)
 Set one or more bits in an event group from an interrupt context. More...
 
EventBits GetBitsFromIsr ()
 Get the current bitfield from an event group from an interrupt context. More...
 
void ClearBitsFromIsr (EventBits bits_to_clear)
 Clear one or more bits in an event group from an interrupt context. More...
 
etcpal_event_group_tget ()
 Get a reference to the underlying etcpal_event_group_t type.
 

Member Function Documentation

◆ ClearBits()

void ClearBits ( EventBits  bits_to_clear)
inline

Clear one or more bits in an event group.

Parameters
bits_to_clearMask of bits to clear.

◆ ClearBitsFromIsr()

void ClearBitsFromIsr ( EventBits  bits_to_clear)
inline

Clear one or more bits in an event group from an interrupt context.

NOTE: Only meaningful on some platforms. See the table in event_group (Event Groups) and the description of etcpal_event_group_clear_bits_from_isr() for more information. On platforms on which it is not meaningful, executes the equivalent of ClearBits().

Parameters
bits_to_clearMask of bits to clear.

◆ GetBitsFromIsr()

EventBits GetBitsFromIsr ( )
inline

Get the current bitfield from an event group from an interrupt context.

NOTE: Only meaningful on some platforms. See the table in event_group (Event Groups) and the description of etcpal_event_group_get_bits_from_isr() for more information. On platforms on which it is not meaningful, executes the equivalent of GetBits().

◆ SetBits()

void SetBits ( EventBits  bits_to_set)
inline

Set one or more bits in an event group.

See etcpal_event_group_set_bits() for more information.

Parameters
bits_to_setMask of bits in the event group to set.

◆ SetBitsFromIsr()

void SetBitsFromIsr ( EventBits  bits_to_set)
inline

Set one or more bits in an event group from an interrupt context.

NOTE: Only meaningful on some platforms. See the table in event_group (Event Groups) and the description of etcpal_event_group_set_bits_from_isr() for more information. On platforms on which it is not meaningful, executes the equivalent of SetBits().

Parameters
bits_to_setMask of bits in the event group to set.

◆ TryWait()

EventBits TryWait ( EventBits  bits,
int  flags = 0,
int  timeout_ms = 0 
)
inline

Wait for one or more bits in an event group until a timeout expires.

NOTE: Timeouts other than 0 or ETCPAL_WAIT_FOREVER are typically only honored on real-time platforms. See the table in event_group (Event Groups) for more information. On platforms where timeouts are not honored, passing 0 for timeout_ms returns the state of the event bits immediately, while any other value executes the equivalent of Wait().

Parameters
bitsMask of bits in the event group to wait for.
flagsFlags that define waiting options.
timeout_msMaximum amount of time to wait for the event bits, in milliseconds. If ETCPAL_WAIT_FOREVER is given, the result is the same as if Wait() was called.

◆ Wait()

EventBits Wait ( EventBits  bits,
int  flags = 0 
)
inline

Wait for one or more bits in an event group.

Parameters
bitsMask of bits in the event group to wait for.
flagsFlags that define waiting options.
Returns
The result of etcpal_event_group_wait() on the underlying event group.

The documentation for this class was generated from the following file: