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

Subversion Repositories neo430

[/] [neo430/] [trunk/] [neo430/] [rtl/] [core/] [neo430_top.vhd] - Blame information for rev 198

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 198 zero_gravi
-- #################################################################################################
2
-- #  << NEO430 - Processor Top Entity >>                                                          #
3
-- # ********************************************************************************************* #
4
-- # This is the top entity of the NEO430 processor. Instantiate this unit in your own project and #
5
-- # define all the configuration generics according to your needs. Alternatively, you can use one #
6
-- # of the other top entities provided in rtl\top_templates                                       #
7
-- # Check the processor's documentary for more information: doc\NEO430.pdf                        #
8
-- # ********************************************************************************************* #
9
-- #  The NEO430 processor:                                                                        #
10
-- #  - Reset and clock generators                                                                 #
11
-- #  - External IRQ synchronizer                                                                  #
12
-- #  - NEO430 CPU (MSP430(TM)-ISA-compatible) (CPU)                                               #
13
-- #  - Internal RAM or ROM (configurable size) for code (IMEM)                                    #
14
-- #  - Internal RAM (configurable size) for data (and code) (DMEM)                                #
15
-- #  - Sysconfig (infomem for various system information) (SYSCONFIG)                             #
16
-- #  - Optional 16-bit multiplier/divider unit (MULDIV)                                           #
17
-- #  - Optional 16-bit IN and 16-bit OUT GPIO port with pin-change interrupt (GPIO)               #
18
-- #  - Optional 32-bit Wishbone interface (WB32)                                                  #
19
-- #  - Optional High precision timer (TIMER)                                                      #
20
-- #  - Optional Universal Asynchronous Receiver and Transmitter (UART)                            #
21
-- #  - Optional Serial Peripheral Interface (SPI)                                                 #
22
-- #  - Optional Internal ROM for bootloader (BOOTLD)                                              #
23
-- #  - Optional Watchdog Timer (WDT)                                                              #
24
-- #  - Optional CRC16/32 Module (CRC16/32)                                                        #
25
-- #  - Optional Custom Functions Unit to implement user-defined processor extension (CFU)         #
26
-- #  - Optional Pulse Width Modulation controller (PWM)                                           #
27
-- #  - Optional Two Wire Serial Interface (TWI)                                                   #
28
-- #  - Optional True Random Number Generator (TRNG)                                               #
29
-- #  - Optional External Interrupts Controller (EXIRQ)                                            #
30
-- #  - Optional Arbitrary Frequency Generator (FREQ_GEN)                                          #
31
-- # ********************************************************************************************* #
32
-- # BSD 3-Clause License                                                                          #
33
-- #                                                                                               #
34
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
35
-- #                                                                                               #
36
-- # Redistribution and use in source and binary forms, with or without modification, are          #
37
-- # permitted provided that the following conditions are met:                                     #
38
-- #                                                                                               #
39
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
40
-- #    conditions and the following disclaimer.                                                   #
41
-- #                                                                                               #
42
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
43
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
44
-- #    provided with the distribution.                                                            #
45
-- #                                                                                               #
46
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
47
-- #    endorse or promote products derived from this software without specific prior written      #
48
-- #    permission.                                                                                #
49
-- #                                                                                               #
50
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
51
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
52
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
53
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
54
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
55
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
56
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
57
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
58
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
59
-- # ********************************************************************************************* #
60
-- # The NEO430 Processor - https://github.com/stnolting/neo430                                    #
61
-- #################################################################################################
62
 
63
library ieee;
64
use ieee.std_logic_1164.all;
65
use ieee.numeric_std.all;
66
 
67
library neo430;
68
use neo430.neo430_package.all;
69
 
70
entity neo430_top is
71
  generic (
72
    -- general configuration --
73
    CLOCK_SPEED  : natural := 100000000; -- main clock in Hz
74
    IMEM_SIZE    : natural := 4*1024; -- internal IMEM size in bytes, max 48kB (default=4kB)
75
    DMEM_SIZE    : natural := 2*1024; -- internal DMEM size in bytes, max 12kB (default=2kB)
76
    -- additional configuration --
77
    USER_CODE    : std_ulogic_vector(15 downto 0) := x"0000"; -- custom user code
78
    -- module configuration --
79
    MULDIV_USE   : boolean := true;  -- implement multiplier/divider unit? (default=true)
80
    WB32_USE     : boolean := true;  -- implement WB32 unit? (default=true)
81
    WDT_USE      : boolean := true;  -- implement WDT? (default=true)
82
    GPIO_USE     : boolean := true;  -- implement GPIO unit? (default=true)
83
    TIMER_USE    : boolean := true;  -- implement timer? (default=true)
84
    UART_USE     : boolean := true;  -- implement UART? (default=true)
85
    CRC_USE      : boolean := true;  -- implement CRC unit? (default=true)
86
    CFU_USE      : boolean := false; -- implement custom functions unit? (default=false)
87
    PWM_USE      : boolean := true;  -- implement PWM controller? (default=true)
88
    TWI_USE      : boolean := true;  -- implement two wire serial interface? (default=true)
89
    SPI_USE      : boolean := true;  -- implement SPI? (default=true)
90
    TRNG_USE     : boolean := false; -- implement TRNG? (default=false)
91
    EXIRQ_USE    : boolean := true;  -- implement EXIRQ? (default=true)
92
    FREQ_GEN_USE : boolean := true;  -- implement FREQ_GEN? (default=true)
93
    -- boot configuration --
94
    BOOTLD_USE   : boolean := true;  -- implement and use bootloader? (default=true)
95
    IMEM_AS_ROM  : boolean := false  -- implement IMEM as read-only memory? (default=false)
96
  );
