10 use IEEE.STD_LOGIC_1164.
all;
11 use IEEE.NUMERIC_STD.
all;
14 use work.ipbus_decode_efex_merging.
all;
20 use ipbus_lib.ipbus_reg_types.
all;
22 use ipbus_lib.ipbus.
all;
26 generic (TEST : boolean := false;
27 ENABLE
: std_logic := '1'
33 IN_Sync : in std_logic;
34 IN_BCN_sync : in std_logic_vector(3 downto 0);
37 IN_local_BCN : in std_logic_vector(11 downto 0);
38 OUT_merged_BCN : out std_logic_vector(11 downto 0);
41 ipb_clk : in std_logic;
42 ipb_rst : in std_logic;
44 ipb_out : out ipb_rbus;
46 OUT_Sync : out std_logic;
47 OUT_Valid : out std_logic;
53 constant N_CTRL : positive := 3;
54 constant N_STAT : positive := 2;
59 signal ipb_to_slaves : ipb_wbus_array(N_SLAVES - 1 downto 0);
60 signal ipb_from_slaves : ipb_rbus_array(N_SLAVES - 1 downto 0) := (others => IPB_RBUS_NULL);
62 signal write_reg : ipb_reg_v(N_STAT - 1 downto 0) := (others => (others => '0'));
63 signal read_reg : ipb_reg_v(N_CTRL - 1 downto 0);
66 signal regMergingControl, regInternalSortingControl, regMergingStatus, regOffset : AlgoRegister;
69 signal MergingStart : std_logic;
70 signal MergedStart : std_logic;
71 signal MergedWrite : std_logic;
82 signal FakeInputEnable : std_logic := '0';
83 signal SpyInputEnable : std_logic := '0';
86 signal FakeOutputEnable : std_logic := '0';
87 signal SpyOutputEnable : std_logic := '0';
90 signal Offset0, Offset1, Offset2, Offset3 : std_logic_vector(5 downto 0);
91 signal Enable0, Enable1, Enable2, Enable3 : std_logic;
93 signal bcn_sync : std_logic;
94 signal BCN_cnt3, BCN_cnt2, BCN_cnt1, BCN_cnt0 : std_logic_vector(9 downto 0) := (others => '0');
95 signal BCN_done : std_logic_vector(2 downto 0) := (others => '0');
96 signal BCN_counters : std_logic_vector(29 downto 0) := (others => '0');
97 signal reset_cnt : std_logic_vector(15 downto 0) := (others => '0');
101 signal merged_bcn_d1, merged_bcn_d2 : std_logic_vector(11 downto 0);
102 type BCN_t is array(6 downto 0) of std_logic_vector(11 downto 0);
103 signal TOB_BCN_d : BCN_t := (others => (others => '0'));
106 ENABLED_MERGE : if ENABLE = '1' generate
107 IPBUS_FABRIC :
entity ipbus_lib.ipbus_fabric_sel
110 SEL_WIDTH => IPBUS_SEL_WIDTH
)
112 sel => ipbus_sel_efex_merging
(ipb_in.ipb_addr
),
116 ipb_to_slaves => ipb_to_slaves,
117 ipb_from_slaves => ipb_from_slaves
);
118 end generate ENABLED_MERGE;
120 DISABLED_MERGE : if ENABLE = '0' generate
121 IPBUS_FABRIC :
entity ipbus_lib.ipbus_fabric_sel
124 SEL_WIDTH => IPBUS_SEL_WIDTH
)
126 sel =>
(others => '0'
),
127 ipb_in => IPB_WBUS_NULL,
129 ipb_to_slaves =>
open,
130 ipb_from_slaves =>
(others => IPB_RBUS_NULL
)
132 ipb_out <= (x"DEADBEEF", '1', '0');
133 end generate DISABLED_MERGE;
135 IPBUS_MERGING_REGISTERS :
entity ipbus_lib.ipbus_ctrlreg_v
142 ctrl_default =>
(2 => x"00000003",
others => x"00000000"
),
143 ipbus_in => ipb_to_slaves
(N_SLV_MERGING_REGISTERS
),
144 ipbus_out => ipb_from_slaves
(N_SLV_MERGING_REGISTERS
),
156 IN_Offset0 => Offset0,
157 IN_Offset1 => Offset1,
158 IN_Offset2 => Offset2,
159 IN_Offset3 => Offset3,
161 IN_BCN => IN_local_BCN,
162 OUT_BCN => TOB_BCN_d
(0),
164 IN_Enable0 => Enable0,
165 IN_Enable1 => Enable1,
166 IN_Enable2 => Enable2,
167 IN_Enable3 => Enable3,
170 OUT_Start => MergingStart,
184 IN_Control => regInternalSortingControl,
185 OUT_Status => regMergingStatus,
186 IN_Start => MergingStart,
188 OUT_Start => MergedStart,
189 OUT_Write => MergedWrite,
190 OUT_Data => MergedData
);
193 MergedDataOut <= to_AlgoTriggerObject(MergedData);
203 ipb_in => ipb_to_slaves
(N_SLV_MERGING_INPUT_RAM_1
),
204 ipb_out => ipb_from_slaves
(N_SLV_MERGING_INPUT_RAM_1
),
206 BCNIn =>
(others => '0'
),
208 SortedIn => IN_Data
(0),
210 Sync => MergingStart,
211 we => SpyInputEnable,
212 SortedOut => InputRAMOut
(0));
218 ipb_in => ipb_to_slaves
(N_SLV_MERGING_INPUT_RAM_2
),
219 ipb_out => ipb_from_slaves
(N_SLV_MERGING_INPUT_RAM_2
),
221 BCNIn =>
(others => '0'
),
223 SortedIn => IN_Data
(1),
225 Sync => MergingStart,
226 we => SpyInputEnable,
227 SortedOut => InputRAMOut
(1));
233 ipb_in => ipb_to_slaves
(N_SLV_MERGING_INPUT_RAM_3
),
234 ipb_out => ipb_from_slaves
(N_SLV_MERGING_INPUT_RAM_3
),
236 BCNIn =>
(others => '0'
),
238 SortedIn => IN_Data
(2),
240 Sync => MergingStart,
241 we => SpyInputEnable,
242 SortedOut => InputRAMOut
(2));
248 ipb_in => ipb_to_slaves
(N_SLV_MERGING_INPUT_RAM_4
),
249 ipb_out => ipb_from_slaves
(N_SLV_MERGING_INPUT_RAM_4
),
251 BCNIn =>
(others => '0'
),
253 SortedIn => IN_Data
(3),
255 Sync => MergingStart,
256 we => SpyInputEnable,
257 SortedOut => InputRAMOut
(3));
268 ipb_in => ipb_to_slaves
(N_SLV_MERGING_OUTPUT_RAM
),
269 ipb_out => ipb_from_slaves
(N_SLV_MERGING_OUTPUT_RAM
),
271 BCNIn =>
(others => '0'
),
273 SortedIn => MergedDataOut,
276 we => SpyOutputEnable,
277 SortedOut => OutputRAMOut
);
280 ENABLED_MERGING_OUTPUT : if ENABLE = '1' generate
284 OUT_TOB <= OutputRAMOut when FakeOutputEnable = '1' else MergedDataOut;
285 OUT_Valid <= '1' when FakeOutputEnable = '1' else MergedWrite;
286 OUT_Sync <= MergedStart;
287 end generate ENABLED_MERGING_OUTPUT;
289 DISABLED_MERGING_OUTPUT : if ENABLE = '0' generate
291 MergingDataIn <= (ZERO_ALGO_TRIGGER_OBJECT, ZERO_ALGO_TRIGGER_OBJECT, ZERO_ALGO_TRIGGER_OBJECT, ZERO_ALGO_TRIGGER_OBJECT);
293 OUT_TOB <= (others => '0');
296 end generate DISABLED_MERGING_OUTPUT;
299 BCN_FPGA_sych :
process (CLK)
301 if rising_edge(CLK) then
303 if IN_BCN_sync(3) = '1' then
304 BCN_cnt0 <= (others => '0');
305 BCN_cnt1 <= (others => '0');
306 BCN_cnt2 <= (others => '0');
307 BCN_done <= IN_BCN_sync(2 downto 0);
308 reset_cnt <= std_logic_vector(unsigned(reset_cnt) + 1);
311 if IN_BCN_sync(0) = '1' or BCN_done(0) = '1' then
313 BCN_cnt0 <= BCN_cnt0;
315 BCN_done(0) <= BCN_done(0);
316 BCN_cnt0 <= std_logic_vector(unsigned(BCN_cnt0) + 1);
319 if IN_BCN_sync(1) = '1' or BCN_done(1) = '1' then
321 BCN_cnt1 <= BCN_cnt1;
323 BCN_done(1) <= BCN_done(1);
324 BCN_cnt1 <= std_logic_vector(unsigned(BCN_cnt1) + 1);
327 if IN_BCN_sync(2) = '1' or BCN_done(2) = '1' then
329 BCN_cnt2 <= BCN_cnt2;
331 BCN_done(2) <= BCN_done(2);
332 BCN_cnt2 <= std_logic_vector(unsigned(BCN_cnt2) + 1);
335 reset_cnt <= reset_cnt;
340 BCN_published_ipbus :
process (CLK)
342 if rising_edge(CLK) then
343 if BCN_done(0) = '1' then
344 BCN_counters(9 downto 0) <= BCN_cnt0;
346 BCN_counters(9 downto 0) <= BCN_counters(9 downto 0);
349 if BCN_done(1) = '1' then
350 BCN_counters(19 downto 10) <= BCN_cnt1;
352 BCN_counters(19 downto 10) <= BCN_counters(19 downto 10);
355 if BCN_done(2) = '1' then
356 BCN_counters(29 downto 20) <= BCN_cnt2;
358 BCN_counters(29 downto 20) <= BCN_counters(29 downto 20);
365 OUT_merged_BCN <= TOB_BCN_d(6);
367 local_BCN_delay :
process (CLK)
369 if rising_edge(CLK) then
370 TOB_BCN_d(6 downto 1) <= TOB_BCN_d(5 downto 0);
377 regMergingControl <= read_reg(0);
378 regInternalSortingControl <= read_reg(1);
379 regOffset <= read_reg(2);
381 write_reg(0) <= "00" & BCN_counters;
382 write_reg(1) <= x"0" & reset_cnt & x"00" & "0" & BCN_done(2) & BCN_done(1) & BCN_done(0);
386 FakeInputEnable <= '0' when TEST else regMergingControl(0);
387 SpyInputEnable <= '0' when TEST else regMergingControl(1);
388 FakeOutputEnable <= '0' when TEST else regMergingControl(2);
389 SpyOutputEnable <= '0' when TEST else regMergingControl(3);
391 Offset0 <= (0 => '1', others => '0') when TEST else regOffset(5 downto 0);
392 Offset1 <= (0 => '1', others => '0') when TEST else regOffset(13 downto 8);
393 Offset2 <= (0 => '0', others => '0') when TEST else regOffset(21 downto 16);
394 Offset3 <= (0 => '1', others => '0') when TEST else regOffset(29 downto 24);
396 Enable0 <= '1' when TEST else not regOffset(7);
397 Enable1 <= '1' when TEST else not regOffset(15);
398 Enable2 <= '0' when TEST else not regOffset(23);
399 Enable3 <= '1' when TEST else not regOffset(31);
External data-types and functions.
array(natural range <> ) of AlgoTriggerObject AlgoTriggerObjects
Algorithm OUTPUT port.
std_logic_vector( OUT_TOB_WIDTH- 1 downto 0) AlgoTriggerObject
Algorithm Trigger Object TOB.
Top of TOB merging module with IPBus interface.
AlgoTriggerObjects( 3 downto 0) MergingDataIn
Input data before offset.
AlgoTriggerObjects( 3 downto 0) MergingData
Input data after demux.
AlgoTriggerObjects( 3 downto 0) OffsetData
Input data after offset, before demux.
Top of TOB merging module with IPBus interface.
TOB synchronisation module.
Top of TOB sorting module.