| 1 |
2 |
jsauermann |
-------------------------------------------------------------------------------
|
| 2 |
|
|
--
|
| 3 |
|
|
-- Copyright (C) 2009, 2010 Dr. Juergen Sauermann
|
| 4 |
|
|
--
|
| 5 |
|
|
-- This code is free software: you can redistribute it and/or modify
|
| 6 |
|
|
-- it under the terms of the GNU General Public License as published by
|
| 7 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
| 8 |
|
|
-- (at your option) any later version.
|
| 9 |
|
|
--
|
| 10 |
|
|
-- This code is distributed in the hope that it will be useful,
|
| 11 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
|
|
-- GNU General Public License for more details.
|
| 14 |
|
|
--
|
| 15 |
|
|
-- You should have received a copy of the GNU General Public License
|
| 16 |
|
|
-- along with this code (see the file named COPYING).
|
| 17 |
|
|
-- If not, see http://www.gnu.org/licenses/.
|
| 18 |
|
|
--
|
| 19 |
|
|
-------------------------------------------------------------------------------
|
| 20 |
|
|
-------------------------------------------------------------------------------
|
| 21 |
|
|
--
|
| 22 |
|
|
-- Module Name: avr_fpga - Behavioral
|
| 23 |
|
|
-- Create Date: 13:51:24 11/07/2009
|
| 24 |
|
|
-- Description: top level of a CPU
|
| 25 |
|
|
--
|
| 26 |
|
|
-------------------------------------------------------------------------------
|
| 27 |
|
|
|
| 28 |
|
|
library IEEE;
|
| 29 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
| 30 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
| 31 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
| 32 |
|
|
|
| 33 |
|
|
entity avr_fpga is
|
| 34 |
|
|
port ( I_CLK_100 : in std_logic;
|
| 35 |
|
|
I_SWITCH : in std_logic_vector(9 downto 0);
|
| 36 |
|
|
I_RX : in std_logic;
|
| 37 |
|
|
|
| 38 |
|
|
Q_7_SEGMENT : out std_logic_vector(6 downto 0);
|
| 39 |
|
|
Q_LEDS : out std_logic_vector(3 downto 0);
|
| 40 |
|
|
Q_TX : out std_logic);
|
| 41 |
|
|
end avr_fpga;
|
| 42 |
|
|
|
| 43 |
|
|
architecture Behavioral of avr_fpga is
|
| 44 |
|
|
|
| 45 |
|
|
component cpu_core
|
| 46 |
|
|
port ( I_CLK : in std_logic;
|
| 47 |
|
|
I_CLR : in std_logic;
|
| 48 |
|
|
I_INTVEC : in std_logic_vector( 5 downto 0);
|
| 49 |
|
|
I_DIN : in std_logic_vector( 7 downto 0);
|
| 50 |
|
|
|
| 51 |
|
|
Q_OPC : out std_logic_vector(15 downto 0);
|
| 52 |
|
|
Q_PC : out std_logic_vector(15 downto 0);
|
| 53 |
|
|
Q_DOUT : out std_logic_vector( 7 downto 0);
|
| 54 |
|
|
Q_ADR_IO : out std_logic_vector( 7 downto 0);
|
| 55 |
|
|
Q_RD_IO : out std_logic;
|
| 56 |
|
|
Q_WE_IO : out std_logic);
|
| 57 |
|
|
end component;
|
| 58 |
|
|
|
| 59 |
|
|
signal C_PC : std_logic_vector(15 downto 0);
|
| 60 |
|
|
signal C_OPC : std_logic_vector(15 downto 0);
|
| 61 |
|
|
signal C_ADR_IO : std_logic_vector( 7 downto 0);
|
| 62 |
|
|
signal C_DOUT : std_logic_vector( 7 downto 0);
|
| 63 |
|
|
signal C_RD_IO : std_logic;
|
| 64 |
|
|
signal C_WE_IO : std_logic;
|
| 65 |
|
|
|
| 66 |
|
|
component io
|
| 67 |
|
|
port ( I_CLK : in std_logic;
|
| 68 |
|
|
I_CLR : in std_logic;
|
| 69 |
|
|
I_ADR_IO : in std_logic_vector( 7 downto 0);
|
| 70 |
|
|
I_DIN : in std_logic_vector( 7 downto 0);
|
| 71 |
|
|
I_RD_IO : in std_logic;
|
| 72 |
|
|
I_WE_IO : in std_logic;
|
| 73 |
|
|
I_SWITCH : in std_logic_vector( 7 downto 0);
|
| 74 |
|
|
I_RX : in std_logic;
|
| 75 |
|
|
|
| 76 |
|
|
Q_7_SEGMENT : out std_logic_vector( 6 downto 0);
|
| 77 |
|
|
Q_DOUT : out std_logic_vector( 7 downto 0);
|
| 78 |
|
|
Q_INTVEC : out std_logic_vector(5 downto 0);
|
| 79 |
|
|
Q_LEDS : out std_logic_vector( 1 downto 0);
|
| 80 |
|
|
Q_TX : out std_logic);
|
| 81 |
|
|
end component;
|
| 82 |
|
|
|
| 83 |
|
|
signal N_INTVEC : std_logic_vector( 5 downto 0);
|
| 84 |
|
|
signal N_DOUT : std_logic_vector( 7 downto 0);
|
| 85 |
|
|
signal N_TX : std_logic;
|
| 86 |
|
|
signal N_7_SEGMENT : std_logic_vector( 6 downto 0);
|
| 87 |
|
|
|
| 88 |
|
|
component segment7
|
| 89 |
|
|
port ( I_CLK : in std_logic;
|
| 90 |
|
|
|
| 91 |
|
|
I_CLR : in std_logic;
|
| 92 |
|
|
I_OPC : in std_logic_vector(15 downto 0);
|
| 93 |
|
|
I_PC : in std_logic_vector(15 downto 0);
|
| 94 |
|
|
|
| 95 |
|
|
Q_7_SEGMENT : out std_logic_vector( 6 downto 0));
|
| 96 |
|
|
end component;
|
| 97 |
|
|
|
| 98 |
|
|
signal S_7_SEGMENT : std_logic_vector( 6 downto 0);
|
| 99 |
|
|
|
| 100 |
|
|
signal L_CLK : std_logic := '0';
|
| 101 |
|
|
signal L_CLK_CNT : std_logic_vector( 2 downto 0) := "000";
|
| 102 |
|
|
signal L_CLR : std_logic; -- reset, active low
|
| 103 |
|
|
signal L_CLR_N : std_logic := '0'; -- reset, active low
|
| 104 |
|
|
signal L_C1_N : std_logic := '0'; -- switch debounce, active low
|
| 105 |
|
|
signal L_C2_N : std_logic := '0'; -- switch debounce, active low
|
| 106 |
|
|
|
| 107 |
|
|
begin
|
| 108 |
|
|
|
| 109 |
|
|
cpu : cpu_core
|
| 110 |
|
|
port map( I_CLK => L_CLK,
|
| 111 |
|
|
I_CLR => L_CLR,
|
| 112 |
|
|
I_DIN => N_DOUT,
|
| 113 |
|
|
I_INTVEC => N_INTVEC,
|
| 114 |
|
|
|
| 115 |
|
|
Q_ADR_IO => C_ADR_IO,
|
| 116 |
|
|
Q_DOUT => C_DOUT,
|
| 117 |
|
|
Q_OPC => C_OPC,
|
| 118 |
|
|
Q_PC => C_PC,
|
| 119 |
|
|
Q_RD_IO => C_RD_IO,
|
| 120 |
|
|
Q_WE_IO => C_WE_IO);
|
| 121 |
|
|
|
| 122 |
|
|
ino : io
|
| 123 |
|
|
port map( I_CLK => L_CLK,
|
| 124 |
|
|
I_CLR => L_CLR,
|
| 125 |
|
|
I_ADR_IO => C_ADR_IO,
|
| 126 |
|
|
I_DIN => C_DOUT,
|
| 127 |
|
|
I_RD_IO => C_RD_IO,
|
| 128 |
|
|
I_RX => I_RX,
|
| 129 |
|
|
I_SWITCH => I_SWITCH(7 downto 0),
|
| 130 |
|
|
I_WE_IO => C_WE_IO,
|
| 131 |
|
|
|
| 132 |
|
|
Q_7_SEGMENT => N_7_SEGMENT,
|
| 133 |
|
|
Q_DOUT => N_DOUT,
|
| 134 |
|
|
Q_INTVEC => N_INTVEC,
|
| 135 |
|
|
Q_LEDS => Q_LEDS(1 downto 0),
|
| 136 |
|
|
Q_TX => N_TX);
|
| 137 |
|
|
|
| 138 |
|
|
seg : segment7
|
| 139 |
|
|
port map( I_CLK => L_CLK,
|
| 140 |
|
|
I_CLR => L_CLR,
|
| 141 |
|
|
I_OPC => C_OPC,
|
| 142 |
|
|
I_PC => C_PC,
|
| 143 |
|
|
|
| 144 |
|
|
Q_7_SEGMENT => S_7_SEGMENT);
|
| 145 |
|
|
|
| 146 |
|
|
-- input clock scaler
|
| 147 |
|
|
--
|
| 148 |
|
|
clk_div : process(I_CLK_100)
|
| 149 |
|
|
begin
|
| 150 |
|
|
if (rising_edge(I_CLK_100)) then
|
| 151 |
|
|
L_CLK_CNT <= L_CLK_CNT + "001";
|
| 152 |
|
|
if (L_CLK_CNT = "001") then
|
| 153 |
|
|
L_CLK_CNT <= "000";
|
| 154 |
|
|
L_CLK <= not L_CLK;
|
| 155 |
|
|
end if;
|
| 156 |
|
|
end if;
|
| 157 |
|
|
end process;
|
| 158 |
|
|
|
| 159 |
|
|
-- reset button debounce process
|
| 160 |
|
|
--
|
| 161 |
|
|
deb : process(L_CLK)
|
| 162 |
|
|
begin
|
| 163 |
|
|
if (rising_edge(L_CLK)) then
|
| 164 |
|
|
-- switch debounce
|
| 165 |
|
|
if ((I_SWITCH(8) = '0') or (I_SWITCH(9) = '0')) then -- pushed
|
| 166 |
|
|
L_CLR_N <= '0';
|
| 167 |
|
|
L_C2_N <= '0';
|
| 168 |
|
|
L_C1_N <= '0';
|
| 169 |
|
|
else -- released
|
| 170 |
|
|
L_CLR_N <= L_C2_N;
|
| 171 |
|
|
L_C2_N <= L_C1_N;
|
| 172 |
|
|
L_C1_N <= '1';
|
| 173 |
|
|
end if;
|
| 174 |
|
|
end if;
|
| 175 |
|
|
end process;
|
| 176 |
|
|
|
| 177 |
|
|
L_CLR <= not L_CLR_N;
|
| 178 |
|
|
|
| 179 |
|
|
Q_LEDS(2) <= I_RX;
|
| 180 |
|
|
Q_LEDS(3) <= N_TX;
|
| 181 |
|
|
Q_7_SEGMENT <= N_7_SEGMENT when (I_SWITCH(7) = '1') else S_7_SEGMENT;
|
| 182 |
|
|
Q_TX <= N_TX;
|
| 183 |
|
|
|
| 184 |
|
|
end Behavioral;
|
| 185 |
|
|
|