ELGIP-179 Update test benches forr fire pulse manager to check both POF protocols

This commit is contained in:
Damian Smith 2021-12-02 10:14:05 +00:00
commit c57d41a6c5
5 changed files with 1644 additions and 0 deletions

View file

@ -43,6 +43,8 @@ vmap work ./work
vcom -2008 -work $WORKLIB $COMMON_PATH/sync_reset.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/common_pkg.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/sync_wire.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/sync_pulse.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/sync_pulse_vec_push.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/sync_wire_rEdge.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/altera/sync_fifo.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/queue_and_delay.vhd

View file

@ -0,0 +1,60 @@
# Multi-channel FPM Simulation macro
.main clear
# Cleanup libraries
foreach lib [list work OSVVM] {
file delete -force -- $lib
vlib $lib
}
# Path variables
set OSVVM_PATH ../../../common/0/src/test/OSVVM
set TB_PATH ../src/test
set WORKLIB work
vlib ./work
vmap work ./work
do com_fpm.do --nocleanup
# Compile the testbench support files:
# Compile OSVVM lib
vlib OSVVM
vcom -2008 -work OSVVM $OSVVM_PATH/RandomBasePkg.vhd
vcom -2008 -work OSVVM $OSVVM_PATH/SortListPkg_int.vhd
vcom -2008 -work OSVVM $OSVVM_PATH/RandomPkg.vhd
# Compile the testbench support files:
vcom -2008 -work $WORKLIB $COMMON_PATH/test/common_test_pkg.vhd
vcom -2008 -work $WORKLIB $COMMON_PATH/test/log_pkg.vhd
# Compile the VHDL packages that support bus protocols, memory mapped registers and functional procedures
vcom -2008 -work $WORKLIB $COMMON_PATH/test/avalon_verify_pkg_2.vhd
# Testbench support package
vcom -2008 -work $WORKLIB $TB_PATH/fire_pulse_manager_7_one_tb_pkg.vhd
# Testbench
vcom -2008 -work $WORKLIB $TB_PATH/fire_pulse_manager_7_one_tb.vhd
# Load design
vsim -t ps work.fire_pulse_manager_7_one_tb
# Add waves
#add wave -r sim:/fire_pulse_manager_7_tb/*
do wave_fpm.do
# remove warnings from standard numeric/arithmetic packages (speed-up simulation)
set StdArithNoWarnings 1
set NumericStdNoWarnings 1
when -label end_of_simulation {test_completed == true} {echo "Simulation Completed"; stop ;}
run -all

View file

@ -11,6 +11,7 @@ vlib ./work
vmap work ./work
# Compile the UUT
vcom -2008 -work $WORKLIB $COMMON_PATH/sync_wire.vhd
vcom -2008 -work $WORKLIB ../src/seb_epd_led_gen_7.vhd
# Compile the constrained random related packages

View file

