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

Subversion Repositories neo430

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 198 zero_gravi
-- #################################################################################################
2
-- #  << NEO430 - Custom Functions Unit >>                                                         #
3
-- # ********************************************************************************************* #
4
-- # This unit is a template for implementing custom functions, which are directly memory-mapped   #
5
-- # into the CPU's IO address space. The address space of this unit is 16 bytes large. This unit  #
6
-- # can only be accessed using full word (16-bit) accesses.                                       #
7
-- # In the original state, this unit only provides 8 16-bit register, that do not perform any     #
8
-- # kind of data manipulation.                                                                    #
9
-- # Exemplary applications: Cryptography, complex arithmetic, rocket science, ...                 #
10
-- # ********************************************************************************************* #
11
-- # BSD 3-Clause License                                                                          #
12
-- #                                                                                               #
13
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
14
-- #                                                                                               #
15
-- # Redistribution and use in source and binary forms, with or without modification, are          #
16
-- # permitted provided that the following conditions are met:                                     #
17
-- #                                                                                               #
18
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
19
-- #    conditions and the following disclaimer.                                                   #
20
-- #                                                                                               #
21
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
22
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
23
-- #    provided with the distribution.                                                            #
24
-- #                                                                                               #
25
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
26
-- #    endorse or promote products derived from this software without specific prior written      #
27
-- #    permission.                                                                                #
28
-- #                                                                                               #
29
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
30
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
31
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
32
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
33
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
34
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
35
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
36
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
37
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
38
-- # ********************************************************************************************* #
39
-- # The NEO430 Processor - https://github.com/stnolting/neo430                                    #
40
-- #################################################################################################
41
 
42
library ieee;
43
use ieee.std_logic_1164.all;
44
use ieee.numeric_std.all;
45
 
46
library neo430;
47
use neo430.neo430_package.all;
48
 
49
entity neo430_cfu is
50
  port (
51
    -- host access --
52
    clk_i       : in  std_ulogic; -- global clock line
53
    rden_i      : in  std_ulogic; -- read enable
54
    wren_i      : in  std_ulogic; -- write enable
55
    addr_i      : in  std_ulogic_vector(15 downto 0); -- address
56
    data_i      : in  std_ulogic_vector(15 downto 0); -- data in
57
    data_o      : out std_ulogic_vector(15 downto 0); -- data out
58
    -- clock generator --
59
    clkgen_en_o : out std_ulogic; -- enable clock generator
60
    clkgen_i    : in  std_ulogic_vector(07 downto 0)
61
    -- custom IOs --
62
--  ...
63
  );
64
end neo430_cfu;
65
 
66
architecture neo430_cfu_rtl of neo430_cfu is
67
 
68
  -- IO space: module base address --
69
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
70
  constant lo_abb_c : natural := index_size_f(cfu_size_c); -- low address boundary bit
71
 
72
  -- access control --
73
  signal acc_en : std_ulogic; -- module access enable
74
  signal addr   : std_ulogic_vector(15 downto 0); -- access address
75
  signal wren   : std_ulogic; -- full word write enable
76
  signal rden   : std_ulogic; -- read enable
77
 
78
  -- accessible regs (8x16-bit) --
79
  signal cfu_ctrl_reg : std_ulogic_vector(15 downto 0);
80
  signal user_reg1    : std_ulogic_vector(15 downto 0);
81
  signal user_reg2    : std_ulogic_vector(15 downto 0);
82
  signal user_reg3    : std_ulogic_vector(15 downto 0);
83
  signal user_reg4    : std_ulogic_vector(15 downto 0);
84
  signal user_reg5    : std_ulogic_vector(15 downto 0);
85
  signal user_reg6    : std_ulogic_vector(15 downto 0);
86
  signal user_reg7    : std_ulogic_vector(15 downto 0);
87
 
88
begin
89
 
90
  -- Access Control -----------------------------------------------------------
91
  -- -----------------------------------------------------------------------------
92
  -- These assignments are required to check if this unit is accessed at all.
93
  -- Do NOT modify this for your custom application (unless you really know what you are doing)!
94
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = cfu_base_c(hi_abb_c downto lo_abb_c)) else '0';
95
  addr   <= cfu_base_c(15 downto lo_abb_c) & addr_i(lo_abb_c-1 downto 1) & '0'; -- word aligned
96
  wren   <= acc_en and wren_i;
97
  rden   <= acc_en and rden_i;
98
 
99
 
100
  -- Clock System -------------------------------------------------------------
101
  -- -----------------------------------------------------------------------------
102
  -- The top unit implements a clock generator providing 8 "derived clocks"
103
  -- Actually, these signals must not be used as direct clock signals, but as clock enable signals.
104
  -- If wou want to drive a system at MAIN_CLK/8 use the following construct:
105
 
106
  -- if rising_edge(clk_i) then -- Always use the main clock for all clock processes!
107
  --   if (clkgen_i(clk_div8_c) = '1') then -- the div8 "clock" is actually a clock enable
108
  --     ...
