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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_sfr.v] - Blame information for rev 116

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

Line No. Rev Author Line
1 75 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 cores sfr 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
////   special function registers for oc8051                      ////
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
// $Log: not supported by cvs2svn $
47 116 simont
// Revision 1.6  2003/04/07 13:29:16  simont
48
// change uart to meet timing.
49
//
50 115 simont
// Revision 1.5  2003/04/04 10:35:07  simont
51
// signal prsc_ow added.
52
//
53 113 simont
// Revision 1.4  2003/03/28 17:45:57  simont
54
// change module name.
55
//
56 90 simont
// Revision 1.3  2003/01/21 13:51:30  simont
57
// add include oc8051_defines.v
58
//
59 87 simont
// Revision 1.2  2003/01/13 14:14:41  simont
60
// replace some modules
61
//
62 82 simont
// Revision 1.1  2002/11/05 17:22:27  simont
63
// initial import
64 75 simont
//
65 82 simont
//
66 75 simont
 
67
// synopsys translate_off
68
`include "oc8051_timescale.v"
69
// synopsys translate_on
70
 
71 87 simont
`include "oc8051_defines.v"
72 75 simont
 
73 87 simont
 
74 82 simont
module oc8051_sfr (rst, clk, adr0, adr1, dat0, dat1, dat2, we, bit_in, bit_out, wr_bit,
75
       wr_sfr, acc, ram_wr_sel, ram_rd_sel, sp, sp_w, bank_sel, desAc, desOv, psw_set, srcAc, cy, rmw,
76
       p0_out, p1_out, p2_out, p3_out, p0_in, p1_in, p2_in, p3_in, rxd, txd, int_ack, intr, int0,
77
       int1, reti, int_src, t0, t1, dptr_hi, dptr_lo, t2, t2ex);
78 75 simont
//
79
// rst           (in)  reset - pin
80
// clk           (in)  clock - pin
81
// adr0, adr1    (in)  address input
82
// dat0          (out) data output
83
// dat1          (in)  data input
84
// dat2
85
// we            (in)  write enable
86
// bit_in
87
// bit_out
88
// wr_bit
89
// ram_rd_sel
90
// ram_wr_sel
91 82 simont
// wr_sfr
92 75 simont
//////////
93
//
94
//  acc:
95
// acc
96
//////////
97
//
98
//  sp:
99
// sp
100
//////////
101
//
102
//  psw:
103
// bank_sel
104
// desAc
105
// desOv
106
// psw_set
107
// srcAc
108
// cy
109
//////////
110
//
111
//  ports:
112
// rmw
113
// px_out
114
// px_in
115
//////////
116
//
117
//  serial interface:
118
// rxd
119
// txd
120
//////////
121
//
122
//  interrupt interface:
123
// int_ack
124
// intr
125
// int0, int1
126
// reti
127
// int_src
128
//////////
129
//
130
//  timers/counters:
131
// t0
132
// t1
133 82 simont
// t2
134
// t2ex
135 75 simont
//
136
//////////
137
//
138
//  dptr:
139
// dptr_hi
140
// dptr_lo
141 82 simont
//
142
//////////
143
//
144 75 simont
 
145
 
146
 
147
 
148 82 simont
input rst, clk, we, bit_in, desAc, desOv, rmw, rxd, t2, t2ex;
149
input int_ack, int0, int1, reti, wr_bit, t0, t1;
150
input [1:0] psw_set;
151
input [2:0] ram_rd_sel, ram_wr_sel, wr_sfr;
152
input [7:0] adr0, adr1, dat1, dat2, p0_in, p1_in, p2_in, p3_in;
153 75 simont
 
154 82 simont
output bit_out, txd, intr, srcAc, cy;
155
output [1:0] bank_sel;
156
output [7:0] dat0, p0_out, p1_out, p2_out, p3_out, int_src, dptr_hi, dptr_lo, acc;
157
output [7:0] sp, sp_w;
158 75 simont
 
159 82 simont
 
