SURF  1.0
JesdRxLane.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : JesdRxLane.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-04-14
5 -- Last update: 2017-06-22
6 -------------------------------------------------------------------------------
7 -- Description: JesdRx single lane module
8 -- Receiver JESD204b standard.
9 -- Supports sub-class 1 deterministic latency.
10 -- Supports sub-class 0 non deterministic latency
11 -- Features:
12 -- - Comma synchronization
13 -- - Internal buffer to align the lanes.
14 -- - Sample data alignment (Sample extraction from GT word - barrel shifter).
15 -- - Alignment character replacement.
16 -- - Scrambling support
17 -- Status register encoding:
18 -- bit 0: GT Reset done
19 -- bit 1: Received data valid
20 -- bit 2: Received data is misaligned
21 -- bit 3: Synchronization output status
22 -- bit 4: Rx buffer overflow
23 -- bit 5: Rx buffer underflow
24 -- bit 6: Comma position not as expected during alignment
25 -- bit 7: RX module enabled status
26 -- bit 8: SysRef detected (active only when the lane is enabled)
27 -- bit 9: Comma (K28.5) detected
28 -- bit 10-13: Disparity error
29 -- bit 14-17: Not in table Error
30 -- bit 18-25: 8-bit buffer latency
31 -- bit 26: CDR Status of the GTH (Not used in yaml)
32 --
33 -- Note: sampleData_o is little endian and not byte swapped
34 -- First sample in time: sampleData_o(15 downto 0)
35 -- Second sample in time: sampleData_o(31 downto 16)
36 --
37 -- Note: The output ADC sample data can be inverted.
38 -- inv_i: '1' Inverted, '0' Normal
39 -- If inverted the mode can be chosen:
40 -- invMode_i: '1' Offset binary, '0' Twos complement
41 -------------------------------------------------------------------------------
42 -- This file is part of 'SLAC Firmware Standard Library'.
43 -- It is subject to the license terms in the LICENSE.txt file found in the
44 -- top-level directory of this distribution and at:
45 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
46 -- No part of 'SLAC Firmware Standard Library', including this file,
47 -- may be copied, modified, propagated, or distributed except according to
48 -- the terms contained in the LICENSE.txt file.
49 -------------------------------------------------------------------------------
50 
51 library ieee;
52 use ieee.std_logic_1164.all;
53 use ieee.std_logic_arith.all;
54 use ieee.std_logic_unsigned.all;
55 
56 use work.StdRtlPkg.all;
57 use work.Jesd204bPkg.all;
58 
59 --! @see entity
60  --! @ingroup protocols_jesd204b
61 entity JesdRxLane is
62  generic (
63  TPD_G : time := 1 ns;
64 
65  -- Number of bytes in a frame
66  F_G : positive := 2;
67 
68  -- Number of frames in a multi frame
69  K_G : positive := 32
70  );
71  port (
72 
73  -- JESD
74  -- Clocks and Resets
75  devClk_i : in sl;
76  devRst_i : in sl;
77 
78  -- JESD subclass selection: '0' or '1'(default)
79  subClass_i : in sl;
80 
81  -- SYSREF for subclass 1 fixed latency
82  sysRef_i : in sl;
83 
84  -- Clear registered errors
85  clearErr_i : in sl;
86 
87  -- Control register
88  enable_i : in sl;
91  status_o : out slv((RX_STAT_WIDTH_C)-1 downto 0);
92 
93  -- Data and character inputs from GT (transceivers)
95 
96  -- Local multi frame clock
97  lmfc_i : in sl;
98 
99  -- Error mask
100  linkErrMask_i : in slv(5 downto 0) := (others => '1');
101 
102  -- One or more RX modules requested synchronization
105 
106  -- Invert ADC data
107  inv_i : in sl := '0';
108 
109  -- Synchronization request output
110  nSync_o : out sl;
111 
112  -- Synchronization process is complete and data is valid
114  sampleData_o : out slv((GT_WORD_SIZE_C*8)-1 downto 0)
115  );
116 end JesdRxLane;
117 
118 
119 architecture rtl of JesdRxLane is
120 
121  constant ERR_REG_WIDTH_C : positive := 4+2*GT_WORD_SIZE_C;
122 
123 -- Register
124  type RegType is record
125  bufWeD1 : sl;
126  errReg : slv(ERR_REG_WIDTH_C-1 downto 0);
127  sampleData : slv(sampleData_o'range);
128  sampleDataValid : sl;
129  jesdGtRx : jesdGtRxLaneType;
130  end record RegType;
131 
132  constant REG_INIT_C : RegType := (
133  bufWeD1 => '0',
134  errReg => (others => '0'),
135  sampleData => (others => '0'),
136  sampleDataValid => '0',
137  jesdGtRx => JESD_GT_RX_LANE_INIT_C
138  );
139 
140  signal r : RegType := REG_INIT_C;
141  signal rin : RegType;
142 
143  -- Internal signals
144 
145  -- Control signals from FSM
146  signal s_nSync : sl;
147  signal s_readBuff : sl;
148  signal s_alignFrame : sl;
149  signal s_ila : sl;
150  signal s_dataValid : sl;
151 
152  -- Buffer control
153  signal s_bufRst : sl;
154  signal s_bufWe : sl;
155  signal s_bufRe : sl;
156 
157  -- Datapath
158  signal s_charAndData : slv(((GT_WORD_SIZE_C*8)+GT_WORD_SIZE_C)-1 downto 0);
159  signal s_charAndDataBuff : slv(s_charAndData'range);
160  signal s_sampleData : slv(sampleData_o'range);
161  signal s_sampleDataValid : sl;
162 
163  -- Statuses
164  signal s_bufOvf : sl;
165  signal s_bufUnf : sl;
166  signal s_bufFull : sl;
167  signal s_alignErr : sl;
168  signal s_positionErr : sl;
169  signal s_linkErrVec : slv(5 downto 0);
170  signal s_linkErr : sl;
171  signal s_kDetected : sl;
172  signal s_refDetected : sl;
173  signal s_errComb : slv(ERR_REG_WIDTH_C-1 downto 0);
174  signal s_buffLatency : slv(7 downto 0);
175 
176 begin
177 
178  s_charAndData <= r.jesdGtRx.dataK & r.jesdGtRx.data;
179 
180  -- Buffer control
181  s_bufRst <= devRst_i or not s_nSync or not enable_i;
182  s_bufWe <= not s_bufRst and not s_bufFull;
183  s_bufRe <= r.bufWeD1 and s_readBuff;
184 
185  -- Buffer samples between first data and LMFC
186  -- Min size one LMFC period
187  RX_buffer_fifo_INST : entity work.FifoSync
188  generic map (
189  TPD_G => TPD_G,
190  RST_POLARITY_G => '1',
191  RST_ASYNC_G => false,
192  BRAM_EN_G => true,
193  FWFT_EN_G => false,
194  USE_DSP48_G => "no",
195  ALTERA_SYN_G => false,
196  ALTERA_RAM_G => "M9K",
197  PIPE_STAGES_G => 0,
198  DATA_WIDTH_G => (GT_WORD_SIZE_C*8) + GT_WORD_SIZE_C,
199  -- ADDR_WIDTH_G => bitSize((K_G * F_G)/GT_WORD_SIZE_C),
200  ADDR_WIDTH_G => 8,
201  INIT_G => "0",
202  FULL_THRES_G => 1,
203  EMPTY_THRES_G => 1)
204  port map (
205  rst => s_bufRst,
206  clk => devClk_i,
207  wr_en => s_bufWe, -- Always write when enabled
208  rd_en => s_bufRe, -- Hold read while sync not in sync with LMFC
209  din => s_charAndData,
210  dout => s_charAndDataBuff,
211  data_count => s_buffLatency,
212  wr_ack => open,
213  valid => open,
214  overflow => s_bufOvf,
215  underflow => s_bufUnf,
216  prog_full => open,
217  prog_empty => open,
218  almost_full => open,
219  almost_empty => open,
220  full => s_bufFull,
221  not_full => open,
222  empty => open
223  );
224 
225  -- Synchronization FSM
226  syncFSM_INST : entity work.JesdSyncFsmRx
227  generic map (
228  TPD_G => TPD_G,
229  F_G => F_G,
230  K_G => K_G)
231  port map (
232  clk => devClk_i,
233  rst => devRst_i,
234  enable_i => enable_i,
235  sysRef_i => sysRef_i,
236  dataRx_i => r.jesdGtRx.data,
237  chariskRx_i => r.jesdGtRx.dataK,
238  gtReady_i => r.jesdGtRx.rstDone,
239  lmfc_i => lmfc_i,
242  linkErr_i => s_linkErr,
243  nSync_o => s_nSync,
244  readBuff_o => s_readBuff,
245  -- buffLatency_o => s_buffLatency,
246  alignFrame_o => s_alignFrame,
247  ila_o => s_ila,
248  kDetected_o => s_kDetected,
249  sysref_o => s_refDetected,
250  dataValid_o => s_dataValid,
252  );
253 
254  -- Align the rx data within the GT word and replace the characters.
255  alignFrRepCh_INST : entity work.JesdAlignFrRepCh
256  generic map (
257  TPD_G => TPD_G,
258  F_G => F_G)
259  port map (
260  clk => devClk_i,
261  rst => devRst_i,
262  replEnable_i => replenable_i,
264  alignFrame_i => s_alignFrame,
265  dataValid_i => s_dataValid,
266  dataRx_i => s_charAndDataBuff((GT_WORD_SIZE_C*8)-1 downto 0),
267  chariskRx_i => s_charAndDataBuff(((GT_WORD_SIZE_C*8)+GT_WORD_SIZE_C)-1 downto (GT_WORD_SIZE_C*8)),
268  sampleDataValid_o => s_sampleDataValid,
269  sampleData_o => s_sampleData,
270  alignErr_o => s_alignErr,
271  positionErr_o => s_positionErr
272  );
273 
274  process(devClk_i)
275  begin
276  if rising_edge(devClk_i) then
277 
278  -- Link error masked by the mask from register and ORed
279  s_linkErrVec <= s_positionErr & s_bufOvf & s_bufUnf & uOr(r.jesdGtRx.dispErr) & uOr(r.jesdGtRx.decErr) & s_alignErr after TPD_G;
280  s_linkErr <= uOr(s_linkErrVec and linkErrMask_i) and enable_i after TPD_G;
281 
282  -- Combine errors that need registering
283  s_errComb <= r.jesdGtRx.decErr & r.jesdGtRx.dispErr & s_alignErr & s_positionErr & s_bufOvf & s_bufUnf after TPD_G;
284 
285  end if;
286  end process;
287 
288  -- Synchronous process function:
289  -- - Registering of errors
290  -- - Delay the s_bufWe to use it for s_bufRe
291  -- - Inverting ADC data
292  -------------------------------------------------------------------------------
293  -------------------------------------------------------------------------------
294  comb : process (clearErr_i, devRst_i, enable_i, inv_i, r, r_jesdGtRx,
295  s_bufWe, s_errComb, s_nSync, s_sampleData,
296  s_sampleDataValid) is
297  variable v : RegType;
298  begin
299  v := r;
300 
301  v.jesdGtRx := r_jesdGtRx;
302  v.bufWeD1 := s_bufWe;
303 
304  -- Register errors (store until reset)
305  if (r.jesdGtRx.rstDone = '1' and s_nSync = '1') then
306  for I in 0 to(ERR_REG_WIDTH_C-1) loop
307  if (s_errComb(I) = '1') and (enable_i = '1') then
308  v.errReg(I) := '1';
309  end if;
310  end loop;
311  end if;
312 
313  -- Clear registered errors if module is disabled
314  if (clearErr_i = '1') then
315  v.errReg := REG_INIT_C.errReg;
316  end if;
317 
318  -- Invert sample data
319  v.sampleDataValid := s_sampleDataValid;
320 
321  if (inv_i = '1') then
322  -- Invert sample data
323  v.sampleData := invData(s_sampleData, F_G, GT_WORD_SIZE_C);
324  else
325  v.sampleData := s_sampleData;
326  end if;
327 
328  -- Reset registers
329  if (devRst_i = '1') then
330  v := REG_INIT_C;
331  end if;
332 
333  rin <= v;
334  end process comb;
335 
336  seq : process (devClk_i) is
337  begin
338  if (rising_edge(devClk_i)) then
339  r <= rin after TPD_G;
340  end if;
341  end process seq;
342 
343  -- Output assignment
344  nSync_o <= s_nSync;
345  dataValid_o <= r.sampleDataValid;
346  sampleData_o <= endianSwapSlv(r.sampleData, GT_WORD_SIZE_C);
347  status_o <= r.jesdGtRx.cdrStable & s_buffLatency & r.errReg(r.errReg'high downto 4) & s_kDetected & s_refDetected & enable_i & r.errReg(2 downto 0) & s_nSync & r.errReg(3) & s_dataValid & r.jesdGtRx.rstDone;
348 -----------------------------------------------------------------------------------------
349 end rtl;
ADDR_WIDTH_Ginteger range 4 to 48:= 4
Definition: FifoSync.vhd:40
USE_DSP48_Gstring := "no"
Definition: FifoSync.vhd:35
in devClk_isl
Definition: JesdRxLane.vhd:75
in wr_ensl
Definition: FifoSync.vhd:47
F_Gpositive := 2
in chariskRx_islv( GT_WORD_SIZE_C- 1 downto 0)
out prog_emptysl
Definition: FifoSync.vhd:57
in rstsl :=not RST_POLARITY_G
Definition: FifoSync.vhd:45
std_logic sl
Definition: StdRtlPkg.vhd:28
BRAM_EN_Gboolean := true
Definition: FifoSync.vhd:32
in subClass_isl
Definition: JesdRxLane.vhd:79
out prog_fullsl
Definition: FifoSync.vhd:56
slv( GT_WORD_SIZE_C- 1 downto 0) dataK
Definition: Jesd204bPkg.vhd:63
out overflowsl
Definition: FifoSync.vhd:54
out validsl
Definition: FifoSync.vhd:53
positive := 19+ 2* GT_WORD_SIZE_C RX_STAT_WIDTH_C
Definition: Jesd204bPkg.vhd:45
out data_countslv( ADDR_WIDTH_G- 1 downto 0)
Definition: FifoSync.vhd:51
PIPE_STAGES_Gnatural range 0 to 16:= 0
Definition: FifoSync.vhd:38
in dataRx_islv(( GT_WORD_SIZE_C* 8)- 1 downto 0)
out almost_emptysl
Definition: FifoSync.vhd:59
TPD_Gtime := 1 ns
Definition: FifoSync.vhd:29
in r_jesdGtRxjesdGtRxLaneType
Definition: JesdRxLane.vhd:94
out sampleData_oslv(( GT_WORD_SIZE_C* 8)- 1 downto 0)
ALTERA_RAM_Gstring := "M9K"
Definition: FifoSync.vhd:37
in nSyncAny_isl
Definition: JesdRxLane.vhd:103
K_Gpositive := 32
in clearErr_isl
Definition: JesdRxLane.vhd:85
DATA_WIDTH_Ginteger range 1 to ( 2** 24):= 16
Definition: FifoSync.vhd:39
in dinslv( DATA_WIDTH_G- 1 downto 0)
Definition: FifoSync.vhd:49
RST_POLARITY_Gsl := '1'
Definition: FifoSync.vhd:30
out emptysl
Definition: FifoSync.vhd:62
FULL_THRES_Ginteger range 1 to ( 2** 24):= 1
Definition: FifoSync.vhd:42
out dataValid_osl
Definition: JesdRxLane.vhd:113
slv( GT_WORD_SIZE_C- 1 downto 0) dispErr
Definition: Jesd204bPkg.vhd:64
out underflowsl
Definition: FifoSync.vhd:55
positive := 4 GT_WORD_SIZE_C
Definition: Jesd204bPkg.vhd:31
out alignFrame_osl
TPD_Gtime := 1 ns
Definition: JesdRxLane.vhd:63
F_Gpositive := 2
Definition: JesdRxLane.vhd:66
in devRst_isl
Definition: JesdRxLane.vhd:76
in replEnable_isl
Definition: JesdRxLane.vhd:89
in scrEnable_isl
Definition: JesdRxLane.vhd:90
out doutslv( DATA_WIDTH_G- 1 downto 0)
Definition: FifoSync.vhd:50
in dataRx_islv(( GT_WORD_SIZE_C* 8)- 1 downto 0)
in clksl
Definition: FifoSync.vhd:46
in rd_ensl
Definition: FifoSync.vhd:48
ALTERA_SYN_Gboolean := false
Definition: FifoSync.vhd:36
in sysRef_isl
Definition: JesdRxLane.vhd:82
out kDetected_osl
out sampleData_oslv(( GT_WORD_SIZE_C* 8)- 1 downto 0)
Definition: JesdRxLane.vhd:115
out almost_fullsl
Definition: FifoSync.vhd:58
RST_ASYNC_Gboolean := false
Definition: FifoSync.vhd:31
out status_oslv(( RX_STAT_WIDTH_C)- 1 downto 0)
Definition: JesdRxLane.vhd:91
jesdGtRxLaneType :=(data =>( others => '0'),dataK =>( others => '0'),dispErr =>( others => '0'),decErr =>( others => '0'),rstDone => '0',cdrStable => '0') JESD_GT_RX_LANE_INIT_C
Definition: Jesd204bPkg.vhd:70
in linkErrMask_islv( 5 downto 0) :=( others => '1')
Definition: JesdRxLane.vhd:100
out nSync_osl
Definition: JesdRxLane.vhd:110
FWFT_EN_Gboolean := false
Definition: FifoSync.vhd:34
out wr_acksl
Definition: FifoSync.vhd:52
in nSyncAnyD1_isl
Definition: JesdRxLane.vhd:104
in enable_isl
Definition: JesdRxLane.vhd:88
in lmfc_isl
Definition: JesdRxLane.vhd:97
out not_fullsl
Definition: FifoSync.vhd:61
slv( GT_WORD_SIZE_C- 1 downto 0) decErr
Definition: Jesd204bPkg.vhd:65
_library_ ieeeieee
Definition: JesdLmfcGen.vhd:25
in inv_isl := '0'
Definition: JesdRxLane.vhd:107
INIT_Gslv := "0"
Definition: FifoSync.vhd:41
EMPTY_THRES_Ginteger range 1 to ( 2** 24):= 1
Definition: FifoSync.vhd:43
out fullsl
Definition: FifoSync.vhd:60
slv(( GT_WORD_SIZE_C* 8)- 1 downto 0) data
Definition: Jesd204bPkg.vhd:62
in chariskRx_islv( GT_WORD_SIZE_C- 1 downto 0)
K_Gpositive := 32
Definition: JesdRxLane.vhd:70
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
TPD_Gtime := 1 ns