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

Subversion Repositories 8051

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

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 122 simont
// Revision 1.23  2003/04/10 12:43:19  simont
48
// defines for pherypherals added
49
//
50 120 simont
// Revision 1.22  2003/04/09 16:24:04  simont
51
// change wr_sft to 2 bit wire.
52
//
53 118 simont
// Revision 1.21  2003/04/09 15:49:42  simont
54
// Register oc8051_sfr dato output, add signal wait_data.
55
//
56 117 simont
// Revision 1.20  2003/04/03 19:13:28  simont
57
// Include instruction cache.
58
//
59 107 simont
// Revision 1.19  2003/04/02 15:08:30  simont
60
// raname signals.
61
//
62 102 simont
// Revision 1.18  2003/01/13 14:14:41  simont
63
// replace some modules
64
//
65 82 simont
// Revision 1.17  2002/11/05 17:23:54  simont
66
// add module oc8051_sfr, 256 bytes internal ram
67
//
68 76 simont
// Revision 1.16  2002/10/28 14:55:00  simont
69
// fix bug in interface to external data ram
70
//
71 72 simont
// Revision 1.15  2002/10/23 16:53:39  simont
72
// fix bugs in instruction interface
73
//
74 62 simont
// Revision 1.14  2002/10/17 18:50:00  simont
75
// cahnge interface to instruction rom
76
//
77 54 simont
// Revision 1.13  2002/09/30 17:33:59  simont
78
// prepared header
79 72 simont
//
80
//
81
 
82
// synopsys translate_off
83
`include "oc8051_timescale.v"
84
// synopsys translate_on
85
 
86
 
87 102 simont
module oc8051_top (wb_rst_i, wb_clk_i,
88
//interface to instruction rom
89 120 simont
                wbi_adr_o,
90
                wbi_dat_i,
91
                wbi_stb_o,
92
                wbi_ack_i,
93
                wbi_cyc_o,
94
                wbi_err_i,
95
 
96 102 simont
//interface to data ram
97 120 simont
                wbd_dat_i,
98
                wbd_dat_o,
99
                wbd_adr_o,
100
                wbd_we_o,
101
                wbd_ack_i,
102
                wbd_stb_o,
103
                wbd_cyc_o,
104
                wbd_err_i,
105
 
106 102 simont
// interrupt interface
107 120 simont
                int0_i,
108
                int1_i,
109
 
110 102 simont
// external access (active low)
111
                ea_in,
112 120 simont
 
113 102 simont
// port interface
114 120 simont
  `ifdef OC8051_PORTS
115
        `ifdef OC8051_PORT0
116
                p0_i,
117
                p0_o,
118
        `endif
119
 
120
        `ifdef OC8051_PORT1
121
                p1_i,
122
                p1_o,
123
        `endif
124
 
125
        `ifdef OC8051_PORT2
126
                p2_i,
127
                p2_o,
128
        `endif
129
 
130
        `ifdef OC8051_PORT3
131
                p3_i,
132
                p3_o,
133
        `endif
134
  `endif
135
 
136 102 simont
// serial interface
137 120 simont
        `ifdef OC8051_UART
138 102 simont
                rxd_i, txd_o,
139 120 simont
        `endif
140
 
141 102 simont
// counter interface
142 120 simont
        `ifdef OC8051_TC01
143
                t0_i, t1_i,
144
        `endif
145 72 simont
 
146 120 simont
        `ifdef OC8051_TC2
147
                t2_i, t2ex_i
148
        `endif
149
                );
150 72 simont
 
151
 
152 120 simont
 
153 102 simont
input         wb_rst_i,         // reset input
154
              wb_clk_i,         // clock input
155
              int0_i,           // interrupt 0
156
              int1_i,           // interrupt 1
157
              ea_in,            // external access
158
              wbd_ack_i,        // data acknowalge
159
              wbi_ack_i,        // instruction acknowlage
160
              wbd_err_i,        // data error
161 120 simont
              wbi_err_i;        // instruction error
162 72 simont
 
163 120 simont
input [7:0]   wbd_dat_i; // ram data input
164 102 simont
input [31:0]  wbi_dat_i; // rom data input
165 72 simont
 
166 102 simont
output        wbd_we_o,         // data write enable
167
              wbd_stb_o,        // data strobe
168
              wbd_cyc_o,        // data cycle
169
              wbi_stb_o,        // instruction strobe
170
              wbi_cyc_o;        // instruction cycle
171 82 simont
 
172 120 simont
output [7:0]  wbd_dat_o; // data output
173 102 simont
 
174
output [15:0] wbd_adr_o, // data address
175
              wbi_adr_o;        // instruction address
176
 
177 120 simont
`ifdef OC8051_PORTS
178 102 simont
 
