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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_ports.v] - Blame information for rev 46

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

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

powered by: WebSVN 2.1.0

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