Line 1... |
Line 1... |
--!
|
--!
|
--! Copyright (C) 2011 - 2012 Creonic GmbH
|
--! Copyright (C) 2011 - 2014 Creonic GmbH
|
--!
|
--!
|
--! This file is part of the Creonic Viterbi Decoder, which is distributed
|
--! This file is part of the Creonic Viterbi Decoder, which is distributed
|
--! under the terms of the GNU General Public License version 2.
|
--! under the terms of the GNU General Public License version 2.
|
--!
|
--!
|
--! @file
|
--! @file
|
Line 27... |
Line 27... |
entity tb_dec_viterbi is
|
entity tb_dec_viterbi is
|
generic(
|
generic(
|
CLK_PERIOD : time := 10 ns; -- Clock period within simulation.
|
CLK_PERIOD : time := 10 ns; -- Clock period within simulation.
|
|
|
BLOCK_LENGTH_START : natural := 200; -- First block length to simulate.
|
BLOCK_LENGTH_START : natural := 200; -- First block length to simulate.
|
BLOCK_LENGTH_END : natural := 300; -- Last block length to simulate.
|
BLOCK_LENGTH_END : natural := 500; -- Last block length to simulate.
|
BLOCK_LENGTH_INCR : integer := 100; -- Increment from one block length to another.
|
BLOCK_LENGTH_INCR : integer := 20; -- Increment from one block length to another.
|
|
|
SIM_ALL_BLOCKS : boolean := true; -- Set to true in order to simulate all blocks within a data file.
|
SIM_ALL_BLOCKS : boolean := true; -- Set to true in order to simulate all blocks within a data file.
|
SIM_BLOCK_START : natural := 396; -- If SIM_ALL_BLOCKS = false, gives block to start simulation with.
|
SIM_BLOCK_START : natural := 0; -- If SIM_ALL_BLOCKS = false, gives block to start simulation with.
|
SIM_BLOCK_END : natural := 398; -- If SIM_ALL_BLOCKS = false, gives last block of simulation.
|
SIM_BLOCK_END : natural := 10; -- If SIM_ALL_BLOCKS = false, gives last block of simulation.
|
|
|
WINDOW_LENGTH : natural := 55; -- Window length to use for simulation.
|
WINDOW_LENGTH : natural := 55; -- Window length to use for simulation.
|
ACQUISITION_LENGTH : natural := 50; -- Acquisition length to use for simulation.
|
ACQUISITION_LENGTH : natural := 50; -- Acquisition length to use for simulation.
|
|
|
DATA_DIRECTORY : string := "../testbench/WiFi_121_91/" -- Path to testbench data, relative to simulation directory.
|
DATA_DIRECTORY : string := "../testbench/WiFi_121_91/" -- Path to testbench data, relative to simulation directory.
|
Line 89... |
Line 89... |
|
|
--
|
--
|
-- Input data send signals.
|
-- Input data send signals.
|
--
|
--
|
|
|
type t_send_data_fsm is (READ_FILE, CONFIGURE, SEND_DATA, SEND_DATA_FINISHED);
|
type t_send_data_fsm is (READ_FILE, CONFIGURE, SEND_DATA, DEASSERT_VALID, SEND_DATA_FINISHED, SEND_FIRST_DATA);
|
signal send_data_fsm : t_send_data_fsm;
|
signal send_data_fsm : t_send_data_fsm;
|
|
|
signal block_send_end : natural;
|
signal block_send_end : natural;
|
|
|
signal current_block : natural;
|
signal current_block : natural;
|
Line 113... |
Line 113... |
|
|
signal first_block_out : natural;
|
signal first_block_out : natural;
|
signal last_block_out : natural;
|
signal last_block_out : natural;
|
signal current_block_out : natural;
|
signal current_block_out : natural;
|
signal current_block_length_out : natural;
|
signal current_block_length_out : natural;
|
signal current_block_length_out_d : natural;
|
|
signal sys_bit_counter_out : natural;
|
signal sys_bit_counter_out : natural;
|
|
|
|
|
-- Get filename that matches to our current configuration.
|
-- Get filename that matches to our current configuration.
|
function get_filename_part(v_block_length : natural;
|
function get_filename_part(v_block_length : natural;
|
Line 128... |
Line 127... |
return "BL_" & str(v_block_length) & "_WL_" & str(v_window_length) & "_AL_" & str(v_acquisition_length);
|
return "BL_" & str(v_block_length) & "_WL_" & str(v_window_length) & "_AL_" & str(v_acquisition_length);
|
end function get_filename_part;
|
end function get_filename_part;
|
|
|
shared variable v_decoded_software : t_nat_array_ptr;
|
shared variable v_decoded_software : t_nat_array_ptr;
|
|
|
|
signal valid_cnt : natural :=0;
|
|
signal ready_cnt : natural :=0;
|
begin
|
begin
|
|
|
clk <= not clk after CLK_PERIOD / 2;
|
clk <= not clk after CLK_PERIOD / 2;
|
|
|
|
|
Line 150... |
Line 151... |
variable v_llr : t_int_array_ptr;
|
variable v_llr : t_int_array_ptr;
|
variable v_filepart_ptr : t_string_ptr;
|
variable v_filepart_ptr : t_string_ptr;
|
variable v_filename_ptr : t_string_ptr;
|
variable v_filename_ptr : t_string_ptr;
|
variable v_num_lines : natural := 0;
|
variable v_num_lines : natural := 0;
|
variable v_num_blocks : natural := 0;
|
variable v_num_blocks : natural := 0;
|
variable v_current_block_length : natural := 0;
|
|
variable v_sys_bit_counter : integer := 0;
|
|
begin
|
begin
|
if rising_edge(clk) then
|
if rising_edge(clk) then
|
if aresetn = '0' then
|
if aresetn = '0' then
|
|
|
-- ctrl_tlast is present but unused in the decoder
|
-- ctrl_tlast is present but unused in the decoder
|
Line 172... |
Line 171... |
current_block <= 0;
|
current_block <= 0;
|
block_send_end <= 0;
|
block_send_end <= 0;
|
sys_bit_counter <= 0;
|
sys_bit_counter <= 0;
|
|
|
send_data_fsm <= READ_FILE;
|
send_data_fsm <= READ_FILE;
|
|
valid_cnt <= 0;
|
|
|
else
|
else
|
|
|
case send_data_fsm is
|
case send_data_fsm is
|
|
|
Line 219... |
Line 219... |
std_logic_vector(to_unsigned(ACQUISITION_LENGTH, BW_MAX_WINDOW_LENGTH));
|
std_logic_vector(to_unsigned(ACQUISITION_LENGTH, BW_MAX_WINDOW_LENGTH));
|
|
|
-- Check whether configuration succeeded
|
-- Check whether configuration succeeded
|
if m_axis_ctrl_tvalid = '1' and m_axis_ctrl_tready = '1' then
|
if m_axis_ctrl_tvalid = '1' and m_axis_ctrl_tready = '1' then
|
m_axis_ctrl_tvalid <= '0';
|
m_axis_ctrl_tvalid <= '0';
|
send_data_fsm <= SEND_DATA;
|
send_data_fsm <= SEND_FIRST_DATA;
|
|
|
else
|
else
|
m_axis_ctrl_tvalid <= '1';
|
m_axis_ctrl_tvalid <= '1';
|
end if;
|
end if;
|
|
|
|
when SEND_FIRST_DATA =>
|
|
for j in 0 to NUMBER_PARITY_BITS - 1 loop
|
|
m_axis_input_tdata(j * 8 + BW_LLR_INPUT - 1 downto j * 8) <=
|
|
std_logic_vector(to_signed(v_llr(current_block * (current_block_length_tail * NUMBER_PARITY_BITS) + sys_bit_counter * NUMBER_PARITY_BITS + j), BW_LLR_INPUT));
|
|
end loop;
|
|
sys_bit_counter <= sys_bit_counter + 1;
|
|
send_data_fsm <= SEND_DATA;
|
|
m_axis_input_tvalid <= '1';
|
|
|
--
|
--
|
-- Send all data of a block. If we are done with this, we check what to do next:
|
-- Send all data of a block. If we are done with this, we check what to do next:
|
-- 1) Configure the decoder to process the next block of the same length.
|
-- 1) Configure the decoder to process the next block of the same length.
|
-- 2) Read a new file if all blocks of this block length were simulated.
|
-- 2) Read a new file if all blocks of this block length were simulated.
|
Line 237... |
Line 246... |
|
|
m_axis_input_tvalid <= '1';
|
m_axis_input_tvalid <= '1';
|
|
|
-- Data transmission => increase bit counter and update data for next cycle.
|
-- Data transmission => increase bit counter and update data for next cycle.
|
if m_axis_input_tvalid = '1' and m_axis_input_tready = '1' then
|
if m_axis_input_tvalid = '1' and m_axis_input_tready = '1' then
|
v_sys_bit_counter := sys_bit_counter + 1;
|
if valid_cnt = 5 then
|
sys_bit_counter <= v_sys_bit_counter;
|
valid_cnt <= 0;
|
|
send_data_fsm <= DEASSERT_VALID;
|
|
m_axis_input_tvalid <= '0';
|
else
|
else
|
v_sys_bit_counter := sys_bit_counter;
|
valid_cnt <= valid_cnt + 1;
|
|
end if;
|
|
sys_bit_counter <= sys_bit_counter + 1;
|
end if;
|
end if;
|
|
|
|
|
if v_sys_bit_counter < current_block_length_tail then
|
if m_axis_input_tvalid = '1' and m_axis_input_tready = '1' then
|
|
if sys_bit_counter < current_block_length_tail then
|
-- trim and move data to stream
|
-- trim and move data to stream
|
for j in 0 to NUMBER_PARITY_BITS - 1 loop
|
for j in 0 to NUMBER_PARITY_BITS - 1 loop
|
m_axis_input_tdata(j * 8 + BW_LLR_INPUT - 1 downto j * 8) <=
|
m_axis_input_tdata(j * 8 + BW_LLR_INPUT - 1 downto j * 8) <=
|
std_logic_vector(to_signed(v_llr(current_block * (current_block_length_tail * NUMBER_PARITY_BITS) + v_sys_bit_counter * NUMBER_PARITY_BITS + j), BW_LLR_INPUT));
|
std_logic_vector(to_signed(v_llr(current_block * (current_block_length_tail * NUMBER_PARITY_BITS) + sys_bit_counter * NUMBER_PARITY_BITS + j), BW_LLR_INPUT));
|
end loop;
|
end loop;
|
end if;
|
end if;
|
|
|
|
|
-- Next data will be last of block
|
-- Next data will be last of block
|
if v_sys_bit_counter = current_block_length_tail - 1 then
|
if sys_bit_counter = current_block_length_tail - 1 then
|
m_axis_input_tlast <= '1';
|
m_axis_input_tlast <= '1';
|
else
|
else
|
m_axis_input_tlast <= '0';
|
m_axis_input_tlast <= '0';
|
end if;
|
end if;
|
|
end if;
|
|
|
-- We have just sent the very last bit of this block.
|
-- We have just sent the very last bit of this block.
|
if m_axis_input_tvalid = '1' and
|
if m_axis_input_tvalid = '1' and m_axis_input_tready = '1' and
|
m_axis_input_tready = '1' and
|
|
m_axis_input_tlast = '1' then
|
m_axis_input_tlast = '1' then
|
-- if v_sys_bit_counter = current_block_length then
|
|
sys_bit_counter <= 0;
|
sys_bit_counter <= 0;
|
m_axis_input_tvalid <= '0';
|
m_axis_input_tvalid <= '0';
|
|
|
-- Did we process the last block of a block length?
|
-- Did we process the last block of a block length?
|
if current_block = block_send_end then
|
if current_block = block_send_end then
|
Line 285... |
Line 298... |
send_data_fsm <= CONFIGURE;
|
send_data_fsm <= CONFIGURE;
|
current_block <= current_block + 1;
|
current_block <= current_block + 1;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
|
when DEASSERT_VALID =>
|
|
send_data_fsm <= SEND_DATA;
|
|
|
--
|
--
|
-- We are done with all blocks, do nothing anynmore.
|
-- We are done with all blocks, do nothing anynmore.
|
--
|
--
|
when SEND_DATA_FINISHED =>
|
when SEND_DATA_FINISHED =>
|
Line 310... |
Line 325... |
begin
|
begin
|
if rising_edge(clk) then
|
if rising_edge(clk) then
|
if aresetn = '0' then
|
if aresetn = '0' then
|
|
|
current_block_length_out <= 0;
|
current_block_length_out <= 0;
|
current_block_length_out_d <= 0;
|
|
sys_bit_counter_out <= 0;
|
sys_bit_counter_out <= 0;
|
s_axis_output_tready <= '1';
|
s_axis_output_tready <= '1';
|
block_receive_complete <= false;
|
block_receive_complete <= false;
|
new_block_length <= false;
|
new_block_length <= false;
|
|
ready_cnt <= 0;
|
|
|
else
|
else
|
|
|
block_receive_complete <= false;
|
block_receive_complete <= false;
|
new_block_length <= false;
|
new_block_length <= false;
|
current_block_length_out_d <= current_block_length_out;
|
s_axis_output_tready <= '1';
|
|
|
-- Data passes the output interface.
|
-- Data passes the output interface.
|
if s_axis_output_tvalid = '1' and s_axis_output_tready = '1' then
|
if s_axis_output_tvalid = '1' and s_axis_output_tready = '1' then
|
|
if ready_cnt = 8 then
|
|
ready_cnt <= 0;
|
|
s_axis_output_tready <= '0';
|
|
else
|
|
ready_cnt <= ready_cnt + 1;
|
|
end if;
|
|
|
decoded_hardware(sys_bit_counter_out) <= s_axis_output_tdata;
|
decoded_hardware(sys_bit_counter_out) <= s_axis_output_tdata;
|
|
|
sys_bit_counter_out <= sys_bit_counter_out + 1;
|
sys_bit_counter_out <= sys_bit_counter_out + 1;
|
|
|
Line 345... |
Line 366... |
v_num_lines := get_num_lines(v_filename_ptr.all);
|
v_num_lines := get_num_lines(v_filename_ptr.all);
|
read_file(v_decoded_software, v_num_lines, BW_LLR_INPUT, v_filename_ptr.all);
|
read_file(v_decoded_software, v_num_lines, BW_LLR_INPUT, v_filename_ptr.all);
|
|
|
if SIM_ALL_BLOCKS then
|
if SIM_ALL_BLOCKS then
|
first_block_out <= 0;
|
first_block_out <= 0;
|
last_block_out <= v_num_lines / (sys_bit_counter_out + 1);
|
last_block_out <= v_num_lines / (sys_bit_counter_out + 1) - 1;
|
else
|
else
|
first_block_out <= SIM_BLOCK_START;
|
first_block_out <= SIM_BLOCK_START;
|
last_block_out <= SIM_BLOCK_END;
|
last_block_out <= SIM_BLOCK_END;
|
end if;
|
end if;
|
|
|
Line 394... |
Line 415... |
(v_decoded_software(v_current_block * current_block_length_out + i) = 1 and decoded_hardware(i) = '0') then
|
(v_decoded_software(v_current_block * current_block_length_out + i) = 1 and decoded_hardware(i) = '0') then
|
|
|
v_bit_error_count := v_bit_error_count + 1;
|
v_bit_error_count := v_bit_error_count + 1;
|
|
|
assert false report "Decoded bit " & str(i) & " in block " & str(v_current_block) & " does not match!"
|
assert false report "Decoded bit " & str(i) & " in block " & str(v_current_block) & " does not match!"
|
severity warning;
|
severity failure;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
-- Dump message.
|
-- Dump message.
|
write(v_line_out, string'("Block length: ") & str(current_block_length_out));
|
write(v_line_out, string'("Block length: ") & str(current_block_length_out));
|
write(v_line_out, string'(", Block: ") & str(current_block_out));
|
write(v_line_out, string'(", Block: ") & str(v_current_block));
|
write(v_line_out, string'(", errors: ") & str(v_bit_error_count));
|
write(v_line_out, string'(", errors: ") & str(v_bit_error_count));
|
|
writeline(output, v_line_out);
|
|
|
if current_block_out /= last_block_out - 1 then
|
|
current_block_out <= current_block_out + 1;
|
current_block_out <= current_block_out + 1;
|
else
|
|
|
if current_block_out = last_block_out then
|
current_block_out <= 0;
|
current_block_out <= 0;
|
|
|
-- Stop simulation, if we are done with all blocks of all block lengths.
|
-- Stop simulation, if we are done with all blocks of all block lengths.
|
if current_block_length_out = BLOCK_LENGTH_END then
|
if current_block_length_out = BLOCK_LENGTH_END then
|
assert false report "End" severity failure;
|
assert false report "Simulation finished with no errors." severity failure;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|