179 120 simont
`ifdef OC8051_PORT0
180
input  [7:0]  p0_i;              // port 0 input
181
output [7:0]  p0_o;              // port 0 output
182
`endif
183 72 simont
 
184 120 simont
`ifdef OC8051_PORT1
185
input  [7:0]  p1_i;              // port 1 input
186
output [7:0]  p1_o;              // port 1 output
187
`endif
188 72 simont
 
189 120 simont
`ifdef OC8051_PORT2
190
input  [7:0]  p2_i;              // port 2 input
191
output [7:0]  p2_o;              // port 2 output
192
`endif
193 72 simont
 
194 120 simont
`ifdef OC8051_PORT3
195
input  [7:0]  p3_i;              // port 3 input
196
output [7:0]  p3_o;              // port 3 output
197
`endif
198 72 simont
 
199 120 simont
`endif
200 72 simont
 
201
 
202
 
203
 
204
 
205
 
206 120 simont
`ifdef OC8051_UART
207
input         rxd_i;            // receive
208
output        txd_o;            // transnmit
209
`endif
210 72 simont
 
211 120 simont
`ifdef OC8051_TC01
212
input         t0_i,             // counter 0 input
213
              t1_i;             // counter 1 input
214
`endif
215 72 simont
 
216 120 simont
`ifdef OC8051_TC2
217
input         t2_i,             // counter 2 input
218
              t2ex_i;           //
