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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [system_integration/] [neorv32_SystemTop_axi4lite.vhd] - Blame information for rev 70

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

Line No. Rev Author Line
1 63 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - Processor Top Entity with AXI4-Lite Compatible Master Interface >>               #
3
-- # ********************************************************************************************* #
4
-- # (c) "AXI", "AXI4" and "AXI4-Lite" are trademarks of Arm Holdings plc.                         #
5
-- # Note: External MTIME is not supported.                                                        #
6
-- # ********************************************************************************************* #
7
-- # BSD 3-Clause License                                                                          #
8
-- #                                                                                               #
9 70 zero_gravi
-- # Copyright (c) 2022, Stephan Nolting. All rights reserved.                                     #
10 63 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_SystemTop_axi4lite is
46
  generic (
47
    -- ------------------------------------------------------------
48
    -- Configuration Generics --
49
    -- ------------------------------------------------------------
50
    -- General --
51
    CLOCK_FREQUENCY              : natural := 0;      -- clock frequency of clk_i in Hz
52
    INT_BOOTLOADER_EN            : boolean := true;   -- boot configuration: true = boot explicit bootloader; false = boot from int/ext (I)MEM
53
    HW_THREAD_ID                 : natural := 0;      -- hardware thread id (32-bit)
54
    -- On-Chip Debugger (OCD) --
55
    ON_CHIP_DEBUGGER_EN          : boolean := false;  -- implement on-chip debugger
56
    -- RISC-V CPU Extensions --
57
    CPU_EXTENSION_RISCV_A        : boolean := false;  -- implement atomic extension?
58 66 zero_gravi
    CPU_EXTENSION_RISCV_B        : boolean := false;  -- implement bit-manipulation extension?
59 63 zero_gravi
    CPU_EXTENSION_RISCV_C        : boolean := false;  -- implement compressed extension?
60
    CPU_EXTENSION_RISCV_E        : boolean := false;  -- implement embedded RF extension?
61
    CPU_EXTENSION_RISCV_M        : boolean := false;  -- implement muld/div extension?
62
    CPU_EXTENSION_RISCV_U        : boolean := false;  -- implement user mode extension?
63
    CPU_EXTENSION_RISCV_Zfinx    : boolean := false;  -- implement 32-bit floating-point extension (using INT reg!)
64
    CPU_EXTENSION_RISCV_Zicsr    : boolean := true;   -- implement CSR system?
65 66 zero_gravi
    CPU_EXTENSION_RISCV_Zicntr   : boolean := true;   -- implement base counters?
66
    CPU_EXTENSION_RISCV_Zihpm    : boolean := false;  -- implement hardware performance monitors?
67 63 zero_gravi
    CPU_EXTENSION_RISCV_Zifencei : boolean := false;  -- implement instruction stream sync.?
68
    -- Extension Options --
69
    FAST_MUL_EN                  : boolean := false;  -- use DSPs for M extension's multiplier
70
    FAST_SHIFT_EN                : boolean := false;  -- use barrel shifter for shift operations
71
    CPU_CNT_WIDTH                : natural := 64;     -- total width of CPU cycle and instret counters (0..64)
72
    -- Physical Memory Protection (PMP) --
73
    PMP_NUM_REGIONS              : natural := 0;      -- number of regions (0..64)
74
    PMP_MIN_GRANULARITY          : natural := 64*1024; -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
75
    -- Hardware Performance Monitors (HPM) --
76
    HPM_NUM_CNTS                 : natural := 0;      -- number of implemented HPM counters (0..29)
77
    HPM_CNT_WIDTH                : natural := 40;     -- total size of HPM counters (0..64)
78
    -- Internal Instruction memory --
79
    MEM_INT_IMEM_EN              : boolean := true;   -- implement processor-internal instruction memory
80
    MEM_INT_IMEM_SIZE            : natural := 16*1024; -- size of processor-internal instruction memory in bytes
81
    -- Internal Data memory --
82
    MEM_INT_DMEM_EN              : boolean := true;   -- implement processor-internal data memory
83
    MEM_INT_DMEM_SIZE            : natural := 8*1024; -- size of processor-internal data memory in bytes
84
    -- Internal Cache memory --
85
    ICACHE_EN                    : boolean := false;  -- implement instruction cache
86
    ICACHE_NUM_BLOCKS            : natural := 4;      -- i-cache: number of blocks (min 1), has to be a power of 2
87
    ICACHE_BLOCK_SIZE            : natural := 64;     -- i-cache: block size in bytes (min 4), has to be a power of 2
88
    ICACHE_ASSOCIATIVITY         : natural := 1;      -- i-cache: associativity / number of sets (1=direct_mapped), has to be a power of 2
89
    -- External Interrupts Controller (XIRQ) --
90
    XIRQ_NUM_CH                  : natural := 0;      -- number of external IRQ channels (0..32)
91
    XIRQ_TRIGGER_TYPE            : std_logic_vector(31 downto 0) := x"FFFFFFFF"; -- trigger type: 0=level, 1=edge
92
    XIRQ_TRIGGER_POLARITY        : std_logic_vector(31 downto 0) := x"FFFFFFFF"; -- trigger polarity: 0=low-level/falling-edge, 1=high-level/rising-edge
93
    -- Processor peripherals --
94
    IO_GPIO_EN                   : boolean := true;   -- implement general purpose input/output port unit (GPIO)?
95
    IO_MTIME_EN                  : boolean := true;   -- implement machine system timer (MTIME)?
96
    IO_UART0_EN                  : boolean := true;   -- implement primary universal asynchronous receiver/transmitter (UART0)?
97 65 zero_gravi
    IO_UART0_RX_FIFO             : natural := 1;      -- RX fifo depth, has to be a power of two, min 1
98
    IO_UART0_TX_FIFO             : natural := 1;      -- TX fifo depth, has to be a power of two, min 1
99 63 zero_gravi
    IO_UART1_EN                  : boolean := true;   -- implement secondary universal asynchronous receiver/transmitter (UART1)?
100 65 zero_gravi
    IO_UART1_RX_FIFO             : natural := 1;      -- RX fifo depth, has to be a power of two, min 1
101
    IO_UART1_TX_FIFO             : natural := 1;      -- TX fifo depth, has to be a power of two, min 1
102 63 zero_gravi
    IO_SPI_EN                    : boolean := true;   -- implement serial peripheral interface (SPI)?
103
    IO_TWI_EN                    : boolean := true;   -- implement two-wire interface (TWI)?
104
    IO_PWM_NUM_CH                : natural := 4;      -- number of PWM channels to implement (0..60); 0 = disabled
105
    IO_WDT_EN                    : boolean := true;   -- implement watch dog timer (WDT)?
106 69 zero_gravi
    IO_TRNG_EN                   : boolean := true;   -- implement true random number generator (TRNG)?
107 63 zero_gravi
    IO_CFS_EN                    : boolean := false;  -- implement custom functions subsystem (CFS)?
108
    IO_CFS_CONFIG                : std_logic_vector(31 downto 0) := x"00000000"; -- custom CFS configuration generic
109
    IO_CFS_IN_SIZE               : positive := 32;    -- size of CFS input conduit in bits
110
    IO_CFS_OUT_SIZE              : positive := 32;    -- size of CFS output conduit in bits
111 65 zero_gravi
    IO_NEOLED_EN                 : boolean := true;   -- implement NeoPixel-compatible smart LED interface (NEOLED)?
112 67 zero_gravi
    IO_NEOLED_TX_FIFO            : natural := 1;      -- NEOLED TX FIFO depth, 1..32k, has to be a power of two
113 70 zero_gravi
    IO_GPTMR_EN                  : boolean := false;  -- implement general purpose timer (GPTMR)?
114
    IO_XIP_EN                    : boolean := false   -- implement execute in place module (XIP)?
115 63 zero_gravi
  );
