Embedded Artistry Framework
Embedded Systems C++ Framework
Functions
Volatile load/store

These functions promote safer loading and storing of volatile values. More...

Collaboration diagram for Volatile load/store:

Functions

template<typename TType >
constexpr TType embutil::volatile_load (const TType *target) noexcept
 Read from a volatile variable. More...
 
template<typename TType >
constexpr TType embutil::volatile_load (volatile const TType *target) noexcept
 Read from a volatile memory location. More...
 
template<typename TType >
void embutil::volatile_store (TType *target, TType value) noexcept
 Write to a volatile variable. More...
 
template<typename TType >
void embutil::volatile_store (volatile TType *target, TType value) noexcept
 Write to a volatile memory location. More...
 

Detailed Description

These functions promote safer loading and storing of volatile values.

To quote Odin Holmes:

There is a scary amount of bare metal devs who think volatile means atomic, because sometimes it happens to mean that on primitive cores.

volatile int i = 2; //probably atomic
i++; //not atomic ...

Instead we must use volatile_load() and volatile_store() to ensure the operations are probably atomic:

auto r = volatile_load(&i);
r++;

What are some goals for an implementation of volatile_load() and volatile_store()?

Note
Implementations are not obliged to provide cross-thread ordering for instances of ​ volatile_load() and ​volatile_store() in the absence of other mechanisms. One such mechanism is ​atomic_thread_fence​.

Function Documentation

◆ volatile_load() [1/2]

template<typename TType >
constexpr TType embutil::volatile_load ( const TType *  target)
inlinenoexcept

Read from a volatile variable.

Template Parameters
TTypethe type of the variable. This will be deduced by the compiler.
Note
T​Type shall satisfy the requirements of ​TrivallyCopyable​.
Parameters
targetThe pointer to the volatile variable to read from.
Returns
the value of the volatile variable.

References assert.

Referenced by check_event_(), clear_event_(), disable_shortcuts_(), get_errorsrc_(), get_rxd_amount_(), and get_txd_amount_().

◆ volatile_load() [2/2]

template<typename TType >
constexpr TType embutil::volatile_load ( volatile const TType *  target)
inlinenoexcept

Read from a volatile memory location.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References assert.

◆ volatile_store() [1/2]

template<typename TType >
void embutil::volatile_store ( TType *  target,
TType  value 
)
inlinenoexcept

Write to a volatile variable.

Causes the value of ​*target to be overwritten with ​value.

Template Parameters
TTypethe type of the variable. This will be deduced by the compiler.
Note
T​Type shall satisfy the requirements of ​TrivallyCopyable​.
Parameters
targetThe pointer to the volatile variable to update.
valueThe new value for the volatile variable.

References assert.

Referenced by nRFGPIOTranslator::clear(), clear_event_(), configure(), nRFTWITranslator::disable(), nRFTWIMTranslator::disable(), disable_shortcuts_(), nRFTWITranslator::enable(), nRFTWIMTranslator::enable(), get_errorsrc_(), interrupts_disable_(), interrupts_enable_(), rx_list_disable_(), rx_list_enable_(), nRFGPIOTranslator::set(), set_rx_buffer_(), set_shortcuts_(), nRFTWITranslator::set_transfer_address(), nRFTWIMTranslator::set_transfer_address(), set_tx_buffer_(), nRFTWITranslator::setFrequency(), nRFTWIMTranslator::setFrequency(), nRFTWITranslator::setSCLPin(), nRFTWIMTranslator::setSCLPin(), nRFTWITranslator::setSDAPin(), nRFTWIMTranslator::setSDAPin(), task_trigger_(), tx_list_disable_(), and tx_list_enable_().

◆ volatile_store() [2/2]

template<typename TType >
void embutil::volatile_store ( volatile TType *  target,
TType  value 
)
inlinenoexcept

Write to a volatile memory location.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References assert.