More on Documenting Registers

More on Documenting Registers

March 31, 2008

Last month’s newsletter discussed some best practices for documenting register layouts, illustrating key points with a sample register diagram. One reader, Joel Saks, noted that my register diagram did not clearly indicate whether the bits were read/write bits or read-only bits. Joel makes an excellent point and also exposes one of the pitfalls of the newsletter format: limited space. I try to keep these newsletters brief, so some subjects have to span multiple newsletters. This month, I will continue with the discussion of register documentation where we left off last month.

Let’s waste no time and immediately address Joel’s concern: The following modification to the register table from last month now indicates the access type, read/write or read-only, of the bits in the register.

MSBStatus RegisterLSB
Bit313029282726252423222120191817161514131211109876543210
RWCCCFA
RORQPONMSD

The row with the bits has been split into two rows, one for read/write bits and one for read-only bits, as indicated in the first column. For registers that have only read/write bits or read-only bits, but not both, only one row is needed with the first column indicating the type of bits.

In the next example, the register deals with a byte count. Firmware can only write a byte count value that is a multiple of 64. But firmware can read a count of any value as the counter counts down the bytes one at a time. This is illustrated through the use of read-only and write-only bits occupying the same bit position.

MSBByte Count RegisterLSB
Bit313029282726252423222120191817161514131211109876543210
ROBBBBBBBBBBBBBBBB
WOCCCCCCCCCC
  • Best Practice: Indicate in the register diagram if bits are read-only, write-only, or read/write.

Firmware engineers also need to know the power-on default for each of these bits. We can add another row to the diagram to convey that information.

MSBStatus RegisterLSB
Bit313029282726252423222120191817161514131211109876543210
RWCCCFA
RORQPONMSD
Def0000000000000000000000X000000010

Most of the bits (including the undefined bits) default to 0 when power is applied. One bit, F, defaults to 1. The default of “X” for the M bit indicates that the initial setting is unknown. An example of an unknown setting is when the bit reflects the current level of an input pin, which depends on how it is driven externally.

  • Best Practice: Document the power-on defaults for each bit in the register diagram.

Until the next read-only newsletter…

Share:

Comments