SURF  1.0
GLinkPkg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : GlinkDecoder.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2012-03-12
5 -- Last update: 2014-10-24
6 -------------------------------------------------------------------------------
7 -- Description: A collection of common constants and functions intended for
8 -- use encoding/decoding the GLink Protocol.
9 -------------------------------------------------------------------------------
10 -- This file is part of 'SLAC Firmware Standard Library'.
11 -- It is subject to the license terms in the LICENSE.txt file found in the
12 -- top-level directory of this distribution and at:
13 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
14 -- No part of 'SLAC Firmware Standard Library', including this file,
15 -- may be copied, modified, propagated, or distributed except according to
16 -- the terms contained in the LICENSE.txt file.
17 -------------------------------------------------------------------------------
18 
19 library ieee;
20 use ieee.std_logic_1164.all;
21 use ieee.numeric_std.all;
22 
23 use work.StdRtlPkg.all;
24 
25 package GLinkPkg is
26 --! @file
27  --! @ingroup protocols_glink_core
28 
29  type GLinkTxType is record
30  idle : sl;
32  flag : sl;
33  data : slv(15 downto 0);
35  end record;
36  type GLinkTxArray is array (natural range <>) of GLinkTxType;
37  type GLinkTxVectorArray is array (natural range<>, natural range<>) of GLinkTxType;
38  constant GLINK_TX_INIT_C : GLinkTxType := (
39  idle => '1',
40  control => '0',
41  flag => '0',
42  data => (others => '0'),
43  linkRst => '1');
45  idle => '1',
46  control => '0',
47  flag => '0',
48  data => (others => '0'),
49  linkRst => '0');
50  function toSlv (vec : GLinkTxType) return slv;
51  function toGLinkTx (vec : slv(19 downto 0)) return GLinkTxType;
52 
53  type GLinkRxType is record
57  flag : sl;
58  data : slv(15 downto 0);
59  -- Link Status Signals
60  error : sl;
64  end record;
65  type GLinkRxArray is array (natural range <>) of GLinkRxType;
66  type GLinkRxVectorArray is array (natural range<>, natural range<>) of GLinkRxType;
67  constant GLINK_RX_INIT_C : GLinkRxType := (
68  isIdle => '1',
69  isData => '0',
70  isControl => '0',
71  flag => '0',
72  data => (others => '0'),
73  -- Link Status Signals
74  error => '0',
75  rxReady => '0',
76  txReady => '0',
77  linkUp => '0');
78  function toSlv (vec : GLinkRxType) return slv;
79  function toGLinkRx (vec : slv(23 downto 0)) return GLinkRxType;
80 
81  -- Valid C Field values
82  constant GLINK_CONTROL_WORD_C : slv(3 downto 0) := "0011";
83  constant GLINK_CONTROL_WORD_INV_C : slv(3 downto 0) := "1100";
84  constant GLINK_DATA_WORD_FLAG_LOW_C : slv(3 downto 0) := "1101";
85  constant GLINK_DATA_WORD_INV_FLAG_LOW_C : slv(3 downto 0) := "0010";
86  constant GLINK_DATA_WORD_FLAG_HIGH_C : slv(3 downto 0) := "1011";
87  constant GLINK_DATA_WORD_INV_FLAG_HIGH_C : slv(3 downto 0) := "0100";
88 
89  -- Array of valid C Fields
90  type GLinkSlv4Array is array (natural range <>) of slv(3 downto 0);
91 
92  constant GLINK_VALID_C_FIELDS_C : GLinkSlv4Array(0 to 5) := (
99 
100  -- Valid idle (fill) words
101  constant GLINK_IDLE_WORD_FF0_C : slv(0 to 15) := X"FF00";
102  constant GLINK_IDLE_WORD_FF1L_C : slv(0 to 15) := X"FE00";
103  constant GLINK_IDLE_WORD_FF1H_C : slv(0 to 15) := X"FF80";
104 
105  -- Array of valid idle words
106  type GLinkSlv16Array is array (natural range <>) of slv(0 to 15);
107 
112 
113  -- GLink Word structure
114  -- Contains 16 bit W-Field (data) and 4 bit C-Field (control)
116  record
117  w : slv(0 to 15); -- W-Field
118  c : slv(3 downto 0); -- C-Field
119  end record;
120 
121  -- Array of GLink words (I really hate that VHDL makes you do this)
122  type GLinkWordArray is array (natural range <>) of GLinkWordType;
123 
124  -- Functions for working with GLinkWordType
125  function toGLinkWord(data : slv(19 downto 0)) return GLinkWordType;
126  function toSlv (word : GLinkWordType) return slv;
127  function isValidWord (word : GLinkWordType) return boolean;
128  function isControlWord (word : GLinkWordType) return boolean;
129  function isIdleWord (word : GLinkWordType) return boolean;
130  function isDataWord (word : GLinkWordType) return boolean;
131  function isInvertedWord (word : GLinkWordType) return boolean;
132  function getControlPayload (word : GLinkWordType) return slv;
133  function getDataPayload(word : GLinkWordType) return slv;
134  function getFlag(word : GLinkWordType) return sl;
135 
136 end package GLinkPkg;
137 
138 package body GLinkPkg is
139 
140  function toSlv (vec : GLinkTxType) return slv is
141  variable retVar : slv(19 downto 0) := (others => '0');
142  begin
143  retVar(19) := vec.idle;
144  retVar(18) := vec.control;
145  retVar(17) := vec.flag;
146  retVar(16) := vec.linkRst;
147  retVar(15 downto 0) := vec.data(15 downto 0);
148  return retVar;
149  end function;
150 
151  function toGLinkTx (vec : slv(19 downto 0)) return GLinkTxType is
152  variable retVar : GLinkTxType;
153  begin
154  retVar.idle := vec(19);
155  retVar.control := vec(18);
156  retVar.flag := vec(17);
157  retVar.linkRst := vec(16);
158  retVar.data(15 downto 0) := vec(15 downto 0);
159  return retVar;
160  end function;
161 
162  function toSlv (vec : GLinkRxType) return slv is
163  variable retVar : slv(23 downto 0) := (others => '0');
164  begin
165  retVar(23) := vec.isIdle;
166  retVar(22) := vec.isData;
167  retVar(21) := vec.isControl;
168  retVar(20) := vec.flag;
169  retVar(19) := vec.error;
170  retVar(18) := vec.rxReady;
171  retVar(17) := vec.txReady;
172  retVar(16) := vec.linkUp;
173  retVar(15 downto 0) := vec.data(15 downto 0);
174  return retVar;
175  end function;
176 
177  function toGLinkRx (vec : slv(23 downto 0)) return GLinkRxType is
178  variable retVar : GLinkRxType;
179  begin
180  retVar.isIdle := vec(23);
181  retVar.isData := vec(22);
182  retVar.isControl := vec(21);
183  retVar.flag := vec(20);
184  retVar.error := vec(19);
185  retVar.rxReady := vec(18);
186  retVar.txReady := vec(17);
187  retVar.linkUp := vec(16);
188  retVar.data(15 downto 0) := vec(15 downto 0);
189  return retVar;
190  end function;
191 
192  function toGLinkWord (
193  data : slv(19 downto 0))
194  return GLinkWordType
195  is
196  variable retVar : GLinkWordType;
197  begin
198  retVar.w := data(19 downto 4);
199  retVar.c := data(3 downto 0);
200  return retVar;
201  end function;
202 
203  function toSlv (
204  word : GLinkWordType)
205  return slv
206  is
207  variable retVar : slv(19 downto 0);
208  begin
209  retVar(19 downto 4) := word.w;
210  retVar(3 downto 0) := word.c;
211  return retVar;
212  end function;
213 
214  -----------------------------------------------------------------------------
215  -- Test if a word is valid.
216  -- Detectable error states listed on page 23 of HDMP-1032A/1034A Data Sheet
217  -----------------------------------------------------------------------------
218  function isValidWord (
219  word : GLinkWordType)
220  return boolean
221  is
222  variable validVar : boolean := true;
223  begin
224  if (std_match(word.c, "-00-") or
225  std_match(word.c, "-11-") or
226  std_match(word.c, "0101") or
227  std_match(word.c, "1010")) then
228  validVar := false;
229  elsif word.c = "1100" then --check for invalid Filled frames
230  if (std_match(word.w, "-------0--------") or
231  std_match(word.w, "-------11-------")) then
232  validVar := false;
233  end if;
234  end if;
235  return validVar;
236  end function isValidWord;
237 
239  -- we might want to add a 01/10 check in the isControlWord function,
240  -- instead on relying on the isValidWord function (LLR - 26FEB2014) function isControlWord (
241  word : GLinkWordType)
242  return boolean
243  is
244  variable retVar : boolean := false;
245  begin
246  if (word.c = GLINK_CONTROL_WORD_C or word.c = GLINK_CONTROL_WORD_INV_C) then
247  retVar := true;
248  end if;
249  return retVar;
250  end function isControlWord;
251 
252  function isIdleWord (
253  word : GLinkWordType)
254  return boolean
255  is
256  variable retVar : boolean := false;
257  begin
258  if (word.c = GLINK_CONTROL_WORD_C) then
259  for i in GLINK_VALID_IDLE_WORDS_C'range loop
260  if (word.w = GLINK_VALID_IDLE_WORDS_C(i)) then
261  retVar := true;
262  end if;
263  end loop; -- i
264  end if;
265  return retVar;
266  end function;
267 
268  function isDataWord (
269  word : GLinkWordType)
270  return boolean
271  is
272  variable retVar : boolean := false;
273  begin
274  if (word.c = GLINK_DATA_WORD_FLAG_LOW_C or
278  retVar := true;
279  end if;
280  return retVar;
281  end function isDataWord;
282 
283  function isInvertedWord (
284  word : GLinkWordType)
285  return boolean
286  is
287  variable retVar : boolean := false;
288  begin
289  if (word.c = GLINK_DATA_WORD_INV_FLAG_LOW_C or
291  word.c = GLINK_CONTROL_WORD_INV_C) then
292  retVar := true;
293  end if;
294  return retVar;
295  end function isInvertedWord;
296 
297  function getControlPayload (
298  word : GLinkWordType)
299  return slv
300  is
301  variable retVar : slv(15 downto 0);
302  begin
303  retVar(6 downto 0) := bitReverse(word.w(0 to 6));
304  retVar(13 downto 7) := bitReverse(word.w(9 to 15));
305  retVar(15 downto 14) := word.w(7 to 8); -- actually don't care
306  return retVar;
307  end function;
308 
309  function getDataPayload(
310  word : GLinkWordType)
311  return slv
312  is
313  begin
314  return bitReverse(word.w);
315  end function;
316 
317  function getFlag(
318  word : GLinkWordType)
319  return sl
320  is
321  begin
322  if (word.c = GLINK_DATA_WORD_FLAG_HIGH_C or
324  return '1';
325  else
326  return '0';
327  end if;
328  end function;
329 
330 end package body GLinkPkg;
array(natural range <> ) of GLinkTxType GLinkTxArray
Definition: GLinkPkg.vhd:36
sl txReady
Definition: GLinkPkg.vhd:62
slv( 0 to 15) := X"FF00" GLINK_IDLE_WORD_FF0_C
Definition: GLinkPkg.vhd:101
array(natural range <> ) of GLinkWordType GLinkWordArray
Definition: GLinkPkg.vhd:122
array(natural range <> ,natural range <> ) of GLinkRxType GLinkRxVectorArray
Definition: GLinkPkg.vhd:66
std_logic sl
Definition: StdRtlPkg.vhd:28
GLinkTxType toGLinkTxvec,
Definition: GLinkPkg.vhd:51
GLinkSlv16Array( 0 to 2) :=( GLINK_IDLE_WORD_FF0_C, GLINK_IDLE_WORD_FF1L_C, GLINK_IDLE_WORD_FF1H_C) GLINK_VALID_IDLE_WORDS_C
Definition: GLinkPkg.vhd:108
_library_ ieeeieee
array(natural range <> ,natural range <> ) of GLinkTxType GLinkTxVectorArray
Definition: GLinkPkg.vhd:37
GLinkRxType toGLinkRxvec,
Definition: GLinkPkg.vhd:79
slv( 0 to 15) := X"FF80" GLINK_IDLE_WORD_FF1H_C
Definition: GLinkPkg.vhd:103
array(natural range <> ) of GLinkRxType GLinkRxArray
Definition: GLinkPkg.vhd:65
slv( 3 downto 0) := "1011" GLINK_DATA_WORD_FLAG_HIGH_C
Definition: GLinkPkg.vhd:86
sl isData
Definition: GLinkPkg.vhd:55
array(natural range <> ) of slv( 0 to 15) GLinkSlv16Array
Definition: GLinkPkg.vhd:106
array(natural range <> ) of slv( 3 downto 0) GLinkSlv4Array
Definition: GLinkPkg.vhd:90
boolean isDataWordword,
Definition: GLinkPkg.vhd:130
slv toSlvvec,
Definition: GLinkPkg.vhd:50
sl linkUp
Definition: GLinkPkg.vhd:63
slv( 3 downto 0) := "1101" GLINK_DATA_WORD_FLAG_LOW_C
Definition: GLinkPkg.vhd:84
sl getFlagword,
Definition: GLinkPkg.vhd:134
slv getControlPayloadword,
Definition: GLinkPkg.vhd:132
sl error
Definition: GLinkPkg.vhd:60
boolean isValidWordword,
Definition: GLinkPkg.vhd:127
GLinkRxType :=(isIdle => '1',isData => '0',isControl => '0',flag => '0',data =>( others => '0'),error => '0',rxReady => '0',txReady => '0',linkUp => '0') GLINK_RX_INIT_C
Definition: GLinkPkg.vhd:67
GLinkTxType :=(idle => '1',control => '0',flag => '0',data =>( others => '0'),linkRst => '1') GLINK_TX_INIT_C
Definition: GLinkPkg.vhd:38
slv getDataPayloadword,
Definition: GLinkPkg.vhd:133
slv( 15 downto 0) data
Definition: GLinkPkg.vhd:33
slv( 3 downto 0) := "0100" GLINK_DATA_WORD_INV_FLAG_HIGH_C
Definition: GLinkPkg.vhd:87
slv( 0 to 15) := X"FE00" GLINK_IDLE_WORD_FF1L_C
Definition: GLinkPkg.vhd:102
boolean isInvertedWordword,
Definition: GLinkPkg.vhd:131
slv( 3 downto 0) := "0011" GLINK_CONTROL_WORD_C
Definition: GLinkPkg.vhd:82
slv( 3 downto 0) := "1100" GLINK_CONTROL_WORD_INV_C
Definition: GLinkPkg.vhd:83
GLinkSlv4Array( 0 to 5) :=( GLINK_CONTROL_WORD_C, GLINK_CONTROL_WORD_INV_C, GLINK_DATA_WORD_FLAG_LOW_C, GLINK_DATA_WORD_INV_FLAG_LOW_C, GLINK_DATA_WORD_FLAG_HIGH_C, GLINK_DATA_WORD_INV_FLAG_HIGH_C) GLINK_VALID_C_FIELDS_C
Definition: GLinkPkg.vhd:92
sl linkRst
Definition: GLinkPkg.vhd:34
GLinkWordType toGLinkWorddata,
Definition: GLinkPkg.vhd:125
sl rxReady
Definition: GLinkPkg.vhd:61
boolean isControlWordword,
Definition: GLinkPkg.vhd:128
sl isIdle
Definition: GLinkPkg.vhd:54
sl isControl
Definition: GLinkPkg.vhd:56
sl idle
Definition: GLinkPkg.vhd:30
slv( 0 to 15) w
Definition: GLinkPkg.vhd:117
slv( 3 downto 0) c
Definition: GLinkPkg.vhd:118
boolean isIdleWordword,
Definition: GLinkPkg.vhd:129
sl flag
Definition: GLinkPkg.vhd:32
GLinkTxType :=(idle => '1',control => '0',flag => '0',data =>( others => '0'),linkRst => '0') GLINK_TX_UNUSED_C
Definition: GLinkPkg.vhd:44
slv( 3 downto 0) := "0010" GLINK_DATA_WORD_INV_FLAG_LOW_C
Definition: GLinkPkg.vhd:85
sl control
Definition: GLinkPkg.vhd:31
std_logic_vector slv
Definition: StdRtlPkg.vhd:29