Skip to content

Commit

Permalink
Added group option
Browse files Browse the repository at this point in the history
Signed-off-by: Anderson Ignacio da Silva <[email protected]>
  • Loading branch information
aignacio committed Oct 26, 2024
1 parent 9596b8c commit f763f40
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 42 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,22 @@ waves.add_signal(
dut.hwdata,
dut.hwrite,
dut.hready_in,
],
group="MOSI",
)
waves.add_signal(
[
dut.hrdata,
dut.hready,
dut.hresp,
]
],
group="MISO",
)
...
<Running sim, issuing txns>
...
waves.save()
waves.save_txt()
```

**Output:**
Expand Down
4 changes: 2 additions & 2 deletions ahb_test.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion cocotbext/waves/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.4"
__version__ = "0.1.5"
164 changes: 127 additions & 37 deletions cocotbext/waves/waves.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
color_data=None,
previous_val=None,
clock_period=1,
group=None,
) -> None:
self.name = name
self.handle = handle
Expand All @@ -35,6 +36,7 @@ def __init__(
self.is_posedge_clock = is_posedge_clock
self.previous_val = previous_val
self.clock_period = clock_period
self.group = group


class waveform:
Expand Down Expand Up @@ -82,29 +84,34 @@ def add_signal(
is_clock: bool = False,
is_posedge_clock: bool = True,
clock_period=1,
group=None,
):
if not isinstance(sig, list):
sig = [sig]

sig_list = []

for signal in sig:
if signal.__len__() == 1:
self.waves["signal"].append(
sig_list.append(
{
"name": signal._name,
"wave": "",
}
)

self.handles.append(
signal_data(
name=signal._name,
handle=signal,
is_clock=is_clock,
is_posedge_clock=is_posedge_clock,
clock_period=clock_period,
group=group,
)
)
else:
self.waves["signal"].append(
sig_list.append(
{
"name": signal._name,
"wave": "",
Expand Down Expand Up @@ -132,9 +139,16 @@ def add_signal(
is_clock=is_clock,
is_posedge_clock=is_posedge_clock,
clock_period=clock_period,
group=group,
)
)

if group is not None:
self.waves["signal"].append([group] + sig_list)
else:
for item in sig_list:
self.waves["signal"].append(item)

async def _monitor(self):
while True:
if self.is_posedge is True:
Expand All @@ -157,7 +171,7 @@ def _add_signals(self):
def _append_wave_dot(self, index, signal):
if signal.is_clock is True:
for entry in self.waves["signal"]:
if entry["name"] == signal.name:
if isinstance(entry, dict) and entry["name"] == signal.name:
if signal.handle.value.is_resolvable is not True:
if "z" in signal.handle.value:
entry["wave"] += "z"
Expand All @@ -169,59 +183,135 @@ def _append_wave_dot(self, index, signal):
entry["period"] = signal.clock_period
else:
entry["wave"] += "."
elif isinstance(entry, list):
for subentry in entry:
if (
isinstance(subentry, dict)
and subentry.get("name") == signal.name
):
if signal.handle.value.is_resolvable is not True:
if "z" in signal.handle.value:
subentry["wave"] += "z"
else:
subentry["wave"] += "x"
else:
if subentry["wave"] == "":
subentry["wave"] += (
"P" if signal.is_posedge_clock else "N"
)
subentry["period"] = signal.clock_period
else:
subentry["wave"] += "."
else:
for entry in self.waves["signal"]:
if entry["name"] == signal.name:
if signal.previous_val is None:
self.handles[index].previous_val = copy.deepcopy(
signal.handle.value
)

if signal.handle.value.is_resolvable is not True:
if "z" in signal.handle.value:
entry["wave"] += "z"
if isinstance(entry, dict) and entry["name"] == signal.name:
if entry["name"] == signal.name:
if signal.previous_val is None:
self.handles[index].previous_val = copy.deepcopy(
signal.handle.value
)

if signal.handle.value.is_resolvable is not True:
if "z" in signal.handle.value:
entry["wave"] += "z"
else:
entry["wave"] += "x"
else:
entry["wave"] += "x"
if signal.handle.__len__() > 1:
entry["data"] += str(hex(signal.handle.value)) + " "
entry["wave"] += signal.color_data
else:
entry["wave"] += str(signal.handle.value)
elif signal.handle.value == signal.previous_val:
entry["wave"] += "."
else:
if signal.handle.__len__() > 1:
entry["data"] += str(hex(signal.handle.value)) + " "
entry["wave"] += signal.color_data
else:
entry["wave"] += str(signal.handle.value)
elif signal.handle.value == signal.previous_val:
entry["wave"] += "."
else:
self.handles[index].previous_val = copy.deepcopy(
signal.handle.value
)
self.handles[index].previous_val = copy.deepcopy(
signal.handle.value
)

if signal.handle.value.is_resolvable is not True:
if "z" in signal.handle.value:
entry["wave"] += "z"
if signal.handle.value.is_resolvable is not True:
if "z" in signal.handle.value:
entry["wave"] += "z"
else:
entry["wave"] += "x"
else:
entry["wave"] += "x"
else:
if signal.handle.__len__() > 1:
entry["wave"] += signal.color_data
entry["data"] += str(hex(signal.handle.value)) + " "
if signal.handle.__len__() > 1:
entry["wave"] += signal.color_data
entry["data"] += str(hex(signal.handle.value)) + " "
else:
entry["wave"] += str(signal.handle.value)
elif isinstance(entry, list):
for subentry in entry:
if (
isinstance(subentry, dict)
and subentry.get("name") == signal.name
):
if signal.previous_val is None:
self.handles[index].previous_val = copy.deepcopy(
signal.handle.value
)

if signal.handle.value.is_resolvable is not True:
if "z" in signal.handle.value:
subentry["wave"] += "z"
else:
subentry["wave"] += "x"
else:
if signal.handle.__len__() > 1:
subentry["data"] += (
str(hex(signal.handle.value)) + " "
)
subentry["wave"] += signal.color_data
else:
subentry["wave"] += str(signal.handle.value)
elif signal.handle.value == signal.previous_val:
subentry["wave"] += "."
else:
entry["wave"] += str(signal.handle.value)
self.handles[index].previous_val = copy.deepcopy(
signal.handle.value
)

if signal.handle.value.is_resolvable is not True:
if "z" in signal.handle.value:
subentry["wave"] += "z"
else:
subentry["wave"] += "x"
else:
if signal.handle.__len__() > 1:
subentry["wave"] += signal.color_data
subentry["data"] += (
str(hex(signal.handle.value)) + " "
)
else:
subentry["wave"] += str(signal.handle.value)

def set_head(self, text, tick, every):
self.head = {"text": text, "tick": tick, "every": every}

def set_foot(self, text, tick, every):
self.foot = {"text": text, "tick": tick, "every": every}

def save(self):
self.mon.kill()
# Format each name entry
def _incl_width(self):
# Format each multi-bit name entry to include width
for signal in self.handles:
for entry in self.waves["signal"]:
if entry["name"] == signal.handle._name:
if isinstance(entry, dict) and entry["name"] == signal.name:
if signal.handle.__len__() > 1:
entry["name"] += "[" + str(signal.handle.__len__() - 1) + ":0]"
elif isinstance(entry, list):
for subentry in entry:
if (
isinstance(subentry, dict)
and subentry.get("name") == signal.name
):
if signal.handle.__len__() > 1:
subentry["name"] += (
"[" + str(signal.handle.__len__() - 1) + ":0]"
)

def save(self):
self.mon.kill()
self._incl_width()
self.waves["config"] = {"hscale": self.hscale}
self.waves["head"] = self.head
self.waves["foot"] = self.foot
Expand Down
9 changes: 8 additions & 1 deletion tests/test_gen_ahb_waves_ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ async def run_test(dut):
dut.hwdata,
dut.hwrite,
dut.hready_in,
],
group="MOSI",
)
waves.add_signal(
[
dut.hrdata,
dut.hready,
dut.hresp,
]
],
group="MISO",
)

await setup_dut(dut, cfg.RST_CYCLES)
Expand All @@ -83,6 +89,7 @@ async def run_test(dut):
resp = await ahb_master.read(address, size, pip=pip_mode)

waves.save()
waves.save_txt()
type(resp)
del waves

Expand Down

0 comments on commit f763f40

Please sign in to comment.