STM32LIB
Static Public Member Functions | List of all members
reg_t< mutability_policy_t, address, offset, width > Struct Template Reference

#include <reg_t.hpp>

Static Public Member Functions

static unsigned read ()
 
static void write (unsigned value)
 
static void set ()
 
static void clear ()
 

Detailed Description

template<typename mutability_policy_t, unsigned address, unsigned offset, unsigned width>
struct reg_t< mutability_policy_t, address, offset, width >

Model an MMIO register.

Allows policy-based configuration of hardware registers to give compile-time assurances. For example, your policy may not implement read() if it wants to prevent read access.

Enhances correctness by constraining register access to the specific subregisters it contains. Compile time calculation constrains the all access to within the subregister.

Performance of register access is exactly the same as traditional *reg = *reg | (1 << offset) style access due to the compiler's ability to inline static function calls which depend only on compile time values. As such, use this with compiler optimization enabled.

Template Parameters
mutability_policy_ta duck-typed static monostate which implements the actual mechanics of register access.
addressthe memory location of the register
offsetthe bit position of the least significant bit within the register for the subregister
widththe width of the subregister in bits

Member Function Documentation

template<typename mutability_policy_t , unsigned address, unsigned offset, unsigned width>
static unsigned reg_t< mutability_policy_t, address, offset, width >::read ( )
inlinestatic

Read the subregister.

Returns
the value
template<typename mutability_policy_t , unsigned address, unsigned offset, unsigned width>
static void reg_t< mutability_policy_t, address, offset, width >::write ( unsigned  value)
inlinestatic

Write a subregister.

Parameters
valuethe new value
template<typename mutability_policy_t , unsigned address, unsigned offset, unsigned width>
static void reg_t< mutability_policy_t, address, offset, width >::set ( )
inlinestatic

Set all bits in the subregister to one.

template<typename mutability_policy_t , unsigned address, unsigned offset, unsigned width>
static void reg_t< mutability_policy_t, address, offset, width >::clear ( )
inlinestatic

Clear all bits in the subregister to zero.


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