OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_sysinfo.vhd] - Blame information for rev 69

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - System/Processor Configuration Information Memory (SYSINFO) >>                   #
3
-- # ********************************************************************************************* #
4 47 zero_gravi
-- # This unit provides information regarding the NEORV32 processor system configuration -         #
5 18 zero_gravi
-- # mostly derived from the top's configuration generics.                                         #
6 12 zero_gravi
-- # ********************************************************************************************* #
7
-- # BSD 3-Clause License                                                                          #
8
-- #                                                                                               #
9 44 zero_gravi
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
10 12 zero_gravi
-- #                                                                                               #
11
-- # Redistribution and use in source and binary forms, with or without modification, are          #
12
-- # permitted provided that the following conditions are met:                                     #
13
-- #                                                                                               #
14
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
15
-- #    conditions and the following disclaimer.                                                   #
16
-- #                                                                                               #
17
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
18
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
19
-- #    provided with the distribution.                                                            #
20
-- #                                                                                               #
21
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
22
-- #    endorse or promote products derived from this software without specific prior written      #
23
-- #    permission.                                                                                #
24
-- #                                                                                               #
25
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
26
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
27
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
28
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
29
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
30
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
31
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
32
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
33
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
34
-- # ********************************************************************************************* #
35
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
36
-- #################################################################################################
37
 
38
library ieee;
39
use ieee.std_logic_1164.all;
40
use ieee.numeric_std.all;
41
 
42
library neorv32;
43
use neorv32.neorv32_package.all;
44
 
45
entity neorv32_sysinfo is
46
  generic (
47
    -- General --
48 63 zero_gravi
    CLOCK_FREQUENCY              : natural; -- clock frequency of clk_i in Hz
49
    INT_BOOTLOADER_EN            : boolean; -- boot configuration: true = boot explicit bootloader; false = boot from int/ext (I)MEM
50
    -- RISC-V CPU Extensions --
51
    CPU_EXTENSION_RISCV_Zfinx    : boolean; -- implement 32-bit floating-point extension (using INT reg!)
52
    CPU_EXTENSION_RISCV_Zicsr    : boolean; -- implement CSR system?
53 66 zero_gravi
    CPU_EXTENSION_RISCV_Zicntr   : boolean; -- implement base counters?
54
    CPU_EXTENSION_RISCV_Zihpm    : boolean; -- implement hardware performance monitors?
55 63 zero_gravi
    CPU_EXTENSION_RISCV_Zifencei : boolean; -- implement instruction stream sync.?
56
    CPU_EXTENSION_RISCV_Zmmul    : boolean; -- implement multiply-only M sub-extension?
57
    CPU_EXTENSION_RISCV_DEBUG    : boolean; -- implement CPU debug mode?
58
    -- Extension Options --
59
    FAST_MUL_EN                  : boolean; -- use DSPs for M extension's multiplier
60
    FAST_SHIFT_EN                : boolean; -- use barrel shifter for shift operations
61
    CPU_CNT_WIDTH                : natural; -- total width of CPU cycle and instret counters (0..64)
62
    -- Physical memory protection (PMP) --
63
    PMP_NUM_REGIONS              : natural; -- number of regions (0..64)
64 23 zero_gravi
    -- Internal Instruction memory --
65 63 zero_gravi
    MEM_INT_IMEM_EN              : boolean; -- implement processor-internal instruction memory
66
    MEM_INT_IMEM_SIZE            : natural; -- size of processor-internal instruction memory in bytes
67 23 zero_gravi
    -- Internal Data memory --
68 63 zero_gravi
    MEM_INT_DMEM_EN              : boolean; -- implement processor-internal data memory
69
    MEM_INT_DMEM_SIZE            : natural; -- size of processor-internal data memory in bytes
70 41 zero_gravi
    -- Internal Cache memory --
71 63 zero_gravi
    ICACHE_EN                    : boolean; -- implement instruction cache
72
    ICACHE_NUM_BLOCKS            : natural; -- i-cache: number of blocks (min 2), has to be a power of 2
73
    ICACHE_BLOCK_SIZE            : natural; -- i-cache: block size in bytes (min 4), has to be a power of 2
74
    ICACHE_ASSOCIATIVITY         : natural; -- i-cache: associativity (min 1), has to be a power 2
75 23 zero_gravi
    -- External memory interface --
76 63 zero_gravi
    MEM_EXT_EN                   : boolean; -- implement external memory bus interface?
77
    MEM_EXT_BIG_ENDIAN           : boolean; -- byte order: true=big-endian, false=little-endian
78 59 zero_gravi
    -- On-Chip Debugger --
79 63 zero_gravi
    ON_CHIP_DEBUGGER_EN          : boolean; -- implement OCD?
80 12 zero_gravi
    -- Processor peripherals --
81 63 zero_gravi
    IO_GPIO_EN                   : boolean; -- implement general purpose input/output port unit (GPIO)?
82
    IO_MTIME_EN                  : boolean; -- implement machine system timer (MTIME)?
83
    IO_UART0_EN                  : boolean; -- implement primary universal asynchronous receiver/transmitter (UART0)?
84
    IO_UART1_EN                  : boolean; -- implement secondary universal asynchronous receiver/transmitter (UART1)?
85
    IO_SPI_EN                    : boolean; -- implement serial peripheral interface (SPI)?
86
    IO_TWI_EN                    : boolean; -- implement two-wire interface (TWI)?
87
    IO_PWM_NUM_CH                : natural; -- number of PWM channels to implement
88
    IO_WDT_EN                    : boolean; -- implement watch dog timer (WDT)?
89
    IO_TRNG_EN                   : boolean; -- implement true random number generator (TRNG)?
90
    IO_CFS_EN                    : boolean; -- implement custom functions subsystem (CFS)?
91
    IO_SLINK_EN                  : boolean; -- implement stream link interface?
92
    IO_NEOLED_EN                 : boolean; -- implement NeoPixel-compatible smart LED interface (NEOLED)?
93 67 zero_gravi
    IO_XIRQ_NUM_CH               : natural; -- number of external interrupt (XIRQ) channels to implement
94
    IO_GPTMR_EN                  : boolean  -- implement general purpose timer (GPTMR)?
95 12 zero_gravi
  );
