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

Subversion Repositories wb_lpc

[/] [wb_lpc/] [trunk/] [sim/] [wb_lpc_sim/] [tb_lpc_top.v] - Blame information for rev 21

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

Line No. Rev Author Line
1 3 hharte
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  tb_lpc_top.v                                                ////
4
////                                                              ////
5
////  This file is part of the Wishbone LPC Bridge project        ////
6
////  http://www.opencores.org/projects/wb_lpc/                   ////
7
////                                                              ////
8
////  Author:                                                     ////
9
////      - Howard M. Harte (hharte@opencores.org)                ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2008 Howard M. Harte                           ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
`timescale 1 ns / 1 ns
39
 
40
`include "../../rtl/verilog/wb_lpc_defines.v"
41
 
42
// Define Module for Test Fixture
43
module wb_lpc_master_bench();
44
 
45
// LPC Host Inputs
46
    reg clk_i;
47
    reg nrst_i;
48
    reg [31:0] wbs_adr_i;
49
    reg [31:0] wbs_dat_i;
50
    reg [3:0] wbs_sel_i;
51
    reg [1:0] wbs_tga_i;
52
    reg wbs_we_i;
53
    reg wbs_stb_i;
54
    reg wbs_cyc_i;
55
    wire [3:0] lad_i;
56
    reg [2:0] dma_chan_i;
57
    reg dma_tc_i;
58
 
59
// LPC Host Outputs
60
    wire [31:0] wbs_dat_o;
61
    wire wbs_ack_o;
62 17 hharte
    wire wbs_err_o;
63 3 hharte
    wire lframe_o;
64
    wire [3:0] lad_o;
65
    wire lad_oe;
66
 
67
// Bidirs
68
    wire [3:0] lad_bus;
69
 
70
// LPC Peripheral Inputs
71
    wire [31:0] wbm_dat_i;
72
    wire wbm_ack_i;
73 17 hharte
    wire wbm_err_i;
74 3 hharte
 
75
// LPC Peripheral Outputs
76
    wire [31:0] wbm_adr_o;
77
    wire [31:0] wbm_dat_o;
78
    wire [3:0] wbm_sel_o;
79
    wire [1:0] wbm_tga_o;
80
    wire wbm_we_o;
81
    wire wbm_stb_o;
82
    wire wbm_cyc_o;
83
    wire [2:0] dma_chan_o;
84
    wire dma_tc_o;
85
 
86
    wire [3:0] slave_lad_i;
87
    wire [3:0] slave_lad_o;
88
 
89
    reg dma_req_i;
90
 
91 17 hharte
    reg [7:0]  regfile_ws;
92
 
93 3 hharte
task Reset;
94
begin
95
    nrst_i = 1; # 1000;
96
    nrst_i = 0; # 1000;
97
    nrst_i = 1; # 1000;
98
end
99
endtask
100
 
101
 
102
task wb_write;
103
    input reg [31:0] adr_i;
104
    input reg [3:0]  sel_i;
105
    input reg [31:0] dat_i;
106 17 hharte
    input reg expect_err;
107 3 hharte
    reg [7:0] wait_cnt;
108
    begin
109
 
110
    wbs_adr_i = adr_i;
111
    wbs_sel_i = sel_i;
112
    wbs_dat_i = dat_i;
113
    wbs_stb_i = 1'b1;
114
    wbs_cyc_i = 1'b1;
115
    wbs_we_i = 1'b1;
116
 
117
    wait_cnt = 0;
118
 
119 17 hharte
    while ((wbs_ack_o == 0) & (wait_cnt < 1000))
120 3 hharte
    begin
121
        wait_cnt = wait_cnt+1;
122
        # 100;
123
    end
124
 
125 17 hharte
    if(wait_cnt == 1000)
126 3 hharte
    begin
127 17 hharte
        $display($time, " Error, wb_w[%x/%x]: timeout waiting for ack", adr_i, dat_i); $stop(1);
128 3 hharte
    end
129 17 hharte
 
130
         if(expect_err != wbs_err_o)
131
         begin
132
        $display($time, " Error: wb_w[%x/%x]: wb_err_o is %d, expected %d", adr_i, dat_i, wbs_err_o, expect_err); $stop(1);
133
    end
134 3 hharte
    wbs_stb_i = 1'b0;
135
    wbs_cyc_i = 1'b0;
136
    wbs_we_i = 1'b0;
137
 
138 17 hharte
    wait_cnt = 0;
139
 
