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

Subversion Repositories sd_card_controller

[/] [sd_card_controller/] [trunk/] [bench/] [verilog/] [sd_fifo_filler_tb.sv] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 rozpruwacz
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// WISHBONE SD Card Controller IP Core                          ////
4
////                                                              ////
5
//// sd_fifo_filler_tb.sv                                         ////
6
////                                                              ////
7
//// This file is part of the WISHBONE SD Card                    ////
8
//// Controller IP Core project                                   ////
9
//// http://www.opencores.org/cores/xxx/                          ////
10
////                                                              ////
11
//// Description                                                  ////
12
//// testbench for sd_fifo_filler module                          ////
13
////                                                              ////
14
//// Author(s):                                                   ////
15
////     - Marek Czerski, ma.czerski@gmail.com                    ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2013 Authors                                   ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE. See the GNU Lesser General Public License for more  ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
 
44
module sd_fifo_filler_tb();
45
 
46
parameter WB_TCLK = 20; // 50 MHz -> timescale 1ns
47
parameter SD_TCLK = WB_TCLK*2; // 25 MHz -> timescale 1ns
48
 
49
reg wb_clk;
50
reg rst;
51
wire [31:0] wbm_adr_o;
52
wire wbm_we_o;
53
wire [31:0] wbm_dat_o;
54
wire [31:0] wbm_dat_i;
55
wire wbm_cyc_o;
56
wire wbm_stb_o;
57
wire wbm_ack_i;
58
reg en_rx_i;
59
reg en_tx_i;
60
reg [31:0] adr_i;
61
reg sd_clk;
62
reg [31:0] dat_i;
63
wire [31:0] dat_o;
64
reg wr_i;
65
reg rd_i;
66
wire sd_full_o;
67
wire sd_empty_o;
68
wire wb_full_o;
69
wire wb_empty_o;
70
 
71
//wb slave helpers
72
integer wb_wait;
73
integer wb_wait_counter;
74
integer wb_idx;
75
//fifo driver helpers
76
reg fifo_drv_ena;
77
integer fifo_drv_wait;
78
integer fifo_drv_wait_counter;
79
integer fifo_drv_idx;
80
 
81
//test memory vector
82
integer test_mem[0:31] = {
83
        32'h01234567, 32'h12345678, 32'h23456789, 32'h3456789a, 32'h456789ab, 32'h56789abc, 32'h6789abcd, 32'h789abcde,
84
        32'h89abcdef, 32'h9abcdef0, 32'habcdef01, 32'hbcdef012, 32'hcdef0123, 32'hdef01234, 32'hef012345, 32'hf0123456,
85
        32'h00010203, 32'h04050607, 32'h08090a0b, 32'h0c0d0e0f, 32'h10111213, 32'h14151617, 32'h18191a1b, 32'h1c1d1e1f,
86
        32'h20212223, 32'h24252627, 32'h28292a2b, 32'h2c2d2e2f, 32'h30313233, 32'h34353637, 32'h38393a3b, 32'h3c3d3e3f
87
    };
88
 
89
sd_fifo_filler sd_fifo_filler_dut(
90
                      .wb_clk    (wb_clk),
91
                      .rst       (rst),
92
                      .wbm_adr_o (wbm_adr_o),
93
                      .wbm_we_o  (wbm_we_o),
94
                      .wbm_dat_o (wbm_dat_o),
95
                      .wbm_dat_i (wbm_dat_i),
96
                      .wbm_cyc_o (wbm_cyc_o),
97
                      .wbm_stb_o (wbm_stb_o),
98
                      .wbm_ack_i (wbm_ack_i),
99
                      .en_rx_i   (en_rx_i),
100
                      .en_tx_i   (en_tx_i),
101
                      .adr_i     (adr_i),
102
                      .sd_clk    (sd_clk),
103
                      .dat_i     (dat_i),
104
                      .dat_o     (dat_o),
105
                      .wr_i      (wr_i),
106
                      .rd_i      (rd_i),
107
                      .sd_empty_o   (sd_empty_o),
108
                      .sd_full_o   (sd_full_o),
109
                      .wb_empty_o   (wb_empty_o),
110
                      .wb_full_o    (wb_full_o)
111
                  );
112
 
113
// Generating sd_clk clock
114
always
115
begin
116
    sd_clk=0;
117
    forever #(SD_TCLK/2) sd_clk = ~sd_clk;
118
end
119
// Generating wb_clk clock
120
always
121
begin
122
    wb_clk=0;
123
    forever #(WB_TCLK/2) wb_clk = ~wb_clk;
124
end
125
 
126
assign wbm_ack_i = wbm_cyc_o && wbm_stb_o & wb_wait == wb_wait_counter;
127
assign wbm_dat_i = wbm_ack_i ? test_mem[wb_idx] : 0;
128
//wb slave
129
always @(posedge wb_clk) begin
130
    if (wbm_cyc_o && wbm_stb_o && wbm_we_o) begin
131
        if (wbm_ack_i) begin
132
            assert(test_mem[wb_idx] == wbm_dat_o);
133
            assert(wbm_adr_o == adr_i + 4*wb_idx);
134
            wb_wait_counter <= 0;
135
            wb_idx++;
136
        end
137
        wb_wait_counter++;
138
    end
139
    else if (wbm_cyc_o && wbm_stb_o) begin
140
        if (wbm_ack_i) begin
141
            assert(wbm_adr_o == adr_i + 4*wb_idx);
142
            wb_wait_counter <= 0;
143
            wb_idx++;
144
        end
145
        wb_wait_counter++;
146
    end
147
    else begin
148
        wb_wait_counter <= 0;
149
    end
150
    if (!en_rx_i && !en_tx_i) wb_idx = 0;