96
  port (
97
    -- host access --
98
    clk_i  : in  std_ulogic; -- global clock line
99
    addr_i : in  std_ulogic_vector(31 downto 0); -- address
100
    rden_i : in  std_ulogic; -- read enable
101
    data_o : out std_ulogic_vector(31 downto 0); -- data out
102
    ack_o  : out std_ulogic  -- transfer acknowledge
103
  );
104
end neorv32_sysinfo;
105
 
106
architecture neorv32_sysinfo_rtl of neorv32_sysinfo is
107
 
108
  -- IO space: module base address --
109
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
110
  constant lo_abb_c : natural := index_size_f(sysinfo_size_c); -- low address boundary bit
111
 
112
  -- access control --
113
  signal acc_en    : std_ulogic; -- module access enable
114
  signal addr      : std_ulogic_vector(31 downto 0);
115
  signal rden      : std_ulogic;
116
  signal info_addr : std_ulogic_vector(02 downto 0);
117
 
118
  -- system information ROM --
119
  type info_mem_t is array (0 to 7) of std_ulogic_vector(31 downto 0);
120
  signal sysinfo_mem : info_mem_t;
121
 
122
begin
123
 
124
  -- Access Control -------------------------------------------------------------------------
125
  -- -------------------------------------------------------------------------------------------
126
  acc_en    <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = sysinfo_base_c(hi_abb_c downto lo_abb_c)) else '0';
127
  rden      <= acc_en and rden_i; -- valid read access
128
  addr      <= sysinfo_base_c(31 downto lo_abb_c) & addr_i(lo_abb_c-1 downto 2) & "00"; -- word aligned
129
  info_addr <= addr(index_size_f(sysinfo_size_c)-1 downto 2);
130
 
131
 
132
  -- Construct Info ROM ---------------------------------------------------------------------
133
  -- -------------------------------------------------------------------------------------------
134
 
135
  -- SYSINFO(0): Processor (primary) clock frequency --
136
  sysinfo_mem(0) <= std_ulogic_vector(to_unsigned(CLOCK_FREQUENCY, 32));
137
 
138 63 zero_gravi
  -- SYSINFO(1): CPU configuration --
139
  sysinfo_mem(1)(00) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zicsr);    -- Zicsr
140
  sysinfo_mem(1)(01) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zifencei); -- Zifencei
141
  sysinfo_mem(1)(02) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zmmul);    -- Zmmul
142
  --
143 66 zero_gravi
  sysinfo_mem(1)(04 downto 03) <= (others => '0'); -- reserved
144 63 zero_gravi
  --
145
  sysinfo_mem(1)(05) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zfinx);    -- Zfinx ("F-alternative")
146 66 zero_gravi
  sysinfo_mem(1)(06) <= bool_to_ulogic_f(boolean(CPU_CNT_WIDTH /= 64)); -- reduced-size CPU counters (Zxscnt)
147
  sysinfo_mem(1)(07) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zicntr);   -- base CPU counter