160 75 simont
reg bit_out;
161 82 simont
reg [7:0] dat0, adr0_r;
162 75 simont
 
163 82 simont
reg wr_bit_r;
164 75 simont
reg [2:0] ram_wr_sel_r;
165 116 simont
 
166
//sfr's
167
wire acc_bit, b_bit, psw_bit, port_bit, uart_bit, int_bit, tc2_bit;
168
 
169 75 simont
wire p, int_uart, tf0, tf1, tr0, tr1;
170 116 simont
wire rclk, tclk, brate2, tc2_int;
171 75 simont
 
172 116 simont
wire [7:0] b_reg, psw,
173
//ports
174
          p0_data, p1_data, p2_data, p3_data,
175
//interrupt control
176
          ie, tcon, ip,
177
// t/c 2
178
          t2con, tl2, th2, rcap2l, rcap2h,
179
// t/c 0,1
180
          tmod, tl0, th0, tl1, th1,
181
// serial interface
182
          scon, pcon, sbuf,
183
// stack
184
          sp_out;
185
 
186 113 simont
wire pres_ow;
187 82 simont
 
188 75 simont
assign cy = psw[7];
189
assign srcAc = psw [6];
190
 
191 82 simont
 
192
 
193 75 simont
//
194
// accumulator
195
// ACC
196
oc8051_acc oc8051_acc1(.clk(clk), .rst(rst), .bit_in(bit_in), .data_in(dat1),
197 82 simont
           .data2_in(dat2), .wr(we), .wr_bit(wr_bit_r), .wr_sfr(wr_sfr),
198 116 simont
           .wr_addr(adr1), .data_out(acc), .p(p));
199 75 simont
 
200
 
201
//
202
// b register
203
// B
204 116 simont
oc8051_b_register oc8051_b_register (.clk(clk), .rst(rst), .bit_in(bit_in),
205
           .data_in(dat1), .wr(we), .wr_bit(wr_bit_r), .wr_addr(adr1),
206 82 simont
           .data_out(b_reg), .wr_sfr(wr_sfr));
207 75 simont
 
208
//
209
//stack pointer
210
// SP
211
oc8051_sp oc8051_sp1(.clk(clk), .rst(rst), .ram_rd_sel(ram_rd_sel), .ram_wr_sel(ram_wr_sel),
212 82 simont
                 .wr_addr(adr1), .wr(we), .wr_bit(wr_bit_r), .data_in(dat1),
213
                 .data_out(sp_out), .sp_out(sp), .sp_w(sp_w));
214 75 simont
 
215
//
216
//data pointer
217
// DPTR, DPH, DPL
218
oc8051_dptr oc8051_dptr1(.clk(clk), .rst(rst), .addr(adr1), .data_in(dat1),
219 82 simont
                .data2_in(dat2), .wr(we), .wr_bit(wr_bit_r),
220
                .data_hi(dptr_hi), .data_lo(dptr_lo), .wr_sfr(wr_sfr));
221 75 simont
 
222 82 simont
 
223 75 simont
//
224
//program status word
225
// PSW
226 116 simont
oc8051_psw oc8051_psw1 (.clk(clk), .rst(rst), .wr_addr(adr1), .data_in(dat1),
227
                .wr(we), .wr_bit(wr_bit_r), .data_out(psw), .p(p), .cy_in(bit_in),
228 75 simont
                .ac_in(desAc), .ov_in(desOv), .set(psw_set), .bank_sel(bank_sel));
229
 
230
//
231
// ports
232
// P0, P1, P2, P3
233
oc8051_ports oc8051_ports1(.clk(clk), .rst(rst), .bit_in(bit_in), .data_in(dat1), .wr(we),
234 116 simont
                 .wr_bit(wr_bit_r), .wr_addr(adr1), .rmw(rmw),
235
                 .p0_out(p0_out), .p1_out(p1_out), .p2_out(p2_out), .p3_out(p3_out),
236
                 .p0_in(p0_in), .p1_in(p1_in), .p2_in(p2_in), .p3_in(p3_in),
237
                 .p0_data(p0_data), .p1_data(p1_data), .p2_data(p2_data), .p3_data(p3_data));
