www.pudn.com > rs3228v11tar.gz > rs_pkg.vhd, change:1998-10-01,size:12755b


-----------------------------------------------------------------
-- model:     PACKAGE rs_pkg
-- copyright: Christian Schuler, GMD-FOKUS, 12/2/1998
--
--
-- description:
--  package for rs(32,28)-gf(256) decoder
--  generated by code generator genfec
--
-- modified:
--   1.10.98 exemplar library eliminated (functions int2suv, suv2int used)
--
-----------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

PACKAGE rs_pkg IS

  CONSTANT mm        : INTEGER := 8;   -- symbol size
  CONSTANT no_p      : INTEGER := 4;   -- number of parity symbols
  CONSTANT tt        : INTEGER := 2;   -- number of correctable symbols
  CONSTANT nn        : INTEGER := 32;   -- RS block length
  CONSTANT kk        : INTEGER := 28;   -- information symbols
  CONSTANT addr_width: INTEGER := 5;   -- max. mm, less for shortened codes

  -- used in euclid:
  TYPE poly_type IS ARRAY (0 TO no_p-1) OF STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);

  CONSTANT deg_sigma: INTEGER := tt;
  -- degree of omega is one less than degree of sigma:
  CONSTANT deg_omega: INTEGER := deg_sigma-1;

  
  CONSTANT alpha_0: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0) := (OTHERS => '0');
  CONSTANT alpha_1: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0) := "00000001";

  TYPE tv_type IS ARRAY (0 TO nn-1) OF STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);

  -- code word memory:
  COMPONENT sram_word
  PORT(
    di    : IN  STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
    a     : IN  STD_ULOGIC_VECTOR(addr_width-1 DOWNTO 0);
    wr_en : IN  STD_ULOGIC;    
    wr_clk: IN  STD_ULOGIC;    
    do    : OUT STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)
    );    
  END COMPONENT;


  -- sigma memory: (used in omcalc)
  CONSTANT sigma_addr_w: INTEGER := 2;
  COMPONENT sram_sigma
  PORT(
    di    : IN  STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
    a     : IN  STD_ULOGIC_VECTOR(sigma_addr_w-1 DOWNTO 0);
    wr_en : IN  STD_ULOGIC;    
    wr_clk: IN  STD_ULOGIC;    
    do    : OUT STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)
    );    
  END COMPONENT;


  -- syndrome memory: (used in euclid)
  CONSTANT synd_addr_w: INTEGER := 2;
  COMPONENT sram_synd
  PORT(
    di    : IN  STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
    a     : IN  STD_ULOGIC_VECTOR(synd_addr_w-1 DOWNTO 0);
    wr_en : IN  STD_ULOGIC;    
    wr_clk: IN  STD_ULOGIC;    
    do    : OUT STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)
    );    
  END COMPONENT;

  -- function prototypes:
  FUNCTION gf_mul_1 (bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)) RETURN STD_ULOGIC_VECTOR; 
  FUNCTION gf_mul_2 (bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)) RETURN STD_ULOGIC_VECTOR; 
  FUNCTION gf_mul_3 (bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)) RETURN STD_ULOGIC_VECTOR; 
  FUNCTION gf_mul_4 (bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)) RETURN STD_ULOGIC_VECTOR; 

  FUNCTION gf_mul_223 (bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)) RETURN STD_ULOGIC_VECTOR; 
  FUNCTION gf_mul_191 (bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)) RETURN STD_ULOGIC_VECTOR; 
  FUNCTION gf_mul_159 (bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)) RETURN STD_ULOGIC_VECTOR; 

  FUNCTION gf256_pow2 (aa: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0)) RETURN STD_ULOGIC_VECTOR;

  FUNCTION gf256_mul ( 
    aa: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
    bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR;
 
  FUNCTION int2suv (l: INTEGER; size: INTEGER := 32) RETURN STD_ULOGIC_VECTOR;
  FUNCTION suv2int (l: STD_ULOGIC_VECTOR) RETURN NATURAL;
                     
END rs_pkg;

------------------------------------------------------------------------------

PACKAGE BODY rs_pkg IS

  -- Galois field multiplier functions for syndrome generation
  -- RS(32,28) decoder:
  FUNCTION gf_mul_1 ( 
    bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR IS
    VARIABLE cc_next: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
  BEGIN
    cc_next(0) := bb(7);
    cc_next(1) := bb(0);
    cc_next(2) := bb(1) XOR bb(7);
    cc_next(3) := bb(2) XOR bb(7);
    cc_next(4) := bb(3) XOR bb(7);
    cc_next(5) := bb(4);
    cc_next(6) := bb(5);
    cc_next(7) := bb(6);
    RETURN cc_next;
  END gf_mul_1;

  FUNCTION gf_mul_2 ( 
    bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR IS
    VARIABLE cc_next: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
  BEGIN
    cc_next(0) := bb(6);
    cc_next(1) := bb(7);
    cc_next(2) := bb(0) XOR bb(6);
    cc_next(3) := bb(1) XOR bb(6) XOR bb(7);
    cc_next(4) := bb(2) XOR bb(6) XOR bb(7);
    cc_next(5) := bb(3) XOR bb(7);
    cc_next(6) := bb(4);
    cc_next(7) := bb(5);
    RETURN cc_next;
  END gf_mul_2;

  FUNCTION gf_mul_3 ( 
    bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR IS
    VARIABLE cc_next: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
  BEGIN
    cc_next(0) := bb(5);
    cc_next(1) := bb(6);
    cc_next(2) := bb(5) XOR bb(7);
    cc_next(3) := bb(0) XOR bb(5) XOR bb(6);
    cc_next(4) := bb(1) XOR bb(5) XOR bb(6) XOR bb(7);
    cc_next(5) := bb(2) XOR bb(6) XOR bb(7);
    cc_next(6) := bb(3) XOR bb(7);
    cc_next(7) := bb(4);
    RETURN cc_next;
  END gf_mul_3;

  FUNCTION gf_mul_4 ( 
    bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR IS
    VARIABLE cc_next: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
  BEGIN
    cc_next(0) := bb(4);
    cc_next(1) := bb(5);
    cc_next(2) := bb(4) XOR bb(6);
    cc_next(3) := bb(4) XOR bb(5) XOR bb(7);
    cc_next(4) := bb(0) XOR bb(4) XOR bb(5) XOR bb(6);
    cc_next(5) := bb(1) XOR bb(5) XOR bb(6) XOR bb(7);
    cc_next(6) := bb(2) XOR bb(6) XOR bb(7);
    cc_next(7) := bb(3) XOR bb(7);
    RETURN cc_next;
  END gf_mul_4;


  -- Galois field multiplier functions shortened polynomial evaluation
  FUNCTION gf_mul_223 ( 
    bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR IS
    VARIABLE cc_next: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
  BEGIN
    cc_next(0) := bb(0) XOR bb(5);
    cc_next(1) := bb(1) XOR bb(6);
    cc_next(2) := bb(2) XOR bb(5) XOR bb(7);
    cc_next(3) := bb(0) XOR bb(3) XOR bb(5) XOR bb(6);
    cc_next(4) := bb(1) XOR bb(4) XOR bb(5) XOR bb(6) XOR bb(7);
    cc_next(5) := bb(2) XOR bb(5) XOR bb(6) XOR bb(7);
    cc_next(6) := bb(3) XOR bb(6) XOR bb(7);
    cc_next(7) := bb(4) XOR bb(7);
    RETURN cc_next;
  END gf_mul_223;

  FUNCTION gf_mul_191 ( 
    bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR IS
    VARIABLE cc_next: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
  BEGIN
    cc_next(0) := bb(0) XOR bb(2) XOR bb(6) XOR bb(7);
    cc_next(1) := bb(1) XOR bb(3) XOR bb(7);
    cc_next(2) := bb(4) XOR bb(6) XOR bb(7);
    cc_next(3) := bb(2) XOR bb(5) XOR bb(6);
    cc_next(4) := bb(2) XOR bb(3);
    cc_next(5) := bb(3) XOR bb(4);
    cc_next(6) := bb(0) XOR bb(4) XOR bb(5);
    cc_next(7) := bb(1) XOR bb(5) XOR bb(6);
    RETURN cc_next;
  END gf_mul_191;

  FUNCTION gf_mul_159 ( 
    bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR IS
    VARIABLE cc_next: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
  BEGIN
    cc_next(0) := bb(0) XOR bb(2) XOR bb(3) XOR bb(4) XOR bb(6) XOR bb(7);
    cc_next(1) := bb(0) XOR bb(1) XOR bb(3) XOR bb(4) XOR bb(5) XOR bb(7);
    cc_next(2) := bb(1) XOR bb(3) XOR bb(5) XOR bb(7);
    cc_next(3) := bb(3) XOR bb(7);
    cc_next(4) := bb(0) XOR bb(2) XOR bb(3) XOR bb(6) XOR bb(7);
    cc_next(5) := bb(0) XOR bb(1) XOR bb(3) XOR bb(4) XOR bb(7);
    cc_next(6) := bb(0) XOR bb(1) XOR bb(2) XOR bb(4) XOR bb(5);
    cc_next(7) := bb(1) XOR bb(2) XOR bb(3) XOR bb(5) XOR bb(6);
    RETURN cc_next;
  END gf_mul_159;


  -- Galois field square function for division circuit:
  FUNCTION gf256_pow2 ( 
    aa: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR IS
    VARIABLE cc_next: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
  BEGIN
    cc_next(0) := (aa(0)) XOR (aa(4)) XOR (aa(6)) XOR (aa(7));
    cc_next(1) := (aa(7));
    cc_next(2) := (aa(1)) XOR (aa(4)) XOR (aa(5)) XOR (aa(6));
    cc_next(3) := (aa(4)) XOR (aa(6));
    cc_next(4) := (aa(2)) XOR (aa(4)) XOR (aa(5)) XOR (aa(7));
    cc_next(5) := (aa(5));
    cc_next(6) := (aa(3)) XOR (aa(5)) XOR (aa(6));
    cc_next(7) := (aa(6));
    RETURN cc_next;
  END gf256_pow2;

  -- Galois field general multiplier:
  FUNCTION gf256_mul ( 
    aa: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
    bb: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0))
    RETURN STD_ULOGIC_VECTOR IS
    VARIABLE cc_next: STD_ULOGIC_VECTOR(mm-1 DOWNTO 0);
  BEGIN
    cc_next(0) := (aa(0) AND bb(0)) XOR (aa(7) AND bb(1)) XOR (aa(6) AND bb(2)) XOR (aa(5) AND bb(3)) XOR (aa(4) AND bb(4)) XOR (aa(3) AND bb(5)) XOR (aa(7) AND bb(5)) XOR (aa(2) AND bb(6)) XOR (aa(6) AND bb(6)) XOR (aa(7) AND bb(6)) XOR (aa(1) AND bb(7)) XOR (aa(5) AND bb(7)) XOR (aa(6) AND bb(7)) XOR (aa(7) AND bb(7));
    cc_next(1) := (aa(1) AND bb(0)) XOR (aa(0) AND bb(1)) XOR (aa(7) AND bb(2)) XOR (aa(6) AND bb(3)) XOR (aa(5) AND bb(4)) XOR (aa(4) AND bb(5)) XOR (aa(3) AND bb(6)) XOR (aa(7) AND bb(6)) XOR (aa(2) AND bb(7)) XOR (aa(6) AND bb(7)) XOR (aa(7) AND bb(7));
    cc_next(2) := (aa(2) AND bb(0)) XOR (aa(1) AND bb(1)) XOR (aa(7) AND bb(1)) XOR (aa(0) AND bb(2)) XOR (aa(6) AND bb(2)) XOR (aa(5) AND bb(3)) XOR (aa(7) AND bb(3)) XOR (aa(4) AND bb(4)) XOR (aa(6) AND bb(4)) XOR (aa(3) AND bb(5)) XOR (aa(5) AND bb(5)) XOR (aa(7) AND bb(5)) XOR (aa(2) AND bb(6)) XOR (aa(4) AND bb(6)) XOR (aa(6) AND bb(6)) XOR (aa(7) AND bb(6)) XOR (aa(1) AND bb(7)) XOR (aa(3) AND bb(7)) XOR (aa(5) AND bb(7)) XOR (aa(6) AND bb(7));
    cc_next(3) := (aa(3) AND bb(0)) XOR (aa(2) AND bb(1)) XOR (aa(7) AND bb(1)) XOR (aa(1) AND bb(2)) XOR (aa(6) AND bb(2)) XOR (aa(7) AND bb(2)) XOR (aa(0) AND bb(3)) XOR (aa(5) AND bb(3)) XOR (aa(6) AND bb(3)) XOR (aa(4) AND bb(4)) XOR (aa(5) AND bb(4)) XOR (aa(7) AND bb(4)) XOR (aa(3) AND bb(5)) XOR (aa(4) AND bb(5)) XOR (aa(6) AND bb(5)) XOR (aa(7) AND bb(5)) XOR (aa(2) AND bb(6)) XOR (aa(3) AND bb(6)) XOR (aa(5) AND bb(6)) XOR (aa(6) AND bb(6)) XOR (aa(1) AND bb(7)) XOR (aa(2) AND bb(7)) XOR (aa(4) AND bb(7)) XOR (aa(5) AND bb(7));
    cc_next(4) := (aa(4) AND bb(0)) XOR (aa(3) AND bb(1)) XOR (aa(7) AND bb(1)) XOR (aa(2) AND bb(2)) XOR (aa(6) AND bb(2)) XOR (aa(7) AND bb(2)) XOR (aa(1) AND bb(3)) XOR (aa(5) AND bb(3)) XOR (aa(6) AND bb(3)) XOR (aa(7) AND bb(3)) XOR (aa(0) AND bb(4)) XOR (aa(4) AND bb(4)) XOR (aa(5) AND bb(4)) XOR (aa(6) AND bb(4)) XOR (aa(3) AND bb(5)) XOR (aa(4) AND bb(5)) XOR (aa(5) AND bb(5)) XOR (aa(2) AND bb(6)) XOR (aa(3) AND bb(6)) XOR (aa(4) AND bb(6)) XOR (aa(1) AND bb(7)) XOR (aa(2) AND bb(7)) XOR (aa(3) AND bb(7)) XOR (aa(7) AND bb(7));
    cc_next(5) := (aa(5) AND bb(0)) XOR (aa(4) AND bb(1)) XOR (aa(3) AND bb(2)) XOR (aa(7) AND bb(2)) XOR (aa(2) AND bb(3)) XOR (aa(6) AND bb(3)) XOR (aa(7) AND bb(3)) XOR (aa(1) AND bb(4)) XOR (aa(5) AND bb(4)) XOR (aa(6) AND bb(4)) XOR (aa(7) AND bb(4)) XOR (aa(0) AND bb(5)) XOR (aa(4) AND bb(5)) XOR (aa(5) AND bb(5)) XOR (aa(6) AND bb(5)) XOR (aa(3) AND bb(6)) XOR (aa(4) AND bb(6)) XOR (aa(5) AND bb(6)) XOR (aa(2) AND bb(7)) XOR (aa(3) AND bb(7)) XOR (aa(4) AND bb(7));
    cc_next(6) := (aa(6) AND bb(0)) XOR (aa(5) AND bb(1)) XOR (aa(4) AND bb(2)) XOR (aa(3) AND bb(3)) XOR (aa(7) AND bb(3)) XOR (aa(2) AND bb(4)) XOR (aa(6) AND bb(4)) XOR (aa(7) AND bb(4)) XOR (aa(1) AND bb(5)) XOR (aa(5) AND bb(5)) XOR (aa(6) AND bb(5)) XOR (aa(7) AND bb(5)) XOR (aa(0) AND bb(6)) XOR (aa(4) AND bb(6)) XOR (aa(5) AND bb(6)) XOR (aa(6) AND bb(6)) XOR (aa(3) AND bb(7)) XOR (aa(4) AND bb(7)) XOR (aa(5) AND bb(7));
    cc_next(7) := (aa(7) AND bb(0)) XOR (aa(6) AND bb(1)) XOR (aa(5) AND bb(2)) XOR (aa(4) AND bb(3)) XOR (aa(3) AND bb(4)) XOR (aa(7) AND bb(4)) XOR (aa(2) AND bb(5)) XOR (aa(6) AND bb(5)) XOR (aa(7) AND bb(5)) XOR (aa(1) AND bb(6)) XOR (aa(5) AND bb(6)) XOR (aa(6) AND bb(6)) XOR (aa(7) AND bb(6)) XOR (aa(0) AND bb(7)) XOR (aa(4) AND bb(7)) XOR (aa(5) AND bb(7)) XOR (aa(6) AND bb(7));
    RETURN cc_next;
  END gf256_mul;

  -----------------------------------------------------------------------------
  -- Left bit is going to be MSB ; 
  -- Simplified version, works only on positive integers ! 
  -- Parameter 'size' is optional, If omitted result vector defaults to 32 bits

  FUNCTION int2suv (l: INTEGER; size: INTEGER := 32)                      
    RETURN STD_ULOGIC_VECTOR IS
      VARIABLE result: STD_ULOGIC_VECTOR(size-1 DOWNTO 0);
      VARIABLE op: INTEGER := l;
  BEGIN
    result := (size-1 DOWNTO 0 => '0');

    FOR i IN 0 TO size-1 LOOP
      IF (op MOD 2) = 1 THEN
        result (i) := '1' ;
      END IF ;
      op := op/2 ;
    END LOOP ;

    RETURN result;
  END int2suv;

  -----------------------------------------------------------------------------
  FUNCTION suv2int (l: STD_ULOGIC_VECTOR)                      
    RETURN NATURAL IS
      VARIABLE result: NATURAL := 0;
  BEGIN
    FOR t1 IN l'RANGE LOOP
      result := result * 2;
      IF l(t1) = '1' THEN
        result := result + 1;
      END IF;
    END LOOP;
    RETURN result;
  END suv2int;

END rs_pkg;