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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [verilog/] [orpsoc_testbench.v] - Blame information for rev 49

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

Line No. Rev Author Line
1 6 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  ORPSoC Testbench                                            ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  ORPSoC Testbench file                                       ////
7
////                                                              ////
8
////  To Do:                                                      ////
9
////                                                              ////
10
////                                                              ////
11
////  Author(s):                                                  ////
12
////      - jb, jb@orsoc.se                                       ////
13
////                                                              ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
18
////                                                              ////
19
//// This source file may be used and distributed without         ////
20
//// restriction provided that this copyright statement is not    ////
21
//// removed from the file and that any derivative work contains  ////
22
//// the original copyright notice and the associated disclaimer. ////
23
////                                                              ////
24
//// This source file is free software; you can redistribute it   ////
25
//// and/or modify it under the terms of the GNU Lesser General   ////
26
//// Public License as published by the Free Software Foundation; ////
27
//// either version 2.1 of the License, or (at your option) any   ////
28
//// later version.                                               ////
29
////                                                              ////
30
//// This source is distributed in the hope that it will be       ////
31
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
32
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
33
//// PURPOSE.  See the GNU Lesser General Public License for more ////
34
//// details.                                                     ////
35
////                                                              ////
36
//// You should have received a copy of the GNU Lesser General    ////
37
//// Public License along with this source; if not, download it   ////
38
//// from http://www.opencores.org/lgpl.shtml                     ////
39
////                                                              ////
40
//////////////////////////////////////////////////////////////////////
41
 
42
`include "timescale.v"
43
`include "orpsoc_testbench_defines.v"
44
 
45
module orpsoc_testbench();
46
 
47
 
48
   reg clk;
49
   reg rst;
50
 
51
   // Setup global clock. Period defined in orpsoc_testbench_defines.v
52
   initial
53
     begin
54
        clk <= 0;
55
        rst <= 1;
56
     end
57
 
58
   always
59
     begin
60
        #((`CLOCK_PERIOD)/2) clk <= ~clk;
61
     end
62
 
63
   // Assert rst and then bring it low again
64
   initial
65
     begin
66
        repeat (2) @(negedge clk);
67
        rst <= 0;
68
        repeat (16) @(negedge clk);
69
        rst <= 1;
70
     end
71
 
72
 
73
   // Wires for the dut
74
   wire spi_sd_sclk_o;
75
   wire spi_sd_ss_o;
76
   wire spi_sd_miso_i;
77
   wire spi_sd_mosi_o;
78
`ifdef USE_SDRAM
79
   wire [15:0] mem_dat_io;
80
   wire [12:0] mem_adr_o;
81
   wire [1:0]  mem_dqm_o;
82
   wire [1:0]  mem_ba_o;
83
   wire        mem_cs_o;
84
   wire        mem_ras_o;
85
   wire        mem_cas_o;
86
   wire        mem_we_o;
87
   wire        mem_cke_o;
88
   wire        spi_flash_sclk_o;
89
   wire        spi_flash_ss_o;
90
   wire        spi_flash_miso_i;
91
   wire        spi_flash_mosi_o;
92
   wire        spi_flash_w_n_o;
93
   wire        spi_flash_hold_n_o;
94
`endif //  `ifdef USE_SDRAM
95
 
96
`ifdef USE_ETHERNET
97
   wire [1:1]  eth_sync_o;
98
   wire [1:1] eth_tx_o;
99
   wire [1:1] eth_rx_i;
100
   wire       eth_clk_i;
101
   wire [1:1] eth_md_io;
102
   wire [1:1] eth_mdc_o;
103
`endif
104
 
105
   wire       spi1_mosi_o;
106
   wire       spi1_miso_i;
107
   wire       spi1_ss_o;
108
   wire       spi1_sclk_o;
109
   wire [8-1:0] gpio_a_io;
110
   wire         uart0_srx_i;
111
   wire         uart0_stx_o;
112
   wire         dbg_tdi_i;
113
   wire         dbg_tck_i;
114
   wire         dbg_tms_i;
115
   wire         dbg_tdo_o;
116
   wire         rst_i;
117
   wire         rst_o;
118
   wire         clk_i;
119
 
120
 
121
   assign clk_i = clk;
122
   assign rst_i = rst;
123
 
124
   // Tie off some inputs   
125
   assign spi1_miso_i = 0;
126
   assign uart0_srx_i = 1;
127
 
128
 
129
   orpsoc_top dut
