-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddr2writePos_tb.sv
51 lines (45 loc) · 1.33 KB
/
addr2writePos_tb.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Set delay unit to 1 ns and simulation precision to 0.1 ns (100 ps)
`timescale 1ns / 100ps
module addr2writePos_tb();
logic [8:0] writePos, writePosExpected;
logic [3:0] addr;
logic ph1, ph2, reset;
logic [31:0] vectornum, errors;
logic [12:0] testvectors[10:0];
// instantiate device under test
addr2writePos dut(.writePos, .addr);
// generate clock to sequence tests
always
begin
ph1 = 0; ph2 = 0; #1;
ph1 = 1; # 4;
ph1 = 0; # 1;
ph2 = 1; # 4;
end
// at start of test, load test vectors
initial
begin
$readmemb("addr2writePos.tv", testvectors);
vectornum=0; errors=0;
reset=1; #17; reset=0;
end
// apply test vectors on rising edge of clk
always @(posedge ph2)
begin
#1; {addr, writePosExpected} = testvectors[vectornum];
end
// check results on falling edge of clk
always @(negedge ph2)
if(~reset) begin // skip during reset
vectornum = vectornum + 1;
if (writePos !== writePosExpected) begin // check result
$display("Error: inputs=%b", addr);
$display("outputs=%b (%b expected)", writePos, writePosExpected);
errors = errors + 1;
end
if(testvectors[vectornum] === 13'bx) begin
$display("%d tests completed with %d errors", vectornum, errors);
$finish;
end
end
endmodule