|
3 | 3 |
|
4 | 4 | @author: Pat Deegan |
5 | 5 | @copyright: Copyright (C) 2024 Pat Deegan, https://psychogenic.com |
6 | | -''' |
7 | | -''' |
8 | | -Created on Oct 28, 2023 |
9 | 6 |
|
10 | | -@author: Pat Deegan |
11 | | -@copyright: Copyright (C) 2023 Pat Deegan, https://psychogenic.com |
| 7 | +
|
| 8 | +
|
12 | 9 | ''' |
13 | 10 |
|
14 | 11 | from microcotb.utils import get_sim_time |
15 | 12 | import microcotb as cocotb |
16 | 13 | from microcotb.clock import Clock |
17 | | -from microcotb.triggers import ClockCycles # RisingEdge, FallingEdge, Timer, |
| 14 | +from microcotb.triggers import ClockCycles, RisingEdge, FallingEdge # , Timer |
18 | 15 | import hashlib |
19 | 16 | import random |
20 | 17 |
|
|
24 | 21 | # so we can load multiple such modules |
25 | 22 | cocotb.set_runner_scope(__name__) |
26 | 23 |
|
27 | | - |
| 24 | +UseEdgeTriggers = False |
28 | 25 | GateLevelTest = False |
29 | 26 | DoLongLongTest = False |
30 | 27 | DoEverySizeBlockTest = False |
@@ -412,26 +409,38 @@ async def startNewDigest(dut): |
412 | 409 |
|
413 | 410 |
|
414 | 411 | 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" |
423 | 426 | return numBusyTicks |
424 | 427 |
|
425 | 428 | 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 | + |
435 | 444 | return numReadyTicks |
436 | 445 |
|
437 | 446 |
|
@@ -483,13 +492,9 @@ async def loadMessageBlock(dut, message_block, quietLogging:bool = True, mode_pa |
483 | 492 | byteVal = (i & (0xff << daShift)) >> daShift |
484 | 493 |
|
485 | 494 | 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 | + |
493 | 498 |
|
494 | 499 | dut._log.debug('Setting data byte and clockin') |
495 | 500 | dut.databyteIn.value = byteVal |
@@ -586,7 +591,7 @@ async def processMessageBlocks(dut, encodedMsg, message_blocks, quietLogging=Tru |
586 | 591 | assert hashval == calculated, f"For message: '{encodedMsg}'\ncalc {calculated} should == {hashval}" |
587 | 592 |
|
588 | 593 |
|
589 | | - return tickWaitCountTotal |
| 594 | + return tickWaitCountTotal |
590 | 595 |
|
591 | 596 |
|
592 | 597 | import ttboard.cocotb.dut |
|
0 commit comments