2024-09-09 21:47:19 +02:00
|
|
|
package PinSync_Test;
|
|
|
|
|
|
|
|
import Assert::*;
|
|
|
|
import StmtFSM::*;
|
|
|
|
|
|
|
|
import PinSync::*;
|
|
|
|
import Testing::*;
|
|
|
|
|
|
|
|
module mkTB();
|
|
|
|
let testflags <- mkTestFlags();
|
|
|
|
let cycles <- mkCycleCounter();
|
|
|
|
|
2024-09-09 21:47:19 +02:00
|
|
|
Reg#(UInt#(2)) dut <- mkPinSync(0);
|
2024-09-09 21:47:19 +02:00
|
|
|
|
|
|
|
function Action check_dut_val(UInt#(2) want_val);
|
|
|
|
return action
|
|
|
|
if (testflags.verbose)
|
|
|
|
$display("%0d: PinSync = %0d, want %0d", cycles.all, dut, want_val);
|
|
|
|
dynamicAssert(dut == want_val, "wrong value");
|
|
|
|
endaction;
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function Stmt check_sync(UInt#(2) starting_val, UInt#(2) want_val);
|
|
|
|
return seq
|
|
|
|
action
|
|
|
|
check_dut_val(starting_val);
|
|
|
|
dut <= want_val;
|
|
|
|
cycles.reset();
|
|
|
|
if (testflags.verbose)
|
|
|
|
$display("%0d: write(%0d)", cycles.all, want_val);
|
|
|
|
endaction
|
|
|
|
|
|
|
|
check_dut_val(starting_val);
|
|
|
|
|
|
|
|
action
|
|
|
|
check_dut_val(want_val);
|
|
|
|
dynamicAssert(cycles == 2, "synchronizer didn't sync at the right time");
|
|
|
|
endaction
|
|
|
|
endseq;
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
runTest(100,
|
|
|
|
mkTest("PinSync", seq
|
|
|
|
check_sync(0, 2);
|
|
|
|
check_sync(2, 3);
|
|
|
|
check_sync(3, 1);
|
|
|
|
endseq));
|
|
|
|
endmodule
|
|
|
|
|
|
|
|
endpackage
|