Removing old files to enable merging from master

This commit is contained in:
gianmarcogirau 2019-04-29 11:46:41 +01:00
commit 00af445c13
3 changed files with 0 additions and 660 deletions

View file

@ -1,55 +0,0 @@
# Simulation macro
#.main clear
# Cleanup libraries
foreach lib [list work OSVVM] {
file delete -force -- $lib
vlib $lib
}
set OSVVM_PATH ../../../common/0/src/test/OSVVM
set COMMON_PATH ../../../common/0/src
set WORKLIB work
vlib ./work
vmap work ./work
# Compile the UUT
vcom -2008 -work $WORKLIB ./../src/encoder_multiply_0.vhd
# Compile the constrained random related packages
vlib OSVVM
vcom -2008 -work OSVVM \
$OSVVM_PATH/RandomBasePkg.vhd \
$OSVVM_PATH/SortListPkg_int.vhd \
$OSVVM_PATH/RandomPkg.vhd \
$OSVVM_PATH/NamePkg.vhd \
$OSVVM_PATH/MessagePkg.vhd \
$OSVVM_PATH/CoveragePkg.vhd
# Compile support files
vcom -2008 -work $WORKLIB $COMMON_PATH/test/common_test_pkg.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/test/log_pkg.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH//test/avalon_verify_pkg.vhd
# Compile the testbench
#vcom -2008 -work $WORKLIB ./../src/test/encoder_mulyiply_tb.vhd
#vsim -t ps work.encoder_multiply_tb
#add wave /encoder_multiply_tb/*
#add wave /encoder_multiply_tb/iUUT/*
# remove warnings from standard numeric/arithmetic packages (speed-up simulation)
set StdArithNoWarnings 1
set NumericStdNoWarnings 1
#do wave_enc_mult.do
#when -label end_of_simulation {test_completed == true} {echo "Simulation Completed"; stop ;}
#run -all
#run 100 us;

View file

