-
Notifications
You must be signed in to change notification settings - Fork 0
/
axi_avalon.vhd
157 lines (131 loc) · 5.41 KB
/
axi_avalon.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
-- This allows a Avalon Slave to be connected to an AXI Master
entity axi_avalon is
generic (
G_ADDR_SIZE : integer;
G_DATA_SIZE : integer
);
port (
clk_i : in std_logic;
rst_i : in std_logic;
-- AXI Lite interface (slave)
s_axil_awready_o : out std_logic;
s_axil_awvalid_i : in std_logic;
s_axil_awaddr_i : in std_logic_vector(G_ADDR_SIZE-1 downto 0);
s_axil_awprot_i : in std_logic_vector(2 downto 0);
s_axil_awid_i : in std_logic_vector(7 downto 0);
s_axil_wready_o : out std_logic;
s_axil_wvalid_i : in std_logic;
s_axil_wdata_i : in std_logic_vector(G_DATA_SIZE-1 downto 0);
s_axil_wstrb_i : in std_logic_vector(G_DATA_SIZE/8-1 downto 0);
s_axil_bready_i : in std_logic;
s_axil_bvalid_o : out std_logic;
s_axil_bresp_o : out std_logic_vector(1 downto 0);
s_axil_bid_o : out std_logic_vector(7 downto 0);
s_axil_arready_o : out std_logic;
s_axil_arvalid_i : in std_logic;
s_axil_araddr_i : in std_logic_vector(G_ADDR_SIZE-1 downto 0);
s_axil_arprot_i : in std_logic_vector(2 downto 0);
s_axil_arid_i : in std_logic_vector(7 downto 0);
s_axil_rready_i : in std_logic;
s_axil_rvalid_o : out std_logic;
s_axil_rdata_o : out std_logic_vector(G_DATA_SIZE-1 downto 0);
s_axil_rresp_o : out std_logic_vector(1 downto 0);
s_axil_rid_o : out std_logic_vector(7 downto 0);
-- Avalon Memory Map interface (master)
m_avm_write_o : out std_logic;
m_avm_read_o : out std_logic;
m_avm_address_o : out std_logic_vector(G_ADDR_SIZE-1 downto 0);
m_avm_writedata_o : out std_logic_vector(G_DATA_SIZE-1 downto 0);
m_avm_byteenable_o : out std_logic_vector(G_DATA_SIZE/8-1 downto 0);
m_avm_readdata_i : in std_logic_vector(G_DATA_SIZE-1 downto 0);
m_avm_readdatavalid_i : in std_logic;
m_avm_waitrequest_i : in std_logic;
m_avm_writeresponsevalid_i : in std_logic;
m_avm_response_i : in std_logic_vector(1 downto 0)
);
end entity axi_avalon;
architecture synthesis of axi_avalon is
signal avm_read_address : std_logic_vector(G_ADDR_SIZE-1 downto 0);
signal avm_write_address : std_logic_vector(G_ADDR_SIZE-1 downto 0);
signal avm_byteenable : std_logic_vector(G_DATA_SIZE/8-1 downto 0);
signal avm_read : std_logic;
signal avm_write : std_logic;
signal avm_writedata : std_logic_vector(G_DATA_SIZE-1 downto 0);
signal aw_stored : std_logic;
signal w_stored : std_logic;
signal s_axil_rvalid : std_logic;
signal s_axil_rdata : std_logic_vector(G_DATA_SIZE-1 downto 0);
signal s_axil_rresp : std_logic_vector(1 downto 0);
begin
-- Handle write
m_avm_address_o <= avm_write_address when avm_write = '1' else avm_read_address;
m_avm_byteenable_o <= avm_byteenable;
m_avm_read_o <= avm_read;
m_avm_write_o <= avm_write;
m_avm_writedata_o <= avm_writedata;
p_read : process (clk_i)
begin
if rising_edge(clk_i) then
avm_read <= '0';
if s_axil_arvalid_i = '1' and s_axil_arready_o = '1' then
avm_read_address <= s_axil_araddr_i;
s_axil_rid_o <= s_axil_arid_i;
avm_read <= '1';
end if;
end if;
end process p_read;
s_axil_awready_o <= not aw_stored;
s_axil_wready_o <= not w_stored;
avm_write <= aw_stored and w_stored and not avm_read;
p_stored : process (clk_i)
begin
if rising_edge(clk_i) then
if s_axil_awvalid_i = '1' and s_axil_awready_o = '1' then
avm_write_address <= s_axil_awaddr_i;
s_axil_bid_o <= s_axil_awid_i;
aw_stored <= '1';
end if;
if s_axil_wvalid_i = '1' and s_axil_wready_o = '1' then
avm_writedata <= s_axil_wdata_i;
avm_byteenable <= s_axil_wstrb_i;
w_stored <= '1';
end if;
if avm_write = '1' or rst_i = '1' then
aw_stored <= '0';
w_stored <= '0';
end if;
end if;
end process p_stored;
p_b : process (clk_i)
begin
if rising_edge(clk_i) then
if s_axil_bready_i = '1' then
s_axil_bvalid_o <= '0';
end if;
if m_avm_writeresponsevalid_i = '1' then
s_axil_bvalid_o <= '1';
s_axil_bresp_o <= m_avm_response_i;
end if;
end if;
end process p_b;
-- Handle read response
s_axil_rvalid_o <= s_axil_rvalid;
s_axil_rdata_o <= s_axil_rdata;
s_axil_rresp_o <= s_axil_rresp;
s_axil_arready_o <= '1';
p_r : process (clk_i)
begin
if rising_edge(clk_i) then
if s_axil_rready_i = '1' then
s_axil_rvalid <= '0';
end if;
if m_avm_readdatavalid_i = '1' then
s_axil_rdata <= m_avm_readdata_i;
s_axil_rvalid <= '1';
end if;
end if;
end process p_r;
end architecture synthesis;