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

Subversion Repositories 8051

[/] [8051/] [tags/] [rel_1/] [bench/] [verilog/] [oc8051_tb.v] - Blame information for rev 186

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 68 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 top level test bench                                   ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/8051/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////   top level test bench.                                      ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   nothing                                                    ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Simon Teran, simont@opencores.org                     ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
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
// CVS Revision History
45
//
46 59 simont
// $Log: not supported by cvs2svn $
47 124 simont
// Revision 1.11  2003/04/10 12:45:06  simont
48
// defines for pherypherals added
49
//
50 120 simont
// Revision 1.10  2003/04/03 19:20:55  simont
51
// Remove instruction cache and wb_interface
52
//
53 111 simont
// Revision 1.9  2003/04/02 15:08:59  simont
54
// rename signals
55
//
56 103 simont
// Revision 1.8  2003/01/13 14:35:25  simont
57
// remove wb_bus_mon
58
//
59 84 simont
// Revision 1.7  2002/10/28 16:43:12  simont
60
// add module oc8051_wb_iinterface
61
//
62 74 simont
// Revision 1.6  2002/10/24 13:36:53  simont
63
// add instruction cache and DELAY parameters for external ram, rom
64
//
65 68 simont
// Revision 1.5  2002/10/17 19:00:50  simont
66
// add external rom
67
//
68 59 simont
// Revision 1.4  2002/09/30 17:33:58  simont
69
// prepared header
70 68 simont
//
71
//
72
 
73
// synopsys translate_off
74
`include "oc8051_timescale.v"
75
// synopsys translate_on
76
 
77
`include "oc8051_defines.v"
78
 
79
 
80
module oc8051_tb;
81
 
82 103 simont
reg  rst, clk;
83
reg  [7:0] p0_in, p1_in, p2_in;
84 68 simont
wire [15:0] ext_addr, iadr_o;
85 84 simont
wire write, write_xram, write_uart, txd, rxd, int_uart, int0, int1, t0, t1, bit_out, stb_o, ack_i;
86
wire ack_xram, ack_uart, cyc_o, iack_i, istb_o, icyc_o, t2, t2ex;
87 68 simont
wire [7:0] data_in, data_out, p0_out, p1_out, p2_out, p3_out, data_out_uart, data_out_xram, p3_in;
88 103 simont
wire wbi_err_i, wbd_err_i;
89 68 simont
 
90 124 simont
`ifdef OC8051_XILINX_RAMB
91
  reg  [31:0] idat_i;
92
`else
93
  wire [31:0] idat_i;
94
`endif
95 84 simont
 
96 68 simont
///
97
/// buffer for test vectors
98
///
99
//
100
// buffer
101 103 simont
reg [23:0] buff [0:255];
102
reg ea [0:1];
103 68 simont
 
104
integer num;
105
 
106 103 simont
assign wbd_err_i = 1'b0;
107
assign wbi_err_i = 1'b0;
108 68 simont
 
109
//
110
// oc8051 controller
111
//
112 103 simont
oc8051_top oc8051_top_1(.wb_rst_i(rst), .wb_clk_i(clk),
113
         .int0_i(int0), .int1_i(int1),
114 68 simont
 
115 103 simont
         .wbd_dat_i(data_in), .wbd_we_o(write), .wbd_dat_o(data_out),
116
         .wbd_adr_o(ext_addr), .wbd_err_i(wbd_err_i),
117
         .wbd_ack_i(ack_i), .wbd_stb_o(stb_o), .wbd_cyc_o(cyc_o),
118 68 simont
 
119 103 simont
         .wbi_adr_o(iadr_o), .wbi_stb_o(istb_o), .wbi_ack_i(iack_i),
120
         .wbi_cyc_o(icyc_o), .wbi_dat_i(idat_i), .wbi_err_i(wbi_err_i),
121
 
122 120 simont
  `ifdef OC8051_PORTS
123 103 simont
 
