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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [verif/] [tb/] [tb_top.v] - Blame information for rev 29

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

Line No. Rev Author Line
1 2 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////                                                              ////
4
////  This file is part of the OMS 8051 cores project             ////
5
////  http://www.opencores.org/cores/oms8051/                     ////
6
////                                                              ////
7
////  Description                                                 ////
8
////  OMS 8051 definitions.                                       ////
9
////                                                              ////
10
////  To Do:                                                      ////
11
////    nothing                                                   ////
12
////                                                              ////
13
////  Author(s):                                                  ////
14
////      - Dinesh Annayya, dinesha@opencores.org                 ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
 
43
 
44
 
45
`include "tb_defines.v"
46
 
47
module tb_top;
48
 
49
 
50
reg    reset_n;
51
reg    reset;
52
reg    xtal_clk;
53
reg    ref_clk_125;
54
wire   app_clk;
55
reg    ref_clk_50;
56
reg    uart_clk_16x;
57
 
58
 
59
parameter XTAL_CLK_PERIOD = 10; // 100MHZ 40; // 25Mhz
60
parameter APP_CLK_PERIOD = 10;
61
parameter REF_CLK_125_PERIOD = 8;
62
parameter REF_CLK_50_PERIOD = 20;
63
parameter UART_REF_CLK_PERIOD = 20;
64
 
65
reg[31:0] events_log;
66
 
67
initial
68
begin
69
        reset_n = 1;
70
   #100 reset_n = 0;
71
   #100 reset_n = 1;
72
end
73
 
74
 
75
initial begin
76
  xtal_clk = 1'b0;
77
  forever #(XTAL_CLK_PERIOD/2.0) xtal_clk = ~xtal_clk;
78
end
79
 
80
 
81
//initial begin
82
//  app_clk = 1'b0;
83
//  forever #(APP_CLK_PERIOD/2.0) app_clk = ~app_clk;
84
//end
85
 
86
initial begin
87
  ref_clk_125 = 1'b0;
88
  forever #(REF_CLK_125_PERIOD/2.0) ref_clk_125 = ~ref_clk_125;
89
end
90
 
91
initial begin
92
  ref_clk_50 = 1'b0;
93
  forever #(REF_CLK_50_PERIOD/2.0) ref_clk_50 = ~ref_clk_50;
94
end
95
 
96
 
97
initial begin
98
  uart_clk_16x = 1'b0;
99
  forever #(UART_REF_CLK_PERIOD/2.0) uart_clk_16x = ~uart_clk_16x;
100
end
101
 
102
 
103
wire [3:0]   phy_txd            ;
104
wire [3:0]   phy_rxd            ;
105
 
106
//---------------------------------
107
// Reg Bus Interface Signal
108
//---------------------------------
109 11 dinesha
reg                reg_cs        ;
110
reg [3:0]          reg_id        ;
111
reg                reg_wr        ;
112
reg  [14:0]        reg_addr      ;
113
reg  [7:0]         reg_wdata     ;
114
reg                reg_be        ;
115 2 dinesha
 
116
// Outputs
117 11 dinesha
wire  [7:0]        reg_rdata     ;
118
wire               reg_ack       ;
119 2 dinesha
 
120 11 dinesha
reg                master_mode   ;
121
reg                ea_in         ;   // 1--> Internal Memory
122 2 dinesha
 
123 11 dinesha
 
124
wire               spi_sck       ;
125
wire               spi_so        ;
126
wire               spi_si        ;
127
wire [3:0]         spi_cs_n      ;
128 2 dinesha
 
129 11 dinesha
wire               clkout        ;
130
wire               reset_out_n   ;
131 2 dinesha
 
132 29 dinesha
parameter I2CS_ADDR    = 7'b0010_000; // I2C Slave Addr
133 2 dinesha
//----------------------------------------
134
 
135
digital_core  u_core (
136
 
137 27 dinesha
             . aresetn             (reset_n            ),
138 2 dinesha
             . fastsim_mode        (1'b1               ),
139
             . mastermode          (master_mode        ),
140
 
141
             . xtal_clk            (xtal_clk           ),
142
             . clkout              (app_clk            ),
143
             . reset_out_n         (reset_out_n        ),
144 10 dinesha
             . ea_in               (ea_in              ), // internal ROM
145 2 dinesha
 
146
        // Reg Bus Interface Signal
147
             . ext_reg_cs          (reg_cs             ),
148
             . ext_reg_tid         (reg_id             ),
149
             . ext_reg_wr          (reg_wr             ),
150
             . ext_reg_addr        (reg_addr[14:0]     ),
151
             . ext_reg_wdata       (reg_wdata          ),
152
 
153
            // Outputs
154
             . ext_reg_rdata       (reg_rdata          ),
155
             . ext_reg_ack         (reg_ack            ),
156
 
157
 
158
 
159
       // UART Line Interface
160 19 dinesha
             .uart1_rxd            (si                 ),
161
             .uart1_txd            (so                 ),
162 2 dinesha
 
163 19 dinesha
             .uart0_rxd            (1'b0               ),
164
             .uart0_txd            (                   ),
165 2 dinesha
 
166
             .spi_sck              (spi_sck            ),
167
             .spi_so               (spi_so             ),
168
             .spi_si               (spi_si             ),
169 29 dinesha
             .spi_cs_n             (spi_cs_n           ),
170 2 dinesha
 
171 29 dinesha
        // i2cm clock line
172
             .i2cm_scl_i           (scl                ),
173
             .i2cm_scl_o           (i2cm_scl_o         ),
174
             .i2cm_scl_oen         (i2cm_scl_oen       ),
175 2 dinesha
 
176 29 dinesha
        // i2cm data line
177
             .i2cm_sda_i           (sda                ),
178
             .i2cm_sda_o           (i2cm_sda_o         ),
179
             .i2cm_sda_oen         (i2cm_sda_oen       )
180
 
181
 
182
 
183 2 dinesha
        );
184
 
185 29 dinesha
                // create i2c lines
186
        delay m0_scl (i2cm_scl_oen ? 1'bz : i2cm_scl_o, scl),
187
              m0_sda (i2cm_sda_oen ? 1'bz : i2cm_sda_o, sda);
188 2 dinesha
 
189 29 dinesha
        pullup p1(scl); // pullup scl line
190
        pullup p2(sda); // pullup sda line
191
 
192
        // hookup i2c slave model
193
        i2c_slave_model #(I2CS_ADDR) tb_i2cs (
194
             .scl                  (scl                  ),
195
             .sda                  (sda                  )
196
        );
197
 
198
 
199 2 dinesha
 uart_agent tb_uart (
200
               . test_clk          (uart_clk_16x       ),
201
               . sin               (si                 ),
202
               . dsr_n             (                   ),
203
               . cts_n             (                   ),
204
               . dcd_n             (                   ),
205
 
206
               . sout              (so                 ),
207
               . dtr_n             (1'b0               ),
208
               . rts_n             (1'b0               ),
209
               . out1_n            (1'b0               ),
210
               . out2_n            (1'b0               )
211
       );
212
 
213
 
214
//----------------------- SPI Agents
215
 
216
m25p20 i_m25p20_0 (
217
               .c                  (spi_sck            ),
218
               .s                  (spi_cs_n[0]        ), // Include selection logic
219
               .w                  (1'b1               ), // Write protect is always disabled
220
               .hold               (1'b1               ), // Hold support not used
221
               .data_in            (spi_so             ),
222
               .data_out           (spi_si             )
223
             );
224
 
225
 
226
AT45DB321 i_AT45DB321_0 (
227
               .CSB                (spi_cs_n[1]        ),
228
               .SCK                (spi_sck            ),
229
               .SI                 (spi_so             ),
230
               .WPB                (1'b1               ),
231
               .RESETB             (1'b1               ),
232
               .RDY_BUSYB          (                   ),
233
               .SO                 (spi_si             )
234
      );
235
/***************
236
spi_agent_3120 spi_agent_3120_0 (
237
               .cs_b               (spi_cs_n[2]        ),
238
               .spi_din            (spi_si             ),
239
               .spi_dout           (spi_so             ),
240
               .spi_clk            (spi_sck            )
241
       );
242
 
243
spi_agent_3120 spi_agent_3120_1 (
244
               .cs_b               (spi_cs_n[3]        ),
245
               .spi_din            (spi_si             ),
246
               .spi_dout           (spi_so             ),
247
               .spi_clk            (spi_sck            )
248
       );
249
*****************/
250
 
251
tb_glbl  tb_glbl ();
252
 
253
 
254
`ifdef DUMP_ENABLE
255
initial begin
256
   if ( $test$plusargs("DUMP") ) begin
