alexforencich / cocotbext-axi

AXI interface modules for Cocotb
MIT License
214 stars 70 forks source link

Option to drive channel signals back to 0 when valid is low #92

Open darsor opened 2 months ago

darsor commented 2 months ago

First of all, incredible library. Well designed and well engineered. Thanks for your hard work!

I'm testing a custom AXI module whose upstream master likes to drive all channel signals back to 0 when *VALID is low. Because this python library doesn't change the signal values when *VALID goes low, there was an uncaught bug where my module depended on this library's behavior.

Would it be possible to add an option to drive channel signals back to some default value when not active?

ollie-etl commented 1 month ago

x would be a better choice. Its equally possible to introduce bugs that incorrectly rely on zeros when valid is low

darsor commented 1 month ago

Great point. Then any reliance on signal values when *VALID is low can be caught in simulation.

I was able to hack this functionality in by adding

for sig_name, sig_handle in self.bus._signals.items():
    if not sig_name.endswith(("valid", "ready")):
        sig_handle.value = BinaryValue("x"*sig_handle.value.n_bits)

to the StreamSource _run() coroutine here. Then every time it sets *valid low it sets all the other signals to X.