wavedrom / bitfield

:cake: bit field diagram renderer
MIT License
335 stars 27 forks source link

byte level #10

Closed SadE54 closed 4 years ago

SadE54 commented 6 years ago

Hi, Is it possible to represent a data structure at the byte level and not only bit level ? It could be a more generic protocol spec generator. I cannot find any tool on the web to do it like wavedrom . The closest tool is a latex macro :-/

drom commented 6 years ago

@SadE54 you could definitely allocate byte wide fields inside the register like that.

[
  {bits: 8, name: 'byte0'},
  {bits: 8, name: 'byte1'},
  {bits: 8, name: 'byte2'},
  {bits: 8}
]

Are you looking for something different?

K4zuki commented 6 years ago

Hello @SadE54 ,

guess something like this one? http://blockdiag.com/en/nwdiag/index.html

my another guess is setting lanes and bits at same value.

from README:

--input      : input JSON filename - must be specified always
--vspace     : vertical space - default 80
--hspace     : horizontal space - default 640
--lanes      : rectangle lanes - default 2
--bits       : overall bitwidth - default 32
--bigendian  : - default false
--fontfamily : - default sans-serif
--fontweight : - default normal
--fontsize   : - default 14

make a file four-byte.json like following:

[
  {"bits": 1, "name": "byte0"},
  {"bits": 1, "name": "byte1"},
  {"bits": 1, "name": "byte2"},
  {"bits": 1}
]

then try: bitfield --input four-byte.json --lane 4 --bits 4 > four-byte.svg

results:

<svg xmlns="http://www.w3.org/2000/svg" width="649" height="165" viewBox="0 0 649 165">
  <g transform="translate(4.5,80.5)">
    <g stroke="black" stroke-width="1" stroke-linecap="round" transform="translate(0,20)">
      <line x2="640"/>
      <line y2="40"/>
      <line x2="640" y1="40" y2="40"/>
      <line x1="640" x2="640" y2="40"/>
      <line x1="320" x2="320" y2="40"/>
    </g>
    <g text-anchor="middle">
      <g>
        <g transform="translate(0,20)"/>
        <g transform="translate(160,16)">
          <text x="320" font-size="14" font-family="sans-serif" font-weight="normal">0</text>
          <text x="0" font-size="14" font-family="sans-serif" font-weight="normal">1</text>
        </g>
        <g transform="translate(160,44)">
          <text x="320" font-size="14" font-family="sans-serif" font-weight="normal">
            <tspan>byte0</tspan>
          </text>
          <text x="0" font-size="14" font-family="sans-serif" font-weight="normal">
            <tspan>byte1</tspan>
          </text>
        </g>
        <g transform="translate(160,80)"/>
      </g>
    </g>
  </g>
  <g transform="translate(4.5,0.5)">
    <g stroke="black" stroke-width="1" stroke-linecap="round" transform="translate(0,20)">
      <line x2="640"/>
      <line y2="40"/>
      <line x2="640" y1="40" y2="40"/>
      <line x1="640" x2="640" y2="40"/>
      <line x1="320" x2="320" y2="40"/>
    </g>
    <g text-anchor="middle">
      <g>
        <g transform="translate(0,20)">
          <rect style="fill-opacity:0.1" x="0" y="0" width="320" height="40"/>
        </g>
        <g transform="translate(160,16)">
          <text x="320" font-size="14" font-family="sans-serif" font-weight="normal">2</text>
          <text x="0" font-size="14" font-family="sans-serif" font-weight="normal">3</text>
        </g>
        <g transform="translate(160,44)">
          <text x="320" font-size="14" font-family="sans-serif" font-weight="normal">
            <tspan>byte2</tspan>
          </text>
        </g>
        <g transform="translate(160,80)"/>
      </g>
    </g>
  </g>
</svg>

the result is 2-bit 2-lane but these may be minimums