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 3

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
    wire lframe_o;
63
    wire [3:0] lad_o;
64
    wire lad_oe;
65
 
66
// Bidirs
67
    wire [3:0] lad_bus;
68
 
69
// LPC Peripheral Inputs
70
    wire [31:0] wbm_dat_i;
71
    wire wbm_ack_i;
72
 
73
// LPC Peripheral Outputs
74
    wire [31:0] wbm_adr_o;
75
    wire [31:0] wbm_dat_o;
76
    wire [3:0] wbm_sel_o;
77
    wire [1:0] wbm_tga_o;
78
    wire wbm_we_o;
79
    wire wbm_stb_o;
80
    wire wbm_cyc_o;
81
    wire [2:0] dma_chan_o;
82
    wire dma_tc_o;
83
 
84
    wire [3:0] slave_lad_i;
85
    wire [3:0] slave_lad_o;
86
 
87
    reg dma_req_i;
88
 
89
task Reset;
90
begin
91
    nrst_i = 1; # 1000;
92
    nrst_i = 0; # 1000;
93
    nrst_i = 1; # 1000;
94
end
95
endtask
96
 
97
 
98
task wb_write;
99
    input reg [31:0] adr_i;
100
    input reg [3:0]  sel_i;
101
    input reg [31:0] dat_i;
102
    reg [7:0] wait_cnt;
103
    begin
104
 
105
    wbs_adr_i = adr_i;
106
    wbs_sel_i = sel_i;
107
    wbs_dat_i = dat_i;
108
    wbs_stb_i = 1'b1;
109
    wbs_cyc_i = 1'b1;
110
    wbs_we_i = 1'b1;
111
 
112
    wait_cnt = 0;
113
 
114
    while ((wbs_ack_o == 0) & (wait_cnt < 100))
115
    begin
116
        wait_cnt = wait_cnt+1;
117
        # 100;
118
    end
119
 
120
    if(wait_cnt == 100)
121
    begin
122
            $display($time, " Error, wb_w[%x/%x]: timeout waiting for ack", adr_i, dat_i); $stop(1);
123
    end
124
 
125
    wbs_stb_i = 1'b0;
126
    wbs_cyc_i = 1'b0;
127
    wbs_we_i = 1'b0;
128
 
129
    end
130
endtask
131
 
132
 
133
task wb_read;
134
    input reg [31:0] adr_i;
135
    input reg [3:0]  sel_i;
136
    input reg [31:0] dat_i;
137
    reg [7:0] wait_cnt;
138
    begin
139
 
140
    wbs_adr_i = adr_i;
141
    wbs_sel_i = sel_i;
142
    wbs_dat_i = 32'h0;
143
    wbs_stb_i = 1'b1;
144
    wbs_cyc_i = 1'b1;
145
    wbs_we_i = 1'b0;
146
 
147
    wait_cnt = 0;
148
 
149
    while ((wbs_ack_o == 0) & (wait_cnt < 100))
150
    begin
151
        wait_cnt = wait_cnt+1;
152
        # 100;
153
    end
154
 
155
    if(wait_cnt == 100)
156
    begin
157
        $display($time, " Error, wb_r[%x]: timeout waiting for ack", adr_i); $stop(1);
158
    end
159
 
160
    wbs_stb_i = 1'b0;
161
    wbs_cyc_i = 1'b0;
162
 
163
    if(dat_i != wbs_dat_o)
164
    begin
165
        $display($time, " Error, wb_r[%x]: expected %x, got %x", adr_i, dat_i, wbs_dat_o); $stop(1);
166
    end
167
 
168
    end
169
endtask
170
 
171
 
172
   always begin
173
       #50 clk_i = 0;
174
       #50 clk_i = 1;
175
   end
176
 
177
// Instantiate the UUT
178
    wb_lpc_host UUT_Host (
179
        .clk_i(clk_i),
180
        .nrst_i(nrst_i),
181
        .wbs_adr_i(wbs_adr_i),
182
        .wbs_dat_o(wbs_dat_o),
183
        .wbs_dat_i(wbs_dat_i),
184
        .wbs_sel_i(wbs_sel_i),
185
        .wbs_tga_i(wbs_tga_i),
186
        .wbs_we_i(wbs_we_i),
187
        .wbs_stb_i(wbs_stb_i),
188
        .wbs_cyc_i(wbs_cyc_i),
189
        .wbs_ack_o(wbs_ack_o),
190
        .dma_chan_i(dma_chan_i),
191
        .dma_tc_i(dma_tc_i),
192
        .lframe_o(lframe_o),
193
        .lad_i(lad_i),
194
        .lad_o(lad_o),
195
        .lad_oe(lad_oe)
196
        );
197
 
