Skip to content

Commit d45c4c7

Browse files
committed
minor rework of shaman tb
1 parent 9ff4e65 commit d45c4c7

File tree

1 file changed

+37
-32
lines changed
  • src/examples/tt_um_psychogenic_shaman

1 file changed

+37
-32
lines changed

src/examples/tt_um_psychogenic_shaman/tb.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
44
@author: Pat Deegan
55
@copyright: Copyright (C) 2024 Pat Deegan, https://psychogenic.com
6-
'''
7-
'''
8-
Created on Oct 28, 2023
96
10-
@author: Pat Deegan
11-
@copyright: Copyright (C) 2023 Pat Deegan, https://psychogenic.com
7+
8+
129
'''
1310

1411
from microcotb.utils import get_sim_time
1512
import microcotb as cocotb
1613
from microcotb.clock import Clock
17-
from microcotb.triggers import ClockCycles # RisingEdge, FallingEdge, Timer,
14+
from microcotb.triggers import ClockCycles, RisingEdge, FallingEdge # , Timer
1815
import hashlib
1916
import random
2017

@@ -24,7 +21,7 @@
2421
# so we can load multiple such modules
2522
cocotb.set_runner_scope(__name__)
2623

27-
24+
UseEdgeTriggers = False
2825
GateLevelTest = False
2926
DoLongLongTest = False
3027
DoEverySizeBlockTest = False
@@ -412,26 +409,38 @@ async def startNewDigest(dut):
412409

413410

414411
async def waitNotBusy(dut):
415-
numBusyTicks = 0
416-
isBusy = dut.busy.value
417-
while isBusy and numBusyTicks < 1000:
418-
dut._log.debug('busy')
419-
await ClockCycles(dut.clk, 1)
420-
isBusy = dut.busy.value
421-
numBusyTicks += 1
422-
assert numBusyTicks < 1000, f"Busy too long: numticks {numBusyTicks}"
412+
if not dut.busy.value:
413+
dut._log.debug("Await not busy, already not busy")
414+
return 0
415+
416+
tstart = get_sim_time('us')
417+
if UseEdgeTriggers:
418+
await FallingEdge(dut.busy)
419+
else:
420+
while dut.busy.value:
421+
await ClockCycles(dut.clk, 1)
422+
423+
tnow = get_sim_time('us')
424+
numBusyTicks = tnow - tstart
425+
assert numBusyTicks < 1000, f"Busy too long"
423426
return numBusyTicks
424427

425428
async def waitOutputReady(dut):
426-
numReadyTicks = 0
427-
outputReady = dut.resultReady.value
428-
while not outputReady:
429-
dut._log.debug('Check resultReady')
430-
outputReady = dut.resultReady.value
431-
await ClockCycles(dut.clk, 1)
432-
numReadyTicks += 1
433-
assert numReadyTicks < 1000, f"Busy too long: numticks {numReadyTicks}"
434-
429+
if dut.resultReady.value:
430+
dut._log.debug("already ready!")
431+
return 0
432+
433+
tstart = get_sim_time('us')
434+
if UseEdgeTriggers:
435+
await RisingEdge(dut.resultReady)
436+
else:
437+
while not dut.resultReady.value:
438+
await ClockCycles(dut.clk, 1)
439+
440+
tnow = get_sim_time('us')
441+
numReadyTicks = tnow - tstart
442+
assert numReadyTicks < 1000, f"Busy too long"
443+
435444
return numReadyTicks
436445

437446

@@ -483,13 +492,9 @@ async def loadMessageBlock(dut, message_block, quietLogging:bool = True, mode_pa
483492
byteVal = (i & (0xff << daShift)) >> daShift
484493

485494
numBusyTicks = 0
486-
isBusy = dut.busy.value
487-
while isBusy and numBusyTicks < 1000:
488-
dut._log.debug('busy')
489-
await ClockCycles(dut.clk, 1)
490-
isBusy = dut.busy.value
491-
numBusyTicks += 1
492-
assert numBusyTicks < 1000, f"Busy for {numBusyTicks} ticks"
495+
if dut.busy.value:
496+
numBusyTicks = await waitNotBusy(dut)
497+
493498

494499
dut._log.debug('Setting data byte and clockin')
495500
dut.databyteIn.value = byteVal
@@ -586,7 +591,7 @@ async def processMessageBlocks(dut, encodedMsg, message_blocks, quietLogging=Tru
586591
assert hashval == calculated, f"For message: '{encodedMsg}'\ncalc {calculated} should == {hashval}"
587592

588593

589-
return tickWaitCountTotal
594+
return tickWaitCountTotal
590595

591596

592597
import ttboard.cocotb.dut

0 commit comments

Comments
 (0)