238 75 simont
 
239
//
240
// serial interface
241
// SCON, SBUF
242 116 simont
oc8051_uart oc8051_uatr1 (.clk(clk), .rst(rst), .bit_in(bit_in),
243 82 simont
                .data_in(dat1), .wr(we), .wr_bit(wr_bit_r), .wr_addr(adr1),
244 116 simont
                .rxd(rxd), .txd(txd), .intr(uart_int),
245
                .rclk(rclk), .tclk(tclk), .brate2(brate2),
246
                .t1_ow(tf1), .pres_ow(pres_ow),
247
                .scon(scon), .pcon(pcon), .sbuf(sbuf));
248 75 simont
 
249
//
250
// interrupt control
251
// IP, IE, TCON
252 116 simont
oc8051_int oc8051_int1 (.clk(clk), .rst(rst), .wr_addr(adr1), .bit_in(bit_in),
253
                .ack(int_ack), .data_in(dat1),
254 82 simont
                .wr(we), .wr_bit(wr_bit_r),
255
                .tf0(tf0), .tf1(tf1), .t2_int(tc2_int), .tr0(tr0), .tr1(tr1),
256
                .ie0(int0), .ie1(int1),
257
                .uart_int(uart_int),
258 116 simont
                .reti(reti), .intr(intr), .int_vec(int_src),
259
                .ie(ie), .tcon(tcon), .ip(ip));
260 75 simont
 
261 82 simont
 
262 75 simont
//
263
// timer/counter control
264
// TH0, TH1, TL0, TH1, TMOD
265 116 simont
oc8051_tc oc8051_tc1(.clk(clk), .rst(rst), .wr_addr(adr1),
266 82 simont
                .data_in(dat1), .wr(we), .wr_bit(wr_bit_r), .ie0(int0), .ie1(int1), .tr0(tr0),
267 116 simont
                .tr1(tr1), .t0(t0), .t1(t1), .tf0(tf0), .tf1(tf1), .pres_ow(pres_ow),
268
                .tmod(tmod), .tl0(tl0), .th0(th0), .tl1(tl1), .th1(th1));
269 75 simont
 
270 82 simont
//
271
// timer/counter 2
272 116 simont
// TH2, TL2, RCAPL2L, RCAPL2H, T2CON
273
oc8051_tc2 oc8051_tc21(.clk(clk), .rst(rst), .wr_addr(adr1), .data_in(dat1), .wr(we),
274
           .wr_bit(wr_bit_r), .bit_in(bit_in), .t2(t2), .t2ex(t2ex),
275
           .rclk(rclk), .tclk(tclk), .brate2(brate2), .tc2_int(tc2_int), .pres_ow(pres_ow),
276
           .t2con(t2con), .tl2(tl2), .th2(th2), .rcap2l(rcap2l), .rcap2h(rcap2h));
277 75 simont
 
278 82 simont
 
279
 
280 75 simont
always @(posedge clk or posedge rst)
281
  if (rst) begin
282
    adr0_r <= #1 8'h00;
283
    ram_wr_sel_r <= #1 3'b000;
284 82 simont
    wr_bit_r <= #1 1'b0;
285 75 simont
  end else begin
286
    adr0_r <= #1 adr0;
287
    ram_wr_sel_r <= #1 ram_wr_sel;
288 82 simont
    wr_bit_r <= #1 wr_bit;
289 75 simont
  end
290
 
291
//
292
//set output in case of address (byte)
293 116 simont
always @(adr0_r or psw or acc or dptr_hi or dptr_lo or b_reg or
294
//ports
295
          p0_data or p1_data or p2_data or p3_data or
296
//interrupt control
297
          ie or tcon or ip or
298
// t/c 2
299
          t2con or tl2 or th2 or rcap2l or rcap2h or
300
// t/c 0,1
301
          tmod or tl0 or th0 or tl1 or th1 or
302
// serial interface
303
          scon or pcon or sbuf or
304
// stack
305
          sp_out)
