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

Subversion Repositories 8051

[/] [8051/] [tags/] [rel_12/] [bench/] [verilog/] [oc8051_tb.v] - Blame information for rev 165

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

powered by: WebSVN 2.1.0

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