SURF  1.0
SsiIbFrameFilter.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SsiIbFrameFilter.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  SLAVE_READY_EN_G : boolean := true;
36  EN_FRAME_FILTER_G : boolean := true;
37  AXIS_CONFIG_G : AxiStreamConfigType := ssiAxiStreamConfig(16));
38  port (
39  -- Slave Port
43  sAxisDropWrite : out sl; -- Word dropped status output
44  sAxisTermFrame : out sl; -- Frame dropped status output
45  -- Master Port (AXIS FIFO Write Interface)
49  -- Clock and Reset
50  axisClk : in sl;
51  axisRst : in sl);
52 end SsiIbFrameFilter;
53 
54 architecture rtl of SsiIbFrameFilter is
55 
56  type StateType is (
57  INIT_S,
58  IDLE_S,
59  BLOWOFF_S,
60  MOVE_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 => INIT_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 "SsiIbFrameFilter: AXIS_CONFIG_G.TUSER_BITS_C must be >= 2" severity failure;
85 
87 
88  NO_FILTER : if (EN_FRAME_FILTER_G = false) generate
89 
92 
93  sAxisDropWrite <= '0';
94  sAxisTermFrame <= '0';
95 
96  end generate;
97 
98  ADD_FILTER : if (EN_FRAME_FILTER_G = true) generate
99 
100  comb : process (axisRst, mAxisCtrl, mAxisSlave, r, sAxisMaster) is
101  variable v : RegType;
102  variable sof : 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') or (SLAVE_READY_EN_G = false) then
112  v.master.tValid := '0';
113  end if;
114 
115  -- Get the SOF status
116  sof := ssiGetUserSof(AXIS_CONFIG_G, sAxisMaster);
117 
118  -- State Machine
119  case (r.state) is
120  ----------------------------------------------------------------------
121  when INIT_S =>
122  -- Wait for FIFO to initialize
123  if (mAxisSlave.tReady = '1') then
124  -- Next state
125  v.state := IDLE_S;
126  end if;
127  ----------------------------------------------------------------------
128  when IDLE_S =>
129  -- Check if ready to move data
130  if (v.master.tValid = '0') and (sAxisMaster.tValid = '1') then
131  -- Accept the data
132  v.slave.tReady := '1';
133  -- Check for SOF and no overflow
134  if (sof = '1') then
135  -- Move the data bus
136  v.master := sAxisMaster;
137  -- Latch tDest
138  v.tDest := sAxisMaster.tDest;
139  -- Check for no EOF
140  if (sAxisMaster.tLast = '0') then
141  -- Next state
142  v.state := MOVE_S;
143  end if;
144  else
145  -- Strobe the error flags
146  v.wordDropped := '1';
147  v.frameDropped := sAxisMaster.tLast;
148  -- Check for non-EOF
149  if (sAxisMaster.tLast = '0') then
150  -- Next state
151  v.state := BLOWOFF_S;
152  end if;
153  end if;
154  end if;
155  ----------------------------------------------------------------------
156  when BLOWOFF_S =>
157  -- Blowoff the data
158  v.slave.tReady := '1';
159  -- Strobe the error flags
160  v.wordDropped := '1';
161  v.frameDropped := sAxisMaster.tLast;
162  -- Check for EOF
163  if (sAxisMaster.tValid = '1') and (sAxisMaster.tLast = '1') then
164  -- Next state
165  v.state := IDLE_S;
166  end if;
167  ----------------------------------------------------------------------
168  when MOVE_S =>
169  -- Check if ready to move data
170  if (v.master.tValid = '0') and (sAxisMaster.tValid = '1') then
171  -- Accept the data
172  v.slave.tReady := '1';
173  -- Move the data bus
174  v.master := sAxisMaster;
175  -- Check for EOF
176  if (sAxisMaster.tLast = '1') then
177  -- Next state
178  v.state := IDLE_S;
179  end if;
180  -- Check for SSI framing errors (repeated SOF or interleaved frame)
181  if (sof = '1') or (r.tDest /= sAxisMaster.tDest) then
182  -- Set the EOF flag
183  v.master.tLast := '1';
184  -- Set the EOFE flag
185  ssiSetUserEofe(AXIS_CONFIG_G, v.master, '1');
186  -- Strobe the error flags
187  v.wordDropped := '1';
188  v.frameDropped := sAxisMaster.tLast;
189  -- Check for non-EOF
190  if (sAxisMaster.tLast = '0') then
191  -- Next state
192  v.state := BLOWOFF_S;
193  end if;
194  end if;
195  end if;
196  ----------------------------------------------------------------------
197  end case;
198 
199  -- Synchronous Reset
200  if (axisRst = '1') then
201  v := REG_INIT_C;
202  end if;
203 
204  -- Register the variable for next clock cycle
205  rin <= v;
206 
207  -- Outputs
208  sAxisSlave <= v.slave;
209  mAxisMaster <= r.master;
210  sAxisDropWrite <= r.wordDropped;
211  sAxisTermFrame <= r.frameDropped;
212 
213  end process comb;
214 
215  seq : process (axisClk) is
216  begin
217  if rising_edge(axisClk) then
218  r <= rin after TPD_G;
219  end if;
220  end process seq;
221 
222  end generate;
223 
224 end rtl;
_library_ ieeeieee
SLAVE_READY_EN_Gboolean := true
sl sof
Definition: SsiPkg.vhd:72
std_logic sl
Definition: StdRtlPkg.vhd:28
AXIS_CONFIG_GAxiStreamConfigType := ssiAxiStreamConfig( 16)
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
out sAxisCtrlAxiStreamCtrlType
out mAxisMasterAxiStreamMasterType
EN_FRAME_FILTER_Gboolean := true
AxiStreamSlaveType :=(tReady => '0') AXI_STREAM_SLAVE_INIT_C
in mAxisCtrlAxiStreamCtrlType
natural range 0 to 8 TUSER_BITS_C
slv( 7 downto 0) tDest
out sAxisSlaveAxiStreamSlaveType
in sAxisMasterAxiStreamMasterType
in mAxisSlaveAxiStreamSlaveType
std_logic_vector slv
Definition: StdRtlPkg.vhd:29