116
  port (
117
    -- ------------------------------------------------------------
118
    -- AXI4-Lite-Compatible Master Interface --
119
    -- ------------------------------------------------------------
120
    -- Clock and Reset --
121
    m_axi_aclk    : in  std_logic;
122
    m_axi_aresetn : in  std_logic;
123
    -- Write Address Channel --
124
    m_axi_awaddr  : out std_logic_vector(31 downto 0);
125
    m_axi_awprot  : out std_logic_vector(2 downto 0);
126
    m_axi_awvalid : out std_logic;
127
    m_axi_awready : in  std_logic;
128
    -- Write Data Channel --
129
    m_axi_wdata   : out std_logic_vector(31 downto 0);
130
    m_axi_wstrb   : out std_logic_vector(3 downto 0);
131
    m_axi_wvalid  : out std_logic;
132
    m_axi_wready  : in  std_logic;
133
    -- Read Address Channel --
134
    m_axi_araddr  : out std_logic_vector(31 downto 0);
135
    m_axi_arprot  : out std_logic_vector(2 downto 0);
136
    m_axi_arvalid : out std_logic;
137
    m_axi_arready : in  std_logic;
138
    -- Read Data Channel --
139
    m_axi_rdata   : in  std_logic_vector(31 downto 0);
140
    m_axi_rresp   : in  std_logic_vector(1 downto 0);
141
    m_axi_rvalid  : in  std_logic;
142
    m_axi_rready  : out std_logic;
143
    -- Write Response Channel --
144
    m_axi_bresp   : in  std_logic_vector(1 downto 0);
145
    m_axi_bvalid  : in  std_logic;
146
    m_axi_bready  : out std_logic;
147
    -- ------------------------------------------------------------
148
    -- JTAG on-chip debugger interface (available if ON_CHIP_DEBUGGER_EN = true) --
149
    -- ------------------------------------------------------------
150
    jtag_trst_i   : in  std_logic := '0'; -- low-active TAP reset (optional)
151
    jtag_tck_i    : in  std_logic := '0'; -- serial clock
152
    jtag_tdi_i    : in  std_logic := '0'; -- serial data input
153
    jtag_tdo_o    : out std_logic;        -- serial data output
154
    jtag_tms_i    : in  std_logic := '0'; -- mode select
155
    -- ------------------------------------------------------------
156
    -- Processor IO --
157
    -- ------------------------------------------------------------
158 70 zero_gravi
    -- XIP (execute in place via SPI) signals (available if IO_XIP_EN = true) --
159
    xip_csn_o     : out std_logic; -- chip-select, low-active
160
    xip_clk_o     : out std_logic; -- serial clock
161
    xip_sdi_i     : in  std_logic := 'L'; -- device data input
162
    xip_sdo_o     : out std_logic; -- controller data output
163 63 zero_gravi
    -- GPIO (available if IO_GPIO_EN = true) --
164
    gpio_o        : out std_logic_vector(63 downto 0); -- parallel output
165
    gpio_i        : in  std_logic_vector(63 downto 0) := (others => '0'); -- parallel input
166
    -- primary UART0 (available if IO_UART0_EN = true) --
167
    uart0_txd_o   : out std_logic; -- UART0 send data
168
    uart0_rxd_i   : in  std_logic := '0'; -- UART0 receive data
169
    uart0_rts_o   : out std_logic; -- hw flow control: UART0.RX ready to receive ("RTR"), low-active, optional
170
    uart0_cts_i   : in  std_logic := '0'; -- hw flow control: UART0.TX allowed to transmit, low-active, optional
171
    -- secondary UART1 (available if IO_UART1_EN = true) --
172
    uart1_txd_o   : out std_logic; -- UART1 send data
173
    uart1_rxd_i   : in  std_logic := '0'; -- UART1 receive data
174
    uart1_rts_o   : out std_logic; -- hw flow control: UART1.RX ready to receive ("RTR"), low-active, optional
175
    uart1_cts_i   : in  std_logic := '0'; -- hw flow control: UART1.TX allowed to transmit, low-active, optional
176
    -- SPI (available if IO_SPI_EN = true) --
177
    spi_sck_o     : out std_logic; -- SPI serial clock
178
    spi_sdo_o     : out std_logic; -- controller data out, peripheral data in
179
    spi_sdi_i     : in  std_logic := '0'; -- controller data in, peripheral data out
180
    spi_csn_o     : out std_logic_vector(07 downto 0); -- SPI CS
181
    -- TWI (available if IO_TWI_EN = true) --
182
    twi_sda_io    : inout std_logic; -- twi serial data line
183
    twi_scl_io    : inout std_logic; -- twi serial clock line
184
    -- PWM (available if IO_PWM_NUM_CH > 0) --
185 70 zero_gravi
    pwm_o         : out std_logic_vector(59 downto 0);  -- pwm channels
186 63 zero_gravi
    -- Custom Functions Subsystem IO (available if IO_CFS_EN = true) --
187
    cfs_in_i      : in  std_logic_vector(IO_CFS_IN_SIZE-1  downto 0); -- custom inputs
188
    cfs_out_o     : out std_logic_vector(IO_CFS_OUT_SIZE-1 downto 0); -- custom outputs
189
    -- NeoPixel-compatible smart LED interface (available if IO_NEOLED_EN = true) --
190
    neoled_o      : out std_logic; -- async serial data line
191
    -- External platform interrupts (available if XIRQ_NUM_CH > 0) --
192 70 zero_gravi
    xirq_i        : in  std_logic_vector(31 downto 0) := (others => '0'); -- IRQ channels
193 63 zero_gravi
    -- CPU Interrupts --
194
    msw_irq_i     : in  std_logic := '0'; -- machine software interrupt
195
    mext_irq_i    : in  std_logic := '0'  -- machine external interrupt
196
  );
197
end entity;
198
 
199
architecture neorv32_SystemTop_axi4lite_rtl of neorv32_SystemTop_axi4lite is
200
 
201
  -- type conversion --
202
  constant IO_CFS_CONFIG_INT         : std_ulogic_vector(31 downto 0) := std_ulogic_vector(IO_CFS_CONFIG);
203
  constant XIRQ_TRIGGER_TYPE_INT     : std_ulogic_vector(31 downto 0) := std_ulogic_vector(XIRQ_TRIGGER_TYPE);
204
  constant XIRQ_TRIGGER_POLARITY_INT : std_ulogic_vector(31 downto 0) := std_ulogic_vector(XIRQ_TRIGGER_POLARITY);
205
  --
206
  signal clk_i_int       : std_ulogic;
207
  signal rstn_i_int      : std_ulogic;
208
  --
209
  signal jtag_trst_i_int :std_ulogic;
210
  signal jtag_tck_i_int  :std_ulogic;
211
  signal jtag_tdi_i_int  :std_ulogic;
212
  signal jtag_tdo_o_int  :std_ulogic;
213
  signal jtag_tms_i_int  :std_ulogic;
214
  --
215 70 zero_gravi
  signal xip_csn_o_int   : std_ulogic;
216
  signal xip_clk_o_int   : std_ulogic;
217
  signal xip_sdi_i_int   : std_ulogic;
218
  signal xip_sdo_o_int   : std_ulogic;
219
  --
220 63 zero_gravi
  signal gpio_o_int      : std_ulogic_vector(63 downto 0);
221
  signal gpio_i_int      : std_ulogic_vector(63 downto 0);
222
  --
223
  signal uart0_txd_o_int : std_ulogic;
224
  signal uart0_rxd_i_int : std_ulogic;
225
  signal uart0_rts_o_int : std_ulogic;
226
  signal uart0_cts_i_int : std_ulogic;
227
  --
228
  signal uart1_txd_o_int : std_ulogic;
229
  signal uart1_rxd_i_int : std_ulogic;
230
  signal uart1_rts_o_int : std_ulogic;
231
  signal uart1_cts_i_int : std_ulogic;
232
  --
233
  signal spi_sck_o_int   : std_ulogic;
234
  signal spi_sdo_o_int   : std_ulogic;
235
  signal spi_sdi_i_int   : std_ulogic;
236
  signal spi_csn_o_int   : std_ulogic_vector(07 downto 0);
237
  --
238 70 zero_gravi
  signal pwm_o_int       : std_ulogic_vector(59 downto 0);
239 63 zero_gravi
  --
240
  signal cfs_in_i_int    : std_ulogic_vector(IO_CFS_IN_SIZE-1  downto 0);
241
  signal cfs_out_o_int   : std_ulogic_vector(IO_CFS_OUT_SIZE-1 downto 0);
242
  --
243
  signal neoled_o_int    : std_ulogic;
244
  --
245 70 zero_gravi
  signal xirq_i_int      : std_ulogic_vector(31 downto 0);
246 63 zero_gravi
  --
247
  signal msw_irq_i_int   : std_ulogic;
248
  signal mext_irq_i_int  : std_ulogic;
249
 
250
  -- internal wishbone bus --
251
  type wb_bus_t is record
252
    adr  : std_ulogic_vector(31 downto 0); -- address
253
    di   : std_ulogic_vector(31 downto 0); -- processor input data
254
    do   : std_ulogic_vector(31 downto 0); -- processor output data
255
    we   : std_ulogic; -- write enable
256
    sel  : std_ulogic_vector(03 downto 0); -- byte enable
257
    stb  : std_ulogic; -- strobe
258
    cyc  : std_ulogic; -- valid cycle
259
    ack  : std_ulogic; -- transfer acknowledge
260
    err  : std_ulogic; -- transfer error
261
    tag  : std_ulogic_vector(02 downto 0); -- tag
262
    lock : std_ulogic; -- exclusive access request
263
  end record;
264
  signal wb_core : wb_bus_t;
265
 
266
  -- AXI bridge control --
267
  type ctrl_t is record
268
    radr_received : std_ulogic;
269
    wadr_received : std_ulogic;
270
    wdat_received : std_ulogic;
271
  end record;
272
  signal ctrl : ctrl_t;
273
 
274
  signal ack_read, ack_write : std_ulogic; -- normal transfer termination
275
  signal err_read, err_write : std_ulogic; -- error transfer termination
276
 
277
begin
278
 
279
  -- Sanity Checks --------------------------------------------------------------------------
280
  -- -------------------------------------------------------------------------------------------
281
  assert not (CPU_EXTENSION_RISCV_A = true) report "NEORV32 PROCESSOR CONFIG WARNING: AXI4-Lite provides NO support for atomic memory operations. LR/SC access via AXI will raise a bus exception." severity warning;
282
 
283
 
284
  -- The Core Of The Problem ----------------------------------------------------------------
285
  -- -------------------------------------------------------------------------------------------
286
  neorv32_top_inst: neorv32_top
