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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_gpio.vhd] - Diff between revs 60 and 61

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

Rev 60 Rev 61
Line 1... Line 1...
-- #################################################################################################
-- #################################################################################################
-- # << NEORV32 - General Purpose Parallel Input/Output Port (GPIO) >>                             #
-- # << NEORV32 - General Purpose Parallel Input/Output Port (GPIO) >>                             #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # 32-bit parallel input & output unit. Any pin change (HI->LO or LO->HI) of an enabled input    #
-- # 64-bit general purpose parallel input & output port unit.                                     #
-- # pin (via irq_en register) triggers an IRQ.                                                    #
 
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # BSD 3-Clause License                                                                          #
-- # BSD 3-Clause License                                                                          #
-- #                                                                                               #
-- #                                                                                               #
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
-- #                                                                                               #
-- #                                                                                               #
Line 51... Line 50...
    wren_i : in  std_ulogic; -- write enable
    wren_i : in  std_ulogic; -- 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(31 downto 0);
    gpio_o : out std_ulogic_vector(63 downto 0);
    gpio_i : in  std_ulogic_vector(31 downto 0);
    gpio_i : in  std_ulogic_vector(63 downto 0)
    -- interrupt --
 
    irq_o  : out std_ulogic
 
  );
  );
end neorv32_gpio;
end neorv32_gpio;
 
 
architecture neorv32_gpio_rtl of neorv32_gpio is
architecture neorv32_gpio_rtl of neorv32_gpio is
 
 
Line 69... Line 66...
  -- 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(31 downto 0); -- r/-
  signal din_lo,  din_hi  : std_ulogic_vector(31 downto 0); -- r/-
  signal dout   : std_ulogic_vector(31 downto 0); -- r/w
  signal dout_lo, dout_hi : std_ulogic_vector(31 downto 0); -- r/w
  signal irq_en : std_ulogic_vector(31 downto 0); -- -/w, uses the same address as data_in
 
 
 
  -- misc --
 
  signal in_buf : std_ulogic_vector(31 downto 0);
 
 
 
begin
begin
 
 
  -- Access Control -------------------------------------------------------------------------
  -- Access Control -------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
Line 89... Line 82...
  -- Read/Write Access ----------------------------------------------------------------------
  -- Read/Write Access ----------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  rw_access: process(clk_i)
  rw_access: process(clk_i)
  begin
  begin
    if rising_edge(clk_i) then
    if rising_edge(clk_i) then
 
      -- bus handshake --
      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_in_addr_c) then
        if (addr = gpio_out_lo_addr_c) then
          irq_en <= data_i; -- pin change IRQ enable
          dout_lo <= data_i;
        else -- gpio_out_addr_c
        end if;
          dout <= data_i; -- data output port
        if (addr = gpio_out_hi_addr_c) then
 
          dout_hi <= data_i;
        end if;
        end if;
      end if;
      end if;
 
 
 
      -- input buffer --
 
      din_lo <= gpio_i(31 downto 00);
 
      din_hi <= gpio_i(63 downto 32);
 
 
      -- 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
        case addr is
          data_o <= din; -- data input port
          when gpio_in_lo_addr_c  => data_o <= din_lo;
        else -- gpio_out_addr_c
          when gpio_in_hi_addr_c  => data_o <= din_hi;
          data_o <= dout; -- data output port
          when gpio_out_lo_addr_c => data_o <= dout_lo;
        end if;
          when gpio_out_hi_addr_c => data_o <= dout_hi;
 
          when others             => data_o <= (others => '0');
 
        end case;
      end if;
      end if;
 
 
    end if;
    end if;
  end process rw_access;
  end process rw_access;
 
 
  -- output --
  -- output --
  gpio_o <= dout;
  gpio_o <= dout_hi & dout_lo;
 
 
 
 
  -- IRQ Detector ------------------------------------------------------------
 
  -- -----------------------------------------------------------------------------
 
  irq_detector: process(clk_i)
 
  begin
 
    if rising_edge(clk_i) then
 
      -- input synchronizer --
 
      in_buf <= gpio_i;
 
      din    <= in_buf;
 
      -- IRQ --
 
      irq_o <= or_reduce_f((in_buf xor din) and irq_en); -- any enabled pin transition triggers an interrupt
 
    end if;
 
  end process irq_detector;
 
 
 
 
 
end neorv32_gpio_rtl;
end neorv32_gpio_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.