130
     (
131
      // Outputs
132
      .spi_sd_sclk_pad_o                        (spi_sd_sclk_o),
133
      .spi_sd_ss_pad_o                  (spi_sd_ss_o),
134
      .spi_sd_mosi_pad_o                        (spi_sd_mosi_o),
135
      .spi1_mosi_pad_o                  (spi1_mosi_o),
136
      .spi1_ss_pad_o                    (spi1_ss_o),
137
      .spi1_sclk_pad_o                  (spi1_sclk_o),
138
      .uart0_stx_pad_o                  (uart0_stx_o),
139
      .dbg_tdo_pad_o                    (dbg_tdo_o),
140
      .rst_pad_o                                (rst_o),
141
      .gpio_a_pad_io                    (gpio_a_io[8-1:0]),
142
      // Inputs
143
      .spi_sd_miso_pad_i                        (spi_sd_miso_i),
144
      .spi1_miso_pad_i                  (spi1_miso_i),
145
      .uart0_srx_pad_i                  (uart0_srx_i),
146
      .dbg_tdi_pad_i                    (dbg_tdi_i),
147
      .dbg_tck_pad_i                    (dbg_tck_i),
148
      .dbg_tms_pad_i                    (dbg_tms_i),
149
`ifdef USE_ETHERNET
150
      // Ethernet ports
151
      .eth_md_pad_io                    (eth_md_io[1:1]),
152 44 julius
      .eth_mdc_pad_o                    (eth_mdc_o[1:1]),
153 6 julius
      .eth_sync_pad_o                   (eth_sync_o[1:1]),
154
      .eth_tx_pad_o                     (eth_tx_o[1:1]),
155
      .eth_rx_pad_i                     (eth_rx_i[1:1]),
156
      .eth_clk_pad_i                    (eth_clk_i),
157
`endif  //  `ifdef USE_ETHERNET      
158
      // SDRAM and flash memory ports
159
`ifdef USE_SDRAM
160
      .mem_dat_pad_io                   (mem_dat_io[15:0]),
161
      .mem_adr_pad_o                    (mem_adr_o[12:0]),
162
      .mem_dqm_pad_o                    (mem_dqm_o[1:0]),
163
      .mem_ba_pad_o                     (mem_ba_o[1:0]),
164
      .mem_cs_pad_o                     (mem_cs_o),
165
      .mem_ras_pad_o                    (mem_ras_o),
166
      .mem_cas_pad_o                    (mem_cas_o),
167
      .mem_we_pad_o                     (mem_we_o),
168
      .mem_cke_pad_o                    (mem_cke_o),
169
      .spi_flash_sclk_pad_o             (spi_flash_sclk_o),
170
      .spi_flash_ss_pad_o                       (spi_flash_ss_o),
171
      .spi_flash_mosi_pad_o             (spi_flash_mosi_o),
172
      .spi_flash_w_n_pad_o                      (spi_flash_w_n_o),
173
      .spi_flash_hold_n_pad_o           (spi_flash_hold_n_o),
174
      .spi_flash_miso_pad_i             (spi_flash_miso_i),
175
`endif
176
      .rst_pad_i                                (rst_i),
177
      .clk_pad_i                                (clk_i));
178
 
179 40 julius
`ifdef VPI_DEBUG_ENABLE
180
   // Debugging interface
181
   vpi_debug_module vpi_dbg(
182
                            .tms(dbg_tms_i),
183
                            .tck(dbg_tck_i),
184
                            .tdi(dbg_tdi_i),
185
                            .tdo(dbg_tdo_o));
186
`else
187
   // If no VPI debugging, tie off JTAG inputs
188
   assign dbg_tdi_i = 1;
189
   assign dbg_tck_i = 0;
190
   assign dbg_tms_i = 1;
191
`endif
192
 
193
 
194
 
195 6 julius
   // External memories, if enabled
196
`ifdef USE_SDRAM
197
   // SPI Flash
198
   AT26DFxxx spi_flash
199
     (
200
      // Outputs
201
      .SO                                       (spi_flash_miso_i),
202
      // Inputs
203
      .CSB                                      (spi_flash_ss_o),
204
      .SCK                                      (spi_flash_sclk_o),
205
      .SI                                       (spi_flash_mosi_o),
206
      .WPB                                      (spi_flash_w_n_o)
207
      //.HOLDB                          (spi_flash_hold_n_o)
208
      );
209
 
210
   // SDRAM
211
   mt48lc16m16a2 sdram
212
     (
213
      // Inouts
214
      .Dq                                       (mem_dat_io),
215
      // Inputs
216
      .Addr                             (mem_adr_o),
217
      .Ba                                       (mem_ba_o),
218
      .Clk                                      (clk_i),
219
      .Cke                                      (mem_cke_o),
220
      .Cs_n                             (mem_cs_o),
221
      .Ras_n                            (mem_ras_o),
222
      .Cas_n                            (mem_cas_o),
223
      .We_n                             (mem_we_o),
224
      .Dqm                                      (mem_dqm_o));
225
 
226
`endif // !`ifdef USE_SDRAM
227
 
