CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
CMX_Jet_Topo_Encoder.vhd
Go to the documentation of this file.
1 ----------------------------------------------------------------------------------
9 ----------------------------------------------------------------------------------
10 library IEEE;
11 use IEEE.STD_LOGIC_1164.ALL;
12 
13 library work;
14 use work.CMXpackage.all;
15 use work.CMX_flavor_package.all;
16 
17 
18 -- Uncomment the following library declaration if using
19 -- arithmetic functions with Signed or Unsigned values
20 use IEEE.NUMERIC_STD.ALL;
21 
22 -- Uncomment the following library declaration if instantiating
23 -- any Xilinx primitives in this code.
24 --library UNISIM;
25 --use UNISIM.VComponents.all;
26 
27 entity CMX_Jet_Topo_Encoder is
28  port (
29  Tobs_to_TOPO : in copy_arr_TOB;
30  overflow : in std_logic_vector(num_copies-1 downto 0);
31  --DATA_Et1 : in std_logic_vector((576/2)-1 downto 0);--(TO_Jet_Et1_size*Num_TO_Jet) - 1 downto 0);
32  --DATA_Et2 : in std_logic_vector((640/2)-1 downto 0);--(TO_Jet_Et2_size*Num_TO_Jet) - 1 downto 0);
33  --DATA_pos : in std_logic_vector((576/2)-1 downto 0);--(TO_Jet_eta_size*Num_TO_Jet) - 1 downto 0);
34  --overflow : in std_logic;
35 
36  -- this instructs the modules downstream to plug in the alignment word.
37  send_align_out : out std_logic_vector(num_GTX_groups*num_GTX_per_group - 1 downto 0);
38 
39  Data_out : out std_logic_vector(TX_indata_length - 1 downto 0));
40  --clk :in std_logic);
41 end CMX_Jet_Topo_Encoder;
42 
43 architecture Behavioral of CMX_Jet_Topo_Encoder is
44 
45  --these consts describe the trigger object arrangement
46  constant num_cols : integer:=4; -- 4 Jet TO's per fiber
47  -- indexing starts on the left i.e. TO 0
48  -- in a given row
49  -- occupies the most sig 28 bits
50  constant num_rows : integer:=8; --8 fibers
51 
52  --these consts describe the word (16 or 18 bit) object arrangement
53  constant num_cols_words : integer:=8; --8 16 bit words per fiber (=8
54  --16bit+2bit K flag per fiber)
55  --note that these start at the low end
56  --i.e. word 0 is 15 downto 0 in
57  --flat_array
58  --or 17 down to 0 in final_array
59  constant num_rows_words : integer:=8; -- 6 fibers (ok a bit redundant)
60 
61  -- obsolete -- --first the input data is interpreted as an array of Jet TOs (no logic here
62  -- obsolete -- --just renaming signals)
63  -- obsolete -- signal TO_Jets : arr_TO_Jet;
64 
65  --then the TO_Jets array is packed onto a flat array
66  --it is just a long vector but we can think of this as having 8 rows 128 bits
67  --each (i.e. each row corresponds to data sent on a single fiber)
68  --each 'row' holds 4 jet TO's and is padded with zeros (least sig 15 bits
69  --bit 16 is the overflow)
70  --the position of TO in the row is the column. Columns are filled first
71  -- e.g. Jet TO 0 occupying bits 127 downto 100 is row 0 column 0
72  -- Jet TO 8 is occupying bits 355 downto 327 is row 2 column 1
73  signal flat_array : std_logic_vector(num_copies*num_cols_words*num_rows_words*16-1 downto 0 );
74 
75 
76 
77  --detects if TO 2 on a given row is 0 energy (then TO 3 is presumeably 0 also)
78  signal send_align : std_logic_vector(num_rows-1 downto 0);
79 
80  signal send_align_ET1ET2 : arr_19(num_rows*num_copies-1 downto 0);
81  --type arr_ET1ET2 is array (integer range <>) of std_logic_vector(TO_Jet_Et1_size+TO_Jet_Et2_size - 1 downto 0);
82  --signal send_align_ET1ET2 : arr_ET1ET2(num_rows-1 downto 0);
83 
84 
85  --component chipscope_ila_jet_encoder is
86  -- port (
87  -- CONTROL : inout std_logic_vector(35 downto 0);
88  -- CLK : in std_logic;
89  -- DATA : in std_logic_vector(585 downto 0);
90  -- TRIG0 : in std_logic_vector(0 to 0));
91  --end component chipscope_ila_jet_encoder;
92 
93  --signal CONTROL : std_logic_vector(35 downto 0);
94  --signal DATA_ila_jet_encoder : std_logic_vector(585 downto 0);
95  --signal TRIG0_ila_jet_encoder : std_logic_vector(0 to 0);
96 
97  --component chipscope_icon_u1_c1 is
98  -- port (
99  -- CONTROL0 : inout std_logic_vector(35 downto 0));
100  --end component chipscope_icon_u1_c1;
101 
102 begin
103 
104 
105  ----form the array of jet TO's
106  --jet_arr_gen: for i_jet in 0 to Num_TO_Jet-1 generate
107  -- TO_Jets(i_jet)(TO_Jet_Et2_size-1 downto 0)<=DATA_Et2((i_jet+1)*TO_Jet_Et2_size - 1 downto i_jet * TO_Jet_Et2_size);
108  -- TO_Jets(i_jet)(TO_Jet_Et2_size+TO_Jet_Et1_size-1 downto TO_Jet_Et2_size)<=DATA_Et1((i_jet+1)*TO_Jet_Et1_size - 1 downto i_jet * TO_Jet_Et1_size);
109  -- TO_Jets(i_jet)(TO_Jet_Et2_size+TO_Jet_Et1_size+TO_Jet_pos_size-1 downto TO_Jet_Et2_size+TO_Jet_Et1_size)<=DATA_pos((i_jet+1)*TO_Jet_pos_size - 1 downto i_jet * TO_Jet_pos_size);
110  --end generate jet_arr_gen;
111 
112 
113 
114 
115  flat_arr_payload_copy_gen: for i_copy in 0 to num_copies-1 generate
116  flat_arr_payload_gen: for i_TO in 0 to Num_TO_Jet-1 generate
117 
118 
119  constant i_col :integer := (i_TO/num_rows);
120  constant i_row :integer := (i_TO rem num_rows)+num_rows*i_copy;
121 
122  --
123  --constant i_row_cpy : integer := i_row+i_copy*num_rows;
124  constant i_row_fiber: integer := fiber_to_gtx(i_row);
125 
126  constant msb : integer := 128*i_row_fiber + 127 - ( i_col * TO_Jet_size );
127  constant lsb : integer := 128*i_row_fiber + 128 - ( ( i_col +1 ) * TO_Jet_size );
128 
129  --flat_array(msb downto lsb)<=TO_Jets(i_TO);
130  --flat_array(128*i_row + 127 - ( i_col * TO_Jet_size ) downto 128*i_row + 128 - ( ( i_col +1 ) * TO_Jet_size ))<=TO_Jets(i_TO);
131 
132  begin
133 
134  --just trigger a report
135  assert 1=0 report "WTF: Jet_Topo_Encoder flat_array generation: i_copy: "&integer'IMAGE(i_copy)&", i_TO: "&integer'IMAGE(i_TO)&", i_col: "&integer'IMAGE(i_col)&", i_row: "&integer'IMAGE(i_row)&", msb: "&integer'IMAGE(msb)&", i_row_fiber: "&integer'IMAGE(i_row_fiber)&", msb: "&integer'IMAGE(msb)&", lsb: "&integer'IMAGE(lsb) severity NOTE;
136 
137  assert i_TO<=32 report "TOO MANY TOBS in THE Jet Encoder INSTATIATION!!!" severity FAILURE;
138  assert lsb>=0 report "LSB less than 0 in the jet encoder instantiation!!!; i_copy: "&integer'IMAGE(i_copy)&", i_TO: "&integer'IMAGE(i_TO)&", i_col: "&integer'IMAGE(i_col)&", i_row: "&integer'IMAGE(i_row)&", msb: "&integer'IMAGE(msb)&", lsb: "&integer'IMAGE(lsb) severity FAILURE;
139 
140  flat_array(lsb+TO_Jet_Et2_size-1 downto lsb)<=Tobs_to_TOPO(i_copy)(i_TO).Et2;
141  flat_array(lsb+TO_Jet_Et2_size+TO_Jet_Et1_size-1 downto lsb+TO_Jet_Et2_size)<=Tobs_to_TOPO(i_copy)(i_TO).Et1;
142  flat_array(lsb+TO_Jet_Et2_size+TO_Jet_Et1_size+TO_Jet_pos_size-1 downto lsb+TO_Jet_Et2_size+TO_Jet_Et1_size)<=Tobs_to_TOPO(i_copy)(i_TO).pos;
143 
144 
145  end generate flat_arr_payload_gen;
146  end generate flat_arr_payload_copy_gen;
147 
148 
149  flat_arr_overflow_copy_gen: for i_copy in 0 to num_copies-1 generate
150  flat_arr_overflow_gen: for i_row in 0 to num_rows-1 generate
151  flat_array(15 + i_row*128 +i_copy*num_rows*128)<=overflow(i_copy);
152  flat_array(14 + i_row*128 +i_copy*num_rows*128 downto i_row*128 +i_copy*num_rows*128)<=(others=>'0');
153  end generate flat_arr_overflow_gen;
154  end generate flat_arr_overflow_copy_gen;
155 
156 
157  send_align_copy_gen: for i_copy in 0 to num_copies-1 generate
158  send_align_gen: for i_row in 0 to num_rows-1 generate
159  constant i_row_cpy : integer := i_row+i_copy*num_rows;
160  constant i_row_fiber: integer := fiber_to_gtx(i_row_cpy);
161  begin
162 
163  send_align_ET1ET2(i_row_fiber)(18 downto 10)<=Tobs_to_TOPO(i_copy)(i_row+2*num_rows).Et1;
164  send_align_ET1ET2(i_row_fiber)(9 downto 0) <=Tobs_to_TOPO(i_copy)(i_row+2*num_rows).Et2;
165  send_align_out(i_row_fiber)<= '0' when send_align_ET1ET2(i_row_fiber)/="0000000000000000000" else '1';
166 
167  end generate send_align_gen;
168  end generate send_align_copy_gen;
169 
170 
171 
172 
173  Data_out<=flat_array;
174 
175  --chipscope_icon_u1_c1_inst: entity work.chipscope_icon_u1_c1
176  -- port map (
177  -- CONTROL0 => CONTROL);
178 
179  --chipscope_ila_jet_encoder_inst: entity work.chipscope_ila_jet_encoder
180  -- port map (
181  -- CONTROL => CONTROL,
182  -- CLK => clk,
183  -- DATA => DATA_ila_jet_encoder,
184  -- TRIG0 => TRIG0_ila_jet_encoder);
185 
186  --TRIG0_ila_jet_encoder(0)<='0';
187 
188  --DATA_ila_jet_encoder(0)<='0';
189  --DATA_ila_jet_encoder(8 downto 1)<=send_align;
190  --DATA_ila_jet_encoder(328 downto 9)<=DATA_Et2;
191  --DATA_ila_jet_encoder(584 downto 329)<=flat_array(255 downto 0);
192  --DATA_ila_jet_encoder(585)<='0';
193 
194 
195 
196 end Behavioral;
197 
integer :=i_row + i_copy * num_rows i_row_cpy
integer :=128 * i_row_fiber + 127 - (i_col * TO_Jet_size msb)
integer :=(i_TO rem num_rows) + num_rows * i_copy i_row
std_logic_vector (num_copies * num_cols_words * num_rows_words * 16 - 1 downto 0) flat_array)
integer :=128 * i_row_fiber + 128 - ((i_col + 1) * TO_Jet_size) lsb
std_logic_vector (num_rows - 1 downto 0) send_align
integer :=(i_TO / num_rows) i_col
integer :=fiber_to_gtx (i_row) i_row_fiber
arr_19 (num_rows * num_copies - 1 downto 0) send_align_ET1ET2)