Electronic – Why are bitfields in register not sequential

register

Why are the bit-fields in the register not sequential? For example, consider an 8 bit register X . X will have bits 0-2 with flags and 3-6 may be reserved and bit 7 may again represent some flag. Why not use bits 0-3 and leave 4-7 as reserved?

For a practical example, look at the LSM303DLHC datasheet. Register CTRL_REG6_A has the following mapping:

CTRL_REG6_A register:

  • 7: I2_CLICKen
  • 6: I2_INT1
  • 5: I2_INT2
  • 4: BOOT_I1
  • 3: P2_ACT
  • 2: —
  • 1: H_LACTIVE
  • 0: —

Bits 0 and 2 are unused.

Best Answer

Register layout is generally determined by the hardware designer. There's usually a reason for unused bits - most likely first:

  • Functionality from an earlier design was removed, the bit flags are now reserved to avoid confusing old revisions of software (backwards compatibility).
  • To leave space to implement behaviour in future revisions. Or indeed the bits may hide features implemented (perhaps partially) that will only be documented in the next revision.
  • Undocumented bits may be driven by signals only useful for testing/debugging so cannot be publicly documented without exposing implementation details. For instance they may read internal state machine encodings or unexpected condition flags.
  • Unused bits may simply be there for data alignment. Some CPUs may be faster processing fields where related bits are packed to byte alignment.