138 lines
4.2 KiB
VHDL
138 lines
4.2 KiB
VHDL
----------------------------------------------------------------------------------
|
|
-- Company: INSA-Toulouse
|
|
-- Engineer: Paul Faure
|
|
--
|
|
-- Create Date: 01.07.2021 09:09:30
|
|
-- Module Name: KeyboardControler - Behavioral
|
|
-- Project Name: Processeur sécurisé
|
|
-- Target Devices: Basys 3 ARTIX7
|
|
-- Tool Versions: Vivado 2016.4
|
|
--
|
|
-- Description: ALU
|
|
--
|
|
-- Dependencies: Fait le lien avec le BUS PS2 du clavier, récupère la touche tapée et la renvoi
|
|
--
|
|
-- Comments : Il n'y a pas de bufferisation
|
|
----------------------------------------------------------------------------------
|
|
|
|
|
|
library IEEE;
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
|
|
|
entity KeyboardControler is
|
|
Port (CLK : in STD_LOGIC;
|
|
|
|
PS2Clk : in STD_LOGIC;
|
|
PS2Data : in STD_LOGIC;
|
|
|
|
Data_av : out STD_LOGIC;
|
|
Data : out STD_LOGIC_VECTOR (0 to 7);
|
|
|
|
alert : out STD_LOGIC);
|
|
end KeyboardControler;
|
|
|
|
architecture Behavioral of KeyboardControler is
|
|
|
|
-- Compteur pour récupérer la trame PS2
|
|
subtype compteur_T is Natural range 0 to 10;
|
|
signal compteur : compteur_T := 0;
|
|
|
|
-- Trame en cours de lecture
|
|
signal current_data : STD_LOGIC_VECTOR (0 to 7) := (others => '0');
|
|
-- Denière trame lue
|
|
signal previous_data : STD_LOGIC_VECTOR (0 to 7) := (others => '0');
|
|
|
|
-- Signaux pour controler le bit de parité de la trame
|
|
signal parity : STD_LOGIC := '0';
|
|
signal intern_alert : STD_LOGIC := '0';
|
|
|
|
-- Signaux pour signaler qu'une touche a été préssée
|
|
signal intern_Data_av : STD_LOGIC := '0';
|
|
signal dejaSignale : boolean := false;
|
|
|
|
begin
|
|
|
|
-- process de récupération de la trame, synchronisé sur la CLK du bus PS2
|
|
-- A chaque front montant on lit ce qu'il y a a lire et on avance le compteur
|
|
process
|
|
begin
|
|
wait until PS2Clk'event and PS2Clk = '1';
|
|
case compteur is
|
|
when 0 =>
|
|
-- Bit de start : on réinitialise tout
|
|
parity <= '1';
|
|
intern_alert <= '0';
|
|
intern_Data_av <= '0';
|
|
when 1 =>
|
|
-- Lecture et MAJ de la parité
|
|
current_data(7) <= PS2Data;
|
|
parity <= parity XOR PS2Data;
|
|
when 2 =>
|
|
-- Lecture et MAJ de la parité
|
|
current_data(6) <= PS2Data;
|
|
parity <= parity XOR PS2Data;
|
|
when 3 =>
|
|
-- Lecture et MAJ de la parité
|
|
current_data(5) <= PS2Data;
|
|
parity <= parity XOR PS2Data;
|
|
when 4 =>
|
|
-- Lecture et MAJ de la parité
|
|
current_data(4) <= PS2Data;
|
|
parity <= parity XOR PS2Data;
|
|
when 5 =>
|
|
-- Lecture et MAJ de la parité
|
|
current_data(3) <= PS2Data;
|
|
parity <= parity XOR PS2Data;
|
|
when 6 =>
|
|
-- Lecture et MAJ de la parité
|
|
current_data(2) <= PS2Data;
|
|
parity <= parity XOR PS2Data;
|
|
when 7 =>
|
|
-- Lecture et MAJ de la parité
|
|
current_data(1) <= PS2Data;
|
|
parity <= parity XOR PS2Data;
|
|
when 8 =>
|
|
-- Lecture et MAJ de la parité
|
|
current_data(0) <= PS2Data;
|
|
parity <= parity XOR PS2Data;
|
|
when 9 =>
|
|
-- Check de la parité
|
|
if (parity = PS2Data) then
|
|
intern_alert <= '0';
|
|
else
|
|
intern_alert <= '1';
|
|
end if;
|
|
when 10 =>
|
|
-- Envoi de la touche
|
|
if (intern_alert = '0') then
|
|
previous_data <= current_data;
|
|
-- Elimination des touches non classiques
|
|
if (not (previous_data = "11110000" or current_data = "11110000" or previous_data = "11100000")) then
|
|
Data <= current_data;
|
|
intern_Data_av <= '1';
|
|
end if;
|
|
end if;
|
|
end case;
|
|
|
|
compteur <= (compteur + 1) mod 11;
|
|
end process;
|
|
|
|
|
|
-- Gestion de l'avertissement de touche
|
|
process
|
|
begin
|
|
wait until CLK'event and CLK = '1';
|
|
if (intern_Data_av = '1' and not dejaSignale) then
|
|
Data_av <= '1';
|
|
dejaSignale <= true;
|
|
else
|
|
Data_av <= '0';
|
|
end if;
|
|
if (intern_Data_av = '0') then
|
|
dejaSignale <= false;
|
|
end if;
|
|
end process;
|
|
|
|
alert <= intern_alert;
|
|
|
|
end Behavioral;
|