1 ------------------------------------------------------------------------------- 2 -- File : JesdAlignFrRepCh.vhd 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2015-04-15 5 -- Last update: 2016-02-12 6 ------------------------------------------------------------------------------- 7 -- Description: Align bytes and replace control characters with data 10 -- Frame sizes 1, 2, 4 11 -- GT Word sizes 2, 4 <--- I don't think 2 word is supported because hard coded in Jesd204bPkg.vhd 14 -- dataRx_i - is little endian and byte-swapped (directly from GTH) 15 -- First sample in time: dataRx_i(7 downto 0) & dataRx_i(15 downto 8) 16 -- Second sample in time: dataRx_i(23 downto 16)& dataRx_i(31 downto 24) 18 -- sampleData_o is big endian and not byte-swapped 19 -- First sample in time: sampleData_o(31 downto 16) 20 -- Second sample in time: sampleData_o(15 downto 0) 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 ------------------------------------------------------------------------------- 32 use ieee.std_logic_1164.
all;
33 use ieee.std_logic_unsigned.
all;
34 use ieee.std_logic_arith.
all;
40 --! @ingroup protocols_jesd204b 45 -- Number of bytes in a frame 51 -- Enable character replacement 54 -- Enable scrambling/descrambling 57 -- One c-c long pulse from syncFSM indicating that first non K 58 -- character has been received 61 -- Data ready (replace control character with data when '1') 64 -- Data and character indication 68 -- Sample data output (after alignment, character replacement and scrambling) 72 -- Alignment and sync position errors 73 alignErr_o : out sl;
-- Invalid or misaligned character in the data 74 positionErr_o : out sl -- Invalid (comma) position received at time of alignment 76 end entity JesdAlignFrRepCh;
79 -- How many samples is in a GT word 82 type RegType is record 97 constant REG_INIT_C : RegType := ( 98 dataRxD1 => (others => '0'), 99 chariskRxD1 => (others => '0'), 100 dataAlignedD1 => (others => '0'), 101 charAlignedD1 => (others => '0'), 102 scrData => (others => '0'), 103 lfsr => (others => '0'), 104 descrData => (others => '0'), 106 sampleData => (others => '0'), 107 descrDataValid => '0', 109 position => intToSlv(1, GT_WORD_SIZE_C) -- Initialize at "0001" or "01" 112 signal r : RegType := REG_INIT_C;
113 signal rin : RegType;
117 -- Buffer two GT words (Sequential logic) 118 -- Register the alignment position when alignFrame_i pulse 119 -- Incorrect alignment (non valid data word received) will result in 120 -- v.position = (others => '1') 121 --------------------------------------------------------------------- 122 --------------------------------------------------------------------- 124 variable v : RegType;
126 -- Alignment error. Invalid data received at time of alignment 127 variable v_positionErr : sl;
128 variable v_alignErr : sl;
139 -- Buffer data and char one clock cycle 143 -- Buffer aligned data 144 v.dataAlignedD1 := v_dataAligned;
145 v.charAlignedD1 := v_charAligned;
147 -- Register the alignment 152 -- Align samples (Combinatorial logic) 154 -- Check position error (if position vector "1111" is returned) 155 v_positionErr := ite(allBits (r.position, '1'), '1', '0');
157 -- Byte swap and combine the two consecutive GT words 159 v_twoCharBuff := bitReverse(r.chariskRxD1) & bitReverse(chariskRx_i);
161 -- Align the bytes within the words 162 v_dataAligned := JesdDataAlign(v_twoWordBuff, r.position, GT_WORD_SIZE_C);
163 v_charAligned := JesdCharAlign(v_twoCharBuff, r.position, GT_WORD_SIZE_C);
165 -- Buffer aligned word and replace the alignment characters with the data 166 v_twoWordBuffAl := r.dataAlignedD1 & v_dataAligned;
167 v_twoCharBuffAl := r.charAlignedD1 & v_charAligned;
170 -- Replace the control characters in the data with valid data 172 for I in (SAMPLES_IN_WORD_C-1) downto 0 loop 173 -- If the A_CHAR_C or F_CHAR_C characters detected in the stream 174 if (v_twoCharBuffAl(I*F_G) = '1' and 178 -- If scrambling disabled 179 -- Replace the character in the data with the data value from previous frame 181 v_twoWordBuffAl((I*F_G*8+7) downto I*F_G*8) := v_twoWordBuffAl((I*F_G*8+8*F_G)+7 downto (I*F_G*8+8*F_G));
182 v_twoCharBuffAl(I*F_G) := '0';
183 -- If scrambling enabled 184 -- The data value equals char value and only the char flags are cleared 186 v_twoWordBuffAl := v_twoWordBuffAl;
187 v_twoCharBuffAl(I*F_G) := '0';
193 -- Check character if there are still characters in the data and issue the alignment error 194 -- The error indicates that the characters in the data are possibly misplaced or wrong characters 195 -- have been received. 198 if (v_twoCharBuffAl(I) = '1') then 204 -- Register data before scrambling 207 v.descrDataValid := r.scrDataValid;
209 -- Descramble data put data into descrambler MSB first 210 -- Start descrambling when data is enabled 211 if (scrEnable_i = '1' and r.scrDataValid = '1') then 213 v.lfsr := v.lfsr(v.lfsr'left-1 downto v.lfsr'right) & r.scrData(i);
215 v.descrData(i) := r.scrData(i);
222 v.descrData := r.scrData;
225 -- Register sample data before output (Prevent timing issues! Adds one clock cycle to latency!) 228 v.sampleData := r.descrData;
229 v.dataValid := r.descrDataValid;
248 ----------------------------------------------------------- 251 seq :
process (
clk)
is 253 if (rising_edge(clk)) then 254 r <= rin after TPD_G;
257 --------------------------------------------------------------------- 258 --------------------------------------------------------------------- 260 end architecture rtl;
in chariskRx_islv( GT_WORD_SIZE_C- 1 downto 0)
out sampleData_oslv(( GT_WORD_SIZE_C* 8)- 1 downto 0)
NaturalArray :=( 0=> 14, 1=> 15) JESD_PRBS_TAPS_C
slv( 7 downto 0) := x"7C" A_CHAR_C
positive := 4 GT_WORD_SIZE_C
in dataRx_islv(( GT_WORD_SIZE_C* 8)- 1 downto 0)
slv( 7 downto 0) := x"FC" F_CHAR_C