A Template to construct register-accessor functions for memory-mapped devices. More...
#include <TemplateRegister.hpp>
Public Types | |
typedef unsigned int | uint32_t |
Public Member Functions | |
TemplateRegister () | |
The Constructor takes no arguments. | |
volatile Size * | regAddress (RegType reg) |
An unsigned int containing the compile-time base address of this register. | |
Size | regRead (RegType reg) |
Read a single register of a device. | |
void | regWrite (RegType reg, Size value) |
Write a single register of a device. | |
uint32_t | bitRead (RegType reg, uint32_t bits) |
Read one or more (consecutive) bits from a device. | |
void | bitWrite (RegType reg, uint32_t bits, uint32_t value) |
Write one or more (consecutive) bits to a device. |
A Template to construct register-accessor functions for memory-mapped devices.
Use it as a typedef, as in the example below. This specialisation requires an at compile time known base address of the device's register.
RegType | An enum describing the register layout of the device.
enum UARTRegisters { STATUS = 0x00, // UART status register TXCTL = 0x01, // Transmit control RXCTL = 0x02 // Receive control }; enum STATUS_bits { TX_BUFFER_EMPTY = ORO_REG_BIT_DEFN(0,0), RX_BUFFER_EMPTY = ORO_REG_BIT_DEFN(1,1), TX_UNDERRUN = ORO_REG_BIT_DEFN(5,5), RX_OVERFLOW = ORO_REG_BIT_DEFN(6,6), }; typedef TemplateRegister<UARTRegisters, uint8_t, 0x0000ffff> UARTDevice; UARTDevice uart; // ... uint16_t v = uart.regRead( STATUS ); bool b = uart.bitRead( STATUS, TX_BUFFER_EMPTY ); | |
Size | The type of a register value. For example, uint8_t if the register contains 8 bits. | |
BaseAddress | The at compile time known base address of the register of the device. If you omit BaseAddress, you need to supply it as the first argument of each method call of this class. |
Definition at line 84 of file TemplateRegister.hpp.
uint32_t bitRead | ( | RegType | reg, | |
uint32_t | bits | |||
) | [inline] |
Read one or more (consecutive) bits from a device.
reg | a value of RegType, denoting from which register to read the bits. | |
bits | the bits to read, using the ORO_REG_BIT_DEFN defined enum. |
Definition at line 127 of file TemplateRegister.hpp.
References TemplateRegister< RegType, Size, BaseAddress_ >::regAddress().
void bitWrite | ( | RegType | reg, | |
uint32_t | bits, | |||
uint32_t | value | |||
) | [inline] |
Write one or more (consecutive) bits to a device.
reg | a value of RegType, denoting from which register to read the bits. | |
bits | the bits to read, using the ORO_REG_BIT_DEFN defined enum. | |
value | the value to write to bits |
Definition at line 143 of file TemplateRegister.hpp.
References TemplateRegister< RegType, Size, BaseAddress_ >::regAddress().
volatile Size* regAddress | ( | RegType | reg | ) | [inline] |
An unsigned int containing the compile-time base address of this register.
Resolve the full address of a register.
Definition at line 101 of file TemplateRegister.hpp.
Referenced by TemplateRegister< RegType, Size, 0 >::bitRead(), TemplateRegister< RegType, Size, BaseAddress_ >::bitRead(), TemplateRegister< RegType, Size, 0 >::bitWrite(), TemplateRegister< RegType, Size, BaseAddress_ >::bitWrite(), TemplateRegister< RegType, Size, 0 >::regRead(), TemplateRegister< RegType, Size, BaseAddress_ >::regRead(), TemplateRegister< RegType, Size, 0 >::regWrite(), and TemplateRegister< RegType, Size, BaseAddress_ >::regWrite().