ROD firmware  1.0.5
ATLAS l1-calo - ROD_eFEX and ROD_jFEX firmware for the L1Calo ROD board

Back to ROD documentation
hdr_in_crc9.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 10.09.2018 18:14:37
6 -- Design Name:
7 -- Module Name: hdr_in_crc9 - RTL
8 -- Project Name: L1Calo ROD
9 -- Target Devices:
10 -- Tool Versions:
11 -- Description:
12 --
13 -- Dependencies:
14 --
15 -- Revision:
16 -- Revision 0.01 - File Created
17 -- Additional Comments:
18 --
19 ----------------------------------------------------------------------------------
20 
21 
22 library IEEE;
23 use IEEE.STD_LOGIC_1164.ALL;
24 
25 -- Uncomment the following library declaration if using
26 -- arithmetic functions with Signed or Unsigned values
27 --use IEEE.NUMERIC_STD.ALL;
28 
29 -- Uncomment the following library declaration if instantiating
30 -- any Xilinx leaf cells in this code.
31 --library UNISIM;
32 --use UNISIM.VComponents.all;
33 
34 --this block checks the header crc on incoming TOB packets from all channels
35 --if any header has a crc error, the header_mismatch flag is set.
36 --the header_mismatch is cleared at the beginning of each event building
37 --the the header_mismatch is incorporated into the Event packet trailer Control Error MAp
38 
39 
40 entity hdr_in_crc9 is
41  Port (
42  clock : in STD_LOGIC;
43  crc_reset : in STD_LOGIC; --connect to ld_hdr_reg in the level above
44  s_tdata : in STD_LOGIC_VECTOR (63 downto 0);
45  crc_start : in STD_LOGIC; --connect to poll in the level above
46  header_mismatch : out std_logic
47  );
48 end hdr_in_crc9;
49 
50 architecture RTL of hdr_in_crc9 is
51 
52 
53 component osum_crc9d32
54  port(
55  clock : in std_logic;
56 
57  crc_start : in std_logic;
58  d_in : in std_logic_vector(31 downto 0);
59 
60  crc_out : out std_logic_vector(8 downto 0)
61  );
62 end component;
63 
64 signal CRC_d_in : std_logic_vector(31 downto 0);
65 signal din_reg : std_logic_vector(31 downto 0);
66 signal declared_crc_reg : std_logic_vector(8 downto 0);
67 signal cyc_1 : std_logic;
68 signal cyc_2 : std_logic;
69 signal crc_error : std_logic;
70 signal CRC_out : std_logic_vector(8 downto 0);
71 --signal header_mismatch : std_logic;
72 
73 begin
74 
75 hdr_chk_crc : osum_crc9d32
76  port map(
77  clock => clock,
78  CRC_out => CRC_out,
79  crc_start => crc_start,
80  d_in => CRC_d_in
81 -- Reset => reset
82  );
83 
84 --register the upper 32-bits (second word) of the header because the header will dissapear in the next cycle
85 
86 process (clock) begin
87  if rising_edge (clock) then
88  if (crc_start = '1') then
89  din_reg <= s_tdata(63 downto 32);
90  declared_crc_reg <= s_tdata(28 downto 20);
91  end if;
92  end if;
93 end process;
94 
95 --first mux the lower 32-bits of header (with 0 in the crc field) because it should be first into the crc
96 --on the second cycle, mux in the registered upper 32-bits (second word) of the header
97  with crc_start select
98  CRC_d_in <= s_tdata(31 downto 29) & "000000000" & s_tdata(19 downto 0) when '1',
99  din_reg (31 downto 0) when others;
100 
101 
102 -- wait two cycles and then capture the crc calculation result
103 process (clock) begin
104  if rising_edge (clock) then
105  if (crc_reset = '1') then
106  cyc_1 <= '0';
107  cyc_2 <= '0';
108  else
109  cyc_1 <= crc_start;
110  cyc_2 <= cyc_1;
111  end if;
112  end if;
113 end process;
114 
115 -- reset the crc error at the beginning of an event
116 -- calculated the crc of each channel's header and compare to that channel's declared crc
117 -- if a channel has an error, the crc_error (header_mismatch) will be set, and it will remain
118 -- set until the next event is started. The header_mismatch flag is incorporated into the event trailer
119 
120 
121 
122 process (clock) begin
123  if rising_edge (clock) then
124  if (crc_reset = '1') then
125  crc_error <= '0';
126  elsif (cyc_2 = '1') then
127  if (CRC_out /= declared_crc_reg) then
128  crc_error <= '1';
129  else
130  crc_error <= crc_error;
131  end if;
132  end if;
133  end if;
134 end process;
135 
136 header_mismatch <= crc_error;
137 
138 end RTL;