Commit e8d940f4 authored by bradomyn's avatar bradomyn

fixed the indetation, between vim, ise and modelsim everything was messy

parent a80789ab
......@@ -7,19 +7,19 @@ use ieee.std_logic_unsigned.all;
-- The word, "word" is reserved for encoded data 24 bits
-- The word. "data" is reserved for non-encoded data 12 btis
entity linear_block_decoder_tb is
end linear_block_decoder_tb;
end linear_block_decoder_tb;
architecture behavioral of linear_block_decoder_tb is
signal clk : std_logic:= '0';
signal reset : std_logic:= '1';
signal data_in : std_logic_vector(23 downto 0);
signal decoded_out : std_logic_vector(11 downto 0):=(others =>'0');
signal errorDecoded_out: std_logic:= '0';
constant period : time := 8 ns;
component linear_block_decoder
port(
clk: in std_logic;
......@@ -33,13 +33,13 @@ architecture behavioral of linear_block_decoder_tb is
begin
decoder_tb : linear_block_decoder
port map(
port map(
clk => clk,
reset => reset,
data_in => data_in,
decoded_out => decoded_out,
errorDecoded_out => errorDecoded_out);
clk_proc : process
begin
clk <= '0';
......@@ -57,7 +57,7 @@ begin
-- error checks state machine till step 4, three bit error
data_in <= to_stdlogicvector(x"54524a");
wait for period*8;
------------------------------------------------------------------
------------------------------------------------------------------
reset <= '1';
data_in <= (others=>'0');
wait for period;
......@@ -65,7 +65,7 @@ begin
-- error checks state machine till fail, four bit error
data_in <= to_stdlogicvector(x"54d24a");
wait for period*8;
---------------------------------------------------------------
---------------------------------------------------------------
reset <= '1';
data_in <= (others=>'0');
wait for period;
......@@ -132,7 +132,7 @@ begin
end process;
end process;
......
......@@ -4,11 +4,11 @@ use ieee.std_logic_arith.all;
entity linear_block_performance is
end linear_block_performance;
end linear_block_performance;
architecture behaviour of linear_block_performance is
signal clk :std_logic := '0';
signal data :std_logic_vector (11 downto 0) := (others => '0');
signal word :std_logic_vector (23 downto 0) := (others => '0');
......@@ -28,83 +28,83 @@ architecture behaviour of linear_block_performance is
clk : in std_logic;
data_in: in std_logic_vector(11 downto 0);
encoded_out:out std_logic_vector(23 downto 0)
);
);
end component;
begin
encoder_1: linear_block_enc
port map(
clk => clk,
data_in => data_1,
encoded_out => word_1
);
port map(
clk => clk,
data_in => data_1,
encoded_out => word_1
);
encoder_2: linear_block_enc
port map(
clk => clk,
data_in => data_2,
encoded_out => word_2
);
port map(
clk => clk,
data_in => data_2,
encoded_out => word_2
);
encoder_3: linear_block_enc
port map(
clk => clk,
data_in => data_3,
encoded_out => word_3
);
port map(
clk => clk,
data_in => data_3,
encoded_out => word_3
);
encoder_4: linear_block_enc
port map(
clk => clk,
data_in => data_4,
encoded_out => word_4
);
port map(
clk => clk,
data_in => data_4,
encoded_out => word_4
);
encoder_5: linear_block_enc
port map(
clk => clk,
data_in => data_5,
encoded_out => word_5
);
clk_proc: process
begin
port map(
clk => clk,
data_in => data_5,
encoded_out => word_5
);
clk_proc: process
begin
clk <= '1';
wait for PERIOD/2;
clk <= '0';
wait for PERIOD/2;
end process;
end process;
data_proc: process(clk)
begin
data_proc: process(clk)
begin
if(count < lengthframe) then
data_1 <= to_stdlogicvector(x"111");
data_2 <= to_stdlogicvector(x"111");
data_3 <= to_stdlogicvector(x"111");
data_4 <= to_stdlogicvector(x"111");
data_5 <= to_stdlogicvector(x"111");
count := count + (numEncoder*sizeword);
data_1 <= to_stdlogicvector(x"111");
data_2 <= to_stdlogicvector(x"111");
data_3 <= to_stdlogicvector(x"111");
data_4 <= to_stdlogicvector(x"111");
data_5 <= to_stdlogicvector(x"111");
count := count + (numEncoder*sizeword);
else
data_1 <= zeros(11 downto 0);
data_2 <= zeros(11 downto 0);
data_3 <= zeros(11 downto 0);
data_4 <= zeros(11 downto 0);
data_5 <= zeros(11 downto 0);
data_1 <= zeros(11 downto 0);
data_2 <= zeros(11 downto 0);
data_3 <= zeros(11 downto 0);
data_4 <= zeros(11 downto 0);
data_5 <= zeros(11 downto 0);
end if;
end process;
frame_proc: process(clk)
variable count1:integer :=0;
begin
end process;
frame_proc: process(clk)
variable count1:integer :=0;
begin
if(count1 < 12000) then
frame(count*2-1 downto (count*2 - (numEncoder*sizeword))) <=
word_5 & word_4 & word_3 & word_2 & word_1;
count1 := count1+120;
else
frame(count*2-1 downto (count*2 - (numEncoder*sizeword))) <=
zeros & zeros & zeros & zeros & zeros;
frame(count*2-1 downto (count*2 - (numEncoder*sizeword))) <=
word_5 & word_4 & word_3 & word_2 & word_1;
count1 := count1+120;
else
frame(count*2-1 downto (count*2 - (numEncoder*sizeword))) <=
zeros & zeros & zeros & zeros & zeros;
end if;
end process;
end process;
end;
......
......@@ -4,11 +4,11 @@ use ieee.std_logic_arith.all;
entity linear_block_testb is
end linear_block_testb;
end linear_block_testb;
architecture behaviour of linear_block_testb is
signal clk :std_logic := '0';
signal data :std_logic_vector (11 downto 0) := (others => '0');
signal word :std_logic_vector (23 downto 0) := (others => '0');
......@@ -20,33 +20,33 @@ architecture behaviour of linear_block_testb is
clk : in std_logic;
data_in: in std_logic_vector(11 downto 0);
encoded_out:out std_logic_vector(23 downto 0)
);
);
end component;
begin
encoder: linear_block_enc
port map(
clk => clk,
data_in => data,
encoded_out => word
);
clk_proc: process
begin
port map(
clk => clk,
data_in => data,
encoded_out => word
);
clk_proc: process
begin
clk <= '1';
wait for PERIOD/2;
clk <= '0';
wait for PERIOD/2;
end process;
end process;
data_proc: process
begin
data_proc: process
begin
wait for 16 ns;
data <= to_stdlogicvector(x"111");
wait;
end process;
end process;
end;
......
......@@ -51,7 +51,7 @@ entity linear_block_decoder is
data_in: in word_vector;
decoded_out: out data_vector;
errorDecoded_out:out std_logic;
succeedDeco_out:out std_logic
succeedDeco_out:out std_logic
);
end linear_block_decoder;
......@@ -65,123 +65,123 @@ architecture behavioral of linear_block_decoder is
type fms is (idle,step1,step2,step2_bis,step3,step4,step4_bis,deco,fail);
signal deco_state: fms;
signal errorDecoded: std_logic;
signal succeedDeco : std_logic;
signal errorVal : errorValset;
signal syndCal : syndCalset;
signal syndxBCal : syndxBCalset;
signal succeedDeco : std_logic;
signal errorVal : errorValset;
signal syndCal : syndCalset;
signal syndxBCal : syndxBCalset;
begin
--============================================================================
--! Process deco_logic
--! @brief logic of the decoder, following the state machine defined in [1]
--============================================================================
--============================================================================
--! Process deco_logic
--! @brief logic of the decoder, following the state machine defined in [1]
--============================================================================
deco_logic: process(clk,reset)
variable syndCalTemp : syndCalset;
variable syndxBCalTemp : syndxBCalset;
variable errorValTemp : errorValset;
variable syndCalTemp : syndCalset;
variable syndxBCalTemp : syndxBCalset;
variable errorValTemp : errorValset;
begin
if(clk'event and clk='1') then
if (reset = '1') then
deco_state <= idle;
syndCal <= ((others=>'0'),0);
errorVal <= ((others=>'0'),0);
syndxBCal <= ((others=>'0'),0);
vector_fixed <= (others=>'0');
errorDecoded <= '0';
succeedDeco <= '0';
else
case deco_state is
when idle =>
if (data_in /= zeros24) then
deco_state <= step1;
else
deco_state <= idle;
end if;
when step1 =>
syndCalTemp := syndromeCal(data_in);
syndCal <= syndCalTemp;
if (syndCalTemp.hammingW<=3) then
deco_state <= deco;
vector_fixed <= (syndCalTemp.synd&zeros12) xor data_in;
else
vector_fixed <= zeros24;
deco_state <= step2;
end if;
when step2 =>
-- calc error vectors
errorValTemp := errorVectorCal(syndCal.synd);
errorVal <= errorValTemp;
deco_state <= step2_bis;
when step2_bis =>
if(errorVal.hammingW <= 2) then
vector_fixed <= errorVal.errorVector xor data_in;
deco_state <= deco;
else
vector_fixed <= zeros24;
deco_state <= step3;
end if;
when step3 =>
-- syndromexB and hammingW(syndromeB)
syndxBCalTemp := syndromexBCal(syndCal.synd);
syndxBCal <= syndxBCalTemp;
if (syndxBCalTemp.hammingW<=3) then
vector_fixed <= (zeros12&syndxBCalTemp.syndxB) xor
data_in;
deco_state <= deco;
else
vector_fixed <= zeros24;
deco_state <= step4;
end if;
when step4 =>
if(clk'event and clk='1') then
if (reset = '1') then
deco_state <= idle;
syndCal <= ((others=>'0'),0);
errorVal <= ((others=>'0'),0);
syndxBCal <= ((others=>'0'),0);
vector_fixed <= (others=>'0');
errorDecoded <= '0';
succeedDeco <= '0';
else
case deco_state is
when idle =>
if (data_in /= zeros24) then
deco_state <= step1;
else
deco_state <= idle;
end if;
when step1 =>
syndCalTemp := syndromeCal(data_in);
syndCal <= syndCalTemp;
if (syndCalTemp.hammingW<=3) then
deco_state <= deco;
vector_fixed <= (syndCalTemp.synd&zeros12) xor data_in;
else
vector_fixed <= zeros24;
deco_state <= step2;
end if;
when step2 =>
-- calc error vectors
errorValTemp := errorVectorCal(syndCal.synd);
errorVal <= errorValTemp;
deco_state <= step2_bis;
when step2_bis =>
if(errorVal.hammingW <= 2) then
vector_fixed <= errorVal.errorVector xor data_in;
deco_state <= deco;
else
vector_fixed <= zeros24;
deco_state <= step3;
end if;
when step3 =>
-- syndromexB and hammingW(syndromeB)
syndxBCalTemp := syndromexBCal(syndCal.synd);
syndxBCal <= syndxBCalTemp;
if (syndxBCalTemp.hammingW<=3) then
vector_fixed <= (zeros12&syndxBCalTemp.syndxB) xor
data_in;
deco_state <= deco;
else
vector_fixed <= zeros24;
deco_state <= step4;
end if;
when step4 =>
-- (Beta*B+rowi) and hammingW
errorValTemp := errorVectorxBCal(syndxBCal.syndxB);
errorVal <= errorValTemp;
deco_state <= step4_bis;
when step4_bis =>
if (errorVal.hammingW <= 2) then
deco_state <= deco;
vector_fixed <= errorVal.errorVector xor
data_in;
else
vector_fixed <= zeros24;
deco_state <= fail;
end if;
when deco =>
deco_state <= idle;
errorDecoded <= '0';
succeedDeco <= '1';
when fail =>
deco_state <= idle;
errorDecoded <= '1';
succeedDeco <= '0';
when others =>
syndCal <= ((others=>'0'),0);
syndxBCal <= ((others=>'0'),0);
vector_fixed <= zeros24;
-- errorVal <= ((others=>'0'),0);
syndCalTemp := ((others=>'0'),0);
end case;
end if;
end if;
end process;
-- output
decoded_out <= vector_fixed(23 downto 12);
succeedDeco_out <= succeedDeco;
errorValTemp := errorVectorxBCal(syndxBCal.syndxB);
errorVal <= errorValTemp;
deco_state <= step4_bis;
when step4_bis =>
if (errorVal.hammingW <= 2) then
deco_state <= deco;
vector_fixed <= errorVal.errorVector xor
data_in;
else
vector_fixed <= zeros24;
deco_state <= fail;
end if;
when deco =>
deco_state <= idle;
errorDecoded <= '0';
succeedDeco <= '1';
when fail =>
deco_state <= idle;
errorDecoded <= '1';
succeedDeco <= '0';
when others =>
syndCal <= ((others=>'0'),0);
syndxBCal <= ((others=>'0'),0);
vector_fixed <= zeros24;
-- errorVal <= ((others=>'0'),0);
syndCalTemp := ((others=>'0'),0);
end case;
end if;
end if;
end process;
-- output
decoded_out <= vector_fixed(23 downto 12);
succeedDeco_out <= succeedDeco;
errorDecoded_out <= errorDecoded;
end behavioral;
......@@ -33,58 +33,58 @@ use work.linear_block_package.all;
entity linear_block_enc is
port ( clk : in std_logic;
port ( clk : in std_logic;
data_in : in data_vector;
encoded_out : out word_vecor
);
encoded_out : out word_vecor
);
end linear_block_enc;
architecture Behavioral of linear_block_enc is
signal check_bits : data_vector:=(others =>'0');
-- b matrix
-- 555 1 0 1 0 1 0 1 0 1 0 1 0
---------------------------------------------------
-- 11 0 1 2 3 4 5 6 7 8 9 10
-- 10 1 5 6 7 9 10 11
-- 9 0 2 6 7 8 10 11
-- 8 0 1 3 7 8 9 11
-- 7 1 2 4 8 9 10 11
-- 6 0 2 3 5 9 10 11
-- 5 0 1 3 4 6 10 11
-- 4 0 1 2 4 5 7 11
-- 3 1 2 3 5 6 8 11
-- 2 2 3 4 6 7 9 11
-- 1 3 4 5 7 8 10 11
-- 0 0 4 5 6 8 9 11
begin
process(data_in,clk)
begin
if(clk'event and clk='1') then -- parity bits c * b
check_bits(11) <= data_in(0) xor data_in(1) xor data_in(2) xor data_in(3) xor data_in(4) xor data_in(5) xor data_in(6)
xor data_in(7) xor data_in(8) xor data_in(9) xor data_in(10);
check_bits(10) <= data_in(1) xor data_in(5) xor data_in(6) xor data_in(7) xor data_in(9) xor data_in(10) xor data_in(11);
check_bits(9) <= data_in(0) xor data_in(2) xor data_in(6) xor data_in(7) xor data_in(8) xor data_in(10) xor data_in(11);
check_bits(8) <= data_in(0) xor data_in(1) xor data_in(3) xor data_in(7) xor data_in(8) xor data_in(9) xor data_in(11);
check_bits(7) <= data_in(1) xor data_in(2) xor data_in(4) xor data_in(8) xor data_in(9) xor data_in(10) xor data_in(11);
check_bits(6) <= data_in(0) xor data_in(2) xor data_in(3) xor data_in(5) xor data_in(9) xor data_in(10) xor data_in(11);
check_bits(5) <= data_in(0) xor data_in(1) xor data_in(3) xor data_in(4) xor data_in(6) xor data_in(10) xor data_in(11);
check_bits(4) <= data_in(0) xor data_in(1) xor data_in(2) xor data_in(4) xor data_in(5) xor data_in(7) xor data_in(11);
check_bits(3) <= data_in(1) xor data_in(2) xor data_in(3) xor data_in(5) xor data_in(6) xor data_in(8) xor data_in(11);
check_bits(2) <= data_in(2) xor data_in(3) xor data_in(4) xor data_in(6) xor data_in(7) xor data_in(9) xor data_in(11);
check_bits(1) <= data_in(3) xor data_in(4) xor data_in(5) xor data_in(7) xor data_in(8) xor data_in(10) xor data_in(11);
check_bits(0) <= data_in(0) xor data_in(4) xor data_in(5) xor data_in(6) xor data_in(8) xor data_in(9) xor data_in(11);
end if;
end process;
signal check_bits : data_vector:=(others =>'0');
-- b matrix
-- 555 1 0 1 0 1 0 1 0 1 0 1 0
---------------------------------------------------
-- 11 0 1 2 3 4 5 6 7 8 9 10
-- 10 1 5 6 7 9 10 11
-- 9 0 2 6 7 8 10 11
-- 8 0 1 3 7 8 9 11
-- 7 1 2 4 8 9 10 11
-- 6 0 2 3 5 9 10 11
-- 5 0 1 3 4 6 10 11
-- 4 0 1 2 4 5 7 11
-- 3 1 2 3 5 6 8 11
-- 2 2 3 4 6 7 9 11
-- 1 3 4 5 7 8 10 11
-- 0 0 4 5 6 8 9 11
begin
process(data_in,clk)
begin
if(clk'event and clk='1') then -- parity bits c * b
check_bits(11) <= data_in(0) xor data_in(1) xor data_in(2) xor data_in(3) xor data_in(4) xor data_in(5) xor data_in(6)
xor data_in(7) xor data_in(8) xor data_in(9) xor data_in(10);
check_bits(10) <= data_in(1) xor data_in(5) xor data_in(6) xor data_in(7) xor data_in(9) xor data_in(10) xor data_in(11);
check_bits(9) <= data_in(0) xor data_in(2) xor data_in(6) xor data_in(7) xor data_in(8) xor data_in(10) xor data_in(11);
check_bits(8) <= data_in(0) xor data_in(1) xor data_in(3) xor data_in(7) xor data_in(8) xor data_in(9) xor data_in(11);
check_bits(7) <= data_in(1) xor data_in(2) xor data_in(4) xor data_in(8) xor data_in(9) xor data_in(10) xor data_in(11);
check_bits(6) <= data_in(0) xor data_in(2) xor data_in(3) xor data_in(5) xor data_in(9) xor data_in(10) xor data_in(11);
check_bits(5) <= data_in(0) xor data_in(1) xor data_in(3) xor data_in(4) xor data_in(6) xor data_in(10) xor data_in(11);
check_bits(4) <= data_in(0) xor data_in(1) xor data_in(2) xor data_in(4) xor data_in(5) xor data_in(7) xor data_in(11);
check_bits(3) <= data_in(1) xor data_in(2) xor data_in(3) xor data_in(5) xor data_in(6) xor data_in(8) xor data_in(11);
check_bits(2) <= data_in(2) xor data_in(3) xor data_in(4) xor data_in(6) xor data_in(7) xor data_in(9) xor data_in(11);
check_bits(1) <= data_in(3) xor data_in(4) xor data_in(5) xor data_in(7) xor data_in(8) xor data_in(10) xor data_in(11);
check_bits(0) <= data_in(0) xor data_in(4) xor data_in(5) xor data_in(6) xor data_in(8) xor data_in(9) xor data_in(11);
end if;
end process;
encoded_out <= data_in & check_bits; -- c = [data,check_bits]
end Behavioral;
......@@ -46,91 +46,89 @@ package linear_block_package is
constant zeros24 : word_vector :=(others=>'0');
constant unos24 : word_vector :=(others=>'1');
--constant tresVector : word_vector := "000000000000000000000011";
type matrix is array (natural range <>) of data_vector;
type matrixl is array (natural range <>) of word_vector;
type HamingWeight is array (63 downto 0) of integer range 0 to 11;
type magicBinaryNumber is array (4 downto 0) of integer;
constant S : magicBinaryNumber := (1, 2, 4, 8,16);
type error_array is array (data_width-1 downto 0) of word_vector;
type syndxB_array is array (data_width-1 downto 0) of word_vector;
type synd_array is array (data_width-1 downto 0) of data_vector;
type hamingW_array is array (data_width-1 downto 0) of integer range 0 to 11;
type errorCalset is
record
errorVector : error_array;
hammingW : integer range 0 to 11;
end record;
type errorValset is
record
errorVector : word_vector;
hammingW : integer range 0 to 11;
end record;
constant iniErrorVal : errorValset := ( errorVector => (others=>'1'),
hammingW => 11);
type syndCalset is
record
synd : data_vector;
hammingW : integer range 0 to 11;
end record;
type syndxBCalset is
record
syndxB : data_vector;
hammingW : integer range 0 to 11;
end record;
-- hamming weigth lookup table
constant hammingWLT_1 : HamingWeight := (6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, 5,
4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 5, 4,
4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 4, 3, 3,
2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0);
constant hammingWLT_2 : HamingWeight := hammingWLT_1;
constant hammingWLT_3 : HamingWeight := hammingWLT_1;
constant hammingWLT_4 : HamingWeight := hammingWLT_1;
type matrixl is array (natural range <>) of word_vector;
type HamingWeight is array (63 downto 0) of integer range 0 to 11;
type magicBinaryNumber is array (4 downto 0) of integer;
constant S : magicBinaryNumber := (1, 2, 4, 8,16);
type error_array is array (data_width-1 downto 0) of word_vector;
type syndxB_array is array (data_width-1 downto 0) of word_vector;
type synd_array is array (data_width-1 downto 0) of data_vector;
type hamingW_array is array (data_width-1 downto 0) of integer range 0 to 11;
type errorCalset is
record
errorVector : error_array;
hammingW : integer range 0 to 11;
end record;
type errorValset is
record
errorVector : word_vector;
hammingW : integer range 0 to 11;
end record;
constant iniErrorVal : errorValset := ( errorVector => (others=>'1'),
hammingW => 11);
type syndCalset is
record
synd : data_vector;
hammingW : integer range 0 to 11;
end record;
type syndxBCalset is
record
syndxB : data_vector;
hammingW : integer range 0 to 11;
end record;
-- hamming weigth lookup table
constant hammingWLT_1 : HamingWeight := (6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, 5,
4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 5, 4,
4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 4, 3, 3,
2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0);
constant hammingWLT_2 : HamingWeight := hammingWLT_1;
constant hammingWLT_3 : HamingWeight := hammingWLT_1;
constant hammingWLT_4 : HamingWeight := hammingWLT_1;
-- Binary b matrix
-- constant bMatrix : matrix := ("011111111111","111011100010","110111000101",
-- "101110001011","101110001011","111000101101",
-- "111000101101","111000101101","111000101101",
-- "111000101101","111000101101","111000101101");
-- constant bMatrix : matrix := ("011111111111","111011100010","110111000101",
-- "101110001011","101110001011","111000101101",
-- "111000101101","111000101101","111000101101",
-- "111000101101","111000101101","111000101101");
-- Binray h matrix
constant hMatrix : matrixl:=( "011111111111100000000000","111011100010010000000000",
"110111000101001000000000","101110001011000100000000",
"111100010110000010000000","111000101101000001000000",
"110001011011000000100000","100010110111000000010000",
"100101101110000000001000","101011011100000000000100",
"110110111000000000000010","101101110001000000000001");
-- binary g matrix
constant gMatrix : matrixl:=("100000000000011111111111","010000000000111011100010",
"001000000000110111000101","000100000000101110001011",
"000010000000111100010110","000001000000111000101101",
"000000100000110001011011","000000010000100010110111",
"000000001000100101101110","000000000100101011011100",
"000000000010110110111000","000000000001101101110001");
function hammingWCal( row : data_vector) return integer;
function hammingWCal_l( row : word_vector) return integer; --word_vector;
function syndromeCal( row : word_vector) return syndCalset;
function errorVectorCal( synd : data_vector) return errorValset;
function syndromexBCal( synd : data_vector) return syndxBCalset;
function errorVectorxBCal( synd : data_vector) return errorValset;
function shift_right(row : data_vector; i : integer) return data_vector;
function shift_right_l(row : word_vector; i : integer) return word_vector;
constant hMatrix : matrixl:=( "011111111111100000000000","111011100010010000000000",
"110111000101001000000000","101110001011000100000000",
"111100010110000010000000","111000101101000001000000",
"110001011011000000100000","100010110111000000010000",
"100101101110000000001000","101011011100000000000100",
"110110111000000000000010","101101110001000000000001");
-- binary g matrix
constant gMatrix : matrixl:=("100000000000011111111111","010000000000111011100010",
"001000000000110111000101","000100000000101110001011",
"000010000000111100010110","000001000000111000101101",
"000000100000110001011011","000000010000100010110111",
"000000001000100101101110","000000000100101011011100",
"000000000010110110111000","000000000001101101110001");
function hammingWCal( row : data_vector) return integer;
function hammingWCal_l( row : word_vector) return integer; --word_vector;
end linear_block_package;
function syndromeCal( row : word_vector) return syndCalset;
function errorVectorCal( synd : data_vector) return errorValset;
function syndromexBCal( synd : data_vector) return syndxBCalset;
function errorVectorxBCal( synd : data_vector) return errorValset;
function shift_right(row : data_vector; i : integer) return data_vector;
function shift_right_l(row : word_vector; i : integer) return word_vector;
end linear_block_package;
package body linear_block_package is
-- calculates the step 1 of the algorithm
-- calc syndrome and hamming(syndrome)
......@@ -154,42 +152,42 @@ package body linear_block_package is
--! @param vector, "row" with the codeword \n
--! @return the hamming height of codeword and teh syndrome
--============================================================================
function syndromeCal( row : word_vector) return syndCalset is
variable syndTemp : syndCalset;
variable tempW : integer range 0 to 12;
begin
syndTemp.synd(11) := row(0) xor row(1) xor row(2) xor row(3) xor row(4) xor
row(5) xor row(6) xor row(7) xor row(8) xor row(9) xor
row(10) xor row(23);
syndTemp.synd(10) := row(1) xor row(5) xor row(6) xor row(7) xor row(9) xor
row(10) xor row(11) xor row(22);
syndTemp.synd(9) := row(0) xor row(2) xor row(6) xor row(7) xor row(8) xor
row(10) xor row(11) xor row(21);
syndTemp.synd(8) := row(0) xor row(1) xor row(3) xor row(7) xor row(8) xor
row(9) xor row(11) xor row(20);
syndTemp.synd(7) := row(1) xor row(2) xor row(4) xor row(8) xor row(9) xor
row(10) xor row(11) xor row(11);
syndTemp.synd(6) := row(0) xor row(2) xor row(3) xor row(5) xor row(9) xor
row(10) xor row(11) xor row(18);
syndTemp.synd(5) := row(0) xor row(1) xor row(3) xor row(4) xor row(6) xor
row(10) xor row(11) xor row(17);
syndTemp.synd(4) := row(0) xor row(1) xor row(2) xor row(4) xor row(5) xor
row(7) xor row(11) xor row(16);
syndTemp.synd(3) := row(1) xor row(2) xor row(3) xor row(5) xor row(6) xor
row(8) xor row(11) xor row(15);
syndTemp.synd(2) := row(2) xor row(3) xor row(4) xor row(6) xor row(7) xor
row(9) xor row(11) xor row(14);
syndTemp.synd(1) := row(3) xor row(4) xor row(5) xor row(7) xor row(8) xor
row(10) xor row(11) xor row(13);
syndTemp.synd(0) := row(0) xor row(4) xor row(5) xor row(6) xor row(8) xor
row(9) xor row(11) xor row(12);
syndTemp.hammingW := hammingWCal(syndTemp.synd);---1;
return syndTemp;
end syndromeCal;
function syndromeCal( row : word_vector) return syndCalset is
variable syndTemp : syndCalset;
variable tempW : integer range 0 to 12;
begin
syndTemp.synd(11) := row(0) xor row(1) xor row(2) xor row(3) xor row(4) xor
row(5) xor row(6) xor row(7) xor row(8) xor row(9) xor
row(10) xor row(23);
syndTemp.synd(10) := row(1) xor row(5) xor row(6) xor row(7) xor row(9) xor
row(10) xor row(11) xor row(22);
syndTemp.synd(9) := row(0) xor row(2) xor row(6) xor row(7) xor row(8) xor
row(10) xor row(11) xor row(21);
syndTemp.synd(8) := row(0) xor row(1) xor row(3) xor row(7) xor row(8) xor
row(9) xor row(11) xor row(20);
syndTemp.synd(7) := row(1) xor row(2) xor row(4) xor row(8) xor row(9) xor
row(10) xor row(11) xor row(11);
syndTemp.synd(6) := row(0) xor row(2) xor row(3) xor row(5) xor row(9) xor
row(10) xor row(11) xor row(18);
syndTemp.synd(5) := row(0) xor row(1) xor row(3) xor row(4) xor row(6) xor
row(10) xor row(11) xor row(17);
syndTemp.synd(4) := row(0) xor row(1) xor row(2) xor row(4) xor row(5) xor
row(7) xor row(11) xor row(16);
syndTemp.synd(3) := row(1) xor row(2) xor row(3) xor row(5) xor row(6) xor
row(8) xor row(11) xor row(15);
syndTemp.synd(2) := row(2) xor row(3) xor row(4) xor row(6) xor row(7) xor
row(9) xor row(11) xor row(14);
syndTemp.synd(1) := row(3) xor row(4) xor row(5) xor row(7) xor row(8) xor
row(10) xor row(11) xor row(13);
syndTemp.synd(0) := row(0) xor row(4) xor row(5) xor row(6) xor row(8) xor
row(9) xor row(11) xor row(12);
syndTemp.hammingW := hammingWCal(syndTemp.synd);---1;
return syndTemp;
end syndromeCal;
-- calculates the step 2 of the algorithm
-- calc error and hamming(error)
......@@ -213,29 +211,29 @@ end syndromeCal;
--! @param vector, syndrome \n
--! @return error vector, the hamming weight is filled with a dummy value
--============================================================================
function errorVectorCal( synd : data_vector) return errorValset is
variable error : errorValset;
variable tmphamWg : integer range 0 to 12:=0;
variable errorTemp : word_vector;
begin
error := iniErrorVal;
for i in 11 downto 0 loop
errorTemp := (synd&zeros12) xor hMatrix(i);
tmphamWg := hammingWCal_l(errorTemp);
--if (tmphamWg <= tresVector) then
if (tmphamWg <= 3) then
function errorVectorCal( synd : data_vector) return errorValset is
variable error : errorValset;
variable tmphamWg : integer range 0 to 12:=0;
variable errorTemp : word_vector;
begin
error := iniErrorVal;
for i in 11 downto 0 loop
errorTemp := (synd&zeros12) xor hMatrix(i);
tmphamWg := hammingWCal_l(errorTemp);
--if (tmphamWg <= tresVector) then
if (tmphamWg <= 3) then
--error.hammingW := conv_integer(tmphamWg)-1;
error.hammingW := tmphamWg-1;
error.errorVector := errorTemp;
end if;
end loop;
return error;
end errorVectorCal;
error.hammingW := tmphamWg-1;
error.errorVector := errorTemp;
end if;
end loop;
return error;
end errorVectorCal;
--============================================================================
-- errorVectorxBCal
......@@ -243,26 +241,26 @@ end errorVectorCal;
--! @param vector, syndrome \n
--! @return error vector, the hamming weight is filled with a dummy value
--============================================================================
function errorVectorxBCal( synd : data_vector) return errorValset is
variable error : errorValset;
variable tmphamWg : integer range 0 to 12:=0;
variable errorTemp : word_vector;
begin
error := iniErrorVal;
for i in 11 downto 0 loop
errorTemp := (zeros12&synd) xor gMatrix(i);
tmphamWg:= hammingWCal_l(errorTemp);
if (tmphamWg <= 3) then
error.hammingW := tmphamWg-1;
error.errorVector := errorTemp;
end if;
end loop;
return error;
end errorVectorxBCal;
function errorVectorxBCal( synd : data_vector) return errorValset is
variable error : errorValset;
variable tmphamWg : integer range 0 to 12:=0;
variable errorTemp : word_vector;
begin
error := iniErrorVal;
for i in 11 downto 0 loop
errorTemp := (zeros12&synd) xor gMatrix(i);
tmphamWg:= hammingWCal_l(errorTemp);
if (tmphamWg <= 3) then
error.hammingW := tmphamWg-1;
error.errorVector := errorTemp;
end if;
end loop;
return error;
end errorVectorxBCal;
--============================================================================
-- shift_right
......@@ -270,13 +268,13 @@ end errorVectorxBCal;
--! @param vector
--! @return the shifted word_vector
--============================================================================
function shift_right(row : data_vector; i : integer) return data_vector is
variable shifted : data_vector;
begin
shifted := zeros24(i-1 downto 0) & row(11 downto i);
return shifted;
end shift_right;
function shift_right(row : data_vector; i : integer) return data_vector is
variable shifted : data_vector;
begin
shifted := zeros24(i-1 downto 0) & row(11 downto i);
return shifted;
end shift_right;
--============================================================================
-- shift_right_l
......@@ -284,86 +282,86 @@ end shift_right;
--! @param vector
--! @return the shifted word_vector
--============================================================================
function shift_right_l(row : word_vector; i : integer) return word_vector is
variable shifted : word_vector;
begin
shifted := zeros24(i-1 downto 0) & row(23 downto i);
return shifted;
end shift_right_l;
function shift_right_l(row : word_vector; i : integer) return word_vector is
variable shifted : word_vector;
begin
shifted := zeros24(i-1 downto 0) & row(23 downto i);
return shifted;
end shift_right_l;
--============================================================================
-- hammingWCal
--! @brief calculates the hamming weight of a vector, inspired in "Bit Twiddling Hacks"
--! @param data_vector
--! @return hamming weight
--============================================================================
function hammingWCal( row : data_vector) return integer is
function hammingWCal( row : data_vector) return integer is
variable hW : integer range 0 to 12:=0;
variable temp : std_logic_vector(11 downto 0);
variable hW : integer range 0 to 12:=0;
variable temp : std_logic_vector(11 downto 0);
---------------------------------------------------------
-- constant five : std_logic_vector(11 downto 0) := x"555";
-- constant three : std_logic_vector(11 downto 0) := x"333";
---------------------------------------------------------
-- constant S : magicBinaryNumber := (1, 2, 4, 8);
-- constant Bi : error_array := (x"555", x"333", x"F0F", x"0FF");
-- constant five : std_logic_vector(11 downto 0) := x"555";
-- constant three : std_logic_vector(11 downto 0) := x"333";
---------------------------------------------------------
-- constant S : magicBinaryNumber := (1, 2, 4, 8);
-- constant Bi : error_array := (x"555", x"333", x"F0F", x"0FF");
-- constant B : matrix := ("010101010101",
-- "001100110011",
-- "111100001111",
-- "000011111111");
-- constant B : matrix := ("010101010101",
-- "001100110011",
-- "111100001111",
-- "000011111111");
begin
hw := hammingWLT_1(conv_integer(row(11 downto 6)))+ hammingWLT_2(conv_integer(row(5 downto 0)));
-- Other method... 125 Mhz
-- temp := row - (shift_right(row,1) and B(0));
-- temp := ((shift_right(temp,S(1)) and B(1))
-- + (temp and B(1)));
-- temp := (shift_right(temp,S(2)) + temp) and B(2);
-- temp := (shift_right(temp,S(3)) + temp) and B(3);
-- hw := conv_integer(temp);
-- Other method... slower
-- temp := row;
-- temp := temp - (shift_right(temp,1) and five);
-- temp := (temp and three) + (shift_right(temp,2) and three);
-- temp := temp + shift_right(temp,4) and x"f0f";
-- templ := (temp * x"1010101") ; Should be improve
-- hw := conv_integer(templ(31 downto 24));
hw := hammingWLT_1(conv_integer(row(11 downto 6)))+ hammingWLT_2(conv_integer(row(5 downto 0)));
-- Other method... 125 Mhz
-- temp := row - (shift_right(row,1) and B(0));
-- temp := ((shift_right(temp,S(1)) and B(1))
-- + (temp and B(1)));
-- temp := (shift_right(temp,S(2)) + temp) and B(2);
-- temp := (shift_right(temp,S(3)) + temp) and B(3);
-- hw := conv_integer(temp);
-- Other method... slower
-- temp := row;
-- temp := temp - (shift_right(temp,1) and five);
-- temp := (temp and three) + (shift_right(temp,2) and three);
-- temp := temp + shift_right(temp,4) and x"f0f";
-- templ := (temp * x"1010101") ; Should be improve
-- hw := conv_integer(templ(31 downto 24));
return hw;
end hammingWCal;
--============================================================================
-- hammingWCal_l
--! @brief calculates the hamming weight of a vector, inspired in "Bit Twiddling Hacks"
--! @param word_vector
--! @return hamming weight
--============================================================================
--============================================================================
-- hammingWCal_l
--! @brief calculates the hamming weight of a vector, inspired in "Bit Twiddling Hacks"
--! @param word_vector
--! @return hamming weight
--============================================================================
function hammingWCal_l( row : word_vector) return integer is -- word_vector is
variable temp : word_vector;
variable hW : integer range 0 to 12:=0;
---------------------------------------------------------
variable temp : word_vector;
variable hW : integer range 0 to 12:=0;
---------------------------------------------------------
-- constant five : std_logic_vector(11 downto 0) := x"555";
-- constant three : std_logic_vector(11 downto 0) := x"333";
---------------------------------------------------------
---------------------------------------------------------
--constant B : matrixl := (x"555555", x"333333", x"0F0F0F", x"FF00FF");
--constant B : matrixl := (x"555555", x"333333", x"0F0F0F", x"FF00FF");
-- constant B : matrixl := ( "010101010101010101010101",
-- "001100110011001100110011",
-- "000011110000111100001111",
-- "111111110000000011111111",
-- "000000001111111111111111");
begin
begin
hw := hammingWLT_1(conv_integer(row(23 downto 18)))+ hammingWLT_2(conv_integer(row(17 downto 12)))
+ hammingWLT_3(conv_integer(row(11 downto 6)))+ hammingWLT_4(conv_integer(row(5 downto 0)));
hw := hammingWLT_1(conv_integer(row(23 downto 18)))+ hammingWLT_2(conv_integer(row(17 downto 12)))
+ hammingWLT_3(conv_integer(row(11 downto 6)))+ hammingWLT_4(conv_integer(row(5 downto 0)));
-- Other method... 125 Mhz
-- temp := row - (shift_right_l(row,1) and B(0));
-- temp := ((shift_right_l(temp,S(1)) and B(1))
......@@ -371,7 +369,7 @@ begin
-- temp := (shift_right_l(temp,S(2)) + temp) and B(2);
-- temp := (shift_right_l(temp,S(3)) + temp) and B(3);
-- temp := (shift_right_l(temp,S(4)) + temp) and B(4);
-- Other method... slower
-- temp := row;
-- temp := temp - (shift_right(temp,1) and five);
......@@ -381,52 +379,52 @@ begin
-- hw := conv_integer(templ(31 downto 24));
-- return temp;
return hw;
end hammingWCal_l;
return hw;
end hammingWCal_l;
--============================================================================
-- syndromeCal
--! @brief Calculates the syndrome of a vector 24 bit, and the hamming weight
--! @param vector, "row" with the codeword \n
--! @return the hamming height of codeword and teh syndrome
--============================================================================
function syndromexBCal( synd : data_vector) return syndxBCalset is
variable syndBTemp : syndxBCalset;
variable tempW : integer range 0 to 12;
begin
syndBTemp.syndxB(11) := synd(0) xor synd(1) xor synd(2) xor synd(3) xor synd(4) xor
synd(5) xor synd(6) xor synd(7) xor synd(8) xor synd(9) xor synd(10);
syndBTemp.syndxB(10) := synd(1) xor synd(5) xor synd(6) xor synd(7) xor synd(9) xor
synd(10) xor synd(11);
syndBTemp.syndxB(9) := synd(0) xor synd(2) xor synd(6) xor synd(7) xor synd(8) xor
synd(10) xor synd(11);
syndBTemp.syndxB(8) := synd(0) xor synd(1) xor synd(3) xor synd(7) xor synd(8) xor
synd(9) xor synd(11);
syndBTemp.syndxB(7) := synd(1) xor synd(2) xor synd(4) xor synd(8) xor synd(9) xor
synd(10) xor synd(11);
syndBTemp.syndxB(6) := synd(0) xor synd(2) xor synd(3) xor synd(5) xor synd(9) xor
synd(10) xor synd(11);
syndBTemp.syndxB(5) := synd(0) xor synd(1) xor synd(3) xor synd(4) xor synd(6) xor
synd(10) xor synd(11);
syndBTemp.syndxB(4) := synd(0) xor synd(1) xor synd(2) xor synd(4) xor synd(5) xor
synd(7) xor synd(11);
syndBTemp.syndxB(3) := synd(1) xor synd(2) xor synd(3) xor synd(5) xor synd(6) xor
synd(8) xor synd(11);
syndBTemp.syndxB(2) := synd(2) xor synd(3) xor synd(4) xor synd(6) xor synd(7) xor
synd(9) xor synd(11);
syndBTemp.syndxB(1) := synd(3) xor synd(4) xor synd(5) xor synd(7) xor synd(8) xor
synd(10) xor synd(11);
syndBTemp.syndxB(0) := synd(0) xor synd(4) xor synd(5) xor synd(6) xor synd(8) xor
synd(9) xor synd(11);
tempW := hammingWCal(syndBTemp.syndxB);---1;
syndBTemp.hammingW := tempW;
return syndBTemp;
end syndromexBCal;
function syndromexBCal( synd : data_vector) return syndxBCalset is
variable syndBTemp : syndxBCalset;
variable tempW : integer range 0 to 12;
begin
syndBTemp.syndxB(11) := synd(0) xor synd(1) xor synd(2) xor synd(3) xor synd(4) xor
synd(5) xor synd(6) xor synd(7) xor synd(8) xor synd(9) xor synd(10);
syndBTemp.syndxB(10) := synd(1) xor synd(5) xor synd(6) xor synd(7) xor synd(9) xor
synd(10) xor synd(11);
syndBTemp.syndxB(9) := synd(0) xor synd(2) xor synd(6) xor synd(7) xor synd(8) xor
synd(10) xor synd(11);
syndBTemp.syndxB(8) := synd(0) xor synd(1) xor synd(3) xor synd(7) xor synd(8) xor
synd(9) xor synd(11);
syndBTemp.syndxB(7) := synd(1) xor synd(2) xor synd(4) xor synd(8) xor synd(9) xor
synd(10) xor synd(11);
syndBTemp.syndxB(6) := synd(0) xor synd(2) xor synd(3) xor synd(5) xor synd(9) xor
synd(10) xor synd(11);
syndBTemp.syndxB(5) := synd(0) xor synd(1) xor synd(3) xor synd(4) xor synd(6) xor
synd(10) xor synd(11);
syndBTemp.syndxB(4) := synd(0) xor synd(1) xor synd(2) xor synd(4) xor synd(5) xor
synd(7) xor synd(11);
syndBTemp.syndxB(3) := synd(1) xor synd(2) xor synd(3) xor synd(5) xor synd(6) xor
synd(8) xor synd(11);
syndBTemp.syndxB(2) := synd(2) xor synd(3) xor synd(4) xor synd(6) xor synd(7) xor
synd(9) xor synd(11);
syndBTemp.syndxB(1) := synd(3) xor synd(4) xor synd(5) xor synd(7) xor synd(8) xor
synd(10) xor synd(11);
syndBTemp.syndxB(0) := synd(0) xor synd(4) xor synd(5) xor synd(6) xor synd(8) xor
synd(9) xor synd(11);
tempW := hammingWCal(syndBTemp.syndxB);---1;
syndBTemp.hammingW := tempW;
return syndBTemp;
end syndromexBCal;
end linear_block_package;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use work.linear_block_package.all;
-- The word, "word" is reserved for encoded data 24 bits
-- The word. "data" is reserved for non-encoded data 12 btis
entity linear_block_decoder is
port(
clk: in std_logic;
reset: in std_logic;
data_in: in word_vector;
decoded_out: out data_vector;
errorDecoded_out:out std_logic
);
end linear_block_decoder;
architecture behavioral of linear_block_decoder is
signal syndrome: word_vector :=(others =>'0');
signal errorVector: data_vector :=(others =>'0');
signal sindromexB: data_vector :=(others =>'0');
signal hammingW: integer := 0;
-- fms contral signals
type fms is (idle,step1,step2,step3,step4,deco,fail);
signal deco_state: fms;
signal deco_next : fms;
-- output control signals
signal decoded_buf : data_vector :=(others=>'0');
signal decoded_buf_next: data_vector :=(others=>'0');
-- error when it is not possible to decode
signal errorDecoded: std_logic:='0';
begin
-- decoder finite state machie
deco_fms: process(clk)
begin
if (reset='1') then
deco_state <= idle;
errorDecoded <= '0';
elsif(clk'event and clk='1') then
deco_state <= deco_next;
end if;
end process;
-- decoded output
deco_buffer: process(clk)
begin
if(reset='1') then
decoded_buf <= zeros12;
elsif(clk'event and clk='1') then
decoded_buf <= decoded_buf_next;
end if;
end process;
-- decoder logic
deco_logic: process(deco_state,data_in)
begin
case deco_state is
when idle =>
if (data_in /= zeros24) then
deco_next <= step1;
else
deco_next <= idle;
end if;
when step1 =>
-- calc syndrome and hamming(syndrome)
if (hammingW<=3) then
deco_next <= deco;
else
deco_next <= step2;
end if;
when step2 =>
-- calc error and hammingW(error)
if (hammingW<=2) then
deco_next <= deco;
else
deco_next <= step3;
end if;
when step3 =>
-- syndromexB and hammingW(syndromeB)
if (hammingW<=3) then
deco_next <= deco;
else
deco_next <= step4;
end if;
when step4 =>
-- (Beta*B+rowi) and hammingW
if (hammingW <= 3) then
deco_next <= deco;
else
deco_next <= fail;
end if;
when deco =>
deco_next <= idle;
when fail =>
deco_next <= idle;
end case;
end process;
-- output logic
output_logic: process(deco_state)
begin
decoded_buf_next <= zeros12;
case deco_next is
when idle =>
when step1 =>
when step2 =>
when step3 =>
when step4 =>
when deco =>
--decoded_buf_next <=
errorDecoded <= '0'; -- no error
when fail =>
decoded_buf_next <= zeros12;
errorDecoded <= '1';
end case;
end process;
-- output
decoded_out <= decoded_buf;
end behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity linear_block_enc is
port ( clk : in std_logic;
data_in : in std_logic_vector(11 downto 0);
encoded_out : out std_logic_vector(23 downto 0)
);
end linear_block_enc;
architecture Behavioral of linear_block_enc is
signal check_bits : std_logic_vector(11 downto 0):=(others =>'0');
-- b matrix
-- 555 1 0 1 0 1 0 1 0 1 0 1 0
---------------------------------------------------
-- 11 0 1 2 3 4 5 6 7 8 9 10
-- 10 1 5 6 7 9 10 11
-- 9 0 2 6 7 8 10 11
-- 8 0 1 3 7 8 9 11
-- 7 1 2 4 8 9 10 11
-- 6 0 2 3 5 9 10 11
-- 5 0 1 3 4 6 10 11
-- 4 0 1 2 4 5 7 11
-- 3 1 2 3 5 6 8 11
-- 2 2 3 4 6 7 9 11
-- 1 3 4 5 7 8 10 11
-- 0 0 4 5 6 8 9 11
begin
process(data_in,clk)
begin
if(clk'event and clk='1') then -- parity bits c * b
check_bits(11) <= data_in(0) xor data_in(1) xor data_in(2) xor data_in(3) xor data_in(4) xor data_in(5) xor data_in(6)
xor data_in(7) xor data_in(8) xor data_in(9) xor data_in(10);
check_bits(10) <= data_in(1) xor data_in(5) xor data_in(6) xor data_in(7) xor data_in(9) xor data_in(10) xor data_in(11);
check_bits(9) <= data_in(0) xor data_in(2) xor data_in(6) xor data_in(7) xor data_in(8) xor data_in(10) xor data_in(11);
check_bits(8) <= data_in(0) xor data_in(1) xor data_in(3) xor data_in(7) xor data_in(8) xor data_in(9) xor data_in(11);
check_bits(7) <= data_in(1) xor data_in(2) xor data_in(4) xor data_in(8) xor data_in(9) xor data_in(10) xor data_in(11);
check_bits(6) <= data_in(0) xor data_in(2) xor data_in(3) xor data_in(5) xor data_in(9) xor data_in(10) xor data_in(11);
check_bits(5) <= data_in(0) xor data_in(1) xor data_in(3) xor data_in(4) xor data_in(6) xor data_in(10) xor data_in(11);
check_bits(4) <= data_in(0) xor data_in(1) xor data_in(2) xor data_in(4) xor data_in(5) xor data_in(7) xor data_in(11);
check_bits(3) <= data_in(1) xor data_in(2) xor data_in(3) xor data_in(5) xor data_in(6) xor data_in(8) xor data_in(11);
check_bits(2) <= data_in(2) xor data_in(3) xor data_in(4) xor data_in(6) xor data_in(7) xor data_in(9) xor data_in(11);
check_bits(1) <= data_in(3) xor data_in(4) xor data_in(5) xor data_in(7) xor data_in(8) xor data_in(10) xor data_in(11);
check_bits(0) <= data_in(0) xor data_in(4) xor data_in(5) xor data_in(6) xor data_in(8) xor data_in(9) xor data_in(11);
end if;
end process;
encoded_out <= data_in & check_bits; -- c = [data,check_bits]
end Behavioral;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package linear_block_package is
constant word_width : integer := 24;
constant data_width : integer := 12;
subtype data_vector is std_logic_vector(data_width-1 downto 0);
subtype word_vector is std_logic_vector(word_width-1 downto 0);
-- subtype fsm is std_logic_vector(2 downto 0);
constant zeros12 : data_vector :=(others=>'0');
constant zeros24 : word_vector :=(others=>'0');
type matrix is array (natural range <>) of data_vector;
-- compile with -87 support for VHDL 1987
constant bMatrix : matrix := (to_stdlogicvector(x"7ff"),to_stdlogicvector(x"ee2"),
to_stdlogicvector(x"dc5"),to_stdlogicvector(x"b8b"),
to_stdlogicvector(x"f16"),to_stdlogicvector(x"e2d"),
to_stdlogicvector(x"c5b"),to_stdlogicvector(x"8b7"),
to_stdlogicvector(x"96e"),to_stdlogicvector(x"adc"),
to_stdlogicvector(x"db8"),to_stdlogicvector(x"b71"));
-- calculates the step 1 of the algorithm
-- calc syndrome and hamming(syndrome)
procedure syndromeCal( signal word :in word_vector;
signal hammingW :out integer);
end linear_block_package;
package body linear_block_package is
-- calculates the step 1 of the algorithm
-- calc syndrome and hamming(syndrome)
procedure syndromeCal( signal word :in word_vector;
signal hammingW :out integer) is
begin
end syndromeCal;
end linear_block_package;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment