-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxil_to_bus.vhd
199 lines (171 loc) · 6.73 KB
/
axil_to_bus.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
-- #############################################################################
-- # << AXI4-Lite to Simple Bus Adaptor >>
-- # ===========================================================================
-- # File : axil_to_bus.vhd
-- # Author : David Gussler - [email protected]
-- # Language : VHDL '08
-- # ===========================================================================
-- # BSD 2-Clause License
-- #
-- # Copyright (c) 2023, David Gussler. All rights reserved.
-- #
-- # Redistribution and use in source and binary forms, with or without
-- # modification, are permitted provided that the following conditions are met:
-- #
-- # 1. Redistributions of source code must retain the above copyright notice,
-- # this list of conditions and the following disclaimer.
-- #
-- # 2. Redistributions in binary form must reproduce the above copyright
-- # notice, this list of conditions and the following disclaimer in the
-- # documentation and/or other materials provided with the distribution.
-- #
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- # POSSIBILITY OF SUCH DAMAGE.
-- # ===========================================================================
-- # This module translates an AXI interface to a simplified bus interface to
-- # make downstream user logic simpler by abstracting away the complexities of
-- # AXI. It is able to maintain 100% thruput as long as
-- # the master doesn't stall and the master sets a valid write address and write
-- # data on the same cycle. No bubble cycles inserted here.
-- #
-- # This module addds no latency or pipelining. If that is needed to ease timing,
-- # use the axil_pipe module along with this one.
-- #############################################################################
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.gen_utils_pkg.all;
entity axil_to_bus is
port(
i_clk : in std_logic;
i_rst : in std_logic;
-- AXI4-Lite Slave
i_s_axil : in axil_req_t;
o_s_axil : out axil_resp_t;
-- Simple Bus Master
i_m_bus : in bus_resp_t;
o_m_bus : out bus_req_t
);
end entity;
architecture rtl of axil_to_bus is
signal awvalid : std_logic;
signal wr_en : std_logic;
signal awaddr : std_logic_vector(31 downto 0);
signal wvalid : std_logic;
signal wready : std_logic;
signal wdata : std_logic_vector(31 downto 0);
signal arvalid : std_logic;
signal rd_en : std_logic;
signal araddr : std_logic_vector(31 downto 0);
begin
-- -------------------------------------------------------------------------
-- Writes
-- -------------------------------------------------------------------------
-- Write Address
u_aw_skid_buff : entity work.skid_buff
generic map (
G_WIDTH => i_s_axil.awaddr'LENGTH,
G_REG_OUTS => FALSE
)
port map (
i_clk => i_clk,
i_rst => i_rst,
i_valid => i_s_axil.awvalid,
o_ready => o_s_axil.awready,
i_data => i_s_axil.awaddr,
o_valid => awvalid,
i_ready => wr_en,
o_data => awaddr
);
-- Write Data
u_w_skid_buff : entity work.skid_buff
generic map (
G_WIDTH => i_s_axil.wdata'LENGTH,
G_REG_OUTS => FALSE
)
port map (
i_clk => i_clk,
i_rst => i_rst,
i_valid => i_s_axil.wvalid,
o_ready => o_s_axil.wready,
i_data => i_s_axil.wdata,
o_valid => wvalid,
i_ready => wr_en,
o_data => wdata
);
-- Enable a write if both the write address and write data are valid
-- Also, we can't enable a new write if the last write response has been stalled
wr_en <= awvalid and wvalid and not (o_s_axil.bvalid and not i_s_axil.bready);
process (i_clk) begin
if rising_edge(i_clk) then
if i_rst then
o_s_axil.bvalid <= '0';
else
-- Set write response to valid the cycle after the write request
-- since our simple bus always responds in one cycle
if wr_en then
o_s_axil.bvalid <= '1';
-- Don't have to check for valid here because if we've made it to
-- this point in the if statement then we know that valid has
-- already been set
elsif i_s_axil.bready then -- and bvalid
o_s_axil.bvalid <= '0';
end if;
end if;
end if;
end process;
-- Always respond with OKAY
o_s_axil.bresp <= AXI_RESP_OKAY;
o_m_bus.wen <= wr_en;
o_m_bus.waddr <= awaddr;
o_m_bus.wdata <= wdata;
-- -------------------------------------------------------------------------
-- Reads
-- -------------------------------------------------------------------------
-- Read Address
u_ar_skid_buff : entity work.skid_buff
generic map (
G_WIDTH => 32,
G_REG_OUTS => FALSE
)
port map (
i_clk => i_clk,
i_rst => i_rst,
i_valid => i_s_axil.arvalid,
o_ready => o_s_axil.arready,
i_data => i_s_axil.araddr,
o_valid => arvalid,
i_ready => rd_en,
o_data => araddr
);
-- Enable a read if the read address is valid
-- Also, we can't enable a new read if the last read response has been stalled
rd_en <= arvalid and not (o_s_axil.rvalid and not i_s_axil.rready);
process (i_clk) begin
if rising_edge(i_clk) then
if i_rst then
o_s_axil.rvalid <= '0';
else
if rd_en then
o_s_axil.rvalid <= '1';
elsif i_s_axil.rready then -- and rvalid
o_s_axil.rvalid <= '0';
end if;
end if;
end if;
end process;
-- Always respond with OKAY
o_s_axil.rresp <= AXI_RESP_OKAY;
o_s_axil.rdata <= i_m_bus.rdata;
o_m_bus.ren <= rd_en;
o_m_bus.raddr <= araddr;
end architecture;