gpio.vhd 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --+-----------------------------------+-------------------------------------+--
  2. --| ___ ___ | (c) 2013-2014 William R Sowerbutts |--
  3. --| ___ ___ ___ ___( _ ) / _ \ | will@sowerbutts.com |--
  4. --| / __|/ _ \ / __|_ / _ \| | | | | |--
  5. --| \__ \ (_) | (__ / / (_) | |_| | | A Z80 FPGA computer, just for fun |--
  6. --| |___/\___/ \___/___\___/ \___/ | |--
  7. --| | http://sowerbutts.com/ |--
  8. --+-----------------------------------+-------------------------------------+--
  9. --| Simple GPIO interface providing 8 bits each of input and output |--
  10. --+-------------------------------------------------------------------------+--
  11. library IEEE;
  12. use IEEE.STD_LOGIC_1164.ALL;
  13. use IEEE.NUMERIC_STD.ALL;
  14. entity gpio is
  15. port ( clk : in std_logic;
  16. reset : in std_logic;
  17. cpu_address : in std_logic_vector(2 downto 0);
  18. data_in : in std_logic_vector(7 downto 0);
  19. data_out : out std_logic_vector(7 downto 0);
  20. enable : in std_logic;
  21. read_notwrite : in std_logic;
  22. input_pins : in std_logic_vector(7 downto 0);
  23. output_pins : out std_logic_vector(7 downto 0)
  24. );
  25. end gpio;
  26. architecture Behavioral of gpio is
  27. signal captured_inputs : std_logic_vector(7 downto 0);
  28. signal register_outputs : std_logic_vector(7 downto 0) := (others => '1');
  29. begin
  30. with cpu_address select
  31. data_out <=
  32. captured_inputs when "000",
  33. register_outputs when "001",
  34. register_outputs when others;
  35. output_pins <= register_outputs;
  36. gpio_proc: process(clk)
  37. begin
  38. if rising_edge(clk) then
  39. if reset = '1' then
  40. captured_inputs <= (others => '0');
  41. register_outputs <= (others => '1');
  42. else
  43. captured_inputs <= input_pins;
  44. if enable = '1' and read_notwrite = '0' then
  45. case cpu_address is
  46. when "000" => -- no change
  47. when "001" => register_outputs <= data_in;
  48. when others => -- no change
  49. end case;
  50. end if;
  51. end if;
  52. end if;
  53. end process;
  54. end Behavioral;