140
    while ((wbs_ack_o == 1) & (wait_cnt < 100))
141
    begin
142
        wait_cnt = wait_cnt+1;
143
        # 100;
144 3 hharte
    end
145 17 hharte
 
146
    if(wait_cnt == 100)
147
    begin
148
        $display($time, " Error, wb_w[%x]: timeout waiting for ack to go away", adr_i); $stop(1);
149
    end
150
 
151
    end
152 3 hharte
endtask
153
 
154
 
155
task wb_read;
156
    input reg [31:0] adr_i;
157
    input reg [3:0]  sel_i;
158
    input reg [31:0] dat_i;
159 17 hharte
    input reg expect_err;
160 3 hharte
    reg [7:0] wait_cnt;
161
    begin
162
 
163
    wbs_adr_i = adr_i;
164
    wbs_sel_i = sel_i;
165
    wbs_dat_i = 32'h0;
166
    wbs_stb_i = 1'b1;
167
    wbs_cyc_i = 1'b1;
168
    wbs_we_i = 1'b0;
169
 
170
    wait_cnt = 0;
171
 
172 17 hharte
    while ((wbs_ack_o == 0) & (wait_cnt < 1000))
173 3 hharte
    begin
174
        wait_cnt = wait_cnt+1;
175
        # 100;
176
    end
177
 
178 17 hharte
    if(wait_cnt == 1000)
179 3 hharte
    begin
180
        $display($time, " Error, wb_r[%x]: timeout waiting for ack", adr_i); $stop(1);
181
    end
182
 
183
    wbs_stb_i = 1'b0;
184
    wbs_cyc_i = 1'b0;
185
 
186 17 hharte
         if(expect_err != wbs_err_o)
187
         begin
188
        $display($time, " Error: wb_r[%x/%x]: wb_err_o is %d, expected %d", adr_i, dat_i, wbs_err_o, expect_err); $stop(1);
189
    end
190
 
191
    if(wbs_err_o == 0) begin
192
        if(dat_i != wbs_dat_o)
193
        begin
194
            $display($time, " Error, wb_r[%x]: expected %x, got %x", adr_i, dat_i, wbs_dat_o); $stop(1);
195
        end
196
    end
197
 
198
    wait_cnt = 0;
199
 
200
    while ((wbs_ack_o == 1) & (wait_cnt < 100))
201 3 hharte
    begin
202 17 hharte
        wait_cnt = wait_cnt+1;
203
        # 100;
204 3 hharte
    end
205
 
206 17 hharte
    if(wait_cnt == 100)
207
    begin
208
        $display($time, " Error, wb_r[%x]: timeout waiting for ack to go away", adr_i); $stop(1);
209 3 hharte
    end
210 17 hharte
end
211
 
212 3 hharte
endtask
213
 
214
 
215
   always begin
216
       #50 clk_i = 0;
217
       #50 clk_i = 1;
218
   end
219
 
220
// Instantiate the UUT
221
    wb_lpc_host UUT_Host (
222
        .clk_i(clk_i),
223
        .nrst_i(nrst_i),
224
        .wbs_adr_i(wbs_adr_i),
225
        .wbs_dat_o(wbs_dat_o),
226
        .wbs_dat_i(wbs_dat_i),
227
        .wbs_sel_i(wbs_sel_i),
228
        .wbs_tga_i(wbs_tga_i),
229
        .wbs_we_i(wbs_we_i),
230
        .wbs_stb_i(wbs_stb_i),
231
        .wbs_cyc_i(wbs_cyc_i),
232
        .wbs_ack_o(wbs_ack_o),
233 17 hharte
        .wbs_err_o(wbs_err_o),
234 3 hharte
        .dma_chan_i(dma_chan_i),
235
        .dma_tc_i(dma_tc_i),
236
        .lframe_o(lframe_o),
237
        .lad_i(lad_i),
238
        .lad_o(lad_o),
239
        .lad_oe(lad_oe)
240
        );
241
 