97
  port (
98
    -- global control --
99
    clk_i      : in  std_ulogic; -- global clock, rising edge
100
    rst_i      : in  std_ulogic; -- global reset, async, LOW-active
101
    -- parallel io --
102
    gpio_o     : out std_ulogic_vector(15 downto 0); -- parallel output
103
    gpio_i     : in  std_ulogic_vector(15 downto 0); -- parallel input
104
    -- pwm channels --
105
    pwm_o      : out std_ulogic_vector(03 downto 0); -- pwm channels
106
    -- arbitrary frequency generator --
107
    freq_gen_o : out std_ulogic_vector(02 downto 0); -- programmable frequency output
108
    -- serial com --
109
    uart_txd_o : out std_ulogic; -- UART send data
110
    uart_rxd_i : in  std_ulogic; -- UART receive data
111
    spi_sclk_o : out std_ulogic; -- serial clock line
112
    spi_mosi_o : out std_ulogic; -- serial data line out
113
    spi_miso_i : in  std_ulogic; -- serial data line in
114
    spi_cs_o   : out std_ulogic_vector(05 downto 0); -- SPI CS
115
    twi_sda_io : inout std_logic; -- twi serial data line
116
    twi_scl_io : inout std_logic; -- twi serial clock line
117
    -- 32-bit wishbone interface --
118
    wb_adr_o   : out std_ulogic_vector(31 downto 0); -- address
119
    wb_dat_i   : in  std_ulogic_vector(31 downto 0); -- read data
120
    wb_dat_o   : out std_ulogic_vector(31 downto 0); -- write data
121
    wb_we_o    : out std_ulogic; -- read/write
122
    wb_sel_o   : out std_ulogic_vector(03 downto 0); -- byte enable
123
    wb_stb_o   : out std_ulogic; -- strobe
124
    wb_cyc_o   : out std_ulogic; -- valid cycle
125
    wb_ack_i   : in  std_ulogic; -- transfer acknowledge
126
    -- external interrupts --
127
    ext_irq_i  : in  std_ulogic_vector(07 downto 0); -- external interrupt request lines (active HI)
128
    ext_ack_o  : out std_ulogic_vector(07 downto 0)  -- external interrupt request acknowledges
129
  );
130
end neo430_top;
131
 
132
architecture neo430_top_rtl of neo430_top is
133
 
134
  -- generators --
135
  signal rst_i_sync0    : std_ulogic;
136
  signal rst_i_sync1    : std_ulogic;
137
  signal rst_gen        : std_ulogic_vector(03 downto 0) := (others => '0'); -- reset on bitstream upload
138
  signal ext_rst        : std_ulogic;
139
  signal sys_rst        : std_ulogic;
140
  signal wdt_rst        : std_ulogic;
141
  signal clk_div        : std_ulogic_vector(11 downto 0);
142
  signal clk_div_ff     : std_ulogic_vector(11 downto 0);
143
  signal clk_gen        : std_ulogic_vector(07 downto 0);
144
  signal timer_cg_en    : std_ulogic;
145
  signal uart_cg_en     : std_ulogic;
146
  signal spi_cg_en      : std_ulogic;
147
  signal wdt_cg_en      : std_ulogic;
148
  signal pwm_cg_en      : std_ulogic;
149
  signal twi_cg_en      : std_ulogic;
150
  signal cfu_cg_en      : std_ulogic;
151
  signal freq_gen_cg_en : std_ulogic;
152
 
153
  type cpu_bus_t is record
154
    rd_en : std_ulogic;
155
    wr_en : std_ulogic_vector(01 downto 0);
156
    addr  : std_ulogic_vector(15 downto 0);
157
    rdata : std_ulogic_vector(15 downto 0);
158
    wdata : std_ulogic_vector(15 downto 0);
159
  end record;
160
 
161
  -- main CPU communication bus --
162
  signal cpu_bus  : cpu_bus_t;
163
  signal io_acc   : std_ulogic;
164
  signal io_wr_en : std_ulogic;
165
  signal io_rd_en : std_ulogic;
166
 
167
  -- read-back data buses --
168
  signal rom_rdata       : std_ulogic_vector(15 downto 0);
169
  signal ram_rdata       : std_ulogic_vector(15 downto 0);
