1 |
198 |
zero_gravi |
-- #################################################################################################
|
2 |
|
|
-- # << NEO430 - Processor Top Entity with AXI4-Lite-Compatible Master Interface >> #
|
3 |
|
|
-- # ********************************************************************************************* #
|
4 |
|
|
-- # BSD 3-Clause License #
|
5 |
|
|
-- # #
|
6 |
|
|
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved. #
|
7 |
|
|
-- # #
|
8 |
|
|
-- # Redistribution and use in source and binary forms, with or without modification, are #
|
9 |
|
|
-- # permitted provided that the following conditions are met: #
|
10 |
|
|
-- # #
|
11 |
|
|
-- # 1. Redistributions of source code must retain the above copyright notice, this list of #
|
12 |
|
|
-- # conditions and the following disclaimer. #
|
13 |
|
|
-- # #
|
14 |
|
|
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of #
|
15 |
|
|
-- # conditions and the following disclaimer in the documentation and/or other materials #
|
16 |
|
|
-- # provided with the distribution. #
|
17 |
|
|
-- # #
|
18 |
|
|
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to #
|
19 |
|
|
-- # endorse or promote products derived from this software without specific prior written #
|
20 |
|
|
-- # permission. #
|
21 |
|
|
-- # #
|
22 |
|
|
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS #
|
23 |
|
|
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF #
|
24 |
|
|
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE #
|
25 |
|
|
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, #
|
26 |
|
|
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
|
27 |
|
|
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED #
|
28 |
|
|
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
|
29 |
|
|
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED #
|
30 |
|
|
-- # OF THE POSSIBILITY OF SUCH DAMAGE. #
|
31 |
|
|
-- # ********************************************************************************************* #
|
32 |
|
|
-- # The NEO430 Processor - https://github.com/stnolting/neo430 #
|
33 |
|
|
-- #################################################################################################
|
34 |
|
|
|
35 |
|
|
library ieee;
|
36 |
|
|
use ieee.std_logic_1164.all;
|
37 |
|
|
use ieee.numeric_std.all;
|
38 |
|
|
|
39 |
|
|
library neo430;
|
40 |
|
|
use neo430.neo430_package.all;
|
41 |
|
|
|
42 |
|
|
entity neo430_top_axi4lite is
|
43 |
|
|
generic (
|
44 |
|
|
-- general configuration --
|
45 |
|
|
CLOCK_SPEED : natural := 100000000; -- main clock in Hz
|
46 |
|
|
IMEM_SIZE : natural := 4*1024; -- internal IMEM size in bytes, max 32kB (default=4kB)
|
47 |
|
|
DMEM_SIZE : natural := 2*1024; -- internal DMEM size in bytes, max 28kB (default=2kB)
|
48 |
|
|
-- additional configuration --
|
49 |
|
|
USER_CODE : std_logic_vector(15 downto 0) := x"0000"; -- custom user code
|
50 |
|
|
-- module configuration --
|
51 |
|
|
MULDIV_USE : boolean := true; -- implement multiplier/divider unit? (default=true)
|
52 |
|
|
WB32_USE : boolean := true; -- implement WB32 unit? (default=true)
|
53 |
|
|
WDT_USE : boolean := true; -- implement WDT? (default=true)
|
54 |
|
|
GPIO_USE : boolean := true; -- implement GPIO unit? (default=true)
|
55 |
|
|
TIMER_USE : boolean := true; -- implement timer? (default=true)
|
56 |
|
|
UART_USE : boolean := true; -- implement UART? (default=true)
|
57 |
|
|
CRC_USE : boolean := true; -- implement CRC unit? (default=true)
|
58 |
|
|
CFU_USE : boolean := false; -- implement custom functions unit? (default=false)
|
59 |
|
|
PWM_USE : boolean := true; -- implement PWM controller?
|
60 |
|
|
TWI_USE : boolean := true; -- implement two wire serial interface? (default=true)
|
61 |
|
|
SPI_USE : boolean := true; -- implement SPI? (default=true)
|
62 |
|
|
TRNG_USE : boolean := false; -- implement TRNG? (default=false)
|
63 |
|
|
EXIRQ_USE : boolean := true; -- implement EXIRQ? (default=true)
|
64 |
|
|
FREQ_GEN_USE : boolean := true; -- implement FREQ_GEN? (default=true)
|
65 |
|
|
-- boot configuration --
|
66 |
|
|
BOOTLD_USE : boolean := true; -- implement and use bootloader? (default=true)
|
67 |
|
|
IMEM_AS_ROM : boolean := false -- implement IMEM as read-only memory? (default=false)
|
68 |
|
|
);
|
69 |
|
|
port (
|
70 |
|
|
-- GPIO --
|
71 |
|
|
gpio_o : out std_logic_vector(15 downto 0); -- parallel output
|
72 |
|
|
gpio_i : in std_logic_vector(15 downto 0); -- parallel input
|
73 |
|
|
-- pwm channels --
|
74 |
|
|
pwm_o : out std_logic_vector(03 downto 0); -- pwm channels
|
75 |
|
|
-- arbitrary frequency generator --
|
76 |
|
|
freq_gen_o : out std_logic_vector(02 downto 0); -- programmable frequency output
|
77 |
|
|
-- UART --
|
78 |
|
|
uart_txd_o : out std_logic; -- UART send data
|
79 |
|
|
uart_rxd_i : in std_logic; -- UART receive data
|
80 |
|
|
-- SPI --
|
81 |
|
|
spi_sclk_o : out std_logic; -- serial clock line
|
82 |
|
|
spi_mosi_o : out std_logic; -- serial data line out
|
83 |
|
|
spi_miso_i : in std_logic; -- serial data line in
|
84 |
|
|
spi_cs_o : out std_logic_vector(05 downto 0); -- SPI CS
|
85 |
|
|
twi_sda_io : inout std_logic; -- twi serial data line
|
86 |
|
|
twi_scl_io : inout std_logic; -- twi serial clock line
|
87 |
|
|
-- external interrupts --
|
88 |
|
|
ext_irq_i : in std_logic_vector(07 downto 0); -- external interrupt request lines
|
89 |
|
|
ext_ack_o : out std_logic_vector(07 downto 0); -- external interrupt request acknowledges
|
90 |
|
|
-- AXI Lite-Compatible Master Interface --
|
91 |
|
|
-- Clock and Reset
|
92 |
|
|
m_axi_aclk : in std_logic;
|
93 |
|
|
m_axi_aresetn : in std_logic;
|
94 |
|
|
-- Write Address Channel
|
95 |
|
|
m_axi_awaddr : out std_logic_vector(31 downto 0);
|
96 |
|
|
m_axi_awvalid : out std_logic;
|
97 |
|
|
m_axi_awready : in std_logic;
|
98 |
|
|
m_axi_awprot : out std_logic_vector(2 downto 0);
|
99 |
|
|
-- Write Data Channel
|
100 |
|
|
m_axi_wdata : out std_logic_vector(31 downto 0);
|
101 |
|
|
m_axi_wstrb : out std_logic_vector(3 downto 0);
|
102 |
|
|
m_axi_wvalid : out std_logic;
|
103 |
|
|
m_axi_wready : in std_logic;
|
104 |
|
|
-- Read Address Channel
|
105 |
|
|
m_axi_araddr : out std_logic_vector(31 downto 0);
|
106 |
|
|
m_axi_arvalid : out std_logic;
|
107 |
|
|
m_axi_arready : in std_logic;
|
108 |
|
|
m_axi_arprot : out std_logic_vector(2 downto 0);
|
109 |
|
|
-- Read Data Channel
|
110 |
|
|
m_axi_rdata : in std_logic_vector(31 downto 0);
|
111 |
|
|
m_axi_rresp : in std_logic_vector(1 downto 0);
|
112 |
|
|
m_axi_rvalid : in std_logic;
|
113 |
|
|
m_axi_rready : out std_logic;
|
114 |
|
|
-- Write Response Channel
|
115 |
|
|
m_axi_bresp : in std_logic_vector(1 downto 0);
|
116 |
|
|
m_axi_bvalid : in std_logic;
|
117 |
|
|
m_axi_bready : out std_logic
|
118 |
|
|
);
|
119 |
|
|
end neo430_top_axi4lite;
|
120 |
|
|
|
121 |
|
|
architecture neo430_top_axi4lite_rtl of neo430_top_axi4lite is
|
122 |
|
|
|
123 |
|
|
-- internal wishbone bus --
|
124 |
|
|
type wb_bus_t is record
|
125 |
|
|
adr : std_ulogic_vector(31 downto 0); -- address
|
126 |
|
|
di : std_ulogic_vector(31 downto 0); -- slave input data
|
127 |
|
|
do : std_ulogic_vector(31 downto 0); -- slave output data
|
128 |
|
|
we : std_ulogic; -- write enable
|
129 |
|
|
sel : std_ulogic_vector(03 downto 0); -- byte enable
|
130 |
|
|
stb : std_ulogic; -- strobe
|
131 |
|
|
cyc : std_ulogic; -- valid cycle
|
132 |
|
|
ack : std_ulogic; -- transfer acknowledge
|
133 |
|
|
end record;
|
134 |
|
|
signal wb_core : wb_bus_t;
|
135 |
|
|
|
136 |
|
|
-- other signals for conversion --
|
137 |
|
|
signal gpio_o_int : std_ulogic_vector(15 downto 0);
|
138 |
|
|
signal gpio_i_int : std_ulogic_vector(15 downto 0);
|
139 |
|
|
signal pwm_o_int : std_ulogic_vector(03 downto 0);
|
140 |
|
|
signal uart_txd_o_int : std_ulogic;
|
141 |
|
|
signal uart_rxd_i_int : std_ulogic;
|
142 |
|
|
signal spi_sclk_o_int : std_ulogic;
|
143 |
|
|
signal spi_mosi_o_int : std_ulogic;
|
144 |
|
|
signal spi_miso_i_int : std_ulogic;
|
145 |
|
|
signal spi_cs_o_int : std_ulogic_vector(05 downto 0);
|
146 |
|
|
signal irq_i_int : std_ulogic_vector(07 downto 0);
|
147 |
|
|
signal irq_ack_o_int : std_ulogic_vector(07 downto 0);
|
148 |
|
|
signal freq_gen_o_int : std_ulogic_vector(02 downto 0);
|
149 |
|
|
constant usrcode_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(USER_CODE);
|
150 |
|
|
|
151 |
|
|
-- AXI arbiter --
|
152 |
|
|
signal read_trans : std_ulogic;
|
153 |
|
|
signal write_trans : std_ulogic;
|
154 |
|
|
signal pending_rd : std_ulogic; -- pending read transfer
|
155 |
|
|
signal pending_wr : std_ulogic; -- pending write transfer
|
156 |
|
|
signal adr_valid : std_ulogic;
|
157 |
|
|
signal wresp_ok : std_logic;
|
158 |
|
|
|
159 |
|
|
begin
|
160 |
|
|
|
161 |
|
|
-- CPU ----------------------------------------------------------------------
|
162 |
|
|
-- -----------------------------------------------------------------------------
|
163 |
|
|
neo430_top_inst: neo430_top
|
164 |
|
|
generic map (
|
165 |
|
|
-- general configuration --
|
166 |
|
|
CLOCK_SPEED => CLOCK_SPEED, -- main clock in Hz
|
167 |
|
|
IMEM_SIZE => IMEM_SIZE, -- internal IMEM size in bytes, max 48kB (default=4kB)
|
168 |
|
|
DMEM_SIZE => DMEM_SIZE, -- internal DMEM size in bytes, max 12kB (default=2kB)
|
169 |
|
|
-- additional configuration --
|
170 |
|
|
USER_CODE => usrcode_c, -- custom user code
|
171 |
|
|
-- module configuration --
|
172 |
|
|
MULDIV_USE => MULDIV_USE, -- implement multiplier/divider unit? (default=true)
|
173 |
|
|
WB32_USE => WB32_USE, -- implement WB32 unit? (default=true)
|
174 |
|
|
WDT_USE => WDT_USE, -- implement WDT? (default=true)
|
175 |
|
|
GPIO_USE => GPIO_USE, -- implement GPIO unit? (default=true)
|
176 |
|
|
TIMER_USE => TIMER_USE, -- implement timer? (default=true)
|
177 |
|
|
UART_USE => UART_USE, -- implement UART? (default=true)
|
178 |
|
|
CRC_USE => CRC_USE, -- implement CRC unit? (default=true)
|
179 |
|
|
CFU_USE => CFU_USE, -- implement CF unit? (default=false)
|
180 |
|
|
PWM_USE => PWM_USE, -- implement PWM controller? (default=true)
|
181 |
|
|
TWI_USE => TWI_USE, -- implement two wire serial interface? (default=true)
|
182 |
|
|
SPI_USE => SPI_USE, -- implement SPI? (default=true)
|
183 |
|
|
TRNG_USE => TRNG_USE, -- implement TRNG? (default=false)
|
184 |
|
|
EXIRQ_USE => EXIRQ_USE, -- implement EXIRQ? (default=true)
|
185 |
|
|
FREQ_GEN_USE => FREQ_GEN_USE, -- implement FREQ_GEN? (default=true)
|
186 |
|
|
-- boot configuration --
|
187 |
|
|
BOOTLD_USE => BOOTLD_USE, -- implement and use bootloader? (default=true)
|
188 |
|
|
IMEM_AS_ROM => IMEM_AS_ROM -- implement IMEM as read-only memory? (default=false)
|
189 |
|
|
)
|
190 |
|
|
port map (
|
191 |
|
|
-- global control --
|
192 |
|
|
clk_i => m_axi_aclk, -- global clock, rising edge
|
193 |
|
|
rst_i => m_axi_aresetn, -- global reset, async, LOW-active
|
194 |
|
|
-- parallel io --
|
195 |
|
|
gpio_o => gpio_o_int, -- parallel output
|
196 |
|
|
gpio_i => gpio_i_int, -- parallel input
|
197 |
|
|
-- pwm channels --
|
198 |
|
|
pwm_o => pwm_o_int, -- pwm channels
|
199 |
|
|
-- arbitrary frequency generator --
|
200 |
|
|
freq_gen_o => freq_gen_o_int, -- programmable frequency output
|
201 |
|
|
-- serial com --
|
202 |
|
|
uart_txd_o => uart_txd_o_int, -- UART send data
|
203 |
|
|
uart_rxd_i => uart_rxd_i_int, -- UART receive data
|
204 |
|
|
spi_sclk_o => spi_sclk_o_int, -- serial clock line
|
205 |
|
|
spi_mosi_o => spi_mosi_o_int, -- serial data line out
|
206 |
|
|
spi_miso_i => spi_miso_i_int, -- serial data line in
|
207 |
|
|
spi_cs_o => spi_cs_o_int, -- SPI CS
|
208 |
|
|
twi_sda_io => twi_sda_io, -- twi serial data line
|
209 |
|
|
twi_scl_io => twi_scl_io, -- twi serial clock line
|
210 |
|
|
-- 32-bit wishbone interface --
|
211 |
|
|
wb_adr_o => wb_core.adr, -- address
|
212 |
|
|
wb_dat_i => wb_core.di, -- read data
|
213 |
|
|
wb_dat_o => wb_core.do, -- write data
|
214 |
|
|
wb_we_o => wb_core.we, -- read/write
|
215 |
|
|
wb_sel_o => wb_core.sel, -- byte enable
|
216 |
|
|
wb_stb_o => wb_core.stb, -- strobe
|
217 |
|
|
wb_cyc_o => wb_core.cyc, -- valid cycle
|
218 |
|
|
wb_ack_i => wb_core.ack, -- transfer acknowledge
|
219 |
|
|
-- interrupts --
|
220 |
|
|
ext_irq_i => irq_i_int, -- external interrupt request line
|
221 |
|
|
ext_ack_o => irq_ack_o_int -- external interrupt request acknowledge
|
222 |
|
|
);
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
-- Output Type Conversion ---------------------------------------------------
|
226 |
|
|
-- -----------------------------------------------------------------------------
|
227 |
|
|
gpio_i_int <= std_ulogic_vector(gpio_i);
|
228 |
|
|
uart_rxd_i_int <= std_ulogic(uart_rxd_i);
|
229 |
|
|
spi_miso_i_int <= std_ulogic(spi_miso_i);
|
230 |
|
|
irq_i_int <= std_ulogic_vector(ext_irq_i);
|
231 |
|
|
|
232 |
|
|
gpio_o <= std_logic_vector(gpio_o_int);
|
233 |
|
|
pwm_o <= std_logic_vector(pwm_o_int);
|
234 |
|
|
uart_txd_o <= std_logic(uart_txd_o_int);
|
235 |
|
|
spi_sclk_o <= std_logic(spi_sclk_o_int);
|
236 |
|
|
spi_mosi_o <= std_logic(spi_mosi_o_int);
|
237 |
|
|
spi_cs_o <= std_logic_vector(spi_cs_o_int);
|
238 |
|
|
ext_ack_o <= std_logic_vector(irq_ack_o_int);
|
239 |
|
|
freq_gen_o <= std_logic_vector(freq_gen_o_int);
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
-- Wishbone-to-AXI4-Lite-compatible Bridge ----------------------------------
|
243 |
|
|
-- -----------------------------------------------------------------------------
|
244 |
|
|
|
245 |
|
|
-- transfer type --
|
246 |
|
|
read_trans <= wb_core.cyc and wb_core.stb and (not wb_core.we);
|
247 |
|
|
write_trans <= wb_core.cyc and wb_core.stb and wb_core.we;
|
248 |
|
|
|
249 |
|
|
-- arbiter --
|
250 |
|
|
axi_arbiter: process(m_axi_aclk)
|
251 |
|
|
begin
|
252 |
|
|
if rising_edge(m_axi_aclk) then
|
253 |
|
|
if (wb_core.cyc = '0') then
|
254 |
|
|
pending_rd <= '0';
|
255 |
|
|
pending_wr <= '0';
|
256 |
|
|
adr_valid <= '0';
|
257 |
|
|
m_axi_bready <= '0';
|
258 |
|
|
else
|
259 |
|
|
-- read/write address valid --
|
260 |
|
|
if ((wb_core.cyc and wb_core.stb) = '1') then
|
261 |
|
|
adr_valid <= '1';
|
262 |
|
|
elsif (m_axi_awready = '1') or (m_axi_arready = '1') then
|
263 |
|
|
adr_valid <= '0';
|
264 |
|
|
end if;
|
265 |
|
|
-- transfer read data --
|
266 |
|
|
if (read_trans = '1') then
|
267 |
|
|
pending_rd <= '1';
|
268 |
|
|
elsif (m_axi_rvalid = '1') then
|
269 |
|
|
pending_rd <= '0';
|
270 |
|
|
end if;
|
271 |
|
|
-- transfer write data --
|
272 |
|
|
if (write_trans = '1') then
|
273 |
|
|
pending_wr <= '1';
|
274 |
|
|
elsif (m_axi_wready = '1') then
|
275 |
|
|
pending_wr <= '0';
|
276 |
|
|
end if;
|
277 |
|
|
-- write response channel -
|
278 |
|
|
if (write_trans = '1') then
|
279 |
|
|
m_axi_bready <= '1';
|
280 |
|
|
elsif (m_axi_bvalid = '1') then
|
281 |
|
|
m_axi_bready <= '0';
|
282 |
|
|
end if;
|
283 |
|
|
end if;
|
284 |
|
|
end if;
|
285 |
|
|
end process axi_arbiter;
|
286 |
|
|
|
287 |
|
|
-- Acknowledge Wishbone transfer --
|
288 |
|
|
wb_core.ack <= (pending_rd and std_ulogic(m_axi_rvalid)) or -- read transfer
|
289 |
|
|
-- (pending_wr and std_ulogic(m_axi_wready)); -- write transfer
|
290 |
|
|
(wresp_ok and m_axi_bvalid); -- acknowledged write transfer
|
291 |
|
|
|
292 |
|
|
-- Read Address Channel --
|
293 |
|
|
m_axi_araddr <= std_logic_vector(wb_core.adr);
|
294 |
|
|
m_axi_arvalid <= std_logic(adr_valid) and std_logic(pending_rd);
|
295 |
|
|
m_axi_arprot <= "000"; -- data access, secure, unprivileged
|
296 |
|
|
|
297 |
|
|
-- Read Data Channel --
|
298 |
|
|
wb_core.di <= std_ulogic_vector(m_axi_rdata);
|
299 |
|
|
m_axi_rready <= std_logic(pending_rd);
|
300 |
|
|
|
301 |
|
|
-- Write Address Channel --
|
302 |
|
|
m_axi_awaddr <= std_logic_vector(wb_core.adr);
|
303 |
|
|
m_axi_awvalid <= std_logic(adr_valid) and std_logic(pending_wr);
|
304 |
|
|
m_axi_awprot <= "000"; -- data access, secure, unprivileged
|
305 |
|
|
|
306 |
|
|
-- Write Data Channel --
|
307 |
|
|
m_axi_wdata <= std_logic_vector(wb_core.do);
|
308 |
|
|
m_axi_wstrb <= std_logic_vector(wb_core.sel);
|
309 |
|
|
m_axi_wvalid <= std_logic(pending_wr);
|
310 |
|
|
|
311 |
|
|
-- Write Data Response Channel --
|
312 |
|
|
wresp_ok <= '1' when (m_axi_bresp = "00") else '0';
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
end neo430_top_axi4lite_rtl;
|