287
  generic map (
288
    -- General --
289
    CLOCK_FREQUENCY              => CLOCK_FREQUENCY,    -- clock frequency of clk_i in Hz
290
    INT_BOOTLOADER_EN            => INT_BOOTLOADER_EN,  -- boot configuration: true = boot explicit bootloader; false = boot from int/ext (I)MEM
291
    HW_THREAD_ID                 => HW_THREAD_ID,       -- hardware thread id (hartid)
292
    -- On-Chip Debugger (OCD) --
293
    ON_CHIP_DEBUGGER_EN          => ON_CHIP_DEBUGGER_EN,          -- implement on-chip debugger
294
    -- RISC-V CPU Extensions --
295
    CPU_EXTENSION_RISCV_A        => CPU_EXTENSION_RISCV_A,        -- implement atomic extension?
296 66 zero_gravi
    CPU_EXTENSION_RISCV_B        => CPU_EXTENSION_RISCV_B,        -- implement bit-manipulation extension?
297 63 zero_gravi
    CPU_EXTENSION_RISCV_C        => CPU_EXTENSION_RISCV_C,        -- implement compressed extension?
298
    CPU_EXTENSION_RISCV_E        => CPU_EXTENSION_RISCV_E,        -- implement embedded RF extension?
299
    CPU_EXTENSION_RISCV_M        => CPU_EXTENSION_RISCV_M,        -- implement muld/div extension?
300
    CPU_EXTENSION_RISCV_U        => CPU_EXTENSION_RISCV_U,        -- implement user mode extension?
301
    CPU_EXTENSION_RISCV_Zfinx    => CPU_EXTENSION_RISCV_Zfinx,    -- implement 32-bit floating-point extension (using INT reg!)
302
    CPU_EXTENSION_RISCV_Zicsr    => CPU_EXTENSION_RISCV_Zicsr,    -- implement CSR system?
303 66 zero_gravi
    CPU_EXTENSION_RISCV_Zicntr   => CPU_EXTENSION_RISCV_Zicntr,   -- implement base counters?
304
    CPU_EXTENSION_RISCV_Zihpm    => CPU_EXTENSION_RISCV_Zihpm,    -- implement hardware performance monitors?
305 63 zero_gravi
    CPU_EXTENSION_RISCV_Zifencei => CPU_EXTENSION_RISCV_Zifencei, -- implement instruction stream sync.?
306
    -- Extension Options --
307
    FAST_MUL_EN                  => FAST_MUL_EN,        -- use DSPs for M extension's multiplier
308
    FAST_SHIFT_EN                => FAST_SHIFT_EN,      -- use barrel shifter for shift operations
309
    CPU_CNT_WIDTH                => CPU_CNT_WIDTH,      -- total width of CPU cycle and instret counters (0..64)
310
    -- Physical Memory Protection (PMP) --
311
    PMP_NUM_REGIONS              => PMP_NUM_REGIONS,    -- number of regions (0..64)
312
    PMP_MIN_GRANULARITY          => PMP_MIN_GRANULARITY, -- minimal region granularity in bytes, has to be a power of 2, min 8 bytes
313
    -- Hardware Performance Monitors (HPM) --
314
    HPM_NUM_CNTS                 => HPM_NUM_CNTS,       -- number of implemented HPM counters (0..29)
315
    HPM_CNT_WIDTH                => HPM_CNT_WIDTH,      -- total size of HPM counters (0..64)
316
    -- Internal Instruction memory --
317
    MEM_INT_IMEM_EN              => MEM_INT_IMEM_EN,    -- implement processor-internal instruction memory
318
    MEM_INT_IMEM_SIZE            => MEM_INT_IMEM_SIZE,  -- size of processor-internal instruction memory in bytes
319
    -- Internal Data memory --
320
    MEM_INT_DMEM_EN              => MEM_INT_DMEM_EN,    -- implement processor-internal data memory
321
    MEM_INT_DMEM_SIZE            => MEM_INT_DMEM_SIZE,  -- size of processor-internal data memory in bytes
322
    -- Internal Cache memory --
323
    ICACHE_EN                    => ICACHE_EN,          -- implement instruction cache
324
    ICACHE_NUM_BLOCKS            => ICACHE_NUM_BLOCKS,  -- i-cache: number of blocks (min 1), has to be a power of 2
325
    ICACHE_BLOCK_SIZE            => ICACHE_BLOCK_SIZE,  -- i-cache: block size in bytes (min 4), has to be a power of 2
326
    ICACHE_ASSOCIATIVITY         => ICACHE_ASSOCIATIVITY, -- i-cache: associativity / number of sets (1=direct_mapped), has to be a power of 2
327
    -- External memory interface --
328
    MEM_EXT_EN                   => true,               -- implement external memory bus interface?
329
    MEM_EXT_TIMEOUT              => 0,                  -- cycles after a pending bus access auto-terminates (0 = disabled)
330
    MEM_EXT_PIPE_MODE            => false,              -- protocol: false=classic/standard wishbone mode, true=pipelined wishbone mode
331
    MEM_EXT_BIG_ENDIAN           => false,              -- byte order: true=big-endian, false=little-endian
332
    MEM_EXT_ASYNC_RX             => false,              -- use register buffer for RX data when false
333
    -- External Interrupts Controller (XIRQ) --
334
    XIRQ_NUM_CH                  => XIRQ_NUM_CH, -- number of external IRQ channels (0..32)
335
    XIRQ_TRIGGER_TYPE            => XIRQ_TRIGGER_TYPE_INT, -- trigger type: 0=level, 1=edge
336
    XIRQ_TRIGGER_POLARITY        => XIRQ_TRIGGER_POLARITY_INT, -- trigger polarity: 0=low-level/falling-edge, 1=high-level/rising-edge
337
    -- Processor peripherals --
338
    IO_GPIO_EN                   => IO_GPIO_EN,         -- implement general purpose input/output port unit (GPIO)?
339
    IO_MTIME_EN                  => IO_MTIME_EN,        -- implement machine system timer (MTIME)?
340
    IO_UART0_EN                  => IO_UART0_EN,        -- implement primary universal asynchronous receiver/transmitter (UART0)?
341 65 zero_gravi
    IO_UART0_RX_FIFO             => IO_UART0_RX_FIFO,   -- RX fifo depth, has to be a power of two, min 1
342
    IO_UART0_TX_FIFO             => IO_UART0_TX_FIFO,   -- TX fifo depth, has to be a power of two, min 1
343 63 zero_gravi
    IO_UART1_EN                  => IO_UART1_EN,        -- implement secondary universal asynchronous receiver/transmitter (UART1)?
344 65 zero_gravi
    IO_UART1_RX_FIFO             => IO_UART1_RX_FIFO,   -- RX fifo depth, has to be a power of two, min 1
345
    IO_UART1_TX_FIFO             => IO_UART1_TX_FIFO,   -- TX fifo depth, has to be a power of two, min 1
346 63 zero_gravi
    IO_SPI_EN                    => IO_SPI_EN,          -- implement serial peripheral interface (SPI)?
347
    IO_TWI_EN                    => IO_TWI_EN,          -- implement two-wire interface (TWI)?
348
    IO_PWM_NUM_CH                => IO_PWM_NUM_CH,      -- number of PWM channels to implement (0..60); 0 = disabled
349
    IO_WDT_EN                    => IO_WDT_EN,          -- implement watch dog timer (WDT)?
350
    IO_TRNG_EN                   => IO_TRNG_EN,         -- implement true random number generator (TRNG)?
351
    IO_CFS_EN                    => IO_CFS_EN,          -- implement custom functions subsystem (CFS)?
352
    IO_CFS_CONFIG                => IO_CFS_CONFIG_INT,  -- custom CFS configuration generic
353
    IO_CFS_IN_SIZE               => IO_CFS_IN_SIZE,     -- size of CFS input conduit in bits
354
    IO_CFS_OUT_SIZE              => IO_CFS_OUT_SIZE,    -- size of CFS output conduit in bits
355 65 zero_gravi
    IO_NEOLED_EN                 => IO_NEOLED_EN,       -- implement NeoPixel-compatible smart LED interface (NEOLED)?
356 67 zero_gravi
    IO_NEOLED_TX_FIFO            => IO_NEOLED_TX_FIFO,  -- NEOLED TX FIFO depth, 1..32k, has to be a power of two
357 70 zero_gravi
    IO_GPTMR_EN                  => IO_GPTMR_EN,        -- implement general purpose timer (GPTMR)?
358
    IO_XIP_EN                    => IO_XIP_EN           -- implement execute in place module (XIP)?
359 63 zero_gravi
  )
