SURF  1.0
SsiPkg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SsiPkg.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-04-25
5 -- Last update: 2016-05-04
6 -------------------------------------------------------------------------------
7 -- Description: SSI Package File
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 -------------------------------------------------------------------------------
17 
18 library ieee;
19 use ieee.std_logic_1164.all;
20 use ieee.std_logic_unsigned.all;
21 use ieee.std_logic_arith.all;
22 
23 use work.StdRtlPkg.all;
24 use work.AxiStreamPkg.all;
25 
26 package SsiPkg is
27 --! @file
28  --! @ingroup protocols_ssi
29 
30  constant SSI_EOFE_C : integer := 0;
31  constant SSI_SOF_C : integer := 1;
32 
33  constant SSI_TUSER_BITS_C : integer := 2;
34  constant SSI_TDEST_BITS_C : integer := 4;
35  constant SSI_TID_BITS_C : integer := 0;
36  constant SSI_TSTRB_EN_C : boolean := false;
37 
39  tValid => '1', -- Force
40  tData => (others => '0'),
41  tStrb => (others => '1'),
42  tKeep => (others => '1'),
43  tLast => '1', -- EOF
44  tDest => (others => '0'),
45  tId => (others => '0'),
46  tUser => x"01010101010101010101010101010101"); -- EOFE
47 
48  -------------------------------------------------------------------------------------------------
49  -- Build an SSI configuration
50  -------------------------------------------------------------------------------------------------
51  function ssiAxiStreamConfig (
52  dataBytes : natural;
53  tKeepMode : TKeepModeType := TKEEP_COMP_C;
54  tUserMode : TUserModeType := TUSER_FIRST_LAST_C;
55  tDestBits : integer range 0 to 8 := 4;
56  tUserBits : integer range 2 to 8 := 2)
57  return AxiStreamConfigType;
58 
59  -- A default SSI config is useful to have
60  constant SSI_CONFIG_INIT_C : AxiStreamConfigType := ssiAxiStreamConfig(16);
61 
62  -------------------------------------------------------------------------------------------------
63  -- SSI Records and AXI-Stream conversion functions
64  -------------------------------------------------------------------------------------------------
65  type SsiMasterType is record
66  valid : sl;
67  data : slv(127 downto 0);
68  strb : slv(15 downto 0);
69  keep : slv(15 downto 0);
70  dest : slv(SSI_TDEST_BITS_C-1 downto 0);
72  sof : sl;
73  eof : sl;
74  eofe : sl;
75  end record SsiMasterType;
76 
77  type SsiSlaveType is record
78  ready : sl;
79  pause : sl;
81  end record SsiSlaveType;
82 
83  function ssi2AxisMaster (
84  axisConfig : AxiStreamConfigType;
85  ssiMaster : SsiMasterType)
86  return AxiStreamMasterType;
87 
88  function ssi2AxisSlave (
89  ssiSlave : SsiSlaveType)
90  return AxiStreamSlaveType;
91 
92  function ssi2AxisCtrl (
93  ssiSlave : SsiSlaveType)
94  return AxiStreamCtrlType;
95 
96  function axis2SsiMaster (
97  axisConfig : AxiStreamConfigType;
98  axisMaster : AxiStreamMasterType)
99  return SsiMasterType;
100 
101  function axis2SsiSlave (
102  axisConfig : AxiStreamConfigType;
105  return SsiSlaveType;
106 
107  function ssiMasterInit (
108  axisConfig : AxiStreamConfigType)
109  return SsiMasterType;
110 
111  function ssiSlaveInit (
112  axisConfig : AxiStreamConfigType)
113  return SsiSlaveType;
114 
115 -- constant SSI_MASTER_INIT_C : SsiMasterType := axis2SsiMaster(SSI_CONFIG_INIT_C, AXI_STREAM_MASTER_INIT_C);
116 -- constant SSI_SLAVE_INIT_C : SsiSlaveType := axis2SsiSlave(AXI_STREAM_SLAVE_INIT_C, AXI_STREAM_CTRL_UNUSED_C);
117 
118 
119  -------------------------------------------------------------------------------------------------
120  -- Functions to interpret TUSER bits
121  -------------------------------------------------------------------------------------------------
122  function ssiGetUserEofe (
123  axisConfig : AxiStreamConfigType;
124  axisMaster : AxiStreamMasterType)
125  return sl;
126 
127  procedure ssiSetUserEofe (
128  axisConfig : in AxiStreamConfigType;
129  axisMaster : inout AxiStreamMasterType;
130  eofe : in sl);
131 
132  function ssiGetUserSof (
133  axisConfig : AxiStreamConfigType;
134  axisMaster : AxiStreamMasterType)
135  return sl;
136 
137  procedure ssiSetUserSof (
138  axisConfig : in AxiStreamConfigType;
139  axisMaster : inout AxiStreamMasterType;
140  sof : in sl);
141 
142  procedure ssiResetFlags (
143  axisMaster : inout AxiStreamMasterType);
144 
145 end package SsiPkg;
146 
147 package body SsiPkg is
148 
150  dataBytes : natural;
151  tKeepMode : TKeepModeType := TKEEP_COMP_C;
152  tUserMode : TUserModeType := TUSER_FIRST_LAST_C;
153  tDestBits : integer range 0 to 8 := 4;
154  tUserBits : integer range 2 to 8 := 2)
155  return AxiStreamConfigType is
156  variable ret : AxiStreamConfigType;
157  begin
158  ret.TDATA_BYTES_C := dataBytes; -- Configurable data size
159  ret.TUSER_BITS_C := tUserBits; -- 2 TUSER: EOFE, SOF
160  ret.TDEST_BITS_C := tDestBits; -- 4 TDEST bits for VC
161  ret.TID_BITS_C := SSI_TID_BITS_C; -- TID not used
162  ret.TKEEP_MODE_C := tKeepMode; --
163  ret.TSTRB_EN_C := SSI_TSTRB_EN_C; -- No TSTRB support in SSI
164  ret.TUSER_MODE_C := tUserMode; -- User field valid on last only
165  return ret;
166  end function ssiAxiStreamConfig;
167 
168  function ssiGetUserEofe (
169  axisConfig : AxiStreamConfigType;
170  axisMaster : AxiStreamMasterType)
171  return sl is
172  variable ret : sl;
173  begin
174  ret := axiStreamGetUserBit(axisConfig, axisMaster, SSI_EOFE_C);
175  return ret;
176  end function;
177 
178  -------------------------------------------------------------------------------------------------
179  function ssi2AxisMaster (
180  axisConfig : AxiStreamConfigType;
181  ssiMaster : SsiMasterType)
182  return AxiStreamMasterType
183  is
184  variable ret : AxiStreamMasterType;
185  begin
187  ret.tValid := ssiMaster.valid;
188  ret.tData := ssiMaster.data;
189  ret.tLast := ssiMaster.eof;
190  ret.tStrb := ssiMaster.strb;
191  ret.tKeep := ssiMaster.keep;
192  ret.tDest(SSI_TDEST_BITS_C-1 downto 0) := ssiMaster.dest;
193  ssiSetUserSof(axisConfig, ret, ssiMaster.sof);
194  ssiSetUserEofe(axisConfig, ret, ssiMaster.eofe);
195  return ret;
196  end function ssi2AxisMaster;
197 
198  function ssi2AxisSlave (
199  ssiSlave : SsiSlaveType)
200  return AxiStreamSlaveType
201  is
202  variable ret : AxiStreamSlaveType;
203  begin
204  ret.tReady := ssiSlave.ready;
205  return ret;
206  end function ssi2AxisSlave;
207 
208  function ssi2AxisCtrl (
209  ssiSlave : SsiSlaveType)
210  return AxiStreamCtrlType
211  is
212  variable ret : AxiStreamCtrlType;
213  begin
214  ret.pause := ssiSlave.pause;
215  ret.overflow := ssiSlave.overflow;
216  return ret;
217  end function ssi2AxisCtrl;
218 
219  function axis2SsiMaster (
220  axisConfig : AxiStreamConfigType;
221  axisMaster : AxiStreamMasterType)
222  return SsiMasterType
223  is
224  variable ret : SsiMasterType;
225  begin
226  ret.valid := axisMaster.tValid;
227  ret.data := axisMaster.tData;
228  ret.strb := axisMaster.tStrb;
229  ret.keep := axisMaster.tKeep;
230  ret.packed := toSl(axiStreamPacked(axisConfig, axisMaster));
231  ret.dest := axisMaster.tDest(SSI_TDEST_BITS_C-1 downto 0);
232  ret.sof := ssiGetUserSof(axisConfig, axisMaster);
233  ret.eof := axisMaster.tLast;
234  ret.eofe := ssiGetUserEofe(axisConfig, axisMaster);
235  return ret;
236  end function axis2SsiMaster;
237 
238  function axis2SsiSlave (
239  axisConfig : AxiStreamConfigType;
242  return SsiSlaveType
243  is
244  variable ret : SsiSlaveType;
245  begin
246  ret.ready := axisSlave.tReady;
247  ret.pause := axisCtrl.pause;
248  ret.overflow := axisCtrl.overflow;
249  return ret;
250  end function axis2SsiSlave;
251 
252  function ssiMasterInit (
253  axisConfig : AxiStreamConfigType)
254  return SsiMasterType is
255  variable ret : SsiMasterType;
256  begin
257  ret := axis2ssiMaster(axisConfig, AXI_STREAM_MASTER_INIT_C);
258  ret.keep := genTKeep(axisConfig.TDATA_BYTES_C);
259  return ret;
260  end function ssiMasterInit;
261 
262  function ssiSlaveInit (
263  axisConfig : AxiStreamConfigType)
264  return SsiSlaveType is
265  begin
266  return axis2ssiSlave(axisConfig, AXI_STREAM_SLAVE_INIT_C, AXI_STREAM_CTRL_UNUSED_C);
267  end function ssiSlaveInit;
268 
269 
270  -------------------------------------------------------------------------------------------------
271  procedure ssiSetUserEofe (
272  axisConfig : in AxiStreamConfigType;
273  axisMaster : inout AxiStreamMasterType;
274  eofe : in sl) is
275  begin
276  axiStreamSetUserBit(axisConfig, axisMaster, SSI_EOFE_C, eofe);
277  end procedure;
278 
279  function ssiGetUserSof (
280  axisConfig : AxiStreamConfigType;
281  axisMaster : AxiStreamMasterType)
282  return sl is
283  variable ret : sl;
284  begin
285  ret := axiStreamGetUserBit(axisConfig, axisMaster, SSI_SOF_C, 0);
286  return ret;
287  end function;
288 
289  procedure ssiSetUserSof (
290  axisConfig : in AxiStreamConfigType;
291  axisMaster : inout AxiStreamMasterType;
292  sof : in sl) is
293  begin
294  axiStreamSetUserBit(axisConfig, axisMaster, SSI_SOF_C, sof, 0);
295  end procedure;
296 
297  procedure ssiResetFlags (
298  axisMaster : inout AxiStreamMasterType) is
299  begin
300  axisMaster.tValid := '0';
301  axisMaster.tLast := '0';
302  axisMaster.tUser := (others => '0');
303  end procedure;
304 
305 end package body SsiPkg;
slv( 127 downto 0) data
Definition: SsiPkg.vhd:67
slv( 7 downto 0) tId
natural range 0 to 8 TDEST_BITS_C
(TUSER_NORMAL_C,TUSER_FIRST_LAST_C,TUSER_LAST_C,TUSER_NONE_C) TUserModeType
ssiSetUserEofeaxisConfig,axisMaster,eofe,
Definition: SsiPkg.vhd:127
sl sof
Definition: SsiPkg.vhd:72
std_logic sl
Definition: StdRtlPkg.vhd:28
integer := 1 SSI_SOF_C
Definition: SsiPkg.vhd:31
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
AxiStreamMasterType ssi2AxisMasteraxisConfig,ssiMaster,
Definition: SsiPkg.vhd:83
sl eofe
Definition: SsiPkg.vhd:74
slv( 15 downto 0) tStrb
SsiMasterType ssiMasterInitaxisConfig,
Definition: SsiPkg.vhd:107
slv( 15 downto 0) strb
Definition: SsiPkg.vhd:68
slv( 15 downto 0) tKeep
natural range 1 to 16 TDATA_BYTES_C
sl ssiGetUserEofeaxisConfig,axisMaster,
Definition: SsiPkg.vhd:122
sl overflow
Definition: SsiPkg.vhd:80
TkeepModeType TKEEP_MODE_C
natural range 0 to 8 TID_BITS_C
slv( 127 downto 0) tData
integer := 0 SSI_TID_BITS_C
Definition: SsiPkg.vhd:35
_library_ ieeeieee
SsiMasterType
Definition: SsiPkg.vhd:65
SsiMasterType axis2SsiMasteraxisConfig,axisMaster,
Definition: SsiPkg.vhd:96
sl ssiGetUserSofaxisConfig,axisMaster,
Definition: SsiPkg.vhd:132
SsiSlaveType
Definition: SsiPkg.vhd:77
AxiStreamSlaveType :=(tReady => '0') AXI_STREAM_SLAVE_INIT_C
integer := 2 SSI_TUSER_BITS_C
Definition: SsiPkg.vhd:33
ssiSetUserSofaxisConfig,axisMaster,sof,
Definition: SsiPkg.vhd:137
boolean TSTRB_EN_C
TUserModeType TUSER_MODE_C
slv( 127 downto 0) tUser
boolean := false SSI_TSTRB_EN_C
Definition: SsiPkg.vhd:36
integer := 4 SSI_TDEST_BITS_C
Definition: SsiPkg.vhd:34
natural range 0 to 8 TUSER_BITS_C
sl valid
Definition: SsiPkg.vhd:66
AxiStreamSlaveType ssi2AxisSlavessiSlave,
Definition: SsiPkg.vhd:88
slv( SSI_TDEST_BITS_C- 1 downto 0) dest
Definition: SsiPkg.vhd:70
AxiStreamConfigType ssiAxiStreamConfigdataBytes,tKeepMode,tUserMode,tDestBits,tUserBits,
Definition: SsiPkg.vhd:51
AxiStreamConfigType := ssiAxiStreamConfig( 16) SSI_CONFIG_INIT_C
Definition: SsiPkg.vhd:60
AxiStreamCtrlType :=(pause => '0',overflow => '0',idle => '1') AXI_STREAM_CTRL_UNUSED_C
slv( 7 downto 0) tDest
AxiStreamMasterType :=(tValid => '1',tData =>( others => '0'),tStrb =>( others => '1'),tKeep =>( others => '1'),tLast => '1',tDest =>( others => '0'),tId =>( others => '0'),tUser => x"01010101010101010101010101010101") SSI_MASTER_FORCE_EOFE_C
Definition: SsiPkg.vhd:38
sl ready
Definition: SsiPkg.vhd:78
(TKEEP_NORMAL_C,TKEEP_COMP_C,TKEEP_FIXED_C) TKeepModeType
sl pause
Definition: SsiPkg.vhd:79
sl eof
Definition: SsiPkg.vhd:73
ssiResetFlagsaxisMaster,
Definition: SsiPkg.vhd:142
SsiSlaveType ssiSlaveInitaxisConfig,
Definition: SsiPkg.vhd:111
slv( 15 downto 0) keep
Definition: SsiPkg.vhd:69
sl packed
Definition: SsiPkg.vhd:71
AxiStreamCtrlType ssi2AxisCtrlssiSlave,
Definition: SsiPkg.vhd:92
SsiSlaveType axis2SsiSlaveaxisConfig,axisSlave,axisCtrl,
Definition: SsiPkg.vhd:101
std_logic_vector slv
Definition: StdRtlPkg.vhd:29