aboutsummaryrefslogtreecommitdiffstats
path: root/tests/ecp5/latches_tb.v
blob: b0585264bc29e387cc52b576b6ed067267dce941 (plain)
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
52
53
54
55
56
57
module testbench;
    reg clk;

    initial begin
        // $dumpfile("testbench.vcd");
        // $dumpvars(0, testbench);

        #5 clk = 0;
        repeat (10000) begin
            #5 clk = 1;
            #5 clk = 0;
        end
    end


    reg [2:0] dinA = 0;
    wire doutB,doutB1,doutB2;
	reg lat,latn,latsr = 0;

    top uut (
        .clk (clk ),
        .a (dinA[0] ),
        .pre (dinA[1] ),
        .clr (dinA[2] ),
        .b (doutB ),
        .b1 (doutB1 ),
        .b2 (doutB2 )
    );

    always @(posedge clk) begin
    #3;
    dinA <= dinA + 1;
    end

    	always @*
		if ( clk )
			lat <= dinA[0];


    	always @*
		if ( !clk )
			latn <= dinA[0];


		always @*
		if ( dinA[2] )
			latsr <= 1'b0;
		else if ( dinA[1] )
			latsr <= 1'b1;
		else if ( clk )
			latsr <= dinA[0];

	assert_dff lat_test(.clk(clk), .test(doutB), .pat(lat));
    assert_dff latn_test(.clk(clk), .test(doutB1), .pat(latn));
    assert_dff latsr_test(.clk(clk), .test(doutB2), .pat(latsr));

endmodule