257
          $fsdbDumpfile("../dump/test_1.fsdb");
258
      $fsdbDumpvars;
259
      $fsdbDumpon;
260
   end
261
end
262
`endif
263
 
264
initial begin //{
265
   $display ("--> Dumpping the design");
266
   $shm_open("simvision.shm");
267
   $shm_probe("AC");
268
end //}
269
 
270
 
271
initial begin
272
 
273
   if ( $test$plusargs("INTERNAL_ROM") )  begin
274
      ea_in       = 1;
275
      master_mode = 1;
276
   end else if ( $test$plusargs("EXTERNAL_ROM") ) begin
277
      ea_in       = 0;
278
      master_mode = 1;
279
   end else begin
280
      ea_in       = 0;
281
      master_mode = 0;
282
   end
283
 
284
  `TB_GLBL.init;
285
 
286
   #1000 wait(reset_out_n == 1);
287
 
288
   if ( $test$plusargs("uart_test_1") )
289
       uart_test1();
290
   else if ( $test$plusargs("spi_test_1") )
291
       spi_test1();
292 29 dinesha
   else if ( $test$plusargs("i2cm_test_1") )
293
       i2cm_test1();
294 2 dinesha
   else begin
295
     // 8051 Test Cases
296
     #80000000
297
     $display("time ",$time, "\n faulire: end of time\n \n");