@ -1,167 +0,0 @@
-------------------------------------------------------------------------------
-- Title : encoder_multiply
-- Project : Generic
-------------------------------------------------------------------------------
-- File : encoder_multiply_0.vhd
-- Author : Gianmarco Girau
-- Company : Global Inkjet Systems
-- Created : 2019-02-27
-- Last update: 2019-03-04
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Encoder Multiply block
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Port Map:
-- init : clears the internal state when '1'
-- enable : do not update the internal state when '0'
-- mult_sel: mult_value = 2**mult_sel => max is 7
-- delta_t : average time difference between pulses, with signed magnitude,
-- fixed point representation (8 bits mantissa), top bit is the sign:
-- 0 => avg time between pos steps, 1 => avg time between neg steps
-- step_pos_in : positive encoder step, before multiplication
-- step_neg_in : negative encoder step, before multiplication
-- step_pos_out : positive encoder step, before multiplication
-- step_neg_out : negative encoder step, before multiplication
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity encoder_multiply is
port(
reset_n : in std_logic;
clk : in std_logic;
init : in std_logic;
enable : in std_logic;
mult_sel : in std_logic_vector( 2 downto 0);
delta_t : in std_logic_vector(47 downto 0);
step_pos_in : in std_logic;
step_neg_in : in std_logic;
step_pos_out : out std_logic;
step_neg_out : out std_logic);
end encoder_multiply;
architecture rtl of encoder_multiply is
/*
function compute_mult(mult_sel : std_logic_vector(2 downto 0)) return std_logic_vector(7 downto 0) is
variable mult_value : std_logic_vector(7 downto 0);
begin
mult_value := (0 => '1', others => '0') sll(to_integer(unsigned(mult_sel)));
return mult_value;
end function compute_mult;
*/
-- number of bits to represent the maximum multiplication value (e.g. 8 => M = 128)
constant MULT_W : natural := 8;
-- Number of bits used to represent the encoder pulse count, before the multiplication
constant PULSE_CNT_W : natural := 8+1;
-- Number of bits used to represent the encoder pulse count, after the multiplication
constant M_PULSE_CNT_W : natural := (MULT_W + PULSE_CNT_W);
-- To prevent counter saturation, subtract a fixed amount each time the
-- counters exceed a given value
constant NORM_VALUE : natural := 2**(PULSE_CNT_W-2);
signal init_d, step_pos, step_neg : std_logic;
signal m_step_pos, m_step_neg : std_logic;
signal sign, sign_i : std_logic;
signal time_cnt_zero : std_logic;
signal norm_pos, norm_pos_d : std_logic;
signal norm_neg, norm_neg_d : std_logic;
signal mult_val, kmax : std_logic_vector(MULT_W-1 downto 0);
signal pulse_cnt : std_logic_vector(PULSE_CNT_W-1 downto 0);
signal m_pulse_cnt, m_norm_value : std_logic_vector(M_PULSE_CNT_W-1 downto 0);
signal delta_m_pos, delta_m_neg : std_logic_vector(M_PULSE_CNT_W-1 downto 0);
signal time_cnt : std_logic_vector(27 downto 0);
signal m_delta_t : std_logic_vector(38-MULT_W downto 0);
signal delta_t_i : std_logic_vector(38 downto 0);
begin
pSEQ_LOGIC_RST : process(reset_n, clk)
begin
if(reset_n = '0') then
mult_val <= (0 => '1', others => '0');
elsif(clk = '1' and clk'event) then
if(init_d = '1') then
mult_val <= std_logic_vector(to_unsigned(1, MULT_W)) sll(to_integer(unsigned(mult_sel)));
end if;
end if;
end process pSEQ_LOGIC_RST;
pSEQ_LOGIC : process(clk)
variable mult_pulse_cnt : std_logic_vector(M_PULSE_CNT_W-1 downto 0);
begin
if(clk = '1' and clk'event) then
init_d <= init;
kmax <= std_logic_vector(unsigned(mult_val)-1);
if(init_d = '1') then
pulse_cnt <= (others => '0');
elsif(step_pos = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt)+1);
elsif(step_neg = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt)-1);
elsif(norm_pos = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt)-NORM_VALUE);
elsif(norm_neg = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt)+NORM_VALUE);
end if;
if(init_d = '1') then
m_pulse_cnt <= (others => '0');
elsif(m_step_pos = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)+1);
elsif(m_step_neg = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)-1);
elsif(norm_pos = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)-signed(m_norm_value));
elsif(norm_neg = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)+signed(m_norm_value));
end if;
if(m_step_pos = '1' or m_step_neg = '1') then
time_cnt <= m_delta_t(27 downto 0);
elsif(time_cnt_zero = '0') then
time_cnt <= std_logic_vector(unsigned(time_cnt)-1);
end if;
m_delta_t <= delta_t_i srl to_integer(unsigned(mult_sel));
sign <= sign_i;
mult_pulse_cnt := pulse_cnt sll to_integer(unsigned(mult_sel));
delta_m_pos <= std_logic_vector(signed(mult_pulse_cnt) + signed(kmax));
delta_m_neg <= std_logic_vector(signed(mult_pulse_cnt) - signed(kmax));
step_pos_out <= m_step_pos;
step_neg_out <= m_step_neg;
if(signed(pulse_cnt) = NORM_VALUE and norm_pos_d = '0') then
norm_pos <= '1';
else
norm_pos <= '0';
end if;
norm_pos_d <= norm_pos;
if(signed(pulse_cnt) = -NORM_VALUE and norm_neg_d = '0') then
norm_neg <= '1';
else
norm_neg <= '0';
end if;
norm_neg_d <= norm_neg;
m_norm_value <= std_logic_vector(to_unsigned(NORM_VALUE, M_PULSE_CNT_W)) sll (to_integer(unsigned(mult_sel)));
end if;
end process pSEQ_LOGIC;
step_pos <= step_pos_in and enable;
step_neg <= step_neg_in and enable;
delta_t_i <= delta_t(46 downto 8);
sign_i <= delta_t(47);
time_cnt_zero <= '1' when unsigned(time_cnt) = 0 else '0';
m_step_pos <= '1' when sign = '0' and time_cnt_zero = '1' and signed(m_pulse_cnt) < signed(delta_m_pos) else '0';
m_step_neg <= '1' when sign = '1' and time_cnt_zero = '1' and signed(m_pulse_cnt) > signed(delta_m_pos) else '0';
end architecture rtl;

