otsdaq_prepmodernization  v2_05_02_indev
burst_controller_sm.vhd
1 -------------------------------------------------------------------------------
2 --
3 -- Title : Burst Controller State Machine
4 -- Design : burst_controller
5 -- Author : Ryan Rivera
6 -- Company : FNAL
7 --
8 --------------------------------
9 --
10 -- Description :
11 --
12 -------------------------------------------------------------------------------
13 
14 library IEEE;
15 use IEEE.std_logic_1164.all;
16 use IEEE.std_logic_arith.all;
17 use IEEE.std_logic_unsigned.all;
18 
19 entity burst_controller_sm is
20  port (
21  clk: in STD_LOGIC;
22  reset: in STD_LOGIC;
23 
24  b_mode: in STD_LOGIC;
25 
26  b_data_we: in STD_LOGIC;
27  b_end_packet: in STD_LOGIC;
28  tx_data_full: in STD_LOGIC;
29  tx_info_full: in STD_LOGIC;
30 
31  b_enable: out STD_LOGIC;
32 
33  tx_data_we: out STD_LOGIC;
34  tx_info: out STD_LOGIC_VECTOR (15 downto 0);
35  tx_info_we: out STD_LOGIC);
36 end burst_controller_sm;
37 
38 architecture burst_controller_sm_arch of burst_controller_sm is
39 
40  constant max_packet_64_size: STD_LOGIC_VECTOR (7 downto 0) := x"B6"; -- B6 = 182;
41 
42  -- diagram signals declarations
43  signal b_enable_sig: STD_LOGIC;
44  signal b_packet_qw_size: STD_LOGIC_VECTOR (7 downto 0); --this count should always be
45  -- equal to data_manager/burst_traffic_controller/writes_in_curr_burst
46  signal first_packet_sig, b_end_packet_old: STD_LOGIC;
47  signal just_reset: STD_LOGIC;
48  signal reset_packet_size: STD_LOGIC;
49 
50  -- SYMBOLIC ENCODED state machine: Sreg0
51  type Sreg0_type is (
52  Wait_for_End, Reset_Size, Idle
53  );
54  -- attribute enum_encoding of Sreg0_type: type is ... -- enum_encoding attribute is not supported for symbolic encoding
55  signal Sreg0: Sreg0_type;
56 
57 begin
58 
59  -- concurrent signals assignments
60 
61  -- this block only affects first 2 bits of packet type: 1 = first in burst, 2 = middle, 3 = last in burst
62  tx_info(7 downto 2) <= (others => '0');
63 
64  -- don't allow writes when tx fifo is full (when overflow data is dropped on the floor)
65  tx_data_we <= b_enable_sig and b_data_we and (not tx_data_full) and (not tx_info_full);
66  b_enable <= b_enable_sig and (not tx_data_full) and (not tx_info_full);
67 
68 
69  ----------------------------------------------------------------------
70  -- Proc_size:
71  -- counts the number of quad-words
72  -- in the current packet and saves the value
73  -- in b_packet_qw_size.
74  ----------------------------------------------------------------------
75  proc_size: process(clk)
76  begin
77  if rising_edge(clk) then
78 
79  if reset = '1' then
80  b_packet_qw_size <= (others => '0');
81  else
82  just_reset <= '0';
83  if b_enable_sig = '1' and b_data_we = '1' and tx_data_full = '0' and tx_info_full = '0' then
84  b_packet_qw_size <= b_packet_qw_size + 1;
85  if b_packet_qw_size = max_packet_64_size or b_end_packet = '1' then -- include case where packet is ended at same time as b_we pulse
86  b_packet_qw_size <= x"01";
87  -- start next packet (allows for burst to not use b_end_packet signal)
88  just_reset <= '1';
89  end if;
90  elsif b_enable_sig = '1' and b_end_packet = '1' then
91  b_packet_qw_size <= (others => '0');
92  elsif just_reset = '0' and reset_packet_size = '1' then
93  -- follow reset_packet_size flag, if didn't just reset
94  b_packet_qw_size <= (others => '0');
95  end if;
96  end if;
97 
98  end if;
99  end process;
100 
101  ----------------------------------------------------------------------
102  -- Machine: Sreg0
103  ----------------------------------------------------------------------
104  Sreg0_machine: process (clk)
105  begin
106  if rising_edge(clk) then
107 
108  -- Set default values for outputs, signals and variables
109  -- ...
110  tx_info_we <= '0';
111  reset_packet_size <= '0';
112  b_end_packet_old <= b_end_packet;
113 
114  if reset = '1' then
115  Sreg0 <= Idle;
116  -- Set reset values for outputs, signals and variables
117  -- ...
118  tx_info(1 downto 0) <= "01";
119  b_enable_sig <= '0';
120  first_packet_sig <= '1';
121  tx_info(15 downto 8) <= (others => '0');
122  else
123  case Sreg0 is
124  when Wait_for_End =>
125  if b_mode = '0' then
126  Sreg0 <= Reset_Size;
127  reset_packet_size <= '1';
128  tx_info(15 downto 8) <= b_packet_qw_size;
129  tx_info(1 downto 0) <= "11"; --indicate last in burst
130  tx_info_we <= '1';
131  b_enable_sig <= '0';
132  elsif (reset_packet_size = '0' ) then -- block back to back packets
133  --(because it takes an extra clock to reset size on wrap around case)
134  if ( (b_end_packet_old = '0' and b_end_packet = '1') or
135  b_packet_qw_size = max_packet_64_size ) then -- end of packet detected
136  Sreg0 <= Wait_for_End;
137  tx_info(15 downto 8) <= b_packet_qw_size;
138 
139  if first_packet_sig = '1' then
140  tx_info(1 downto 0) <= "01"; --indicate first in burst
141  first_packet_sig <= '0';
142  else
143  tx_info(1 downto 0) <= "10"; --indicate middle of burst
144  end if;
145 
146  tx_info_we <= '1';
147  reset_packet_size <= '1';
148  end if;
149  end if;
150  when Reset_Size =>
151  Sreg0 <= Idle;
152  b_enable_sig <= '0';
153  first_packet_sig <= '1';
154  when Idle =>
155  if b_mode = '1' then
156  Sreg0 <= Wait_for_End;
157  b_enable_sig <= '1';
158  end if;
159  when others =>
160  null;
161  end case;
162  end if;
163  end if;
164  end process;
165 
166 end burst_controller_sm_arch;