219
`endif
220 72 simont
 
221 120 simont
wire [7:0]  op1_i,
222
            op2_i,
223
            op3_i,
224
            dptr_hi,
225
            dptr_lo,
226
            ri,
227
            rn_mem,
228
            data_out,
229
            op1,
230
            op2,
231
            op3,
232
            acc,
233
            p0_out,
234
            p1_out,
235
            p2_out,
236
            p3_out,
237
            sp,
238
            sp_w;
239 72 simont
 
240 120 simont
wire [15:0] pc;
241 72 simont
 
242 120 simont
assign wbd_cyc_o = wbd_stb_o;
243 72 simont
 
244 120 simont
wire        src_sel3;
245
wire [1:0]  wr_sfr;
246
wire [2:0]  ram_rd_sel,  // ram read
247
            ram_wr_sel, // ram write
248
            src_sel2,
249
            src_sel1;
250
 
251
wire [7:0]  ram_data,
252
            ram_out,    //data from ram
253
            sfr_out,
254
            wr_dat,
255
            wr_addr,    //ram write addres
256
            rd_addr;    //data ram read addres
257
wire        sfr_bit;
258
 
259
wire [1:0]  cy_sel,      //carry select; from decoder to cy_selct1
260
            bank_sel;
261
wire        rom_addr_sel,       //rom addres select; alu or pc
262
            rmw,
263
            ea_int;
264
 
265
wire        reti,
266
            intr,
267
            int_ack,
268
            istb;
269
wire [7:0]  int_src;
270
 
271
wire        mem_wait;
272
wire [2:0]  mem_act;
273
wire [3:0]  alu_op;      //alu operation (from decoder)
274
wire [1:0]  psw_set;    //write to psw or not; from decoder to psw (through register)
275
 
276
wire [7:0]  src1,        //alu sources 1
277
            src2,       //alu sources 2
278
            src3,       //alu sources 3
279
            des1,       //alu destination 1
280
            des2,       //alu destinations 2
281
            des1_r;     //destination 1 registerd (to comp1)
282
wire        desCy,      //carry out
283
            desAc,
284
            desOv,      //overflow
285
            alu_cy,
286
            wr,         //write to data ram
287
            wr_o;
288
 
289
wire        rd,         //read program rom
290
            pc_wr;
291
wire [2:0]  pc_wr_sel;   //program counter write select (from decoder to pc)
292
 
293
wire [7:0]  op1_n, //from memory_interface to decoder
294
            op2_n,
295
            op3_n;
296
 
297
wire [1:0]  comp_sel;    //select source1 and source2 to compare
298
wire        eq,         //result (from comp1 to decoder)
299
            srcAc,
300
            cy,
301
            rd_ind,
302
            wr_ind;
303
wire [2:0]  op1_cur;
304
 
305
wire        bit_addr,   //bit addresable instruction
306
            bit_data,   //bit data from ram to ram_select
307
            bit_out,    //bit data from ram_select to alu and cy_select
308
            bit_addr_o,
309
            wait_data;
310
 
311 72 simont
//
312 107 simont
// cpu to cache/wb_interface
313
wire        iack_i,
314
            istb_o,
315
            icyc_o;
316
wire [31:0] idat_i;
317
wire [15:0] iadr_o;
318 72 simont
 
319
 
320
//
321
// decoder
322 120 simont
oc8051_decoder oc8051_decoder1(.clk(wb_clk_i),
323
                               .rst(wb_rst_i),
324
                               .op_in(op1_n),
325
                               .op1_c(op1_cur),
326
                               .ram_rd_sel_o(ram_rd_sel),
327
                               .ram_wr_sel_o(ram_wr_sel),
328
                               .bit_addr(bit_addr),
329 72 simont
 
330 120 simont
                               .src_sel1(src_sel1),
331
                               .src_sel2(src_sel2),
332
                               .src_sel3(src_sel3),
333 72 simont
 
334 120 simont
                               .alu_op_o(alu_op),
335
                               .psw_set(psw_set),
336
                               .cy_sel(cy_sel),
337
                               .wr_o(wr),
338
                               .pc_wr(pc_wr),
339
                               .pc_sel(pc_wr_sel),
340
                               .comp_sel(comp_sel),
341
                               .eq(eq),
342
                               .wr_sfr_o(wr_sfr),
343
                               .rd(rd),
344
                               .rmw(rmw),
345
                               .istb(istb),
346
                               .mem_act(mem_act),
347
                               .mem_wait(mem_wait),
348
                               .wait_data(wait_data));
349
 
350
 
351 72 simont
//
352
//alu
353 120 simont
oc8051_alu oc8051_alu1(.rst(wb_rst_i),
354
                       .clk(wb_clk_i),
355
                       .op_code(alu_op),
356
                       .rd(rd),
357
                       .src1(src1),
358
                       .src2(src2),
359
                       .src3(src3),
360
                       .srcCy(alu_cy),
361
                       .srcAc(srcAc),
362
                       .des1(des1),
363
                       .des2(des2),
364
                       .des1_r(des1_r),
365
                       .desCy(desCy),
366
                       .desAc(desAc),
367
                       .desOv(desOv),
368
                       .bit_in(bit_out));
369 72 simont
 
370
//
371
//data ram
372 120 simont
oc8051_ram_top oc8051_ram_top1(.clk(wb_clk_i),
373
                               .rst(wb_rst_i),
374
                               .rd_addr(rd_addr),
375
                               .rd_data(ram_data),
376
                               .wr_addr(wr_addr),
377
                               .bit_addr(bit_addr_o),
378
                               .wr_data(wr_dat),
379
                               .wr(wr_o && (!wr_addr[7] || wr_ind)),
380
                               .bit_data_in(desCy),
381
                               .bit_data_out(bit_data));
382 72 simont
 
383
//
384
 
385 120 simont
oc8051_alu_src_sel oc8051_alu_src_sel1(.clk(wb_clk_i),
386
                                       .rst(wb_rst_i),
387
                                       .rd(rd),
388 82 simont
 
389 120 simont
                                       .sel1(src_sel1),
390
                                       .sel2(src_sel2),
391
                                       .sel3(src_sel3),
392 82 simont
 
393 120 simont
                                       .acc(acc),
394
                                       .ram(ram_out),
395
                                       .pc(pc),
396
                                       .dptr({dptr_hi, dptr_lo}),
397
                                       .op1(op1_n),
398
                                       .op2(op2_n),
399
                                       .op3(op3_n),
400
 
401
                                       .src1(src1),
402
                                       .src2(src2),
403
                                       .src3(src3));
404
 
405
 
406 72 simont
//
407
//
408 120 simont
oc8051_comp oc8051_comp1(.sel(comp_sel),
409
                         .eq(eq),
410
                         .b_in(bit_out),
411
                         .cy(cy),
412
                         .acc(acc),
413
                         .des(des1_r));
414 72 simont
 
415
 
416
//
417
//program rom
418 122 simont
`ifdef OC8051_ROM
419
  oc8051_rom oc8051_rom1(.rst(wb_rst_i),
420
                       .clk(wb_clk_i),
421
                       .ea_int(ea_int),
422 120 simont
                       .addr(iadr_o),
423 122 simont
                       .data1(op1_i),
424
                       .data2(op2_i),
425 120 simont
                       .data3(op3_i));
426 122 simont
`else
427
  assign ea_int = 1'b0;
428
  assign op1_i = 8'h00;
429
  assign op2_i = 8'h00;
430
  assign op3_i = 8'h00;
431
`endif
432 72 simont
 
