-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_fsm_tb.v
195 lines (195 loc) · 4.24 KB
/
router_fsm_tb.v
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
module router_fsm_tb();
reg clock,resetn,pkt_valid,fifo_full,fifo_empty_0,fifo_empty_1,fifo_empty_2,soft_reset_0,soft_reset_1,soft_reset_2,parity_done,low_packet_valid;
reg [1:0] data_in;
wire write_enb_reg,detect_add,ld_state,laf_state,lfd_state,full_state,rst_int_reg,busy;
parameter T = 10;
router_fsm DUT(clock,resetn,pkt_valid,data_in,fifo_full,fifo_empty_0,fifo_empty_1,fifo_empty_2,soft_reset_0,soft_reset_1,soft_reset_2,parity_done,low_packet_valid,write_enb_reg,detect_add,ld_state,laf_state, lfd_state,full_state,rst_int_reg,busy);
parameter
DECODE_ADDRESS = 3'b000,
LOAD_FIRST_DATA = 3'b001,
LOAD_DATA = 3'b010,
WAIT_TILL_EMPTY = 3'b011,
CHECK_PARITY_ERROR = 3'b100,
LOAD_PARITY = 3'b101,
FIFO_FULL_STATE = 3'b110,
LOAD_AFTER_FULL = 3'b111;
reg [21*8:0]string_cmd;
always@(DUT.ps) // it used to call the ps in the dut
begin
case (DUT.ps)
DECODE_ADDRESS : string_cmd = "DECODER_ADDRESS_s1";
LOAD_FIRST_DATA : string_cmd = "LOAD_FIRST_DATA_s2";
LOAD_DATA : string_cmd = "LOAD_DATA_s3";
WAIT_TILL_EMPTY : string_cmd = "WAIT_TILL_EMPTY_si";
CHECK_PARITY_ERROR : string_cmd = "CHECK_PARITY_ERROR_s8";
LOAD_PARITY : string_cmd = "LOAD_PARITY_TB";
FIFO_FULL_STATE : string_cmd = "FIFO_FULL_STATE_TB";
LOAD_AFTER_FULL : string_cmd = "LOAD_AFTER_FULL_TB";
endcase
end
initial
begin
clock=1'b0;
forever #T clock = ~clock;
end
task initialize;
begin
{pkt_valid,fifo_empty_0,fifo_empty_1,fifo_empty_2,fifo_full,parity_done,low_packet_valid}=0;
end
endtask
task DA_LFA_LD_FFS_LAF_DA;
begin
{resetn,soft_reset_0,soft_reset_1,soft_reset_2} = 0;
data_in = 0;
{pkt_valid,low_packet_valid} = 2'b01;
fifo_full = 0;
parity_done = 0;
{fifo_empty_0,fifo_empty_1,fifo_empty_2} = 3'b111;
end
endtask
task rst;
begin
@(negedge clock)
resetn=1'b0;
@(negedge clock)
resetn=1'b1;
end
endtask
task DA_LFD_LD_LP_CPE_DA;
begin
@(negedge clock)
begin pkt_valid=1'b1;
data_in[1:0]=0;
fifo_empty_0=1;
end
@(negedge clock)
@(negedge clock)
begin
pkt_valid=0;
end
@(negedge clock)
@(negedge clock)
fifo_full=0;
end
endtask
task DA_LFA_LD_FFS_LAF_LP_CPE_DA;
begin @(negedge clock)
begin pkt_valid=1;
data_in[1:0]=0;
fifo_empty_0=1;
end
@(negedge clock)
@(negedge clock)
fifo_full=1;
@(negedge clock)
fifo_full=0;
@(negedge clock)
begin
parity_done=0;
low_packet_valid=1;
end
@(negedge clock)
@(negedge clock)
fifo_full=0;
end
endtask
task DA_LFD_LD_FFS_LAF_LD_LP_CPE_DA;
begin @(negedge clock)
begin pkt_valid=1;
data_in[1:0]=0;
fifo_empty_0=1;
end
@(negedge clock)
@(negedge clock)
fifo_full=1;
@(negedge clock)
fifo_full=0;
@(negedge clock)
begin low_packet_valid=0;
parity_done=0;
end
@(negedge clock)
begin fifo_full=0;
pkt_valid=0;
end
@(negedge clock)
@(negedge clock)
fifo_full=0;
end
endtask
task DA_LFD_LD_LP_CPE_FFS_LAF_DA;
begin
@(negedge clock)
begin pkt_valid=1;
data_in[1:0]=0;
fifo_empty_0=1;
end @(negedge clock)
@(negedge clock)
begin fifo_full=0;
pkt_valid=0;
end
@(negedge clock)
@(negedge clock)
fifo_full=1;
@(negedge clock)
fifo_full=0;
@(negedge clock)
parity_done=1;
end
endtask
task soft_rst;
begin
@(negedge clock)
soft_reset_0 = 1'b1;
@(negedge clock)
soft_reset_0 = 1'b0;
#15;
@(negedge clock)
soft_reset_1 = 1'b1;
@(negedge clock)
soft_reset_1 = 1'b0;
#15;
@(negedge clock)
soft_reset_2 = 1'b1;
@(negedge clock)
soft_reset_2 = 1'b0;
@(negedge clock);
end
endtask
initial
begin
rst;
DA_LFA_LD_FFS_LAF_DA;
#20;
rst;
@(negedge clock);
initialize;
#20
$display("--------- DA_LFD_LD_LP_CPE_DA (1)--------");
DA_LFD_LD_LP_CPE_DA;
rst;
#30
$display("--------- DA_LFA_LD_FFS_LAF_LP_CPE_DA (2)--------");
DA_LFA_LD_FFS_LAF_LP_CPE_DA;
rst;
#30
$display("--------- DA_LFD_LD_FFS_LAF_LD_LP_CPE_DA (3)--------");
DA_LFD_LD_FFS_LAF_LD_LP_CPE_DA;
rst;
#30
$display("--------- DA_LFD_LD_LP_CPE_FFS_LAF_DA (4)--------");
DA_LFD_LD_LP_CPE_FFS_LAF_DA;
#30;
$display("---------three soft_reset conditions (5)--------");
soft_rst;
end
initial
$monitor("Reset=%b, State=%s, det_add=%b, write_enb_reg=%b, full_state=%b, lfd_state=%b, busy=%b, ld_state=%b, laf_state=%b, rst_int_reg=%b, low_packet_valid=%b",resetn,string_cmd,detect_add,write_enb_reg,full_state,lfd_state,busy,ld_state,laf_state,rst_int_reg,low_packet_valid);
initial
begin
$dumpfile("router_fsm.vcd");
$dumpvars();
#1000
$finish;
end
endmodule