242
// Instantiate the module
243
wb_lpc_periph UUT_Periph (
244
    .clk_i(clk_i),
245
    .nrst_i(nrst_i),
246
    .wbm_adr_o(wbm_adr_o),
247
    .wbm_dat_o(wbm_dat_o),
248
    .wbm_dat_i(wbm_dat_i),
249
    .wbm_sel_o(wbm_sel_o),
250
    .wbm_tga_o(wbm_tga_o),
251
    .wbm_we_o(wbm_we_o),
252
    .wbm_stb_o(wbm_stb_o),
253
    .wbm_cyc_o(wbm_cyc_o),
254
    .wbm_ack_i(wbm_ack_i),
255 17 hharte
    .wbm_err_i(wbm_err_i),
256 3 hharte
    .dma_chan_o(dma_chan_o),
257
    .dma_tc_o(dma_tc_o),
258
    .lframe_i(lframe_o),
259
    .lad_i(slave_lad_i),
260
    .lad_o(slave_lad_o),
261
    .lad_oe(slave_lad_oe)
262
    );
263
 
264
wire       ldrq_o;
265
wire [2:0] master_dma_chan_o;
266
wire       master_dma_req_o;
267
 
268
// Instantiate the module
269
wb_dreq_periph UUT_DREQ_Periph (
270
    .clk_i(clk_i),
271
    .nrst_i(nrst_i),
272
    .dma_chan_i(dma_chan_i),
273
    .dma_req_i(dma_req_i),
274
    .ldrq_o(ldrq_o)
275
    );
276
 
277
// Instantiate the module
278
wb_dreq_host UUT_DREQ_Host (
279
    .clk_i(clk_i),
280
    .nrst_i(nrst_i),
281
    .dma_chan_o(master_dma_chan_o),
282
    .dma_req_o(master_dma_req_o),
283
    .ldrq_i(ldrq_o)
284
    );
285
 
286
wire [31:0] datareg0;
287
wire [31:0] datareg1;
288
 
