-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
125 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,24 +7,23 @@ | |
# Tim Fischer <[email protected]> | ||
|
||
import argparse | ||
import hjson | ||
import pathlib | ||
import math | ||
import hjson | ||
from jsonref import JsonRef | ||
from mako.lookup import TemplateLookup | ||
|
||
AXI_CHANNELS = ["aw", "w", "b", "ar", "r"] | ||
|
||
templates = TemplateLookup(directories=[pathlib.Path(__file__).parent], | ||
output_encoding="utf-8") | ||
templates = TemplateLookup(directories=[pathlib.Path(__file__).parent], output_encoding="utf-8") | ||
|
||
|
||
def clog2(x: int) -> int: | ||
"""Compute the ceil of the log2 of x.""" | ||
return int(math.ceil(math.log(x, 2))) | ||
|
||
|
||
def get_axi_chs(channel_mapping: dict, **kwargs) -> list: | ||
def get_axi_chs(channel_mapping: dict) -> list: | ||
"""Return all the AXI channels.""" | ||
channels = [] | ||
for axi_chs in channel_mapping.values(): | ||
|
@@ -34,7 +33,7 @@ def get_axi_chs(channel_mapping: dict, **kwargs) -> list: | |
return channels | ||
|
||
|
||
def get_inverted_mapping(channel_mapping: dict, **kwargs) -> dict: | ||
def get_inverted_mapping(channel_mapping: dict) -> dict: | ||
"""Return the mapping of the link.""" | ||
mappings = {} | ||
for phys_ch, ch_types in channel_mapping.items(): | ||
|
@@ -45,6 +44,7 @@ def get_inverted_mapping(channel_mapping: dict, **kwargs) -> dict: | |
|
||
|
||
def get_axi_channel_sizes(aw: int, dw: int, iw: int, uw: int) -> dict: | ||
# pylint: disable=too-many-locals | ||
"""Compute the AXI channel size in bits.""" | ||
|
||
# Constant widths | ||
|
@@ -54,7 +54,7 @@ def get_axi_channel_sizes(aw: int, dw: int, iw: int, uw: int) -> dict: | |
prot = 3 | ||
qos = 4 | ||
region = 4 | ||
len = 8 | ||
length = 8 | ||
size = 3 | ||
atop = 6 | ||
last = 1 | ||
|
@@ -64,27 +64,29 @@ def get_axi_channel_sizes(aw: int, dw: int, iw: int, uw: int) -> dict: | |
iw = max(iw.values()) | ||
|
||
axi_ch_size = {} | ||
axi_ch_size["aw"] = iw + aw + len + size + burst + lock + cache + \ | ||
prot + qos + region + atop + uw | ||
axi_ch_size["w"] = dw + dw//8 + last + uw | ||
axi_ch_size["aw"] = ( | ||
iw + aw + length + size + burst + lock + cache + prot + qos + region + atop + uw | ||
) | ||
axi_ch_size["w"] = dw + dw // 8 + last + uw | ||
axi_ch_size["b"] = iw + resp + uw | ||
axi_ch_size["ar"] = iw + aw + len + size + burst + lock + cache + \ | ||
prot + qos + region + uw | ||
axi_ch_size["ar"] = iw + aw + length + size + burst + lock + cache + prot + qos + region + uw | ||
axi_ch_size["r"] = iw + dw + resp + last + uw | ||
|
||
return axi_ch_size | ||
|
||
|
||
def get_link_sizes(channel_mapping: dict, protocols: list, **kwargs) -> dict: | ||
def get_link_sizes(channel_mapping: dict, protocols: list) -> dict: | ||
"""Infer the link sizes AXI channels and the mapping.""" | ||
link_sizes = {} | ||
for phys_ch, axi_chs in channel_mapping.items(): | ||
# Get all protocols that use this channel | ||
used_protocols = [p for p in protocols if p['name'] in axi_chs and p['direction'] == 'input'] | ||
used_protocols = [ | ||
p for p in protocols if p["name"] in axi_chs and p["direction"] == "input" | ||
] | ||
# Get only the exact AXI channels that are used by the link | ||
used_axi_chs = [axi_chs[p['name']] for p in used_protocols] | ||
used_axi_chs = [axi_chs[p["name"]] for p in used_protocols] | ||
# Get the sizes of the AXI channels | ||
axi_ch_sizes = [get_axi_channel_sizes(**p['params']) for p in used_protocols] | ||
axi_ch_sizes = [get_axi_channel_sizes(**p["params"]) for p in used_protocols] | ||
link_message_sizes = [] | ||
for used_axi_ch, axi_ch_size in zip(used_axi_chs, axi_ch_sizes): | ||
link_message_sizes += [axi_ch_size[ch] for ch in used_axi_ch] | ||
|
@@ -96,21 +98,22 @@ def get_link_sizes(channel_mapping: dict, protocols: list, **kwargs) -> dict: | |
def main(): | ||
"""Generate a flit packet package.""" | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Generate flit files for a given configuration") | ||
parser.add_argument("--config", "-c", type=pathlib.Path, required=True, help="Path to the config file") | ||
parser = argparse.ArgumentParser(description="Generate flit files for a given configuration") | ||
parser.add_argument( | ||
"--config", "-c", type=pathlib.Path, required=True, help="Path to the config file" | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
# Read HJSON description of System. | ||
with open(args.config, "r") as f: | ||
with open(args.config, "r", encoding="utf-8") as f: | ||
cfg = JsonRef.replace_refs(hjson.load(f)) | ||
|
||
kwargs = cfg | ||
kwargs['axi_channels'] = get_axi_chs(**kwargs) | ||
kwargs['inv_map'] = get_inverted_mapping(**kwargs) | ||
kwargs['get_axi_channel_sizes'] = get_axi_channel_sizes | ||
kwargs['link_sizes'] = get_link_sizes(**kwargs) | ||
kwargs["axi_channels"] = get_axi_chs(**kwargs) | ||
kwargs["inv_map"] = get_inverted_mapping(**kwargs) | ||
kwargs["get_axi_channel_sizes"] = get_axi_channel_sizes | ||
kwargs["link_sizes"] = get_link_sizes(**kwargs) | ||
|
||
tpl = templates.get_template("floo_flit_pkg.sv.mako") | ||
print(tpl.render_unicode(**kwargs)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters