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

Subversion Repositories 8051

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

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

powered by: WebSVN 2.1.0

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