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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_top.v] - Blame information for rev 107

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

Line No. Rev Author Line
1 72 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 cores top level module                                 ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/8051/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  8051 definitions.                                           ////
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 54 simont
// $Log: not supported by cvs2svn $
47 107 simont
// Revision 1.19  2003/04/02 15:08:30  simont
48
// raname signals.
49
//
50 102 simont
// Revision 1.18  2003/01/13 14:14:41  simont
51
// replace some modules
52
//
53 82 simont
// Revision 1.17  2002/11/05 17:23:54  simont
54
// add module oc8051_sfr, 256 bytes internal ram
55
//
56 76 simont
// Revision 1.16  2002/10/28 14:55:00  simont
57
// fix bug in interface to external data ram
58
//
59 72 simont
// Revision 1.15  2002/10/23 16:53:39  simont
60
// fix bugs in instruction interface
61
//
62 62 simont
// Revision 1.14  2002/10/17 18:50:00  simont
63
// cahnge interface to instruction rom
64
//
65 54 simont
// Revision 1.13  2002/09/30 17:33:59  simont
66
// prepared header
67 72 simont
//
68
//
69
 
70
// synopsys translate_off
71
`include "oc8051_timescale.v"
72
// synopsys translate_on
73
 
74
 
75 102 simont
module oc8051_top (wb_rst_i, wb_clk_i,
76
//interface to instruction rom
77
                wbi_adr_o, wbi_dat_i, wbi_stb_o, wbi_ack_i, wbi_cyc_o, wbi_err_i,
78
//interface to data ram
79
                wbd_dat_i, wbd_dat_o,
80
                wbd_adr_o, wbd_we_o, wbd_ack_i, wbd_stb_o, wbd_cyc_o, wbd_err_i,
81
// interrupt interface
82
                int0_i, int1_i,
83
// external access (active low)
84
                ea_in,
85
// port interface
86
                p0_i, p1_i, p2_i, p3_i,
87
                p0_o, p1_o, p2_o, p3_o,
88
// serial interface
89
                rxd_i, txd_o,
90
// counter interface
91
                t0_i, t1_i, t2_i, t2ex_i);
92 72 simont
 
93
 
94
 
95 102 simont
input         wb_rst_i,         // reset input
96
              wb_clk_i,         // clock input
97
              int0_i,           // interrupt 0
98
              int1_i,           // interrupt 1
99
              ea_in,            // external access
100
              rxd_i,            // receive
101
              t0_i,             // counter 0 input
102
              t1_i,             // counter 1 input
103
              wbd_ack_i,        // data acknowalge
104
              wbi_ack_i,        // instruction acknowlage
105
              wbd_err_i,        // data error
106
              wbi_err_i,        // instruction error
107
              t2_i,             // counter 2 input
108
              t2ex_i;           // ???
109 72 simont
 
110 102 simont
input [7:0]   wbd_dat_i, // ram data input
111
              p0_i,             // port 0 input
112
              p1_i,             // port 1 input
113
              p2_i,             // port 2 input
114
              p3_i;             // port 3 input
115
input [31:0]  wbi_dat_i; // rom data input
116 72 simont
 
117 102 simont
output        wbd_we_o,         // data write enable
118
              txd_o,            // transnmit
119
              wbd_stb_o,        // data strobe
120
              wbd_cyc_o,        // data cycle
121
              wbi_stb_o,        // instruction strobe
122
              wbi_cyc_o;        // instruction cycle
123 82 simont
 
124 102 simont
output [7:0]  wbd_dat_o, // data output
125
              p0_o,             // port 0 output
126
              p1_o,             // port 1 output
127
              p2_o,             // port 2 output
128
              p3_o;             // port 3 output
129
 
130
output [15:0] wbd_adr_o, // data address
131
              wbi_adr_o;        // instruction address
132
 
133
 
134 82 simont
wire [7:0] op1_i, op2_i, op3_i, dptr_hi, dptr_lo, ri, rn_mem, data_out;
135 54 simont
wire [7:0] op1, op2, op3;
136 76 simont
wire [7:0] acc, p0_out, p1_out, p2_out, p3_out;
137 82 simont
wire [7:0] sp, sp_w;
138 72 simont
 
139
wire [15:0] pc;
140
 
141 102 simont
assign wbd_cyc_o = wbd_stb_o;
142 107 simont
//assign wbi_cyc_o = wbi_stb_o;
143 72 simont
 
144
//
145
// ram_rd_sel    ram read (internal)
146
// ram_wr_sel    ram write (internal)
147
// src_sel1, src_sel2    from decoder to register
148 82 simont
wire src_sel3;
149
wire [2:0] ram_rd_sel, ram_wr_sel, wr_sfr;
150
wire [2:0] src_sel2, src_sel1;
151 72 simont
 
152
//
153
// wr_addr       ram write addres
154
// ram_out       data from ram
155
// rd_addr       data ram read addres
156
// rd_addr_r     data ram read addres registerd
157 82 simont
wire [7:0] ram_data, ram_out, sfr_out, wr_dat;
158
wire [7:0] wr_addr, rd_addr;
159 76 simont
wire sfr_bit;
160 72 simont
 
161
 
162
//
163
// cy_sel       carry select; from decoder to cy_selct1
164
// rom_addr_sel rom addres select; alu or pc
165
// ext_adddr_sel        external addres select; data pointer or Ri
166
// write_p      output from decoder; write to external ram, go to register;
167 82 simont
wire [1:0] cy_sel, bank_sel;
168
wire rom_addr_sel, rmw, ea_int;
169 72 simont
 
170
//
171
// int_uart     interrupt from uart
172
// tf0          interrupt from t/c 0
173
// tf1          interrupt from t/c 1
174
// tr0          timer 0 run
175
// tr1          timer 1 run
176 76 simont
wire reti, intr, int_ack, istb;
177 72 simont
wire [7:0] int_src;
178
 
179
//
180
//alu_op        alu operation (from decoder)
181
//psw_set       write to psw or not; from decoder to psw (through register)
182 82 simont
wire mem_wait;
183
wire [2:0] mem_act;
184
wire [3:0] alu_op;
185
wire [1:0] psw_set;
186 72 simont
 
187
//
188
// immediate1_r         from imediate_sel1 to alu_src1_sel1
189
// immediate2_r         from imediate_sel1 to alu_src2_sel1
190
// src1. src2, src2     alu sources
191
// des2, des2           alu destinations
192
// des1_r               destination 1 registerd (to comp1)
193
// desCy                carry out
194
// desAc
195
// desOv                overflow
196 82 simont
// wr                   write to data ram
197
wire [7:0] src1, src2, des1, des2, des1_r;
198
wire [7:0] src3;
199
wire desCy, desAc, desOv, alu_cy, wr, wr_o;
200 72 simont
 
201
 
202
//
203
// rd           read program rom
204
// pc_wr_sel    program counter write select (from decoder to pc)
205
wire rd, pc_wr;
206 82 simont
wire [2:0] pc_wr_sel;
207 72 simont
 
208
//
209
// op1_n                from op_select to decoder
210
// op2_n,         output of op_select, to immediate_sel1, pc1, comp1
211
// op3_n,         output of op_select, to immediate_sel1, ram_wr_sel1
212
// op2_dr,      output of op_select, to ram_rd_sel1, ram_wr_sel1
213 82 simont
wire [7:0] op1_n, op2_n, op3_n;
214 72 simont
 
215
//
216
// comp_sel     select source1 and source2 to compare
217
// eq           result (from comp1 to decoder)
218
wire [1:0] comp_sel;
219 82 simont
wire eq, srcAc, cy, rd_ind, wr_ind;
220
wire [2:0] op1_cur;
221 72 simont
 
222
 
223
//
224
// bit_addr     bit addresable instruction
225
// bit_data     bit data from ram to ram_select
226
// bit_out      bit data from ram_select to alu and cy_select
227 82 simont
wire bit_addr, bit_data, bit_out, bit_addr_o;
228 72 simont
 
229
//
230 107 simont
// cpu to cache/wb_interface
231
wire        iack_i,
232
            istb_o,
233
            icyc_o;
234
wire [31:0] idat_i;
235
wire [15:0] iadr_o;
236 72 simont
 
237
 
238
 
239
//
240
// decoder
241 102 simont
oc8051_decoder oc8051_decoder1(.clk(wb_clk_i), .rst(wb_rst_i), .op_in(op1_n), .op1_c(op1_cur),
242 76 simont
     .ram_rd_sel(ram_rd_sel), .ram_wr_sel(ram_wr_sel), .bit_addr(bit_addr),
243 82 simont
     .src_sel1(src_sel1), .src_sel2(src_sel2),
244 62 simont
     .src_sel3(src_sel3), .alu_op(alu_op), .psw_set(psw_set),
245 82 simont
     .cy_sel(cy_sel), .wr(wr), .pc_wr(pc_wr),
246 76 simont
     .pc_sel(pc_wr_sel), .comp_sel(comp_sel), .eq(eq),
247 82 simont
     .wr_sfr(wr_sfr), .rd(rd), .rmw(rmw),
248
     .istb(istb), .mem_act(mem_act), .mem_wait(mem_wait));
249 72 simont
 
250
 
251
//
252
//alu
253 102 simont
oc8051_alu oc8051_alu1(.rst(wb_rst_i), .clk(wb_clk_i), .op_code(alu_op), .rd(rd),
254 82 simont
     .src1(src1), .src2(src2), .src3(src3), .srcCy(alu_cy), .srcAc(srcAc),
255
     .des1(des1), .des2(des2), .des1_r(des1_r), .desCy(desCy),
256
     .desAc(desAc), .desOv(desOv), .bit_in(bit_out));
257 72 simont
 
258
//
259
//data ram
260 102 simont
oc8051_ram_top oc8051_ram_top1(.clk(wb_clk_i), .rst(wb_rst_i), .rd_addr(rd_addr), .rd_data(ram_data),
261 82 simont
          .wr_addr(wr_addr), .bit_addr(bit_addr_o), .wr_data(wr_dat), .wr(wr_o && (!wr_addr[7] || wr_ind)),
262 72 simont
          .bit_data_in(desCy), .bit_data_out(bit_data));
263
 
264
//
265
 
266 102 simont
oc8051_alu_src_sel oc8051_alu_src_sel1(.clk(wb_clk_i), .rst(wb_rst_i), .rd(rd),
267 82 simont
     .sel1(src_sel1), .sel2(src_sel2), .sel3(src_sel3),
268
     .acc(acc), .ram(ram_out), .pc(pc), .dptr({dptr_hi, dptr_lo}),
269
     .op1(op1_n), .op2(op2_n), .op3(op3_n),
270
     .src1(src1), .src2(src2), .src3(src3));
271
 
272
 
273 72 simont
//
274
//
275 76 simont
oc8051_comp oc8051_comp1(.sel(comp_sel), .eq(eq), .b_in(bit_out), .cy(cy), .acc(acc), .des(des1_r));
276 72 simont
 
277
 
278
//
279
//program rom
280 107 simont
oc8051_rom oc8051_rom1(.rst(wb_rst_i), .clk(wb_clk_i), .ea_int(ea_int), .addr(iadr_o),
281 72 simont
                .data1(op1_i), .data2(op2_i), .data3(op3_i));
282
 
283
//
284
//
285 82 simont
oc8051_cy_select oc8051_cy_select1(.cy_sel(cy_sel), .cy_in(cy), .data_in(bit_out),
286 72 simont
                 .data_out(alu_cy));
287
//
288
//
289 102 simont
oc8051_indi_addr oc8051_indi_addr1 (.clk(wb_clk_i), .rst(wb_rst_i), .rd_addr(rd_addr), .wr_addr(wr_addr),
290 82 simont
      .data_in(wr_dat), .wr(wr_o), .wr_bit(bit_addr_o), .rn_out(rn_mem),
291
      .ri_out(ri), .sel(op1_cur), .bank(bank_sel));
292 72 simont
 
293
 
294 107 simont
 
295
assign icyc_o = istb_o;
296 72 simont
//
297
//
298 102 simont
oc8051_memory_interface oc8051_memory_interface1(.clk(wb_clk_i), .rst(wb_rst_i),
299 107 simont
// internal ram
300 82 simont
   .wr_i(wr), .wr_o(wr_o), .wr_bit_i(bit_addr), .wr_bit_o(bit_addr_o), .wr_dat(wr_dat),
301 107 simont
   .des1(des1), .des2(des2),
302
   .rd_addr(rd_addr), .wr_addr(wr_addr),
303
   .wr_ind(wr_ind),
304
   .bit_in(bit_data), .in_ram(ram_data),
305
   .sfr(sfr_out), .sfr_bit(sfr_bit), .bit_out(bit_out), .iram_out(ram_out),
306 72 simont
 
307 107 simont
// external instrauction rom
308
   .iack_i(iack_i),
309
   .iadr_o(iadr_o),
310
   .idat_i(idat_i),
311
   .istb_o(istb_o),
312 82 simont
 
313 107 simont
// internal instruction rom
314
   .op1_i(op1_i), .op2_i(op2_i), .op3_i(op3_i),
315 82 simont
 
316 107 simont
// data memory
317
   .dadr_o(wbd_adr_o), .ddat_o(wbd_dat_o),
318
   .dwe_o(wbd_we_o), .dstb_o(wbd_stb_o),
319
   .ddat_i(wbd_dat_i), .dack_i(wbd_ack_i),
320
 
321
// from decoder
322
   .rd_sel(ram_rd_sel), .wr_sel(ram_wr_sel), .rn({bank_sel, op1_n[2:0]}),
323
   .rd_ind(rd_ind), .rd(rd),
324
   .mem_act(mem_act), .mem_wait(mem_wait),
325
 
326
// external access
327 102 simont
   .ea(ea_in), .ea_int(ea_int),
328 107 simont
 
329
// instructions outputs to cpu
330 82 simont
   .op1_out(op1_n), .op2_out(op2_n), .op3_out(op3_n),
331
 
332 107 simont
// interrupt interface
333
   .intr(intr), .int_v(int_src), .int_ack(int_ack), .istb(istb),
334
   .reti(reti),
335
 
336 82 simont
//pc
337
   .pc_wr_sel(pc_wr_sel), .pc_wr(pc_wr), .pc(pc),
338
 
339 107 simont
// sfr's
340
   .sp_w(sp_w), .dptr({dptr_hi, dptr_lo}),
341
   .ri(ri), .rn_mem(rn_mem),
342
   .acc(acc), .sp(sp)
343
   );
344 82 simont
 
345 107 simont
 
346 72 simont
//
347
//
348
 
349 102 simont
oc8051_sfr oc8051_sfr1(.rst(wb_rst_i), .clk(wb_clk_i), .adr0(rd_addr[7:0]), .adr1(wr_addr[7:0]),
350 82 simont
       .dat0(sfr_out), .dat1(wr_dat), .dat2(des2), .we(wr_o && !wr_ind), .bit_in(desCy),
351
       .bit_out(sfr_bit), .wr_bit(bit_addr_o), .ram_rd_sel(ram_rd_sel), .ram_wr_sel(ram_wr_sel), .wr_sfr(wr_sfr),
352 76 simont
// acc
353 82 simont
       .acc(acc),
354 76 simont
// sp
355 82 simont
       .sp(sp), .sp_w(sp_w),
356 76 simont
// psw
357 82 simont
       .bank_sel(bank_sel), .desAc(desAc), .desOv(desOv), .psw_set(psw_set),
358 76 simont
       .srcAc(srcAc), .cy(cy),
359
// ports
360 102 simont
       .rmw(rmw), .p0_out(p0_o), .p1_out(p1_o), .p2_out(p2_o), .p3_out(p3_o),
361
       .p0_in(p0_i), .p1_in(p1_i), .p2_in(p2_i), .p3_in(p3_i),
362 76 simont
// uart
363 102 simont
       .rxd(rxd_i), .txd(txd_o),
364 76 simont
// int
365 102 simont
       .int_ack(int_ack), .intr(intr), .int0(int0_i), .int1(int1_i),
366
       .reti(reti), .int_src(int_src),
367 76 simont
// t/c
368 102 simont
       .t0(t0_i), .t1(t1_i), .t2(t2_i), .t2ex(t2ex_i),
369 76 simont
// dptr
370
       .dptr_hi(dptr_hi), .dptr_lo(dptr_lo));
371 72 simont
 
372 82 simont
 
373 107 simont
 
374
 
375
`ifdef OC8051_CACHE
376
 