360
  port map (
361
    -- Global control --
362
    clk_i       => clk_i_int,       -- global clock, rising edge
363
    rstn_i      => rstn_i_int,      -- global reset, low-active, async
364
    -- JTAG on-chip debugger interface (available if ON_CHIP_DEBUGGER_EN = true) --
365
    jtag_trst_i => jtag_trst_i_int, -- low-active TAP reset (optional)
366
    jtag_tck_i  => jtag_tck_i_int,  -- serial clock
367
    jtag_tdi_i  => jtag_tdi_i_int,  -- serial data input
368
    jtag_tdo_o  => jtag_tdo_o_int,  -- serial data output
369
    jtag_tms_i  => jtag_tms_i_int,  -- mode select
370
    -- Wishbone bus interface (available if MEM_EXT_EN = true) --
371
    wb_tag_o    => wb_core.tag,     -- tag
372
    wb_adr_o    => wb_core.adr,     -- address
373
    wb_dat_i    => wb_core.di,      -- read data
374
    wb_dat_o    => wb_core.do,      -- write data
375
    wb_we_o     => wb_core.we,      -- read/write
376
    wb_sel_o    => wb_core.sel,     -- byte enable
377
    wb_stb_o    => wb_core.stb,     -- strobe
378
    wb_cyc_o    => wb_core.cyc,     -- valid cycle
379
    wb_lock_o   => wb_core.lock,    -- exclusive access request
380
    wb_ack_i    => wb_core.ack,     -- transfer acknowledge
381
    wb_err_i    => wb_core.err,     -- transfer error
382
    -- Advanced memory control signals (available if MEM_EXT_EN = true) --
383
    fence_o     => open,            -- indicates an executed FENCE operation
384
    fencei_o    => open,            -- indicates an executed FENCEI operation
385 70 zero_gravi
    -- XIP (execute in place via SPI) signals (available if IO_XIP_EN = true) --
386
    xip_csn_o   => xip_csn_o_int,   -- chip-select, low-active
387
    xip_clk_o   => xip_clk_o_int,   -- serial clock
388
    xip_sdi_i   => xip_sdi_i_int,   -- device data input
389
    xip_sdo_o   => xip_sdo_o_int,   -- controller data output
390 63 zero_gravi
    -- GPIO (available if IO_GPIO_EN = true) --
391
    gpio_o      => gpio_o_int,      -- parallel output
392
    gpio_i      => gpio_i_int,      -- parallel input
393
    -- primary UART0 (available if IO_UART0_EN = true) --
394
    uart0_txd_o => uart0_txd_o_int, -- UART0 send data
395
    uart0_rxd_i => uart0_rxd_i_int, -- UART0 receive data
396
    uart0_rts_o => uart0_rts_o_int, -- hw flow control: UART0.RX ready to receive ("RTR"), low-active, optional
397
    uart0_cts_i => uart0_cts_i_int, -- hw flow control: UART0.TX allowed to transmit, low-active, optional
398
    -- secondary UART1 (available if IO_UART1_EN = true) --
399
    uart1_txd_o => uart1_txd_o_int, -- UART1 send data
400
    uart1_rxd_i => uart1_rxd_i_int, -- UART1 receive data
401
    uart1_rts_o => uart1_rts_o_int, -- hw flow control: UART1.RX ready to receive ("RTR"), low-active, optional
402
    uart1_cts_i => uart1_cts_i_int, -- hw flow control: UART1.TX allowed to transmit, low-active, optional
403
    -- SPI (available if IO_SPI_EN = true) --
404
    spi_sck_o   => spi_sck_o_int,   -- SPI serial clock
405
    spi_sdo_o   => spi_sdo_o_int,   -- controller data out, peripheral data in
406
    spi_sdi_i   => spi_sdi_i_int,   -- controller data in, peripheral data out
407
    spi_csn_o   => spi_csn_o_int,   -- SPI CS
408
    -- TWI (available if IO_TWI_EN = true) --
409
    twi_sda_io  => twi_sda_io,      -- twi serial data line
410
    twi_scl_io  => twi_scl_io,      -- twi serial clock line
411
    -- PWM available if IO_PWM_NUM_CH > 0) --
