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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_cfs.vhd] - Diff between revs 71 and 73

Show entire file | Details | Blame | View Log

Rev 71 Rev 73
Line 74... Line 74...
  );
  );
end neorv32_cfs;
end neorv32_cfs;
 
 
architecture neorv32_cfs_rtl of neorv32_cfs is
architecture neorv32_cfs_rtl of neorv32_cfs is
 
 
  -- IO space: module base address (DO NOT MODIFY!) --
  -- IO space: module base address --
 
  -- WARNING: Do not modify the CFS base address or the CFS' occupied address
 
  -- space as this might cause access collisions with other processor modules.
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
  constant lo_abb_c : natural := index_size_f(cfs_size_c); -- low address boundary bit
  constant lo_abb_c : natural := index_size_f(cfs_size_c); -- low address boundary bit
 
 
  -- access control --
  -- access control --
  signal acc_en : std_ulogic; -- module access enable
  signal acc_en : std_ulogic; -- module access enable
Line 93... Line 95...
 
 
begin
begin
 
 
  -- Access Control -------------------------------------------------------------------------
  -- Access Control -------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- This logic is required to handle the CPU accesses.
  -- This logic is required to handle the CPU accesses - DO NOT MODIFY!
  -- DO NOT MODIFY this unless you really know what you are doing.
 
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = cfs_base_c(hi_abb_c downto lo_abb_c)) else '0';
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = cfs_base_c(hi_abb_c downto lo_abb_c)) else '0';
  addr   <= cfs_base_c(31 downto lo_abb_c) & addr_i(lo_abb_c-1 downto 2) & "00"; -- word aligned
  addr   <= cfs_base_c(31 downto lo_abb_c) & addr_i(lo_abb_c-1 downto 2) & "00"; -- word aligned
  wren   <= acc_en and wren_i; -- write accesses always write a full 32-bit word
  wren   <= acc_en and wren_i; -- only full-word write accesses are supported
  rden   <= acc_en and rden_i; -- read accesses always return a full 32-bit word
  rden   <= acc_en and rden_i; -- read accesses always return a full 32-bit word
 
 
  -- NOTE: Do not modify the CFS base address or the CFS' occupied address space as this might cause access
 
  -- collisions with other modules.
 
 
 
 
 
  -- CFS Generics ---------------------------------------------------------------------------
  -- CFS Generics ---------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- In it's default version the CFS provides three configuration generics:
  -- In it's default version the CFS provides three configuration generics:
  -- CFS_IN_SIZE  - configures the size (in bits) of the CFS input conduit cfs_in_i
  -- > CFS_IN_SIZE  - configures the size (in bits) of the CFS input conduit cfs_in_i
  -- CFS_OUT_SIZE - configures the size (in bits) of the CFS output conduit cfs_out_o
  -- > CFS_OUT_SIZE - configures the size (in bits) of the CFS output conduit cfs_out_o
  -- CFS_CONFIG   - is a blank 32-bit generic. It is intended as a "generic conduit" to propagate
  -- > CFS_CONFIG   - is a blank 32-bit generic. It is intended as a "generic conduit" to propagate
  --                custom configuration flags from the top entity down to this module.
  --                custom configuration flags from the top entity down to this module.
 
 
 
 
  -- CFS IOs --------------------------------------------------------------------------------
  -- CFS IOs --------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
