Memory layout (Bytefield)

Embedded documentation lives and dies on byte offsets. Generating the diagram means the offsets cannot drift from the table.


#What this example shows

  • A register map with named fields at fixed offsets.

  • Reserved regions, drawn rather than omitted.

  • Colour separating configuration from status.


#A worked example

Open it, edit it, or copy the source below.

Memory layout (Bytefield)

The source, which you can paste into a new diagram and edit:

(defattrs :cfg {:fill "#e6eeff"})
(defattrs :status {:fill "#e6fffa"})
(defattrs :rsvd {:fill "#f1f5f9"})

(draw-column-headers)

(draw-box "CTRL (rw)" {:span 4 :attrs :cfg})
(draw-box "CLKDIV (rw)" {:span 2 :attrs :cfg})
(draw-box "BAUD (rw)" {:span 2 :attrs :cfg})
(draw-box "STATUS (ro)" {:span 4 :attrs :status})
(draw-box "IRQ_EN (rw)" {:span 2 :attrs :cfg})
(draw-box "IRQ_FLAGS (rc)" {:span 2 :attrs :status})
(draw-box "reserved" {:span 8 :attrs :rsvd})
(draw-box "TX_DATA (wo)" {:span 4 :attrs :cfg})
(draw-box "RX_DATA (ro)" {:span 4 :attrs :status})
(draw-bottom)

#Making it your own

  • Mark access type on every register: rw, ro, wo, rc. It is what firmware authors check.

  • Draw reserved regions. Invisible padding is how structs break on a different compiler.

  • Keep the offsets in one place; regenerate rather than editing both.



The offsets are computed, not drawn.