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 5 of 15)

May, 2005: Register Access in C++

Listing 11


// Template versions of bitRead/Write - put them at global scope
// and you don't have to copy bitRead/Write into every device namespace
template <typename RegType>
inline uint32_t bitRead(RegType reg, uint32_t bits)

    uint32_t       regval = *regAddress(reg);
    const uint32_t width  = bits & 0xff;
    const uint32_t bitno  = bits >> 16;
    regval >>= bitno;
    regval  &= ((1<<width)-1);
    return regval;
}
template <typename RegType>
inline void bitWrite(RegType reg, uint32_t bits, uint32_t value)
{
    uint32_t           regval = *regAddress(reg);
    const uint32_t     width  = bits & 0xff;
    const uint32_t     bitno  = bits >> 16;
    regval &= ~(((1<<width)-1) << bitno);
    regval |=  value << bitno;
    *regAddress(reg) = regval;
}

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