Hamming codec
This library provides functions for Hamming encoding and decoding of data arrays of any width/size.
Supports single error correction/double error detection (SECDED).
Functionality
- Perform Hamming encoding
- Perform Hamming decoding
- Perform parity calculation (odd/even)
The number of parity bits (r) for a data word of length n is given by the equation: 2^r ≥ r + n + 1. The output of the encoder is non-systematic: Position of the parity bits are given by 2^p, p ∈ [0, r). The decoder expects the parity bits of the encoded data to be positioned as above.
More details in nw_hamming_pkg
Example use
Include the libraries:
library nw_codec;
context nw_codec.nw_codec_context;
Example 1: Encode/decode 32bit data array without extra parity bit.
v_ewidth := f_hamming_enc_width(data_array_32bit, false); -- determine word width of encoded array
v_enc_data := new t_slv_arr(0 to data_array_32bit'length - 1)(v_ewidth - 1 downto 0); -- allocate array
v_enc_data := f_hamming_enc(data_array_32bit, false); -- encode data
...
v_dwidth := f_hamming_dec_width(v_enc_data, false); -- determine width of decoded data (32bit + 1 status bit)
v_dec_data := new t_slv_arr(0 to data_array_32bit'length - 1)(v_dwidth - 1 downto 0); -- allocate array
v_dec_data := f_hamming_dec(v_enc_data, false); -- decode data (MSB holds error status)
Example 2: Encode/decode 128bit data array with extra parity bit (SECDED).
v_ewidth := f_hamming_enc_width(data_array_128bit, true); -- determine word width of encoded array
v_enc_data := new t_slv_arr(0 to data_array_128bit'length - 1)(v_ewidth - 1 downto 0); -- allocate array
v_enc_data := f_hamming_enc(data_array_128bit, true); -- encode data
...
v_dwidth := f_hamming_dec_width(v_enc_data, true); -- determine width of decoded data (128bit + 2 status bits)
v_dec_data := new t_slv_arr(0 to data_array_128bit'length - 1)(v_dwidth - 1 downto 0); -- allocate array
v_dec_data := f_hamming_dec(v_enc_data, true); -- decode data (two MSBs hold error status)
See further examples in the test bench nw_codec_tb.vhd.