SURF  1.0
JesdAlignChGen.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : JesdAlignChGen.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-04-15
5 -- Last update: 2016-02-22
6 -------------------------------------------------------------------------------
7 -- Description: Alignment character generator
8 -- Scrambles incoming data if enabled
9 -- Inverts incoming data if enabled
10 --
11 -- Replaces data with F and A characters.
12 -- A(K28.3) - x"7C" - Inserted at the end of a multi-frame.
13 -- F(K28.7) - x"FC" - Inserted at the end of a frame.
14 --
15 -- Note: Character replacement mechanism is different weather scrambler is enabled or disabled.
16 -- Disabled: The characters are inserted if two corresponding octets in consecutive samples have the same value.
17 -- Enabled: The characters are inserted it the corresponding octet has the same value as the inserted character.
18 --
19 -- 3 c-c data latency
20 --
21 -------------------------------------------------------------------------------
22 -- This file is part of 'SLAC Firmware Standard Library'.
23 -- It is subject to the license terms in the LICENSE.txt file found in the
24 -- top-level directory of this distribution and at:
25 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
26 -- No part of 'SLAC Firmware Standard Library', including this file,
27 -- may be copied, modified, propagated, or distributed except according to
28 -- the terms contained in the LICENSE.txt file.
29 -------------------------------------------------------------------------------
30 
31 library ieee;
32 use ieee.std_logic_1164.all;
33 use ieee.std_logic_unsigned.all;
34 use ieee.std_logic_arith.all;
35 
36 use work.StdRtlPkg.all;
37 use work.jesd204bpkg.all;
38 
39 --! @see entity
40  --! @ingroup protocols_jesd204b
41 entity JesdAlignChGen is
42  generic (
43  TPD_G : time := 1 ns;
44  F_G : positive := 2);
45  port (
46  clk : in sl;
47  rst : in sl;
48 
49  -- Enable counter
50  enable_i : in sl;
51 
52  -- Enable scrambling/descrambling
54 
55  -- Local multi clock
56  lmfc_i : in sl;
57 
58  -- Valid data from Tx FSM
60 
61  -- Invert ADC data
62  inv_i : in sl:='0';
63 
64  --
65  sampleData_i : in slv(GT_WORD_SIZE_C*8-1 downto 0);
66 
67  -- Outs
68  sampleData_o : out slv(GT_WORD_SIZE_C*8-1 downto 0);
69  sampleK_o : out slv(GT_WORD_SIZE_C-1 downto 0)
70  );
71 end entity JesdAlignChGen;
72 
73 architecture rtl of JesdAlignChGen is
74 
75  -- How many samples is in a GT word
76  constant SAMPLES_IN_WORD_C : positive := (GT_WORD_SIZE_C/F_G);
77 
78  -- Register type
79  type RegType is record
80  sampleDataReg : slv(sampleData_o'range);
81  sampleDataInv : slv(sampleData_o'range);
82  sampleDataD1 : slv(sampleData_o'range);
83  sampleDataD2 : slv(sampleData_o'range);
84  sampleKD1 : slv(sampleK_o'range);
85  lfsr : slv(sampleData_o'range);
86  lmfcD1 : sl;
87  end record RegType;
88 
89  constant REG_INIT_C : RegType := (
90  sampleDataReg => (others => '0'),
91  sampleDataInv => (others => '0'),
92  sampleDataD1 => (others => '0'),
93  sampleDataD2 => (others => '0'),
94  sampleKD1 => (others => '0'),
95  lfsr => (others => '0'),
96  lmfcD1 => '0'
97  );
98 
99  signal r : RegType := REG_INIT_C;
100  signal rin : RegType;
101 
102 --
103 begin
104 
105 
106  comb : process (r, rst, sampleData_i, dataValid_i, enable_i, lmfc_i, scrEnable_i,
107  inv_i) is
108  variable v : RegType;
109  variable v_sampleData : slv(sampleData_o'range);
110  variable v_sampleK : slv(sampleK_o'range);
111 
112  variable v_twoWordBuff : slv((2*GT_WORD_SIZE_C*8)-1 downto 0);
113  variable v_twoCharBuff : slv((2*GT_WORD_SIZE_C) -1 downto 0);
114  begin
115  v := r;
116 
117  -- Register data
118  v.sampleDataReg := sampleData_i;
119 
120  -- Invert Data if enabled
121  if (inv_i = '1') then
122  -- Invert sample data
123  v.sampleDataInv := invData(r.sampleDataReg, F_G, GT_WORD_SIZE_C);
124  else
125  v.sampleDataInv := r.sampleDataReg;
126  end if;
127 
128  -- Scramble Data if enabled
129  if scrEnable_i = '1' then
130  for i in (GT_WORD_SIZE_C*8)-1 downto 0 loop
131  v.sampleDataD1(i) := r.sampleDataInv(i);
132  for j in JESD_PRBS_TAPS_C'range loop
133  v.sampleDataD1(i) := v.sampleDataD1(i) xor v.lfsr(JESD_PRBS_TAPS_C(j)-1);
134  end loop;
135  v.lfsr := v.lfsr((GT_WORD_SIZE_C*8)-2 downto 0) & v.sampleDataD1(i);
136  end loop;
137  else
138  -- Use the data from the input if scrambling disabled
139  v.sampleDataD1 := r.sampleDataInv;
140  end if;
141 
142 
143  -- Buffer data for two clock cycles
144  v.sampleDataD2 := r.sampleDataD1;
145 
146  -- Delay LMFC for 1 c-c
147  v.lmfcD1 := lmfc_i;
148 
149  -- Combinatorial logic
150  v_twoWordBuff := r.sampleDataD2 & r.sampleDataD1;
151  v_twoCharBuff := r.sampleKD1 & (sampleK_o'range => '0');
152 
153  --
154  if enable_i = '1' and dataValid_i = '1' then
155  -- Replace with A character at the end of the multi-frame
156  if r.lmfcD1 = '1' then
157  if scrEnable_i = '1' then
158  if (v_twoWordBuff(7 downto 0) = A_CHAR_C) then
159  v_twoCharBuff(0) := '1';
160  end if;
161  else
162  if (v_twoWordBuff((F_G*8)+7 downto (F_G*8)) = v_twoWordBuff(7 downto 0)) then
163  v_twoWordBuff(7 downto 0) := A_CHAR_C;
164  v_twoCharBuff(0) := '1';
165  end if;
166  end if;
167  end if;
168 
169  -- Replace with F character
170  for I in (SAMPLES_IN_WORD_C-1) downto 0 loop
171  if scrEnable_i = '1' then
172  if (v_twoWordBuff((I*F_G*8)+7 downto (I*F_G*8)) = F_CHAR_C and
173  v_twoCharBuff((I*F_G+F_G)) = '0')
174  then
175  v_twoCharBuff(I*F_G) := '1';
176  end if;
177  else
178  if (v_twoWordBuff((I*F_G*8)+(F_G*8)+7 downto (I*F_G*8)+(F_G*8)) = v_twoWordBuff((I*F_G*8)+7 downto (I*F_G*8)) and
179  v_twoCharBuff((I*F_G+F_G)) = '0')
180  then
181  v_twoWordBuff((I*F_G*8)+7 downto (I*F_G*8)) := F_CHAR_C;
182  v_twoCharBuff(I*F_G) := '1';
183  end if;
184  end if;
185  end loop;
186  end if;
187 
188  if (rst = '1') then
189  v := REG_INIT_C;
190  end if;
191 
192  -- Buffer char for one clock cycle
193  v.sampleKD1 := v_twoCharBuff((GT_WORD_SIZE_C)-1 downto 0);
194 
195  rin <= v;
196 
197  -- Output assignment
198  sampleData_o <= byteSwapSlv(v_twoWordBuff((GT_WORD_SIZE_C*8)-1 downto 0), GT_WORD_SIZE_C);
199  sampleK_o <= bitReverse(v_twoCharBuff((GT_WORD_SIZE_C)-1 downto 0));
200 
201  end process comb;
202 
203  seq : process (clk) is
204  begin
205  if (rising_edge(clk)) then
206  r <= rin after TPD_G;
207  end if;
208  end process seq;
209 ---------------------------------------
210 
211 
212 end architecture rtl;
_library_ ieeeieee
std_logic sl
Definition: StdRtlPkg.vhd:28
F_Gpositive := 2
in sampleData_islv( GT_WORD_SIZE_C* 8- 1 downto 0)
out sampleData_oslv( GT_WORD_SIZE_C* 8- 1 downto 0)
in inv_isl := '0'
out sampleK_oslv( GT_WORD_SIZE_C- 1 downto 0)
TPD_Gtime := 1 ns
std_logic_vector slv
Definition: StdRtlPkg.vhd:29