124 120 simont
   `ifdef OC8051_PORT0
125
         .p0_i(p0_in),
126
         .p0_o(p0_out),
127
   `endif
128
 
129
   `ifdef OC8051_PORT1
130
         .p1_i(p1_in),
131
         .p1_o(p1_out),
132
   `endif
133
 
134
   `ifdef OC8051_PORT2
135
         .p2_i(p2_in),
136
         .p2_o(p2_out),
137
   `endif
138
 
139
   `ifdef OC8051_PORT3
140
         .p3_i(p3_in),
141
         .p3_o(p3_out),
142
   `endif
143
  `endif
144
 
145
 
146
   `ifdef OC8051_UART
147 103 simont
         .rxd_i(rxd), .txd_o(txd),
148 120 simont
   `endif
149 103 simont
 
150 120 simont
   `ifdef OC8051_TC01
151
         .t0_i(t0), .t1_i(t1),
152
   `endif
153 103 simont
 
154 120 simont
   `ifdef OC8051_TC2
155
         .t2_i(t2), .t2ex_i(t2ex),
156
   `endif
157
 
158
         .ea_in(ea[0]));
159
 
160
 
161 68 simont
//
162
// external data ram
163
//
164
oc8051_xram oc8051_xram1 (.clk(clk), .rst(rst), .wr(write_xram), .addr(ext_addr), .data_in(data_out), .data_out(data_out_xram), .ack(ack_xram), .stb(stb_o));
165
 
166
 
167
defparam oc8051_xram1.DELAY = 2;
168
 
169
//
170
// external uart
171
//
172
oc8051_uart_test oc8051_uart_test1(.clk(clk), .rst(rst), .addr(ext_addr[7:0]), .wr(write_uart),
173
                  .wr_bit(p3_out[0]), .data_in(data_out), .data_out(data_out_uart), .bit_out(bit_out), .rxd(txd),
174
                  .txd(rxd), .ow(p3_out[1]), .intr(int_uart), .stb(stb_o), .ack(ack_uart));
175
 
176 124 simont
 
177
 
178
`ifdef OC8051_XILINX_RAMB
179
 
180
`include "oc8051_rom_values.v"
181
 
182 68 simont
//
183
// exteranl program rom
184
//
185 124 simont
//
186
// rom 0
187
//
188
wire [11:0] adr0, adr1;
189
wire [15:0] dat0, dat1;
190 68 simont
 
191 124 simont
assign adr0 = iadr_o[13:2] + {11'h0, iadr_o[1]};
192
assign adr1 = iadr_o[13:2];
193 74 simont
 
194 124 simont
rom_8kx16_top rom_8kx16_top_0
195
(
196
  // WISHBONE slave
197
  .wb_clk_i(clk),
198
  .wb_rst_i(rst),
199
  .wb_dat_i(16'h0),
200
  .wb_dat_o(dat0),
201 74 simont
 
202 124 simont
  .wb_adr_i(adr0),
203
  .wb_sel_i(2'b11),
204
  .wb_we_i(1'b0),
205
  .wb_cyc_i(icyc_o),
206
  .wb_stb_i(istb_o),
207
  .wb_ack_o(iack_i),
208
  .wb_err_o(wbi_err_i)
209
);
210
 
211
rom_8kx16_top rom_8kx16_top_1
212
(
213
  // WISHBONE slave
214
  .wb_clk_i(clk),
215
  .wb_rst_i(rst),
216
  .wb_dat_i(16'h0),
217
  .wb_dat_o(dat1),
218
 
219
  .wb_adr_i(adr1),
220
  .wb_sel_i(2'b11),
221
  .wb_we_i(1'b0),
222
  .wb_cyc_i(icyc_o),
223
  .wb_stb_i(istb_o),
224
  .wb_ack_o(iack_i),
225
  .wb_err_o(wbi_err_i)
226
);
227
 
228
defparam  rom_8kx16_top_0.awidth = 12;
229
defparam  rom_8kx16_top_1.awidth = 12;
230
 
231
always @(iadr_o[1:0] or dat0 or dat1)
232
begin
233
  case (iadr_o[1:0])
234
    2'b00: idat_i = {8'h0, dat1[7:0], dat0};
235
    2'b01: idat_i = {8'h0, dat1, dat0[15:8]};
236
    2'b10: idat_i = {8'h0, dat0[7:0], dat1};
237
    default: idat_i = {8'h0, dat0, dat1[15:8]};
238
  endcase
239
end
240
 
241
`else
242
 