Line 139... Line 137...
  -- The processor top unit implements a clock generator providing 8 "derived clocks".
  -- The processor top unit implements a clock generator providing 8 "derived clocks".
  -- Actually, these signals should not be used as direct clock signals, but as *clock enable* signals.
  -- Actually, these signals should not be used as direct clock signals, but as *clock enable* signals.
  -- clkgen_i is always synchronous to the main system clock (clk_i).
  -- clkgen_i is always synchronous to the main system clock (clk_i).
  --
  --
  -- The following clock dividers are available:
  -- The following clock dividers are available:
  --  + clkgen_i(clk_div2_c)    -> MAIN_CLK/2
  -- > clkgen_i(clk_div2_c)    -> MAIN_CLK/2
  --  + clkgen_i(clk_div4_c)    -> MAIN_CLK/4
  -- > clkgen_i(clk_div4_c)    -> MAIN_CLK/4
  --  + clkgen_i(clk_div8_c)    -> MAIN_CLK/8
  -- > clkgen_i(clk_div8_c)    -> MAIN_CLK/8
  --  + clkgen_i(clk_div64_c)   -> MAIN_CLK/64
  -- > clkgen_i(clk_div64_c)   -> MAIN_CLK/64
  --  + clkgen_i(clk_div128_c)  -> MAIN_CLK/128
  -- > clkgen_i(clk_div128_c)  -> MAIN_CLK/128
  --  + clkgen_i(clk_div1024_c) -> MAIN_CLK/1024
  -- > clkgen_i(clk_div1024_c) -> MAIN_CLK/1024
  --  + clkgen_i(clk_div2048_c) -> MAIN_CLK/2048
  -- > clkgen_i(clk_div2048_c) -> MAIN_CLK/2048
  --  + clkgen_i(clk_div4096_c) -> MAIN_CLK/4096
  -- > clkgen_i(clk_div4096_c) -> MAIN_CLK/4096
  --
  --
  -- For instance, if you want to drive a clock process at MAIN_CLK/8 clock speed you can use the following construct:
  -- For instance, if you want to drive a clock process at MAIN_CLK/8 clock speed you can use the following construct:
  --
  --
  --   if (rstn_i = '0') then -- async and low-active reset (if required at all)
  --   if (rstn_i = '0') then -- async and low-active reset (if required at all)
  --   ...
  --   ...
  --   elsif rising_edge(clk_i) then -- always use the main clock for all clock processes!
  --   elsif rising_edge(clk_i) then -- always use the main clock for all clock processes
  --     if (clkgen_i(clk_div8_c) = '1') then -- the div8 "clock" is actually a clock enable
  --     if (clkgen_i(clk_div8_c) = '1') then -- the div8 "clock" is actually a clock enable
  --       ...
  --       ...
  --     end if;
  --     end if;
  --   end if;
  --   end if;
  --
  --
  -- The clkgen_i input clocks are available when at least one IO/peripheral device (for example the UART) requires the clocks
  -- The clkgen_i input clocks are available when at least one IO/peripheral device (for example UART0) requires the clocks
  -- generated by the clock generator. The CFS can enable the clock generator by itself by setting the clkgen_en_o signal high.
  -- generated by the clock generator. The CFS can enable the clock generator by itself by setting the clkgen_en_o signal high.
  -- The CFS cannot ensure to deactivate the clock generator by setting the clkgen_en_o signal low as other peripherals might
  -- The CFS cannot ensure to deactivate the clock generator by setting the clkgen_en_o signal low as other peripherals might
  -- still keep the generator activated. Make sure to deactivate the CFS's clkgen_en_o if no clocks are required in here to
  -- still keep the generator activated. Make sure to deactivate the CFS's clkgen_en_o if no clocks are required in here to
  -- reduce dynamic power consumption.
  -- reduce dynamic power consumption.
 
 
