SURF  1.0
GLinkDecoder.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: 2015-12-07
6 -------------------------------------------------------------------------------
7 -- Description: Decoder for the Condition Inversion Master Transition coding
8 -- used by 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 use work.GlinkPkg.all;
25 
26 --! @see entity
27  --! @ingroup protocols_glink_core
28 entity GLinkDecoder is
29  generic (
30  TPD_G : time := 1 ns;
31  RST_ASYNC_G : boolean := false;
32  RST_POLARITY_G : sl := '1'; -- '1' for active HIGH reset, '0' for active LOW reset
33  FLAGSEL_G : boolean := false);
34  port (
35  en : in sl := '1';
36  clk : in sl;
37  rst : in sl;
38  gtRxData : in slv(19 downto 0);
39  rxReady : in sl;
40  txReady : in sl; -- TX Clock domain
41  gLinkRx : out GLinkRxType;
43  decoderErrorL : out sl);
44 end entity GLinkDecoder;
45 
46 architecture rtl of GLinkDecoder is
47 
48  type RegType is record
49  deglitch : slv(3 downto 0);
50  toggle : sl;
51  gLinkRx : GLinkRxType;
52  end record;
53 
54  constant REG_INIT_C : RegType := (
55  deglitch => (others => '0'),
56  toggle => '0',
57  gLinkRx => GLINK_RX_INIT_C);
58 
59  signal r : RegType := REG_INIT_C;
60  signal rin : RegType;
61 
62  signal txRdy : sl;
63 
64 begin
65 
66  Synchronizer_Inst : entity work.Synchronizer
67  generic map (
68  TPD_G => TPD_G,
71  port map (
72  clk => clk,
73  rst => rst,
74  dataIn => txReady,
75  dataOut => txRdy);
76 
77  comb : process (gtRxData, r, rst, rxReady, txRdy) is
78  variable v : RegType;
79  variable glinkWordVar : GLinkWordType;
80  begin
81  v := r;
82 
83  -- Shift Register
84  v.deglitch(3) := r.gLinkRx.error;
85  v.deglitch(2 downto 0) := r.deglitch(3 downto 1);
86 
87  -- Update the TX and RX MGT ready values
88  v.gLinkRx.rxReady := rxReady;
89  v.gLinkRx.txReady := txRdy;
90 
91  -- Reset strobe signals
92  v.gLinkRx.error := '0';
93  v.gLinkRx.isControl := '0';
94  v.gLinkRx.isIdle := '1';
95  v.gLinkRx.isData := '0';
96  v.gLinkRx.flag := '0';
97 
98  -- Convert input to GLinkWordType to use GLinkPkg functions for decoding
99  glinkWordVar := toGLinkWord(gtRxData);
100 
101  if (not isValidWord(glinkWordVar)) then
102  -- Invalid input, don't decode
103  v.gLinkRx.error := '1';
104  else
105  -- Valid input, decode the input
106  -- Check for control word
107  if (isControlWord(glinkWordVar)) then
108  -- Check for idle word (subcase of control word)
109  if (not isIdleWord(glinkWordVar)) then
110  v.gLinkRx.isIdle := '0';
111  v.gLinkRx.isControl := '1';
112  v.gLinkRx.data := getControlPayload(glinkWordVar);
113  end if;
114  end if;
115 
116  -- Check for data word
117  if (isDataWord(glinkWordVar)) then
118  -- Set the gLinkRx bus
119  v.gLinkRx.isIdle := '0';
120  v.gLinkRx.isData := '1';
121  v.gLinkRx.data := getDataPayload(gLinkWordVar); -- Bit flip done by function
122  v.gLinkRx.flag := getFlag(gLinkWordVar);
123  -- Check if FLAG is used for additional error checking
124  if FLAGSEL_G then
125  -- Set the flag
126  v.gLinkRx.linkUp := '1';
127  else
128  -- Check for first data frame
129  if r.gLinkRx.linkUp = '0' then
130  -- First frame Detected
131  v.gLinkRx.linkUp := '1';
132  -- Latch the flag value
133  v.toggle := getFlag(gLinkWordVar);
134  else
135  -- Check for flag error
136  if (r.toggle = getFlag(gLinkWordVar)) then
137  -- Invalid flag detected
138  v.gLinkRx.error := '1';
139  else
140  -- Latch the flag value
141  v.toggle := getFlag(gLinkWordVar);
142  end if;
143  end if;
144  end if;
145  end if;
146 
147  -- Invert if necessary
148  if (isInvertedWord(glinkWordVar)) then
149  v.gLinkRx.data := not v.gLinkRx.data;
150  end if;
151  end if;
152 
153  -- Synchronous Reset
154  if (RST_ASYNC_G = false and rst = RST_POLARITY_G) then
155  v := REG_INIT_C;
156  end if;
157 
158  -- Register the variable for next clock cycle
159  rin <= v;
160 
161  -- Outputs
162  gLinkRx <= r.gLinkRx;
163  decoderError <= uAnd(r.deglitch);
164  decoderErrorL <= not(uAnd(r.deglitch));
165 
166  end process comb;
167 
168  seq : process (clk, rst) is
169  begin
170  if rising_edge(clk) then
171  if en = '1' then
172  r <= rin after TPD_G;
173  end if;
174  end if;
175  -- Asynchronous Reset
176  if (RST_ASYNC_G and rst = RST_POLARITY_G) then
177  r <= REG_INIT_C after TPD_G;
178  end if;
179  end process seq;
180 
181 end architecture rtl;
std_logic sl
Definition: StdRtlPkg.vhd:28
in rstsl :=not RST_POLARITY_G
in gtRxDataslv( 19 downto 0)
out gLinkRxGLinkRxType
RST_POLARITY_Gsl := '1'
TPD_Gtime := 1 ns
out dataOutsl
RST_ASYNC_Gboolean := false
TPD_Gtime := 1 ns
out decoderErrorLsl
FLAGSEL_Gboolean := false
in ensl := '1'
RST_ASYNC_Gboolean := false
out decoderErrorsl
_library_ ieeeieee
RST_POLARITY_Gsl := '1'
std_logic_vector slv
Definition: StdRtlPkg.vhd:29