412
    pwm_o       => pwm_o_int,       -- pwm channels
413
    -- Custom Functions Subsystem IO (available if IO_CFS_EN = true) --
414
    cfs_in_i    => cfs_in_i_int,    -- custom inputs
415
    cfs_out_o   => cfs_out_o_int,   -- custom outputs
416
    -- NeoPixel-compatible smart LED interface (available if IO_NEOLED_EN = true) --
417
    neoled_o    => neoled_o_int,    -- async serial data line
418
    -- System time --
419
    mtime_i     => (others => '0'), -- current system time from ext. MTIME (if IO_MTIME_EN = false)
420
    mtime_o     => open,            -- current system time from int. MTIME (if IO_MTIME_EN = true)
421
    -- External platform interrupts (available if XIRQ_NUM_CH > 0) --
422
    xirq_i      => xirq_i_int,      -- IRQ channels
423
    -- CPU Interrupts --
424
    mtime_irq_i => '0',             -- machine timer interrupt, available if IO_MTIME_EN = false
425
    msw_irq_i   => msw_irq_i_int,   -- machine software interrupt
426
    mext_irq_i  => mext_irq_i_int   -- machine external interrupt
427
  );
428
 
429
  -- type conversion --
430 70 zero_gravi
  xip_csn_o       <= std_logic(xip_csn_o_int);
431
  xip_clk_o       <= std_logic(xip_clk_o_int);
432
  xip_sdi_i_int   <= std_ulogic(xip_sdi_i);
433
  xip_sdo_o       <= std_logic(xip_sdo_o_int);
434
 
435 63 zero_gravi
  gpio_o          <= std_logic_vector(gpio_o_int);
436
  gpio_i_int      <= std_ulogic_vector(gpio_i);
437
 
438
  jtag_trst_i_int <= std_ulogic(jtag_trst_i);
439
  jtag_tck_i_int  <= std_ulogic(jtag_tck_i);
440
  jtag_tdi_i_int  <= std_ulogic(jtag_tdi_i);
441
  jtag_tdo_o      <= std_logic(jtag_tdo_o_int);
442
  jtag_tms_i_int  <= std_ulogic(jtag_tms_i);
443
 
444
  uart0_txd_o     <= std_logic(uart0_txd_o_int);
445
  uart0_rxd_i_int <= std_ulogic(uart0_rxd_i);
446 65 zero_gravi
  uart0_rts_o     <= std_logic(uart0_rts_o_int);
447
  uart0_cts_i_int <= std_ulogic(uart0_cts_i);
448
  uart1_txd_o     <= std_logic(uart1_txd_o_int);
449
  uart1_rxd_i_int <= std_ulogic(uart1_rxd_i);
450
  uart1_rts_o     <= std_logic(uart1_rts_o_int);
451
  uart1_cts_i_int <= std_ulogic(uart1_cts_i);
452 63 zero_gravi
 
453
  spi_sck_o       <= std_logic(spi_sck_o_int);
454
  spi_sdo_o       <= std_logic(spi_sdo_o_int);
455
  spi_sdi_i_int   <= std_ulogic(spi_sdi_i);
456
  spi_csn_o       <= std_logic_vector(spi_csn_o_int);
457
 
458
  pwm_o           <= std_logic_vector(pwm_o_int);
459
 
460
  cfs_in_i_int    <= std_ulogic_vector(cfs_in_i);
461
  cfs_out_o       <= std_logic_vector(cfs_out_o_int);
462
 
463
  neoled_o        <= std_logic(neoled_o_int);
