linreceiver-vhdl/ReceptionTrame_lib/receptionTrame_com.vhd
2023-09-26 11:58:30 +02:00

444 lines
9.2 KiB
VHDL

LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
ENTITY receptionTrame_com IS
PORT(
H: IN std_logic;
nRST: IN std_logic;
LinSynchro: IN std_logic;
octetRecu_EN: OUT std_logic;
n_SELECT: OUT std_logic;
n_LOAD: OUT std_logic;
n_EN: OUT std_logic;
nbBit_SELECT: OUT std_logic;
nbBit_LOAD: OUT std_logic;
nbBit_EN: OUT std_logic;
identifier_EN: OUT std_logic;
nbData_LOAD: OUT std_logic;
nbData_EN: OUT std_logic;
n_0: IN std_logic;
nbBit_0: IN std_logic;
nbData_0: IN std_logic
);
END receptionTrame_com;
ARCHITECTURE arch of receptionTrame_com IS
TYPE state IS (waiting, syncBreak0, syncBreak1, syncFieldWait, syncFieldStart, syncFieldData, syncFieldStop, idFieldWait, idFieldStart, idFieldData, idFieldStop, dataFieldWait, dataFieldStart, dataFieldData, dataFieldStop, checksumFieldWait, checksumFieldStart, checksumFieldData, checksumFieldStop);
SIGNAL cState, nState : state;
type errors is record
ErrorStartBit: std_logic;
ErrorStopBit: std_logic;
ErrorSync: std_logic;
end record errors;
SIGNAL errs: errors;
BEGIN
stateUpd : PROCESS(H, nRST)
BEGIN
IF(nRST = '0') THEN
cState <= waiting;
ELSIF(rising_edge(H)) THEN
cState <= nState;
END IF;
END process stateUpd;
nStateUpd : PROCESS(LinSynchro, cState, n_0, nbBit_0)
BEGIN
nState <= cState;
CASE cState IS
WHEN waiting =>
if(LinSynchro = '0') THEN
nState <= syncBreak0;
END IF;
WHEN syncBreak0 =>
if(LinSynchro = '1') THEN
if(nbBit_0 = '1') THEN
nState <= syncBreak1;
else
nState <= waiting;
END IF;
END IF;
WHEN syncBreak1 =>
if(n_0 = '1') THEN
if(LinSynchro = '1') THEN
nState <= syncFieldWait;
else
nState <= waiting;
end if;
END IF;
WHEN syncFieldWAit =>
if(LinSynchro = '0') THEN
nState <= syncFieldStart;
END IF;
WHEN syncFieldStart =>
if(n_0 = '1') THEN
IF(LinSynchro = '0') THEN
nState <= syncFieldData;
else
nState <= waiting;
END IF;
end if;
WHEN syncFieldData =>
if(nbBit_0 = '1') THEN
nState <= syncFieldStop;
END IF;
WHEN syncFieldStop =>
if(n_0 = '1') THEN
if(LinSynchro = '1') THEN
nState <= idFieldWait;
else
nState <= waiting;
end if;
end if;
WHEN idFieldWait =>
if(LinSynchro = '0') then
nState <= idFieldStart;
end if;
WHEN idFieldStart =>
if(n_0 = '1') then
if(LinSynchro = '0') then
nState <= idFieldData;
else
nState <= waiting;
end if;
end if;
WHEN idFieldData =>
if(nbBit_0 = '1') then
nState <= idFieldStop;
end if;
WHEN idFieldStop =>
if(n_0 = '1') then
if(LinSYnchro = '1') then
nState <= dataFieldWait;
else
nState <= waiting;
end if;
end if;
WHEN dataFieldWait =>
if(LinSynchro = '0') then
nState <= dataFieldStart;
end if;
WHEN dataFieldStart =>
if(n_0 = '1') then
if(LinSynchro = '0') then
nState <= dataFieldData;
else
nState <= waiting;
end if;
end if;
WHEN dataFieldData =>
if(nbBit_0 = '1') then
nState <= dataFieldStop;
end if;
WHEN dataFieldStop =>
if(n_0 = '1') then
if(LinSynchro = '1') then
if(nbData_0 = '1') then
nState <= checksumFieldWait;
else
nState <= dataFieldWait;
end if;
else
nState <= waiting;
end if;
end if;
WHEN checksumFieldWait =>
if(LinSynchro = '0') then
nState <= checksumFieldStart;
end if;
WHEN checksumFieldStart =>
if(n_0 = '1') then
if(LinSynchro = '0') then
nState <= checksumFieldData;
else
nState <= waiting;
end if;
end if;
WHEN checksumFieldData =>
if(nbBit_0 = '1') then
nState <= checksumFieldStop;
end if;
WHEN checksumFieldStop =>
if(n_0 = '1') then
nState <= waiting;
end if;
end CASE;
END PROCESS nStateUpd;
RCS : PROCESS(cState, LinSynchro, n_0)
BEGIN
CASE cState IS
WHEN waiting =>
if(LinSynchro = '0') THEN
n_LOAD <= '1';
n_SELECT <= '1';
nbBit_LOAD <= '1';
nbBit_SELECT <= '0';
end IF;
WHEN syncBreak0 =>
if(LinSynchro = '1') then
if(nbBit_0 = '1') then
n_LOAD <= '1';
n_SELECT <= '0';
else
errs.ErrorSync <= '1';
end if;
else
if(n_0 = '1') then
n_select <= '0';
n_LOAD <= '1';
nbBit_EN <= '1';
else
n_LOAD <= '0';
nbBit_EN <= '0';
end if;
n_EN <= '1';
nbBit_LOAD <= '0';
end if;
WHEN syncBreak1 =>
if(n_0 = '1') then
if(LinSynchro = '0') then
errs.ErrorStopBit <= '1';
end if;
else
n_LOAD <= '0';
n_EN <= '1';
end if;
WHEN syncFieldWait =>
if(LinSynchro = '0') then
n_LOAD <= '1';
n_SELECT <= '1';
end if;
WHEN syncFieldStart =>
if(n_0 = '1') then
if(LinSynchro = '0') then
n_SELECT <= '0';
n_LOAD <= '1';
nbBit_SELECT <= '1';
nbBit_LOAD <= '1';
else
errs.ErrorStartBit <= '1';
end if;
else
n_LOAD <= '0';
n_EN <= '1';
end if;
WHEN syncFieldData =>
if(nbBit_0 = '1') then
n_SELECT <= '0';
n_LOAD <= '1';
octetRecu_EN <= '0';
else
if(n_0 = '1') then
n_LOAD <= '1';
n_SELECT <= '0';
nbBit_EN <= '1';
octetRecu_EN <= '1';
else
n_LOAD <= '0';
nbBit_EN <= '0';
octetRecu_EN <= '0';
end if;
nbBit_LOAD <= '0';
end if;
WHEN syncFieldStop =>
if(n_0 = '1') then
if(LinSynchro = '1') then
else
errs.ErrorStopBit <= '1';
end if;
else
n_LOAD <= '0';
n_EN <= '1';
end if;
WHEN idFieldWait =>
if(LinSynchro = '0') then
n_SELECT <= '1';
n_LOAD <= '1';
end if;
WHEN idFieldStart =>
if(n_0 = '1') then
n_SELECT <= '0';
n_LOAD <= '1';
nbBit_SELECT <= '1';
nbBit_LOAD <= '1';
else
n_LOAD <= '0';
n_EN <= '1';
end if;
WHEN idFieldData =>
if(nbBit_0 = '1') then
n_SELECT <= '0';
n_LOAD <= '1';
octetRecu_EN <= '0';
else
if(n_0 = '1') then
n_LOAD <= '1';
n_SELECT <= '0';
nbBit_EN <= '1';
octetRecu_EN <= '1';
else
n_LOAD <= '0';
nbBIt_EN <= '0';
octetRecu_EN <= '0';
end if;
nbBit_LOAD <= '0';
n_EN <= '1';
end if;
WHEN idFieldStop =>
if(n_0 = '1') then
if(LinSynchro = '1') then
nbData_LOAD <= '1';
else
errs.ErrorStopBit <= '1';
end if;
else
n_LOAD <= '0';
n_EN <= '1';
end if;
WHEN dataFieldWait =>
if(LinSynchro = '0') then
n_SELECT <= '1';
n_LOAD <= '1';
else
nbData_EN <= '0';
nbData_LOAD <= '0';
end if;
WHEN dataFieldStart =>
if(n_0 = '1') then
n_SELECT <= '0';
n_LOAD <= '1';
nbBit_SELECT <= '1';
nbBit_LOAD <= '1';
else
n_LOAD <= '0';
n_EN <= '1';
end if;
WHEN dataFieldData =>
if(nbBit_0 = '1') then
n_SELECT <= '0';
n_LOAD <= '1';
octetRecu_EN <= '0';
else
if(n_0 = '1') then
n_LOAD <= '1';
n_SELECT <= '0';
nbBit_EN <= '1';
octetRecu_EN <= '1';
else
n_LOAD <= '0';
nbBIt_EN <= '0';
octetRecu_EN <= '0';
end if;
nbBit_LOAD <= '0';
n_EN <= '1';
end if;
WHEN dataFieldStop =>
if(n_0 = '1') then
if(LinSynchro = '1') then
nbData_EN <= '1';
else
errs.ErrorStopBit <= '1';
end if;
else
n_LOAD <= '0';
n_EN <= '1';
end if;
WHEN checksumFieldWait =>
if(LinSynchro = '0') then
n_SELECT <= '1';
n_LOAD <= '1';
end if;
WHEN checksumFieldStart =>
if(n_0 = '1') then
n_SELECT <= '0';
n_LOAD <= '1';
nbBit_SELECT <= '1';
nbBit_LOAD <= '1';
else
n_LOAD <= '0';
n_EN <= '1';
end if;
WHEN checksumFieldData =>
if(nbBit_0 = '1') then
n_SELECT <= '0';
n_LOAD <= '1';
octetRecu_EN <= '0';
else
if(n_0 = '1') then
n_LOAD <= '1';
n_SELECT <= '0';
nbBit_EN <= '1';
octetRecu_EN <= '1';
else
n_LOAD <= '0';
nbBIt_EN <= '0';
octetRecu_EN <= '0';
end if;
nbBit_LOAD <= '0';
n_EN <= '1';
end if;
WHEN checksumFieldStop =>
if(n_0 = '1') then
if(LinSynchro = '1') then
else
errs.ErrorStopBit <= '1';
end if;
else
n_LOAD <= '0';
n_EN <= '1';
end if;
end CASE;
END PROCESS RCS;
END ARCHITECTURE arch;