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

Subversion Repositories 8051

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

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

powered by: WebSVN 2.1.0

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