Skip to content

Commit

Permalink
pkg: Use explicit bitwidth for enum values (#42)
Browse files Browse the repository at this point in the history
* floogen(pkg): Use explicit bit widths for enum

* hw(pkg): Regenerate sources

* doc: Update CHANGELOG
  • Loading branch information
fischeti authored Apr 29, 2024
1 parent 1b21bb7 commit 127d994
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- The generation of the unique ID has been changed resp. aligned for 2D meshes to increment Y-first and X-second. This way the address range and ID increment are consistent with each other.
- Broadcasted input `id_i` in the chimneys should not throw an error anymore in elaboration.
- The `id_offset` should not be correctly applied in the system address map. Before it resulted in negative coordinates.
- The `axi_ch_e` types now have an explicit bitwidth. Previously, this caused issues during elaboration since a 32-bit integer was used as a type.

### Removed

Expand Down
8 changes: 5 additions & 3 deletions floogen/model/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ def render_enum_decl(cls):
for ch_type, axi_chs in mapping.items():
for axi_ch in axi_chs:
name = f"{ch_type}_{axi_ch}"
string += f"{snake_to_camel(name)} = {i},\n"
string += f"{snake_to_camel(name)} = TMP_BIT_WIDTH'd{i},\n"
i += 1
string = f"typedef enum logic [{clog2(i+1)-1}:0]{{" + string
string += f"NumAxiChannels = {i}\n}} axi_ch_e;\n"
bitwidth = clog2(i+1)
string = f"typedef enum logic [{bitwidth-1}:0]{{" + string
string = string.replace("TMP_BIT_WIDTH", str(bitwidth))
string += f"NumAxiChannels = {bitwidth}'d{i}\n}} axi_ch_e;\n"
return string

@classmethod
Expand Down
12 changes: 6 additions & 6 deletions hw/floo_axi_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ package floo_axi_pkg;
////////////////////////

typedef enum logic [2:0] {
AxiAw = 0,
AxiW = 1,
AxiAr = 2,
AxiB = 3,
AxiR = 4,
NumAxiChannels = 5
AxiAw = 3'd0,
AxiW = 3'd1,
AxiAr = 3'd2,
AxiB = 3'd3,
AxiR = 3'd4,
NumAxiChannels = 3'd5
} axi_ch_e;


Expand Down
22 changes: 11 additions & 11 deletions hw/floo_narrow_wide_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ package floo_narrow_wide_pkg;
////////////////////////

typedef enum logic [3:0] {
NarrowAw = 0,
NarrowW = 1,
NarrowAr = 2,
WideAr = 3,
NarrowB = 4,
NarrowR = 5,
WideB = 6,
WideAw = 7,
WideW = 8,
WideR = 9,
NumAxiChannels = 10
NarrowAw = 4'd0,
NarrowW = 4'd1,
NarrowAr = 4'd2,
WideAr = 4'd3,
NarrowB = 4'd4,
NarrowR = 4'd5,
WideB = 4'd6,
WideAw = 4'd7,
WideW = 4'd8,
WideR = 4'd9,
NumAxiChannels = 4'd10
} axi_ch_e;


Expand Down

0 comments on commit 127d994

Please sign in to comment.