@ -0,0 +1,754 @@
-------------------------------------------------------------------------------
-- Title : fire_pulse_manager_one_tb
-- Project : fire_pulse_manager
-------------------------------------------------------------------------------
-- File : fire_pulse_manager_tb.vhd
-- Author : Christos Spirotis
-- Company : Global Inkjet Systems
-- Created : 2018-08-10
-- Last update: 2020-04-20
-- SVN ID : Git
-- Standard : VHDL'08
-------------------------------------------------------------------------------
-- Description:
-- Testbench for fire pulse manager block with protocol version one
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
use std.textio.all;
use work.fire_pulse_7_pkg.all;
use work.fpm_ctrl_7_pkg.all;
use work.log_pkg.all;
use work.avalon_verify_pkg_2.all;
use work.pulse_generator_5_pkg.all;
use work.enc_pd_emul_2_pkg.all;
use work.fire_pulse_manager_7_one_tb_pkg.all;
library osvvm;
use osvvm.RandomPkg.all;
entity fire_pulse_manager_7_one_tb is
end fire_pulse_manager_7_one_tb;
architecture behav of fire_pulse_manager_7_one_tb is
constant DEV_NUM : integer := 2;
constant RX_CLK_PERIOD : time := CLK_PERIOD / 3; -- clock period for used by the
-- UART-Rx on the POF
constant POF_DELAY : time := 30 ns; -- Total delay from POF-Tx input to POF-Rx output
constant ENC_PPR : natural := 10000;
constant ENC_FREQ : enc_freq_t := 1.0e6;
constant PD_PULSE_W : pd_pulse_width_t := 0.5;
constant PD_PERIOD : pd_period_t := 2.0;
constant NUM_ITERATIONS : natural := 5;
constant SWATHE_LEN : integer := 2000;
constant IMAGE_SIZE : integer := 100;
constant DIV_RATIO : real := 5.0;
constant SUBPIX_PHASES : integer := 5;
constant SEL_SUBPIX_PH : integer := 4;
constant START_DIR : enc_dir_t := DIR_0;
-- when DRIVE_DROP_WATCH is true, FPM output pof_tx is driven with the
-- drop-watch signal
constant DRIVE_DROP_WATCH : boolean := true;
constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM;
type ch_offset_t is array (0 to CH_NUM - 1) of integer;
signal ch_offset : ch_offset_t := (others => 0);
type fire_pulse_t is array (0 to CH_NUM - 1) of std_logic_vector(31 downto 0);
signal ch_fire_pulse : fire_pulse_t;
signal ch_start_of_image : fire_pulse_t;
type avs_read_bus_t is array (0 to DEV_NUM - 1) of std_logic_vector(31 downto 0);
signal reset_n : std_logic := '0';
signal clk : std_logic := '0';
signal rx_clk : std_logic := '0';
signal pof_tx, pof_rx : std_logic;
signal fire_pulse : std_logic_vector(32 * CH_NUM - 1 downto 0);
signal start_of_image : std_logic_vector(32 * CH_NUM - 1 downto 0);
signal avs_address : std_logic_vector(14 downto 0);
signal avs_write : std_logic_vector(DEV_NUM - 1 downto 0);
signal avs_writedata : std_logic_vector(31 downto 0);
signal avs_read : std_logic_vector(DEV_NUM - 1 downto 0);
signal avs_readdata : avs_read_bus_t;
--
signal init_tx : std_logic;
signal inc_pos : std_logic;
signal dec_pos : std_logic;
signal abs_position : std_logic_vector(31 downto 0);
signal tx_data : std_logic;
signal pof_tx_avs_rv : std_logic;
signal pof_tx_avs_we_d : std_logic;
signal enc_p1 : std_logic;
signal enc_p2 : std_logic;
signal pd : std_logic;
signal seb_epd_enc_p1 : std_logic;
signal seb_epd_enc_p2 : std_logic;
signal seb_epd_pd : std_logic;
--
signal emul_address : std_logic_vector(9 downto 0);
signal emul_write : std_logic;
signal emul_writedata : std_logic_vector(31 downto 0);
signal emul_read : std_logic;
signal emul_readdata : std_logic_vector(31 downto 0);
signal emul_inc_pos : std_logic;
signal emul_dec_pos : std_logic;
signal emul_pos : std_logic_vector(39 downto 0);
--
signal enc_dir : enc_dir_t;
signal swathe_cnt : integer;
signal half_swathe_cnt : integer;
signal swathe_pos : integer;
signal end_of_swathe : std_logic;
signal test_completed : boolean;
signal running : boolean;
signal configuring : boolean;
signal passed : boolean;
signal failed : boolean;
signal stimuli_completed : boolean;
--
shared variable error_flag : boolean;
signal registers_read : boolean := false;
signal reprogram_offset : boolean := false;
--
signal avs_m : mm_m_rec_t;
signal avs_s : mm_s_rec_t;
signal sel_slave_0 : std_logic;
signal sel_slave_1 : std_logic;
signal emul_s : mm_s_rec_t;
signal emul_m : mm_m_rec_t;
--
type pd_cnt_t is array (0 to CH_NUM - 1) of integer;
signal pd_cnt : pd_cnt_t;
type fp_cnt_t is array (0 to CH_NUM - 1) of integer;
signal fp_cnt : fp_cnt_t;
signal loc_fp_cnt : fp_cnt_t;
signal rst_fp_cnt : std_logic;
signal ch_pulse_out : std_logic_vector(CH_NUM - 1 downto 0);
signal ch_pulse_out_d : std_logic_vector(CH_NUM - 1 downto 0);
signal ch_start_of_img : std_logic_vector(CH_NUM - 1 downto 0);
--
signal run_dw : std_logic;
signal dw : std_logic;
signal dw_d : std_logic;
signal dw_cnt : natural;
--
signal input_mode : fpm_input_type_t;
--
signal ext_pulse : std_logic;
signal ext_pulse_enable : std_logic;
begin -- behav
clk_pr : process
begin
clk <= '0';
wait for 0.5 * CLK_PERIOD;
clk <= '1';
wait for 0.5 * CLK_PERIOD;
end process clk_pr;
rx_clk_pr : process
begin
rx_clk <= '0';
wait for 0.5 * RX_CLK_PERIOD;
rx_clk <= '1';
wait for 0.5 * RX_CLK_PERIOD;
end process rx_clk_pr;
-----------------------------------------------------------------------------
-- DUTs : Fire Pulse Manager
-----------------------------------------------------------------------------
-- FIXME test FPM with pof protocol version 1
iDUT : entity work.fire_pulse_manager_7
generic map(
SEB_EPD_MODE => true,
CH_NUM => CH_NUM)
port map(
reset_n => reset_n,
clk => clk,
rx_clk => rx_clk,
pof_rx => pof_rx,
pof_tx => pof_tx,
seb_epd_enc_p1 => seb_epd_enc_p1,
seb_epd_enc_p2 => seb_epd_enc_p2,
seb_epd_pd => seb_epd_pd,
fire_pulse => fire_pulse,
start_of_image => start_of_image,
mon_pt => open,
ins_fpm_irq_0 => open,
ins_fpm_irq_1 => open,
ins_fpm_irq_2 => open,
ins_fpm_irq_3 => open,
avs_address => avs_address,
avs_write => avs_write(0),
avs_writedata => avs_writedata,
avs_read => avs_read(0),
avs_readdata => avs_readdata(0));
pof_rx <= transport tx_data after POF_DELAY when ext_pulse_enable = '0' else ext_pulse;
-----------------------------------------------------------------------------
-- Split subpixel phases
-----------------------------------------------------------------------------
pSPLIT_SUBPIX_PH : process(all)
begin
for i in 0 to CH_NUM - 1 loop
ch_fire_pulse(i) <= fire_pulse(32 * i + 31 downto 32 * i);
ch_start_of_image(i) <= start_of_image(32 * i + 31 downto 32 * i);
ch_pulse_out(i) <= ch_fire_pulse(i)(0);
ch_start_of_img(i) <= ch_start_of_image(i)(SEL_SUBPIX_PH - 1);
end loop; -- i
end process pSPLIT_SUBPIX_PH;
-----------------------------------------------------------------------------
-- Encoder/PD emulator (Stimuli Generator)
-----------------------------------------------------------------------------
-- The Emulator provides the Encoder and PD stimuli to the FPM:
-- When using the SEB-POF, the encoder stimuli is given by the absolute position.
-- A POF-Transmitter block (below) encodes the Absolute position and PD
-- events according to the POF-Protocol format.
-- When using the SEB-EPD, the encoder phase-1/2 outputs of the emulator are
-- directly fed as inputs to the FPM
iEMUL : entity work.enc_pd_emul_2
port map(
clk => clk,
reset_n => reset_n,
ttl_pd => open,
ttl_enc_p1 => open,
ttl_enc_p2 => open,
ttl_enc_zp => open,
rs422_pd => pd,
rs422_enc_p1 => enc_p1,
rs422_enc_p2 => enc_p2,
rs422_enc_zp => open,
abs_pos_out => emul_pos,
set_pos_out => open,
inc_pos_out => inc_pos,
dec_pos_out => dec_pos,
avs_address => emul_address,
avs_write => emul_write,
avs_writedata => emul_writedata,
avs_read => emul_read,
avs_readdata => emul_readdata);
abs_position <= emul_pos(31 downto 0);
seb_epd_pd <= pd;
seb_epd_enc_p1 <= enc_p1;
seb_epd_enc_p2 <= enc_p2;
-----------------------------------------------------------------------------
-- POF Tx (Stimuli Generator)
-----------------------------------------------------------------------------
iPOF_TX : entity work.pof_tx_2
port map(
reset_n => reset_n,
clk => clk,
init => init_tx,
pd_in => pd,
print_start => open,
pof_protocol_version => '1',
inc_pos => inc_pos,
dec_pos => dec_pos,
abs_position => abs_position,
tx_data => tx_data,
avs_address => avs_address(2 downto 0),
avs_write => avs_write(1),
avs_writedata => avs_writedata,
avs_read => avs_read(1),
avs_readdata => avs_readdata(1));
-----------------------------------------------------------------------------
-- Stimuli Generation
-----------------------------------------------------------------------------
pSTIMULI : process
variable end_of_stimuli : boolean;
variable swathe_completed : boolean;
variable pd_pos : integer;
variable rv : RandomPType;
begin
-- initialization
init_tx <= '0';
enc_dir <= START_DIR;
swathe_pos <= 0;
--
swathe_cnt <= 0;
half_swathe_cnt <= 0;
stimuli_completed <= false;
end_of_swathe <= '0';
--
mm_m_init(emul_m, use_readvalid => false);
-- generating the stimulus
if (running /= true) then
wait until running = true;
end if;
wait for 200 ns;
-- Set the initial absolute-position for the encoder emulator
set_enc_abs_pos(40x"0", emul_s, emul_m);
-- Send a Init/Sync pulse to the POF-Tx
wait until clk = '1' and clk'event;
init_tx <= '1';
wait until clk = '1' and clk'event;
init_tx <= '0';
wait for 500 ns;
--
-- generate the forward swathe
end_of_stimuli := false;
while end_of_stimuli = false loop
--swathe_pos <= 0;
for i in 0 to CH_NUM - 1 loop
ch_offset(i) <= rv.RandInt(0, 199);
--ch_offset(i) <= 50;
end loop;
reprogram_offset <= true;
wait until configuring = true;
reprogram_offset <= false;
wait until configuring = false;
wait until clk = '1' and clk'event;
-- start running the encoder
run_enc_pulses(ENC_FREQ, enc_dir, true, SWATHE_LEN, ENC_PPR, emul_s, emul_m);
if (enc_dir = DIR_0) then
log("Running Swathe " & to_string(swathe_cnt + 1) & ", DIR-0.", VMEDIUM);
else
log("Running Swathe " & to_string(swathe_cnt + 1) & ", DIR-1.", VMEDIUM);
end if;
-- issue a PD to start firing
pd_pos := rv.RandInt(0, 49);
--pd_pos := 10;
for k in 1 to pd_pos loop
wait until abs_position'event;
end loop; -- k
run_pd_pulses(PD_PULSE_W, PD_PERIOD, true, emul_s, emul_m);
swathe_completed := false;
while swathe_completed = false loop
wait for 500 ns;
-- Check whether the encoder generation has completed
check_max_pulses_done(swathe_completed, emul_s, emul_m);
end loop;
wait for 25 us;
half_swathe_cnt <= half_swathe_cnt + 1;
wait until clk = '1' and clk'event;
end_of_swathe <= '1';
wait until clk = '1' and clk'event;
end_of_swathe <= '0';
-- reverse direction
if (enc_dir /= START_DIR) then
-- The number of iterations is doubled, to take into account POF and
-- EPD input types
if (swathe_cnt = 2 * NUM_ITERATIONS - 1) then
end_of_stimuli := true;
else
swathe_cnt <= swathe_cnt + 1;
end if;
end if;
if (end_of_stimuli = false) then
wait until clk = '1' and clk'event;
if (enc_dir = DIR_0) then
enc_dir <= DIR_1;
else
enc_dir <= DIR_0;
end if;
-- Wait some time to make sure the change of direction is transmitted.
-- Note: if the position starts changing before the receiver was able to
-- confirm the change of direction, then some encoder pulses may not be
-- generated
wait for 1 us;
wait until clk = '1' and clk'event;
end if;
end loop; -- end_of_stimuli = false
stimuli_completed <= true;
wait;
end process pSTIMULI;
--
pGEN_EXT_PULSE : process
begin
ext_pulse <= '0';
if ext_pulse_enable = '0' then
wait until ext_pulse_enable = '1';
end if;
wait for 200 ns;
for n in 0 to 11 loop
ext_pulse <= '1';
if n = 5 or n = 6 then
wait for 170 ns;
ext_pulse <= '0';
wait for 30 ns;
else
wait for 200 ns;
ext_pulse <= '0';
end if;
wait for 800 ns;
end loop; -- n
if ext_pulse_enable = '1' then
wait until ext_pulse_enable = '0';
end if;
end process pGEN_EXT_PULSE;
-----------------------------------------------------------------------------
-- Testbench Control
-----------------------------------------------------------------------------
dw <= pof_tx when run_dw = '1' else '0';
pOUT_CHECK_REGs : process(reset_n, clk)
begin
if (reset_n = '0') then
ch_pulse_out_d <= (others => '0');
loc_fp_cnt <= (others => 0);
dw_d <= '0';
dw_cnt <= 0;
elsif (clk = '1' and clk'event) then
ch_pulse_out_d <= ch_pulse_out;
for n in 0 to CH_NUM - 1 loop
if (rst_fp_cnt = '1') then
loc_fp_cnt(n) <= 0;
elsif (ch_pulse_out(n) = '1' and ch_pulse_out_d(n) = '0') then
loc_fp_cnt(n) <= loc_fp_cnt(n) + 1;
end if;
end loop; -- n
-- Check the number of generated fire-requests at the end of the swathe
if (end_of_swathe = '1') then
for n in 0 to CH_NUM - 1 loop
if (loc_fp_cnt(n) /= half_swathe_cnt * IMAGE_SIZE) then
log("ERROR on Channel CH" & integer'image(n) & ": Expected Fire-Requests = " & to_string(half_swathe_cnt * IMAGE_SIZE) & ", detected Fire-Requests = " & to_string(loc_fp_cnt(n)), VLOW, true);
error_flag := true;
end if;
end loop; -- n
end if;
dw_d <= dw;
if (run_dw = '0') then
dw_cnt <= 0;
elsif (dw = '1' and dw_d = '0') then
dw_cnt <= dw_cnt + 1;
end if;
end if;
end process pOUT_CHECK_REGs;
pTB_CTRL : process
type fp_arrived_t is array (0 to CH_NUM - 1) of boolean;
variable fp_arrived : fp_arrived_t;
type fp_arrived_pos_t is array (0 to CH_NUM - 1) of integer;
variable fp_arrived_pos : fp_arrived_pos_t;
variable fp_arrived_agg : integer;
variable pd_arrived_pos : integer;
alias pd_spy is <<signal iDUT.pd_pulse : std_logic>>;
alias abs_spy is <<signal iDUT.abs_pos : std_logic_vector(31 downto 0)>>;
begin
-- Set the verbosity level for logging
set_log_verbosity(VERBOSITY_LEVEL);
--set_log_verbosity(VHIGH);
log_header("Multi-channel FPM verification:", VLOW);
running <= false;
passed <= false;
error_flag := false;
-- Reset
reset_n <= '0';
wait for 100 ns;
wait until clk = '1' and clk'event;
reset_n <= '1';
if (configuring /= true) then
wait until configuring = true;
end if;
wait until configuring = false;
running <= true;
while stimuli_completed = false loop
wait until ((pd_spy = '1' and pd_spy'event) or stimuli_completed);
if (stimuli_completed) then
exit;
end if;
pd_arrived_pos := to_integer(signed(abs_spy));
for i in 0 to CH_NUM - 1 loop
fp_arrived(i) := false;
fp_arrived_pos(i) := 0;
end loop;
log("Product detect fired @ " & integer'image(pd_arrived_pos) & " ... ", VLOW, true);
fp_arrived_agg := 0;
while fp_arrived_agg < CH_NUM loop
fp_arrived_agg := 0;
for i in 0 to CH_NUM - 1 loop
if fp_arrived(i) = true then
fp_arrived_agg := fp_arrived_agg + 1;
end if;
end loop;
wait until (unsigned(ch_pulse_out) /= 0 or stimuli_completed);
if (stimuli_completed) then
exit;
end if;
for i in 0 to CH_NUM - 1 loop
if ch_pulse_out(i) = '1' and fp_arrived(i) = false then
fp_arrived(i) := true;
fp_arrived_pos(i) := to_integer(signed(abs_spy));
log("Channel CH" & integer'image(i) & " Fire pulse logged @ " & integer'image(fp_arrived_pos(i)) & " ... ", VLOW, true);
if (abs (pd_arrived_pos - fp_arrived_pos(i)) /= ch_offset(i)) then
log("ERROR on Channel CH" & integer'image(i) & ": First Fire-Pulse detected at position " & to_string(fp_arrived_pos(i)) & ", expected position is " & to_string((pd_arrived_pos + ch_offset(i))), VLOW, true);
error_flag := true;
end if;
end if;
end loop;
end loop;
end loop;
if (stimuli_completed = true) then
-- wait enough time to make sure that a max length package can be propagated
wait for 20 us;
end if;
if (registers_read = false) then
wait until registers_read = true;
end if;
-- Report PD and FP counter from pulse generator
for i in 0 to CH_NUM - 1 loop
log("Channel CH" & integer'image(i) & " PD-in counter value : " & integer'image(pd_cnt(i)) & " ... ", VLOW, true);
log("Channel CH" & integer'image(i) & " FP-out counter value : " & integer'image(fp_cnt(i)) & " ... ", VLOW, true);
log("Channel CH" & integer'image(i) & " Detected Fire-Pulses : " & integer'image(loc_fp_cnt(i)) & " ... ", VLOW, true);
if (pd_cnt(i) /= (NUM_ITERATIONS) * 2 * 2) then -- fire_pulse_manager now has no registers beyond channel 0
log("Channel CH" & integer'image(i) & " PD_cnt counter value Incorrect: ", VLOW, true);
error_flag := true;
end if;
if ((loc_fp_cnt(i) /= (NUM_ITERATIONS) * 2 * 2 * IMAGE_SIZE) or (fp_cnt(i) /= (NUM_ITERATIONS) * 2 * 2 * IMAGE_SIZE)) then
log("Channel CH" & integer'image(i) & " FP_cnt counter value Incorrect: ", VLOW, true);
error_flag := true;
end if;
end loop;
wait until clk = '1' and clk'event;
running <= false;
passed <= true after 100 ns;
wait;
end process pTB_CTRL;
pFAILED : process
begin
failed <= false;
while true loop
wait for 1 us;
if (error_flag = true) then
failed <= true;
end if;
end loop;
end process pFAILED;
pREPORT_RESULT : process
begin
wait until failed = true or passed = true;
wait for 1 us;
log_separator_line(VLOW);
if (failed = true) then
log("FAILURE: test completed with errors.", VLOW);
elsif (passed = true) then
log("SUCCESS: test successfully completed.", VLOW);
end if;
log_separator_line(VLOW);
test_completed <= true;
end process pREPORT_RESULT;
pUUT_CTRL : process
variable addr : std_logic_vector(31 downto 0) := (others => '0');
variable data : std_logic_vector(31 downto 0) := (others => '0');
begin
sel_slave_0 <= '0';
sel_slave_1 <= '0';
rst_fp_cnt <= '0';
configuring <= true;
input_mode <= POF_INPUT;
run_dw <= '0';
-- Initialize avalon mm interfaces
mm_m_init(avs_m, use_waitrequest => false);
if (reset_n = '0') then
wait until reset_n = '1';
wait for 100 ns;
wait until clk = '1' and clk'event;
end if;
log("Driving external pulses ... ", VLOW, true);
ext_pulse_enable <= '1';
wait for 20 us;
ext_pulse_enable <= '0';
wait for 1 us;
wait until clk = '1' and clk'event;
rst_fp_cnt <= '1';
wait until clk = '1' and clk'event;
rst_fp_cnt <= '0';
log("Configuring POFTX ... ", VLOW, true);
sel_slave_1 <= '1';
-- enable the block
addr := std_logic_vector(to_unsigned(0, 32));
data := X"0000_0021";
mm_32b_write(addr, data, avs_s, avs_m);
sel_slave_1 <= '0';
sel_slave_0 <= '1';
wait until clk = '1' and clk'event;
log("Configuring FPM ... ", VLOW, true);
fpm_ctrl_config(avs_s, avs_m);
fpm_ems_config(avs_s, avs_m);
config_pg_l : for i in 0 to CH_NUM - 1 loop
pulse_gen_config(i, ch_offset(i), DIV_RATIO, SUBPIX_PHASES, IMAGE_SIZE, avs_s, avs_m);
end loop config_pg_l;
log("Configuration completed.", VLOW, true);
configuring <= false;
log_separator_line(VLOW);
log("POF input mode verification", VLOW, true);
log_separator_line(VLOW);
fpm_input_config(input_mode, avs_s, avs_m);
if (DRIVE_DROP_WATCH = true) then
drop_watch_config('1', "0001", 15, avs_s, avs_m);
end if;
while stimuli_completed = false loop
wait until reprogram_offset = true or stimuli_completed = true;
if (stimuli_completed) then
exit;
end if;
log("Reading counters ... ", VLOW, true);
-- Read PD and FP counter from pulse generator
for i in 0 to CH_NUM - 1 loop
fpm_reg_read(PG_CH_ID + i, work.pulse_generator_5_pkg.CSR_PD_COUNTER_ADDR, data, avs_s, avs_m);
pd_cnt(i) <= to_integer(unsigned(data));
fpm_reg_read(PG_CH_ID + i, work.pulse_generator_5_pkg.CSR_FIRE_REQ_COUNTER_ADDR, data, avs_s, avs_m);
fp_cnt(i) <= to_integer(unsigned(data));
wait until clk = '1' and clk'event;
log("CH-" & to_string(i) & ": pd_in_cnt = " & to_string(pd_cnt(i)) & ", fire_req_cnt = " & to_string(fp_cnt(i)) & ", detected fire-req-cnt = " & to_string(loc_fp_cnt(i)), VMEDIUM);
end loop;
configuring <= true;
-- Reprogram the input to EPD and repeat the same number of iterations
if (swathe_cnt = NUM_ITERATIONS) then
log_separator_line(VLOW);
log("EPD input mode verification", VLOW, true);
log_separator_line(VLOW);
input_mode <= EPD_INPUT;
wait until clk = '1' and clk'event;
fpm_input_config(input_mode, avs_s, avs_m);
if (DRIVE_DROP_WATCH = true) then
drop_watch_config('1', "0001", 15, avs_s, avs_m);
end if;
run_dw <= '1';
end if;
log("Reprogramming offset ... ", VLOW, true);
config_of_l : for i in 0 to CH_NUM - 1 loop
ch_offset_config(i, ch_offset(i), avs_s, avs_m);
end loop;
configuring <= false;
end loop;
log("Reading counters ... ", VLOW, true);
-- Read PD and FP counter from pulse generator
for i in 0 to CH_NUM - 1 loop
fpm_reg_read(PG_CH_ID + i, work.pulse_generator_5_pkg.CSR_PD_COUNTER_ADDR, data, avs_s, avs_m);
pd_cnt(i) <= to_integer(unsigned(data));
fpm_reg_read(PG_CH_ID + i, work.pulse_generator_5_pkg.CSR_FIRE_REQ_COUNTER_ADDR, data, avs_s, avs_m);
fp_cnt(i) <= to_integer(unsigned(data));
wait until clk = '1' and clk'event;
log("CH-" & to_string(i) & ": pd_in_cnt = " & to_string(pd_cnt(i)) & ", fire_req_cnt = " & to_string(fp_cnt(i)), VMEDIUM);
end loop;
registers_read <= true;
wait;
end process pUUT_CTRL;
clk_clk <= clk;
reset_reset_n <= reset_n;
avs_s.mm_readdata <= avs_readdata(0) when sel_slave_0 = '1' else
avs_readdata(1) when sel_slave_1 = '1' else (others => '0');
avs_s.mm_readdatavalid <= '0';
avs_s.mm_waitrequest <= '0';
avs_address <= avs_m.mm_address(avs_address'range);
avs_write(0) <= avs_m.mm_write and sel_slave_0;
avs_write(1) <= avs_m.mm_write and sel_slave_1;
avs_writedata <= avs_m.mm_writedata;
avs_read(0) <= avs_m.mm_read and sel_slave_0;
avs_read(1) <= avs_m.mm_read and sel_slave_1;
-- Emulator Avalon bus maapings
emul_s.mm_readdata <= emul_readdata;
emul_s.mm_readdatavalid <= '0';
emul_s.mm_waitrequest <= '0';
emul_address <= emul_m.mm_address(emul_address'range);
emul_writedata <= emul_m.mm_writedata;
emul_write <= emul_m.mm_write;
emul_read <= emul_m.mm_read;
end behav;

View file

@ -0,0 +1,827 @@
-------------------------------------------------------------------------------
-- Title : fire_pulse_manager_7_one_tb_pkg
-- Project : SMB
-------------------------------------------------------------------------------
-- File : fire_pulse_manager_7_one_tb_pkg.vhd
-- Author : Gianmarco Girau
-- Company : Global Inkjet Systems
-- Created : 2020-01-02
-- Last update: 2021-01-06
-- SVN ID : Git
-- Standard : VHDL'2008
-------------------------------------------------------------------------------
-- Description:
-- Support package for the FPM testbench
-------------------------------------------------------------------------------
--library std;
--use std.textio.all;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_textio.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
library work;
use work.fire_pulse_7_pkg.all;
use work.ems_1_pkg.all;
use work.fpm_ctrl_7_pkg.all;
library OSVVM;
use OSVVM.RandomBasePkg.all;
use OSVVM.RandomPkg.all;
library work;
use work.log_pkg.all;
use work.avalon_verify_pkg_2.all;
use work.enc_pd_emul_2_pkg.all;
package fire_pulse_manager_7_one_tb_pkg is
constant CLK_PERIOD : time := 10.0 ns;
constant CLK_FREQ : real := 100.0e6;
constant CH_NUM : integer := 4;
constant BLK_NUM : natural := 6 + CH_NUM;
constant ENC_NCO_WIDTH : positive := 32;
-- Logging Verbosity Level
constant VERBOSITY_LEVEL : verb_level_t := VMEDIUM;
type fpm_input_type_t is (POF_INPUT, EPD_INPUT, INTERNAL);
-----------------------------------------------------------------------------
-- FPM Configuration
-----------------------------------------------------------------------------
-- fpm_reg_write with addr defined as std_logic_vector
procedure fpm_reg_write(
blk_id : in natural range 0 to BLK_NUM-1;
addr : in std_logic_vector;
data : in std_logic_vector(31 downto 0);
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
-- fpm_reg_write with addr defined as integer
procedure fpm_reg_write(
blk_id : in natural range 0 to BLK_NUM-1;
addr : in integer;
data : in std_logic_vector(31 downto 0);
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
-- fpm_reg_read with addr defined as std_logic_vector
procedure fpm_reg_read(
blk_id : in natural range 0 to BLK_NUM-1;
addr : in std_logic_vector;
data : out std_logic_vector(31 downto 0);
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
-- fpm_reg_read with addr defined as integer
procedure fpm_reg_read(
blk_id : in natural range 0 to BLK_NUM-1;
addr : in integer;
data : out std_logic_vector(31 downto 0);
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
procedure fpm_ctrl_config(
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
procedure ch_offset_config(
ch_id : in natural;
ch_offset : in natural;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
procedure ch_ctrl_config(
ch_id : in natural;
pixel_num : in natural;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
procedure pulse_gen_config(
ch_id : in natural;
ch_offset : in natural;
div_ratio : in real;
subpix_phases : in natural;
pixel_num : in natural;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
procedure fpm_input_config(
input_type : in fpm_input_type_t;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
procedure fpm_ems_config(
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
procedure drop_watch_config(
enable : in std_logic;
src : in std_logic_vector(3 downto 0);
pulse_witdth : in natural;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t);
-----------------------------------------------------------------------------
-- ENC/PD Emulator Configuration
-----------------------------------------------------------------------------
type enc_phase_t is (SINGLE_PHASE, DUAL_PHASE);
type enc_edge_t is (RISING, FALLING, RISING_AND_FALLING);
type pd_edge_t is (RISING, FALLING, RISING_AND_FALLING);
subtype enc_freq_t is real range 0.0e3 to 10.0e6;
subtype pd_pulse_width_t is real range 0.0 to 1000.0; -- PD period in us
--subtype pd_period_t is real range 50.0 to 1.0e6; -- PD period in us
subtype pd_period_t is real range 0.5 to 1.0e6; -- PD period in us
type enc_dir_t is (DIR_0, DIR_1);
type emul_cfg_t is record
enc_res : real;
enc_ppr : integer;
enc_phase : enc_phase_t;
enc_edge : enc_edge_t;
enc_dir : enc_dir_t;
pd_edge : pd_edge_t;
enc_freq : enc_freq_t;
pd_pulse_w : pd_pulse_width_t;
pd_period : pd_period_t;
enc_pulses : integer;
end record emul_cfg_t;
-- set abs-pos
procedure set_enc_abs_pos(
abs_pos : in std_logic_vector(39 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
-- The ENC/PD emulator configuration is derived from the EMS
procedure apply_enc_pd_emul_cfg(
cfg : in emul_cfg_t;
init : in boolean := true;
run_pulses_mode : in boolean := false;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
-- Stop the ENC/PD emulator
procedure stop_enc_pd_emul(
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
procedure check_max_pulses_done(
done : out boolean;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
-- Run a fix number of encoder pulses
procedure run_enc_pulses(
enc_freq : in enc_freq_t;
direction : in enc_dir_t;
double_ph_mode : in boolean := true;
num_pulses : in integer;
enc_ppr : in integer;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
-- Run PD pulses: either single pulse or periodic mode
procedure run_pd_pulses(
pulse_width : in pd_pulse_width_t;
pd_period : in pd_period_t;
single_pulse_mode : in boolean := false;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t);
-----------------------------------------------------------------------------
-- Support functions
-----------------------------------------------------------------------------
-- generate the NCO increment corresponding to a given output frequency
function freq2NCO_inc(
f_out : real; f_clk : real) return std_logic_vector;
end fire_pulse_manager_7_one_tb_pkg;
package body fire_pulse_manager_7_one_tb_pkg is
-----------------------------------------------------------------------------
-- FPM Configuration
-----------------------------------------------------------------------------
-- fpm_reg_write with addr defined as std_logic_vector
procedure fpm_reg_write(
blk_id : in natural range 0 to BLK_NUM-1;
addr : in std_logic_vector;
data : in std_logic_vector(31 downto 0);
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable address : std_logic_vector(31 downto 0);
begin
address := std_logic_vector(to_unsigned(blk_id * BLK_SIZE + to_integer(unsigned(addr)), 32));
mm_32b_write(address, data, mm_s, mm_m);
end procedure fpm_reg_write;
-- fpm_reg_write with addr defined as integer
procedure fpm_reg_write(
blk_id : in natural range 0 to BLK_NUM-1;
addr : in integer;
data : in std_logic_vector(31 downto 0);
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable address : std_logic_vector(31 downto 0);
begin
address := std_logic_vector(to_unsigned((blk_id * BLK_SIZE) + addr, 32));
mm_32b_write(address, data, mm_s, mm_m);
end procedure fpm_reg_write;
-- fpm_reg_read with addr defined as std_logic_vector
procedure fpm_reg_read(
blk_id : in natural range 0 to BLK_NUM-1;
addr : in std_logic_vector;
data : out std_logic_vector(31 downto 0);
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable address : std_logic_vector(31 downto 0);
begin
address := std_logic_vector(to_unsigned(blk_id * BLK_SIZE + to_integer(unsigned(addr)), 32));
mm_32b_read(address, data, mm_s, mm_m);
end procedure fpm_reg_read;
-- fpm_reg_read with addr defined as std_logic_vector
procedure fpm_reg_read(
blk_id : in natural range 0 to BLK_NUM-1;
addr : in integer;
data : out std_logic_vector(31 downto 0);
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable address : std_logic_vector(31 downto 0);
begin
address := std_logic_vector(to_unsigned((blk_id * BLK_SIZE) + addr, 32));
mm_32b_read(address, data, mm_s, mm_m);
end procedure fpm_reg_read;
procedure fpm_ctrl_config(
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable data : std_logic_vector(31 downto 0);
begin
log("Configuring FPM Controller ... ", VMEDIUM, true);
-- Enable the POF-Rx and set protocol version 1
data := X"0000_0101";
fpm_reg_write(FP_CTRL_ID, CSR_POF_RECEIVER_CONTROL_ADDR_INT, data, mm_s, mm_m);
fpm_reg_read(FP_CTRL_ID, CSR_SIGNAL_SELECTION_ADDR_INT, data, mm_s, mm_m);
-- Select the input source
data(2 downto 0) := b"001";
fpm_reg_write(FP_CTRL_ID, CSR_SIGNAL_SELECTION_ADDR_INT, data, mm_s, mm_m);
end procedure fpm_ctrl_config;
procedure ch_offset_config(
ch_id : in natural;
ch_offset : in natural;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable data : std_logic_vector(31 downto 0);
begin
-- Disable/Re-enable first the whole pulse_generator
data := std_logic_vector(to_unsigned(ch_offset, 32));
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_PD_OFFSET_DIR_0_ADDR, data, mm_s, mm_m);
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_PD_OFFSET_DIR_1_ADDR, data, mm_s, mm_m);
log("CH-" & to_string(ch_id) & ": PD offset configured to " & to_string(ch_offset) & ".", VMEDIUM);
end procedure ch_offset_config;
procedure ch_ctrl_config(
ch_id : in natural;
pixel_num : in natural;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable data : std_logic_vector(31 downto 0);
variable ram_idx : natural;
variable ram_offset : natural;
begin
ram_offset := to_integer(unsigned(work.pulse_generator_5_pkg.SEQ_GENERIC_SEQUENCER_18_CHANNEL_ADDR));
ram_idx := 0;
-- Issue first an image on DIR-0, then on DIR-1
-- Reset the vector output value
data := X"30000000";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
-- Enable Trigger Mask (All the triggers)
data := X"1000000F";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
-- Wait for a single PD event
data := X"20000001";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
-- Issue a request to generate 'pixel_num' fire requests
data := X"30" & std_logic_vector(to_unsigned(pixel_num, 16)) & X"24";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
data := X"30" & std_logic_vector(to_unsigned(pixel_num, 16)) & X"00";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
-- wait until the end of the image
data := X"23000001";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
-- Switch to DIR-1
data := X"30000001";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
-- Wait for a single PD event
data := X"20000001";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
-- Issue a request to generate 'pixel_num' fire requests
data := X"30" & std_logic_vector(to_unsigned(pixel_num, 16)) & X"25";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
data := X"30" & std_logic_vector(to_unsigned(pixel_num, 16)) & X"01";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
-- wait until the end of the image
data := X"23000001";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
-- Jump to DIR-0
data := X"C0000000";
fpm_reg_write(PG_CH_ID + ch_id, ram_offset + ram_idx, data, mm_s, mm_m);
ram_idx := ram_idx + 1;
end procedure ch_ctrl_config;
procedure pulse_gen_config(
ch_id : in natural;
ch_offset : in natural;
div_ratio : in real;
subpix_phases : in natural;
pixel_num : in natural;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable data : std_logic_vector(31 downto 0);
variable ratio_int : integer;
variable ratio_slv : std_logic_vector(33 downto 0);
begin
log("Configuring Channel " & to_string(ch_id) & " ... ", VMEDIUM, true);
-- Disable/Re-enable first the whole pulse_generator
data := (others => '0');
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_PULSE_GEN_CONTROL_W_ADDR, data, mm_s, mm_m);
data := (0 => '1', 16 => '1', others => '0');
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_PULSE_GEN_CONTROL_W_ADDR, data, mm_s, mm_m);
-- Disable/Re-enable the Channel Controller sequencer
data := (others => '0');
fpm_reg_write(PG_CH_ID + ch_id, to_integer(unsigned(work.pulse_generator_5_pkg.CSR_GENERIC_SEQUENCER_18_CHANNEL_ADDR)) + 3, data, mm_s, mm_m);
data := (0 => '1', others => '0');
fpm_reg_write(PG_CH_ID + ch_id, to_integer(unsigned(work.pulse_generator_5_pkg.CSR_GENERIC_SEQUENCER_18_CHANNEL_ADDR)) + 3, data, mm_s, mm_m);
-- Set the number of sub-pixel phases
data := std_logic_vector(to_unsigned(subpix_phases, 32));
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_SUBPIXEL_PHASE_NUM_ADDR, data, mm_s, mm_m);
-- set the division ratio
ratio_int := integer((div_ratio / real(subpix_phases)) * real(2 ** 24));
ratio_slv := std_logic_vector(to_unsigned(ratio_int, 34));
-- Set the integer part of the div-ratio
data(31 downto 10) := (others => '0');
data(9 downto 0) := ratio_slv(33 downto 24);
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_DIVIDER_RATIO_INT_ADDR, data, mm_s, mm_m);
data(31 downto 24) := (others => '0');
data(23 downto 0) := ratio_slv(23 downto 0);
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_DIVIDER_RATIO_FRACTION_ADDR, data, mm_s, mm_m);
-- Disable/Enable the fractional divider
data := (others => '0');
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_FRACTIONAL_DIVIDER_CONTROL_ADDR, data, mm_s, mm_m);
data := (0 => '1', others => '0');
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_FRACTIONAL_DIVIDER_CONTROL_ADDR, data, mm_s, mm_m);
-- configure the channel offset
ch_offset_config(ch_id, ch_offset, mm_s, mm_m);
-- Configure the sequencer RAM
ch_ctrl_config(ch_id, pixel_num, mm_s, mm_m);
-- Restart the sequencer
data := (others => '0');
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_CHANNEL_CONTROLLER_CONTROL_W_ADDR, data, mm_s, mm_m);
data := (0 => '1', others => '0');
fpm_reg_write(PG_CH_ID + ch_id, work.pulse_generator_5_pkg.CSR_CHANNEL_CONTROLLER_CONTROL_W_ADDR, data, mm_s, mm_m);
end procedure pulse_gen_config;
procedure fpm_input_config(
input_type : in fpm_input_type_t;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable data : std_logic_vector(31 downto 0);
begin
if (input_type = POF_INPUT) then
fpm_reg_read(FP_CTRL_ID, CSR_SIGNAL_SELECTION_ADDR_INT, data, mm_s, mm_m);
data(2 downto 0) := b"001";
fpm_reg_write(FP_CTRL_ID, CSR_SIGNAL_SELECTION_ADDR_INT, data, mm_s, mm_m);
log("FPM input set to POF. ", VLOW, true);
elsif (input_type = EPD_INPUT) then
data(2 downto 0) := b"101";
fpm_reg_write(FP_CTRL_ID, CSR_SIGNAL_SELECTION_ADDR_INT, data, mm_s, mm_m);
log("FPM input set to EPD. ", VLOW, true);
end if;
end procedure fpm_input_config;
procedure fpm_ems_config(
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable data : std_logic_vector(31 downto 0);
begin
log("Configuring EMS ... ", VMEDIUM, true);
-- EMS software init
fpm_reg_write(EMS_BLK_ID, work.ems_1_pkg.CSR_EMS_ENABLE_ADDR, 32x"1", mm_s, mm_m);
-- disable the EMS during the configuration
fpm_reg_write(EMS_BLK_ID, work.ems_1_pkg.CSR_EMS_ENABLE_ADDR, 32x"0", mm_s, mm_m);
-- apply EMS config
fpm_reg_write(EMS_BLK_ID, work.ems_1_pkg.CSR_EMS_CONFIG_ADDR, 32x"3E0", mm_s, mm_m);
-- enable the EMS
fpm_reg_write(EMS_BLK_ID, work.ems_1_pkg.CSR_EMS_ENABLE_ADDR, 32x"E", mm_s, mm_m);
end procedure fpm_ems_config;
procedure drop_watch_config(
enable : in std_logic;
src : in std_logic_vector(3 downto 0);
pulse_witdth : in natural;
signal mm_s : in mm_s_rec_t;
signal mm_m : out mm_m_rec_t) is
variable data : std_logic_vector(31 downto 0);
begin
-- configure the drop-watch
data := std_logic_vector(to_unsigned(pulse_witdth, 16)) & X"000" & src;
fpm_reg_write(FP_CTRL_ID, work.fpm_ctrl_7_pkg.CSR_DROP_WATCH_CONFIG_ADDR_INT, data, mm_s, mm_m);
-- Enable/disable the drop-watch
fpm_reg_read(FP_CTRL_ID, work.fpm_ctrl_7_pkg.CSR_SIGNAL_SELECTION_ADDR_INT, data, mm_s, mm_m);
data(3) := enable;
fpm_reg_write(FP_CTRL_ID, work.fpm_ctrl_7_pkg.CSR_SIGNAL_SELECTION_ADDR_INT, data, mm_s, mm_m);
if (enable = '1') then
log("Drop-Watch output enable on channel " & to_string(to_integer(unsigned(src))) & ".", VMEDIUM, true);
else
log("Drop-Watch output disabled.", VMEDIUM, true);
end if;
end procedure drop_watch_config;
-----------------------------------------------------------------------------
-- ENC/PD Emulator Configuration
-----------------------------------------------------------------------------
procedure set_enc_abs_pos(
abs_pos : in std_logic_vector(39 downto 0);
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
variable addr : std_logic_vector(31 downto 0) := (others => '0');
variable data : std_logic_vector(31 downto 0) := (others => '0');
begin
-- set the value for MSBs
addr := std_logic_vector(resize(unsigned(CSR_POS_INIT_MSB_ADDR), 32));
mm_32b_write(addr, 24x"0" & abs_pos(39 downto 32), mm_s_rec, mm_m_rec);
-- set the value for LSBs
addr := std_logic_vector(resize(unsigned(CSR_POS_INIT_LSB_ADDR), 32));
mm_32b_write(addr, abs_pos(31 downto 0), mm_s_rec, mm_m_rec);
-- read back the encoder configuration, then apply the set_abs_pos control
-- bit
addr := std_logic_vector(resize(unsigned(CSR_ENC_CTRL_W_ADDR), 32));
mm_32b_read(addr, data, mm_s_rec, mm_m_rec);
data(3) := '1';
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
log("Encoder/PD emulator abs-pos preset to " & to_string(to_integer(signed(abs_pos))) & ".", VMEDIUM);
end procedure set_enc_abs_pos;
procedure apply_enc_pd_emul_cfg(
cfg : in emul_cfg_t;
init : in boolean := true;
run_pulses_mode : in boolean := false;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
variable addr : std_logic_vector(31 downto 0) := (others => '0');
variable data : std_logic_vector(31 downto 0) := (others => '0');
variable data_check : std_logic_vector(31 downto 0) := (others => '0');
--
variable pd_low_period : real := 0.0; -- PD low period (ns)
variable pd_high_period : real := 0.0; -- PD high period (ns)
begin
-- Set the NCO inc: output freq
addr := std_logic_vector(resize(unsigned(CSR_ENC_NCO_INC_ADDR), 32));
data := freq2NCO_inc(real(cfg.enc_freq), CLK_FREQ);
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
-- set the max pulses register
addr := std_logic_vector(resize(unsigned(CSR_ENC_PULSE_NUM_ADDR), 32));
data := std_logic_vector(to_unsigned(cfg.enc_pulses, 32));
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
-- set the zero-phase ppr number
addr := std_logic_vector(resize(unsigned(CSR_ENC_ZP_PPR_ADDR), 32));
data := std_logic_vector(to_unsigned(cfg.enc_ppr, 32));
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
-- Enable only the necessary outputs:
if (cfg.enc_phase = DUAL_PHASE) then
data := 32x"FF";
else
data := 32x"BB";
end if;
addr := std_logic_vector(resize(unsigned(CSR_OUT_ENABLE_ADDR), 32));
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
addr := std_logic_vector(resize(unsigned(CSR_ENC_CTRL_W_ADDR), 32));
if (init = true) then
mm_32b_write(addr, 32x"2", mm_s_rec, mm_m_rec);
end if;
data := (others => '0');
if (run_pulses_mode = true) then
data(4) := '1';
end if;
if (cfg.enc_dir = DIR_0) then
data(2) := '0';
else
data(2) := '1';
end if;
-- enable the encoder
data(0) := '1';
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
log("Encoder/PD emulator enabled.", VMEDIUM);
end procedure apply_enc_pd_emul_cfg;
-- Stop the ENC/PD emulator
procedure stop_enc_pd_emul(
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
variable addr : std_logic_vector(31 downto 0) := (others => '0');
variable data : std_logic_vector(31 downto 0) := (others => '0');
begin
-- Disable PD emulation
addr := std_logic_vector(resize(unsigned(CSR_PD_CTRL_ADDR), 32));
mm_32b_read(addr, data, mm_s_rec, mm_m_rec);
data(0) := '0';
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
-- Disable Enc emulation
addr := std_logic_vector(resize(unsigned(CSR_ENC_CTRL_W_ADDR), 32));
mm_32b_read(addr, data, mm_s_rec, mm_m_rec);
data(0) := '0';
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
end procedure stop_enc_pd_emul;
-- Check whether the generation of a fixed number of encoder pulses has completed
procedure check_max_pulses_done(
done : out boolean;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
variable addr : std_logic_vector(31 downto 0) := (others => '0');
variable data : std_logic_vector(31 downto 0) := (others => '0');
begin
addr := std_logic_vector(resize(unsigned(CSR_ENC_CTRL_R_ADDR), 32));
mm_32b_read(addr, data, mm_s_rec, mm_m_rec);
if (data(6) = '1') then
done := true;
else
done := false;
end if;
end procedure check_max_pulses_done;
-- Run a fix number of encoder pulses
procedure run_enc_pulses(
enc_freq : in enc_freq_t;
direction : in enc_dir_t;
double_ph_mode : in boolean := true;
num_pulses : in integer;
enc_ppr : in integer;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
variable addr : std_logic_vector(31 downto 0) := (others => '0');
variable data : std_logic_vector(31 downto 0) := (others => '0');
variable data_check : std_logic_vector(31 downto 0) := (others => '0');
begin
-- Set the NCO inc: output freq
addr := std_logic_vector(resize(unsigned(CSR_ENC_NCO_INC_ADDR), 32));
data := freq2NCO_inc(real(enc_freq), CLK_FREQ);
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
-- set the max pulses register
addr := std_logic_vector(resize(unsigned(CSR_ENC_PULSE_NUM_ADDR), 32));
data := std_logic_vector(to_unsigned(num_pulses, 32));
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
-- set the zero-phase ppr number
addr := std_logic_vector(resize(unsigned(CSR_ENC_ZP_PPR_ADDR), 32));
data := std_logic_vector(to_unsigned(enc_ppr, 32));
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
-- Enable only the necessary outputs:
if (double_ph_mode = true) then
data := 32x"FF";
else
data := 32x"BB";
end if;
addr := std_logic_vector(resize(unsigned(CSR_OUT_ENABLE_ADDR), 32));
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
addr := std_logic_vector(resize(unsigned(CSR_ENC_CTRL_W_ADDR), 32));
data := (4 => '1', 5 => '1', others => '0');
if (direction = DIR_0) then
data(2) := '0';
else
data(2) := '1';
end if;
-- enable the encoder
data(0) := '1';
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
--log("Running encoder pulses ... ", VMEDIUM);
end procedure run_enc_pulses;
-- Run PD pulses: either single pulse or periodic mode
procedure run_pd_pulses(
pulse_width : in pd_pulse_width_t;
pd_period : in pd_period_t;
single_pulse_mode : in boolean := false;
signal mm_s_rec : in mm_s_rec_t;
signal mm_m_rec : out mm_m_rec_t) is
variable addr : std_logic_vector(31 downto 0) := (others => '0');
variable data : std_logic_vector(31 downto 0) := (others => '0');
variable data_check : std_logic_vector(31 downto 0) := (others => '0');
variable tmp_val : integer;
variable idx : integer;
variable loop_idx : integer;
begin
-- set the pulse width
addr := std_logic_vector(resize(unsigned(CSR_PD_PULSE_WIDTH_ADDR), 32));
data := std_logic_vector(to_unsigned(integer(pulse_width * 100.0), 32));
mm_32b_write(addr, data, mm_s_rec, mm_m_rec);
-- No need to use the sequerncer for a single pulse
if (single_pulse_mode = true) then
addr := std_logic_vector(resize(unsigned(CSR_PD_CTRL_ADDR), 32));
mm_32b_write(addr, 32x"3", mm_s_rec, mm_m_rec);
log("Issued single PD pulse. ", VMEDIUM);
return;
end if;
-- Use the sequencer to generate periodic pulses (here the periodicity is
-- in time): First program the sequencer RAM with instructions to generate
-- pulses with the specified periodicity, then enable the sequencer,
-- finally trigger the start of the procedure:
-- Write in the Emulator sequencer a simple procedure to issue PD pulses
addr := std_logic_vector(resize(unsigned(SEQ_GENERIC_SEQUENCER_18_ADDR) + 0, 32));
mm_32b_write(addr, X"100000FF", mm_s_rec, mm_m_rec); -- Enable triggers
addr := std_logic_vector(resize(unsigned(SEQ_GENERIC_SEQUENCER_18_ADDR) + 1, 32));
mm_32b_write(addr, X"30000000", mm_s_rec, mm_m_rec); -- All the outputs to zero
idx := 2;
loop_idx := idx;
if (pd_period >= 1.0) then
-- add a first trigger-wait instruction for 1-us pulses
addr := std_logic_vector(resize(unsigned(SEQ_GENERIC_SEQUENCER_18_ADDR) + idx, 32));
tmp_val := integer(pd_period);
data := X"21000" & std_logic_vector(to_unsigned(tmp_val, 12));
mm_32b_write(addr, data, mm_s_rec, mm_m_rec); -- trig_wait (us pulses)
idx := idx + 1;
end if;
-- add a second trigger on single clock cycle events
addr := std_logic_vector(resize(unsigned(SEQ_GENERIC_SEQUENCER_18_ADDR) + idx, 32));
tmp_val := integer((pd_period - floor(pd_period)) * 100.0);
data := X"20000" & std_logic_vector(to_unsigned(tmp_val, 12));
mm_32b_write(addr, data, mm_s_rec, mm_m_rec); -- trig_wait (clk pulses)
idx := idx + 1;
-- issue the PD pulse
addr := std_logic_vector(resize(unsigned(SEQ_GENERIC_SEQUENCER_18_ADDR) + idx, 32));
mm_32b_write(addr, X"31000001", mm_s_rec, mm_m_rec); -- All the outputs to zero
idx := idx + 1;
-- Jump to the beginning of the loop
addr := std_logic_vector(resize(unsigned(SEQ_GENERIC_SEQUENCER_18_ADDR) + idx, 32));
mm_32b_write(addr, X"31000001", mm_s_rec, mm_m_rec); -- All the outputs to zero
-- Enable the sequencer
addr := std_logic_vector(resize(unsigned(SEQ_GENERIC_SEQUENCER_18_ADDR) + idx, 32));
mm_32b_write(addr, 32x"1", mm_s_rec, mm_m_rec); -- All the outputs to zero
-- issue a start-request to the sequencer
addr := std_logic_vector(resize(unsigned(CSR_SEQ_CTRL_ADDR), 32));
data(0) := '1'; -- start-request bit
data(24 downto 16) := 9x"0"; -- EAM sequence start-address
mm_32b_write(addr, 32x"1", mm_s_rec, mm_m_rec);
log("Running PD pulses ... ", VMEDIUM);
end procedure run_pd_pulses;
-----------------------------------------------------------------------------
-- Support functions
-----------------------------------------------------------------------------
-- generate the NCO increment corresponding to a given output frequency
function freq2NCO_inc(
f_out : real; f_clk : real) return std_logic_vector is
variable nco_inc : std_logic_vector(ENC_NCO_WIDTH - 1 downto 0);
begin
nco_inc := std_logic_vector(to_unsigned(integer((f_out / f_clk) * (2.0 ** ENC_NCO_WIDTH)), ENC_NCO_WIDTH));
return nco_inc;
end function freq2NCO_inc;
end fire_pulse_manager_7_one_tb_pkg;