148 63 zero_gravi
  sysinfo_mem(1)(08) <= bool_to_ulogic_f(boolean(PMP_NUM_REGIONS > 0)); -- PMP (physical memory protection)
149 66 zero_gravi
  sysinfo_mem(1)(09) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zihpm);    -- HPM (hardware performance monitors)
150 63 zero_gravi
  sysinfo_mem(1)(10) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_DEBUG);    -- RISC-V debug mode
151
  --
152
  sysinfo_mem(1)(29 downto 11) <= (others => '0'); -- reserved
153
  -- misc --
154
  sysinfo_mem(1)(30) <= bool_to_ulogic_f(FAST_MUL_EN);                  -- DSP-based multiplication (M extension only)
155
  sysinfo_mem(1)(31) <= bool_to_ulogic_f(FAST_SHIFT_EN);                -- parallel logic for shifts (like barrel shifters)
156 12 zero_gravi
 
157
  -- SYSINFO(2): Implemented processor devices/features --
158 23 zero_gravi
  -- Memory --
159 61 zero_gravi
  sysinfo_mem(2)(00) <= bool_to_ulogic_f(INT_BOOTLOADER_EN); -- processor-internal bootloader implemented?
160 44 zero_gravi
  sysinfo_mem(2)(01) <= bool_to_ulogic_f(MEM_EXT_EN);        -- external memory bus interface implemented?
161 68 zero_gravi
  sysinfo_mem(2)(02) <= bool_to_ulogic_f(MEM_INT_IMEM_EN) and bool_to_ulogic_f(boolean(MEM_INT_IMEM_SIZE > 0)); -- processor-internal instruction memory implemented?
162
  sysinfo_mem(2)(03) <= bool_to_ulogic_f(MEM_INT_DMEM_EN) and bool_to_ulogic_f(boolean(MEM_INT_DMEM_SIZE > 0)); -- processor-internal data memory implemented?
163 62 zero_gravi
  sysinfo_mem(2)(04) <= bool_to_ulogic_f(MEM_EXT_BIG_ENDIAN); -- is external memory bus interface using BIG-endian byte-order?
164 61 zero_gravi
  sysinfo_mem(2)(05) <= bool_to_ulogic_f(ICACHE_EN);         -- processor-internal instruction cache implemented?
165 23 zero_gravi
  --
166 69 zero_gravi
  sysinfo_mem(2)(12 downto 06) <= (others => '0'); -- reserved
167 57 zero_gravi
  -- Misc --
168 69 zero_gravi
  sysinfo_mem(2)(13) <= bool_to_ulogic_f(is_simulation_c);     -- is this a simulation?
169 59 zero_gravi
  sysinfo_mem(2)(14) <= bool_to_ulogic_f(ON_CHIP_DEBUGGER_EN); -- on-chip debugger implemented?
170
  sysinfo_mem(2)(15) <= bool_to_ulogic_f(dedicated_reset_c);   -- dedicated hardware reset of all core registers?
171 23 zero_gravi
  -- IO --
172 52 zero_gravi
  sysinfo_mem(2)(16) <= bool_to_ulogic_f(IO_GPIO_EN);   -- general purpose input/output port unit (GPIO) implemented?
173
  sysinfo_mem(2)(17) <= bool_to_ulogic_f(IO_MTIME_EN);  -- machine system timer (MTIME) implemented?
174
  sysinfo_mem(2)(18) <= bool_to_ulogic_f(IO_UART0_EN);  -- primary universal asynchronous receiver/transmitter (UART0) implemented?
175
  sysinfo_mem(2)(19) <= bool_to_ulogic_f(IO_SPI_EN);    -- serial peripheral interface (SPI) implemented?
176
  sysinfo_mem(2)(20) <= bool_to_ulogic_f(IO_TWI_EN);    -- two-wire interface (TWI) implemented?
177 60 zero_gravi
  sysinfo_mem(2)(21) <= bool_to_ulogic_f(boolean(IO_PWM_NUM_CH > 0)); -- pulse-width modulation unit (PWM) implemented?
178 52 zero_gravi
  sysinfo_mem(2)(22) <= bool_to_ulogic_f(IO_WDT_EN);    -- watch dog timer (WDT) implemented?
179
  sysinfo_mem(2)(23) <= bool_to_ulogic_f(IO_CFS_EN);    -- custom functions subsystem (CFS) implemented?
180
  sysinfo_mem(2)(24) <= bool_to_ulogic_f(IO_TRNG_EN);   -- true random number generator (TRNG) implemented?
