1 |
11 |
N.Boukadid |
library ieee;
|
2 |
|
|
use ieee.std_logic_1164.all;
|
3 |
|
|
--use work.interlaken_package.all;
|
4 |
|
|
entity Meta_Framer is
|
5 |
|
|
generic(
|
6 |
|
|
PacketLength : positive -- 2048 * 8 = 16KB - 128Kb each packet. Including the metaframing itself
|
7 |
|
|
);
|
8 |
|
|
port (
|
9 |
|
|
clk : in std_logic;
|
10 |
|
|
reset : in std_logic;
|
11 |
|
|
|
12 |
|
|
TX_Enable : in std_logic;
|
13 |
|
|
|
14 |
|
|
HealthLane : in std_logic; -- Lane status bit transmitted in diagnostic
|
15 |
|
|
HealthInterface : in std_logic; -- Interface status bit transmitted in diagnostic
|
16 |
|
|
|
17 |
|
|
Data_In : in std_logic_vector(66 downto 0); -- Input data
|
18 |
|
|
Data_Out : out std_logic_vector(66 downto 0); -- To scrambling/framing
|
19 |
|
|
Data_Valid_In : in std_logic; -- Indicate data received is valid
|
20 |
|
|
Data_Valid_Out : out std_logic; -- Indicate data transmitted is valid
|
21 |
|
|
--Data_Control_In : in std_logic; -- Control word indication from the burst component
|
22 |
|
|
--Data_Control_Out : out std_logic; -- Control word indication
|
23 |
|
|
|
24 |
|
|
Gearboxready : in std_logic;
|
25 |
|
|
|
26 |
|
|
FIFO_read : out std_logic
|
27 |
|
|
);
|
28 |
|
|
end Meta_Framer;
|
29 |
|
|
|
30 |
|
|
architecture framing of Meta_Framer is
|
31 |
|
|
type state_type is (IDLE, SCRAM, SKIP, DATA, P1, P2, P3, DIAG);
|
32 |
|
|
signal pres_state, next_state : state_type;
|
33 |
|
|
|
34 |
|
|
signal Packet_Counter : integer range 0 to PacketLength;
|
35 |
|
|
|
36 |
|
|
signal HDR, HDR_Meta, HDR_Burst : std_logic_vector(2 downto 0);
|
37 |
|
|
signal Data_Valid : std_logic;
|
38 |
|
|
signal Data_P1, Data_P2, Data_P3 : std_logic_vector (63 downto 0); -- Pipeline for framing
|
39 |
|
|
signal HDR_P1, HDR_P2 : std_logic_vector(2 downto 0);
|
40 |
|
|
signal HDR_IN_P1, HDR_IN_P2, HDR_IN_P3 : std_logic_vector(2 downto 0);
|
41 |
|
|
|
42 |
|
|
signal Data_valid_p1, Data_valid_p2, Data_valid_p3, Data_valid_framed : std_logic;
|
43 |
|
|
signal Data_valid_Framed_P1, Data_valid_Framed_P2: std_logic;
|
44 |
|
|
|
45 |
|
|
signal Data_Framed, Data_Framed_P1, Data_Framed_P2: std_logic_vector (63 downto 0);
|
46 |
|
|
|
47 |
|
|
--signal CRC32_In : std_logic_vector(63 downto 0); -- Data transmitted to CRC-32 -- leo: uncommented
|
48 |
|
|
signal CRC32_Out : std_logic_vector(31 downto 0); -- Calculated CRC-32 which returns
|
49 |
|
|
signal CRC32_En : std_logic; -- Indicate the CRC-32 the data is valid
|
50 |
|
|
signal CRC32_Rst : std_logic; -- CRC-32 reset
|
51 |
|
|
signal CalcCRC : std_logic;
|
52 |
|
|
--signal CRC32_Ready : std_logic;
|
53 |
|
|
signal Gearboxready_P1 : std_logic;
|
54 |
|
|
signal CRC32_Rst_P1 : std_logic;
|
55 |
|
|
|
56 |
|
|
-- Constants
|
57 |
|
|
constant SYNCHRONIZATION : std_logic_vector(63 downto 0) := X"78f6_78f6_78f6_78f6"; -- synchronization, framing layer control word
|
58 |
|
|
constant SCRAM_STATE_INIT_VALUE : std_logic_vector(63 downto 0) := X"2800_0000_0000_0000"; -- Starting value of scrambler
|
59 |
|
|
constant SKIP_WORD : std_logic_vector(63 downto 0) := X"1e1e_1e1e_1e1e_1e1e"; -- skip word, framing layer control word
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
begin
|
63 |
|
|
|
64 |
|
|
CRC_32_Encoding : entity work.CRC_32 -- Define the connections of the CRC-24 component to the Burst component and generics
|
65 |
|
|
-- generic map
|
66 |
|
|
-- (
|
67 |
|
|
-- Nbits => 64,
|
68 |
|
|
-- CRC_Width => 32,
|
69 |
|
|
-- G_Poly => X"1EDC_6F41", --Test with CRC-32 (Interlaken-32 : X"1EDC_6F41")
|
70 |
|
|
-- G_InitVal => X"FFFF_FFFF"
|
71 |
|
|
-- )
|
72 |
|
|
port map
|
73 |
|
|
(
|
74 |
|
|
Clk => Clk,
|
75 |
|
|
DIn => Data_Framed,
|
76 |
|
|
CRC => CRC32_Out,
|
77 |
|
|
Calc => CalcCRC,
|
78 |
|
|
Reset => CRC32_Rst
|
79 |
|
|
);
|
80 |
|
|
CalcCRC <= CRC32_En and Gearboxready_P1;
|
81 |
|
|
|
82 |
|
|
diagnostic : process (clk, reset) is
|
83 |
|
|
variable CRC32_Out_v: std_logic_vector(31 downto 0);
|
84 |
|
|
begin
|
85 |
|
|
if (reset = '1') then
|
86 |
|
|
Data_Framed_P1 <= (others => '0');
|
87 |
|
|
Data_Framed_P2 <= (others => '0');
|
88 |
|
|
Data_Out <= (others => '0');
|
89 |
|
|
-- Data_Control_Out <= '0';
|
90 |
|
|
Data_Valid_Out <= '0';
|
91 |
|
|
elsif (rising_edge(clk)) then
|
92 |
|
|
Gearboxready_P1 <= Gearboxready;
|
93 |
|
|
CRC32_Rst_P1 <= CRC32_Rst;
|
94 |
|
|
if(CRC32_Rst_P1 = '1') then
|
95 |
|
|
CRC32_Out_v := CRC32_Out;
|
96 |
|
|
end if;
|
97 |
|
|
|
98 |
|
|
if(Gearboxready = '1') then
|
99 |
|
|
Data_Framed_P1 <= Data_Framed;
|
100 |
|
|
Data_Framed_P2 <= Data_Framed_P1;
|
101 |
|
|
Data_Out(63 downto 0) <= Data_Framed_P2;
|
102 |
|
|
Data_Valid_Framed_P1 <= (Data_Valid or Data_valid_framed);
|
103 |
|
|
Data_Valid_Framed_P2 <= Data_Valid_Framed_P1;
|
104 |
|
|
Data_Valid_Out <= Data_Valid_Framed_P2;
|
105 |
|
|
HDR_P1 <= HDR; -- Waiting for CRC calculation to be ready
|
106 |
|
|
HDR_P2 <= HDR_P1;
|
107 |
|
|
Data_Out(66 downto 64) <= HDR_P2;
|
108 |
|
|
if((Data_Valid_Framed_P2 = '1') and (Data_Framed_P2(63 downto 58) = "011001")) then
|
109 |
|
|
Data_Out(31 downto 0) <= CRC32_Out_v;
|
110 |
|
|
end if;
|
111 |
|
|
end if;
|
112 |
|
|
end if;
|
113 |
|
|
end process diagnostic;
|
114 |
|
|
|
115 |
|
|
hdr_or : process (HDR_Meta, HDR_Burst, Gearboxready) is
|
116 |
|
|
begin
|
117 |
|
|
if((HDR_Meta = "010" or HDR_Burst= "010") and Gearboxready = '1') then
|
118 |
|
|
HDR <= "010";
|
119 |
|
|
else
|
120 |
|
|
HDR <= "001";
|
121 |
|
|
end if;
|
122 |
|
|
end process;
|
123 |
|
|
|
124 |
|
|
control_pipeline : process(clk, reset) is
|
125 |
|
|
begin
|
126 |
|
|
if(reset = '1') then
|
127 |
|
|
HDR_Burst <= "010";
|
128 |
|
|
HDR_IN_P3 <= "010";
|
129 |
|
|
HDR_IN_P2 <= "010";
|
130 |
|
|
HDR_IN_P1 <= "010";
|
131 |
|
|
elsif(rising_edge(clk)) then
|
132 |
|
|
if(Gearboxready = '1') then
|
133 |
|
|
HDR_Burst <= HDR_IN_P3;
|
134 |
|
|
HDR_IN_P3 <= HDR_IN_P2;
|
135 |
|
|
HDR_IN_P2 <= HDR_IN_P1;
|
136 |
|
|
if(Data_in(65 downto 64) = "10") then
|
137 |
|
|
HDR_IN_P1 <= "010";
|
138 |
|
|
else
|
139 |
|
|
HDR_IN_P1 <= "001";
|
140 |
|
|
end if;
|
141 |
|
|
end if;
|
142 |
|
|
end if;
|
143 |
|
|
end process control_pipeline;
|
144 |
|
|
|
145 |
|
|
state_register : process (clk) is
|
146 |
|
|
begin
|
147 |
|
|
if (rising_edge(clk)) then
|
148 |
|
|
pres_state <= next_state;
|
149 |
|
|
end if;
|
150 |
|
|
end process state_register;
|
151 |
|
|
|
152 |
|
|
state_decoder : process (pres_state, Data_valid_in , Packet_Counter, Gearboxready, TX_enable) is
|
153 |
|
|
begin
|
154 |
|
|
if(Gearboxready = '0') then
|
155 |
|
|
next_state <= pres_state;
|
156 |
|
|
else
|
157 |
|
|
case pres_state is
|
158 |
|
|
when IDLE =>
|
159 |
|
|
if(TX_Enable = '1') then --and Data_valid_in = '1') then
|
160 |
|
|
next_state <= SCRAM;
|
161 |
|
|
else
|
162 |
|
|
next_state <= IDLE;
|
163 |
|
|
--Optional error state for not receiving valid data?
|
164 |
|
|
end if;
|
165 |
|
|
when SCRAM =>
|
166 |
|
|
next_state <= SKIP;
|
167 |
|
|
when SKIP =>
|
168 |
|
|
next_state <= DATA;
|
169 |
|
|
when DATA =>
|
170 |
|
|
if (Packet_Counter >= (PacketLength - 5)) then --(PacketLength-1 - metawords) --24-5
|
171 |
|
|
next_state <= P1;
|
172 |
|
|
else
|
173 |
|
|
next_state <= DATA;
|
174 |
|
|
end if;
|
175 |
|
|
when P1 =>
|
176 |
|
|
next_state <= P2;
|
177 |
|
|
when P2 =>
|
178 |
|
|
next_state <= P3;
|
179 |
|
|
when P3 =>
|
180 |
|
|
next_state <= DIAG;
|
181 |
|
|
when DIAG =>
|
182 |
|
|
next_state <= IDLE;
|
183 |
|
|
when others =>
|
184 |
|
|
next_state <= IDLE;
|
185 |
|
|
end case;
|
186 |
|
|
end if;
|
187 |
|
|
end process state_decoder;
|
188 |
|
|
|
189 |
|
|
output : process (clk) is
|
190 |
|
|
begin
|
191 |
|
|
if rising_edge(clk) then
|
192 |
|
|
CRC32_RST <= '0';
|
193 |
|
|
--Data_Valid <= '1';
|
194 |
|
|
if(Gearboxready = '0') then
|
195 |
|
|
NULL;
|
196 |
|
|
else
|
197 |
|
|
case pres_state is
|
198 |
|
|
when IDLE =>
|
199 |
|
|
Data_Valid <= '0';
|
200 |
|
|
Data_Framed <= (others => '0');
|
201 |
|
|
FIFO_Read <= '1';
|
202 |
|
|
HDR_Meta <= "001";
|
203 |
|
|
if (TX_Enable = '1') then--and Data_valid_in = '1') then -- Only start real transmission when there is valid data
|
204 |
|
|
Data_Framed <= SYNCHRONIZATION; -- Predefined sync word 78f6_78f6_78f6_78f6
|
205 |
|
|
HDR_Meta <= "010";
|
206 |
|
|
Data_Valid <= '1';
|
207 |
|
|
CRC32_Rst <= '1'; --CRC-32
|
208 |
|
|
end if;
|
209 |
|
|
Packet_Counter <= 1;
|
210 |
|
|
Data_P1 <= Data_in(63 downto 0);
|
211 |
|
|
Data_valid_p1 <= Data_Valid_In;
|
212 |
|
|
CRC32_En <= '1'; --CRC-32
|
213 |
|
|
|
214 |
|
|
when SCRAM =>
|
215 |
|
|
Data_Valid <= '1';
|
216 |
|
|
Packet_Counter <= Packet_Counter + 1;
|
217 |
|
|
Data_Framed <= SCRAM_STATE_INIT_VALUE; -- Scrambler state (real data added later)
|
218 |
|
|
Data_P2 <= Data_P1;
|
219 |
|
|
Data_P1 <= Data_in(63 downto 0);
|
220 |
|
|
Data_valid_p2 <= Data_valid_p1;
|
221 |
|
|
Data_valid_p1 <= Data_Valid_In;
|
222 |
|
|
|
223 |
|
|
when SKIP =>
|
224 |
|
|
Data_Valid <= '1';
|
225 |
|
|
Packet_Counter <= Packet_Counter + 1;
|
226 |
|
|
Data_Framed <= SKIP_WORD; -- Predefined skip word
|
227 |
|
|
Data_P3 <= Data_P2;
|
228 |
|
|
Data_P2 <= Data_P1;
|
229 |
|
|
Data_P1 <= Data_in(63 downto 0);
|
230 |
|
|
Data_valid_p3 <= Data_valid_p2;
|
231 |
|
|
Data_valid_p2 <= Data_valid_p1;
|
232 |
|
|
Data_valid_p1 <= Data_Valid_In;
|
233 |
|
|
|
234 |
|
|
when DATA =>
|
235 |
|
|
CRC32_EN <= '1';
|
236 |
|
|
Packet_Counter <= Packet_Counter + 1;
|
237 |
|
|
HDR_Meta <= "001";
|
238 |
|
|
Data_valid <= '0'; -- why 0
|
239 |
|
|
|
240 |
|
|
Data_Framed <= Data_P3;
|
241 |
|
|
Data_P3 <= Data_P2;
|
242 |
|
|
Data_P2 <= Data_P1;
|
243 |
|
|
Data_P1 <= Data_in(63 downto 0);
|
244 |
|
|
Data_valid_framed <= Data_valid_p3;
|
245 |
|
|
Data_valid_p3 <= Data_valid_p2;
|
246 |
|
|
Data_valid_p2 <= Data_valid_p1;
|
247 |
|
|
Data_valid_p1 <= Data_Valid_In;
|
248 |
|
|
|
249 |
|
|
--changed size from -2 to -3!!
|
250 |
|
|
if(packet_counter >= (PacketLength - 6) and packet_counter < (PacketLength - 3)) then -- Still 4 packets incoming after FIFO read disable
|
251 |
|
|
FIFO_Read <= '0'; -- PacketLength - 4 packets - 1 - 1 cycle delay fifo read - 4 cycle delay burst component
|
252 |
|
|
else
|
253 |
|
|
FIFO_Read <= '1';
|
254 |
|
|
end if;
|
255 |
|
|
|
256 |
|
|
when P1 =>
|
257 |
|
|
Packet_Counter <= Packet_Counter + 1;
|
258 |
|
|
Data_Framed <= Data_P3;
|
259 |
|
|
Data_P3 <= Data_P2;
|
260 |
|
|
Data_P2 <= Data_P1;
|
261 |
|
|
Data_valid_framed <= Data_valid_p3;
|
262 |
|
|
Data_valid_p3 <= Data_valid_p2;
|
263 |
|
|
Data_valid_p2 <= Data_valid_p1;
|
264 |
|
|
|
265 |
|
|
when P2 =>
|
266 |
|
|
Packet_Counter <= Packet_Counter + 1;
|
267 |
|
|
Data_Framed <= Data_P3;
|
268 |
|
|
Data_P3 <= Data_P2;
|
269 |
|
|
Data_valid_framed <= Data_valid_p3;
|
270 |
|
|
Data_valid_p3 <= Data_valid_p2;
|
271 |
|
|
|
272 |
|
|
when P3 =>
|
273 |
|
|
Packet_Counter <= Packet_Counter + 1;
|
274 |
|
|
Data_Framed <= Data_P3;
|
275 |
|
|
Data_valid_framed <= Data_valid_p3;
|
276 |
|
|
FIFO_Read <= '1';
|
277 |
|
|
|
278 |
|
|
when DIAG =>
|
279 |
|
|
Data_Valid <= '1';
|
280 |
|
|
Packet_Counter <= Packet_Counter + 1;
|
281 |
|
|
--FIFO_Read <= '1';
|
282 |
|
|
|
283 |
|
|
Data_Framed <= X"6400_0000_0000_0000"; -- Diagnostic word including CRC32
|
284 |
|
|
Data_Framed(33 downto 32) <= HealthLane & HealthInterface;
|
285 |
|
|
HDR_Meta <= "010";
|
286 |
|
|
end case;
|
287 |
|
|
end if;
|
288 |
|
|
end if;
|
289 |
|
|
end process output;
|
290 |
|
|
end architecture framing;
|
291 |
|
|
|