1 |
198 |
zero_gravi |
-- #################################################################################################
|
2 |
|
|
-- # << NEO430 - Processor Top Entity with Avalon-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_avm 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 48kB (default=4kB)
|
47 |
|
|
DMEM_SIZE : natural := 2*1024; -- internal DMEM size in bytes, max 12kB (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 |
|
|
-- global control --
|
71 |
|
|
clk_i : in std_logic; -- global clock, rising edge
|
72 |
|
|
rst_i : in std_logic; -- global reset, async, low-active
|
73 |
|
|
-- GPIO --
|
74 |
|
|
gpio_o : out std_logic_vector(15 downto 0); -- parallel output
|
75 |
|
|
gpio_i : in std_logic_vector(15 downto 0); -- parallel input
|
76 |
|
|
-- pwm channels --
|
77 |
|
|
pwm_o : out std_logic_vector(03 downto 0); -- pwm channels
|
78 |
|
|
-- arbitrary frequency generator --
|
79 |
|
|
freq_gen_o : out std_logic_vector(02 downto 0); -- programmable frequency output
|
80 |
|
|
-- UART --
|
81 |
|
|
uart_txd_o : out std_logic; -- UART send data
|
82 |
|
|
uart_rxd_i : in std_logic; -- UART receive data
|
83 |
|
|
-- SPI --
|
84 |
|
|
spi_sclk_o : out std_logic; -- serial clock line
|
85 |
|
|
spi_mosi_o : out std_logic; -- serial data line out
|
86 |
|
|
spi_miso_i : in std_logic; -- serial data line in
|
87 |
|
|
spi_cs_o : out std_logic_vector(05 downto 0); -- SPI CS
|
88 |
|
|
twi_sda_io : inout std_logic; -- twi serial data line
|
89 |
|
|
twi_scl_io : inout std_logic; -- twi serial clock line
|
90 |
|
|
-- external interrupts --
|
91 |
|
|
ext_irq_i : in std_logic_vector(07 downto 0); -- external interrupt request lines
|
92 |
|
|
ext_ack_o : out std_logic_vector(07 downto 0); -- external interrupt request acknowledges
|
93 |
|
|
-- Avalon master interface --
|
94 |
|
|
avm_address : out std_logic_vector(31 downto 0);
|
95 |
|
|
avm_readdata : in std_logic_vector(31 downto 0);
|
96 |
|
|
avm_writedata : out std_logic_vector(31 downto 0);
|
97 |
|
|
avm_byteenable : out std_logic_vector(03 downto 0);
|
98 |
|
|
avm_write : out std_logic;
|
99 |
|
|
avm_read : out std_logic;
|
100 |
|
|
avm_waitrequest : in std_logic
|
101 |
|
|
);
|
102 |
|
|
end neo430_top_avm;
|
103 |
|
|
|
104 |
|
|
architecture neo430_top_avm_rtl of neo430_top_avm is
|
105 |
|
|
|
106 |
|
|
-- internal wishbone (unresolved) bus --
|
107 |
|
|
type wb_bus_ul_t is record
|
108 |
|
|
adr : std_ulogic_vector(31 downto 0); -- address
|
109 |
|
|
di : std_ulogic_vector(31 downto 0); -- slave input data
|
110 |
|
|
do : std_ulogic_vector(31 downto 0); -- slave output data
|
111 |
|
|
we : std_ulogic; -- write enable
|
112 |
|
|
sel : std_ulogic_vector(03 downto 0); -- byte enable
|
113 |
|
|
stb : std_ulogic; -- strobe
|
114 |
|
|
cyc : std_ulogic; -- valid cycle
|
115 |
|
|
ack : std_ulogic; -- transfer acknowledge
|
116 |
|
|
end record;
|
117 |
|
|
signal wb_core : wb_bus_ul_t;
|
118 |
|
|
|
119 |
|
|
-- internal wishbone bus --
|
120 |
|
|
type wb_bus_t is record
|
121 |
|
|
adr : std_logic_vector(31 downto 0); -- address
|
122 |
|
|
di : std_logic_vector(31 downto 0); -- slave input data
|
123 |
|
|
do : std_logic_vector(31 downto 0); -- slave output data
|
124 |
|
|
we : std_logic; -- write enable
|
125 |
|
|
sel : std_logic_vector(03 downto 0); -- byte enable
|
126 |
|
|
stb : std_logic; -- strobe
|
127 |
|
|
cyc : std_logic; -- valid cycle
|
128 |
|
|
ack : std_logic; -- transfer acknowledge
|
129 |
|
|
end record;
|
130 |
|
|
signal wb_conv : wb_bus_t;
|
131 |
|
|
|
132 |
|
|
-- other signals for conversion --
|
133 |
|
|
signal clk_i_int : std_ulogic;
|
134 |
|
|
signal rst_i_int : std_ulogic;
|
135 |
|
|
signal gpio_o_int : std_ulogic_vector(15 downto 0);
|
136 |
|
|
signal gpio_i_int : std_ulogic_vector(15 downto 0);
|
137 |
|
|
signal pwm_o_int : std_ulogic_vector(03 downto 0);
|
138 |
|
|
signal uart_txd_o_int : std_ulogic;
|
139 |
|
|
signal uart_rxd_i_int : std_ulogic;
|
140 |
|
|
signal spi_sclk_o_int : std_ulogic;
|
141 |
|
|
signal spi_mosi_o_int : std_ulogic;
|
142 |
|
|
signal spi_miso_i_int : std_ulogic;
|
143 |
|
|
signal spi_cs_o_int : std_ulogic_vector(05 downto 0);
|
144 |
|
|
signal irq_i_int : std_ulogic_vector(07 downto 0);
|
145 |
|
|
signal irq_ack_o_int : std_ulogic_vector(07 downto 0);
|
146 |
|
|
signal freq_gen_o_int : std_ulogic_vector(02 downto 0);
|
147 |
|
|
constant usrcode_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(USER_CODE);
|
148 |
|
|
|
149 |
|
|
-- misc --
|
150 |
|
|
signal trans_en : std_logic;
|
151 |
|
|
|
152 |
|
|
begin
|
153 |
|
|
|
154 |
|
|
-- CPU ----------------------------------------------------------------------
|
155 |
|
|
-- -----------------------------------------------------------------------------
|
156 |
|
|
neo430_top_inst: neo430_top
|
157 |
|
|
generic map (
|
158 |
|
|
-- general configuration --
|
159 |
|
|
CLOCK_SPEED => CLOCK_SPEED, -- main clock in Hz
|
160 |
|
|
IMEM_SIZE => IMEM_SIZE, -- internal IMEM size in bytes, max 48kB (default=4kB)
|
161 |
|
|
DMEM_SIZE => DMEM_SIZE, -- internal DMEM size in bytes, max 12kB (default=2kB)
|
162 |
|
|
-- additional configuration --
|
163 |
|
|
USER_CODE => usrcode_c, -- custom user code
|
164 |
|
|
-- module configuration --
|
165 |
|
|
MULDIV_USE => MULDIV_USE, -- implement multiplier/divider unit? (default=true)
|
166 |
|
|
WB32_USE => WB32_USE, -- implement WB32 unit? (default=true)
|
167 |
|
|
WDT_USE => WDT_USE, -- implement WDT? (default=true)
|
168 |
|
|
GPIO_USE => GPIO_USE, -- implement GPIO unit? (default=true)
|
169 |
|
|
TIMER_USE => TIMER_USE, -- implement timer? (default=true)
|
170 |
|
|
UART_USE => UART_USE, -- implement UART? (default=true)
|
171 |
|
|
CRC_USE => CRC_USE, -- implement CRC unit? (default=true)
|
172 |
|
|
CFU_USE => CFU_USE, -- implement CF unit? (default=false)
|
173 |
|
|
PWM_USE => PWM_USE, -- implement PWM controller? (default=true)
|
174 |
|
|
TWI_USE => TWI_USE, -- implement two wire serial interface? (default=true)
|
175 |
|
|
SPI_USE => SPI_USE, -- implement SPI? (default=true)
|
176 |
|
|
TRNG_USE => TRNG_USE, -- implement TRNG? (default=false)
|
177 |
|
|
EXIRQ_USE => EXIRQ_USE, -- implement EXIRQ? (default=true)
|
178 |
|
|
FREQ_GEN_USE => FREQ_GEN_USE, -- implement FREQ_GEN? (default=true)
|
179 |
|
|
-- boot configuration --
|
180 |
|
|
BOOTLD_USE => BOOTLD_USE, -- implement and use bootloader? (default=true)
|
181 |
|
|
IMEM_AS_ROM => IMEM_AS_ROM -- implement IMEM as read-only memory? (default=false)
|
182 |
|
|
)
|
183 |
|
|
port map (
|
184 |
|
|
-- global control --
|
185 |
|
|
clk_i => clk_i_int, -- global clock, rising edge
|
186 |
|
|
rst_i => rst_i_int, -- global reset, async, low-active
|
187 |
|
|
-- parallel io --
|
188 |
|
|
gpio_o => gpio_o_int, -- parallel output
|
189 |
|
|
gpio_i => gpio_i_int, -- parallel input
|
190 |
|
|
-- pwm channels --
|
191 |
|
|
pwm_o => pwm_o_int, -- pwm channels
|
192 |
|
|
-- arbitrary frequency generator --
|
193 |
|
|
freq_gen_o => freq_gen_o_int, -- programmable frequency output
|
194 |
|
|
-- serial com --
|
195 |
|
|
uart_txd_o => uart_txd_o_int, -- UART send data
|
196 |
|
|
uart_rxd_i => uart_rxd_i_int, -- UART receive data
|
197 |
|
|
spi_sclk_o => spi_sclk_o_int, -- serial clock line
|
198 |
|
|
spi_mosi_o => spi_mosi_o_int, -- serial data line out
|
199 |
|
|
spi_miso_i => spi_miso_i_int, -- serial data line in
|
200 |
|
|
spi_cs_o => spi_cs_o_int, -- SPI CS
|
201 |
|
|
twi_sda_io => twi_sda_io, -- twi serial data line
|
202 |
|
|
twi_scl_io => twi_scl_io, -- twi serial clock line
|
203 |
|
|
-- 32-bit wishbone interface --
|
204 |
|
|
wb_adr_o => wb_core.adr, -- address
|
205 |
|
|
wb_dat_i => wb_core.di, -- read data
|
206 |
|
|
wb_dat_o => wb_core.do, -- write data
|
207 |
|
|
wb_we_o => wb_core.we, -- read/write
|
208 |
|
|
wb_sel_o => wb_core.sel, -- byte enable
|
209 |
|
|
wb_stb_o => wb_core.stb, -- strobe
|
210 |
|
|
wb_cyc_o => wb_core.cyc, -- valid cycle
|
211 |
|
|
wb_ack_i => wb_core.ack, -- transfer acknowledge
|
212 |
|
|
-- interrupts --
|
213 |
|
|
ext_irq_i => irq_i_int, -- external interrupt request line
|
214 |
|
|
ext_ack_o => irq_ack_o_int -- external interrupt request acknowledge
|
215 |
|
|
);
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
-- Output Type Conversion ---------------------------------------------------
|
219 |
|
|
-- -----------------------------------------------------------------------------
|
220 |
|
|
clk_i_int <= std_ulogic(clk_i);
|
221 |
|
|
rst_i_int <= std_ulogic(rst_i);
|
222 |
|
|
gpio_i_int <= std_ulogic_vector(gpio_i);
|
223 |
|
|
uart_rxd_i_int <= std_ulogic(uart_rxd_i);
|
224 |
|
|
spi_miso_i_int <= std_ulogic(spi_miso_i);
|
225 |
|
|
irq_i_int <= std_ulogic_vector(ext_irq_i);
|
226 |
|
|
|
227 |
|
|
gpio_o <= std_logic_vector(gpio_o_int);
|
228 |
|
|
pwm_o <= std_logic_vector(pwm_o_int);
|
229 |
|
|
uart_txd_o <= std_logic(uart_txd_o_int);
|
230 |
|
|
spi_sclk_o <= std_logic(spi_sclk_o_int);
|
231 |
|
|
spi_mosi_o <= std_logic(spi_mosi_o_int);
|
232 |
|
|
spi_cs_o <= std_logic_vector(spi_cs_o_int);
|
233 |
|
|
ext_ack_o <= std_logic_vector(irq_ack_o_int);
|
234 |
|
|
freq_gen_o <= std_logic_vector(freq_gen_o_int);
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
-- Wishbone-to-Avalon Bridge ------------------------------------------------
|
238 |
|
|
-- -----------------------------------------------------------------------------
|
239 |
|
|
-- Type Conversion --
|
240 |
|
|
wb_conv.adr <= std_logic_vector(wb_core.adr);
|
241 |
|
|
wb_conv.do <= std_logic_vector(wb_core.do);
|
242 |
|
|
wb_conv.we <= std_logic(wb_core.we);
|
243 |
|
|
wb_conv.sel <= std_logic_vector(wb_core.sel);
|
244 |
|
|
wb_conv.stb <= std_logic(wb_core.stb);
|
245 |
|
|
wb_conv.cyc <= std_logic(wb_core.cyc);
|
246 |
|
|
|
247 |
|
|
wb_core.di <= std_ulogic_vector(wb_conv.di);
|
248 |
|
|
wb_core.ack <= std_ulogic(wb_conv.ack);
|
249 |
|
|
|
250 |
|
|
active_transfer: process(clk_i_int)
|
251 |
|
|
begin
|
252 |
|
|
if rising_edge(clk_i_int) then
|
253 |
|
|
trans_en <= wb_conv.cyc and (trans_en or wb_conv.stb); -- keep STB virtually alive
|
254 |
|
|
end if;
|
255 |
|
|
end process active_transfer;
|
256 |
|
|
|
257 |
|
|
-- Wishbone -> Avalon
|
258 |
|
|
avm_address <= wb_conv.adr;
|
259 |
|
|
avm_writedata <= wb_conv.do;
|
260 |
|
|
avm_byteenable <= wb_conv.sel;
|
261 |
|
|
avm_write <= wb_conv.cyc and (wb_conv.stb or trans_en) and wb_conv.we;
|
262 |
|
|
avm_read <= wb_conv.cyc and (wb_conv.stb or trans_en) and (not wb_conv.we);
|
263 |
|
|
|
264 |
|
|
-- Avalon -> Wishbone
|
265 |
|
|
wb_conv.di <= avm_readdata;
|
266 |
|
|
wb_conv.ack <= wb_conv.cyc and (not avm_waitrequest);
|
267 |
|
|
|
268 |
|
|
|
269 |
|
|
end neo430_top_avm_rtl;
|