306 75 simont
begin
307 82 simont
    case (adr0_r)
308 116 simont
      `OC8051_SFR_ACC:          dat0 = acc;
309
      `OC8051_SFR_PSW:          dat0 = psw;
310
      `OC8051_SFR_P0:           dat0 = p0_data;
311
      `OC8051_SFR_P1:           dat0 = p1_data;
312
      `OC8051_SFR_P2:           dat0 = p2_data;
313
      `OC8051_SFR_P3:           dat0 = p3_data;
314
      `OC8051_SFR_SP:           dat0 = sp_out;
315
      `OC8051_SFR_B:            dat0 = b_reg;
316
      `OC8051_SFR_DPTR_HI:      dat0 = dptr_hi;
317
      `OC8051_SFR_DPTR_LO:      dat0 = dptr_lo;
318
      `OC8051_SFR_SCON:         dat0 = scon;
319
      `OC8051_SFR_SBUF:         dat0 = sbuf;
320
      `OC8051_SFR_PCON:         dat0 = pcon;
321
      `OC8051_SFR_TH0:          dat0 = th0;
322
      `OC8051_SFR_TH1:          dat0 = th1;
323
      `OC8051_SFR_TL0:          dat0 = tl0;
324
      `OC8051_SFR_TL1:          dat0 = tl1;
325
      `OC8051_SFR_TMOD:         dat0 = tmod;
326
      `OC8051_SFR_IP:           dat0 = ip;
327
      `OC8051_SFR_IE:           dat0 = ie;
328
      `OC8051_SFR_TCON:         dat0 = tcon;
329
      `OC8051_SFR_RCAP2H:       dat0 = rcap2h;
330
      `OC8051_SFR_RCAP2L:       dat0 = rcap2l;
331
      `OC8051_SFR_TH2:          dat0 = th2;
332
      `OC8051_SFR_TL2:          dat0 = tl2;
333
      `OC8051_SFR_T2CON:        dat0 = t2con;
334
      default:                  dat0 = 8'h00;
335 82 simont
    endcase
336 75 simont
end
337
 
338
 
339
//
340
//set output in case of address (bit)
341 116 simont
always @(adr0_r or psw or acc or b_reg or
342
//ports
343
          p0_data or p1_data or p2_data or p3_data or
344
//interrupt control
345
          ie or tcon or ip or
346
// t/c 2
347
          t2con or
348
// serial interface
349
          scon)
350 75 simont
begin
351 82 simont
    case (adr0_r[7:3])
352 116 simont
      `OC8051_SFR_B_ACC:   bit_out = acc[adr0_r[2:0]];
353
      `OC8051_SFR_B_PSW:   bit_out = psw[adr0_r[2:0]];
354
      `OC8051_SFR_B_P0:    bit_out = p0_data[adr0_r[2:0]];
355
      `OC8051_SFR_B_P1:    bit_out = p1_data[adr0_r[2:0]];
356
      `OC8051_SFR_B_P2:    bit_out = p2_data[adr0_r[2:0]];
357
      `OC8051_SFR_B_P3:    bit_out = p3_data[adr0_r[2:0]];
358
      `OC8051_SFR_B_B:     bit_out = b_reg[adr0_r[2:0]];
359
      `OC8051_SFR_B_IP:    bit_out = ip[adr0_r[2:0]];
360
      `OC8051_SFR_B_IE:    bit_out = ie[adr0_r[2:0]];
361
      `OC8051_SFR_B_TCON:  bit_out = tcon[adr0_r[2:0]];
362
      `OC8051_SFR_B_SCON:  bit_out = scon[adr0_r[2:0]];
363
      `OC8051_SFR_B_T2CON: bit_out = t2con[adr0_r[2:0]];
364
      default:             bit_out = 1'b0;
365 82 simont
    endcase
366 75 simont
end
367
 
368
endmodule

powered by: WebSVN 2.1.0

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