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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_gpio.vhd] - Diff between revs 2 and 22

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 2 Rev 22
Line 1... Line 1...
-- #################################################################################################
-- #################################################################################################
-- # << NEORV32 - General Purpose Parallel Input/Output Port (GPIO) >>                             #
-- # << NEORV32 - General Purpose Parallel Input/Output Port (GPIO) >>                             #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # 16-bit parallel input & output unit. Any pin-change (HI->LO or LO->HI) triggers the IRQ.      #
-- # 32-bit parallel input & output unit. Any pin change (HI->LO or LO->HI) triggers an IRQ.       #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # BSD 3-Clause License                                                                          #
-- # BSD 3-Clause License                                                                          #
-- #                                                                                               #
-- #                                                                                               #
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
-- #                                                                                               #
-- #                                                                                               #
Line 46... Line 46...
    -- host access --
    -- host access --
    clk_i  : in  std_ulogic; -- global clock line
    clk_i  : in  std_ulogic; -- global clock line
    addr_i : in  std_ulogic_vector(31 downto 0); -- address
    addr_i : in  std_ulogic_vector(31 downto 0); -- address
    rden_i : in  std_ulogic; -- read enable
    rden_i : in  std_ulogic; -- read enable
    wren_i : in  std_ulogic; -- write enable
    wren_i : in  std_ulogic; -- write enable
    ben_i  : in  std_ulogic_vector(03 downto 0); -- byte write enable
 
    data_i : in  std_ulogic_vector(31 downto 0); -- data in
    data_i : in  std_ulogic_vector(31 downto 0); -- data in
    data_o : out std_ulogic_vector(31 downto 0); -- data out
    data_o : out std_ulogic_vector(31 downto 0); -- data out
    ack_o  : out std_ulogic; -- transfer acknowledge
    ack_o  : out std_ulogic; -- transfer acknowledge
    -- parallel io --
    -- parallel io --
    gpio_o : out std_ulogic_vector(15 downto 0);
    gpio_o : out std_ulogic_vector(31 downto 0);
    gpio_i : in  std_ulogic_vector(15 downto 0);
    gpio_i : in  std_ulogic_vector(31 downto 0);
    -- interrupt --
    -- interrupt --
    irq_o  : out std_ulogic
    irq_o  : out std_ulogic
  );
  );
end neorv32_gpio;
end neorv32_gpio;
 
 
Line 69... Line 68...
  -- access control --
  -- access control --
  signal acc_en : std_ulogic; -- module access enable
  signal acc_en : std_ulogic; -- module access enable
  signal addr   : std_ulogic_vector(31 downto 0); -- access address
  signal addr   : std_ulogic_vector(31 downto 0); -- access address
 
 
  -- accessible regs --
  -- accessible regs --
  signal din  : std_ulogic_vector(15 downto 0); -- r/w
  signal din  : std_ulogic_vector(31 downto 0); -- r/w
  signal dout : std_ulogic_vector(15 downto 0); -- r/w
  signal dout : std_ulogic_vector(31 downto 0); -- r/w
 
 
  -- misc --
  -- misc --
  signal in_buf, din2 : std_ulogic_vector(15 downto 0);
  signal in_buf : std_ulogic_vector(31 downto 0);
 
 
begin
begin
 
 
  -- Access Control -------------------------------------------------------------------------
  -- Access Control -------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
Line 92... Line 91...
    if rising_edge(clk_i) then
    if rising_edge(clk_i) then
      ack_o <= acc_en and (rden_i or wren_i);
      ack_o <= acc_en and (rden_i or wren_i);
      -- write access --
      -- write access --
      if ((acc_en and wren_i) = '1') then
      if ((acc_en and wren_i) = '1') then
        if (addr = gpio_out_addr_c) then
        if (addr = gpio_out_addr_c) then
          for i in 0 to 1 loop
          dout <= data_i;
            if (ben_i(i) = '1') then
 
              dout(7+i*8 downto 0+i*8) <= data_i(7+i*8 downto 0+i*8);
 
            end if;
 
          end loop;
 
        end if;
        end if;
      end if;
      end if;
      -- read access --
      -- read access --
      data_o <= (others => '0');
      data_o <= (others => '0');
      if ((acc_en and rden_i) = '1') then
      if ((acc_en and rden_i) = '1') then
        if (addr = gpio_in_addr_c) then
        if (addr = gpio_in_addr_c) then
          data_o(15 downto 0) <= din;
          data_o <= din;
        else -- gpio_out_addr_c
        else -- gpio_out_addr_c
          data_o(15 downto 0) <= dout;
          data_o <= dout;
        end if;
        end if;
      end if;
      end if;
    end if;
    end if;
  end process rw_access;
  end process rw_access;
 
 
Line 123... Line 118...
  begin
  begin
    if rising_edge(clk_i) then
    if rising_edge(clk_i) then
      -- input synchronizer --
      -- input synchronizer --
      in_buf <= gpio_i;
      in_buf <= gpio_i;
      din    <= in_buf;
      din    <= in_buf;
      din2   <= din;
 
      -- IRQ --
      -- IRQ --
      irq_o <= or_all_f(din xor din2); -- any transition triggers an interrupt
      irq_o <= or_all_f(in_buf xor din); -- any transition triggers an interrupt
    end if;
    end if;
  end process irq_detector;
  end process irq_detector;
 
 
 
 
end neorv32_gpio_rtl;
end neorv32_gpio_rtl;

powered by: WebSVN 2.1.0

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