433
//
434
//
435 120 simont
oc8051_cy_select oc8051_cy_select1(.cy_sel(cy_sel),
436
                                   .cy_in(cy),
437
                                   .data_in(bit_out),
438
                                   .data_out(alu_cy));
439 72 simont
//
440
//
441 120 simont
oc8051_indi_addr oc8051_indi_addr1 (.clk(wb_clk_i),
442
                                    .rst(wb_rst_i),
443
                                    .rd_addr(rd_addr),
444
                                    .wr_addr(wr_addr),
445
                                    .data_in(wr_dat),
446
                                    .wr(wr_o),
447
                                    .wr_bit(bit_addr_o),
448
                                    .rn_out(rn_mem),
449
                                    .ri_out(ri),
450
                                    .sel(op1_cur),
451
                                    .bank(bank_sel));
452 72 simont
 
453
 
454 107 simont
 
455
assign icyc_o = istb_o;
456 72 simont
//
457
//
458 120 simont
oc8051_memory_interface oc8051_memory_interface1(.clk(wb_clk_i),
459
                       .rst(wb_rst_i),
460 107 simont
// internal ram
461 120 simont
                       .wr_i(wr),
462
                       .wr_o(wr_o),
463
                       .wr_bit_i(bit_addr),
464
                       .wr_bit_o(bit_addr_o),
465
                       .wr_dat(wr_dat),
466
                       .des1(des1),
467
                       .des2(des2),
468
                       .rd_addr(rd_addr),
469
                       .wr_addr(wr_addr),
470
                       .wr_ind(wr_ind),
471
                       .bit_in(bit_data),
472
                       .in_ram(ram_data),
473
                       .sfr(sfr_out),
474
                       .sfr_bit(sfr_bit),
475
                       .bit_out(bit_out),
476
                       .iram_out(ram_out),
477 72 simont
 
478 107 simont
// external instrauction rom
479 120 simont
                       .iack_i(iack_i),
480
                       .iadr_o(iadr_o),
481
                       .idat_i(idat_i),
482
                       .istb_o(istb_o),
483 82 simont
 
484 107 simont
// internal instruction rom
485 120 simont
                       .op1_i(op1_i),
486
                       .op2_i(op2_i),
487
                       .op3_i(op3_i),
488 82 simont
 
489 107 simont
// data memory
490 120 simont
                       .dadr_o(wbd_adr_o),
491
                       .ddat_o(wbd_dat_o),
492
                       .dwe_o(wbd_we_o),
493
                       .dstb_o(wbd_stb_o),
494
                       .ddat_i(wbd_dat_i),
495
                       .dack_i(wbd_ack_i),
496 107 simont
 
497
// from decoder
498 120 simont
                       .rd_sel(ram_rd_sel),
499
                       .wr_sel(ram_wr_sel),
500
                       .rn({bank_sel, op1_n[2:0]}),
501
                       .rd_ind(rd_ind),
502
                       .rd(rd),
503
                       .mem_act(mem_act),
504
                       .mem_wait(mem_wait),
505 107 simont
 
506
// external access
507 120 simont
                       .ea(ea_in),
508
                       .ea_int(ea_int),
509 107 simont
 
510
// instructions outputs to cpu
511 120 simont
                       .op1_out(op1_n),
512
                       .op2_out(op2_n),
513
                       .op3_out(op3_n),
514 82 simont
 
515 107 simont
// interrupt interface
516 120 simont
                       .intr(intr),
517
                       .int_v(int_src),
518
                       .int_ack(int_ack),
519
                       .istb(istb),
520
                       .reti(reti),
521 107 simont
 
522 82 simont
//pc
523 120 simont
                       .pc_wr_sel(pc_wr_sel),
524
                       .pc_wr(pc_wr),
525
                       .pc(pc),
526 82 simont
 
527 107 simont
// sfr's
528 120 simont
                       .sp_w(sp_w),
529
                       .dptr({dptr_hi, dptr_lo}),
530
                       .ri(ri),
531
                       .rn_mem(rn_mem),
532
                       .acc(acc),
533
                       .sp(sp)
534
                       );
535 82 simont
 
536 107 simont
 
537 72 simont
//
538
//
539
 
