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

Subversion Repositories System09

[/] [System09/] [tags/] [V10/] [rtl/] [vhdl/] [ioport.vhd] - Blame information for rev 66

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dilbert57
--===========================================================================----
2
--
3
--  S Y N T H E Z I A B L E    ioport - 2 x 8 bit parallel I/O port
4
--
5
--  www.OpenCores.Org - September 2003
6
--  This core adheres to the GNU public license  
7
--
8
-- File name      : ioport.vhd
9
--
10
-- Purpose        : dual 8 bit I/O module for System09
11
--
12
-- Dependencies   : ieee.Std_Logic_1164
13
--                  ieee.std_logic_unsigned
14
--
15
-- Uses           : None
16
--
17
-- Author         : John E. Kent      
18
--                  dilbert57@opencores.org      
19
--
20
--===========================================================================----
21
--
22
-- Revision History:
23
--===========================================================================--
24
--
25
-- Version 0.1 - 11 Oct 2002
26
--   Used a loop counter for data direction & read port signals
27
-- Version 0.2 - 5 Sept 2003
28
--   Reduced to 2 x 8 bit ports
29
-- Version 1.0 - 6 Sept 2003 - John Kent
30
--   Realeased to open Cores
31
--   changed Clock Edge
32
--
33
--===========================================================================
34
--
35
--
36
-- John Kent - 6 Sept 2002
37
--
38
 
39
library ieee;
40
use ieee.std_logic_1164.all;
41
use ieee.std_logic_unsigned.all;
42
 
43
entity ioport is
44
        port (
45
         clk       : in  std_logic;
46
    rst       : in  std_logic;
47
    cs        : in  std_logic;
48
    rw        : in  std_logic;
49
    addr      : in  std_logic_vector(1 downto 0);
50
    data_in   : in  std_logic_vector(7 downto 0);
51
         data_out  : out std_logic_vector(7 downto 0);
52
         porta_io  : inout std_logic_vector(7 downto 0);
53
         portb_io  : inout std_logic_vector(7 downto 0)
54
         );
55
end;
56
 
57
architecture ioport_arch of ioport is
58
signal porta_ddr : std_logic_vector(7 downto 0);
59
signal portb_ddr : std_logic_vector(7 downto 0);
60
signal porta_data : std_logic_vector(7 downto 0);
61
signal portb_data : std_logic_vector(7 downto 0);
62
 
63
begin
64
 
65
 
66
--------------------------------
67
--
68
-- read I/O port
69
--
70
--------------------------------
71
 
72
ioport_read : process( addr,
73
                     porta_ddr, portb_ddr,
74
                                                        porta_data, portb_data,
75
                                                   porta_io, portb_io )
76
variable count : integer;
77
begin
78
      case addr is
79
             when "00" =>
80
                    for count in 0 to 7 loop
81
            if porta_ddr(count) = '1' then
82
              data_out(count) <= porta_data(count);
83
            else
84
              data_out(count) <= porta_io(count);
85
            end if;
86
                         end loop;
87
 
88
                  when "01" =>
89
                    for count in 0 to 7 loop
90
            if portb_ddr(count) = '1' then
91
              data_out(count) <= portb_data(count);
92
            else
93
              data_out(count) <= portb_io(count);
94
            end if;
95
                         end loop;
96
 
97
             when "10" =>
98
                    data_out <= porta_ddr;
99
                  when "11" =>
100
                    data_out <= portb_ddr;
101
                  when others =>
102
                    data_out <= "00000000";
103
                end case;
104
end process;
105
 
106
---------------------------------
107
--
108
-- Write I/O ports
109
--
110
---------------------------------
111
 
112
ioport_write : process( clk, rst, addr, cs, rw, data_in,
113
                        porta_data, portb_data,
114
                                                                porta_ddr, portb_ddr )
115
begin
116
  if clk'event and clk = '0' then
117
    if rst = '1' then
118
      porta_data <= "00000000";
119
      portb_data <= "00000000";
120
      porta_ddr <= "00000000";
121
      portb_ddr <= "00000000";
122
    elsif cs = '1' and rw = '0' then
123
      case addr is
124
             when "00" =>
125
                    porta_data <= data_in;
126
                    portb_data <= portb_data;
127
                    porta_ddr  <= porta_ddr;
128
                    portb_ddr  <= portb_ddr;
129
                  when "01" =>
130
                    porta_data <= porta_data;
131
                    portb_data <= data_in;
132
                    porta_ddr  <= porta_ddr;
133
                    portb_ddr  <= portb_ddr;
134
                  when "10" =>
135
                    porta_data <= porta_data;
136
                    portb_data <= portb_data;
137
                    porta_ddr  <= data_in;
138
                    portb_ddr  <= portb_ddr;
139
                  when "11" =>
140
                    porta_data <= porta_data;
141
                    portb_data <= portb_data;
142
                    porta_ddr  <= porta_ddr;
143
                    portb_ddr  <= data_in;
144
                  when others =>
145
                    porta_data <= porta_data;
146
                    portb_data <= portb_data;
147
                    porta_ddr  <= porta_ddr;
148
                    portb_ddr  <= portb_ddr;
149
                end case;
150
         else
151
                    porta_data <= porta_data;
152
                    portb_data <= portb_data;
153
                    porta_ddr  <= porta_ddr;
154
                    portb_ddr  <= portb_ddr;
155
         end if;
156
  end if;
157
end process;
158
 
159
---------------------------------
160
--
161
-- direction control port a
162
--
163
---------------------------------
164
porta_direction : process ( porta_data, porta_ddr )
165
variable count : integer;
166
begin
167
  for count in 0 to 7 loop
168
    if porta_ddr(count) = '1' then
169
      porta_io(count) <= porta_data(count);
170
    else
171
      porta_io(count) <= 'Z';
172
    end if;
173
  end loop;
174
end process;
175
---------------------------------
176
--
177
-- direction control port b
178
--
179
---------------------------------
180
portb_direction : process ( portb_data, portb_ddr )
181
variable count : integer;
182
begin
183
  for count in 0 to 7 loop
184
    if portb_ddr(count) = '1' then
185
      portb_io(count) <= portb_data(count);
186
    else
187
      portb_io(count) <= 'Z';
188
    end if;
189
  end loop;
190
end process;
191
---------------------------------
192
 
193
end ioport_arch;
194
 

powered by: WebSVN 2.1.0

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