AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
rcv_pckt_s.vhd
1 
2 ------------------------------------------------------
3 -- Receive packet
4 --
5 -- Ver 1.00
6 --
7 -- Dominique Gigi May 2015
8 ------------------------------------------------------
9 -- Version 1.00
10 --
11 --
12 --
13 ------------------------------------------------------
14 LIBRARY ieee;
15 USE ieee.std_logic_1164.all;
16 use ieee.numeric_std.all;
17 use ieee.std_logic_unsigned.all;
18 
19 
21 
22 port (
23  reset_clk : in std_logic;
24  reset_clkT : in std_logic;
25  Greset_clk : in std_logic;
26  Greset_clkT : in std_logic;
27  clock : in std_logic;
28  clock_t : in std_logic;
29 
30  datai : in std_logic_vector(63 downto 0); --- data and K bit send from SERDES
31  k_byte : in std_logic_vector( 7 downto 0);
32 
33  error_gen : in std_logic; -- 1 will emulate an error in one ack packet
34 
35  cmd : out std_logic_vector(31 downto 0); -- command from MOL
36  data : out std_logic_vector(31 downto 0); -- data from MOL
37  ena_cmd : out std_logic; -- validate command
38 
39  status : out std_logic_vector(63 downto 0); -- value return from read command request
40  seqnb : out std_logic_vector(30 downto 0); -- seq numb from ack (received an ack)
41  ena_ack : out std_logic;
42 
43  card_ID : out std_logic_vector(15 downto 0);
44  cnt_pckt_rcv : out std_logic_vector(31 downto 0)
45  );
46 
47 end rcv_pckt_s_XGMII;
48 
49 architecture behavioral of rcv_pckt_s_XGMII is
50 
51 component crc_gen_32b IS
52  PORT(
53  clock : IN STD_LOGIC;
54  reset : IN STD_LOGIC;
55  data : IN STD_LOGIC_VECTOR(63 DOWNTO 0);
56  data_valid : IN STD_LOGIC;
57  eoc : IN STD_LOGIC;
58  crc : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
59  crc_valid : OUT STD_LOGIC
60  );
61 end component;
62 
63 component resync
64 port (
65  reset : in std_logic;
66  Free_clki : in std_logic;
67  clocki : in std_logic;
68  clocko : in std_logic;
69  input : in std_logic;
70  output : out std_logic
71  );
72 end component;
73 
74 signal pipe_a : std_logic_vector(63 downto 0);
75 signal pipe_b : std_logic_vector(63 downto 0);
76 signal pipe_c : std_logic_vector(63 downto 0);
77 signal pipe_K : std_logic_vector( 7 downto 0);
78 
79 signal SOF : std_logic_vector(2 downto 0);
80 signal EOF : std_logic_vector(0 downto 0);
81 
82 --attribute mark_debug : string;
83 --attribute mark_debug of SOF, EOF : signal is "true";
84 
85 signal stage : std_logic_vector(1 downto 0);
86 
87 signal cmd_reg : std_logic_vector(31 downto 0);
88 signal data_reg : std_logic_vector(31 downto 0);
89 signal ena_cmd_reg : std_logic;
90 
91 signal status_reg : std_logic_vector(63 downto 0);
92 signal ena_ack_reg : std_logic;
93 
94 
95 signal seqnb_reg : std_logic_vector(30 downto 0);
96 signal ID_reg : std_logic_vector(15 downto 0);
97 signal length_reg : std_logic_vector(15 downto 0);
98 
99 signal cmp_crc : std_logic;
100 
101 signal eoc : std_logic;
102 signal crc_val : std_logic_vector(31 downto 0);
103 signal crc_valid : std_logic;
104 signal crc_to_be_check : std_logic_vector(31 downto 0);
105 signal end_check : std_logic;
106 signal cmd_pckt : std_logic;
107 signal ack_pckt : std_logic;
108 signal mem_error_gen : std_logic_vector(1 downto 0);
109 signal pack_counter : std_logic_vector(31 downto 0);
110 
111 
112 --*******************************************************
113 --************** BEGIN ********************************
114 --*******************************************************
115 begin
116 
117 --****** error gen ********
118 process(reset_clk,clock)
119 begin
120  if reset_clk = '0' then
121  mem_error_gen <= (others => '0');
122  elsif rising_edge(clock) then
123  if SOF(0) = '1' then
124  mem_error_gen(1) <= mem_error_gen(0);
125  elsif crc_valid = '1' then
126  mem_error_gen(1) <= '0';
127  end if;
128 
129  if error_gen = '1' then
130  mem_error_gen(0) <= '1';
131  elsif SOF(0) = '1' then
132  mem_error_gen(0) <= '0';
133  end if;
134  end if;
135 end process;
136 --*************************
137 
138 process(reset_clk,clock) -- alignment on the start of frame
139 begin
140 if reset_clk = '0' then
141  SOF <= (others => '0');
142 elsif rising_edge(clock) then
143 
144  SOF(2 downto 1) <= SOF(1 downto 0);
145  SOF(0) <= '0';
146  if k_byte(0) = '1' and datai(07 downto 00) = x"FB" then --start
147  SOF(0) <= '1';
148  end if;
149 end if;
150 end process;
151 
152 -- realign the byte following on 64-bit word
153 -- And Pipe data
154 process(clock)
155 begin
156 if rising_edge(clock) then
157  pipe_c <= pipe_b;
158 
159  pipe_a(63 downto 00) <= datai(63 downto 00);
160  pipe_K <= k_byte;
161  pipe_b(63 downto 00) <= pipe_a(63 downto 00);
162 
163 end if;
164 end process;
165 
166 
167 process(clock)
168 begin
169 if rising_edge(clock) then
170  stage(1) <= stage(0);
171  stage(0) <= SOF(0);
172 end if;
173 end process;
174 
175 
176 -- Envelop the data to be used to compute the CRC
177 process(reset_clk,clock)
178 begin
179 if reset_clk = '0' then
180  cmp_crc <= '0';
181 elsif rising_edge(clock) then
182  if SOF(1) = '1' then
183  cmp_crc <= '1';
184  elsif EOF(0) = '1' then
185  cmp_crc <= '0';
186  end if;
187 end if;
188 end process;
189 
190 -- latch the CRC received in the packet
191 process(reset_clk,clock)
192 begin
193 if rising_edge(clock) then
194  if EOF(0) = '1' then
195  crc_to_be_check <= pipe_a(31 downto 00);
196  end if;
197 end if;
198 end process;
199 
200 -- check where is the CRC in the packet
201 -- according the alignment of the data
202 process(reset_clk,clock)
203 begin
204 if reset_clk = '0' then
205  EOF <= (others => '0');
206 elsif rising_edge(clock) then
207  EOF(0) <= '0';
208  if (datai(39 downto 32) = x"FD" and k_byte(4) = '1') then --End of frame
209  EOF(0) <= '1';
210  end if;
211 end if;
212 end process;
213 
214 EOC <= '1' when (datai(39 downto 32) = x"FD" and k_byte(4) = '1') else '0';
215 
216 --********************************************************
217 -- instantiation to Compute the CRC
218 
219 CRC_generate:crc_gen_32b
220 PORT MAP(
221  clock => clock,
222  reset => SOF(1),
223  data => pipe_b ,
224  data_valid => cmp_crc,
225  eoc => EOF(0),
226  crc => crc_val,
227  crc_valid => crc_valid
228  );
229 --********************************************************
230 
231 -- recover the values from the packet
232 -- Sequence#,
233 -- Ack nit,
234 --Status,....
235 process(reset_clk,clock)
236 begin
237 if reset_clk = '0' then
238  cmd_pckt <= '0';
239  ack_pckt <= '0';
240 elsif rising_edge(clock) then
241  if stage(0) = '1' then
242  seqnb_reg <= pipe_a(62 downto 32);
243  ack_pckt <= pipe_a(63);
244  cmd_pckt <= not(pipe_a(63));
245 
246  ID_reg <= pipe_a(31 downto 16);
247  length_reg <= pipe_a(15 downto 00);
248 
249  elsif stage(1) = '1' then
250  cmd_reg <= pipe_a(63 downto 32);
251  status_reg(31 downto 00) <= pipe_a(63 downto 32);
252  data_reg <= pipe_a(31 downto 00);
253 
254  elsif end_check = '1' then
255  cmd_pckt <= '0';
256  ack_pckt <= '0';
257  end if;
258 end if;
259 end process;
260 
261 -- validate or unvalidate the packet according the CRC check
262 process(reset_clk,clock)
263 begin
264 if reset_clk = '0' then
265  ena_cmd_reg <= '0';
266  ena_ack_reg <= '0';
267  end_check <= '0';
268 elsif rising_edge(clock) then
269  ena_cmd_reg <= '0';
270  ena_ack_reg <= '0';
271  end_check <= '0';
272  if crc_valid = '1' then
273  end_check <= '1';
274  if crc_val = crc_to_be_check then
275  if ack_pckt = '1' then
276  ena_ack_reg <= '1';
277  elsif cmd_pckt = '1' then
278  ena_cmd_reg <= '1';
279  end if;
280  end if;
281  end if;
282 end if;
283 end process;
284 
285 process(Greset_clk,clock)
286 begin
287 if Greset_clk = '0' then
288  pack_counter <= (others => '0');
289 elsif rising_edge(clock) then
290  if crc_valid = '1' then
291  if crc_val = crc_to_be_check then
292  if ack_pckt = '1' then
293  pack_counter <= pack_counter + '1';
294  end if;
295  end if;
296  end if;
297 end if;
298 end process;
299 
300 -- resynchronisation between clock domains
301 resync_ena_ack:resync
302 port map(
303  reset => reset_clk,
304  Free_clki => '1',
305  clocki => clock,
306  clocko => clock_t,
307  input => ena_ack_reg,
308  output => ena_ack
309  );
310 
311 resync_ena_cmd:resync
312 port map(
313  reset => reset_clk,
314  Free_clki => '1',
315  clocki => clock,
316  clocko => clock_t,
317  input => ena_cmd_reg,
318  output => ena_cmd
319  );
320 
321 
322 cmd <= cmd_reg;
323 data <= data_reg;
324 status <= status_reg;
325 seqnb <= seqnb_reg;
326 card_ID <= ID_reg;
327 
328 cnt_pckt_rcv <= pack_counter; -- count only the ack (not the command received
329 
330 end behavioral;
331