nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Public Types | Public Member Functions | Static Public Member Functions
nrfcxx::event_set Class Reference

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...
 

Detailed Description

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
}

Member Typedef Documentation

◆ event_type

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.

Member Function Documentation

◆ cev()

static void nrfcxx::event_set::cev ( )
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().

◆ copy_and_clear()

event_set_copy nrfcxx::event_set::copy_and_clear ( )
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.

◆ make_setter()

notifier_type nrfcxx::event_set::make_setter ( event_type  events)
inline

Return an invokable object that records events in this set.

Example:

auto setter = events.make_setter(EVT_ALARM);
// ...
if (alarmed) {
  setter();
}
Parameters
eventsthe events that should be set by the returned notifier.
Warning
There is no link from an to a setter setter that references it. If an event set instance has a limited lifetime then before the set is destroyed any infrastructure that has recorded a setter for it should be updated to clear that setter.

◆ set()

void nrfcxx::event_set::set ( event_type  events)
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.


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