TemplateRegister< RegType, Size, 0 > Struct Template Reference

A Template to construct register-accessor functions for memory-mapped devices, which address is only known at run-time. More...

#include <TemplateRegister.hpp>

List of all members.

Public Types

typedef unsigned int uint32_t

Public Member Functions

 TemplateRegister (unsigned int base_address)
 The constructor takes the base_address of the register as an unsigned integer.
volatile Size * regAddress (RegType reg)
 Resolve the full address of a 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.

Public Attributes

unsigned int BaseAddress
 An unsigned int containing the run-time obtained base address of this register.

Detailed Description

template<typename RegType, class Size>
struct RTT::TemplateRegister< RegType, Size, 0 >

A Template to construct register-accessor functions for memory-mapped devices, which address is only known at run-time.

Use it as a typedef, as in the example below.

Parameters:
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> UARTDevice;
        // ...
        unsigned int base_address = ...;
        UARTDevice uart( base_address );
        // ...
        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 189 of file TemplateRegister.hpp.


Member Function Documentation

uint32_t bitRead ( RegType  reg,
uint32_t  bits 
) [inline]

Read one or more (consecutive) bits from a device.

Parameters:
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 234 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.

Parameters:
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 250 of file TemplateRegister.hpp.

References TemplateRegister< RegType, Size, BaseAddress_ >::regAddress().


The documentation for this struct was generated from the following file:
Generated on Thu Dec 23 15:05:29 2010 for OrocosComponentLibrary by  doxygen 1.6.3