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

powered by: WebSVN 2.1.0

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