243
  oc8051_xrom oc8051_xrom1(.rst(rst), .clk(clk), .addr(iadr_o), .data(idat_i),
244
               .stb_i(istb_o), .cyc_i(icyc_o), .ack_o(iack_i));
245
 
246
   defparam oc8051_xrom1.DELAY = 5;
247
 
248
`endif
249 68 simont
//
250
//
251
//
252 59 simont
 
253
 
254 124 simont
 
255 74 simont
//
256
// test wb interface
257
//
258 84 simont
 
259 74 simont
reg [31:0] log_file;
260 59 simont
 
261 74 simont
initial
262
begin
263
  log_file = $fopen("log_file");
264
  $fdisplay(log_file, "file open");
265
end
266 68 simont
 
267 74 simont
 
268 68 simont
assign write_xram = p3_out[7] & write;
269
assign write_uart = !p3_out[7] & write;
270
assign data_in = p3_out[7] ? data_out_xram : data_out_uart;
271
assign ack_i = p3_out[7] ? ack_xram : ack_uart;
272 84 simont
assign p3_in = {6'h0, bit_out, int_uart};
273 68 simont
assign t0 = p3_out[5];
274
assign t1 = p3_out[6];
275
 
276
assign int0 = p3_out[3];
277
assign int1 = p3_out[4];
278 84 simont
assign t2 = p3_out[5];
279
assign t2ex = p3_out[2];
280 68 simont
 
281
initial begin
282
  rst= 1'b1;
283
  p0_in = 8'h00;
284
  p1_in = 8'h00;
285
  p2_in = 8'h00;
286 103 simont
#220
287 68 simont
  rst = 1'b0;
288
 
289 111 simont
#40000000
290 74 simont
  $fclose(log_file);
291 68 simont
  $display("time ",$time, "\n faulire: end of time\n \n");
292
  $finish;
293
end
294
 
295
 
296 103 simont
initial
297
begin
298
  clk = 0;
299 111 simont
  forever #30 clk <= ~clk;
300 103 simont
end
301 68 simont
 
302
 
303
 
304
initial
305 103 simont
  $readmemh("../../../bench/vec/oc8051_test.vec", buff);
306 68 simont
 
307
initial
308
  $readmemb("../oc8051_ea.in", ea);
309
 
310
 
311
initial num= 0;
312
 
313
always @(p0_out or p1_out or p2_out)
314
begin
315
  if ({p0_out, p1_out, p2_out} != buff[num])
316
  begin
317
    $display("time ",$time, " faulire: mismatch on ports in step %d", num);
318
    $display(" p0_out %h", p0_out, " p1_out %h", p1_out, " p2_out %h", p2_out);
319
    $display(" testvecp %h", buff[num]);
320
    $display(" p_out   %h%h%h", p0_out, p1_out, p2_out);
321
#22
322 74 simont
    $fclose(log_file);
323 68 simont
    $finish;
324
  end
325
  else begin
326
    $display("time ",$time, " step %d", num, ": pass");
327
    num =  num+1;
328
    if (buff[num]===24'hxxxxxx)
329
    begin
330
      $display("");
331
      $display(" Done!");
332 74 simont
      $fclose(log_file);
333 68 simont
      $finish;
334
    end
335
  end
336
end
337
 
338
 
339
initial $dumpvars;
340
 
341
 
342
endmodule

powered by: WebSVN 2.1.0

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