298
   end
299
 
300
   `TB_GLBL.test_stats;
301
   `TB_GLBL.test_finish;
302
   #1000 $finish;
303
end
304
 
305
wire [7:0] p2_out = u_core.u_8051_core.p2_o;
306
wire [7:0] p3_out = u_core.u_8051_core.p3_o;
307
always @(p2_out or p3_out)
308
begin
309
  if((p2_out == 8'haa) &&      // fib.c
310
     (p3_out == 8'haa )) begin
311
      $display("################################");
312 4 dinesha
      $display("TEST STATUS : PASSED ");
313 2 dinesha
      $display("################################");
314
      #100
315
      $finish;
316
  end else if(p2_out == 8'h55) begin     // fib.c
317
      $display("");
318
      $display("time ",$time," Error: %h", p3_out);
319 4 dinesha
      $display("TEST STATUS : FAILED ");
320 2 dinesha
      $display("");
321
      #100
322
      $finish;
323
  end
324
end
325
 
326
 
327 29 dinesha
module delay (in, out);
328
  input  in;
329
  output out;
330 2 dinesha
 
331 29 dinesha
  assign out = in;
332 2 dinesha
 
333 29 dinesha
  specify
334
    (in => out) = (600,600);
335
  endspecify
336
endmodule
337
 
338
 
339 2 dinesha
`include "uart_test1.v"
340
`include "spi_test1.v"
341 29 dinesha
`include "i2cm_test1.v"
342 2 dinesha
`include "tb_tasks.v"
343
`include "spi_tasks.v"
344
 
345
 
346
endmodule
347
`include "tb_glbl.v"

powered by: WebSVN 2.1.0

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