Line 179... Line 177...
  irq_o <= '0'; -- not used for this minimal example
  irq_o <= '0'; -- not used for this minimal example
 
 
 
 
  -- Read/Write Access ----------------------------------------------------------------------
  -- Read/Write Access ----------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- Here we are reading/writing from/to the interface registers of the module. Please note that the peripheral/IO modules
  -- Here we are reading/writing from/to the interface registers of the module and generate the CPU access handshake (bus response).
  -- of the NEORV32 can only be written in full word mode (32-bit). Any other write accesses (half-word or byte) will raise
 
  -- a store bus access fault exception.
 
  --
  --
  -- The CFS provides up to 32 memory-mapped 32-bit interface register. For instance, these could be used to provide a
  -- The CFS provides up to 32 memory-mapped 32-bit interface registers. For instance, these could be used to provide a
  -- <control register> for global control of the unit, a <data register> for reading/writing from/to a data FIFO, a
  -- <control register> for global control of the unit, a <data register> for reading/writing from/to a data FIFO, a
  -- <command register> for issuing commands and a <status register> for status information.
  -- <command register> for issuing commands and a <status register> for status information.
  --
  --
  -- Following the interface protocol, each read or write access has to be acknowledged in the following cycle using the ack_o
  -- Following the interface protocol, each read or write access has to be acknowledged in the following cycle using the ack_o
  -- signal (or even later if the module needs additional time; exceeding the maximum ACK latency will raise a bus exception).
  -- signal (or even later if the module needs additional time). If no ACK is generated at all, the bus access will time out
  -- If no ACK is generated at all, the bus access will time out and cause a bus access fault exception.
  -- and cause a bus access fault exception.
  --
  --
  -- This module also provides an optional ERROR signal to indicate a faulty access operation (for example when accessing an
  -- This module also provides an optional ERROR signal to indicate a faulty access operation (for example when accessing an
  -- unused, read-only or "locked" CFS register address). This signal may only be set when the module is actually accessed
  -- unused, read-only or "locked" CFS register address). This signal may only be set when the module is actually accessed
  -- and is asserted INSTEAD of the ACK signal. Setting the ERR signal will raise a bus access exception that can be handled
  -- and is set INSTEAD of the ACK signal. Setting the ERR signal will raise a bus access exception with a "Device Error" qualifier
  -- by the application software.
  -- that can be handled by the application software.
 
 
  err_o <= '0'; -- Tie to zero if not explicitly used.
  err_o <= '0'; -- Tie to zero if not explicitly used.
 
 
  -- Host access: Read and write access to the interface registers + bus transfer acknowledge. This example only implements
 
  -- four physical r/w register (the four lowest CFS registers). The remaining addresses of the CFS are not associated with
  -- Host access example: Read and write access to the interface registers + bus transfer acknowledge. This example only
  -- any physical registers - any access to those is simply ignored but still acknowledged.
  -- implements four physical r/w register (the four lowest CFS registers). The remaining addresses of the CFS are not associated
 
  -- with any physical registers - any access to those is simply ignored but still acknowledged. Only full-word write accesses are
 
  -- supported (and acknowledged) by this example. Sub-word write access will not alter any CFS register state and will cause
 
  -- a "bus store access" exception (with a "Device Timeout" qualifier as not ACK is generated in that case).
 
 
  host_access: process(clk_i)
  host_access: process(clk_i)
  begin
  begin
    if rising_edge(clk_i) then -- synchronous interface for read and write accesses
    if rising_edge(clk_i) then -- synchronous interface for read and write accesses
      -- transfer/access acknowledge --
      -- transfer/access acknowledge --
      ack_o <= rden or wren; -- default: required for the CPU to check the CFS is answering a bus read OR write request;
      -- default: required for the CPU to check the CFS is answering a bus read OR write request;
                             -- all r/w accesses (to any cfs_reg) will succeed
      -- all read and write accesses (to any cfs_reg, even if there is no according physical register implemented) will succeed.
 
      ack_o <= rden or wren;
 
 
      -- write access --
      -- write access --
      if (wren = '1') then
      if (wren = '1') then -- full-word write access, high for one cycle if there is an actual write access
        if (addr = cfs_reg0_addr_c) then -- make sure to use the internal "addr" signal for the read/write interface
        if (addr = cfs_reg0_addr_c) then -- make sure to use the internal "addr" signal for the read/write interface
          cfs_reg_wr(0) <= data_i; -- physical register, for example: control register
          cfs_reg_wr(0) <= data_i; -- some physical register, for example: control register
        end if;
        end if;
        if (addr = cfs_reg1_addr_c) then
        if (addr = cfs_reg1_addr_c) then
          cfs_reg_wr(1) <= data_i; -- physical register, for example: data in/out fifo
          cfs_reg_wr(1) <= data_i; -- some physical register, for example: data in/out fifo
        end if;
        end if;
        if (addr = cfs_reg2_addr_c) then
        if (addr = cfs_reg2_addr_c) then
          cfs_reg_wr(2) <= data_i; -- physical register, for example: command fifo
          cfs_reg_wr(2) <= data_i; -- some physical register, for example: command fifo
        end if;
        end if;
        if (addr = cfs_reg3_addr_c) then
        if (addr = cfs_reg3_addr_c) then
          cfs_reg_wr(3) <= data_i; -- physical register, for example: status register
          cfs_reg_wr(3) <= data_i; -- some physical register, for example: status register
        end if;
        end if;
      end if;
      end if;
 
 
      -- read access --
      -- read access --
      data_o <= (others => '0'); -- the output has to be zero if there is no actual read access
      data_o <= (others => '0'); -- the output HAS TO BE ZERO if there is no actual read access
      if (rden = '1') then -- the read access is always a full 32-bit word wide
      if (rden = '1') then -- the read access is always 32-bit wide, high for one cycle if there is an actual read access
        case addr is -- make sure to use the internal 'addr' signal for the read/write interface
        case addr is -- make sure to use the internal 'addr' signal for the read/write interface
          when cfs_reg0_addr_c => data_o <= cfs_reg_rd(0);
          when cfs_reg0_addr_c => data_o <= cfs_reg_rd(0);
          when cfs_reg1_addr_c => data_o <= cfs_reg_rd(1);
          when cfs_reg1_addr_c => data_o <= cfs_reg_rd(1);
          when cfs_reg2_addr_c => data_o <= cfs_reg_rd(2);
          when cfs_reg2_addr_c => data_o <= cfs_reg_rd(2);
          when cfs_reg3_addr_c => data_o <= cfs_reg_rd(3);
          when cfs_reg3_addr_c => data_o <= cfs_reg_rd(3);
Line 245... Line 245...
  -- CFS Function Core ----------------------------------------------------------------------
  -- CFS Function Core ----------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
 
 
  -- This is where the actual functionality can be implemented.
  -- This is where the actual functionality can be implemented.
  -- The logic below is just a very simple example that transforms data
  -- The logic below is just a very simple example that transforms data
  -- from an inpout register into data in an output register.
  -- from an input register into data in an output register.
  cfs_core_logic: process(cfs_reg_wr)
 
  begin
 
    cfs_reg_rd(0) <= bin_to_gray_f(cfs_reg_wr(0)); -- convert binary to gray code
    cfs_reg_rd(0) <= bin_to_gray_f(cfs_reg_wr(0)); -- convert binary to gray code
    cfs_reg_rd(1) <= gray_to_bin_f(cfs_reg_wr(1)); -- convert gray to binary code
    cfs_reg_rd(1) <= gray_to_bin_f(cfs_reg_wr(1)); -- convert gray to binary code
    cfs_reg_rd(2) <= bit_rev_f(cfs_reg_wr(2)); -- bit reversal
    cfs_reg_rd(2) <= bit_rev_f(cfs_reg_wr(2)); -- bit reversal
    cfs_reg_rd(3) <= bswap32_f(cfs_reg_wr(3)); -- byte swap (endianness conversion)
    cfs_reg_rd(3) <= bswap32_f(cfs_reg_wr(3)); -- byte swap (endianness conversion)
  end process cfs_core_logic;
 
 
 
 
 
end neorv32_cfs_rtl;
end neorv32_cfs_rtl;
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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