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

Subversion Repositories 8051

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

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

powered by: WebSVN 2.1.0

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