198
// Instantiate the module
199
wb_lpc_periph UUT_Periph (
200
    .clk_i(clk_i),
201
    .nrst_i(nrst_i),
202
    .wbm_adr_o(wbm_adr_o),
203
    .wbm_dat_o(wbm_dat_o),
204
    .wbm_dat_i(wbm_dat_i),
205
    .wbm_sel_o(wbm_sel_o),
206
    .wbm_tga_o(wbm_tga_o),
207
    .wbm_we_o(wbm_we_o),
208
    .wbm_stb_o(wbm_stb_o),
209
    .wbm_cyc_o(wbm_cyc_o),
210
    .wbm_ack_i(wbm_ack_i),
211
    .dma_chan_o(dma_chan_o),
212
    .dma_tc_o(dma_tc_o),
213
    .lframe_i(lframe_o),
214
    .lad_i(slave_lad_i),
215
    .lad_o(slave_lad_o),
216
    .lad_oe(slave_lad_oe)
217
    );
218
 
219
wire       ldrq_o;
220
wire [2:0] master_dma_chan_o;
221
wire       master_dma_req_o;
222
 
223
// Instantiate the module
224
wb_dreq_periph UUT_DREQ_Periph (
225
    .clk_i(clk_i),
226
    .nrst_i(nrst_i),
227
    .dma_chan_i(dma_chan_i),
228
    .dma_req_i(dma_req_i),
229
    .ldrq_o(ldrq_o)
230
    );
231
 
232
// Instantiate the module
233
wb_dreq_host UUT_DREQ_Host (
234
    .clk_i(clk_i),
235
    .nrst_i(nrst_i),
236
    .dma_chan_o(master_dma_chan_o),
237
    .dma_req_o(master_dma_req_o),
238
    .ldrq_i(ldrq_o)
239
    );
240
 
241
wire [31:0] datareg0;
242
wire [31:0] datareg1;
243
 
244
// Instantiate the module
245
wb_regfile regfile (
246
    .clk_i(clk_i),
247
    .nrst_i(nrst_i),
248
    .wb_adr_i(wbm_adr_o),
249
    .wb_dat_o(wbm_dat_i),
250
    .wb_dat_i(wbm_dat_o),
251
    .wb_sel_i(wbm_sel_o),
252
    .wb_we_i(wbm_we_o),
253
    .wb_stb_i(wbm_stb_o),
254
    .wb_cyc_i(wbm_cyc_o),
255
    .wb_ack_o(wbm_ack_i),
256
    .datareg0(datareg0),
257
    .datareg1(datareg1)
258
    );
259
 
