1 |
198 |
zero_gravi |
-- #################################################################################################
|
2 |
|
|
-- # << NEO430 - Processor Package >> #
|
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 |
|
|
package neo430_package is
|
40 |
|
|
|
41 |
|
|
-- Processor Hardware Version -------------------------------------------------------------
|
42 |
|
|
-- -------------------------------------------------------------------------------------------
|
43 |
|
|
constant hw_version_c : std_ulogic_vector(15 downto 0) := x"0407"; -- no touchy!
|
44 |
|
|
|
45 |
|
|
-- Danger Zone (Advanced Hardware Configuration) ------------------------------------------
|
46 |
|
|
-- -------------------------------------------------------------------------------------------
|
47 |
|
|
constant use_dsp_mul_c : boolean := false; -- use DSP blocks for MULDIV's multiplication core (default=false)
|
48 |
|
|
constant use_xalu_c : boolean := false; -- implement extended ALU function (default=false)
|
49 |
|
|
constant low_power_mode_c : boolean := false; -- can reduce switching activity, but will also decrease f_max and might increase area (default=false)
|
50 |
|
|
|
51 |
|
|
-- Internal Functions ---------------------------------------------------------------------
|
52 |
|
|
-- -------------------------------------------------------------------------------------------
|
53 |
|
|
function index_size_f(input : natural) return natural;
|
54 |
|
|
function is_power_of_two_f(num : natural; bit_width : natural) return boolean;
|
55 |
|
|
function bit_reversal_f(input : std_ulogic_vector) return std_ulogic_vector;
|
56 |
|
|
function set_bits_f(input : std_ulogic_vector) return natural;
|
57 |
|
|
function leading_zeros_f(input : std_ulogic_vector) return natural;
|
58 |
|
|
function cond_sel_natural_f(cond : boolean; val_t : natural; val_f : natural) return natural;
|
59 |
|
|
function cond_sel_stdulogicvector_f(cond : boolean; val_t : std_ulogic_vector; val_f : std_ulogic_vector) return std_ulogic_vector;
|
60 |
|
|
function bool_to_ulogic_f(cond : boolean) return std_ulogic;
|
61 |
|
|
function bin_to_gray_f(input : std_ulogic_vector) return std_ulogic_vector;
|
62 |
|
|
function gray_to_bin_f(input : std_ulogic_vector) return std_ulogic_vector;
|
63 |
|
|
function int_to_hexchar_f(input : integer) return character;
|
64 |
|
|
function or_all_f(a : std_ulogic_vector) return std_ulogic;
|
65 |
|
|
function and_all_f(a : std_ulogic_vector) return std_ulogic;
|
66 |
|
|
function xor_all_f(a : std_ulogic_vector) return std_ulogic;
|
67 |
|
|
|
68 |
|
|
-- Address Space Layout (make sure this is always sync with neo430.h) ---------------------
|
69 |
|
|
-- -------------------------------------------------------------------------------------------
|
70 |
|
|
|
71 |
|
|
-- Main Memory: IMEM(ROM/RAM) --
|
72 |
|
|
constant imem_base_c : std_ulogic_vector(15 downto 0) := x"0000"; -- base address, fixed!
|
73 |
|
|
constant imem_max_size_c : natural := 48*1024; -- bytes, fixed!
|
74 |
|
|
|
75 |
|
|
-- Main Memory: DMEM(RAM) --
|
76 |
|
|
constant dmem_base_c : std_ulogic_vector(15 downto 0) := x"C000"; -- base address, fixed!
|
77 |
|
|
constant dmem_max_size_c : natural := 12*1024; -- bytes, fixed!
|
78 |
|
|
|
79 |
|
|
-- Boot ROM --
|
80 |
|
|
constant boot_base_c : std_ulogic_vector(15 downto 0) := x"F000"; -- bootloader base address, fixed!
|
81 |
|
|
constant boot_size_c : natural := 2*1024; -- bytes, max 2048 bytes!
|
82 |
|
|
constant boot_max_size_c : natural := 2*1024; -- bytes, fixed!
|
83 |
|
|
|
84 |
|
|
-- IO: Peripheral Devices ("IO") Area --
|
85 |
|
|
-- Each device must use 2 bytes or a multiple of 2 bytes as address space!
|
86 |
|
|
-- CONTROL register(s) (including the device enable) must be located at the base address of the device!
|
87 |
|
|
constant io_base_c : std_ulogic_vector(15 downto 0) := x"FF80";
|
88 |
|
|
constant io_size_c : natural := 128; -- bytes, fixed!
|
89 |
|
|
|
90 |
|
|
-- IO: Multiplier/Divider Unit (MULDIV) --
|
91 |
|
|
constant muldiv_base_c : std_ulogic_vector(15 downto 0) := x"FF80";
|
92 |
|
|
constant muldiv_size_c : natural := 8; -- bytes
|
93 |
|
|
|
94 |
|
|
constant muldiv_opa_resx_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(muldiv_base_c) + x"0000");
|
95 |
|
|
constant muldiv_opb_umul_resy_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(muldiv_base_c) + x"0002");
|
96 |
|
|
constant muldiv_opb_smul_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(muldiv_base_c) + x"0004");
|
97 |
|
|
constant muldiv_opb_udiv_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(muldiv_base_c) + x"0006");
|
98 |
|
|
|
99 |
|
|
-- IO: Frequency Generator (FREQ_GEN) --
|
100 |
|
|
constant freq_gen_base_c : std_ulogic_vector(15 downto 0) := x"FF88";
|
101 |
|
|
constant freq_gen_size_c : natural := 8; -- bytes
|
102 |
|
|
|
103 |
|
|
constant freq_gen_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(freq_gen_base_c) + x"0000");
|
104 |
|
|
constant freq_gen_tw_ch0_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(freq_gen_base_c) + x"0002");
|
105 |
|
|
constant freq_gen_tw_ch1_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(freq_gen_base_c) + x"0004");
|
106 |
|
|
constant freq_gen_tw_ch2_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(freq_gen_base_c) + x"0006");
|
107 |
|
|
|
108 |
|
|
-- IO: Wishbone32 Interface (WB32) --
|
109 |
|
|
constant wb32_base_c : std_ulogic_vector(15 downto 0) := x"FF90";
|
110 |
|
|
constant wb32_size_c : natural := 16; -- bytes
|
111 |
|
|
|
112 |
|
|
constant wb32_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(wb32_base_c) + x"0000");
|
113 |
|
|
constant wb32_rd_adr_lo_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(wb32_base_c) + x"0002");
|
114 |
|
|
constant wb32_rd_adr_hi_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(wb32_base_c) + x"0004");
|
115 |
|
|
constant wb32_wr_adr_lo_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(wb32_base_c) + x"0006");
|
116 |
|
|
constant wb32_wr_adr_hi_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(wb32_base_c) + x"0008");
|
117 |
|
|
constant wb32_data_lo_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(wb32_base_c) + x"000A");
|
118 |
|
|
constant wb32_data_hi_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(wb32_base_c) + x"000C");
|
119 |
|
|
--constant wb32_???_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(wb32_base_c) + x"000E");
|
120 |
|
|
|
121 |
|
|
-- IO: Universal asynchronous receiver and transmitter (UART) --
|
122 |
|
|
constant uart_base_c : std_ulogic_vector(15 downto 0) := x"FFA0";
|
123 |
|
|
constant uart_size_c : natural := 4; -- bytes
|
124 |
|
|
|
125 |
|
|
constant uart_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(uart_base_c) + x"0000");
|
126 |
|
|
constant uart_rtx_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(uart_base_c) + x"0002");
|
127 |
|
|
|
128 |
|
|
-- IO: Serial Peripheral Interface (SPI) --
|
129 |
|
|
constant spi_base_c : std_ulogic_vector(15 downto 0) := x"FFA4";
|
130 |
|
|
constant spi_size_c : natural := 4; -- bytes
|
131 |
|
|
|
132 |
|
|
constant spi_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(spi_base_c) + x"0000");
|
133 |
|
|
constant spi_rtx_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(spi_base_c) + x"0002");
|
134 |
|
|
|
135 |
|
|
-- IO: General purpose input/output port (GPIO) --
|
136 |
|
|
constant gpio_base_c : std_ulogic_vector(15 downto 0) := x"FFA8";
|
137 |
|
|
constant gpio_size_c : natural := 8; -- bytes
|
138 |
|
|
|
139 |
|
|
constant gpio_irqmask_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(gpio_base_c) + x"0000");
|
140 |
|
|
constant gpio_in_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(gpio_base_c) + x"0002");
|
141 |
|
|
constant gpio_out_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(gpio_base_c) + x"0004");
|
142 |
|
|
--constant gpio_???_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(gpio_base_c) + x"0006");
|
143 |
|
|
|
144 |
|
|
-- IO: High-Precision Timer (TIMER) --
|
145 |
|
|
constant timer_base_c : std_ulogic_vector(15 downto 0) := x"FFB0";
|
146 |
|
|
constant timer_size_c : natural := 8; -- bytes
|
147 |
|
|
|
148 |
|
|
constant timer_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(timer_base_c) + x"0000");
|
149 |
|
|
constant timer_cnt_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(timer_base_c) + x"0002");
|
150 |
|
|
constant timer_thres_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(timer_base_c) + x"0004");
|
151 |
|
|
--constant timer_???_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(timer_base_c) + x"0006");
|
152 |
|
|
|
153 |
|
|
-- IO: Watchdog Timer (WDT) --
|
154 |
|
|
constant wdt_base_c : std_ulogic_vector(15 downto 0) := x"FFB8";
|
155 |
|
|
constant wdt_size_c : natural := 2; -- bytes
|
156 |
|
|
|
157 |
|
|
constant wdt_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(wdt_base_c) + x"0000");
|
158 |
|
|
|
159 |
|
|
-- IO: Cyclic Redundancy Check (CRC) --
|
160 |
|
|
constant crc_base_c : std_ulogic_vector(15 downto 0) := x"FFC0";
|
161 |
|
|
constant crc_size_c : natural := 16; -- bytes
|
162 |
|
|
|
163 |
|
|
constant crc_poly_lo_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(crc_base_c) + x"0000");
|
164 |
|
|
constant crc_poly_hi_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(crc_base_c) + x"0002");
|
165 |
|
|
constant crc_crc16_in_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(crc_base_c) + x"0004");
|
166 |
|
|
constant crc_crc32_in_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(crc_base_c) + x"0006");
|
167 |
|
|
--constant crc_???_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(crc_base_c) + x"0008");
|
168 |
|
|
--constant crc_???_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(crc_base_c) + x"000A");
|
169 |
|
|
constant crc_resx_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(crc_base_c) + x"000C");
|
170 |
|
|
constant crc_resy_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(crc_base_c) + x"000E");
|
171 |
|
|
|
172 |
|
|
-- IO: Custom Functions Unit (CFU) --
|
173 |
|
|
constant cfu_base_c : std_ulogic_vector(15 downto 0) := x"FFD0";
|
174 |
|
|
constant cfu_size_c : natural := 16; -- bytes
|
175 |
|
|
|
176 |
|
|
constant cfu_reg0_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(cfu_base_c) + x"0000");
|
177 |
|
|
constant cfu_reg1_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(cfu_base_c) + x"0002");
|
178 |
|
|
constant cfu_reg2_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(cfu_base_c) + x"0004");
|
179 |
|
|
constant cfu_reg3_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(cfu_base_c) + x"0006");
|
180 |
|
|
constant cfu_reg4_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(cfu_base_c) + x"0008");
|
181 |
|
|
constant cfu_reg5_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(cfu_base_c) + x"000A");
|
182 |
|
|
constant cfu_reg6_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(cfu_base_c) + x"000C");
|
183 |
|
|
constant cfu_reg7_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(cfu_base_c) + x"000E");
|
184 |
|
|
|
185 |
|
|
-- IO: Pulse-Width Modulation Controller (PWM) --
|
186 |
|
|
constant pwm_base_c : std_ulogic_vector(15 downto 0) := x"FFE0";
|
187 |
|
|
constant pwm_size_c : natural := 8; -- bytes
|
188 |
|
|
|
189 |
|
|
constant pwm_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(pwm_base_c) + x"0000");
|
190 |
|
|
constant pwm_ch10_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(pwm_base_c) + x"0002");
|
191 |
|
|
constant pwm_ch32_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(pwm_base_c) + x"0004");
|
192 |
|
|
--constant pwm_???_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(pwm_base_c) + x"0006");
|
193 |
|
|
|
194 |
|
|
-- IO: Two Wire Serial Interface (TWI) --
|
195 |
|
|
constant twi_base_c : std_ulogic_vector(15 downto 0) := x"FFE8";
|
196 |
|
|
constant twi_size_c : natural := 4; -- bytes
|
197 |
|
|
|
198 |
|
|
constant twi_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(twi_base_c) + x"0000");
|
199 |
|
|
constant twi_rtx_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(twi_base_c) + x"0002");
|
200 |
|
|
|
201 |
|
|
-- IO: True Random Number Generator (TRNG) --
|
202 |
|
|
constant trng_base_c : std_ulogic_vector(15 downto 0) := x"FFEC";
|
203 |
|
|
constant trng_size_c : natural := 2; -- bytes
|
204 |
|
|
|
205 |
|
|
constant trng_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(trng_base_c) + x"0000");
|
206 |
|
|
|
207 |
|
|
-- IO: External Interrupts Controller (EXIRQ) --
|
208 |
|
|
constant exirq_base_c : std_ulogic_vector(15 downto 0) := x"FFEE";
|
209 |
|
|
constant exirq_size_c : natural := 2; -- bytes
|
210 |
|
|
|
211 |
|
|
constant exirq_ctrl_addr_c : std_ulogic_vector(15 downto 0) := std_ulogic_vector(unsigned(exirq_base_c) + x"0000");
|
212 |
|
|
|
213 |
|
|
-- IO: System Configuration (SYSCONFIG) --
|
214 |
|
|
constant sysconfig_base_c : std_ulogic_vector(15 downto 0) := x"FFF0";
|
215 |
|
|
constant sysconfig_size_c : natural := 16; -- bytes
|
216 |
|
|
|
217 |
|
|
-- Clock Generator -------------------------------------------------------------------------
|
218 |
|
|
-- -------------------------------------------------------------------------------------------
|
219 |
|
|
constant clk_div2_c : natural := 0;
|
220 |
|
|
constant clk_div4_c : natural := 1;
|
221 |
|
|
constant clk_div8_c : natural := 2;
|
222 |
|
|
constant clk_div64_c : natural := 3;
|
223 |
|
|
constant clk_div128_c : natural := 4;
|
224 |
|
|
constant clk_div1024_c : natural := 5;
|
225 |
|
|
constant clk_div2048_c : natural := 6;
|
226 |
|
|
constant clk_div4096_c : natural := 7;
|
227 |
|
|
|
228 |
|
|
-- Register Addresses ---------------------------------------------------------------------
|
229 |
|
|
-- -------------------------------------------------------------------------------------------
|
230 |
|
|
constant reg_pc_c : std_ulogic_vector(3 downto 0) := x"0"; -- program counter
|
231 |
|
|
constant reg_sp_c : std_ulogic_vector(3 downto 0) := x"1"; -- stack pointer
|
232 |
|
|
constant reg_sr_c : std_ulogic_vector(3 downto 0) := x"2"; -- status register
|
233 |
|
|
constant reg_cg_c : std_ulogic_vector(3 downto 0) := x"3"; -- constant generator
|
234 |
|
|
|
235 |
|
|
-- Status Register ------------------------------------------------------------------------
|
236 |
|
|
-- -------------------------------------------------------------------------------------------
|
237 |
|
|
constant sreg_c_c : natural := 0; -- r/w: carry flag
|
238 |
|
|
constant sreg_z_c : natural := 1; -- r/w: zero flag
|
239 |
|
|
constant sreg_n_c : natural := 2; -- r/w: negative flag
|
240 |
|
|
constant sreg_i_c : natural := 3; -- r/w: global interrupt enable
|
241 |
|
|
constant sreg_s_c : natural := 4; -- r/w: CPU sleep flag
|
242 |
|
|
constant sreg_p_c : natural := 5; -- r/w: parity flag
|
243 |
|
|
constant sreg_v_c : natural := 8; -- r/w: overflow flag
|
244 |
|
|
constant sreg_q_c : natural := 14; -- -/w: clear pending IRQ buffer when set
|
245 |
|
|
constant sreg_r_c : natural := 15; -- r/w: enable write access to IMEM (ROM) when set
|
246 |
|
|
|
247 |
|
|
-- ALU Flag Bus ---------------------------------------------------------------------------
|
248 |
|
|
-- -------------------------------------------------------------------------------------------
|
249 |
|
|
constant flag_c_c : natural := 0; -- carry flag
|
250 |
|
|
constant flag_z_c : natural := 1; -- zero flag
|
251 |
|
|
constant flag_n_c : natural := 2; -- negative flag
|
252 |
|
|
constant flag_v_c : natural := 3; -- overflow flag
|
253 |
|
|
constant flag_p_c : natural := 4; -- parity flag
|
254 |
|
|
|
255 |
|
|
-- Main Control Bus -----------------------------------------------------------------------
|
256 |
|
|
-- -------------------------------------------------------------------------------------------
|
257 |
|
|
-- register file --
|
258 |
|
|
constant ctrl_rf_in_sel_c : natural := 0; -- input source
|
259 |
|
|
constant ctrl_rf_adr0_c : natural := 1; -- source/destination register address bit 0
|
260 |
|
|
constant ctrl_rf_adr1_c : natural := 2; -- source/destination register address bit 1
|
261 |
|
|
constant ctrl_rf_adr2_c : natural := 3; -- source/destination register address bit 2
|
262 |
|
|
constant ctrl_rf_adr3_c : natural := 4; -- source/destination register address bit 3
|
263 |
|
|
constant ctrl_rf_as0_c : natural := 5; -- source addressing mode bit 0
|
264 |
|
|
constant ctrl_rf_as1_c : natural := 6; -- source addressing mode bit 1
|
265 |
|
|
constant ctrl_rf_fup_c : natural := 7; -- update ALU flags
|
266 |
|
|
constant ctrl_rf_wb_en_c : natural := 8; -- enable RF write back
|
267 |
|
|
constant ctrl_rf_dsleep_c : natural := 9; -- disable sleep mode
|
268 |
|
|
constant ctrl_rf_dgie_c : natural := 10; -- disable global interrupt enable
|
269 |
|
|
constant ctrl_rf_boot_c : natural := 11; -- inject PC boot address
|
270 |
|
|
-- alu --
|
271 |
|
|
constant ctrl_alu_in_sel_c : natural := 12; -- ALU OP input select
|
272 |
|
|
constant ctrl_alu_opa_wr_c : natural := 13; -- write ALU operand A
|
273 |
|
|
constant ctrl_alu_opb_wr_c : natural := 14; -- write ALU operand B
|
274 |
|
|
constant ctrl_alu_cmd0_c : natural := 15; -- ALU command bit 0
|
275 |
|
|
constant ctrl_alu_cmd1_c : natural := 16; -- ALU command bit 1
|
276 |
|
|
constant ctrl_alu_cmd2_c : natural := 17; -- ALU command bit 2
|
277 |
|
|
constant ctrl_alu_cmd3_c : natural := 18; -- ALU command bit 3
|
278 |
|
|
constant ctrl_alu_bw_c : natural := 19; -- byte(1)/word(0) operation
|
279 |
|
|
-- address generator --
|
280 |
|
|
constant ctrl_adr_off0_c : natural := 20; -- address offset selection bit 0
|
281 |
|
|
constant ctrl_adr_off1_c : natural := 21; -- address offset selection bit 1
|
282 |
|
|
constant ctrl_adr_off2_c : natural := 22; -- address offset selection bit 2
|
283 |
|
|
constant ctrl_adr_mar_sel_c : natural := 23; -- select input for MAR
|
284 |
|
|
constant ctrl_adr_bp_en_c : natural := 24; -- mem addr output select, 0:MAR, 1:bypass
|
285 |
|
|
constant ctrl_adr_ivec_oe_c : natural := 25; -- output IRQ if 1, else output PC
|
286 |
|
|
constant ctrl_adr_mar_wr_c : natural := 26; -- write MAR
|
287 |
|
|
-- memory interface --
|
288 |
|
|
constant ctrl_mem_wr_c : natural := 27; -- write to memory
|
289 |
|
|
constant ctrl_mem_rd_c : natural := 28; -- read from memory
|
290 |
|
|
-- bus size --
|
291 |
|
|
constant ctrl_width_c : natural := 29; -- control bus size
|
292 |
|
|
|
293 |
|
|
-- Condition Codes ------------------------------------------------------------------------
|
294 |
|
|
-- -------------------------------------------------------------------------------------------
|
295 |
|
|
constant cond_ne_c : std_ulogic_vector(2 downto 0) := "000"; -- not equal
|
296 |
|
|
constant cond_eq_c : std_ulogic_vector(2 downto 0) := "001"; -- equal
|
297 |
|
|
constant cond_lo_c : std_ulogic_vector(2 downto 0) := "010"; -- lower
|
298 |
|
|
constant cond_hs_c : std_ulogic_vector(2 downto 0) := "011"; -- higher or same
|
299 |
|
|
constant cond_mi_c : std_ulogic_vector(2 downto 0) := "100"; -- negative
|
300 |
|
|
constant cond_ge_c : std_ulogic_vector(2 downto 0) := "101"; -- greater or equal
|
301 |
|
|
constant cond_le_c : std_ulogic_vector(2 downto 0) := "110"; -- less
|
302 |
|
|
constant cond_al_c : std_ulogic_vector(2 downto 0) := "111"; -- always
|
303 |
|
|
|
304 |
|
|
-- ALU Function Codes ---------------------------------------------------------------------
|
305 |
|
|
-- -------------------------------------------------------------------------------------------
|
306 |
|
|
constant alu_rrc_c : std_ulogic_vector(3 downto 0) := "0000"; -- r <= a >>> 1, rotate right through carry
|
307 |
|
|
constant alu_swap_c : std_ulogic_vector(3 downto 0) := "0001"; -- r <= swap bytes of a
|
308 |
|
|
constant alu_rra_c : std_ulogic_vector(3 downto 0) := "0010"; -- r <= a >>> 1, rotate right arithmetically
|
309 |
|
|
constant alu_sxt_c : std_ulogic_vector(3 downto 0) := "0011"; -- r <= a, sign extend byte
|
310 |
|
|
constant alu_mov_c : std_ulogic_vector(3 downto 0) := "0100"; -- r <= a
|
311 |
|
|
constant alu_add_c : std_ulogic_vector(3 downto 0) := "0101"; -- r <= a + b
|
312 |
|
|
constant alu_addc_c : std_ulogic_vector(3 downto 0) := "0110"; -- r <= a + b + carry
|
313 |
|
|
constant alu_subc_c : std_ulogic_vector(3 downto 0) := "0111"; -- r <= b - a - 1 + carry
|
314 |
|
|
constant alu_sub_c : std_ulogic_vector(3 downto 0) := "1000"; -- r <= b - a
|
315 |
|
|
constant alu_cmp_c : std_ulogic_vector(3 downto 0) := "1001"; -- b - a (no write back)
|
316 |
|
|
--constant alu_dadd_c : std_ulogic_vector(3 downto 0) := "1010"; -- r <= a + b (BCD) [NOT SUPPORTED!]
|
317 |
|
|
constant alu_bit_c : std_ulogic_vector(3 downto 0) := "1011"; -- a & b (no write back)
|
318 |
|
|
constant alu_bic_c : std_ulogic_vector(3 downto 0) := "1100"; -- r <= !a & b
|
319 |
|
|
constant alu_bis_c : std_ulogic_vector(3 downto 0) := "1101"; -- r <= a | b
|
320 |
|
|
constant alu_xor_c : std_ulogic_vector(3 downto 0) := "1110"; -- r <= a xor b
|
321 |
|
|
constant alu_and_c : std_ulogic_vector(3 downto 0) := "1111"; -- r <= a & b
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
-- The Core of the Problem: NEO430 Processor Top Entity -----------------------------------
|
325 |
|
|
-- -------------------------------------------------------------------------------------------
|
326 |
|
|
component neo430_top
|
327 |
|
|
generic (
|
328 |
|
|
-- general configuration --
|
329 |
|
|
CLOCK_SPEED : natural := 100000000; -- main clock in Hz
|
330 |
|
|
IMEM_SIZE : natural := 4*1024; -- internal IMEM size in bytes, max 32kB (default=4kB)
|
331 |
|
|
DMEM_SIZE : natural := 2*1024; -- internal DMEM size in bytes, max 28kB (default=2kB)
|
332 |
|
|
-- additional configuration --
|
333 |
|
|
USER_CODE : std_ulogic_vector(15 downto 0) := x"0000"; -- custom user code
|
334 |
|
|
-- module configuration --
|
335 |
|
|
MULDIV_USE : boolean := true; -- implement multiplier/divider unit? (default=true)
|
336 |
|
|
WB32_USE : boolean := true; -- implement WB32 unit? (default=true)
|
337 |
|
|
WDT_USE : boolean := true; -- implement WDT? (default=true)
|
338 |
|
|
GPIO_USE : boolean := true; -- implement GPIO unit? (default=true)
|
339 |
|
|
TIMER_USE : boolean := true; -- implement timer? (default=true)
|
340 |
|
|
UART_USE : boolean := true; -- implement UART? (default=true)
|
341 |
|
|
CRC_USE : boolean := true; -- implement CRC unit? (default=true)
|
342 |
|
|
CFU_USE : boolean := false; -- implement custom functions unit? (default=false)
|
343 |
|
|
PWM_USE : boolean := true; -- implement PWM controller? (default=true)
|
344 |
|
|
TWI_USE : boolean := true; -- implement two wire serial interface? (default=true)
|
345 |
|
|
SPI_USE : boolean := true; -- implement SPI? (default=true)
|
346 |
|
|
TRNG_USE : boolean := false; -- implement TRNG? (default=false)
|
347 |
|
|
EXIRQ_USE : boolean := true; -- implement EXIRQ? (default=true)
|
348 |
|
|
FREQ_GEN_USE : boolean := true; -- implement FREQ_GEN? (default=true)
|
349 |
|
|
-- boot configuration --
|
350 |
|
|
BOOTLD_USE : boolean := true; -- implement and use bootloader? (default=true)
|
351 |
|
|
IMEM_AS_ROM : boolean := false -- implement IMEM as read-only memory? (default=false)
|
352 |
|
|
);
|
353 |
|
|
port (
|
354 |
|
|
-- global control --
|
355 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
356 |
|
|
rst_i : in std_ulogic; -- global reset, async, low-active
|
357 |
|
|
-- gpio --
|
358 |
|
|
gpio_o : out std_ulogic_vector(15 downto 0); -- parallel output
|
359 |
|
|
gpio_i : in std_ulogic_vector(15 downto 0); -- parallel input
|
360 |
|
|
-- pwm channels --
|
361 |
|
|
pwm_o : out std_ulogic_vector(03 downto 0); -- pwm channels
|
362 |
|
|
-- arbitrary frequency generator --
|
363 |
|
|
freq_gen_o : out std_ulogic_vector(02 downto 0); -- programmable frequency output
|
364 |
|
|
-- serial com --
|
365 |
|
|
uart_txd_o : out std_ulogic; -- UART send data
|
366 |
|
|
uart_rxd_i : in std_ulogic; -- UART receive data
|
367 |
|
|
spi_sclk_o : out std_ulogic; -- serial clock line
|
368 |
|
|
spi_mosi_o : out std_ulogic; -- serial data line out
|
369 |
|
|
spi_miso_i : in std_ulogic; -- serial data line in
|
370 |
|
|
spi_cs_o : out std_ulogic_vector(05 downto 0); -- SPI CS
|
371 |
|
|
twi_sda_io : inout std_logic; -- twi serial data line
|
372 |
|
|
twi_scl_io : inout std_logic; -- twi serial clock line
|
373 |
|
|
-- 32-bit wishbone interface --
|
374 |
|
|
wb_adr_o : out std_ulogic_vector(31 downto 0); -- address
|
375 |
|
|
wb_dat_i : in std_ulogic_vector(31 downto 0); -- read data
|
376 |
|
|
wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
|
377 |
|
|
wb_we_o : out std_ulogic; -- read/write
|
378 |
|
|
wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
379 |
|
|
wb_stb_o : out std_ulogic; -- strobe
|
380 |
|
|
wb_cyc_o : out std_ulogic; -- valid cycle
|
381 |
|
|
wb_ack_i : in std_ulogic; -- transfer acknowledge
|
382 |
|
|
-- external interrupts --
|
383 |
|
|
ext_irq_i : in std_ulogic_vector(07 downto 0); -- external interrupt request lines
|
384 |
|
|
ext_ack_o : out std_ulogic_vector(07 downto 0) -- external interrupt request acknowledges
|
385 |
|
|
);
|
386 |
|
|
end component;
|
387 |
|
|
|
388 |
|
|
-- Component: CPU Control -----------------------------------------------------------------
|
389 |
|
|
-- -------------------------------------------------------------------------------------------
|
390 |
|
|
component neo430_control
|
391 |
|
|
port (
|
392 |
|
|
-- global control --
|
393 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
394 |
|
|
rst_i : in std_ulogic; -- global reset, low-active, async
|
395 |
|
|
-- memory interface --
|
396 |
|
|
instr_i : in std_ulogic_vector(15 downto 0); -- instruction word from memory
|
397 |
|
|
-- control --
|
398 |
|
|
sreg_i : in std_ulogic_vector(15 downto 0); -- current status register
|
399 |
|
|
ctrl_o : out std_ulogic_vector(ctrl_width_c-1 downto 0); -- control signals
|
400 |
|
|
irq_vec_o : out std_ulogic_vector(01 downto 0); -- irq channel address
|
401 |
|
|
imm_o : out std_ulogic_vector(15 downto 0); -- branch offset
|
402 |
|
|
-- irq lines --
|
403 |
|
|
irq_i : in std_ulogic_vector(03 downto 0) -- IRQ lines
|
404 |
|
|
);
|
405 |
|
|
end component;
|
406 |
|
|
|
407 |
|
|
-- Component: Register File ---------------------------------------------------------------
|
408 |
|
|
-- -------------------------------------------------------------------------------------------
|
409 |
|
|
component neo430_reg_file
|
410 |
|
|
generic (
|
411 |
|
|
BOOTLD_USE : boolean := true; -- implement and use bootloader?
|
412 |
|
|
IMEM_AS_ROM : boolean := false -- implement IMEM as read-only memory?
|
413 |
|
|
);
|
414 |
|
|
port (
|
415 |
|
|
-- global control --
|
416 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
417 |
|
|
rst_i : in std_ulogic; -- global reset, low-active, async
|
418 |
|
|
-- data input --
|
419 |
|
|
alu_i : in std_ulogic_vector(15 downto 0); -- data from alu
|
420 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- data from addr unit
|
421 |
|
|
flag_i : in std_ulogic_vector(04 downto 0); -- new ALU flags
|
422 |
|
|
-- control --
|
423 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0);
|
424 |
|
|
-- data output --
|
425 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- read data
|
426 |
|
|
sreg_o : out std_ulogic_vector(15 downto 0) -- current SR
|
427 |
|
|
);
|
428 |
|
|
end component;
|
429 |
|
|
|
430 |
|
|
-- Component: Data ALU --------------------------------------------------------------------
|
431 |
|
|
-- -------------------------------------------------------------------------------------------
|
432 |
|
|
component neo430_alu
|
433 |
|
|
port (
|
434 |
|
|
-- global control --
|
435 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
436 |
|
|
-- operands --
|
437 |
|
|
reg_i : in std_ulogic_vector(15 downto 0); -- data from reg file
|
438 |
|
|
mem_i : in std_ulogic_vector(15 downto 0); -- data from memory
|
439 |
|
|
sreg_i : in std_ulogic_vector(15 downto 0); -- current SR
|
440 |
|
|
-- control --
|
441 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0);
|
442 |
|
|
-- results --
|
443 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- result
|
444 |
|
|
flag_o : out std_ulogic_vector(04 downto 0) -- new ALU flags
|
445 |
|
|
);
|
446 |
|
|
end component;
|
447 |
|
|
|
448 |
|
|
-- Component: Address Generator -----------------------------------------------------------
|
449 |
|
|
-- -------------------------------------------------------------------------------------------
|
450 |
|
|
component neo430_addr_gen
|
451 |
|
|
port (
|
452 |
|
|
-- global control --
|
453 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
454 |
|
|
-- data input --
|
455 |
|
|
reg_i : in std_ulogic_vector(15 downto 0); -- reg file input
|
456 |
|
|
mem_i : in std_ulogic_vector(15 downto 0); -- memory input
|
457 |
|
|
imm_i : in std_ulogic_vector(15 downto 0); -- branch offset
|
458 |
|
|
irq_sel_i : in std_ulogic_vector(01 downto 0); -- IRQ vector
|
459 |
|
|
-- control --
|
460 |
|
|
ctrl_i : in std_ulogic_vector(ctrl_width_c-1 downto 0);
|
461 |
|
|
-- data output --
|
462 |
|
|
mem_addr_o : out std_ulogic_vector(15 downto 0); -- memory address
|
463 |
|
|
dwb_o : out std_ulogic_vector(15 downto 0) -- data write back output
|
464 |
|
|
);
|
465 |
|
|
end component;
|
466 |
|
|
|
467 |
|
|
-- Component: CPU core --------------------------------------------------------------------
|
468 |
|
|
-- -------------------------------------------------------------------------------------------
|
469 |
|
|
component neo430_cpu
|
470 |
|
|
generic (
|
471 |
|
|
BOOTLD_USE : boolean := true; -- implement and use bootloader?
|
472 |
|
|
IMEM_AS_ROM : boolean := false -- implement IMEM as read-only memory?
|
473 |
|
|
);
|
474 |
|
|
port(
|
475 |
|
|
-- global control --
|
476 |
|
|
clk_i : in std_ulogic; -- global clock, rising edge
|
477 |
|
|
rst_i : in std_ulogic; -- global reset, low-active, async
|
478 |
|
|
-- memory interface --
|
479 |
|
|
mem_rd_o : out std_ulogic; -- memory read
|
480 |
|
|
mem_imwe_o : out std_ulogic; -- allow writing to IMEM
|
481 |
|
|
mem_wr_o : out std_ulogic_vector(01 downto 0); -- memory write
|
482 |
|
|
mem_addr_o : out std_ulogic_vector(15 downto 0); -- address
|
483 |
|
|
mem_data_o : out std_ulogic_vector(15 downto 0); -- write data
|
484 |
|
|
mem_data_i : in std_ulogic_vector(15 downto 0); -- read data
|
485 |
|
|
-- interrupt system --
|
486 |
|
|
irq_i : in std_ulogic_vector(03 downto 0) -- interrupt requests
|
487 |
|
|
);
|
488 |
|
|
end component;
|
489 |
|
|
|
490 |
|
|
-- Component: Instruction Memory RAM (IMEM) -----------------------------------------------
|
491 |
|
|
-- -------------------------------------------------------------------------------------------
|
492 |
|
|
component neo430_imem
|
493 |
|
|
generic (
|
494 |
|
|
IMEM_SIZE : natural := 4*1024; -- internal IMEM size in bytes
|
495 |
|
|
IMEM_AS_ROM : boolean := false; -- implement IMEM as read-only memory?
|
496 |
|
|
BOOTLD_USE : boolean := true -- implement and use bootloader?
|
497 |
|
|
);
|
498 |
|
|
port (
|
499 |
|
|
clk_i : in std_ulogic; -- global clock line
|
500 |
|
|
rden_i : in std_ulogic; -- read enable
|
501 |
|
|
wren_i : in std_ulogic_vector(01 downto 0); -- write enable
|
502 |
|
|
upen_i : in std_ulogic; -- update enable
|
503 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
504 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
505 |
|
|
data_o : out std_ulogic_vector(15 downto 0) -- data out
|
506 |
|
|
);
|
507 |
|
|
end component;
|
508 |
|
|
|
509 |
|
|
-- Component: Data Memory RAM (DMEM) ------------------------------------------------------
|
510 |
|
|
-- -------------------------------------------------------------------------------------------
|
511 |
|
|
component neo430_dmem
|
512 |
|
|
generic (
|
513 |
|
|
DMEM_SIZE : natural := 2*1024 -- internal DMEM size in bytes
|
514 |
|
|
);
|
515 |
|
|
port (
|
516 |
|
|
clk_i : in std_ulogic; -- global clock line
|
517 |
|
|
rden_i : in std_ulogic; -- read enable
|
518 |
|
|
wren_i : in std_ulogic_vector(01 downto 0); -- write enable
|
519 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
520 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
521 |
|
|
data_o : out std_ulogic_vector(15 downto 0) -- data out
|
522 |
|
|
);
|
523 |
|
|
end component;
|
524 |
|
|
|
525 |
|
|
-- Component: Bootloader ROM --------------------------------------------------------------
|
526 |
|
|
-- -------------------------------------------------------------------------------------------
|
527 |
|
|
component neo430_boot_rom
|
528 |
|
|
port (
|
529 |
|
|
clk_i : in std_ulogic; -- global clock line
|
530 |
|
|
rden_i : in std_ulogic; -- read enable
|
531 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
532 |
|
|
data_o : out std_ulogic_vector(15 downto 0) -- data out
|
533 |
|
|
);
|
534 |
|
|
end component;
|
535 |
|
|
|
536 |
|
|
-- Component: Multiplier/Divider (MULDIV) -------------------------------------------------
|
537 |
|
|
-- -------------------------------------------------------------------------------------------
|
538 |
|
|
component neo430_muldiv
|
539 |
|
|
port (
|
540 |
|
|
-- host access --
|
541 |
|
|
clk_i : in std_ulogic; -- global clock line
|
542 |
|
|
rden_i : in std_ulogic; -- read enable
|
543 |
|
|
wren_i : in std_ulogic; -- write enable
|
544 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
545 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
546 |
|
|
data_o : out std_ulogic_vector(15 downto 0) -- data out
|
547 |
|
|
);
|
548 |
|
|
end component;
|
549 |
|
|
|
550 |
|
|
-- Component: 32bit Wishbone Interface (WB32) ---------------------------------------------
|
551 |
|
|
-- -------------------------------------------------------------------------------------------
|
552 |
|
|
component neo430_wb_interface
|
553 |
|
|
port (
|
554 |
|
|
-- host access --
|
555 |
|
|
clk_i : in std_ulogic; -- global clock line
|
556 |
|
|
rden_i : in std_ulogic; -- read enable
|
557 |
|
|
wren_i : in std_ulogic; -- write enable
|
558 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
559 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
560 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
561 |
|
|
-- wishbone interface --
|
562 |
|
|
wb_adr_o : out std_ulogic_vector(31 downto 0); -- address
|
563 |
|
|
wb_dat_i : in std_ulogic_vector(31 downto 0); -- read data
|
564 |
|
|
wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
|
565 |
|
|
wb_we_o : out std_ulogic; -- read/write
|
566 |
|
|
wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
|
567 |
|
|
wb_stb_o : out std_ulogic; -- strobe
|
568 |
|
|
wb_cyc_o : out std_ulogic; -- valid cycle
|
569 |
|
|
wb_ack_i : in std_ulogic -- transfer acknowledge
|
570 |
|
|
);
|
571 |
|
|
end component;
|
572 |
|
|
|
573 |
|
|
-- Component: Universal Asynchornous Receiver/Transmitter (UART) --------------------------
|
574 |
|
|
-- -------------------------------------------------------------------------------------------
|
575 |
|
|
component neo430_uart
|
576 |
|
|
port (
|
577 |
|
|
-- host access --
|
578 |
|
|
clk_i : in std_ulogic; -- global clock line
|
579 |
|
|
rden_i : in std_ulogic; -- read enable
|
580 |
|
|
wren_i : in std_ulogic; -- write enable
|
581 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
582 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
583 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
584 |
|
|
-- clock generator --
|
585 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
586 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
587 |
|
|
-- com lines --
|
588 |
|
|
uart_txd_o : out std_ulogic;
|
589 |
|
|
uart_rxd_i : in std_ulogic;
|
590 |
|
|
-- interrupts --
|
591 |
|
|
uart_irq_o : out std_ulogic -- uart rx/tx interrupt
|
592 |
|
|
);
|
593 |
|
|
end component;
|
594 |
|
|
|
595 |
|
|
-- Component: Serial Peripheral Interface (SPI) -------------------------------------------
|
596 |
|
|
-- -------------------------------------------------------------------------------------------
|
597 |
|
|
component neo430_spi
|
598 |
|
|
port (
|
599 |
|
|
-- host access --
|
600 |
|
|
clk_i : in std_ulogic; -- global clock line
|
601 |
|
|
rden_i : in std_ulogic; -- read enable
|
602 |
|
|
wren_i : in std_ulogic; -- write enable
|
603 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
604 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
605 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
606 |
|
|
-- clock generator --
|
607 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
608 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
609 |
|
|
-- com lines --
|
610 |
|
|
spi_sclk_o : out std_ulogic; -- SPI serial clock
|
611 |
|
|
spi_mosi_o : out std_ulogic; -- SPI master out, slave in
|
612 |
|
|
spi_miso_i : in std_ulogic; -- SPI master in, slave out
|
613 |
|
|
spi_cs_o : out std_ulogic_vector(05 downto 0); -- SPI CS
|
614 |
|
|
-- interrupt --
|
615 |
|
|
spi_irq_o : out std_ulogic -- transmission done interrupt
|
616 |
|
|
);
|
617 |
|
|
end component;
|
618 |
|
|
|
619 |
|
|
-- Component: General Purpose Input/Ouput Controller (GPIO) -------------------------------
|
620 |
|
|
-- -------------------------------------------------------------------------------------------
|
621 |
|
|
component neo430_gpio
|
622 |
|
|
port (
|
623 |
|
|
-- host access --
|
624 |
|
|
clk_i : in std_ulogic; -- global clock line
|
625 |
|
|
rden_i : in std_ulogic; -- read enable
|
626 |
|
|
wren_i : in std_ulogic; -- write enable
|
627 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
628 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
629 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
630 |
|
|
-- parallel io --
|
631 |
|
|
gpio_o : out std_ulogic_vector(15 downto 0);
|
632 |
|
|
gpio_i : in std_ulogic_vector(15 downto 0);
|
633 |
|
|
-- GPIO PWM --
|
634 |
|
|
gpio_pwm_i : in std_ulogic;
|
635 |
|
|
-- interrupt --
|
636 |
|
|
irq_o : out std_ulogic
|
637 |
|
|
);
|
638 |
|
|
end component;
|
639 |
|
|
|
640 |
|
|
-- Component: High-Precision Timer (TIMER) ------------------------------------------------
|
641 |
|
|
-- -------------------------------------------------------------------------------------------
|
642 |
|
|
component neo430_timer
|
643 |
|
|
port (
|
644 |
|
|
-- host access --
|
645 |
|
|
clk_i : in std_ulogic; -- global clock line
|
646 |
|
|
rden_i : in std_ulogic; -- read enable
|
647 |
|
|
wren_i : in std_ulogic; -- write enable
|
648 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
649 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
650 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
651 |
|
|
-- clock generator --
|
652 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
653 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
654 |
|
|
-- interrupt --
|
655 |
|
|
irq_o : out std_ulogic -- interrupt request
|
656 |
|
|
);
|
657 |
|
|
end component;
|
658 |
|
|
|
659 |
|
|
-- Component: Watchdog Timer (WDT) --------------------------------------------------------
|
660 |
|
|
-- -------------------------------------------------------------------------------------------
|
661 |
|
|
component neo430_wdt
|
662 |
|
|
port (
|
663 |
|
|
-- host access --
|
664 |
|
|
clk_i : in std_ulogic; -- global clock line
|
665 |
|
|
rst_i : in std_ulogic; -- global (external) reset, low-active, use as async
|
666 |
|
|
rden_i : in std_ulogic; -- read enable
|
667 |
|
|
wren_i : in std_ulogic; -- write enable
|
668 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
669 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
670 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
671 |
|
|
-- clock generator --
|
672 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
673 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
674 |
|
|
-- system reset --
|
675 |
|
|
rst_o : out std_ulogic -- timeout reset, low_active, use as async
|
676 |
|
|
);
|
677 |
|
|
end component;
|
678 |
|
|
|
679 |
|
|
-- Component: Cyclic Redundancy Check Unit (CRC)-------------------------------------------
|
680 |
|
|
-- -------------------------------------------------------------------------------------------
|
681 |
|
|
component neo430_crc
|
682 |
|
|
port (
|
683 |
|
|
-- host access --
|
684 |
|
|
clk_i : in std_ulogic; -- global clock line
|
685 |
|
|
rden_i : in std_ulogic; -- read enable
|
686 |
|
|
wren_i : in std_ulogic; -- write enable
|
687 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
688 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
689 |
|
|
data_o : out std_ulogic_vector(15 downto 0) -- data out
|
690 |
|
|
);
|
691 |
|
|
end component;
|
692 |
|
|
|
693 |
|
|
-- Component: Custom Functions Unit (CFU) -------------------------------------------------
|
694 |
|
|
-- -------------------------------------------------------------------------------------------
|
695 |
|
|
component neo430_cfu
|
696 |
|
|
port (
|
697 |
|
|
-- host access --
|
698 |
|
|
clk_i : in std_ulogic; -- global clock line
|
699 |
|
|
rden_i : in std_ulogic; -- read enable
|
700 |
|
|
wren_i : in std_ulogic; -- write enable
|
701 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
702 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
703 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
704 |
|
|
-- clock generator --
|
705 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
706 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0)
|
707 |
|
|
-- custom IOs --
|
708 |
|
|
-- ...
|
709 |
|
|
);
|
710 |
|
|
end component;
|
711 |
|
|
|
712 |
|
|
-- Component: PWM Controller (PWM) --------------------------------------------------------
|
713 |
|
|
-- -------------------------------------------------------------------------------------------
|
714 |
|
|
component neo430_pwm
|
715 |
|
|
port (
|
716 |
|
|
-- host access --
|
717 |
|
|
clk_i : in std_ulogic; -- global clock line
|
718 |
|
|
rden_i : in std_ulogic; -- read enable
|
719 |
|
|
wren_i : in std_ulogic; -- write enable
|
720 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
721 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
722 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
723 |
|
|
-- clock generator --
|
724 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
725 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
726 |
|
|
-- GPIO output PWM --
|
727 |
|
|
gpio_pwm_o : out std_ulogic;
|
728 |
|
|
-- pwm output channels --
|
729 |
|
|
pwm_o : out std_ulogic_vector(03 downto 0)
|
730 |
|
|
);
|
731 |
|
|
end component;
|
732 |
|
|
|
733 |
|
|
-- Component: Serial Two Wire Interfcae (TWI) ---------------------------------------------
|
734 |
|
|
-- -------------------------------------------------------------------------------------------
|
735 |
|
|
component neo430_twi
|
736 |
|
|
port (
|
737 |
|
|
-- host access --
|
738 |
|
|
clk_i : in std_ulogic; -- global clock line
|
739 |
|
|
rden_i : in std_ulogic; -- read enable
|
740 |
|
|
wren_i : in std_ulogic; -- write enable
|
741 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
742 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
743 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
744 |
|
|
-- clock generator --
|
745 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
746 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
747 |
|
|
-- com lines --
|
748 |
|
|
twi_sda_io : inout std_logic; -- serial data line
|
749 |
|
|
twi_scl_io : inout std_logic; -- serial clock line
|
750 |
|
|
-- interrupt --
|
751 |
|
|
twi_irq_o : out std_ulogic -- transfer done IRQ
|
752 |
|
|
);
|
753 |
|
|
end component;
|
754 |
|
|
|
755 |
|
|
-- Component: True Random Number Generator (TRNG) -----------------------------------------
|
756 |
|
|
-- -------------------------------------------------------------------------------------------
|
757 |
|
|
component neo430_trng
|
758 |
|
|
port (
|
759 |
|
|
-- host access --
|
760 |
|
|
clk_i : in std_ulogic; -- global clock line
|
761 |
|
|
rden_i : in std_ulogic; -- read enable
|
762 |
|
|
wren_i : in std_ulogic; -- write enable
|
763 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
764 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
765 |
|
|
data_o : out std_ulogic_vector(15 downto 0) -- data out
|
766 |
|
|
);
|
767 |
|
|
end component;
|
768 |
|
|
|
769 |
|
|
-- Component: External Interrupts Controller (EXIRQ) --------------------------------------
|
770 |
|
|
-- -------------------------------------------------------------------------------------------
|
771 |
|
|
component neo430_exirq
|
772 |
|
|
port (
|
773 |
|
|
-- host access --
|
774 |
|
|
clk_i : in std_ulogic; -- global clock line
|
775 |
|
|
rden_i : in std_ulogic; -- read enable
|
776 |
|
|
wren_i : in std_ulogic; -- write enable
|
777 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
778 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
779 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
780 |
|
|
-- cpu interrupt --
|
781 |
|
|
cpu_irq_o : out std_ulogic;
|
782 |
|
|
-- external interrupt lines --
|
783 |
|
|
ext_irq_i : in std_ulogic_vector(7 downto 0); -- IRQ
|
784 |
|
|
ext_ack_o : out std_ulogic_vector(7 downto 0) -- acknowledge
|
785 |
|
|
);
|
786 |
|
|
end component;
|
787 |
|
|
|
788 |
|
|
-- Component: Arbitrary Frequency Generator (FREG_GEN)) -----------------------------------
|
789 |
|
|
-- -------------------------------------------------------------------------------------------
|
790 |
|
|
component neo430_freq_gen
|
791 |
|
|
port (
|
792 |
|
|
-- host access --
|
793 |
|
|
clk_i : in std_ulogic; -- global clock line
|
794 |
|
|
rden_i : in std_ulogic; -- read enable
|
795 |
|
|
wren_i : in std_ulogic; -- write enable
|
796 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
797 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
798 |
|
|
data_o : out std_ulogic_vector(15 downto 0); -- data out
|
799 |
|
|
-- clock generator --
|
800 |
|
|
clkgen_en_o : out std_ulogic; -- enable clock generator
|
801 |
|
|
clkgen_i : in std_ulogic_vector(07 downto 0);
|
802 |
|
|
-- frequency generator --
|
803 |
|
|
freq_gen_o : out std_ulogic_vector(02 downto 0) -- programmable frequency output
|
804 |
|
|
);
|
805 |
|
|
end component;
|
806 |
|
|
|
807 |
|
|
-- Component: System Configuration (SYSCONFIG) --------------------------------------------
|
808 |
|
|
-- -------------------------------------------------------------------------------------------
|
809 |
|
|
component neo430_sysconfig
|
810 |
|
|
generic (
|
811 |
|
|
-- general configuration --
|
812 |
|
|
CLOCK_SPEED : natural := 100000000; -- main clock in Hz
|
813 |
|
|
IMEM_SIZE : natural := 4*1024; -- internal IMEM size in bytes
|
814 |
|
|
DMEM_SIZE : natural := 2*1024; -- internal DMEM size in bytes
|
815 |
|
|
-- additional configuration --
|
816 |
|
|
USER_CODE : std_ulogic_vector(15 downto 0) := x"0000"; -- custom user code
|
817 |
|
|
-- module configuration --
|
818 |
|
|
MULDIV_USE : boolean := true; -- implement multiplier/divider unit?
|
819 |
|
|
WB32_USE : boolean := true; -- implement WB32 unit?
|
820 |
|
|
WDT_USE : boolean := true; -- implement WDT?
|
821 |
|
|
GPIO_USE : boolean := true; -- implement GPIO unit?
|
822 |
|
|
TIMER_USE : boolean := true; -- implement timer?
|
823 |
|
|
UART_USE : boolean := true; -- implement UART?
|
824 |
|
|
CRC_USE : boolean := true; -- implement CRC unit?
|
825 |
|
|
CFU_USE : boolean := true; -- implement CF unit?
|
826 |
|
|
PWM_USE : boolean := true; -- implement PWM controller?
|
827 |
|
|
TWI_USE : boolean := true; -- implement TWI?
|
828 |
|
|
SPI_USE : boolean := true; -- implement SPI?
|
829 |
|
|
TRNG_USE : boolean := true; -- implement TRNG?
|
830 |
|
|
EXIRQ_USE : boolean := true; -- implement EXIRQ?
|
831 |
|
|
FREQ_GEN_USE : boolean := true; -- implement FREQ_GEN?
|
832 |
|
|
-- boot configuration --
|
833 |
|
|
BOOTLD_USE : boolean := true; -- implement and use bootloader?
|
834 |
|
|
IMEM_AS_ROM : boolean := false -- implement IMEM as read-only memory?
|
835 |
|
|
);
|
836 |
|
|
port (
|
837 |
|
|
clk_i : in std_ulogic; -- global clock line
|
838 |
|
|
rden_i : in std_ulogic; -- read enable
|
839 |
|
|
wren_i : in std_ulogic; -- write enable
|
840 |
|
|
addr_i : in std_ulogic_vector(15 downto 0); -- address
|
841 |
|
|
data_i : in std_ulogic_vector(15 downto 0); -- data in
|
842 |
|
|
data_o : out std_ulogic_vector(15 downto 0) -- data out
|
843 |
|
|
);
|
844 |
|
|
end component;
|
845 |
|
|
|
846 |
|
|
end neo430_package;
|
847 |
|
|
|
848 |
|
|
package body neo430_package is
|
849 |
|
|
|
850 |
|
|
-- Function: Minimal required bit width ---------------------------------------------------
|
851 |
|
|
-- -------------------------------------------------------------------------------------------
|
852 |
|
|
function index_size_f(input : natural) return natural is
|
853 |
|
|
begin
|
854 |
|
|
for i in 0 to natural'high loop
|
855 |
|
|
if (2**i >= input) then
|
856 |
|
|
return i;
|
857 |
|
|
end if;
|
858 |
|
|
end loop; -- i
|
859 |
|
|
return 0;
|
860 |
|
|
end function index_size_f;
|
861 |
|
|
|
862 |
|
|
-- Function: Test if value (encoded with a certain bit width) is a power of 2 -------------
|
863 |
|
|
-- -------------------------------------------------------------------------------------------
|
864 |
|
|
function is_power_of_two_f(num : natural; bit_width : natural) return boolean is
|
865 |
|
|
begin
|
866 |
|
|
for i in 0 to bit_width loop
|
867 |
|
|
if ((2**i) = num) then
|
868 |
|
|
return true;
|
869 |
|
|
end if;
|
870 |
|
|
end loop; -- i
|
871 |
|
|
return false;
|
872 |
|
|
end function is_power_of_two_f;
|
873 |
|
|
|
874 |
|
|
-- Function: Bit reversal -----------------------------------------------------------------
|
875 |
|
|
-- -------------------------------------------------------------------------------------------
|
876 |
|
|
function bit_reversal_f(input : std_ulogic_vector) return std_ulogic_vector is
|
877 |
|
|
variable output_v : std_ulogic_vector(input'range);
|
878 |
|
|
begin
|
879 |
|
|
for i in 0 to input'length-1 loop
|
880 |
|
|
output_v(input'length-i-1) := input(i);
|
881 |
|
|
end loop; -- i
|
882 |
|
|
return output_v;
|
883 |
|
|
end function bit_reversal_f;
|
884 |
|
|
|
885 |
|
|
-- Function: Count number of set bits (aka population count) ------------------------------
|
886 |
|
|
-- -------------------------------------------------------------------------------------------
|
887 |
|
|
function set_bits_f(input : std_ulogic_vector) return natural is
|
888 |
|
|
variable cnt_v : natural range 0 to input'length-1;
|
889 |
|
|
begin
|
890 |
|
|
cnt_v := 0;
|
891 |
|
|
for i in input'length-1 downto 0 loop
|
892 |
|
|
if (input(i) = '1') then
|
893 |
|
|
cnt_v := cnt_v + 1;
|
894 |
|
|
end if;
|
895 |
|
|
end loop; -- i
|
896 |
|
|
return cnt_v;
|
897 |
|
|
end function set_bits_f;
|
898 |
|
|
|
899 |
|
|
-- Function: Count leading zeros ----------------------------------------------------------
|
900 |
|
|
-- -------------------------------------------------------------------------------------------
|
901 |
|
|
function leading_zeros_f(input : std_ulogic_vector) return natural is
|
902 |
|
|
variable cnt_v : natural range 0 to input'length;
|
903 |
|
|
begin
|
904 |
|
|
cnt_v := 0;
|
905 |
|
|
for i in input'length-1 downto 0 loop
|
906 |
|
|
if (input(i) = '0') then
|
907 |
|
|
cnt_v := cnt_v + 1;
|
908 |
|
|
else
|
909 |
|
|
exit;
|
910 |
|
|
end if;
|
911 |
|
|
end loop; -- i
|
912 |
|
|
return cnt_v;
|
913 |
|
|
end function leading_zeros_f;
|
914 |
|
|
|
915 |
|
|
-- Function: Conditional select natural ---------------------------------------------------
|
916 |
|
|
-- -------------------------------------------------------------------------------------------
|
917 |
|
|
function cond_sel_natural_f(cond : boolean; val_t : natural; val_f : natural) return natural is
|
918 |
|
|
begin
|
919 |
|
|
if (cond = true) then
|
920 |
|
|
return val_t;
|
921 |
|
|
else
|
922 |
|
|
return val_f;
|
923 |
|
|
end if;
|
924 |
|
|
end function cond_sel_natural_f;
|
925 |
|
|
|
926 |
|
|
-- Function: Conditional select std_ulogic_vector -----------------------------------------
|
927 |
|
|
-- -------------------------------------------------------------------------------------------
|
928 |
|
|
function cond_sel_stdulogicvector_f(cond : boolean; val_t : std_ulogic_vector; val_f : std_ulogic_vector) return std_ulogic_vector is
|
929 |
|
|
begin
|
930 |
|
|
if (cond = true) then
|
931 |
|
|
return val_t;
|
932 |
|
|
else
|
933 |
|
|
return val_f;
|
934 |
|
|
end if;
|
935 |
|
|
end function cond_sel_stdulogicvector_f;
|
936 |
|
|
|
937 |
|
|
-- Function: Convert BOOL to STD_ULOGIC ---------------------------------------------------
|
938 |
|
|
-- -------------------------------------------------------------------------------------------
|
939 |
|
|
function bool_to_ulogic_f(cond : boolean) return std_ulogic is
|
940 |
|
|
begin
|
941 |
|
|
if (cond = true) then
|
942 |
|
|
return '1';
|
943 |
|
|
else
|
944 |
|
|
return '0';
|
945 |
|
|
end if;
|
946 |
|
|
end function bool_to_ulogic_f;
|
947 |
|
|
|
948 |
|
|
-- Function: Binary to Gray ---------------------------------------------------------------
|
949 |
|
|
-- -------------------------------------------------------------------------------------------
|
950 |
|
|
function bin_to_gray_f(input : std_ulogic_vector) return std_ulogic_vector is
|
951 |
|
|
variable output_v : std_ulogic_vector(input'range);
|
952 |
|
|
begin
|
953 |
|
|
output_v(input'length-1) := input(input'length-1); -- keep MSB
|
954 |
|
|
for i in input'length-2 downto 0 loop
|
955 |
|
|
output_v(i) := input(i) xor input(i+1);
|
956 |
|
|
end loop; -- i
|
957 |
|
|
return output_v;
|
958 |
|
|
end function bin_to_gray_f;
|
959 |
|
|
|
960 |
|
|
-- Function: Gray to Binary ---------------------------------------------------------------
|
961 |
|
|
-- -------------------------------------------------------------------------------------------
|
962 |
|
|
function gray_to_bin_f(input : std_ulogic_vector) return std_ulogic_vector is
|
963 |
|
|
variable output_v : std_ulogic_vector(input'range);
|
964 |
|
|
begin
|
965 |
|
|
output_v(input'length-1) := input(input'length-1); -- keep MSB
|
966 |
|
|
for i in input'length-2 downto 0 loop
|
967 |
|
|
output_v(i) := output_v(i+1) xor input(i);
|
968 |
|
|
end loop; -- i
|
969 |
|
|
return output_v;
|
970 |
|
|
end function gray_to_bin_f;
|
971 |
|
|
|
972 |
|
|
-- Function: Integer (4-bit) to hex char --------------------------------------------------
|
973 |
|
|
-- -------------------------------------------------------------------------------------------
|
974 |
|
|
function int_to_hexchar_f(input : integer) return character is
|
975 |
|
|
variable output_v : character;
|
976 |
|
|
begin
|
977 |
|
|
case (input) is
|
978 |
|
|
when 0 => output_v := '0';
|
979 |
|
|
when 1 => output_v := '1';
|
980 |
|
|
when 2 => output_v := '2';
|
981 |
|
|
when 3 => output_v := '3';
|
982 |
|
|
when 4 => output_v := '4';
|
983 |
|
|
when 5 => output_v := '5';
|
984 |
|
|
when 6 => output_v := '6';
|
985 |
|
|
when 7 => output_v := '7';
|
986 |
|
|
when 8 => output_v := '8';
|
987 |
|
|
when 9 => output_v := '9';
|
988 |
|
|
when 10 => output_v := 'A';
|
989 |
|
|
when 11 => output_v := 'B';
|
990 |
|
|
when 12 => output_v := 'C';
|
991 |
|
|
when 13 => output_v := 'D';
|
992 |
|
|
when 14 => output_v := 'E';
|
993 |
|
|
when 15 => output_v := 'F';
|
994 |
|
|
when others => output_v := '?';
|
995 |
|
|
end case;
|
996 |
|
|
return output_v;
|
997 |
|
|
end function int_to_hexchar_f;
|
998 |
|
|
|
999 |
|
|
-- Function: OR all bits ------------------------------------------------------------------
|
1000 |
|
|
-- -------------------------------------------------------------------------------------------
|
1001 |
|
|
function or_all_f(a : std_ulogic_vector) return std_ulogic is
|
1002 |
|
|
variable tmp_v : std_ulogic;
|
1003 |
|
|
begin
|
1004 |
|
|
tmp_v := a(a'low);
|
1005 |
|
|
for i in a'low+1 to a'high loop
|
1006 |
|
|
tmp_v := tmp_v or a(i);
|
1007 |
|
|
end loop; -- i
|
1008 |
|
|
return tmp_v;
|
1009 |
|
|
end function or_all_f;
|
1010 |
|
|
|
1011 |
|
|
-- Function: AND all bits -----------------------------------------------------------------
|
1012 |
|
|
-- -------------------------------------------------------------------------------------------
|
1013 |
|
|
function and_all_f(a : std_ulogic_vector) return std_ulogic is
|
1014 |
|
|
variable tmp_v : std_ulogic;
|
1015 |
|
|
begin
|
1016 |
|
|
tmp_v := a(a'low);
|
1017 |
|
|
for i in a'low+1 to a'high loop
|
1018 |
|
|
tmp_v := tmp_v and a(i);
|
1019 |
|
|
end loop; -- i
|
1020 |
|
|
return tmp_v;
|
1021 |
|
|
end function and_all_f;
|
1022 |
|
|
|
1023 |
|
|
-- Function: XOR all bits -----------------------------------------------------------------
|
1024 |
|
|
-- -------------------------------------------------------------------------------------------
|
1025 |
|
|
function xor_all_f(a : std_ulogic_vector) return std_ulogic is
|
1026 |
|
|
variable tmp_v : std_ulogic;
|
1027 |
|
|
begin
|
1028 |
|
|
tmp_v := a(a'low);
|
1029 |
|
|
for i in a'low+1 to a'high loop
|
1030 |
|
|
tmp_v := tmp_v xor a(i);
|
1031 |
|
|
end loop; -- i
|
1032 |
|
|
return tmp_v;
|
1033 |
|
|
end function xor_all_f;
|
1034 |
|
|
|
1035 |
|
|
end neo430_package;
|