109
  --   end if;
110
  -- end if;
111
 
112
  -- The following clock divider rates are available:
113
  -- clkgen_i(clk_div2_c)    -> MAIN_CLK/2
114
  -- clkgen_i(clk_div4_c)    -> MAIN_CLK/4
115
  -- clkgen_i(clk_div8_c)    -> MAIN_CLK/8
116
  -- clkgen_i(clk_div64_c)   -> MAIN_CLK/64
117
  -- clkgen_i(clk_div128_c)  -> MAIN_CLK/128
118
  -- clkgen_i(clk_div1024_c) -> MAIN_CLK/1024
119
  -- clkgen_i(clk_div2048_c) -> MAIN_CLK/2048
120
  -- clkgen_i(clk_div4096_c) -> MAIN_CLK/4096
121
 
122
  -- this signal enabled the generator driving the clkgen_i
123
  -- set this signal to '0' when you do not need the clkgen_i signal or when your CFU is disabled
124
  -- to reduce dynamic power consumption
125
  clkgen_en_o <= '0';
126
 
127
 
128
  -- Write access -------------------------------------------------------------
129
  -- -----------------------------------------------------------------------------
130
  -- Here we are writing to the interface registers of the module. This unit can only be accessed
131
  -- in full 16-bit word mode!
132
  -- Please note, that all register of every unit are cleared during the processor boot sequence.
133
  -- Make cfu_reg0_addr_c the CFU's control register. This register is cleared first during booting.
134
  -- If the control register is cleared no actions should be taken when writing to other CFU registers.
135
  wr_access: process(clk_i)
136
  begin
137
    if rising_edge(clk_i) then
138
      -- write access to user registers --
139
      if (wren = '1') then -- valid write access
140
        -- use full-parallel IFs instead of a CASE to prevent some EDA tools from complaining (GHDL)
141
        if (addr = cfu_reg0_addr_c) then
142
          cfu_ctrl_reg <= data_i;
143
        end if;
144
        if (addr = cfu_reg1_addr_c) then
145
          user_reg1 <= data_i;
146
        end if;
147
        if (addr = cfu_reg2_addr_c) then
148
          user_reg2 <= data_i;
149
        end if;
150
        if (addr = cfu_reg3_addr_c) then
151
          user_reg3 <= data_i;
152
        end if;
153
        if (addr = cfu_reg4_addr_c) then
154
          user_reg4 <= data_i;
155
        end if;
156
        if (addr = cfu_reg5_addr_c) then
157
          user_reg5 <= data_i;
158
        end if;
159
        if (addr = cfu_reg6_addr_c) then
160
          user_reg6 <= data_i;
161
        end if;
162
        if (addr = cfu_reg7_addr_c) then
163
          user_reg7 <= data_i;
164
        end if;
165
      end if;
166
    end if;
167
  end process wr_access;
168
 
169
  -- >>> UNIT HARDWARE RESET <<< --
170
  -- The IO devices DO NOT feature a dedicated reset signal, so make sure your CFU does not require a defined initial state.
171
  -- If you really require a defined initial state, implement a software reset by implementing a control register with an
172
  -- enable bit, which resets all internal states when cleared.
173
 
174
 
175
  -- Read access --------------------------------------------------------------
176
  -- -----------------------------------------------------------------------------
177
  -- This is the read access process. Data must be asserted synchronously to the output data bus
178
  -- and thus, with exactly 1 cycle delay. The units always output a full 16-bit word, no matter if we want to
179
  -- read 8- or 16-bit. For actual 8-bit read accesses the corresponding byte is selected in the
180
  -- hardware of the CPU core.
181
  rd_access: process(clk_i)
182
  begin
183
    if rising_edge(clk_i) then
184
      data_o <= (others => '0'); -- this is crucial for the final OR-ing of all IO device's outputs
185
      if (rden = '1') then -- valid read access
186
        -- use IFs instead of a CASE to prevent some EDA tools from complaining (GHDL)
187
        if (addr = cfu_reg0_addr_c) then
188
          data_o <= cfu_ctrl_reg;
189
        elsif (addr = cfu_reg1_addr_c) then
190
          data_o <= user_reg1;
191
        elsif (addr = cfu_reg2_addr_c) then
192
          data_o <= user_reg2;
193
        elsif (addr = cfu_reg3_addr_c) then
194
          data_o <= user_reg3;
195
        elsif (addr = cfu_reg4_addr_c) then
196
          data_o <= user_reg4;
197
        elsif (addr = cfu_reg5_addr_c) then
198
          data_o <= user_reg5;
199
        elsif (addr = cfu_reg6_addr_c) then
200
          data_o <= user_reg6;
201
        elsif (addr = cfu_reg7_addr_c) then
202
          data_o <= user_reg7;
203
        else
204
          data_o <= (others => '0');
205
        end if;
206
      end if;
207
    end if;
208
  end process rd_access;
209
 
210
 
211
end neo430_cfu_rtl;

powered by: WebSVN 2.1.0

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