00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef ORO_TEMPLATEREGISTER_HPP
00030 #define ORO_TEMPLATEREGISTER_HPP
00031
00032 namespace RTT
00033 {
00050 #define ORO_REG_BIT_DEFN(start, end) (( start << 16)|(end-start+1))
00051
00083 template<typename RegType, class Size, unsigned int BaseAddress_ = 0>
00084 struct TemplateRegister
00085 {
00086 typedef unsigned int uint32_t;
00087
00091 TemplateRegister() {}
00092
00096
00097
00101 inline volatile Size *regAddress(RegType reg)
00102 {
00103 return reinterpret_cast<volatile Size*>(BaseAddress_ + reg);
00104 }
00105
00109 inline Size regRead(RegType reg)
00110 {
00111 return *regAddress(reg);
00112 }
00113
00117 inline void regWrite(RegType reg, Size value)
00118 {
00119 *regAddress(reg) = value;
00120 }
00121
00127 inline uint32_t bitRead( RegType reg, uint32_t bits)
00128 {
00129 uint32_t regval = *regAddress(reg);
00130 const uint32_t width = bits & 0xff;
00131 const uint32_t bitno = bits >> 16;
00132 regval >>= bitno;
00133 regval &= ((1<<width)-1);
00134 return regval;
00135 }
00136
00143 inline void bitWrite(RegType reg, uint32_t bits, uint32_t value)
00144 {
00145 uint32_t regval = *regAddress(reg);
00146 const uint32_t width = bits & 0xff;
00147 const uint32_t bitno = bits >> 16;
00148 regval &= ~(((1<<width)-1) << bitno);
00149 regval |= value << bitno;
00150 *regAddress(reg) = regval;
00151 }
00152
00153 };
00154
00188 template<typename RegType, class Size>
00189 struct TemplateRegister<RegType,Size,0>
00190 {
00191 typedef unsigned int uint32_t;
00192
00196 unsigned int BaseAddress;
00197
00201 TemplateRegister( unsigned int base_address )
00202 : BaseAddress(base_address)
00203 {}
00204
00208 inline volatile Size *regAddress(RegType reg)
00209 {
00210 return reinterpret_cast<volatile Size*>(BaseAddress + reg);
00211 }
00212
00216 inline Size regRead(RegType reg)
00217 {
00218 return *regAddress(reg);
00219 }
00220
00224 inline void regWrite(RegType reg, Size value)
00225 {
00226 *regAddress(reg) = value;
00227 }
00228
00234 inline uint32_t bitRead( RegType reg, uint32_t bits)
00235 {
00236 uint32_t regval = *regAddress(reg);
00237 const uint32_t width = bits & 0xff;
00238 const uint32_t bitno = bits >> 16;
00239 regval >>= bitno;
00240 regval &= ((1<<width)-1);
00241 return regval;
00242 }
00243
00250 inline void bitWrite(RegType reg, uint32_t bits, uint32_t value)
00251 {
00252 uint32_t regval = *regAddress(reg);
00253 const uint32_t width = bits & 0xff;
00254 const uint32_t bitno = bits >> 16;
00255 regval &= ~(((1<<width)-1) << bitno);
00256 regval |= value << bitno;
00257 *regAddress(reg) = regval;
00258 }
00259
00260 };
00261
00262
00263
00264 }
00265
00266
00267 #endif