SURF  1.0
SspFramer.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SspFramer.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 output of
9 -- module should be attached to an 8b10b encoder.
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 SspFramer is
30 
31  generic (
32  TPD_G : time := 1 ns;
33  RST_POLARITY_G : sl := '0';
34  RST_ASYNC_G : boolean := true;
35  AUTO_FRAME_G : boolean := true;
36  FLOW_CTRL_EN_G : boolean := false;
37  WORD_SIZE_G : integer := 16;
38  K_SIZE_G : integer := 2;
45 
46  port (
47  clk : in sl;
49  validIn : in sl;
50  readyIn : out sl;
51  dataIn : in slv(WORD_SIZE_G-1 downto 0);
52  sof : in sl := '0';
53  eof : in sl := '0';
54  validOut : out sl;
55  readyOut : in sl := '1';
56  dataOut : out slv(WORD_SIZE_G-1 downto 0);
57  dataKOut : out slv(K_SIZE_G-1 downto 0));
58 
59 end entity SspFramer;
60 
61 architecture rtl of SspFramer is
62 
63  constant IDLE_MODE_C : sl := '0';
64  constant DATA_MODE_C : sl := '1';
65 
66  type RegType is record
67  readyIn : sl;
68  validOut : sl;
69  mode : sl;
70  eofLast : sl;
71  eof : sl;
72  dataInLast : slv(WORD_SIZE_G-1 downto 0);
73  validInLast : sl;
74  dataOut : slv(WORD_SIZE_G-1 downto 0);
75  dataKOut : slv(K_SIZE_G-1 downto 0);
76  end record RegType;
77 
78  constant REG_INIT_C : RegType := (
79  readyIn => '0',
80  validOut => toSl(not FLOW_CTRL_EN_G),
81  mode => '0',
82  eofLast => '0',
83  eof => '0',
84  dataInLast => (others => '0'),
85  validInLast => '0',
86  dataKOut => (others => '0'),
87  dataOut => (others => '0'));
88 
89  signal r : RegType := REG_INIT_C;
90  signal rin : RegType;
91 
92 begin
93 
94  comb : process (dataIn, eof, r, readyOut, rst, sof, validIn) is
95  variable v : RegType;
96  begin
97  v := r;
98 
99  v.readyIn := readyOut;
100 
101  if (readyOut = '1' and FLOW_CTRL_EN_G) then
102  v.validOut := '0';
103  end if;
104 
105  if (v.validOut = '0' or FLOW_CTRL_EN_G = false) then
106  v.validOut := '1';
107  v.dataInLast := dataIn;
108  v.validInLast := validIn;
109  v.eofLast := eof;
110 
111  -- Send commas while waiting for valid, then send SOF
112  if (r.mode = IDLE_MODE_C) then
114  v.dataKOut := SSP_IDLE_K_G;
115  if (validIn = '1' and (sof = '1' or AUTO_FRAME_G)) then
116  v.dataOut := SSP_SOF_CODE_G;
117  v.dataKOut := SSP_SOF_K_G;
118  v.mode := DATA_MODE_C;
119  end if;
120 
121  -- Send pipline delayed data, send eof when delayed valid falls
122  elsif (r.mode = DATA_MODE_C) then
123  v.dataOut := r.dataInLast;
124  v.dataKOut := slvZero(K_SIZE_G);
125  v.eof := r.validInLast and r.eofLast;
126  if (r.validInLast = '0') then
127  if (AUTO_FRAME_G or r.eof = '1') then
128  v.dataOut := SSP_EOF_CODE_G;
129  v.dataKOut := SSP_EOF_K_G;
130  v.mode := IDLE_MODE_C;
131  else
132  -- if not auto framing and valid drops, insert idle char
134  v.dataKOut := SSP_EOF_K_G;
135  end if;
136  end if;
137 
138  end if;
139 
140  if (RST_ASYNC_G = false and rst = RST_POLARITY_G) then
141  v := REG_INIT_C;
142  end if;
143 
144  end if;
145 
146  rin <= v;
147  dataOut <= r.dataOut;
148  dataKOut <= r.dataKOut;
149  validOut <= r.validOut;
150  readyIn <= v.readyIn;
151 
152  end process comb;
153 
154  -- Sequential process
155  seq : process (clk, rst) is
156  begin
157  if (RST_ASYNC_G = true and rst = RST_POLARITY_G) then
158  r <= REG_INIT_C after TPD_G;
159  elsif (rising_edge(clk)) then
160  r <= rin after TPD_G;
161  end if;
162  end process seq;
163 
164 end architecture rtl;
SSP_SOF_K_Gslv
Definition: SspFramer.vhd:42
in validInsl
Definition: SspFramer.vhd:49
RST_POLARITY_Gsl := '0'
Definition: SspFramer.vhd:33
in rstsl := RST_POLARITY_G
Definition: SspFramer.vhd:48
SSP_EOF_CODE_Gslv
Definition: SspFramer.vhd:43
SSP_SOF_CODE_Gslv
Definition: SspFramer.vhd:41
out readyInsl
Definition: SspFramer.vhd:50
std_logic sl
Definition: StdRtlPkg.vhd:28
in dataInslv( WORD_SIZE_G- 1 downto 0)
Definition: SspFramer.vhd:51
_library_ IEEEIEEE
Definition: StdRtlPkg.vhd:18
in eofsl := '0'
Definition: SspFramer.vhd:53
SSP_EOF_K_Gslv
Definition: SspFramer.vhd:44
SSP_IDLE_K_Gslv
Definition: SspFramer.vhd:40
_library_ ieeeieee
out dataKOutslv( K_SIZE_G- 1 downto 0)
Definition: SspFramer.vhd:57
out dataOutslv( WORD_SIZE_G- 1 downto 0)
Definition: SspFramer.vhd:56
FLOW_CTRL_EN_Gboolean := false
Definition: SspFramer.vhd:36
RST_ASYNC_Gboolean := true
Definition: SspFramer.vhd:34
in sofsl := '0'
Definition: SspFramer.vhd:52
out validOutsl
Definition: SspFramer.vhd:54
AUTO_FRAME_Gboolean := true
Definition: SspFramer.vhd:35
SSP_IDLE_CODE_Gslv
Definition: SspFramer.vhd:39
in readyOutsl := '1'
Definition: SspFramer.vhd:55
TPD_Gtime := 1 ns
Definition: SspFramer.vhd:32
WORD_SIZE_Ginteger := 16
Definition: SspFramer.vhd:37
K_SIZE_Ginteger := 2
Definition: SspFramer.vhd:38
in clksl
Definition: SspFramer.vhd:47
std_logic_vector slv
Definition: StdRtlPkg.vhd:29