181 61 zero_gravi
  sysinfo_mem(2)(25) <= bool_to_ulogic_f(IO_SLINK_EN);  -- stream links (SLINK) implemented?
182 52 zero_gravi
  sysinfo_mem(2)(26) <= bool_to_ulogic_f(IO_UART1_EN);  -- secondary universal asynchronous receiver/transmitter (UART1) implemented?
183
  sysinfo_mem(2)(27) <= bool_to_ulogic_f(IO_NEOLED_EN); -- NeoPixel-compatible smart LED interface (NEOLED) implemented?
184 61 zero_gravi
  sysinfo_mem(2)(28) <= bool_to_ulogic_f(boolean(IO_XIRQ_NUM_CH > 0)); -- external interrupt controller (XIRQ) implemented?
185 67 zero_gravi
  sysinfo_mem(2)(29) <= bool_to_ulogic_f(IO_GPTMR_EN);  -- general purpose timer (GPTMR) implemented?
186 23 zero_gravi
  --
187 67 zero_gravi
  sysinfo_mem(2)(31 downto 30) <= (others => '0'); -- reserved
188 12 zero_gravi
 
189 41 zero_gravi
  -- SYSINFO(3): Cache configuration --
190 45 zero_gravi
  sysinfo_mem(3)(03 downto 00) <= std_ulogic_vector(to_unsigned(index_size_f(ICACHE_BLOCK_SIZE),    4)) when (ICACHE_EN = true) else (others => '0'); -- i-cache: log2(block_size_in_bytes)
191
  sysinfo_mem(3)(07 downto 04) <= std_ulogic_vector(to_unsigned(index_size_f(ICACHE_NUM_BLOCKS),    4)) when (ICACHE_EN = true) else (others => '0'); -- i-cache: log2(number_of_block)
192 44 zero_gravi
  sysinfo_mem(3)(11 downto 08) <= std_ulogic_vector(to_unsigned(index_size_f(ICACHE_ASSOCIATIVITY), 4)) when (ICACHE_EN = true) else (others => '0'); -- i-cache: log2(associativity)
193 45 zero_gravi
  sysinfo_mem(3)(15 downto 12) <= "0001" when (ICACHE_ASSOCIATIVITY > 1) and (ICACHE_EN = true) else (others => '0'); -- i-cache: replacement strategy (LRU only (yet))
194 41 zero_gravi
  --
195 45 zero_gravi
  sysinfo_mem(3)(19 downto 16) <= (others => '0'); -- reserved - d-cache: log2(block_size)
196
  sysinfo_mem(3)(23 downto 20) <= (others => '0'); -- reserved - d-cache: log2(num_blocks)
197
  sysinfo_mem(3)(27 downto 24) <= (others => '0'); -- reserved - d-cache: log2(associativity)
198
  sysinfo_mem(3)(31 downto 28) <= (others => '0'); -- reserved - d-cache: replacement strategy
199 12 zero_gravi
 
200
  -- SYSINFO(4): Base address of instruction memory space --
201 23 zero_gravi
  sysinfo_mem(4) <= ispace_base_c; -- defined in neorv32_package.vhd file
202 12 zero_gravi
 
203
  -- SYSINFO(5): Base address of data memory space --
204 23 zero_gravi
  sysinfo_mem(5) <= dspace_base_c; -- defined in neorv32_package.vhd file
205 12 zero_gravi
 
206 23 zero_gravi
  -- SYSINFO(6): Size of IMEM in bytes --
207 44 zero_gravi
  sysinfo_mem(6) <= std_ulogic_vector(to_unsigned(MEM_INT_IMEM_SIZE, 32)) when (MEM_INT_IMEM_EN = true) else (others => '0');
208 12 zero_gravi
 
209 23 zero_gravi
  -- SYSINFO(7): Size of DMEM in bytes --
210 44 zero_gravi
  sysinfo_mem(7) <= std_ulogic_vector(to_unsigned(MEM_INT_DMEM_SIZE, 32)) when (MEM_INT_DMEM_EN = true) else (others => '0');
211 12 zero_gravi
 
212
 
213
  -- Read Access ----------------------------------------------------------------------------
214
  -- -------------------------------------------------------------------------------------------
215
  read_access: process(clk_i)
216
  begin
217
    if rising_edge(clk_i) then
218 23 zero_gravi
      ack_o  <= rden;
219
      data_o <= (others => '0');
220 12 zero_gravi
      if (rden = '1') then
221
        data_o <= sysinfo_mem(to_integer(unsigned(info_addr)));
222
      end if;
223
    end if;
224
  end process read_access;
225
 
226
 
227
end neorv32_sysinfo_rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.