1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
// This prototype writes a value to the entire register. All
// bit-fields of the register will be written. Write REGISTER REGISTERVALUE
// This prototype writes a value only to the bit-field specified.
// In the actual implementation, the other bit-fields should be
// masked to prevent them from being written. Also, the
// actual implementation should left-shift the BITFIELDVALUE
// by appropriate number to match the starting bit location of
// the BITFIELD.
Modify REGISTER -> BITFIELD, BITFIELDVALUE //Bitfield Location
// Example implementation
// Modify DAP_EN (bit 0) bit to value 1 to enable DAP block
Modify( DAP_CONTROL_REG, 0xFFFE, 1 << DAP_EN_STARTBIT );
// Example Implementation of Modify
void Modify(unsigned short usRegister, unsigned short usClearMask, unsigned short usSetValue)
{ unsigned short usData;
// 1) Read current value
ReadRegister(usRegister, &usData);
// 2) Clear out old bits
usData = usData & usClearMask;
// 3) set new bit values usData = usData | usSetValue;
// 4) Write out new value created
WriteRegister(usRegister,usData);
} |
Partager