260
assign lad_bus = lad_oe ? lad_o : (slave_lad_oe ? slave_lad_o : 4'bzzzz);
261
assign lad_i = lad_bus;
262
assign slave_lad_i = lad_bus;
263
 
264
// Initialize Inputs
265
    initial begin
266
//      $monitor("Time: %d clk_i=%b",
267
//          $time, clk_i);
268
            clk_i = 0;
269
            nrst_i = 1;
270
            wbs_adr_i = 0;
271
            wbs_dat_i = 0;
272
            wbs_sel_i = 0;
273
            wbs_tga_i = `WB_TGA_IO;
274
            wbs_we_i = 0;
275
            wbs_stb_i = 0;
276
            wbs_cyc_i = 0;
277
            dma_chan_i = 3'b0;
278
            dma_tc_i = 0;
279
            dma_req_i = 0;
280
 
281
    Reset();
282
 
283
    wbs_tga_i = `WB_TGA_IO;
284
    $display($time, " Testing LPC I/O Accesses");
285
    wb_write(32'h00000000, `WB_SEL_BYTE, 32'h00000012);
286
    # 100;
287
    wb_write(32'h00000001, `WB_SEL_BYTE, 32'h00000034);
288
    # 100;
289
    wb_write(32'h00000002, `WB_SEL_BYTE, 32'h00000056);
290
    # 100;
291
    wb_write(32'h00000003, `WB_SEL_BYTE, 32'h00000078);
292
    # 100;
293
    wb_write(32'h00000004, `WB_SEL_BYTE, 32'h0000009a);
294
    # 100;
295
    wb_write(32'h00000005, `WB_SEL_BYTE, 32'h000000bc);
296
    # 100;
297
    wb_write(32'h00000006, `WB_SEL_BYTE, 32'h000000de);
298
    # 100;
299
    wb_write(32'h00000007, `WB_SEL_BYTE, 32'h000000f0);
300
    # 100;
301
 
302
    wb_read(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX12);
303
    # 100;
304
    wb_read(32'h00000001, `WB_SEL_BYTE, 32'hXXXXXX34);
305
    # 100;
306
    wb_read(32'h00000002, `WB_SEL_BYTE, 32'hXXXXXX56);
307
    # 100;
308
    wb_read(32'h00000003, `WB_SEL_BYTE, 32'hXXXXXX78);
309
    # 100;
310
    wb_read(32'h00000004, `WB_SEL_BYTE, 32'hXXXXXX9a);
311
    # 100;
312
    wb_read(32'h00000005, `WB_SEL_BYTE, 32'hXXXXXXbc);
313
    # 100;
314
    wb_read(32'h00000006, `WB_SEL_BYTE, 32'hXXXXXXde);
315
    # 100;
316
    wb_read(32'h00000007, `WB_SEL_BYTE, 32'hXXXXXXf0);
317
    # 100;
318
 
319
 
320
    wbs_tga_i = `WB_TGA_MEM;
321
    $display($time, " Testing LPC MEM Accesses");
322
    wb_write(32'h00000000, `WB_SEL_BYTE, 32'h00000012);
323
    # 100;
324
    wb_write(32'h00000001, `WB_SEL_BYTE, 32'h00000034);
325
    # 100;
326
    wb_write(32'h00000002, `WB_SEL_BYTE, 32'h00000056);
327
    # 100;
328
    wb_write(32'h00000003, `WB_SEL_BYTE, 32'h00000078);
329
    # 100;
330
    wb_write(32'h00000004, `WB_SEL_BYTE, 32'h0000009a);
331
    # 100;
332
    wb_write(32'h00000005, `WB_SEL_BYTE, 32'h000000bc);
333
    # 100;
334
    wb_write(32'h00000006, `WB_SEL_BYTE, 32'h000000de);
335
    # 100;
336
    wb_write(32'h00000007, `WB_SEL_BYTE, 32'h000000f0);
337
    # 100;
338
 
339
    wb_read(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX12);
340
    # 100;
341
    wb_read(32'h00000001, `WB_SEL_BYTE, 32'hXXXXXX34);
342
    # 100;
343
    wb_read(32'h00000002, `WB_SEL_BYTE, 32'hXXXXXX56);
344
    # 100;
345
    wb_read(32'h00000003, `WB_SEL_BYTE, 32'hXXXXXX78);
346
    # 100;
347
    wb_read(32'h00000004, `WB_SEL_BYTE, 32'hXXXXXX9a);
348
    # 100;
349
    wb_read(32'h00000005, `WB_SEL_BYTE, 32'hXXXXXXbc);
350
    # 100;
351
    wb_read(32'h00000006, `WB_SEL_BYTE, 32'hXXXXXXde);
352
    # 100;
353
    wb_read(32'h00000007, `WB_SEL_BYTE, 32'hXXXXXXf0);
354
    # 100;
355
 
356
    wbs_tga_i = `WB_TGA_DMA;
357
 
358
    $display($time, " Testing LPC DMA BYTE Accesses");
359
    dma_chan_i = 3'h1;
360
    wb_write(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX21);
361
    # 100;
362
 
363
    wb_read(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX21);
364
    # 100;
365
 
366
    $display($time, " Testing LPC DMA SHORT Accesses");
367
    dma_chan_i = 3'h3;
368
    wb_write(32'h00000000, `WB_SEL_SHORT, 32'hXXXX6543);
369
    # 100;
370
 
371
    wb_read(32'h00000000, `WB_SEL_SHORT, 32'hXXXX6543);
372
    # 100;
373
 
374
    $display($time, " Testing LPC DMA WORD Accesses");
375
    dma_chan_i = 3'h7;
376
    wb_write(32'h00000000, `WB_SEL_WORD, 32'hedcba987);
377
    # 100;
378
 
379
    wb_read(32'h00000000, `WB_SEL_WORD, 32'hedcba987);
380
    # 100;
381
 
382
    wbs_tga_i = `WB_TGA_FW;
383
 
384
    $display($time, " Testing LPC Firmwre BYTE Accesses");
385
    dma_chan_i = 3'h1;
386
    wb_write(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX12);
387
    # 100;
388
 
389
    wb_read(32'h00000000, `WB_SEL_BYTE, 32'hXXXXXX12);
390
    # 100;
391
 
392
    $display($time, " Testing LPC Firmware SHORT Accesses");
393
    dma_chan_i = 3'h3;
394
    wb_write(32'h00000000, `WB_SEL_SHORT, 32'hXXXX3456);
395
    # 100;
396
 
397
    wb_read(32'h00000000, `WB_SEL_SHORT, 32'hXXXX3456);
398
    # 100;
399
 
400
    $display($time, " Testing LPC Firmware WORD Accesses");
401
    dma_chan_i = 3'h7;
402
    wb_write(32'h00000000, `WB_SEL_WORD, 32'h789abcde);
403
    # 100;
404
 
405
    wb_read(32'h00000000, `WB_SEL_WORD, 32'h789abcde);
406
    # 100;
407
 
408
    dma_req_i = 1;
409
    # 100
410
    dma_req_i = 0;
411
    # 1000;
412
 
413
    dma_chan_i = 3'b101;
414
 
415
    dma_req_i = 1;
416
    # 100
417
    dma_req_i = 0;
418
    # 1000;
419
 
420
 
421
    $display($time, " Simulation passed"); $stop(1);
422
 
423
end
424
 
425
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.