-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdff.sv
120 lines (104 loc) · 1.89 KB
/
dff.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
///////dff
`timescale 10ns/1ns
interface dff_if (input clk);
logic d0,d1,sel,rst,q;
parameter thold=2,//output_skew
tsetup=4; //input_skew
clocking cb @(posedge clk);
default input # (tsetup) output # (thold);
output d0;
output d1;
output rst;
output sel;
input q;
endclocking
modport DUV(input d0,d1,rst,sel,clk, output q);
////////////task for checking reset
task sync_reset;
cb.rst <= 1'b1;
cb.sel <= $random;
cb.d0 <= 1'b1;
cb.d1 <= 1'b1;
repeat(2)
@(cb);
if(cb.q!==0)
begin
$display("RESET IS NOT WORKING");
end
else
$display("RESET IS PERFECT");
endtask
///////////task for checking load d0
task load_d0;
input data;
cb.rst <= 1'b0;
cb.sel <= 1'b0;
cb.d0 <= data;
cb.d1 <= ~data;
repeat(2)
@(cb);
if(cb.q!==data)
begin
$display("LOAD D0 IS NOT WORKING");
end
else
$display("LOAD D0 IS PERFECT");
endtask
///////////task for checking load d1
task load_d1;
input data;
cb.rst <= 1'b0;
cb.sel <= 1'b0;
cb.d0 <= ~data;
cb.d1 <= data;
repeat(2)
@(cb);
if(cb.q!==data)
begin
$display("LOAD D1 IS NOT WORKING");
end
else
$display("LOAD D1 IS PERFECT");
endtask
modport TEST(clocking cb,import sync_reset,import load_d0,import load_d1);
endinterface
//////dff DUT
module dff(dff_if.DUV duv_if);
logic d;
always@(*)
begin
case(duv_if.sel)
0:d=duv_if.d0;
1:d=duv_if.d1;
default:d=duv_if.d0;
endcase
end
always@(posedge duv_if.clk)
begin
if(duv_if.rst)
duv_if.q<=0;
else
duv_if.q<=d;
end
endmodule
//////////sv tb and top module
module testcase(dff_if.TEST test_if);
initial
begin
@(test_if.cb);
test_if.sync_reset;
test_if.load_d0(1);
test_if.load_d1(0);
test_if.load_d0(0);
test_if.load_d1(1);
#10 $finish;
end
endmodule
module top();
bit clk;
always
#10 clk = ~clk;
dff_if IF(clk);
dff RTL(IF);
testcase TB(IF);
endmodule