464
 
465 64 zero_gravi
  xirq_i_int      <= std_ulogic_vector(xirq_i);
466
 
467
  msw_irq_i_int   <= std_ulogic(msw_irq_i);
468 63 zero_gravi
  mext_irq_i_int  <= std_ulogic(mext_irq_i);
469
 
470
 
471
  -- Wishbone to AXI4-Lite Bridge -----------------------------------------------------------
472
  -- -------------------------------------------------------------------------------------------
473
 
474
  -- access arbiter --
475
  axi_access_arbiter: process(rstn_i_int, clk_i_int)
476
  begin
477
    if (rstn_i_int = '0') then
478
      ctrl.radr_received <= '0';
479
      ctrl.wadr_received <= '0';
480
      ctrl.wdat_received <= '0';
481
    elsif rising_edge(clk_i_int) then
482
      if (wb_core.cyc = '0') then -- idle
483
        ctrl.radr_received <= '0';
484
        ctrl.wadr_received <= '0';
485
        ctrl.wdat_received <= '0';
486
      else -- busy
487
        -- "read address received" flag --
488
        if (wb_core.we = '0') then -- pending READ
489
          if (m_axi_arready = '1') then -- read address received by interconnect?
490
            ctrl.radr_received <= '1';
491
          end if;
492
        end if;
493
        -- "write address received" flag --
494
        if (wb_core.we = '1') then -- pending WRITE
495
          if (m_axi_awready = '1') then -- write address received by interconnect?
496
            ctrl.wadr_received <= '1';
497
          end if;
498
        end if;
499
        -- "write data received" flag --
500
        if (wb_core.we = '1') then -- pending WRITE
501
          if (m_axi_wready = '1') then -- write data received by interconnect?
502
            ctrl.wdat_received <= '1';
503
          end if;
504
        end if;
505
      end if;
506
    end if;
507
  end process axi_access_arbiter;
508
 
509
 
510
  -- AXI4-Lite Global Signals --
511
  clk_i_int     <= std_ulogic(m_axi_aclk);
512
  rstn_i_int    <= std_ulogic(m_axi_aresetn);
513
 
514
 
515
  -- AXI4-Lite Read Address Channel --
516
  m_axi_araddr  <= std_logic_vector(wb_core.adr);
517
  m_axi_arvalid <= std_logic((wb_core.cyc and (not wb_core.we)) and (not ctrl.radr_received));
518
--m_axi_arprot  <= "000"; -- recommended by Xilinx
519
  m_axi_arprot(0) <= wb_core.tag(0); -- 0:unprivileged access, 1:privileged access
520
  m_axi_arprot(1) <= wb_core.tag(1); -- 0:secure access, 1:non-secure access
521
  m_axi_arprot(2) <= wb_core.tag(2); -- 0:data access, 1:instruction access
522
 
523
  -- AXI4-Lite Read Data Channel --
524
  m_axi_rready  <= std_logic(wb_core.cyc and (not wb_core.we));
525
  wb_core.di    <= std_ulogic_vector(m_axi_rdata);
526
  ack_read      <= std_ulogic(m_axi_rvalid);
527
  err_read      <= '0' when (m_axi_rresp = "00") else '1'; -- read response = ok? check this signal only when m_axi_rvalid = '1'
528
 
529
 
530
  -- AXI4-Lite Write Address Channel --
531
  m_axi_awaddr  <= std_logic_vector(wb_core.adr);
532
  m_axi_awvalid <= std_logic((wb_core.cyc and wb_core.we) and (not ctrl.wadr_received));
533
--m_axi_awprot  <= "000"; -- recommended by Xilinx
534
  m_axi_awprot(0) <= wb_core.tag(0); -- 0:unprivileged access, 1:privileged access
535
  m_axi_awprot(1) <= wb_core.tag(1); -- 0:secure access, 1:non-secure access
536
  m_axi_awprot(2) <= wb_core.tag(2); -- 0:data access, 1:instruction access
537
 
538
  -- AXI4-Lite Write Data Channel --
539
  m_axi_wdata   <= std_logic_vector(wb_core.do);
540
  m_axi_wvalid  <= std_logic((wb_core.cyc and wb_core.we) and (not ctrl.wdat_received));
541
  m_axi_wstrb   <= std_logic_vector(wb_core.sel); -- byte-enable
542
 
543
  -- AXI4-Lite Write Response Channel --
544
  m_axi_bready  <= std_logic(wb_core.cyc and wb_core.we);
545
  ack_write     <= std_ulogic(m_axi_bvalid);
546
  err_write     <= '0' when (m_axi_bresp = "00") else '1'; -- write response = ok? check this signal only when m_axi_bvalid = '1'
547
 
548
 
549
  -- Wishbone transfer termination --
550
  wb_core.ack   <= ack_read or ack_write;
551
  wb_core.err   <= (ack_read and err_read) or (ack_write and err_write) or wb_core.lock;
552
 
553
 
554
end architecture;

powered by: WebSVN 2.1.0

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