170
  signal muldiv_rdata    : std_ulogic_vector(15 downto 0);
171
  signal wb_rdata        : std_ulogic_vector(15 downto 0);
172
  signal boot_rdata      : std_ulogic_vector(15 downto 0);
173
  signal wdt_rdata       : std_ulogic_vector(15 downto 0);
174
  signal timer_rdata     : std_ulogic_vector(15 downto 0);
175
  signal uart_rdata      : std_ulogic_vector(15 downto 0);
176
  signal spi_rdata       : std_ulogic_vector(15 downto 0);
177
  signal gpio_rdata      : std_ulogic_vector(15 downto 0);
178
  signal crc_rdata       : std_ulogic_vector(15 downto 0);
179
  signal cfu_rdata       : std_ulogic_vector(15 downto 0);
180
  signal pwm_rdata       : std_ulogic_vector(15 downto 0);
181
  signal twi_rdata       : std_ulogic_vector(15 downto 0);
182
  signal trng_rdata      : std_ulogic_vector(15 downto 0);
183
  signal exirq_rdata     : std_ulogic_vector(15 downto 0);
184
  signal freq_gen_rdata  : std_ulogic_vector(15 downto 0);
185
  signal sysconfig_rdata : std_ulogic_vector(15 downto 0);
186
 
187
  -- interrupt system --
188
  signal irq       : std_ulogic_vector(03 downto 0);
189
  signal timer_irq : std_ulogic;
190
  signal uart_irq  : std_ulogic;
191
  signal spi_irq   : std_ulogic;
192
  signal twi_irq   : std_ulogic;
193
  signal gpio_irq  : std_ulogic;
194
  signal ext_irq   : std_ulogic;
195
 
196
  -- misc --
197
  signal imem_up_en : std_ulogic;
198
  signal gpio_pwm   : std_ulogic;
199
 
200
begin
201
 
202
  -- Reset Generator ----------------------------------------------------------
203
  -- -----------------------------------------------------------------------------
204
  -- make sure the external reset is free of metastability and has a minimal duration of 1 clock cycle
205
  reset_generator_filter: process(clk_i)
206
  begin
207
    if rising_edge(clk_i) then
208
      rst_i_sync0 <= rst_i;
209
      rst_i_sync1 <= rst_i_sync0; -- no metastability, thanks
210
    end if;
211
  end process reset_generator_filter;
212
 
213
  -- keep internal reset active for at least 4 clock cycles
214
  reset_generator: process(rst_i_sync1, clk_i)
215
  begin
216
    if rising_edge(clk_i) then
217
      if (rst_i_sync1 = '0') then
218
        rst_gen <= (others => '0');
219
      else
