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

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [VHDL/] [ioport.vhd] - Blame information for rev 101

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

Line No. Rev Author Line
1 99 davidgb
--===========================================================================--
2
--                                                                           --
3
--  ioport.vhd - Synthesizable Dual Bidirectionsal I/O Port                  --
4
--                                                                           --
5
--===========================================================================--
6 19 dilbert57
--
7 99 davidgb
--  File name      : ioport.vhd
8 19 dilbert57
--
9 99 davidgb
--  Purpose        : Implements a dual 8 bit bidirectional I/O port
10
--                  
11
--  Dependencies   : ieee.std_logic_1164
12
--                   ieee.std_logic_unsigned
13
--                   unisim.vcomponents
14
--
15
--  Author         : John E. Kent
16
--
17
--  Email          : dilbert57@opencores.org      
18
--
19
--  Web            : http://opencores.org/project,system09
20
--
21
--  ioport.vhd is a dual bi-directional 8 bit I/O port written in VHDL.
22
-- 
23
--  Copyright (C) 2002 - 2010 John Kent
24
--
25
--  This program is free software: you can redistribute it and/or modify
26
--  it under the terms of the GNU General Public License as published by
27
--  the Free Software Foundation, either version 3 of the License, or
28
--  (at your option) any later version.
29
--
30
--  This program is distributed in the hope that it will be useful,
31
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
32
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
--  GNU General Public License for more details.
34
--
35
--  You should have received a copy of the GNU General Public License
36
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
37
--
38
--===========================================================================--
39
--                                                                           --
40
--                              Revision  History                            --
41
--                                                                           --
42
--===========================================================================--
43
--
44
-- Version  Author        Date               Description
45
-- 0.1      John E. Kent  11 October 2002    Used a loop counter for 
46
--                                           data direction & read port signals
47
-- 0.2      John E. Kent  5 September 2003   Reduced to 2 x 8 bit ports
48
-- 1.0      John E. Kent  6 September 2003   Changed Clock Edge
49
-- 1.1      John E. Kent  25 Februrary 2007  Modified sensitivity lists
50
-- 1.2      John E. Kent  30 May 2010        Updated Header, added unisim library
51 19 dilbert57
--
52
--===========================================================================
53
--
54
 
55
library ieee;
56
  use ieee.std_logic_1164.all;
57
  use ieee.std_logic_unsigned.all;
58 99 davidgb
library unisim;
59
  use unisim.vcomponents.all;
60 19 dilbert57
 
61
entity ioport is
62
        port (
63
         clk       : in  std_logic;
64
    rst       : in  std_logic;
65
    cs        : in  std_logic;
66
    rw        : in  std_logic;
67
    addr      : in  std_logic_vector(1 downto 0);
68
    data_in   : in  std_logic_vector(7 downto 0);
69
         data_out  : out std_logic_vector(7 downto 0);
70
         porta_io  : inout std_logic_vector(7 downto 0);
71
         portb_io  : inout std_logic_vector(7 downto 0)
72
         );
73
end;
74
 
75
architecture rtl of ioport is
76
 
77
signal porta_ddr : std_logic_vector(7 downto 0);
78
signal portb_ddr : std_logic_vector(7 downto 0);
79
signal porta_data : std_logic_vector(7 downto 0);
80
signal portb_data : std_logic_vector(7 downto 0);
81
 
82
begin
83
 
84
 
85
--------------------------------
86
--
87
-- read I/O port
88
--
89
--------------------------------
90
 
91
ioport_read : process( addr,
92
                     porta_ddr, portb_ddr,
93
                                                        porta_data, portb_data,
94
                                                   porta_io, portb_io )
95
variable count : integer;
96
begin
97
      case addr is
98
             when "00" =>
99
                    for count in 0 to 7 loop
100
            if porta_ddr(count) = '1' then
101
              data_out(count) <= porta_data(count);
102
            else
103
              data_out(count) <= porta_io(count);
104
            end if;
105
                         end loop;
106
 
107
                  when "01" =>
108
                    for count in 0 to 7 loop
109
            if portb_ddr(count) = '1' then
110
              data_out(count) <= portb_data(count);
111
            else
112
              data_out(count) <= portb_io(count);
113
            end if;
114
                         end loop;
115
 
116
             when "10" =>
117
                    data_out <= porta_ddr;
118
                  when "11" =>
119
                    data_out <= portb_ddr;
120
                  when others =>
121
                    null;
122
                end case;
123
end process;
124
 
125
---------------------------------
126
--
127
-- Write I/O ports
128
--
129
---------------------------------
130
 
131
ioport_write : process( clk, rst, addr, cs, rw, data_in,
132
                        porta_data, portb_data,
133
                                                                porta_ddr, portb_ddr )
134
begin
135
  if clk'event and clk = '0' then
136
    if rst = '1' then
137
      porta_data <= "00000000";
138
      portb_data <= "00000000";
139
      porta_ddr <= "00000000";
140
      portb_ddr <= "00000000";
141
    elsif cs = '1' and rw = '0' then
142
      case addr is
143
             when "00" =>
144
                    porta_data <= data_in;
145
                    portb_data <= portb_data;
146
                    porta_ddr  <= porta_ddr;
147
                    portb_ddr  <= portb_ddr;
148
                  when "01" =>
149
                    porta_data <= porta_data;
150
                    portb_data <= data_in;
151
                    porta_ddr  <= porta_ddr;
152
                    portb_ddr  <= portb_ddr;
153
                  when "10" =>
154
                    porta_data <= porta_data;
155
                    portb_data <= portb_data;
156
                    porta_ddr  <= data_in;
157
                    portb_ddr  <= portb_ddr;
158
                  when "11" =>
159
                    porta_data <= porta_data;
160
                    portb_data <= portb_data;
161
                    porta_ddr  <= porta_ddr;
162
                    portb_ddr  <= data_in;
163
                  when others =>
164
                    null;
165
                end case;
166
         else
167
                    porta_data <= porta_data;
168
                    portb_data <= portb_data;
169
                    porta_ddr  <= porta_ddr;
170
                    portb_ddr  <= portb_ddr;
171
         end if;
172
  end if;
173
end process;
174
 
175
---------------------------------
176
--
177
-- direction control port a
178
--
179
---------------------------------
180
porta_direction : process ( porta_data, porta_ddr )
181
variable count : integer;
182
begin
183
  for count in 0 to 7 loop
184
    if porta_ddr(count) = '1' then
185
      porta_io(count) <= porta_data(count);
186
    else
187
      porta_io(count) <= 'Z';
188
    end if;
189
  end loop;
190
end process;
191
---------------------------------
192
--
193
-- direction control port b
194
--
195
---------------------------------
196
portb_direction : process ( portb_data, portb_ddr )
197
variable count : integer;
198
begin
199
  for count in 0 to 7 loop
200
    if portb_ddr(count) = '1' then
201
      portb_io(count) <= portb_data(count);
202
    else
203
      portb_io(count) <= 'Z';
204
    end if;
205
  end loop;
206
end process;
207
---------------------------------
208
 
209
end rtl;
210
 

powered by: WebSVN 2.1.0

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