gary/lib/Strobe_Test.bsv

66 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

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
// 16x115_200bps strobe for a serial port. That translates to a
// strobe that happens every 13 or 14 cycles, depending on the
// amount of accumulated error from the imprecise frequency
// division.
let dut <- mkStrobe(25_000_000, 115_200*16);
let want_pulse_every = 14;
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(Integer cycle_len);
return seq
action
$display("%0d: cycle start", cycles.all);
check_dut(True);
cycles.reset();
endaction
while (cycles < fromInteger(cycle_len))
check_dut(False);
endseq;
endfunction
runTest(500,
mkTest("Strobe", seq
dut.reset();
check_one_cycle(14);
check_one_cycle(14);
check_one_cycle(13);
check_one_cycle(14);
check_one_cycle(13);
check_one_cycle(14);
check_one_cycle(13);
check_one_cycle(14);
check_one_cycle(14);
check_one_cycle(13);
check_one_cycle(14);
check_one_cycle(13);
// Reset should actually reset
repeat(10) noAction;
dut.reset();
check_one_cycle(14);
check_one_cycle(14);
endseq));
endmodule
endpackage