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

Subversion Repositories 8051

[/] [8051/] [tags/] [rel_12/] [rtl/] [verilog/] [oc8051_ports.v] - Blame information for rev 82

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

Line No. Rev Author Line
1 82 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  8051 port output                                            ////
4
////                                                              ////
5
////  This file is part of the 8051 cores project                 ////
6
////  http://www.opencores.org/cores/8051/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////   8051 special function registers: port 0:3 - output         ////
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
// Revision 1.6  2002/09/30 17:33:59  simont
48
// prepared header
49
//
50
//
51
 
52
 
53
// synopsys translate_off
54
`include "oc8051_timescale.v"
55
// synopsys translate_on
56
 
57
`include "oc8051_defines.v"
58
 
59
 
60
module oc8051_ports (clk, rst, bit_in, data_in, wr, wr_bit, wr_addr, rd_addr, rmw, data_out, bit_out, p0_out, p1_out, p2_out, p3_out,
61
                     p0_in, p1_in, p2_in, p3_in);
62
//
63
// clk          (in)  clock
64
// rst          (in)  reset
65
// bit_in       (in)  bit input [oc8051_alu.desCy]
66
// data_in      (in)  data input (from alu destiantion 1) [oc8051_alu.des1]
67
// wr           (in)  write [oc8051_decoder.wr -r]
68
// wr_bit       (in)  write bit addresable [oc8051_decoder.bit_addr -r]
69
// wr_addr      (in)  write address [oc8051_ram_wr_sel.out]
70
// rd_addr      (in)  read address [oc8051_ram_rd_sel.out]
71
// rmw          (in)  read modify write feature [oc8051_decoder.rmw]
72
// data_out     (out) data output [oc8051_ram_sel.ports_in]
73
// p0_out, p1_out, p2_out, p3_out       (out) port outputs [pin]
74
// p0_in, p1_in, p2_in, p3_in           (in)  port inputs [pin]
75
//
76
 
77
 
78
input clk, rst, wr, wr_bit, bit_in, rmw;
79
input [7:0] wr_addr, rd_addr, data_in, p0_in, p1_in, p2_in, p3_in;
80
 
81
output bit_out;
82
output [7:0] data_out, p0_out, p1_out, p2_out, p3_out;
83
 
84
reg bit_out;
85
reg [7:0] data_out, p0_out, p1_out, p2_out, p3_out;
86
 
87
//
88
// case of writing to port
89
always @(posedge clk or posedge rst)
90
begin
91
  if (rst) begin
92
    p0_out <= #1 `OC8051_RST_P0;
93
    p1_out <= #1 `OC8051_RST_P1;
94
    p2_out <= #1 `OC8051_RST_P2;
95
    p3_out <= #1 `OC8051_RST_P3;
96
  end else if (wr) begin
97
    if (!wr_bit) begin
98
      case (wr_addr)
99
//
100
// bytaddresable
101
        `OC8051_SFR_P0: p0_out <= #1 data_in;
102
        `OC8051_SFR_P1: p1_out <= #1 data_in;
103
        `OC8051_SFR_P2: p2_out <= #1 data_in;
104
        `OC8051_SFR_P3: p3_out <= #1 data_in;
105
      endcase
106
    end else begin
107
      case (wr_addr[7:3])
108
 
109
//
110
// bit addressable
111
        `OC8051_SFR_B_P0: p0_out[wr_addr[2:0]] <= #1 bit_in;
112
        `OC8051_SFR_B_P1: p1_out[wr_addr[2:0]] <= #1 bit_in;
113
        `OC8051_SFR_B_P2: p2_out[wr_addr[2:0]] <= #1 bit_in;
114
        `OC8051_SFR_B_P3: p3_out[wr_addr[2:0]] <= #1 bit_in;
115
      endcase
116
    end
117
  end
118
end
119
 
120
//always @(p0_out or p0_in or p1_out or p1_in or p2_out or p2_in or p3_out or p3_in or rmw)
121
always @(posedge clk or posedge rst)
122
begin
123
  if (rst)
124
    data_out <= #1 8'h0;
125
  else if (rmw) begin
126
    if ((rd_addr==wr_addr) & wr & !wr_bit)
127
      data_out <= #1 data_in;
128
    else begin
129
      case (rd_addr[5:4])
130
        2'b00: data_out <= #1 p0_out;
131
        2'b01: data_out <= #1 p1_out;
132
        2'b10: data_out <= #1 p2_out;
133
        2'b11: data_out <= #1 p3_out;
134
      endcase
135
     end
136
  end else
137
    case (rd_addr[5:4])
138
      2'b00: data_out <= #1 p0_in;
139
      2'b01: data_out <= #1 p1_in;
140
      2'b10: data_out <= #1 p2_in;
141
      2'b11: data_out <= #1 p3_in;
142
    endcase
143
end
144
 
145
//always  @(rmw or rd_addr or p0_out or p1_out or p2_out or p3_out or p0_in or p1_in or p2_in or p3_in)
146
always @(posedge clk or posedge rst)
147
begin
148
  if (rst)
149
    bit_out <= #1 1'b0;
150
  else if (rmw) begin
151
    if ((wr_addr==rd_addr) & wr & wr_bit)
152
      bit_out <= #1 bit_in;
153
    else if ((wr_addr[7:3]==rd_addr[7:3]) & wr)
154
      bit_out <= #1 data_in[rd_addr[2:0]];
155
    else begin
156
      case (rd_addr[7:3])
157
        `OC8051_SFR_B_P0: bit_out <= #1 p0_out[rd_addr[2:0]];
158
        `OC8051_SFR_B_P1: bit_out <= #1 p1_out[rd_addr[2:0]];
159
        `OC8051_SFR_B_P2: bit_out <= #1 p2_out[rd_addr[2:0]];
160
        default: bit_out <= #1 p3_out[rd_addr[2:0]];
161
      endcase
162
    end
163
  end else begin
164
    case (rd_addr[7:3])
165
      `OC8051_SFR_B_P0: bit_out <= #1 p0_in[rd_addr[2:0]];
166
      `OC8051_SFR_B_P1: bit_out <= #1 p1_in[rd_addr[2:0]];
167
      `OC8051_SFR_B_P2: bit_out <= #1 p2_in[rd_addr[2:0]];
168
      default: bit_out <= #1 p3_in[rd_addr[2:0]];
169
    endcase
170
  end
171
end
172
 
173
endmodule
174
 

powered by: WebSVN 2.1.0

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