1 ------------------------------------------------------------------------------- 2 -- File : GLinkEncoder.vhd 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2012-04-19 5 -- Last update: 2017-05-05 6 ------------------------------------------------------------------------------- 7 -- Description: Encodes 16 bit data raw words into 20 bit GLink words. 8 ------------------------------------------------------------------------------- 9 -- This file is part of 'SLAC Firmware Standard Library'. 10 -- It is subject to the license terms in the LICENSE.txt file found in the 11 -- top-level directory of this distribution and at: 12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. 13 -- No part of 'SLAC Firmware Standard Library', including this file, 14 -- may be copied, modified, propagated, or distributed except according to 15 -- the terms contained in the LICENSE.txt file. 16 ------------------------------------------------------------------------------- 19 use ieee.std_logic_1164.
all;
26 --! @ingroup protocols_glink_core 32 FLAGSEL_G : := false);
43 function disparity (vec :
slv(
19 downto 0))
return is 44 variable onesCountVar : (4 downto 0);
45 variable disparityVar : (5 downto 0);
47 onesCountVar := onesCountU(vec);
48 disparityVar := (('0' & onesCountVar) - 10);
49 return disparityVar(4 downto 0);
52 type RegType is record 55 runningDisparity : (4 downto 0);
58 constant REG_INIT_C : RegType := ( 63 signal r : RegType := REG_INIT_C;
71 variable rawBufferflyVar : slv(0 to 15);
72 variable rawDisparityVar : (4 downto 0);
74 -- Latch the current value 77 -- Reverse the bit order 80 -- Check for idle or control 84 -- Check for flag select enabled 92 -- Check the toggle bit 93 if r.toggle = '1' then 105 -- Latch the reversed word 106 glinkWordVar.w := rawBufferflyVar;
108 -- Control overrides data assignments 110 glinkWordVar.w := rawBufferflyVar(0 to 6) & "01" & rawBufferflyVar(7 to 13);
113 -- Idle overrides control 118 -- Encode the G-Link word into an SLV 121 -- Calculate the disparity of the encoded word so far 124 -- Invert if necessary to reduce disparity 125 if (rawDisparityVar(4) = r.runningDisparity(4)) then 129 -- Normal data or control, invert everything 132 -- Calculated raw disparity must be (2's complement) inverted too 133 rawDisparityVar := (not rawDisparityVar) + 1;
136 -- Data now fully encoded. Calculate its disparity and add it to the running total 137 v.runningDisparity := r.runningDisparity + rawDisparityVar;
144 -- Register the variable for next clock cycle 152 seq :
process (
clk,
rst)
is 154 if rising_edge(clk) then 156 r <= rin after TPD_G;
159 -- Asynchronous Reset 161 r <= REG_INIT_C after TPD_G;
out encodedDataslv( 19 downto 0)
slv( 0 to 15) := X"FF00" GLINK_IDLE_WORD_FF0_C
RST_ASYNC_Gboolean := false
slv( 0 to 15) := X"FF80" GLINK_IDLE_WORD_FF1H_C
slv( 3 downto 0) := "1011" GLINK_DATA_WORD_FLAG_HIGH_C
slv( 3 downto 0) := "1101" GLINK_DATA_WORD_FLAG_LOW_C
slv( 0 to 15) := X"FE00" GLINK_IDLE_WORD_FF1L_C
slv( 3 downto 0) := "0011" GLINK_CONTROL_WORD_C
FLAGSEL_Gboolean := false