OpenCores
URL https://opencores.org/ocsvn/dmt_tx/dmt_tx/trunk

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [const_encoder/] [tb/] [tb_fifo.v] - Blame information for rev 12

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 dannori
 
2
module tb_fifo;
3
 
4
parameter AWIDTH = 2;
5
parameter DWIDTH = 8;
6
parameter TW=10;
7
 
8
 
9
 
10
//
11
// to interface the dut
12
// 
13
reg                 clk;
14
reg                 reset;
15
reg   [DWIDTH-1:0]  data_i;
16
reg                 re_i;
17
wire                empty_o;
18
wire                full_o;
19
wire                one_available_o;
20
wire                two_available_o;
21
reg                 we_i;
22
reg   [DWIDTH-1:0]  data_i;
23
reg                 re_i;
24
wire  [DWIDTH-1:0]  data_o;
25
 
26
 
27
 
28
//
29
// instantiate the DUT
30
//
31
fifo #(.AWIDTH(AWIDTH), .DWIDTH(DWIDTH))
32
 
33
      dut ( .clk(clk),
34
            .reset(reset),
35
            .empty_o(empty_o),
36
            .full_o(full_o),
37
            .one_available_o(one_available_o),
38
            .two_available_o(two_available_o),
39
            .we_i(we_i),
40
            .data_i(data_i),
41
            .re_i(re_i),
42
            .data_o(data_o));
43
 
44
 
45
//
46
// local reg/wires
47
//
48
reg [DWIDTH-1:0] got_data;
49
 
50
//
51
// main tests
52
// 
53
 
54
initial begin
55
  clk = 0;
56
  we_i = 0;
57
  re_i = 0;
58
  reset = 0;
59
end
60
 
61
always begin
62
  #TW clk = ~clk;
63
end
64
 
65
//
66
// dump signals
67
//
68
initial begin
69
  $dumpfile("tb_fifo.vcd");
70
  $dumpvars;
71
end
72
 
73
 
74
initial begin
75
  $display("Verifing FIFO");
76
 
77
  test_reset;
78
  check_control(5'b0001);
79
 
80
  write_data(8'haa);
81
  check_control(5'b0100);
82
 
83
  read_data(got_data);
84
  check_result(got_data, 8'haa);
85
  check_control(5'b0001);
86
 
87
  // fifo is empty again
88
 
89
  // fill it and only expect after the 4th write a full signal
90
 
91
  // #1
92
  write_data(8'h70);
93
  check_control(5'b0100);
94
  // #2
95
  write_data(8'h71);
96
  check_control(5'b1100);
97
  // #3
98
  write_data(8'h72);
99
  check_control(5'b1100);
100
  // #4
101
  write_data(8'h73);
102
  check_control(5'b1110);
103
  // fifo full, should not get written
104
  write_data(8'hab);
105
  check_control(5'b1110);
106
 
107
  // #1  
108
  read_data(got_data);
109
  check_result(got_data, 8'h70);
110
  check_control(5'b1100);
111
  // #2  
112
  read_data(got_data);
113
  check_result(got_data, 8'h71);
114
  check_control(5'b1100);
115
  // #3  
116
  read_data(got_data);
117
  check_result(got_data, 8'h72);
118
  check_control(5'b0100);
119
  // #4  
120
  read_data(got_data);
121
  check_result(got_data, 8'h73);
122
  check_control(5'b0001);
123
 
124
 
125
  $finish();
126
 
127
end
128
 
129
 
130
 
131
 
132
// =====================================================================
133
// bus functional models
134
//
135
task test_reset;
136
  begin
137
  $display("Testing reset");
138
  reset = 0;
139
  #10 reset = 1;
140
  #20 reset = 0;
141
 
142
end
143
endtask
144
 
145
 
146
// =====================================================================
147
// check the expected control line status
148
//
149
// exp_ctrl[4:0] == {two_available, one_available, full, empty}
150
//
151
task check_control(input [4:0]exp_ctrl);
152
  begin
153
 
154
    $display("# %d expCtrl: %d", $time, exp_ctrl);
155
 
156
  if(empty_o !== exp_ctrl[0])
157
    $display("ERROR! => Expected empty_o == %d, got %d", exp_ctrl[0], empty_o);
158
 
159
  if(full_o !== exp_ctrl[1])
160
    $display("ERROR! => Expected full_o == %d, got %d", exp_ctrl[1], full_o);
161
 
162
  if(one_available_o !== exp_ctrl[2])
163
    $display("ERROR! => Expected one_available_o == %d, got %d", exp_ctrl[3], one_available_o);
164
 
165
  if(two_available_o !== exp_ctrl[3])
166
    $display("ERROR! => Expected two_available_o == %d, got %d", exp_ctrl[4], two_available_o);
167
 
168
  end
169
endtask
170
 
171
 
172
// =====================================================================
173
//
174
// write data to the fifo
175
// 
176
task write_data(input [DWIDTH-1:0]data);
177
  begin
178
    $display("# %d Writing data", $time);
179
    @(negedge clk);
180
    data_i = data;
181
    we_i = 1;
182
    @(negedge clk);
183
    we_i = 0;
184
 
185
  end
186
endtask
187
 
188
// =====================================================================
189
//
190
// read data from the fifo
191
// 
192
// 
193
task read_data(output [DWIDTH-1:0]data);
194
  begin
195
 
196
    $display("# %d Reading data", $time);
197
    @(negedge clk);
198
    re_i = 1;
199
    @(negedge clk);
200
    data = data_o;
201
    re_i = 0;
202
 
203
  end
204
endtask
205
 
206
 
207
// =====================================================================
208
//
209
// check result
210
// 
211
// 
212
task check_result(input [DWIDTH-1:0]got, input [DWIDTH-1:0]expected);
213
  begin
214
    if(got !== expected)
215
      $display("ERROR! => Result does not match! Got: %d (%x) expected: %d (%x)", got, got, expected, expected);
216
  end
217
endtask
218
 
219
endmodule
220
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.