54 lines
1.3 KiB
Plaintext
54 lines
1.3 KiB
Plaintext
|
package Strobe_Test;
|
||
|
|
||
|
import Assert::*;
|
||
|
import StmtFSM::*;
|
||
|
|
||
|
import Strobe::*;
|
||
|
import Testing::*;
|
||
|
|
||
|
module mkTB();
|
||
|
let testflags <- mkTestFlags();
|
||
|
let cycles <- mkCycleCounter();
|
||
|
|
||
|
// For this test, we assume we're clocked at 25MHz, and want a
|
||
|
// 115_200bps strobe for a serial port. That translates to a strobe
|
||
|
// every 217 cycles.
|
||
|
let dut <- mkStrobe(25_000_000, 115_200);
|
||
|
let want_pulse_every = 217;
|
||
|
|
||
|
function Action check_dut(Bool want);
|
||
|
return action
|
||
|
if (testflags.verbose)
|
||
|
$display("%0d (%0d): strobe = %0d, want %0d", cycles.all, cycles, dut, want);
|
||
|
dynamicAssert(dut == want, "incorrect strobe state");
|
||
|
endaction;
|
||
|
endfunction
|
||
|
|
||
|
function Stmt check_one_cycle();
|
||
|
return seq
|
||
|
action
|
||
|
check_dut(True);
|
||
|
cycles.reset();
|
||
|
endaction
|
||
|
while (cycles < want_pulse_every)
|
||
|
check_dut(False);
|
||
|
endseq;
|
||
|
endfunction
|
||
|
|
||
|
runTest(2000,
|
||
|
mkTest("Strobe", seq
|
||
|
dut.reset();
|
||
|
repeat(3) check_one_cycle();
|
||
|
|
||
|
// Reset should actually reset
|
||
|
repeat(10) noAction;
|
||
|
par
|
||
|
check_dut(False);
|
||
|
dut.reset();
|
||
|
endpar
|
||
|
repeat(3) check_one_cycle();
|
||
|
endseq));
|
||
|
endmodule
|
||
|
|
||
|
endpackage
|