otsdaq_prepmodernization  v2_05_02_indev
burst_traffic_controller.vhd
1 
2 library IEEE;
3 use IEEE.STD_LOGIC_1164.ALL;
4 use IEEE.STD_LOGIC_ARITH.ALL;
5 use IEEE.STD_LOGIC_UNSIGNED.ALL;
6 
7 use work.params_package.ALL;
8 
9 
11  port (
12 
13  MASTER_CLK : in std_logic; -- 125 MHz Ethernet Clock
14  RESET : in std_logic;
15  BURST_WE: in std_logic;
16  BURST_FORCE_PACKET: in std_logic;
17 
18  BURST_END_PACKET: out std_logic
19 
20  );
21 end burst_traffic_controller;
22 
23 
24 architecture burst_traffic_controller_arch of burst_traffic_controller is
25 
26  signal clocks_since_send : std_logic_vector(33 downto 0);
27  signal writes_in_curr_burst : std_logic_vector(7 downto 0); --this count should always be
28  -- equal to burst_controller_sm/b_packet_qw_size
29  signal force_packet_old : std_logic;
30 
31 begin
32 
33  process(MASTER_CLK)
34  begin
35 
36  if rising_edge(MASTER_CLK) then
37 
38  -- keep pulses to only one clock
39  BURST_END_PACKET <= '0';
40 
41  force_packet_old <= BURST_FORCE_PACKET;
42 
43  if reset = '1' then
44 
45  clocks_since_send <= (others => '0');
46  writes_in_curr_burst <= (others => '0');
47 
48  else -- main section
49 
50  if clocks_since_send /= '1' & x"00000000" then -- increment clocks since last burst packet send
51  clocks_since_send <= clocks_since_send + 1;
52  end if;
53 
54  if BURST_WE = '1' then
55 
56  clocks_since_send <= (others => '0');
57 
58  if writes_in_curr_burst >= 181 then
59  writes_in_curr_burst <= (others => '0');
60  else
61  writes_in_curr_burst <= writes_in_curr_burst + 1;
62  end if;
63 
64  --allow for case when packet ended and write occurs
65  if (force_packet_old = '0' and BURST_FORCE_PACKET = '1') then
66  BURST_END_PACKET <= '1'; -- force end burst packet
67  writes_in_curr_burst <= x"01"; -- based on what happens in burst_controller_sm .. this write is first in next packet!
68  end if;
69 
70  else
71 
72  -- check if between hits should end Burst Packet due to time out period or external force signal
73  if ( writes_in_curr_burst /= 0 and
74  ( (force_packet_old = '0' and BURST_FORCE_PACKET = '1')
75  or
76  --BURST_PERIOD_MAX & '1' & x"E848" then -- in ms : [<val> * 0x1E848] 125Mhz clocks is max wait
77  (clocks_since_send >= '0' & x"0080" & '1' & x"E848") ) ) then
78 
79  BURST_END_PACKET <= '1'; -- force end burst packet
80  clocks_since_send <= (others => '0');
81  writes_in_curr_burst <= (others => '0');
82 
83  end if;
84 
85  end if;
86 
87  end if;
88 
89  end if;
90 
91  end process;
92 
93 
94 end architecture;