Embedded Artistry Framework
Embedded Systems C++ Framework
Public Member Functions | Private Attributes | List of all members
embutil::InterruptCondition< TWaitOp, TNotifyOp > Class Template Reference

Generic interrupt condition concept. More...

#include <interrupt_condition.hpp>

Public Member Functions

 InterruptCondition (const TWaitOp &w) noexcept
 Construct an InterruptCondition with a wait op. More...
 
 InterruptCondition (const TWaitOp &w, const TNotifyOp &n) noexcept
 Construct an InterruptCondition with a wait op and notify op. More...
 
 InterruptCondition (const InterruptCondition &)=delete
 Deleted copy constructor. More...
 
const InterruptConditionoperator= (const InterruptCondition &)=delete
 Deleted copy assignment operator. More...
 
 InterruptCondition (InterruptCondition &&)=delete
 Deleted move constructor. More...
 
InterruptConditionoperator= (InterruptCondition &&)=delete
 Deleted move assignment operator. More...
 
template<typename TLock >
void wait (TLock &lock) noexcept
 Initiate a wait state. More...
 
void notify () const noexcept
 Notify the processor to wake up. More...
 
void set_notify_op (TNotifyOp &&n) noexcept
 Set the notify operation. More...
 

Private Attributes

TNotifyOp notify_
 (optional) notification operation functor More...
 
TWaitOp wait_
 Wait operaton functor. More...
 

Detailed Description

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
class embutil::InterruptCondition< TWaitOp, TNotifyOp >

Generic interrupt condition concept.

Provides a condition-variable class for use on an embedded system which does not have threading, but wants to use interrupts for notifications (e.g. with ARM's WFI instruction). ` If we think about interrupt and non-interrupt execution modes as two threads, locking in a non-interrupt thread is equivalent to disabling interrupts; waiting for condition variable to be notified is the equivalent for waiting for interrupts.

Clients supply one or two operations:

Note
Some scenarios, like wfi, do not require a function to be called. Instead, the wfi state exit is equivalent to notify(). Clients do not need to supply the notify operation in such scenarios.

This class is designed to be used with an InterruptLock.

Template Parameters
TWaitOpRepresents the storage type (std::function, stdext::inplace_function) and prototype for the wait operation.
TNotifyOpRepresents the storage type (std::function, stdext::inplace_function) and prototype for the notify operation.

Constructor & Destructor Documentation

◆ InterruptCondition() [1/4]

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
embutil::InterruptCondition< TWaitOp, TNotifyOp >::InterruptCondition ( const TWaitOp &  w)
inlineexplicitnoexcept

Construct an InterruptCondition with a wait op.

Parameters
[in]wThe wait operation functor.

◆ InterruptCondition() [2/4]

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
embutil::InterruptCondition< TWaitOp, TNotifyOp >::InterruptCondition ( const TWaitOp &  w,
const TNotifyOp &  n 
)
inlineexplicitnoexcept

Construct an InterruptCondition with a wait op and notify op.

Parameters
[in]wThe wait operation functor.
[in]nThe notify operation functor.

◆ InterruptCondition() [3/4]

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
embutil::InterruptCondition< TWaitOp, TNotifyOp >::InterruptCondition ( const InterruptCondition< TWaitOp, TNotifyOp > &  )
delete

Deleted copy constructor.

◆ InterruptCondition() [4/4]

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
embutil::InterruptCondition< TWaitOp, TNotifyOp >::InterruptCondition ( InterruptCondition< TWaitOp, TNotifyOp > &&  )
delete

Deleted move constructor.

Member Function Documentation

◆ notify()

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
void embutil::InterruptCondition< TWaitOp, TNotifyOp >::notify ( ) const
inlinenoexcept

Notify the processor to wake up.

This function is used to notify condition that wait should be terminated. If nothing needs to be done (e.g. WFI), then client classes do not need to supply a notify function.

References embutil::InterruptCondition< TWaitOp, TNotifyOp >::notify_.

◆ operator=() [1/2]

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
const InterruptCondition& embutil::InterruptCondition< TWaitOp, TNotifyOp >::operator= ( const InterruptCondition< TWaitOp, TNotifyOp > &  )
delete

Deleted copy assignment operator.

◆ operator=() [2/2]

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
InterruptCondition& embutil::InterruptCondition< TWaitOp, TNotifyOp >::operator= ( InterruptCondition< TWaitOp, TNotifyOp > &&  )
delete

Deleted move assignment operator.

◆ set_notify_op()

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
void embutil::InterruptCondition< TWaitOp, TNotifyOp >::set_notify_op ( TNotifyOp &&  n)
inlinenoexcept

Set the notify operation.

Parameters
[in]nThe operation to call to notify() the processor that the wait is completed.

References n, and embutil::InterruptCondition< TWaitOp, TNotifyOp >::notify_.

◆ wait()

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
template<typename TLock >
void embutil::InterruptCondition< TWaitOp, TNotifyOp >::wait ( TLock &  lock)
inlinenoexcept

Initiate a wait state.

Receives the reference to lockable object (has lock() and unlock() member functions) that is already locked.

The behavior of this function matches std::condition_variable:

  • locked lock is received
  • unlock the lock
  • wait for notification to wake up
  • re-acquire the lock and return control to the caller

This function is marked noexcept because we want the program to terminate if an exception results from this call. We don't actually know whether lock/unlock/wait_ can throw.

Template Parameters
TLockthe type of the lock. The compiler deduces this template parameter.
Parameters
lockThe lock instance.
Precondition
lock is already locked.
Postcondition
lock is locked.

References embutil::InterruptCondition< TWaitOp, TNotifyOp >::wait_.

Member Data Documentation

◆ notify_

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
TNotifyOp embutil::InterruptCondition< TWaitOp, TNotifyOp >::notify_
private

◆ wait_

template<typename TWaitOp = stdext::inplace_function<void()>, typename TNotifyOp = stdext::inplace_function<void()>>
TWaitOp embutil::InterruptCondition< TWaitOp, TNotifyOp >::wait_
private

Wait operaton functor.

Referenced by embutil::InterruptCondition< TWaitOp, TNotifyOp >::wait().


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