377
 
378
oc8051_icache oc8051_icache1(.rst(wb_rst_i), .clk(wb_clk_i),
379
// cpu
380
        .adr_i(iadr_o),
381
        .dat_o(idat_i),
382
        .stb_i(istb_o),
383
        .ack_o(iack_i),
384
        .cyc_i(icyc_o),
385
// pins
386
        .dat_i(wbi_dat_i),
387
        .stb_o(wbi_stb_o),
388
        .adr_o(wbi_adr_o),
389
        .ack_i(wbi_ack_i),
390
        .cyc_o(wbi_cyc_o));
391
 
392
defparam oc8051_icache1.ADR_WIDTH = 7;  // cache address wihth
393
defparam oc8051_icache1.LINE_WIDTH = 2; // line address width (2 => 4x32)
394
defparam oc8051_icache1.BL_NUM = 31; // number of blocks (2^BL_WIDTH-1); BL_WIDTH = ADR_WIDTH - LINE_WIDTH
395
defparam oc8051_icache1.CACHE_RAM = 128; // cache ram x 32 (2^ADR_WIDTH)
396
 
397
//
398
//    no cache
399
//
400
`else
401
 
402
oc8051_wb_iinterface oc8051_wb_iinterface(.rst(wb_rst_i), .clk(wb_clk_i),
403
// cpu
404
        .adr_i(iadr_o),
405
        .dat_o(idat_i),
406
        .stb_i(istb_o),
407
        .ack_o(iack_i),
408
        .cyc_i(icyc_o),
409
// external rom
410
        .dat_i(wbi_dat_i),
411
        .stb_o(wbi_stb_o),
412
        .adr_o(wbi_adr_o),
413
        .ack_i(wbi_ack_i),
414
        .cyc_o(wbi_cyc_o));
415
 
416
 
417
`endif
418
 
419
 
420
 
421 72 simont
endmodule

powered by: WebSVN 2.1.0

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