289
// Instantiate the module
290
wb_regfile regfile (
291
    .clk_i(clk_i),
292
    .nrst_i(nrst_i),
293 17 hharte
    .wb_adr_i(dma_chan_i == 2 ? 32'h00000008 : wbm_adr_o),
294 3 hharte
    .wb_dat_o(wbm_dat_i),
295
    .wb_dat_i(wbm_dat_o),
296
    .wb_sel_i(wbm_sel_o),
297
    .wb_we_i(wbm_we_o),
298
    .wb_stb_i(wbm_stb_o),
299
    .wb_cyc_i(wbm_cyc_o),
300 17 hharte
    .wb_ack_o(wbm_ack_i),
301
    .wb_err_o(wbm_err_i),
302
    .ws_i(regfile_ws),
303 3 hharte
    .datareg0(datareg0),
304
    .datareg1(datareg1)
305
    );
306
 
307
assign lad_bus = lad_oe ? lad_o : (slave_lad_oe ? slave_lad_o : 4'bzzzz);
308
assign lad_i = lad_bus;
309
assign slave_lad_i = lad_bus;
310
 
311
// Initialize Inputs
312
    initial begin
313
//      $monitor("Time: %d clk_i=%b",
314
//          $time, clk_i);
315
            clk_i = 0;
316
            nrst_i = 1;
317
            wbs_adr_i = 0;
318
            wbs_dat_i = 0;
319
            wbs_sel_i = 0;
320
            wbs_tga_i = `WB_TGA_IO;
321
            wbs_we_i = 0;
322
            wbs_stb_i = 0;
323
            wbs_cyc_i = 0;
324
            dma_chan_i = 3'b0;
325
            dma_tc_i = 0;
326
            dma_req_i = 0;
327 17 hharte
            regfile_ws = 8'h0;          // Number of wait-states (0-255)
328 3 hharte
    Reset();
329 17 hharte
    $display($time, " * * * Using %d peripheral-side wait-states for this test.", regfile_ws);
330 3 hharte
    wbs_tga_i = `WB_TGA_IO;
331
    $display($time, " Testing LPC I/O Accesses");
332 17 hharte
    wb_write(32'h00000000, `WB_SEL_BYTE, 32'h00000012, 0);
333
    wb_write(32'h00000001, `WB_SEL_BYTE, 32'h00000034, 0);
334
    wb_write(32'h00000002, `WB_SEL_BYTE, 32'h00000056, 0);
335
    wb_write(32'h00000003, `WB_SEL_BYTE, 32'h00000078, 0);
336
    wb_write(32'h00000004, `WB_SEL_BYTE, 32'h0000009a, 0);
337
    wb_write(32'h00000005, `WB_SEL_BYTE, 32'h000000bc, 0);
338
    wb_write(32'h00000006, `WB_SEL_BYTE, 32'h000000de, 0);
339
    wb_write(32'h00000007, `WB_SEL_BYTE, 32'h000000f0, 0);
340 3 hharte
 
341 17 hharte
    wb_read(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX12, 0);
342
    wb_read(32'h00000001, `WB_SEL_BYTE, 32'hXXXXXX34, 0);
343
    wb_read(32'h00000002, `WB_SEL_BYTE, 32'hXXXXXX56, 0);
344
    wb_read(32'h00000003, `WB_SEL_BYTE, 32'hXXXXXX78, 0);
345
    wb_read(32'h00000004, `WB_SEL_BYTE, 32'hXXXXXX9a, 0);
346
    wb_read(32'h00000005, `WB_SEL_BYTE, 32'hXXXXXXbc, 0);
347
    wb_read(32'h00000006, `WB_SEL_BYTE, 32'hXXXXXXde, 0);
348
    wb_read(32'h00000007, `WB_SEL_BYTE, 32'hXXXXXXf0, 0);
349 3 hharte
 
350
    wbs_tga_i = `WB_TGA_MEM;
351
    $display($time, " Testing LPC MEM Accesses");
352 17 hharte
    wb_write(32'h00000000, `WB_SEL_BYTE, 32'h00000012, 0);
353
    wb_write(32'h00000001, `WB_SEL_BYTE, 32'h00000034, 0);
354
    wb_write(32'h00000002, `WB_SEL_BYTE, 32'h00000056, 0);
355
    wb_write(32'h00000003, `WB_SEL_BYTE, 32'h00000078, 0);
356
    wb_write(32'h00000004, `WB_SEL_BYTE, 32'h0000009a, 0);
357
    wb_write(32'h00000005, `WB_SEL_BYTE, 32'h000000bc, 0);
358
    wb_write(32'h00000006, `WB_SEL_BYTE, 32'h000000de, 0);
359
    wb_write(32'h00000007, `WB_SEL_BYTE, 32'h000000f0, 0);
360 3 hharte
 
361 17 hharte
    wb_read(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX12, 0);
362
    wb_read(32'h00000001, `WB_SEL_BYTE, 32'hXXXXXX34, 0);
363
    wb_read(32'h00000002, `WB_SEL_BYTE, 32'hXXXXXX56, 0);
364
    wb_read(32'h00000003, `WB_SEL_BYTE, 32'hXXXXXX78, 0);
365
    wb_read(32'h00000004, `WB_SEL_BYTE, 32'hXXXXXX9a, 0);
366
    wb_read(32'h00000005, `WB_SEL_BYTE, 32'hXXXXXXbc, 0);
367
    wb_read(32'h00000006, `WB_SEL_BYTE, 32'hXXXXXXde, 0);
368
    wb_read(32'h00000007, `WB_SEL_BYTE, 32'hXXXXXXf0, 0);
369 3 hharte
 
370
    wbs_tga_i = `WB_TGA_DMA;
371
 
372
    $display($time, " Testing LPC DMA BYTE Accesses");
373
    dma_chan_i = 3'h1;
374 17 hharte
    wb_write(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX21, 0);
375
    wb_read(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX21, 0);
376 3 hharte
 
377
    $display($time, " Testing LPC DMA SHORT Accesses");
378
    dma_chan_i = 3'h3;
379 17 hharte
    wb_write(32'h00000000, `WB_SEL_SHORT, 32'hXXXX6543, 0);
380
    wb_read(32'h00000000, `WB_SEL_SHORT, 32'hXXXX6543, 0);
381 3 hharte
 
382
    $display($time, " Testing LPC DMA WORD Accesses");
383
    dma_chan_i = 3'h7;
384 17 hharte
    wb_write(32'h00000000, `WB_SEL_WORD, 32'hedcba987, 0);
385
    wb_read(32'h00000000, `WB_SEL_WORD, 32'hedcba987, 0);
386 3 hharte
 
387 17 hharte
    dma_chan_i = 3'h0;
388 3 hharte
    wbs_tga_i = `WB_TGA_FW;
389
 
390
    $display($time, " Testing LPC Firmwre BYTE Accesses");
391 17 hharte
    wb_write(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX12, 0);
392
    wb_read(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX12, 0);
393 3 hharte
 
394
    $display($time, " Testing LPC Firmware SHORT Accesses");
395 17 hharte
    wb_write(32'h00000000, `WB_SEL_SHORT, 32'hXXXX3456, 0);
396
    wb_read(32'h00000000, `WB_SEL_SHORT, 32'hXXXX3456, 0);
397 3 hharte
 
398
    $display($time, " Testing LPC Firmware WORD Accesses");
399 17 hharte
    wb_write(32'h00000000, `WB_SEL_WORD, 32'h789abcde, 0);
400
    wb_read(32'h00000000, `WB_SEL_WORD, 32'h789abcde, 0);
401 3 hharte
 
402 17 hharte
    dma_chan_i = 3'h0;
403
    // Test Wishbone transfers that complete with an error.
404
    // This should abort the LPC access in progress and return
405
    // a Wishbone error at the host.  Note that Wishbone will
406
    // detect the bus error when the wishbone master on the
407
    // LPC peripheral attempts the Wishbone transfer.  For LPC
408
    // reads (peripheral to host,) this will be during the
409
    // first byte of the LPC transfer.  For LPC writes (host
410
    // to peripheral,) the Wishbone cycle is initiated when
411
    // the last byte of the LPC access is transferred.
412
    wbs_tga_i = `WB_TGA_IO;
413
    $display($time, " Testing LPC I/O Accesses (with Wishbone error)");
414
    wb_write(32'h00000008, `WB_SEL_BYTE, 32'h00000012, 1);
415
    wb_read(32'h00000008, `WB_SEL_BYTE, 32'hXXXXXX12, 1);
416 3 hharte
 
417 17 hharte
    wbs_tga_i = `WB_TGA_MEM;
418
    $display($time, " Testing LPC MEM Accesses (with Wishbone error)");
419
    wb_write(32'h00000008, `WB_SEL_BYTE, 32'h00000012, 1);
420
    wb_read(32'h00000008, `WB_SEL_BYTE, 32'hXXXXXX12, 1);
421 3 hharte
 
422 17 hharte
    wbs_tga_i = `WB_TGA_DMA;
423 3 hharte
 
424 17 hharte
    $display($time, " Testing LPC DMA BYTE Accesses (with Wishbone error)");
425
    // DMA channel 2 is a special case, using this channel will cause an
426
    // error on the Wishbone backplane.
427
    dma_chan_i = 3'h2;
428
    wb_write(32'h00000008, `WB_SEL_BYTE, 32'hXXXXXX21, 1);
429
    wb_read(32'h00000008, `WB_SEL_BYTE, 32'hXXXXXX21, 1);
430 3 hharte
 
431 17 hharte
    $display($time, " Testing LPC DMA SHORT Accesses (with Wishbone error)");
432
    dma_chan_i = 3'h2;
433
    wb_write(32'h00000008, `WB_SEL_SHORT, 32'hXXXX6543, 1);
434
    wb_read(32'h00000008, `WB_SEL_SHORT, 32'hXXXX6543, 1);
435 3 hharte
 
436 17 hharte
    $display($time, " Testing LPC DMA WORD Accesses (with Wishbone error)");
437
    dma_chan_i = 3'h2;
438
    wb_write(32'h00000008, `WB_SEL_WORD, 32'hedcba987, 1);
439
    wb_read(32'h00000008, `WB_SEL_WORD, 32'hedcba987, 1);
440
 
441
    dma_chan_i = 3'h0;
442
    wbs_tga_i = `WB_TGA_FW;
443
 
444
    // Firmware accesses cannot generate an error, according to the LPC spec;
445
         // however, the wishbone write will fail, so the subsequent read
446
         // will return bad data, so we just don't check the read data.
447
    $display($time, " Testing LPC Firmwre BYTE Accesses (with Wishbone error)");
448
    wb_write(32'h00000008, `WB_SEL_BYTE, 32'hXXXXXX12, 0);
449
    wb_read(32'h00000008, `WB_SEL_BYTE, 32'hXXXXXXXX, 0);
450
 
451
    $display($time, " Testing LPC Firmware SHORT Accesses (with Wishbone error)");
452
    wb_write(32'h00000008, `WB_SEL_SHORT, 32'hXXXX3456, 0);
453
    wb_read(32'h00000008, `WB_SEL_SHORT, 32'hXXXXXXXX, 0);
454
 
455
    $display($time, " Testing LPC Firmware WORD Accesses (with Wishbone error)");
456
    wb_write(32'h00000008, `WB_SEL_WORD, 32'h789abcde, 0);
457
    wb_read(32'h00000008, `WB_SEL_WORD, 32'hXXXXXXXX, 0);
458
 
459 3 hharte
    $display($time, " Simulation passed"); $stop(1);
460
 
461
end
462
 
463
endmodule // wb_lpc_master_tf

powered by: WebSVN 2.1.0

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