1 |
4 |
arif_endro |
-- $Id: io_interface.vhdl,v 1.1 2005-12-23 04:19:55 arif_endro Exp $
|
2 |
|
|
-------------------------------------------------------------------------------
|
3 |
|
|
-- Title : IO Interface
|
4 |
|
|
-- Project : Mini AES 128
|
5 |
|
|
-------------------------------------------------------------------------------
|
6 |
|
|
-- File : io_interface.vhdl
|
7 |
|
|
-- Author : "Arif E. Nugroho" <arif_endro@yahoo.com>
|
8 |
|
|
-- Created : 2005/12/22
|
9 |
|
|
-- Last update :
|
10 |
|
|
-- Simulators : ModelSim SE PLUS 6.0
|
11 |
|
|
-- Synthesizers: ISE Xilinx 6.3i
|
12 |
|
|
-- Target :
|
13 |
|
|
-------------------------------------------------------------------------------
|
14 |
|
|
-- Description : IO Interface used to implement 8bit communications.
|
15 |
|
|
-------------------------------------------------------------------------------
|
16 |
15 |
arif_endro |
-- Copyright (C) 2005 Arif Endro Nugroho
|
17 |
4 |
arif_endro |
-------------------------------------------------------------------------------
|
18 |
|
|
--
|
19 |
|
|
-- THIS SOURCE FILE MAY BE USED AND DISTRIBUTED WITHOUT RESTRICTION
|
20 |
|
|
-- PROVIDED THAT THIS COPYRIGHT STATEMENT IS NOT REMOVED FROM THE FILE AND THAT
|
21 |
|
|
-- ANY DERIVATIVE WORK CONTAINS THE ORIGINAL COPYRIGHT NOTICE AND THE
|
22 |
|
|
-- ASSOCIATED DISCLAIMER.
|
23 |
|
|
--
|
24 |
|
|
-------------------------------------------------------------------------------
|
25 |
|
|
--
|
26 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
27 |
|
|
-- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
28 |
|
|
-- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
29 |
|
|
-- EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
30 |
|
|
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
31 |
|
|
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
32 |
|
|
-- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
33 |
|
|
-- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
34 |
|
|
-- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
35 |
|
|
-- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36 |
|
|
--
|
37 |
|
|
-------------------------------------------------------------------------------
|
38 |
|
|
library ieee;
|
39 |
|
|
use ieee.std_logic_1164.all;
|
40 |
|
|
use ieee.std_logic_arith.all;
|
41 |
|
|
use ieee.std_logic_unsigned.all;
|
42 |
|
|
|
43 |
|
|
entity io_interface is
|
44 |
|
|
port (
|
45 |
|
|
clock : in std_logic;
|
46 |
|
|
clear : in std_logic;
|
47 |
|
|
load_i : in std_logic;
|
48 |
|
|
load_i_int : out std_logic;
|
49 |
|
|
data_i : in std_logic_vector (7 downto 0);
|
50 |
|
|
key_i : in std_logic_vector (7 downto 0);
|
51 |
|
|
data_o : out std_logic_vector (7 downto 0);
|
52 |
|
|
data_o_int : in std_logic_vector (127 downto 000);
|
53 |
|
|
data_i_int : out std_logic_vector (127 downto 000);
|
54 |
|
|
key_i_int : out std_logic_vector (127 downto 000);
|
55 |
|
|
done_o_int : in std_logic;
|
56 |
|
|
done_o : out std_logic
|
57 |
|
|
);
|
58 |
|
|
end io_interface;
|
59 |
|
|
|
60 |
|
|
architecture data_flow of io_interface is
|
61 |
|
|
|
62 |
|
|
type fifo16x8 is array ( 0 to 15 ) of std_logic_vector (7 downto 0);
|
63 |
|
|
|
64 |
|
|
signal fifo_data : fifo16x8 :=
|
65 |
|
|
(
|
66 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000",
|
67 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000",
|
68 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000",
|
69 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000"
|
70 |
|
|
);
|
71 |
|
|
|
72 |
|
|
signal fifo_key : fifo16x8 :=
|
73 |
|
|
(
|
74 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000",
|
75 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000",
|
76 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000",
|
77 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000"
|
78 |
|
|
);
|
79 |
|
|
|
80 |
|
|
signal fifo_output : fifo16x8 :=
|
81 |
|
|
(
|
82 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000",
|
83 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000",
|
84 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000",
|
85 |
|
|
B"0000_0000", B"0000_0000", B"0000_0000", B"0000_0000"
|
86 |
|
|
);
|
87 |
|
|
|
88 |
|
|
signal load_core : std_logic := '0';
|
89 |
|
|
signal done_int : std_logic := '0';
|
90 |
|
|
signal up_counter : integer range 0 to 15 := 0;
|
91 |
|
|
-- signal data_o_int : std_logic_vector (127 downto 000) :=
|
92 |
|
|
-- ( X"3925841D_02DC09FB_DC118597_196A0B32" ); -- CT 0
|
93 |
|
|
|
94 |
|
|
begin
|
95 |
|
|
|
96 |
|
|
load_i_int <= load_core;
|
97 |
|
|
|
98 |
|
|
process(clock, clear)
|
99 |
|
|
begin
|
100 |
|
|
if (clear = '1') then
|
101 |
|
|
done_o <= '0';
|
102 |
|
|
elsif (clock = '1' and clock'event) then
|
103 |
|
|
done_o <= done_int;
|
104 |
|
|
end if;
|
105 |
|
|
end process;
|
106 |
|
|
|
107 |
|
|
process(clock, clear)
|
108 |
|
|
begin
|
109 |
|
|
if (clear = '1') then
|
110 |
|
|
up_counter <= 0;
|
111 |
|
|
elsif (clock = '1' and clock'event) then
|
112 |
|
|
if (done_o_int = '1') then
|
113 |
|
|
up_counter <= 0;
|
114 |
|
|
-- elsif ((up_counter = 0) and (done_o_int = '1')) then
|
115 |
|
|
-- elsif (done_o_int = '0' and done_o_int'event) then
|
116 |
|
|
-- 20051219 FIXME
|
117 |
|
|
done_int <= '1';
|
118 |
|
|
elsif (up_counter < 15 ) then
|
119 |
|
|
up_counter <= up_counter + 1;
|
120 |
|
|
else
|
121 |
|
|
-- up_counter <= 0;
|
122 |
|
|
done_int <= '0';
|
123 |
|
|
end if;
|
124 |
|
|
end if;
|
125 |
|
|
end process;
|
126 |
|
|
|
127 |
|
|
process(clock, clear)
|
128 |
|
|
begin
|
129 |
|
|
if (clear = '1') then
|
130 |
|
|
fifo_output <= (others => (others => '0'));
|
131 |
|
|
elsif (clock = '1' and clock'event) then
|
132 |
|
|
if (done_o_int = '1') then
|
133 |
|
|
fifo_output <= ( data_o_int (127 downto 120), data_o_int (119 downto 112), data_o_int (111 downto 104),
|
134 |
|
|
data_o_int (103 downto 096), data_o_int (095 downto 088), data_o_int (087 downto 080),
|
135 |
|
|
data_o_int (079 downto 072), data_o_int (071 downto 064), data_o_int (063 downto 056),
|
136 |
|
|
data_o_int (055 downto 048), data_o_int (047 downto 040), data_o_int (039 downto 032),
|
137 |
|
|
data_o_int (031 downto 024), data_o_int (023 downto 016), data_o_int (015 downto 008),
|
138 |
|
|
data_o_int (007 downto 000));
|
139 |
|
|
end if;
|
140 |
|
|
end if;
|
141 |
|
|
end process;
|
142 |
|
|
|
143 |
|
|
process(clock, clear)
|
144 |
|
|
begin
|
145 |
|
|
if (clear = '1') then
|
146 |
|
|
data_o <= (others => '0');
|
147 |
|
|
elsif (clock = '1' and clock'event) then
|
148 |
|
|
data_o <= fifo_output(up_counter);
|
149 |
|
|
end if;
|
150 |
|
|
end process;
|
151 |
|
|
|
152 |
|
|
process(clock, clear)
|
153 |
|
|
begin
|
154 |
|
|
if (clear = '1') then
|
155 |
|
|
fifo_key <= (others => (others => '0'));
|
156 |
|
|
fifo_data <= (others => (others => '0'));
|
157 |
|
|
load_core <= '1';
|
158 |
|
|
elsif (clock = '1' and clock'event) then
|
159 |
|
|
if (load_i = '1') then
|
160 |
|
|
fifo_key <= (fifo_key (1 to 15) & key_i);
|
161 |
|
|
fifo_data <= (fifo_data (1 to 15) & data_i);
|
162 |
|
|
end if;
|
163 |
|
|
load_core <= load_i;
|
164 |
|
|
end if;
|
165 |
|
|
end process;
|
166 |
|
|
|
167 |
|
|
key_i_int<= ( fifo_key (00) & fifo_key (01) & fifo_key (02) & fifo_key (03) &
|
168 |
|
|
fifo_key (04) & fifo_key (05) & fifo_key (06) & fifo_key (07) &
|
169 |
|
|
fifo_key (08) & fifo_key (09) & fifo_key (10) & fifo_key (11) &
|
170 |
|
|
fifo_key (12) & fifo_key (13) & fifo_key (14) & fifo_key (15) );
|
171 |
|
|
|
172 |
|
|
data_i_int<= ( fifo_data (00) & fifo_data (01) & fifo_data (02) & fifo_data (03) &
|
173 |
|
|
fifo_data (04) & fifo_data (05) & fifo_data (06) & fifo_data (07) &
|
174 |
|
|
fifo_data (08) & fifo_data (09) & fifo_data (10) & fifo_data (11) &
|
175 |
|
|
fifo_data (12) & fifo_data (13) & fifo_data (14) & fifo_data (15) );
|
176 |
|
|
|
177 |
|
|
end data_flow;
|