SURF  1.0
SspDeframer.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SspDeframer.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-07-14
5 -- Last update: 2017-05-01
6 -------------------------------------------------------------------------------
7 -- Description: SimpleStreamingProtocol - A simple protocol layer for inserting
8 -- idle and framing control characters into a raw data stream. The input of
9 -- module should be attached to an 8b10b decoder.
10 -------------------------------------------------------------------------------
11 -- This file is part of 'SLAC Firmware Standard Library'.
12 -- It is subject to the license terms in the LICENSE.txt file found in the
13 -- top-level directory of this distribution and at:
14 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
15 -- No part of 'SLAC Firmware Standard Library', including this file,
16 -- may be copied, modified, propagated, or distributed except according to
17 -- the terms contained in the LICENSE.txt file.
18 -------------------------------------------------------------------------------
19 
20 library ieee;
21 use ieee.std_logic_1164.all;
22 use IEEE.STD_LOGIC_UNSIGNED.all;
23 use IEEE.STD_LOGIC_ARITH.all;
24 
25 use work.StdRtlPkg.all;
26 
27 --! @see entity
28  --! @ingroup protocols_ssp
29 entity SspDeframer is
30 
31  generic (
32  TPD_G : time := 1 ns;
33  RST_POLARITY_G : sl := '0';
34  RST_ASYNC_G : boolean := true;
35  WORD_SIZE_G : integer := 16;
36  K_SIZE_G : integer := 2;
43  port (
44  clk : in sl;
46  dataKIn : in slv(K_SIZE_G-1 downto 0);
47  dataIn : in slv(WORD_SIZE_G-1 downto 0);
48  validIn : in sl;
49  decErrIn : in sl := '0';
50  dataOut : out slv(WORD_SIZE_G-1 downto 0);
51  validOut : out sl;
52  sof : out sl;
53  eof : out sl;
54  eofe : out sl);
55 
56 
57 end entity SspDeframer;
58 
59 architecture rtl of SspDeframer is
60 
61  constant WAIT_SOF_S : sl := '0';
62  constant WAIT_EOF_S : sl := '1';
63 
64  type RegType is record
65  state : sl;
66 
67  -- Internal
68  iDataOut : slv(WORD_SIZE_G-1 downto 0);
69  iValidOut : sl;
70  iSof : sl;
71  iEof : sl;
72  iEofe : sl;
73 
74  -- Output registers
75  dataOut : slv(WORD_SIZE_G-1 downto 0);
76  validOut : sl;
77  sof : sl;
78  eof : sl;
79  eofe : sl;
80 
81  end record RegType;
82 
83  constant REG_INIT_C : RegType := (
84  state => WAIT_SOF_S,
85  iDataOut => (others => '0'),
86  iValidOut => '0',
87  iSof => '0',
88  iEof => '0',
89  iEofe => '0',
90  dataOut => (others => '0'),
91  validOut => '0',
92  sof => '0',
93  eof => '0',
94  eofe => '0');
95 
96  signal r : RegType := REG_INIT_C;
97  signal rin : RegType;
98 
99 begin
100 
101  comb : process (dataIn, dataKin, decErrIn, r, rst, validIn) is
102  variable v : RegType;
103  begin
104  v := r;
105 
106 -- v.iDataOut := dataIn;
107 -- v.iValidOut := '0';
108 
109  if (validIn = '1') then
110 
111  if (r.state = WAIT_SOF_S) then
112 
113  v.iSof := '0';
114  v.iEof := '0';
115  v.iEofe := '0';
116 
117  if (dataKin /= slvZero(K_SIZE_G) and decErrIn = '0') then
118 
119  if (dataKIn = SSP_IDLE_K_G) and (dataIn = SSP_IDLE_CODE_G) then
120  -- Ignore idle codes
121  v.iSof := '0';
122  v.iEof := '0';
123  v.iEofe := '0';
124  v.iValidOut := '0';
125 
126  elsif (dataKIn = SSP_SOF_K_G) and (dataIn = SSP_SOF_CODE_G) then
127  -- Correct SOF
128  v.iSof := '1';
129  v.iValidOut := '0';
130  v.state := WAIT_EOF_S;
131 
132  else
133  -- Invalid K Code
134  v.iEof := '1';
135  v.iEofe := '1';
136  v.iValidOut := '1';
137  end if;
138  end if;
139 
140  elsif (r.state = WAIT_EOF_S) then
141 
142  -- Expect data to come
143  -- Will be overridden if IDLE char seen
144  v.iValidOut := '1';
145  v.iDataOut := dataIn;
146 
147  -- sof is asserted without valid in previous state
148  -- Hold it until the first data arrives
149  if (r.iValidOut = '1') then
150  v.iSof := '0';
151  end if;
152 
153 
154  if (dataKin /= slvZero(K_SIZE_G)) then
155 
156  if (dataKin = SSP_EOF_K_G and dataIn = SSP_EOF_CODE_G) then
157  v.iEof := '1';
158  v.iValidOut := '0';
159  v.state := WAIT_SOF_S;
160 
161  elsif (dataKIn = SSP_IDLE_K_G and dataIn = SSP_IDLE_CODE_G) then
162  -- Ignore idle codes that arrive mid frame
163  v.iValidOut := '0';
164 
165  else
166  -- Unknown and/or incorrect K CODE
167  v.iValidOut := '0';
168  v.iEof := '1';
169  v.iEofe := '1';
170  v.state := WAIT_SOF_S;
171  end if;
172 
173  end if;
174 
175  if (decErrIn = '1') then
176  v.iEofe := '1';
177  end if;
178 
179  end if;
180 
181  end if;
182 
183  ----------------------------------------------------------------------------------------------
184  -- Delay buffer to output SOF on first valid and EOF/EOFE on last valid
185  ----------------------------------------------------------------------------------------------
186  v.validOut := '0';
187  if ((v.iValidOut = '1' or v.iEof = '1') and r.iValidOut = '1') then
188  -- If new data arrived an existing data is waiting,
189  -- Advance the pipeline and output the waiting data
190  v.validOut := validIn;
191  v.sof := r.iSof;
192  v.eof := v.iEof;
193  v.eofe := v.iEofe;
194  v.dataOut := r.iDataOut;
195  end if;
196 
197  if (RST_ASYNC_G = false and rst = RST_POLARITY_G) then
198  v := REG_INIT_C;
199  end if;
200 
201  rin <= v;
202  dataOut <= r.dataOut;
203  validOut <= r.validOut;
204  sof <= r.sof;
205  eof <= r.eof;
206  eofe <= r.eofe;
207 
208  end process comb;
209 
210  -- Sequential process
211  seq : process (clk, rst) is
212  begin
213  if (RST_ASYNC_G = true and rst = RST_POLARITY_G) then
214  r <= REG_INIT_C after TPD_G;
215  elsif (rising_edge(clk)) then
216  r <= rin after TPD_G;
217  end if;
218  end process seq;
219 
220 end architecture rtl;
out sofsl
Definition: SspDeframer.vhd:52
out dataOutslv( WORD_SIZE_G- 1 downto 0)
Definition: SspDeframer.vhd:50
in validInsl
Definition: SspDeframer.vhd:48
std_logic sl
Definition: StdRtlPkg.vhd:28
_library_ IEEEIEEE
Definition: StdRtlPkg.vhd:18
WORD_SIZE_Ginteger := 16
Definition: SspDeframer.vhd:35
RST_ASYNC_Gboolean := true
Definition: SspDeframer.vhd:34
TPD_Gtime := 1 ns
Definition: SspDeframer.vhd:32
in decErrInsl := '0'
Definition: SspDeframer.vhd:49
RST_POLARITY_Gsl := '0'
Definition: SspDeframer.vhd:33
K_SIZE_Ginteger := 2
Definition: SspDeframer.vhd:36
out eofsl
Definition: SspDeframer.vhd:53
_library_ ieeeieee
in rstsl := RST_POLARITY_G
Definition: SspDeframer.vhd:45
out eofesl
Definition: SspDeframer.vhd:54
SSP_EOF_CODE_Gslv
Definition: SspDeframer.vhd:41
in dataKInslv( K_SIZE_G- 1 downto 0)
Definition: SspDeframer.vhd:46
SSP_SOF_CODE_Gslv
Definition: SspDeframer.vhd:39
out validOutsl
Definition: SspDeframer.vhd:51
SSP_IDLE_K_Gslv
Definition: SspDeframer.vhd:38
SSP_IDLE_CODE_Gslv
Definition: SspDeframer.vhd:37
in dataInslv( WORD_SIZE_G- 1 downto 0)
Definition: SspDeframer.vhd:47
std_logic_vector slv
Definition: StdRtlPkg.vhd:29