SURF  1.0
SsiObFrameFilter.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SsiObFrameFilter.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-05-02
5 -- Last update: 2017-06-01
6 -------------------------------------------------------------------------------
7 -- Description: This module is used to filter out bad SSI frames.
8 --
9 -- Note: If EN_FRAME_FILTER_G = true, then this module DOES NOT support
10 -- interleaving of channels during the middle of a frame transfer.
11 -------------------------------------------------------------------------------
12 -- This file is part of 'SLAC Firmware Standard Library'.
13 -- It is subject to the license terms in the LICENSE.txt file found in the
14 -- top-level directory of this distribution and at:
15 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
16 -- No part of 'SLAC Firmware Standard Library', including this file,
17 -- may be copied, modified, propagated, or distributed except according to
18 -- the terms contained in the LICENSE.txt file.
19 -------------------------------------------------------------------------------
20 
21 library ieee;
22 use ieee.std_logic_1164.all;
23 use ieee.std_logic_arith.all;
24 use ieee.std_logic_unsigned.all;
25 
26 use work.StdRtlPkg.all;
27 use work.AxiStreamPkg.all;
28 use work.SsiPkg.all;
29 
30 --! @see entity
31  --! @ingroup protocols_ssi
33  generic (
34  TPD_G : time := 1 ns;
35  VALID_THOLD_G : natural := 1;
36  EN_FRAME_FILTER_G : boolean := true;
37  AXIS_CONFIG_G : AxiStreamConfigType := ssiAxiStreamConfig(16));
38  port (
39  -- Slave Port (AXIS FIFO Read Interface)
41  sTLastTUser : in slv(7 downto 0);
43  overflow : in sl;
44  -- Master Port
47  mAxisDropWrite : out sl; -- Word dropped status output
48  mAxisTermFrame : out sl; -- Frame dropped status output
49  -- Clock and Reset
50  axisClk : in sl;
51  axisRst : in sl);
52 end SsiObFrameFilter;
53 
54 architecture rtl of SsiObFrameFilter is
55 
56  type StateType is (
57  IDLE_S,
58  BLOWOFF_S,
59  MOVE_S,
60  TERM_S);
61 
62  type RegType is record
63  wordDropped : sl;
64  frameDropped : sl;
65  tDest : slv(7 downto 0);
66  master : AxiStreamMasterType;
67  slave : AxiStreamSlaveType;
68  state : StateType;
69  end record RegType;
70 
71  constant REG_INIT_C : RegType := (
72  wordDropped => '0',
73  frameDropped => '0',
74  tDest => x"00",
75  master => AXI_STREAM_MASTER_INIT_C,
76  slave => AXI_STREAM_SLAVE_INIT_C,
77  state => IDLE_S);
78 
79  signal r : RegType := REG_INIT_C;
80  signal rin : RegType;
81 
82 begin
83 
84  assert (AXIS_CONFIG_G.TUSER_BITS_C >= 2) report "SsiObFrameFilter: AXIS_CONFIG_G.TUSER_BITS_C must be >= 2" severity failure;
85 
86  NO_FILTER : if (EN_FRAME_FILTER_G = false) generate
87 
90 
91  mAxisDropWrite <= '0';
92  mAxisTermFrame <= '0';
93 
94  end generate;
95 
96  ADD_FILTER : if (EN_FRAME_FILTER_G = true) generate
97 
98  comb : process (axisRst, mAxisSlave, overflow, r, sAxisMaster, sTLastTUser) is
99  variable v : RegType;
100  variable sof : sl;
101  variable eof : AxiStreamMasterType;
102  variable eofe : sl;
103  begin
104  -- Latch the current value
105  v := r;
106 
107  -- Reset strobe Signals
108  v.wordDropped := '0';
109  v.frameDropped := '0';
110  v.slave := AXI_STREAM_SLAVE_INIT_C;
111  if (mAxisSlave.tReady = '1') then
112  v.master.tValid := '0';
113  end if;
114 
115  -- Get the SOF status
116  sof := ssiGetUserSof(AXIS_CONFIG_G, sAxisMaster);
117 
118  -- Check for FIFO caching
119  if (VALID_THOLD_G = 0) then
120  -- Get the EOFE status
122  else
123  -- Reset the flag
124  eofe := '0';
125  end if;
126 
127  -- State Machine
128  case (r.state) is
129  ----------------------------------------------------------------------
130  when IDLE_S =>
131  -- Check for FIFO caching and a frame larger than the FIFO depth
132  if (VALID_THOLD_G = 0) and (overflow = '1') then
133  -- Blowoff the data
134  v.slave.tReady := '1';
135  -- Next state
136  v.state := BLOWOFF_S;
137  -- Check for non-EOF or tValid not set
138  if (sAxisMaster.tLast = '0') or (sAxisMaster.tValid = '0') then
139  -- Next state
140  v.state := BLOWOFF_S;
141  end if;
142  -- Check if ready to move data
143  elsif (v.master.tValid = '0') and (sAxisMaster.tValid = '1') then
144  -- Accept the data
145  v.slave.tReady := '1';
146  -- Check for SOF
147  if (sof = '1') and (eofe = '0') and (overflow = '0') then
148  -- Move the data bus
149  v.master := sAxisMaster;
150  -- Latch tDest
151  v.tDest := sAxisMaster.tDest;
152  -- Check for no EOF
153  if (sAxisMaster.tLast = '0') then
154  -- Next state
155  v.state := MOVE_S;
156  end if;
157  else
158  -- Strobe the error flags
159  v.wordDropped := '1';
160  v.frameDropped := sAxisMaster.tLast;
161  -- Check for non-EOF
162  if (sAxisMaster.tLast = '0') then
163  -- Next state
164  v.state := BLOWOFF_S;
165  end if;
166  end if;
167  end if;
168  ----------------------------------------------------------------------
169  when BLOWOFF_S =>
170  -- Blowoff the data
171  v.slave.tReady := '1';
172  -- Strobe the error flags
173  v.wordDropped := '1';
174  v.frameDropped := sAxisMaster.tLast;
175  -- Check for EOF
176  if (sAxisMaster.tValid = '1') and (sAxisMaster.tLast = '1') then
177  -- Next state
178  v.state := IDLE_S;
179  end if;
180  ----------------------------------------------------------------------
181  when MOVE_S =>
182  -- Check if ready to move data
183  if (v.master.tValid = '0') and (sAxisMaster.tValid = '1') then
184  -- Accept the data
185  v.slave.tReady := '1';
186  -- Move the data bus
187  v.master := sAxisMaster;
188  -- Check for EOF
189  if (sAxisMaster.tLast = '1') then
190  -- Next state
191  v.state := IDLE_S;
192  end if;
193  -- Check for SSI framing errors (repeated SOF or interleaved frame)
194  if (sof = '1') or (r.tDest /= sAxisMaster.tDest) then
195  -- Set the EOF flag
196  v.master.tLast := '1';
197  -- Set the EOFE flag
198  ssiSetUserEofe(AXIS_CONFIG_G, v.master, '1');
199  -- Strobe the error flags
200  v.wordDropped := '1';
201  v.frameDropped := sAxisMaster.tLast;
202  -- Next state
203  v.state := IDLE_S;
204  end if;
205  end if;
206  -- Check for overflow event
207  if (overflow = '1') then
208  -- Check if moving data
209  if (v.master.tValid = '1') then
210  -- Set the EOF flag
211  v.master.tLast := '1';
212  -- Set the EOFE flag
213  ssiSetUserEofe(AXIS_CONFIG_G, v.master, '1');
214  -- Strobe the error flags
215  v.wordDropped := '1';
216  v.frameDropped := sAxisMaster.tLast;
217  -- Next state
218  v.state := IDLE_S;
219  else
220  -- Next state
221  v.state := TERM_S;
222  end if;
223  end if;
224  ----------------------------------------------------------------------
225  when TERM_S =>
226  -- Check if ready to move data
227  if (v.master.tValid = '0') then
228  -- Set the EOF flag
229  v.master.tValid := '1';
230  v.master.tLast := '1';
231  -- Set the EOFE flag
232  ssiSetUserEofe(AXIS_CONFIG_G, v.master, '1');
233  -- Next state
234  v.state := IDLE_S;
235  end if;
236  ----------------------------------------------------------------------
237  end case;
238 
239  -- Synchronous Reset
240  if (axisRst = '1') then
241  v := REG_INIT_C;
242  end if;
243 
244  -- Register the variable for next clock cycle
245  rin <= v;
246 
247  -- Outputs
248  sAxisSlave <= v.slave;
249  mAxisMaster <= r.master;
250  mAxisDropWrite <= r.wordDropped;
251  mAxisTermFrame <= r.frameDropped;
252 
253  end process comb;
254 
255  seq : process (axisClk) is
256  begin
257  if rising_edge(axisClk) then
258  r <= rin after TPD_G;
259  end if;
260  end process seq;
261 
262  end generate;
263 
264 end rtl;
VALID_THOLD_Gnatural := 1
sl sof
Definition: SsiPkg.vhd:72
in mAxisSlaveAxiStreamSlaveType
std_logic sl
Definition: StdRtlPkg.vhd:28
integer := 0 SSI_EOFE_C
Definition: SsiPkg.vhd:30
AxiStreamMasterType :=(tValid => '0',tData =>( others => '0'),tStrb =>( others => '1'),tKeep =>( others => '1'),tLast => '0',tDest =>( others => '0'),tId =>( others => '0'),tUser =>( others => '0')) AXI_STREAM_MASTER_INIT_C
_library_ ieeeieee
sl eofe
Definition: SsiPkg.vhd:74
AxiStreamSlaveType :=(tReady => '0') AXI_STREAM_SLAVE_INIT_C
natural range 0 to 8 TUSER_BITS_C
slv( 7 downto 0) tDest
in sAxisMasterAxiStreamMasterType
in sTLastTUserslv( 7 downto 0)
AXIS_CONFIG_GAxiStreamConfigType := ssiAxiStreamConfig( 16)
sl eof
Definition: SsiPkg.vhd:73
out sAxisSlaveAxiStreamSlaveType
out mAxisMasterAxiStreamMasterType
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
EN_FRAME_FILTER_Gboolean := true