1 -------------------------------------------------------------------------------     3 -- Company    : SLAC National Accelerator Laboratory     4 -- Created    : 2015-08-09     5 -- Last update: 2015-08-09     6 -------------------------------------------------------------------------------     7 -- Description: Calculates and checks the RUDP packet checksum.     8 --              Checksum for IP/UDP/TCP/RUDP.     9 --              Works with 64-bit word         10 -------------------------------------------------------------------------------    11 -- This file is part of 'SLAC Firmware Standard Library'.    12 -- It is subject to the license terms in the LICENSE.txt file found in the     13 -- top-level directory of this distribution and at:     14 --    https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.     15 -- No part of 'SLAC Firmware Standard Library', including this file,     16 -- may be copied, modified, propagated, or distributed except according to     17 -- the terms contained in the LICENSE.txt file.    18 -------------------------------------------------------------------------------    21 use ieee.std_logic_1164.
all;
    22 use ieee.std_logic_unsigned.
all;
    23 use ieee.std_logic_arith.
all;
    28  --! @ingroup protocols_rssi    40       -- Enables and initializes the calculations.    41       -- enable_i <= '1' enables the calculation.    42       --                 the checksum value holds as long as enabled.    43       -- enable_i <= '0' initializes the calculation.    46       -- Has to indicate valid data and defines the number of calculation clock cycles.    49       -- Length of checksumed data    52       -- Initial value of the sum    53       -- Calculation: init_i = (others=>'0')    54       -- Validation:  init_i = Checksum value    57       -- Fixed to 2 octets (standard specification)    60       -- Direct out 1 c-c delay    63       -- Indicates when the module is ready and the checksum is valid    65       -- Indicates if the calculated checksum is ok (valid upon valid_o='1')    70 architecture rtl 
of Chksum is
    74    type RegType is record    81    constant REG_INIT_C : RegType := (    83       chksum   => (others=>'0'),    88    signal r   : RegType := REG_INIT_C;
    96    -- TODO make it generic    97    --data_i((CSUM_WIDTH_G-1)+(CSUM_WIDTH_G*I) downto CSUM_WIDTH_G*I);       98    s_dataWordSum <=   "00"& data_i(63 downto 48) +   106       variable v : RegType;
   110       -- Cumulative sum of the data_i while enabled   112          v.sum    := ("00000" & init_i);
   117          v.lenCnt := r.lenCnt;
   121          v.sum    := r.sum + s_dataWordSum;
   122          v.lenCnt := r.lenCnt +1;
   126          v.lenCnt := r.lenCnt;
   130       -- Add the sum carry bits   132       -- Add the checksum carry bit        135       -- Checksum output (calculated with 2 c-c delay towards data)   139       if (rst_i = '1') then   144       -----------------------------------------------------------   147    seq : 
process (
clk_i) 
is   149       if (rising_edge(clk_i)) then   150          r <= rin after TPD_G;
   153    ---------------------------------------------------------------------   156    check_o  <= '1' when (not r.chksum(CSUM_WIDTH_G-1 downto 0)) = (r.chksum'range => '0') else '0';
   157    ---------------------------------------------------------------------   158 end architecture rtl;
 CSUM_WIDTH_Gpositive  := 16
 
out chksum_oslv(   CSUM_WIDTH_G- 1 downto  0)  
 
DATA_WIDTH_Gpositive  := 64
 
in data_islv(   DATA_WIDTH_G- 1 downto  0)  
 
in init_islv(   CSUM_WIDTH_G- 1 downto  0)