220
        rst_gen <= rst_gen(rst_gen'left-1 downto 0) & '1';
221
      end if;
222
    end if;
223
  end process reset_generator;
224
 
225
  ext_rst <= rst_gen(rst_gen'left); -- the beautified external reset signal
226
  sys_rst <= ext_rst and wdt_rst;
227
 
228
 
229
  -- Clock Generator ----------------------------------------------------------
230
  -- -----------------------------------------------------------------------------
231
  clock_generator: process(sys_rst, clk_i)
232
  begin
233
    if (sys_rst = '0') then
234
      clk_div <= (others => '0');
235
    elsif rising_edge(clk_i) then
236
      -- anybody needing fresh clocks?
237
      if ((timer_cg_en or uart_cg_en or spi_cg_en or wdt_cg_en or pwm_cg_en or twi_cg_en or cfu_cg_en or freq_gen_cg_en) = '1') then
238
        clk_div <= std_ulogic_vector(unsigned(clk_div) + 1);
239
      end if;
240
    end if;
241
  end process clock_generator;
242
 
243
  clock_generator_buf: process(clk_i)
244
  begin
245
    if rising_edge(clk_i) then
246
      clk_div_ff <= clk_div;
247
    end if;
248
  end process clock_generator_buf;
249
 
250
  -- clock enable select: rising edge detectors --
251
  clk_gen(clk_div2_c)    <= clk_div(0)  and (not clk_div_ff(0));  -- CLK/2
252
  clk_gen(clk_div4_c)    <= clk_div(1)  and (not clk_div_ff(1));  -- CLK/4
253
  clk_gen(clk_div8_c)    <= clk_div(2)  and (not clk_div_ff(2));  -- CLK/8
254
  clk_gen(clk_div64_c)   <= clk_div(5)  and (not clk_div_ff(5));  -- CLK/64
255
  clk_gen(clk_div128_c)  <= clk_div(6)  and (not clk_div_ff(6));  -- CLK/128
256
  clk_gen(clk_div1024_c) <= clk_div(9)  and (not clk_div_ff(9));  -- CLK/1024
257
  clk_gen(clk_div2048_c) <= clk_div(10) and (not clk_div_ff(10)); -- CLK/2048
258
  clk_gen(clk_div4096_c) <= clk_div(11) and (not clk_div_ff(11)); -- CLK/4096
259
 
260
 
261
  -- The core of the problem: The CPU -----------------------------------------
262
  -- -----------------------------------------------------------------------------
263
  neo430_cpu_inst: neo430_cpu
264
  generic map (
265
    BOOTLD_USE  => BOOTLD_USE,      -- implement and use bootloader? (default=true)
266
    IMEM_AS_ROM => IMEM_AS_ROM      -- implement IMEM as read-only memory?
267
  )
268
  port map (
269
    -- global control --
270
    clk_i      => clk_i,            -- global clock, rising edge
271
    rst_i      => sys_rst,          -- global reset, low-active, async
272
    -- memory interface --
273
    mem_rd_o   => cpu_bus.rd_en,    -- memory read
274
    mem_imwe_o => imem_up_en,       -- allow writing to IMEM
275
    mem_wr_o   => cpu_bus.wr_en,    -- memory write
276
    mem_addr_o => cpu_bus.addr,     -- address
277
    mem_data_o => cpu_bus.wdata,    -- write data
278
    mem_data_i => cpu_bus.rdata,    -- read data
279
    -- interrupt system --
280
    irq_i      => irq              -- interrupt request lines
281
  );
282
 
283
  -- final CPU read data --
284
  cpu_bus.rdata <= rom_rdata or ram_rdata or boot_rdata or muldiv_rdata or
285
                   wb_rdata or uart_rdata or spi_rdata or gpio_rdata or freq_gen_rdata or
286
                   timer_rdata or wdt_rdata or sysconfig_rdata or crc_rdata or
287
                   cfu_rdata or pwm_rdata or twi_rdata or trng_rdata or exirq_rdata;
288
 
289
  -- interrupts: priority assignment --
290
  irq(0) <= timer_irq;                      -- timer match (highest priority)
291
  irq(1) <= uart_irq or spi_irq or twi_irq; -- serial IRQ
292
  irq(2) <= gpio_irq;                       -- GPIO input pin change
293
  irq(3) <= ext_irq;                        -- external interrupt request (lowest priority)
294
 
295
 
296
  -- Main Memory (ROM/IMEM & RAM/DMEM) ----------------------------------------
297
  -- -----------------------------------------------------------------------------
298
  neo430_imem_inst: neo430_imem
299
  generic map (
300
    IMEM_SIZE   => IMEM_SIZE,       -- internal IMEM size in bytes, max 32kB (default=4kB)
301
    IMEM_AS_ROM => IMEM_AS_ROM,     -- implement IMEM as read-only memory?
302
    BOOTLD_USE  => BOOTLD_USE       -- implement and use bootloader? (default=true)
303
  )
304
  port map (
305
    clk_i  => clk_i,                -- global clock line
306
    rden_i => cpu_bus.rd_en,        -- read enable
307
    wren_i => cpu_bus.wr_en,        -- write enable
308
    upen_i => imem_up_en,           -- update enable
309
    addr_i => cpu_bus.addr,         -- address
310
    data_i => cpu_bus.wdata,        -- data in
311
    data_o => rom_rdata             -- data out
312
  );
313
 
314
  neo430_dmem_inst: neo430_dmem
315
  generic map (
316
    DMEM_SIZE => DMEM_SIZE          -- internal DMEM size in bytes, max 28kB (default=2kB)
317
  )
318
  port map (
319
    clk_i  => clk_i,                -- global clock line
320
    rden_i => cpu_bus.rd_en,        -- read enable
321
    wren_i => cpu_bus.wr_en,        -- write enable
322
    addr_i => cpu_bus.addr,         -- address
323
    data_i => cpu_bus.wdata,        -- data in
324
    data_o => ram_rdata             -- data out
325
  );
326
 
327
 
328
  -- Boot ROM -----------------------------------------------------------------
329
  -- -----------------------------------------------------------------------------
330
  neo430_boot_rom_inst_true:
331
  if (BOOTLD_USE = true) generate
332
    neo430_boot_rom_inst: neo430_boot_rom
333
    port map (
334
      clk_i  => clk_i,              -- global clock line
335
      rden_i => cpu_bus.rd_en,      -- read enable
336
      addr_i => cpu_bus.addr,       -- address
337
      data_o => boot_rdata          -- data out
338
    );
339
  end generate;
340
 
341
  neo430_boot_rom_inst_false:
342
  if (BOOTLD_USE = false) generate
343
    boot_rdata <= (others => '0');
344
  end generate;
345
 
346
 
347
  -- IO Access? ---------------------------------------------------------------
348
  -- -----------------------------------------------------------------------------
349
  io_acc   <= '1' when (cpu_bus.addr(15 downto index_size_f(io_size_c)) = io_base_c(15 downto index_size_f(io_size_c))) else '0';
350
  io_rd_en <= cpu_bus.rd_en and io_acc;
351
  io_wr_en <= (cpu_bus.wr_en(0) or cpu_bus.wr_en(1)) and io_acc; -- use all accesses as full-word accesses
352
 
353
 
354
  -- Multiplier/Divider Unit (MULDIV) -----------------------------------------
355
  -- -----------------------------------------------------------------------------
356
  neo430_muldiv_inst_true:
357
  if (MULDIV_USE = true) generate
358
    neo430_muldiv_inst: neo430_muldiv
359
    port map (
360
      -- host access --
361
      clk_i  => clk_i,              -- global clock line
362
      rden_i => io_rd_en,           -- read enable
363
      wren_i => io_wr_en,           -- write enable
364
      addr_i => cpu_bus.addr,       -- address
365
      data_i => cpu_bus.wdata,      -- data in
366
      data_o => muldiv_rdata        -- data out
367
    );
368
  end generate;
369
 
370
  neo430_muldiv_inst_false:
371
  if (MULDIV_USE = false) generate
372
    muldiv_rdata <= (others => '0');
373
  end generate;
374
 
375
 
376
  -- Wishbone Adapter (WB32) --------------------------------------------------
377
  -- -----------------------------------------------------------------------------
378
  neo430_wb32_if_inst_true:
379
  if (WB32_USE = true) generate
380
    neo430_wb32_inst: neo430_wb_interface
381
    port map (
382
      -- host access --
383
      clk_i    => clk_i,            -- global clock line
384
      rden_i   => io_rd_en,         -- read enable
385
      wren_i   => io_wr_en,         -- write enable
386
      addr_i   => cpu_bus.addr,     -- address
387
      data_i   => cpu_bus.wdata,    -- data in
388
      data_o   => wb_rdata,         -- data out
389
      -- wishbone interface --
390
      wb_adr_o => wb_adr_o,         -- address
391
      wb_dat_i => wb_dat_i,         -- read data
392
      wb_dat_o => wb_dat_o,         -- write data
393
      wb_we_o  => wb_we_o,          -- read/write
394
      wb_sel_o => wb_sel_o,         -- byte enable
395
      wb_stb_o => wb_stb_o,         -- strobe
396
      wb_cyc_o => wb_cyc_o,         -- valid cycle
397
      wb_ack_i => wb_ack_i          -- transfer acknowledge
398
    );
399
  end generate;
400
 
401
  neo430_wb32_if_inst_false:
402
  if (WB32_USE = false) generate
403
    wb_rdata <= (others => '0');
404
    wb_adr_o <= (others => '0');
405
    wb_dat_o <= (others => '0');
406
    wb_we_o  <= '0';
407
    wb_sel_o <= (others => '0');
408
    wb_stb_o <= '0';
409
    wb_cyc_o <= '0';
410
  end generate;
411
 
412
 
413
  -- Universal Asynchronous Receiver & Transmitter (UART) ---------------------
414
  -- -----------------------------------------------------------------------------
415
  neo430_uart_inst_true:
416
  if (UART_USE = true) generate
417
    neo430_uart_inst: neo430_uart
418
    port map (
419
      -- host access --
420
      clk_i       => clk_i,         -- global clock line
421
      rden_i      => io_rd_en,      -- read enable
422
      wren_i      => io_wr_en,      -- write enable
423
      addr_i      => cpu_bus.addr,  -- address
424
      data_i      => cpu_bus.wdata, -- data in
425
      data_o      => uart_rdata,    -- data out
426
      -- clock generator --
427
      clkgen_en_o => uart_cg_en,    -- enable clock generator
428
      clkgen_i    => clk_gen,
429
      -- com lines --
430
      uart_txd_o  => uart_txd_o,
431
      uart_rxd_i  => uart_rxd_i,
432
      -- interrupts --
433
      uart_irq_o  => uart_irq       -- uart rx/tx interrupt
434
    );
435
  end generate;
436
 
437
  neo430_uart_inst_false:
438
  if (UART_USE = false) generate
439
    uart_rdata <= (others => '0');
440
    uart_irq   <= '0';
441
    uart_cg_en <= '0';
442
    uart_txd_o <= '1';
443
  end generate;
444
 
445
 
446
  -- Serial Peripheral Interface (SPI) ----------------------------------------
447
  -- -----------------------------------------------------------------------------
448
  neo430_spi_inst_true:
449
  if (SPI_USE = true) generate
450
    neo430_spi_inst: neo430_spi
451
    port map (
452
      -- host access --
453
      clk_i       => clk_i,         -- global clock line
454
      rden_i      => io_rd_en,      -- read enable
455
      wren_i      => io_wr_en,      -- write enable
456
      addr_i      => cpu_bus.addr,  -- address
457
      data_i      => cpu_bus.wdata, -- data in
458
      data_o      => spi_rdata,     -- data out
459
      -- clock generator --
460
      clkgen_en_o => spi_cg_en,     -- enable clock generator
461
      clkgen_i    => clk_gen,
462
      -- com lines --
463
      spi_sclk_o  => spi_sclk_o,    -- SPI serial clock
464
      spi_mosi_o  => spi_mosi_o,    -- SPI master out, slave in
465
      spi_miso_i  => spi_miso_i,    -- SPI master in, slave out
466
      spi_cs_o    => spi_cs_o,      -- SPI CS 0..5
467
      -- interrupt --
468
      spi_irq_o   => spi_irq        -- transmission done interrupt
469
    );
470
  end generate;
471
 
472
  neo430_spi_inst_false:
473
  if (SPI_USE = false) generate
474
    spi_rdata  <= (others => '0');
475
    spi_cg_en  <= '0';
476
    spi_sclk_o <= '0';
477
    spi_mosi_o <= '0';
478
    spi_cs_o   <= (others => '1');
479
    spi_irq    <= '0';
480
  end generate;
481
 
482
 
483
  -- General Purpose Parallel IO (GPIO) ---------------------------------------
484
  -- -----------------------------------------------------------------------------
485
  neo430_gpio_inst_true:
486
  if (GPIO_USE = true) generate
487
    neo430_gpio_inst: neo430_gpio
488
    port map (
489
      -- host access --
490
      clk_i      => clk_i,          -- global clock line
491
      rden_i     => io_rd_en,       -- read enable
492
      wren_i     => io_wr_en,       -- write enable
493
      addr_i     => cpu_bus.addr,   -- address
494
      data_i     => cpu_bus.wdata,  -- data in
495
      data_o     => gpio_rdata,     -- data out
496
      -- parallel io --
497
      gpio_o     => gpio_o,
498
      gpio_i     => gpio_i,
499
     -- GPIO PWM --
500
      gpio_pwm_i => gpio_pwm,
501
      -- interrupt --
502
      irq_o      => gpio_irq        -- pin-change interrupt
503
    );
504
  end generate;
505
 
506
  neo430_gpio_inst_false:
507
  if (GPIO_USE = false) generate
508
    gpio_rdata <= (others => '0');
509
    gpio_o     <= (others => '0');
510
    gpio_irq   <= '0';
511
  end generate;
512
 
513
 
514
  -- High Precision Timer (TIMER) ---------------------------------------------
515
  -- -----------------------------------------------------------------------------
516
  neo430_timer_inst_true:
517
  if (TIMER_USE = true) generate
518
  neo430_timer_inst: neo430_timer
519
    port map (
520
      -- host access --
521
      clk_i       => clk_i,         -- global clock line
522
      rden_i      => io_rd_en,      -- read enable
523
      wren_i      => io_wr_en,      -- write enable
524
      addr_i      => cpu_bus.addr,  -- address
525
      data_i      => cpu_bus.wdata, -- data in
526
      data_o      => timer_rdata,   -- data out
527
      -- clock generator --
528
      clkgen_en_o => timer_cg_en,   -- enable clock generator
529
      clkgen_i    => clk_gen,
530
      -- interrupt --
531
      irq_o       => timer_irq      -- interrupt request
532
    );
533
  end generate;
534
 
535
  neo430_timer_inst_false:
536
  if (TIMER_USE = false) generate
537
    timer_rdata <= (others => '0');
538
    timer_irq   <= '0';
539
    timer_cg_en <= '0';
540
  end generate;
541
 
542
 
543
  -- Watchdog Timer (WDT) -----------------------------------------------------
544
  -- -----------------------------------------------------------------------------
545
  neo430_wdt_inst_true:
546
  if (WDT_USE = true) generate
547
    neo430_wdt_inst: neo430_wdt
548
    port map(
549
      -- host access --
550
      clk_i       => clk_i,         -- global clock line
551
      rst_i       => ext_rst,       -- external reset, low-active, use as async
552
      rden_i      => io_rd_en,      -- read enable
553
      wren_i      => io_wr_en,      -- write enable
554
      addr_i      => cpu_bus.addr,  -- address
555
      data_i      => cpu_bus.wdata, -- data in
556
      data_o      => wdt_rdata,     -- data out
557
      -- clock generator --
558
      clkgen_en_o => wdt_cg_en,     -- enable clock generator
559
      clkgen_i    => clk_gen,       -- clock generator
560
      -- system reset --
561
      rst_o       => wdt_rst        -- timeout reset, low-active, use as async
562
    );
563
  end generate;
564
 
565
  neo430_wdt_inst_false:
566
  if (WDT_USE = false) generate
567
    wdt_rdata <= (others => '0');
568
    wdt_rst   <= '1';
569
    wdt_cg_en <= '0';
570
  end generate;
571
 
572
 
573
  -- Checksum Module (CRC) ----------------------------------------------------
574
  -- -----------------------------------------------------------------------------
575
  neo430_crc_inst_true:
576
  if (CRC_USE = true) generate
577
    neo430_crc_inst: neo430_crc
578
    port map(
579
      -- host access --
580
      clk_i  => clk_i,              -- global clock line
581
      rden_i => io_rd_en,           -- read enable
582
      wren_i => io_wr_en,           -- write enable
583
      addr_i => cpu_bus.addr,       -- address
584
      data_i => cpu_bus.wdata,      -- data in
585
      data_o => crc_rdata           -- data out
586
    );
587
  end generate;
588
 
589
  neo430_crc_inst_false:
590
  if (CRC_USE = false) generate
591
    crc_rdata <= (others => '0');
592
  end generate;
593
 
594
 
595
  -- Custom Functions Unit (CFU) ----------------------------------------------
596
  -- -----------------------------------------------------------------------------
597
  neo430_cfu_inst_true:
598
  if (CFU_USE = true) generate
599
    neo430_cfu_inst: neo430_cfu
600
    port map(
601
      -- host access --
602
      clk_i       => clk_i,         -- global clock line
603
      rden_i      => io_rd_en,      -- read enable
604
      wren_i      => io_wr_en,      -- write enable
605
      addr_i      => cpu_bus.addr,  -- address
606
      data_i      => cpu_bus.wdata, -- data in
607
      data_o      => cfu_rdata,     -- data out
608
      -- clock generator --
609
      clkgen_en_o => cfu_cg_en,     -- enable clock generator
610
      clkgen_i    => clk_gen
611
      -- add custom IOs below --
612
    );
613
  end generate;
614
 
615
  neo430_cfu_inst_false:
616
  if (CFU_USE = false) generate
617
    cfu_cg_en <= '0';
618
    cfu_rdata <= (others => '0');
619
  end generate;
620
 
621
 
622
  -- PWM Controller (PWM) -----------------------------------------------------
623
  -- -----------------------------------------------------------------------------
624
  neo430_pwm_inst_true:
625
  if (PWM_USE = true) generate
626
    neo430_pwm_inst: neo430_pwm
627
    port map(
628
      -- host access --
629
      clk_i       => clk_i,         -- global clock line
630
      rden_i      => io_rd_en,      -- read enable
631
      wren_i      => io_wr_en,      -- write enable
632
      addr_i      => cpu_bus.addr,  -- address
633
      data_i      => cpu_bus.wdata, -- data in
634
      data_o      => pwm_rdata,     -- data out
635
      -- clock generator --
636
      clkgen_en_o => pwm_cg_en,     -- enable clock generator
637
      clkgen_i    => clk_gen,
638
      -- GPIO output PWM --
639
      gpio_pwm_o  => gpio_pwm,
640
      -- pwm output channels --
641
      pwm_o       => pwm_o
642
    );
643
  end generate;
644
 
645
  neo430_pwm_inst_false:
646
  if (PWM_USE = false) generate
647
    pwm_cg_en <= '0';
648
    gpio_pwm  <= '1';
649
    pwm_rdata <= (others => '0');
650
    pwm_o     <= (others => '0');
651
  end generate;
652
 
653
 
654
  -- Two Wire Serial Interface (SPI) ------------------------------------------
655
  -- -----------------------------------------------------------------------------
656
  neo430_twi_inst_true:
657
  if (TWI_USE = true) generate
658
    neo430_twi_inst: neo430_twi
659
    port map (
660
      -- host access --
661
      clk_i       => clk_i,         -- global clock line
662
      rden_i      => io_rd_en,      -- read enable
663
      wren_i      => io_wr_en,      -- write enable
664
      addr_i      => cpu_bus.addr,  -- address
665
      data_i      => cpu_bus.wdata, -- data in
666
      data_o      => twi_rdata,     -- data out
667
      -- clock generator --
668
      clkgen_en_o => twi_cg_en,     -- enable clock generator
669
      clkgen_i    => clk_gen,
670
      -- com lines --
671
      twi_sda_io  => twi_sda_io,    -- serial data line
672
      twi_scl_io  => twi_scl_io,    -- serial clock line
673
      -- interrupt --
674
      twi_irq_o   => twi_irq        -- transfer done IRQ
675
    );
676
  end generate;
677
 
678
  neo430_twi_inst_false:
679
  if (TWI_USE = false) generate
680
    twi_cg_en <= '0';
681
    twi_rdata <= (others => '0');
682
    twi_irq   <= '0';
683
  end generate;
684
 
685
 
686
  -- True Random Number Generator (TRNG) --------------------------------------
687
  -- -----------------------------------------------------------------------------
688
  neo430_trng_inst_true:
689
  if (TRNG_USE = true) generate
690
    neo430_trng_inst: neo430_trng
691
    port map (
692
      -- host access --
693
      clk_i       => clk_i,         -- global clock line
694
      rden_i      => io_rd_en,      -- read enable
695
      wren_i      => io_wr_en,      -- write enable
696
      addr_i      => cpu_bus.addr,  -- address
697
      data_i      => cpu_bus.wdata, -- data in
698
      data_o      => trng_rdata     -- data out
699
    );
700
  end generate;
701
 
702
  neo430_trng_inst_false:
703
  if (TRNG_USE = false) generate
704
    trng_rdata <= (others => '0');
705
  end generate;
706
 
707
 
708
  -- External Interrupts Controller (EXIRQ) -----------------------------------
709
  -- -----------------------------------------------------------------------------
710
  neo430_exirq_inst_true:
711
  if (EXIRQ_USE = true) generate
712
    neo430_exirq_inst: neo430_exirq
713
    port map (
714
      -- host access --
715
      clk_i     => clk_i,           -- global clock line
716
      rden_i    => io_rd_en,        -- read enable
717
      wren_i    => io_wr_en,        -- write enable
718
      addr_i    => cpu_bus.addr,    -- address
719
      data_i    => cpu_bus.wdata,   -- data in
720
      data_o    => exirq_rdata,     -- data out
721
      -- cpu interrupt --
722
      cpu_irq_o => ext_irq,
723
      -- external interrupt lines --
724
      ext_irq_i => ext_irq_i,       -- IRQ
725
      ext_ack_o => ext_ack_o        -- acknowledge
726
    );
727
  end generate;
728
 
729
  neo430_exirq_inst_false:
730
  if (EXIRQ_USE = false) generate
731
    exirq_rdata <= (others => '0');
732
    ext_ack_o   <= (others => '0');
733
    ext_irq     <= '0';
734
  end generate;
735
 
736
 
737
  -- Arbitrary Frequency Generator (FREW_GEN)) --------------------------------
738
  -- -----------------------------------------------------------------------------
739
  neo430_freq_gen_inst_true:
740
  if (FREQ_GEN_USE = true) generate
741
    neo430_freq_gen_inst: neo430_freq_gen
742
    port map (
743
      -- host access --
744
      clk_i       => clk_i,           -- global clock line
745
      rden_i      => io_rd_en,        -- read enable
746
      wren_i      => io_wr_en,        -- write enable
747
      addr_i      => cpu_bus.addr,    -- address
748
      data_i      => cpu_bus.wdata,   -- data in
749
      data_o      => freq_gen_rdata,  -- data out
750
      -- clock generator --
751
      clkgen_en_o => freq_gen_cg_en,  -- enable clock generator
752
      clkgen_i    => clk_gen,
753
      -- frequency generator --
754
      freq_gen_o  => freq_gen_o  -- programmable frequency output
755
    );
756
  end generate;
757
 
758
  neo430_freq_gen_inst_false:
759
  if (FREQ_GEN_USE = false) generate
760
    freq_gen_cg_en <= '0';
761
    freq_gen_rdata <= (others => '0');
762
    freq_gen_o     <= (others => '0');
763
  end generate;
764
 
765
 
766
  -- System Configuration -----------------------------------------------------
767
  -- -----------------------------------------------------------------------------
768
  neo430_sysconfig_inst: neo430_sysconfig
769
  generic map (
770
    -- general configuration --
771
    CLOCK_SPEED  => CLOCK_SPEED,    -- main clock in Hz
772
    IMEM_SIZE    => IMEM_SIZE,      -- internal IMEM size in bytes
773
    DMEM_SIZE    => DMEM_SIZE,      -- internal DMEM size in bytes
774
    -- additional configuration --
775
    USER_CODE    => USER_CODE,      -- custom user code
776
    -- module configuration --
777
    MULDIV_USE   => MULDIV_USE,     -- implement multiplier/divider unit?
778
    WB32_USE     => WB32_USE,       -- implement WB32 unit?
779
    WDT_USE      => WDT_USE,        -- implement WDT?
780
    GPIO_USE     => GPIO_USE,       -- implement GPIO unit?
781
    TIMER_USE    => TIMER_USE,      -- implement timer?
782
    UART_USE     => UART_USE,       -- implement UART?
783
    CRC_USE      => CRC_USE,        -- implement CRC unit?
784
    CFU_USE      => CFU_USE,        -- implement CFU?
785
    PWM_USE      => PWM_USE,        -- implement PWM?
786
    TWI_USE      => TWI_USE,        -- implement TWI?
787
    SPI_USE      => SPI_USE,        -- implement SPI?
788
    TRNG_USE     => TRNG_USE,       -- implement TRNG?
789
    EXIRQ_USE    => EXIRQ_USE,      -- implement EXIRQ?
790
    FREQ_GEN_USE => FREQ_GEN_USE,   -- implement FREQ_GEN?
791
    -- boot configuration --
792
    BOOTLD_USE   => BOOTLD_USE,     -- implement and use bootloader?
793
    IMEM_AS_ROM  => IMEM_AS_ROM     -- implement IMEM as read-only memory?
794
  )
795
  port map (
796
    clk_i  => clk_i,                -- global clock line
797
    rden_i => io_rd_en,             -- read enable
798
    wren_i => io_wr_en,             -- write enable
799
    addr_i => cpu_bus.addr,         -- address
800
    data_i => cpu_bus.wdata,        -- data in
801
    data_o => sysconfig_rdata       -- data out
802
  );
803
 
804
 
805
end neo430_top_rtl;

powered by: WebSVN 2.1.0

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