-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWrapper.vhd
127 lines (107 loc) · 5.06 KB
/
Wrapper.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
----------------------------------------------------------------------------------
-- Company: RAT Technologies (a subdivision of Cal Poly CENG)
-- Engineer: Various RAT rats
--
-- Create Date: 02/03/2017
-- Module Name: RAT_wrapper - Behavioral
-- Target Devices: Basys3
-- Description: Wrapper for RAT CPU. This model provides a template to interfaces
-- the RAT CPU to the Basys3 development board.
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity RAT_wrapper is
Port ( LEDS : out STD_LOGIC_VECTOR (7 downto 0);
SWITCHES : in STD_LOGIC_VECTOR (7 downto 0);
RST : in STD_LOGIC;
CLK : in STD_LOGIC);
end RAT_wrapper;
architecture Behavioral of RAT_wrapper is
-- INPUT PORT IDS -------------------------------------------------------------
-- Right now, the only possible inputs are the switches
-- In future labs you can add more port IDs, and you'll have
-- to add constants here for the mux below
CONSTANT SWITCHES_ID : STD_LOGIC_VECTOR (7 downto 0) := X"20";
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- OUTPUT PORT IDS ------------------------------------------------------------
-- In future labs you can add more port IDs
CONSTANT LEDS_ID : STD_LOGIC_VECTOR (7 downto 0) := X"40";
-------------------------------------------------------------------------------
-- Declare RAT_CPU ------------------------------------------------------------
component RAT_MCU
Port ( IN_PORT : in STD_LOGIC_VECTOR (7 downto 0);
OUT_PORT : out STD_LOGIC_VECTOR (7 downto 0);
PORT_ID : out STD_LOGIC_VECTOR (7 downto 0);
IO_STRB : out STD_LOGIC;
RESET : in STD_LOGIC;
INT : in STD_LOGIC;
CLK : in STD_LOGIC);
end component RAT_MCU;
-------------------------------------------------------------------------------
-- Signals for connecting RAT_CPU to RAT_wrapper -------------------------------
signal s_input_port : std_logic_vector (7 downto 0);
signal s_output_port : std_logic_vector (7 downto 0);
signal s_port_id : std_logic_vector (7 downto 0);
signal s_load : std_logic;
signal s_clk_sig : std_logic := '0';
--signal s_interrupt : std_logic; -- not yet used
-- Register definitions for output devices ------------------------------------
-- add signals for any added outputs
signal r_LEDS : std_logic_vector (7 downto 0);
-------------------------------------------------------------------------------
begin
-- Clock Divider Process ------------------------------------------------------
clkdiv: process(CLK)
begin
if RISING_EDGE(CLK) then
s_clk_sig <= NOT s_clk_sig;
end if;
end process clkdiv;
-------------------------------------------------------------------------------
-- Instantiate RAT_CPU --------------------------------------------------------
CPU: RAT_MCU
port map( IN_PORT => s_input_port,
OUT_PORT => s_output_port,
PORT_ID => s_port_id,
RESET => RST,
IO_STRB => s_load,
INT => '0', -- s_interrupt
CLK => s_clk_sig);
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- MUX for selecting what input to read ---------------------------------------
-- add conditions and connections for any added PORT IDs
-------------------------------------------------------------------------------
inputs: process(s_port_id, SWITCHES)
begin
if (s_port_id = SWITCHES_ID) then
s_input_port <= SWITCHES;
else
s_input_port <= x"00";
end if;
end process inputs;
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- MUX for updating output registers ------------------------------------------
-- Register updates depend on rising clock edge and asserted load signal
-- add conditions and connections for any added PORT IDs
-------------------------------------------------------------------------------
outputs: process(CLK)
begin
if (rising_edge(CLK)) then
if (s_load = '1') then
-- the register definition for the LEDS
if (s_port_id = LEDS_ID) then
r_LEDS <= s_output_port;
end if;
end if;
end if;
end process outputs;
-------------------------------------------------------------------------------
-- Register Interface Assignments ---------------------------------------------
-- add all outputs that you added to this design
LEDS <= r_LEDS;
end Behavioral;