-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.vhd
126 lines (97 loc) · 2.49 KB
/
memory.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
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity memory is
generic (
WIDTH : positive := 32
);
port (
clk : in std_logic;
rst : in std_logic;
inport0 : in std_logic_vector(WIDTH-1 downto 0);
inport1 : in std_logic_vector(WIDTH-1 downto 0);
wr_en : in std_logic;
inport0_en : in std_logic;
inport1_en : in std_logic;
byte_address : in std_logic_vector(WIDTH-1 downto 0);
wr_data : in std_logic_vector(WIDTH-1 downto 0);
out_data : out std_logic_vector(WIDTH-1 downto 0);
outport : out std_logic_vector(WIDTH-1 downto 0)
);
end memory;
architecture BHV of memory is
signal ram_out : std_logic_vector(WIDTH-1 downto 0);
signal ram_en : std_logic;
signal inport0_out : std_logic_vector(WIDTH-1 downto 0);
signal inport1_out : std_logic_vector(WIDTH-1 downto 0);
signal mux_sel : std_logic_vector(1 downto 0);
signal outport_en : std_logic;
begin
U_RAM : entity work.ram
port map(
address => byte_address(9 downto 2),
clock => clk,
data => wr_data,
wren => ram_en,
q => ram_out
);
U_INPORT0 : entity work.reg
generic map( width => WIDTH)
port map(
clk => clk,
rst => '0',
-- rst => rst,
load => inport0_en,
input => inport0,
output => inport0_out
);
U_INPORT1 : entity work.reg
generic map( width => WIDTH)
port map(
clk => clk,
rst => '0',
-- rst => rst,
load => inport1_en,
input => inport1,
output => inport1_out
);
U_MUX3x1 : entity work.mux3x1
generic map( width => WIDTH)
port map(
in1 => inport1_out, -- "10"
in2 => inport0_out, -- "01"
in3 => ram_out, -- "00"
sel => mux_sel,
output => out_data
);
U_OUTPORT : entity work.reg
generic map( width => WIDTH)
port map(
clk => clk,
rst => rst,
load => outport_en,
input => wr_data,
output => outport
);
process(wr_en, byte_address)
begin
outport_en <= '0';
ram_en <= '0';
mux_sel <= "11";
if(unsigned(byte_address) = 16#0000FFF8#) then -- inport0 start address
mux_sel <= "01";
elsif(unsigned(byte_address) = 16#0000FFFC#) then -- inport1 start address
if(wr_en = '1') then
outport_en <= '1';
end if;
mux_sel <= "10";
elsif(signed(byte_address) >= 0 and signed(byte_address) < 1024) then
if(wr_en = '1') then
ram_en <= '1';
else
ram_en <= '0';
end if;
mux_sel <= "00";
end if;
end process;
end BHV;