FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
May 01, 2005

Register Access in C++

(Page 13 of 15)

May, 2005: Register Access in C++

Listing 9


// New enums for each register width
enum Registers8
{
    STATUS = 0x00, // UART status register
    ... and so on ...
};
enum Registers32
{
    TXBUF = 0x04,  // Transmit buffer
    ... and so on ...
};
// Two overloads of regAddress
inline volatile uint8_t *regAddress(Registers8 reg)
{
    return reinterpret_cast<volatile uint8_t*>(baseAddress + reg);
}
inline volatile uint32_t *regAddress(Registers32 reg)
{
    return reinterpret_cast<volatile uint32_t*>(baseAddress + reg);
}
// Two overloads of regRead
inline uint8_t regRead(Registers8 reg)
{
    return *regAddress(reg);
} 
inline uint32_t regRead(Registers32 reg)
{
    return *regAddress(reg);
}
 ... similarly for regWrite ...

Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 Next Page
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK