nrfcxx
0.1.0
C++-17 Framework for Nordic nRF5 Devices
|
A record of events that occur asynchonously. More...
#include <nrfcxx/core.hpp>
Public Types | |
using | event_type = unsigned int |
The type used to represent a (set of) event(s). More... | |
Public Member Functions | |
constexpr | event_set (event_type events=0U) |
Construct with an optional initial set of events. | |
operator bool () const | |
Implicit cast to bool, true if there are events pending. | |
event_type | fetch () const |
Return the current event set. | |
event_type | fetch_and_clear () |
Atomically return the current event set and clear the event record. | |
event_set_copy | copy_and_clear () |
Create a non-mutex copy then clear the current event set. More... | |
void | set (event_type events) |
Atomically record one or more events. More... | |
void | reset (event_type events=0U) |
Reset the event set to a specific state. | |
notifier_type | make_setter (event_type events) |
Return an invokable object that records events in this set. More... | |
Static Public Member Functions | |
static void | cev () |
Safely clear the MCU event flag. More... | |
A record of events that occur asynchonously.
This class supports recording up to 32 distinct types of event for the application to process at its convenience.
The order that the events occurred is not retained, nor is the fact of duplicate events.
Example:
// main loop while (true) { nrfcxx::event_set::cev(); auto pending = my_events.copy_and_clear(); if (pending.fetch_and_clear(EVT_EVT0)) { // ... } // ... __WFE(); // sleep until next IRQ-driven event }
using nrfcxx::event_set::event_type = unsigned int |
The type used to represent a (set of) event(s).
Each event is an independent bit in the word representation.
|
inlinestatic |
Safely clear the MCU event flag.
This function should be invoked prior to fetch_and_clear() for event sets that record fact-of interrupt occurrence. Doing so ensures that __WFE()
invoked after processing events will not suspend if an interrupt occurred while or after the event records were fetched, but will suspend if no interrupts occurred after invoking cev().
|
inline |
Create a non-mutex copy then clear the current event set.
The resulting object can be used to process individual events without incuring mutex costs.
|
inline |
Return an invokable object that records events in this set.
Example:
auto setter = events.make_setter(EVT_ALARM); // ... if (alarmed) { setter(); }
events | the events that should be set by the returned notifier. |
|
inline |
Atomically record one or more events.
This sets the processor event register after the event set has been updating, ensuring a subsequent __WFE()
will not block even if the event was not set in an interrupt handler.