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

Subversion Repositories 8051

[/] [8051/] [trunk/] [bench/] [verilog/] [oc8051_tb.v] - Blame information for rev 166

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

powered by: WebSVN 2.1.0

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