示例#1
0
void Port::configure(unsigned bitnum, unsigned code) const {
  if(! isEnabled()) { // deferred init, so we don't have to sequence init routines, and so we can statically create objects wihtout wasting power if they aren't needed.
    init(); // must have the whole port running before we can modify a config of any pin.
  }
  volatile u32 &confword(*registerAddress((bitnum & 8) ? 4 : 0));
  bitnum &= 7; // modulo 8, number of conf blocks in a 32 bit word.
  // 4 bits each block, apply to offset and to width:
  mergeBits(confword, code, bitnum<<2, 4); // can't use bitfield insert, position is not a constant.
}
示例#2
0
文件: afio.cpp 项目: 980f/cortexm
void AfioManager::selectEvent(const Pin &pin){
  //4 per word, 0th at 8
  volatile u32 &gangof4(*registerAddress(8+(pin.bitnum&~3)));//4 fields per register, 4 bytes per register= ignore 2 lsbs of port's bit number
  u32 value(pin.port.slot-2);//port A is slot 2.
  mergeBits(gangof4,value,(pin.bitnum&3)<<2,4);//2 lsbs of port's bitnumber select 4 bit field
}