151
end
152
 
153
//fifo driver
154
always @(posedge sd_clk)
155
    if (en_rx_i) begin
156
        if (fifo_drv_wait == fifo_drv_wait_counter) begin
157
            wr_i <= 1;
158
            dat_i <= test_mem[fifo_drv_idx];
159
            fifo_drv_wait_counter <= 0;
160
            fifo_drv_idx++;
161
        end
162
        else begin
163
            wr_i <= 0;
164
            dat_i <= 0;
165
            fifo_drv_wait_counter++;
166
        end
167
    end
168
    else if (fifo_drv_ena) begin
169
        if (fifo_drv_wait_counter == 0) begin
170
            rd_i <= 1;
171
            assert(dat_o == test_mem[fifo_drv_idx]);
172
            fifo_drv_wait_counter++;
173
            fifo_drv_idx++;
174
        end
175
        else begin
176
            rd_i <= 0;
177
            if (fifo_drv_wait_counter == fifo_drv_wait)
178
                fifo_drv_wait_counter <= 0;
179
            else
180
                fifo_drv_wait_counter++;
181
        end
182
    end
183
    else begin
184
        wr_i <= 0;
185
        rd_i <= 0;
186
        fifo_drv_idx = 0;
187
        fifo_drv_wait_counter <= 0;
188
    end
189
 
190
initial
191
begin
192
    rst = 1;
193
    fifo_drv_wait = 0;
194
    fifo_drv_ena = 0;
195
    wb_wait = 2;
196
    en_rx_i = 0;
197
    en_tx_i = 0;
198
    adr_i = 0;
199
    dat_i = 0;
200
    wr_i = 0;
201
    rd_i = 0;
202
 
203
    $display("sd_fifo_filler_tb finish ...");
204
 
205
    #(3*WB_TCLK);
206
    rst = 0;
207
    assert(wbm_we_o == 0);
208
    assert(wbm_cyc_o == 0);
209
    assert(wbm_stb_o == 0);
210
    assert(wb_full_o == 0);
211
    #(3*WB_TCLK);
212
    assert(wbm_we_o == 0);
213
    assert(wbm_cyc_o == 0);
214
    assert(wbm_stb_o == 0);
215
    assert(wb_full_o == 0);
216
    assert(sd_empty_o == 1);
217
 
218
    //check normal operation
219
    en_rx_i = 1;
220
    fifo_drv_wait = 7;
221
    wb_wait = 2;
222
 
223
    #(100*WB_TCLK);
224
    wait(wbm_cyc_o == 0);
225
    en_rx_i = 0;
226
    #SD_TCLK;
227
    assert(wbm_we_o == 0);
228
    assert(wbm_cyc_o == 0);
229
    assert(wbm_stb_o == 0);
230
    assert(wb_full_o == 0);
231
 
232
    //check for full condition
233
    #(WB_TCLK/2);
234
    en_rx_i = 1;
235
    fifo_drv_wait = 7;
236
    wb_wait = 17*(fifo_drv_wait+1)*(SD_TCLK/WB_TCLK);
237
    #(wb_wait*WB_TCLK);
238
    #SD_TCLK;
239
    assert(sd_full_o == 1);
240
    assert(wb_empty_o == 0);
241
    en_rx_i = 0;
242
    fork
243
        begin
244
            #WB_TCLK;
245
            assert(wbm_we_o == 0);
246
            assert(wbm_cyc_o == 0);
247
            assert(wbm_stb_o == 0);
248
        end
249
        begin
250
            #SD_TCLK;
251
            assert(sd_full_o == 0);
252
        end
253
    join
254
    wait(wb_empty_o == 1);
255
    #SD_TCLK;
256
 
257
    //fill almost fuul fifo then burst write
258
    en_rx_i = 1;
259
    fifo_drv_wait = 7;
260
    wb_wait = 14*(fifo_drv_wait+1)*(SD_TCLK/WB_TCLK);
261
    wait(wbm_ack_i);
262
    #SD_TCLK;
263
    assert(sd_full_o == 0);
264
    assert(wb_empty_o == 0);
265
    wb_wait = 0;
266
    wait(wb_empty_o == 1);
267
    wait(wbm_cyc_o == 0);
268
    en_rx_i = 0;
269
    #SD_TCLK;
270
    assert(wbm_we_o == 0);
271
    assert(wbm_cyc_o == 0);
272
    assert(wbm_stb_o == 0);
273
    assert(sd_full_o == 0);
274
 
275
//////////////////////////////////////////////////////////////
276
    //check fifo fill
277
    en_tx_i = 1;
278
    wb_wait = 2;
279
    wait(wb_full_o == 1);
280
    #(WB_TCLK/2);
281
    assert(sd_empty_o == 0);
282
    assert(wbm_we_o == 0);
283
    assert(wbm_cyc_o == 0);
284
    assert(wbm_stb_o == 0);
285
    #WB_TCLK;
286
    assert(sd_empty_o == 0);
287
    assert(wbm_we_o == 0);
288
    assert(wbm_cyc_o == 0);
289
    assert(wbm_stb_o == 0);
290
 
291
    //check normal operation
292
    fifo_drv_wait = 7;
293
    fifo_drv_ena = 1;
294
    #(100*SD_TCLK);
295
    wait(wbm_cyc_o == 0 && rd_i == 0);
296
    #(WB_TCLK/2);
297
    en_tx_i = 0;
298
    fifo_drv_ena = 0;
299
    wait(sd_empty_o == 1);
300
    assert(wb_full_o == 0);
301
 
302
    #(10*WB_TCLK) $display("sd_fifo_filler_tb finish ...");
303
    $finish;
304
 
305
end
306
 
307
endmodule

powered by: WebSVN 2.1.0

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