otsdaq_prepmodernization  v2_05_02_indev
stat_pulse.vhd
1 ----------------------------------------------------------------------------------
2 -- Company: Fermilab
3 -- Engineer: Collin Bradford
4 --
5 -- Create Date: 12:48:44 07/27/2017
6 -- Design Name:
7 -- Module Name: stat_pulse - Behavioral
8 -- Project Name:
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 -- This module takes data from the project and puts it into a small statistic packet no more than 64 bits long. This packet will then be sent along with
20 -- all the other burst data to the controll software on the computer. The statistic packet will monitor the fifo overflow signals as well as the number
21 -- of pulses sent every statistic period. The statistic period should probably be controlled with a user-set register that will come sometime.
22 -- In order to have this work, I am going to have to be able to insert this packet into the normal flow of data coming from the adc without blocking
23 -- the adc data. This will probably have to be accomplished with a multiplexer and will nessessitate that the stat data be only 64 bits long.
24 -- otherwise, the stat pakcet might be split up because of the more important adc data.
25 
26 --
27 --
28 ----------------------------------------------------------------------------------
29 library IEEE;
30 use IEEE.numeric_std.all;
31 use IEEE.STD_LOGIC_1164.ALL;
32 use IEEE.STD_LOGIC_UNSIGNED.ALL;
33 
34 entity stat_pulse is
35  Port ( master_clk : in STD_LOGIC;
36  reset : in STD_LOGIC;
37  adc_fifo_overflow : in STD_LOGIC;
38  ethernet_fifo_overflow : in STD_LOGIC;
39  new_peak : in STD_LOGIC;
40  ethernet_fifo_in_en : in STD_LOGIC;
41  adc_fifo_overflow_lat_res : out STD_LOGIC;
42  ethernet_fifo_overflow_lat_res : out STD_LOGIC;
43  tx_data : out STD_LOGIC_VECTOR (63 downto 0);
44  stat_ethernet_fifo_in_en : out STD_LOGIC;
45  new_stat : out STD_LOGIC);
46 end stat_pulse;
47 
48 architecture Behavioral of stat_pulse is
49  signal timer : unsigned(19 downto 0);
50  signal sendReady : STD_LOGIC;
51  signal triggers : unsigned(31 downto 0);
52  signal sig_tx_data : STD_LOGIC_VECTOR (63 downto 0);
53  signal stat_sent : STD_LOGIC;
54  signal reset_lat : STD_LOGIC;
55  signal new_stat_sig : STD_LOGIC;
56 begin
57 
58  tx_data(63 downto 0) <= sig_tx_data(63 downto 0);
59 
60  sig_tx_data(63 downto 32) <= std_logic_vector(triggers(31 downto 0)); --T (number of triggers since last stat packet)
61  sig_tx_data(31 downto 21) <= (others => '0'); --X (unused + padding for A)
62  sig_tx_data(20) <= adc_fifo_overflow; --A (ADC FiFo overflow)
63  sig_tx_data(19 downto 17) <= (others => '0'); --X (padding for E)
64  sig_tx_data(16) <= ethernet_fifo_overflow; --E (ethernet FiFo overflow)
65  sig_tx_data(15 downto 0) <= (others => '1'); --F (Padding with 1's to designate packet as stat)
66 
67  new_stat <= new_stat_sig;
68 
69  process(master_clk) begin
70 
71  if(rising_edge(master_clk)) then
72 
73  if(reset = '0') then
74 
75  if(timer /= "11110100001001000000" and sendReady = '0') then
76  timer <= timer + 1;
77  elsif (sendReady = '0') then
78  if(ethernet_fifo_in_en = '0') then --TODO if PeakFinder is currently triggered and sending data, wait until a better time. Else, go ahead and send the packet.
79  new_stat_sig <= '1';
80  stat_ethernet_fifo_in_en <= '1';
81  timer <= (others => '0');
82  stat_sent <= '1';
83  else
84  sendReady <= '1';
85  end if;
86  end if;
87 
88  if(sendReady = '1' and ethernet_fifo_in_en = '0' and stat_sent = '0') then --A send is due and PeakFinder is not Triggered.
89  new_stat_sig <= '1';
90  stat_ethernet_fifo_in_en <= '1';
91  timer <= (others => '0');
92  sendReady <= '0';
93  stat_sent <= '1';
94  end if;
95 
96  if(stat_sent = '1') then --Reset the fifo overflow latches and trigger count.
97  stat_sent <= '0';
98  triggers <= (others => '0');
99  adc_fifo_overflow_lat_res <= '1';
100  ethernet_fifo_overflow_lat_res <= '1';
101  reset_lat <= '1';
102  new_stat_sig <= '0';
103  stat_ethernet_fifo_in_en <= '0';
104  end if;
105 
106  if(reset_lat = '1') then --Reset the latch resets after one clock to pulse the reset and allow them to work agian.
107  adc_fifo_overflow_lat_res <= '0';
108  ethernet_fifo_overflow_lat_res <= '0';
109  reset_lat <= '0';
110  end if;
111 
112  if(new_peak = '1') then --Count the triggers.
113  triggers <= triggers + 1;
114  end if;
115 
116  else --reset is high
117  timer <= (others => '0');
118  triggers <= (others => '1');
119  sendReady <= '0';
120  reset_lat <= '0';
121  stat_sent <= '0';
122  adc_fifo_overflow_lat_res <= '0';
123  ethernet_fifo_overflow_lat_res <= '0';
124  end if;
125 
126  end if;
127 
128  end process;
129 
130 end Behavioral;
131