From fb588994b7cb2e35e2da742e6c6203ee2e3346cf Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Mon, 9 Jan 2023 20:50:00 -0500 Subject: [PATCH] tb: phy_core: Fix col/crs detection Detecting non-clock signal edges with RisingEdge and FallingEdge is not very robust, and is recommended against. Track edges manually. Fixes: f6f3f02 ("Add phy_core") Signed-off-by: Sean Anderson --- tb/phy_core.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tb/phy_core.py b/tb/phy_core.py index 9b748a6..a7d5885 100644 --- a/tb/phy_core.py +++ b/tb/phy_core.py @@ -142,17 +142,21 @@ async def test_transfer(phy): async def count_crs(): nonlocal crs + last_crs = 0 while True: - await RisingEdge(phy.crs) - crs += 1 - await FallingEdge(phy.crs) + await RisingEdge(phy.clk) + if phy.crs.value and not last_crs: + crs += 1 + last_crs = phy.crs.value async def count_col(): nonlocal col + last_col = 0 while True: - await RisingEdge(phy.col) - col += 1 - await FallingEdge(phy.col) + await RisingEdge(phy.clk) + if phy.col.value and not last_col: + col += 1 + last_col = phy.col.value await cocotb.start(count_crs()) await cocotb.start(count_col())