Advertisement
CoMoDoS

ps2_keyboard

May 15th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.53 KB | None | 0 0
  1.  
  2. library IEEE;
  3. use IEEE.STD_LOGIC_1164.ALL;
  4. use IEEE.STD_LOGIC_ARITH.ALL;
  5. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  6.  
  7. entity ps2_keyboard is
  8.    Port (
  9.       Clock : in std_logic;
  10.       Reset : in std_logic;
  11.       Enable : in std_logic;
  12.       Ps2clock : in std_logic;
  13.       Ps2data : in std_logic;
  14.       Output : out std_logic_vector(7 downto 0);
  15.       Ready: out std_logic;
  16.       Error: out std_logic
  17.    );
  18. end ps2_keyboard;
  19.  
  20. architecture Behavioral of ps2_keyboard is
  21. signal  filtered_clock, filtered_data: std_logic;
  22. type TIP_STARE is (Init, Waait, Read, GetData, DataReady, Done);
  23. signal Stare : TIP_STARE;
  24.  
  25. begin
  26. filter_comp : entity work.filter
  27.    port map(
  28.     Clock => Clock,
  29.     Reset => Reset,
  30.     Enable => Enable,
  31.     Ps2clock => Ps2clock,
  32.     Ps2data  => Ps2data,
  33.     Ps2clock_filtered => filtered_clock,
  34.     Ps2data_filtered  => filtered_data
  35.    );
  36.    
  37. process(Clock)
  38. variable counter:integer:=0;
  39. variable parityCounter:integer:=0;
  40. variable buf:std_logic_vector(8 downto 0):="000000000";
  41. begin
  42. if rising_edge(Clock) then
  43.     if(Reset='1') then
  44.         Stare<=Init;
  45.     elsif(Enable='1') then
  46.         case Stare is
  47.             when Init=>
  48.                 counter:=0;
  49.                 parityCounter:=0;
  50.                 buf:="000000000";
  51.                 if(filtered_clock='0' and filtered_data='0') then
  52.                     Stare<=Waait;
  53.                 end if;
  54.             when Waait=>
  55.                 if(filtered_clock='1') then
  56.                     Stare<=Read;
  57.                 end if;
  58.             when Read=>
  59.                 if(filtered_clock='0') then
  60.                     counter:=counter+1;
  61.                     Stare<=GetData;
  62.                 end if;
  63.             when GetData=>
  64.                 if(filtered_data='1')then
  65.                     parityCounter:=parityCounter+1;
  66.                 end if;
  67.                 buf:=filtered_data & buf(8 downto 1);
  68.                 if(counter<9) then
  69.                     Stare<=Waait;
  70.                 else
  71.                     Stare<=DataReady;
  72.                 end if;
  73.             when DataReady=>
  74.                 if((parityCounter mod 2)=0) then
  75.                     Error<='1';
  76.                 else
  77.                     Error<='0';
  78.                 end if;
  79.                 if(filtered_clock='1' and filtered_data='1') then
  80.                     Output<=buf(7 downto 0);
  81.                     Stare<=Done;
  82.                 end if;
  83.             when Done =>
  84.                 Stare<=Init;
  85.         end case;
  86.     end if;
  87. end if;
  88. end process;
  89.  
  90. Ready<='1' when Stare=Done else '0';
  91. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement