library ieee;
use     ieee.std_logic_1164.all;

library work;
use     work.bfm_hamm_rom_pkg.all;

-- ------------------------------------------------------------------------ --
--                                                      package declaration --
-- ------------------------------------------------------------------------ --
package coder_pkg is

-- functions --------------------------------
-- function to encode data
  -- -------------------------------------------------------------------------
  function encode_data(data_in : std_logic_vector) return std_logic_vector;

end coder_pkg;

-- ------------------------------------------------------------------------ --
--                                                             package body --
-- ------------------------------------------------------------------------ --
package body coder_pkg is

-- function to encode data
  -- -------------------------------------------------------------------------
  function encode_data(data_in : std_logic_vector) return std_logic_vector is

	 variable h_col : std_logic_vector (c_CHECK_DATA_WIDTH-1 downto 0);
     variable parity_bits : std_logic_vector(c_CHECK_DATA_WIDTH-1 downto 0);
     variable encoded_data : std_logic_vector(c_ENCODED_DATA_WIDTH - 1 downto 0);

  begin
  parity_bits := (others => '0');

  ParityGen:
  for i in c_ENCODED_DATA_WIDTH-1 downto c_CHECK_DATA_WIDTH loop
    for j in c_CHECK_DATA_WIDTH-1 downto 0 loop
      h_col(j) := c_H_EXT(j)(i); 
    end loop;

    if data_in(i-c_CHECK_DATA_WIDTH) = '1' then
      parity_bits := parity_bits xor h_col;
    end if;
  end loop;

  encoded_data := DATA_IN & parity_bits;

  return encoded_data;

  end function;


end coder_pkg;