228 44 julius
`ifdef USE_ETHERNET
229 6 julius
 
230 44 julius
   reg          eth_clk;
231
   initial
232
     eth_clk <= 0;
233
 
234
   always
235
     #(8/2) eth_clk <= ~eth_clk; // 125 Mhz clock
236
 
237
   assign eth_clk_i = eth_clk;
238
 
239
 
240
 
241
   wire [3:0]            ethphy_mii_tx_d;
242
   wire                 ethphy_mii_tx_en;
243
   wire                 ethphy_mii_tx_err;
244
   wire                 mcoll_o;
245
   wire                 mcrs_o;
246
   wire                 md_io;
247
   wire                 mrx_clk_o;
248
   wire [3:0]            mrxd_o;
249
   wire                 mrxdv_o;
250
   wire                 mrxerr_o;
251
   wire                 mtx_clk_o;
252
   wire                 smii_rx;
253
   wire                 fast_ethernet, duplex, link;
254
 
255
   /* Converts SMII back to MII */
256
   smii_phy smii_phyend
257
     (
258
      // Outputs
259
      .smii_rx                          (eth_rx_i[1:1]), /* SMII RX */
260
      .ethphy_mii_tx_d                  (ethphy_mii_tx_d[3:0]), /* MII TX */
261
      .ethphy_mii_tx_en                 (ethphy_mii_tx_en),     /* MII TX */
262
      .ethphy_mii_tx_err                (ethphy_mii_tx_err),    /* MII TX */
263
      // Inputs
264
      .smii_tx                          (eth_tx_o[1:1]),        /* SMII TX */
265
      .smii_sync                        (eth_sync_o[1:1]),      /* SMII SYNC */
266
      .ethphy_mii_tx_clk                (mtx_clk_o),            /* MII TX */
267
 
268
      .ethphy_mii_rx_d                  (mrxd_o[3:0]), /* MII RX */
269
      .ethphy_mii_rx_dv                 (mrxdv_o),     /* MII RX */
270
      .ethphy_mii_rx_err                (mrxerr_o),    /* MII RX */
271
      .ethphy_mii_rx_clk                (mrx_clk_o),   /* MII RX */
272
 
273
      .ethphy_mii_mcoll                 (),
274
      .ethphy_mii_crs                   (mcrs_o),
275
      .fast_ethernet                    (fast_ethernet),
276
      .duplex                           (duplex),
277
      .link                             (link),
278
      .clk                              (eth_clk_i),
279
      .rst_n                            (rst_i));
280
 
281
`ifdef ENABLE_ETH_STIM
282
   /* Generates an RX packet */
283
 `include "eth_stim.v"
284
`endif
285
 
286
   eth_phy eth_phy0
287
     (
288
      // Outputs
289
      .mtx_clk_o                        (mtx_clk_o),
290
      .mrx_clk_o                        (mrx_clk_o),
291
      .mrxd_o                           (mrxd_o[3:0]),
292
      .mrxdv_o                          (mrxdv_o),
293
      .mrxerr_o                         (mrxerr_o),
294
      .mcoll_o                          (mcoll_o),
295
      .mcrs_o                           (mcrs_o),
296
      // Sideband outputs for smii converter --jb
297
      .link_o                             (link),
298
      .speed_o                            (fast_ethernet),
299
      .duplex_o                           (duplex),
300
      // Inouts
301
      .md_io                            (eth_md_io[1:1]),
302
      // Inputs
303
      .m_rst_n_i                        (rst_i),
304
      .mtxd_i                           (ethphy_mii_tx_d[3:0]),
305
      .mtxen_i                          (ethphy_mii_tx_en),
306
      .mtxerr_i                         (ethphy_mii_tx_err),
307
      .mdc_i                            (eth_mdc_o[1:1]));
308
 
309
`endif //  `ifdef USE_ETHERNET
310
 
311
 
312 6 julius
initial
313
  begin
314
     $display("\nStarting RTL simulation of %s test\n", `TEST_NAME_STRING);
315
`ifdef USE_SDRAM
316
     $display("Using SDRAM - loading application from SPI flash memory\n");
317
`endif
318
 
319
`ifdef VCD
320
     $display("VCD in %s\n", {`TEST_RESULTS_DIR,`TEST_NAME_STRING,".vcd"});
321
     $dumpfile({`TEST_RESULTS_DIR,`TEST_NAME_STRING,".vcd"});
322
     $dumpvars(0);
323
`endif
324
  end
325
 
326
   // Instantiate the monitor
327
   or1200_monitor monitor();
328
 
329
   // If we're using UART for printf output, include the
330
   // UART decoder
331
`ifdef UART_PRINTF
332
   // Define the UART's txt line for it to listen to
333
 `define UART_TX_LINE uart0_stx_o
334
 `define UART_BAUDRATE 115200
335
 `include "uart_decoder.v"
336
`endif
337
 
338
endmodule // orpsoc_testbench
339
 
340
// Local Variables:
341 49 julius
// verilog-library-files:("../../rtl/verilog/orpsoc_top.v")
342 6 julius
// verilog-library-directories:("." "../../rtl/verilog")
343 49 julius
// End:

powered by: WebSVN 2.1.0

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