Skip to content

Commit c314121

Browse files
Merge pull request #382 from algofoogle/main
Fix counter_wb test & Makefile cocotb-verify-* regex
2 parents af5b44b + 84c92ef commit c314121

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
*.gtkw
99
/env
1010
/venv
11+
/venv-cocotb
1112
/caravel
1213
/dependencies
1314
/mgmt_core_wrapper
14-
/logs
15+
/logs

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ $(blocks): % :
126126
$(MAKE) -C openlane $*
127127

128128
dv_patterns=$(shell cd verilog/dv && find * -maxdepth 0 -type d)
129-
cocotb-dv_patterns=$(shell cd verilog/dv/cocotb && find . -name "*.c" | sed -e 's|^.*/||' -e 's/.c//')
129+
cocotb-dv_patterns=$(shell cd verilog/dv/cocotb && find . -name "*.c" | sed -e 's|^.*/||' -e 's/\.c//')
130130
dv-targets-rtl=$(dv_patterns:%=verify-%-rtl)
131131
cocotb-dv-targets-rtl=$(cocotb-dv_patterns:%=cocotb-verify-%-rtl)
132132
dv-targets-gl=$(dv_patterns:%=verify-%-gl)

verilog/dv/cocotb/user_proj_tests/counter_wb/counter_wb.py

+27-18
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,54 @@
1919
from caravel_cocotb.caravel_interfaces import report_test
2020
import cocotb
2121

22+
# Read the 16-bit counter value from GPIO[37:30,7:0]
23+
def counter_value(caravelEnv):
24+
return int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
25+
2226
@cocotb.test()
2327
@report_test
2428
async def counter_wb(dut):
25-
caravelEnv = await test_configure(dut,timeout_cycles=22620)
29+
caravelEnv = await test_configure(dut,timeout_cycles=27000)
2630

27-
cocotb.log.info(f"[TEST] Start counter_wb test")
31+
cocotb.log.info(f"[TEST] Start counter_wb test")
2832
# wait for start of sending
2933
await caravelEnv.release_csb()
3034
await caravelEnv.wait_mgmt_gpio(1)
31-
cocotb.log.info(f"[TEST] finish configuration")
32-
overwrite_val = 7 # value will be written to the counter by wishbone
35+
cocotb.log.info(f"[TEST] Finished configuration")
36+
overwrite_val = 7 # value will be written to the counter by wishbone (hard-coded in firmware)
3337
# expect value bigger than 7
34-
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
38+
received_val = counter_value(caravelEnv)
3539
counter = received_val
3640
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
3741

38-
while True: # wait until the value 1 start counting after the initial
39-
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
40-
if counter == 0xFFFF: # rollover
42+
cocotb.log.info(f"[TEST] Testing Wishbone write")
43+
# Track the counter expected vs. actual, until they diverge...
44+
while True:
45+
received_val = counter_value(caravelEnv)
46+
if counter == 0xFFFF: # rollover
4147
counter = 0
4248
else:
4349
counter +=1
44-
if received_val != counter:
45-
if received_val == overwrite_val:
46-
counter = received_val +1
47-
cocotb.log.info(f"Counter value has been overwritten by wishbone to be {received_val}")
48-
while True: #wait until the wishbone writing finished and the counter start running again
49-
received_val = int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2)
50+
if received_val != counter:
51+
# Counter actual has diverged from expected. Verify it was a Wishbone write...
52+
if received_val == overwrite_val:
53+
# Yes, new counter value matches the expected Wishbone overwrite value.
54+
counter = received_val +1 # Counter's next value will increment from this new value.
55+
cocotb.log.info(f"Counter value has been overwritten by Wishbone to be {received_val}")
56+
while True: #wait until the Wishbone writing finished and the counter started running again
57+
received_val = counter_value(caravelEnv)
5058
if counter == received_val:
5159
break
5260
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
53-
cocotb.log.info(f"Counter value has been overwritten by wishbone to be {received_val}")
61+
cocotb.log.info(f"Counter value is now {received_val}")
5462
break
5563
else:
56-
cocotb.log.error(f"Counter has wrong value before overwrite happened expected: {counter} received: {received_val}")
64+
cocotb.log.error(f"Counter has wrong value before overwrite. Expected={counter} Received={received_val}")
5765
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
5866

67+
cocotb.log.info(f"[TEST] Testing 100 more counts")
5968
for i in range(100):
60-
if counter != int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) :
61-
cocotb.log.error(f"Counter have wrong value expected = {counter} recieved = {int ((caravelEnv.monitor_gpio(37,30).binstr + caravelEnv.monitor_gpio(7,0).binstr ),2) }")
69+
if counter != counter_value(caravelEnv):
70+
cocotb.log.error(f"Counter has wrong value. Expected={counter} Received={counter_value(caravelEnv)}")
6271
await cocotb.triggers.ClockCycles(caravelEnv.clk,1)
6372
counter +=1

0 commit comments

Comments
 (0)