540 120 simont
oc8051_sfr oc8051_sfr1(.rst(wb_rst_i),
541
                       .clk(wb_clk_i),
542
                       .adr0(rd_addr[7:0]),
543
                       .adr1(wr_addr[7:0]),
544
                       .dat0(sfr_out),
545
                       .dat1(wr_dat),
546
                       .dat2(des2),
547
                       .we(wr_o && !wr_ind),
548
                       .bit_in(desCy),
549
                       .bit_out(sfr_bit),
550
                       .wr_bit(bit_addr_o),
551
                       .ram_rd_sel(ram_rd_sel),
552
                       .ram_wr_sel(ram_wr_sel),
553
                       .wr_sfr(wr_sfr),
554 76 simont
// acc
555 120 simont
                       .acc(acc),
556 76 simont
// sp
557 120 simont
                       .sp(sp),
558
                       .sp_w(sp_w),
559 76 simont
// psw
560 120 simont
                       .bank_sel(bank_sel),
561
                       .desAc(desAc),
562
                       .desOv(desOv),
563
                       .psw_set(psw_set),
564
                       .srcAc(srcAc),
565
                       .cy(cy),
566 76 simont
// ports
567 120 simont
                       .rmw(rmw),
568
 
569
  `ifdef OC8051_PORTS
570
        `ifdef OC8051_PORT0
571
                       .p0_out(p0_o),
572
                       .p0_in(p0_i),
573
        `endif
574
 
575
        `ifdef OC8051_PORT1
576
                       .p1_out(p1_o),
577
                       .p1_in(p1_i),
578
        `endif
579
 
580
        `ifdef OC8051_PORT2
581
                       .p2_out(p2_o),
582
                       .p2_in(p2_i),
583
        `endif
584
 
585
        `ifdef OC8051_PORT3
586
                       .p3_out(p3_o),
587
                       .p3_in(p3_i),
588
        `endif
589
  `endif
590
 
591 76 simont
// uart
592 120 simont
        `ifdef OC8051_UART
593
                       .rxd(rxd_i), .txd(txd_o),
594
        `endif
595
 
596 76 simont
// int
597 120 simont
                       .int_ack(int_ack),
598
                       .intr(intr),
599
                       .int0(int0_i),
600
                       .int1(int1_i),
601
                       .reti(reti),
602
                       .int_src(int_src),
603
 
604
// t/c 0,1
605
        `ifdef OC8051_TC01
606
                       .t0(t0_i),
607
                       .t1(t1_i),
608
        `endif
609
 
610
// t/c 2
611
        `ifdef OC8051_TC2
612
                       .t2(t2_i),
613
                       .t2ex(t2ex_i),
614
        `endif
615
 
616 76 simont
// dptr
617 120 simont
                       .dptr_hi(dptr_hi),
618
                       .dptr_lo(dptr_lo),
619
                       .wait_data(wait_data)
620
                       );
621 72 simont
 
622 82 simont
 
623 107 simont
 
624
 
625
`ifdef OC8051_CACHE
626
 
627
 
628
oc8051_icache oc8051_icache1(.rst(wb_rst_i), .clk(wb_clk_i),
629
// cpu
630
        .adr_i(iadr_o),
631
        .dat_o(idat_i),
632
        .stb_i(istb_o),
633
        .ack_o(iack_i),
634
        .cyc_i(icyc_o),
635
// pins
636
        .dat_i(wbi_dat_i),
637
        .stb_o(wbi_stb_o),
638
        .adr_o(wbi_adr_o),
639
        .ack_i(wbi_ack_i),
640
        .cyc_o(wbi_cyc_o));
641
 
642
defparam oc8051_icache1.ADR_WIDTH = 7;  // cache address wihth
643
defparam oc8051_icache1.LINE_WIDTH = 2; // line address width (2 => 4x32)
644
defparam oc8051_icache1.BL_NUM = 31; // number of blocks (2^BL_WIDTH-1); BL_WIDTH = ADR_WIDTH - LINE_WIDTH
645
defparam oc8051_icache1.CACHE_RAM = 128; // cache ram x 32 (2^ADR_WIDTH)
646
 
647
//
648
//    no cache
649
//
650
`else
651
 
652
oc8051_wb_iinterface oc8051_wb_iinterface(.rst(wb_rst_i), .clk(wb_clk_i),
653
// cpu
654
        .adr_i(iadr_o),
655
        .dat_o(idat_i),
656
        .stb_i(istb_o),
657
        .ack_o(iack_i),
658
        .cyc_i(icyc_o),
659
// external rom
660
        .dat_i(wbi_dat_i),
661
        .stb_o(wbi_stb_o),
662
        .adr_o(wbi_adr_o),
663
        .ack_i(wbi_ack_i),
664
        .cyc_o(wbi_cyc_o));
665
 
666
 
667
`endif
668
 
669
 
670
 
671 72 simont
endmodule

powered by: WebSVN 2.1.0

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