1 |
11 |
N.Boukadid |
library ieee;
|
2 |
|
|
use ieee.std_logic_1164.all;
|
3 |
|
|
use ieee.numeric_std.all;
|
4 |
|
|
|
5 |
|
|
entity Meta_Deframer is
|
6 |
|
|
port(
|
7 |
|
|
Clk : in std_logic; -- Clock input
|
8 |
|
|
Reset : in std_logic; -- Reset decoder
|
9 |
|
|
|
10 |
|
|
Data_In : in std_logic_vector(66 downto 0); -- Data input
|
11 |
|
|
Data_Out : out std_logic_vector(66 downto 0);-- Decoded 64-bit output
|
12 |
|
|
|
13 |
|
|
--Data_Control_In : in std_logic; -- Indicates whether the word is data or control
|
14 |
|
|
--Data_Control_Out : out std_logic; -- Indicates whether the word is data or control
|
15 |
|
|
|
16 |
|
|
CRC32_Error : out std_logic;
|
17 |
|
|
|
18 |
|
|
Data_Valid_In : in std_logic;
|
19 |
|
|
Data_Valid_Out : out std_logic
|
20 |
|
|
);
|
21 |
|
|
end entity Meta_Deframer;
|
22 |
|
|
|
23 |
|
|
architecture Deframing of Meta_Deframer is
|
24 |
|
|
type state_type is (IDLE, CRC);
|
25 |
|
|
signal pres_state, next_state : state_type;
|
26 |
|
|
|
27 |
|
|
signal Packet_Counter : integer range 0 to 60;
|
28 |
|
|
signal Data_P1, Data_P2 : std_logic_vector(63 downto 0);
|
29 |
|
|
|
30 |
|
|
-- Diagnostic word related signals
|
31 |
|
|
signal Diagnostic_Error : std_logic := '0'; -- In case diagnostic word disappeared
|
32 |
|
|
signal CRC32_Value : std_logic_vector(31 downto 0) := (others => '0'); -- CRC-32 value received
|
33 |
|
|
signal HealthLane, HealthInterface : std_logic := '0'; -- Health status bits
|
34 |
|
|
|
35 |
|
|
-- CRC-32 related
|
36 |
|
|
signal CRC32_In : std_logic_vector(63 downto 0); -- Data transmitted to CRC-32
|
37 |
|
|
signal CRC32_Out : std_logic_vector(31 downto 0); -- Calculated CRC-32 which returns
|
38 |
|
|
--signal CRC32_En : std_logic; -- Indicate the CRC-32 the data is valid
|
39 |
|
|
signal CRC32_Rst : std_logic; -- CRC-32 reset
|
40 |
|
|
signal CrcCalc : std_logic; -- Calculate the CRC-32
|
41 |
|
|
signal CRC32_Check1, CRC32_Check2, CRC32_Check3 : std_logic := '0'; -- Pipeline for CRC check
|
42 |
|
|
signal CRC32_Good : std_logic; -- CRC value is checked and valid
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
-- Constants
|
46 |
|
|
constant SYNCHRONIZATION : std_logic_vector(63 downto 0) := X"78f6_78f6_78f6_78f6"; -- synchronization framing layer control word
|
47 |
|
|
constant DIAGNOSTIC : std_logic_vector(63 downto 34) := "011001"&X"000000";
|
48 |
|
|
constant SCRAM_STATE_INIT_VALUE : std_logic_vector(63 downto 0) := X"2800_0000_0000_0000"; -- Starting value of scrambler
|
49 |
|
|
constant META_TYPE_SYNCHRONIZATION: std_logic_vector(4 downto 0) := "11110";
|
50 |
|
|
constant META_TYPE_SCRAM_STATE: std_logic_vector(4 downto 0) := "01010";
|
51 |
|
|
constant META_TYPE_SKIP_WORD: std_logic_vector(4 downto 0) := "01010";
|
52 |
|
|
constant META_TYPE_DIAGNOSTIC: std_logic_vector(4 downto 0) := "11001";
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
-- component CRC_32 -- Add the CRC-32 component
|
57 |
|
|
-- generic
|
58 |
|
|
-- (
|
59 |
|
|
-- Nbits : positive := 64;
|
60 |
|
|
-- CRC_Width : positive := 24;
|
61 |
|
|
-- G_Poly : Std_Logic_Vector := X"1EDC_6F41";
|
62 |
|
|
-- G_InitVal : std_logic_vector :=X"FFFF_FFFF"
|
63 |
|
|
-- );
|
64 |
|
|
-- port
|
65 |
|
|
-- (
|
66 |
|
|
-- CRC : out std_logic_vector(CRC_Width-1 downto 0);
|
67 |
|
|
-- Calc : in std_logic;
|
68 |
|
|
-- Clk : in std_logic;
|
69 |
|
|
-- DIn : in std_logic_vector(Nbits-1 downto 0);
|
70 |
|
|
-- Reset : in std_logic
|
71 |
|
|
-- );
|
72 |
|
|
-- end component CRC_32;
|
73 |
|
|
begin
|
74 |
|
|
|
75 |
|
|
CRC_32_Encoding : entity work.CRC_32 -- Define the connections of the CRC-24 component to the Burst component and generics
|
76 |
|
|
-- generic map
|
77 |
|
|
-- (
|
78 |
|
|
-- Nbits => 64,
|
79 |
|
|
-- CRC_Width => 32,
|
80 |
|
|
-- G_Poly => X"1EDC_6F41", --Test with CRC-32 (Interlaken-32 : X"1EDC_6F41")
|
81 |
|
|
-- G_InitVal => X"FFFF_FFFF"
|
82 |
|
|
-- )
|
83 |
|
|
port map
|
84 |
|
|
(
|
85 |
|
|
Clk => Clk,
|
86 |
|
|
DIn => CRC32_In,
|
87 |
|
|
CRC => CRC32_Out,
|
88 |
|
|
Calc => CrcCalc,
|
89 |
|
|
Reset => CRC32_Rst
|
90 |
|
|
);
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
Meta_Deframing : process (clk, reset) is
|
94 |
|
|
begin
|
95 |
|
|
if reset = '1' then
|
96 |
|
|
Data_Out(63 downto 0) <= (others => '0');
|
97 |
|
|
Data_Out(66 downto 64) <= "010";
|
98 |
|
|
Data_Valid_Out <= '0';
|
99 |
|
|
elsif rising_edge(clk) then
|
100 |
|
|
Data_Valid_Out <= '0';
|
101 |
|
|
if(Data_Valid_in = '1') then
|
102 |
|
|
Data_Valid_Out <= '1';
|
103 |
|
|
Data_Out(66 downto 64) <= Data_In(66 downto 64);
|
104 |
|
|
Data_Out(63 downto 0) <= Data_In(63 downto 0);
|
105 |
|
|
if (Data_In(65 downto 64) = "10" and Data_In(63) = '0')then
|
106 |
|
|
Data_Out(63 downto 0) <= (others => '0');
|
107 |
|
|
Data_Valid_Out <= '0';
|
108 |
|
|
end if;
|
109 |
|
|
end if;
|
110 |
|
|
end if;
|
111 |
|
|
end process Meta_Deframing;
|
112 |
|
|
|
113 |
|
|
-- Burst_Deframing : process (clk, reset) is
|
114 |
|
|
-- begin
|
115 |
|
|
-- if reset = '1' then
|
116 |
|
|
-- Data_Test <= (others => '0');
|
117 |
|
|
-- Data_Control_Out <= '0';
|
118 |
|
|
-- Data_Valid_Out <= '0';
|
119 |
|
|
-- elsif rising_edge(clk) then
|
120 |
|
|
-- Data_Valid_Out <= '1';
|
121 |
|
|
-- if (Data_Control_In = '1' and Data_In(63) = '0')then
|
122 |
|
|
-- Data_Out <= (others => '0');
|
123 |
|
|
-- Data_Control_Out <= '1';
|
124 |
|
|
-- Data_Valid_Out <= '0';
|
125 |
|
|
-- elsif (Data_Control_In = '1' and Data_In(63) = '1') then
|
126 |
|
|
-- Data_Out <= Data_In;
|
127 |
|
|
-- Data_Control_Out <= '1';
|
128 |
|
|
-- else
|
129 |
|
|
-- Data_Out <= Data_In;
|
130 |
|
|
-- Data_Control_Out <= '0';
|
131 |
|
|
-- end if;
|
132 |
|
|
-- end if;
|
133 |
|
|
-- end process Burst_Deframing;
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
crc_check : process (pres_state, clk)
|
138 |
|
|
begin
|
139 |
|
|
if (Reset = '1') then
|
140 |
|
|
Data_P1 <= (others => '1');
|
141 |
|
|
Data_P2 <= (others => '1');
|
142 |
|
|
CRC32_Rst <= '0';
|
143 |
|
|
CRC32_Error <= '0';
|
144 |
|
|
CRC32_Good <= '0';
|
145 |
|
|
elsif rising_edge(clk) then
|
146 |
|
|
CRC32_Rst <= '0';
|
147 |
|
|
CRC32_Error <= '0';
|
148 |
|
|
CRC32_Good <= '0';
|
149 |
|
|
CRC32_Check1 <= '0'; --default
|
150 |
|
|
CrcCalc <= Data_valid_in;
|
151 |
|
|
if(Data_valid_in = '0' and CRC32_Check1 = '1') then
|
152 |
|
|
CRC32_Check1 <= '1';
|
153 |
|
|
CRC32_Check2 <= '0';
|
154 |
|
|
else
|
155 |
|
|
CRC32_Check2 <= CRC32_Check1; --pipeline
|
156 |
|
|
end if;
|
157 |
|
|
CRC32_Check3 <= CRC32_Check2; --pipeline
|
158 |
|
|
if (CRC32_Check3 = '1') then
|
159 |
|
|
if(CRC32_Out /= CRC32_Value) then
|
160 |
|
|
CRC32_Error <= '1';
|
161 |
|
|
else
|
162 |
|
|
CRC32_Good <= '1';
|
163 |
|
|
end if;
|
164 |
|
|
end if;
|
165 |
|
|
|
166 |
|
|
if(Data_valid_in = '1') then
|
167 |
|
|
Data_P2 <= Data_P1;
|
168 |
|
|
Data_P1 <= Data_In(63 downto 0);
|
169 |
|
|
|
170 |
|
|
Packet_Counter <= Packet_Counter + 1;
|
171 |
|
|
|
172 |
|
|
if (Data_In(65 downto 0) = "10"&SYNCHRONIZATION) then
|
173 |
|
|
CRC32_Rst <= '1';
|
174 |
|
|
Packet_Counter <= 1;
|
175 |
|
|
pres_state <= CRC;
|
176 |
|
|
CRC32_In <= Data_In(63 downto 0);
|
177 |
|
|
end if;
|
178 |
|
|
|
179 |
|
|
if (Data_In(65 downto 58) = "10"&"0"&META_TYPE_SCRAM_STATE) then -- 58-bit scrambler state is treated as all 00's for CRC
|
180 |
|
|
CRC32_In(63 downto 58) <= Data_In(63 downto 58);
|
181 |
|
|
CRC32_In(57 downto 0) <= (others => '0'); -- CRC was generated with field padded with zeros
|
182 |
|
|
|
183 |
|
|
--if(Packet_Counter = 23) then
|
184 |
|
|
elsif(Data_In(65 downto 58) = "10"&"0"&META_TYPE_DIAGNOSTIC ) then
|
185 |
|
|
-- if(Data_In(65 downto 34) = "10"&DIAGNOSTIC ) then
|
186 |
|
|
Diagnostic_Error <= '0';
|
187 |
|
|
CRC32_Value <= Data_In(31 downto 0);
|
188 |
|
|
CRC32_In(63 downto 58) <= Data_In(63 downto 58);
|
189 |
|
|
CRC32_In(57 downto 34) <= (others => '0');
|
190 |
|
|
CRC32_In(33 downto 32) <= Data_In(33 downto 32);
|
191 |
|
|
CRC32_In(31 downto 0) <= (others => '0'); -- CRC was generated with field padded with zeros
|
192 |
|
|
HealthLane <= Data_In(33);
|
193 |
|
|
HealthInterface <= Data_In(32);
|
194 |
|
|
pres_state <= IDLE;
|
195 |
|
|
CRC32_Check1 <= '1';
|
196 |
|
|
-- else
|
197 |
|
|
-- Diagnostic_Error <= '1';
|
198 |
|
|
-- CRC32_Value <= (others => '0');
|
199 |
|
|
-- CRC32_In(63 downto 0) <= (others => '0');
|
200 |
|
|
else
|
201 |
|
|
CRC32_In <= Data_In(63 downto 0);
|
202 |
|
|
end if;
|
203 |
|
|
--end if;
|
204 |
|
|
end if;
|
205 |
|
|
end if;
|
206 |
|
|
end process;
|
207 |
|
|
|
208 |
|
|
end architecture Deframing;
|