View file

@ -1,438 +0,0 @@
-------------------------------------------------------------------------------
-- Title : encoder_multiply_tb
-- Project : EMB/SMB
-------------------------------------------------------------------------------
-- File : encoder_multiply_tb.vhd
-- Author : GMG
-- Company : Global Inkjet Systems
-- Created : 2019-03-05
-- Last update: 2019-03-05
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Testbench for the encoder_multiply block
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
library OSVVM;
use OSVVM.RandomBasePkg.all;
use OSVVM.RandomPkg.all;
use work.log_pkg.all;
entity encoder_multiply_tb is
-- ..
end entity encoder_multiply_tb;
architecture behav of encoder_multiply_tb is
constant CLK_PERIOD : time := 10 ns;
-- Logging Verbosity Level
constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM;
constant MAX_DIST : natural := 10000;
-- define the percentage of reverse steps, with respect to the intended
-- direction, while advancing the position:
-- 0 => no reverse movement at all
-- 20 => 20% of position increments are in the opposite dirtection
-- 49 => Essentially this is an oscillation around the centre position with a
-- tiny bias in the intended direction!
constant POS_RANDOM_PERC : natural range 0 to 49 := 0; -- define
-----------------------------------------------------------------------------
-- TB Functions / Procedures
-----------------------------------------------------------------------------
procedure wait_latency(
signal clk : in std_logic;
cycles : in natural) is
begin
for i in 1 to cycles loop
wait until clk = '1' and clk'event;
end loop; -- i
end procedure wait_latency;
-----------------------------------------------------------------------------
-- Signal declarations
-----------------------------------------------------------------------------
--
signal test_completed : boolean;
signal configuring : boolean;
signal running : boolean;
signal passed : boolean;
signal failed : boolean;
begin -- architecture behav
clk <= not clk after 0.5*CLK_PERIOD;
-----------------------------------------------------------------------------
-- UUTs
-----------------------------------------------------------------------------
iUUT: entity work.encoder_multiply
port map (
reset_n => reset_n,
clk => clk,
init => init,
enable => enable,
mult_sel => mult_sel,
delta_t => delta_t,
step_pos_in => step_pos_in,
step_neg_in => step_neg_in,
step_pos_out => step_pos_out,
step_neg_out => step_neg_out);
-----------------------------------------------------------------------------
-- Support Logic
-----------------------------------------------------------------------------
pGEN_POS : process(clk)
begin
if(clk = '1' and clk'event) then
if(init = '1') then
abs_pos <= (others => '0');
elsif(step_pos_in = '1') then
abs_pos <= std_logic_vector(unsigned(abs_pos)+1);
elsif(step_neg_in = '1') then
abs_pos <= std_logic_vector(unsigned(abs_pos)-1);
end if;
if(init = '1') then
m_abs_pos <= (others => '0');
elsif(step_pos_out = '1') then
m_abs_pos <= std_logic_vector(unsigned(m_abs_pos)+1);
elsif(step_neg_out = '1') then
m_abs_pos <= std_logic_vector(unsigned(m_abs_pos)-1);
end if;
end if;
end process pGEN_POS;
-----------------------------------------------------------------------------
-- Testbench Logic
-----------------------------------------------------------------------------
pTB_CTRL : process
variable delta_pos : integer := 0;
variable init_pos : integer;
variable dir_m : integer;
variable tot_steps : integer;
variable result : boolean;
variable test_idx : natural;
variable rv : RandomPType;
procedure run_test is
variable steps : integer;
variable sel_dir : integer;
begin
log_header("Test-case " & to_string(test_idx), VMEDIUM);
wait_latency(clk, 1);
if dir = '0' then
dir_m := 1;
else
dir_m := -1;
end if;
init_pos := pos;
-- reset the absolute position memory
enable <= '0';
upd_max_pos <= '0';
upd_min_pos <= '0';
wait_latency(clk, 1);
upd_max_pos <= '1';
upd_min_pos <= '1';
wait_latency(clk, 1);
upd_max_pos <= '0';
upd_min_pos <= '0';
-- restart the divider
wait_latency(clk, 1);
enable <= '1';
wait_latency(clk, INTRA_POS_LATENCY);
-- run the steps
steps := 0;
loop_pos: while steps < tot_steps loop
wait_latency(clk, INTRA_POS_LATENCY);
/*
-- check the result and report
delta_pos := dir_m * (pos - init_pos);
result := check_result(div_ratio, pixel_offset, delta_pos, tot_fire_num, true);
exit loop_pos when result = false;
*/
sel_dir := rv.RandInt(1, 100);
if(sel_dir > POS_RANDOM_PERC) then
-- move in the intended direction
pos <= pos + dir_m;
steps := steps + 1;
else
-- move in the opposite direction
pos <= pos - dir_m;
steps := steps - 1;
end if;
end loop loop_pos;
-- wait the propagation of the latency
wait_latency(clk, INTRA_POS_LATENCY);
-- check the result and report
delta_pos := dir_m * (pos - init_pos);
if(result /= false) then
result := check_result(div_ratio, pixel_offset, delta_pos, tot_fire_num);
end if;
log("div_ratio = " & to_string(div_ratio), VMEDIUM);
end procedure run_test;
begin
-- Set the verbosity level for logging
set_log_verbosity(VERBOSITY_LEVEL);
--set_log_verbosity(VHIGH);
log_header("Fractional Divider verification:", VLOW);
test_completed <= false;
configuring <= false;
running <= false;
passed <= false;
failed <= false;
enable <= '0';
dir <= '1';
-- Reset
reset_n <= '0';
wait for 100 ns;
wait until clk = '1' and clk'event;
reset_n <= '1';
result := true;
test_idx := 0;
---------------------------------------------------------------------------
-- Test-00
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.000;
pixel_offset <= 0.0;
dir <= '0';
tot_steps := 100000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-01
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 1.001;
pixel_offset <= 0.0;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-02
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 1.002;
pixel_offset <= 0.9;
dir <= '1';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-03
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 1.333;
pixel_offset <= 1.5;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-04
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.008;
pixel_offset <= 0.25;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-05
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.000;
pixel_offset <= 0.0;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-06
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.000;
pixel_offset <= 0.25;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-07
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.000;
pixel_offset <= 0.5;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-08
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.000;
pixel_offset <= 0.75;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-09
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.000;
pixel_offset <= 1.0;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-10
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.000;
pixel_offset <= 0.12;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-11
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.000;
pixel_offset <= 0.13;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-12
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 126.0;
pixel_offset <= 0.99;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-13
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 126.0;
pixel_offset <= 0.0;
dir <= '0';
tot_steps := 10000;
run_test;
end if;
---------------------------------------------------------------------------
-- Test-14 - Very long test to check internal-reg-saturation
---------------------------------------------------------------------------
if(result /= false) then
test_idx := test_idx+1;
div_ratio <= 4.000;
pixel_offset <= 0.0;
dir <= '0';
tot_steps := 100000;
run_test;
end if;
---------------------------------------------------------------------------
-- Random Tests
---------------------------------------------------------------------------
for n in 1 to 20 loop
if(result /= false) then
test_idx := test_idx+1;
-- the div_ratio fractional part must be a multiple of 0.001
div_ratio <= 0.001*real(rv.RandInt(1000, 50000));
if((rv.RandInt(1,10) mod 2) = 0) then
dir <= '0';
else
dir <= '1';
end if;
tot_steps := rv.RandInt(5000, 20000);
run_test;
end if;
end loop; -- n
wait for 200 ns;
log_separator_line(VLOW);
if(result = false) then
failed <= true;
log("FAILURE: test completed with errors.", VLOW);
else
passed <= true;
log("SUCCESS: test successfully completed.", VLOW);
end if;
log_separator_line(VLOW);
test_completed <= true;
running <= false;
wait;
end process pTB_CTRL;
end architecture behav;