A working simulation folder to be run with wsl has been added

This commit is contained in:
David Rodriguez 2026-04-05 22:00:37 +01:00
commit 4acd5c71d4
2 changed files with 216 additions and 0 deletions

66
sim/run_pei_fpga_top.do Normal file
View file

@ -0,0 +1,66 @@
transcript on
onerror {quit -code 1}
if {[file exists work]} {
vdel -lib work -all
}
vlib work
vmap work work
# Adjust the source paths to match your project layout.
# This script assumes:
# ../src -> RTL sources
# . -> testbench directory
# Compile package(s) first
vcom -2008 ../src/pei_register_pkg.vhd
vcom -2008 ../src/pkg_functions_pei.vhd
# Compile any IP wrappers/models needed by the top level
vcom -2008 ../quartus/pll_25in_100out_pei.vhd
vcom -2008 ../quartus/io_buf_i2c.vhd
vcom -2008 ../quartus/fifo_v20.vhd
vcom -2008 ../quartus/pll_25in_100out_pei.vhd
# Compile the DUT
vcom -2008 ../src/pei_debug_uart_1.vhd
vcom -2008 ../src/ring_buffer.vhd
vcom -2008 ../src/mcp4631.vhd
vcom -2008 ../src/head_data_proc.vhd
vcom -2008 ../src/head_data_proc.vhd
vcom -2008 ../src/pei_fpga_top.vhd
# Compile the testbench
vcom -2008 tb_pei_fpga_top.vhd
# Launch simulation
vsim -t 1ps work.tb_pei_fpga_top
# Useful wave groups
add wave -noupdate /tb_pei_fpga_top/clk25_in
add wave -noupdate /tb_pei_fpga_top/dbg_ser_in
add wave -noupdate /tb_pei_fpga_top/dbg_ser_out
add wave -noupdate /tb_pei_fpga_top/c_clk
add wave -noupdate /tb_pei_fpga_top/head_lat
add wave -noupdate /tb_pei_fpga_top/two_col
add wave -noupdate /tb_pei_fpga_top/head_data
add wave -noupdate /tb_pei_fpga_top/lvdsoe
add wave -noupdate /tb_pei_fpga_top/stm8_alert_in
add wave -noupdate /tb_pei_fpga_top/temp_alert_in
add wave -noupdate /tb_pei_fpga_top/alert_out
add wave -noupdate /tb_pei_fpga_top/shutdn
add wave -noupdate /tb_pei_fpga_top/v_en
add wave -noupdate /tb_pei_fpga_top/wf_sel
add wave -noupdate /tb_pei_fpga_top/cfg_ncs
add wave -noupdate /tb_pei_fpga_top/cfg_wdata
add wave -noupdate /tb_pei_fpga_top/debug_out
add wave -noupdate /tb_pei_fpga_top/nled_g
add wave -noupdate /tb_pei_fpga_top/nled_y
add wave -noupdate /tb_pei_fpga_top/nled_r
add wave -noupdate -r /tb_pei_fpga_top/dut/*
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {0 ps} 0}
update
run 50 us

150
sim/tb_pei_fpga_top.vhd Normal file
View file

@ -0,0 +1,150 @@
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity tb_pei_fpga_top is
end entity;
architecture tb of tb_pei_fpga_top is
constant CLK25_PERIOD : time := 40 ns; -- 25 MHz
signal clk25_in : std_logic := '0';
signal dbg_ser_out : std_logic;
signal dbg_ser_in : std_logic := '1';
signal c_clk : std_logic_vector(1 downto 0) := (others => '0');
signal head_lat : std_logic_vector(1 downto 0) := (others => '0');
signal two_col : std_logic := '0';
signal head_data : std_logic_vector(7 downto 0) := (others => '0');
signal nled_g : std_logic;
signal nled_y : std_logic;
signal nled_r : std_logic;
signal sda_fpga : std_logic := 'H';
signal scl_fpga : std_logic := 'H';
signal stm8_alert_in : std_logic_vector(1 downto 0) := (others => '1');
signal alert_out : std_logic;
signal temp_alert_in : std_logic := '1';
signal shutdn : std_logic;
signal v_en : std_logic_vector(3 downto 0);
signal wf_sel : std_logic_vector(2 downto 0);
signal cfg_ncs : std_logic;
signal cfg_wdata : std_logic;
signal hd_scl_fpga : std_logic := 'H';
signal hd_sda_fpga : std_logic := 'H';
signal lvdsoe : std_logic := '0';
signal debug_out : std_logic_vector(5 downto 1);
begin
dut : entity work.pei_fpga_top
generic map (
DEVICE_FAMILY => "Cyclone 10 LP",
ADDRESS_WIDTH => 8,
DATA_WIDTH => 32,
TEST_MODE => false
)
port map (
clk25_in => clk25_in,
dbg_ser_out => dbg_ser_out,
dbg_ser_in => dbg_ser_in,
c_clk => c_clk,
head_lat => head_lat,
two_col => two_col,
head_data => head_data,
nled_g => nled_g,
nled_y => nled_y,
nled_r => nled_r,
sda_fpga => sda_fpga,
scl_fpga => scl_fpga,
stm8_alert_in => stm8_alert_in,
alert_out => alert_out,
temp_alert_in => temp_alert_in,
shutdn => shutdn,
v_en => v_en,
wf_sel => wf_sel,
cfg_ncs => cfg_ncs,
cfg_wdata => cfg_wdata,
hd_scl_fpga => hd_scl_fpga,
hd_sda_fpga => hd_sda_fpga,
lvdsoe => lvdsoe,
debug_out => debug_out
);
clk25_in <= not clk25_in after CLK25_PERIOD / 2;
stim_proc : process
begin
-- settle
wait for 200 ns;
-- basic idle condition
lvdsoe <= '0';
two_col <= '0';
head_data <= x"00";
c_clk <= "00";
head_lat <= "00";
stm8_alert_in <= "11";
temp_alert_in <= '1';
wait for 2 us;
-- apply a few PEI-like activity patterns
lvdsoe <= '1';
head_data <= x"A5";
for i in 0 to 15 loop
c_clk(0) <= '1';
wait for 20 ns;
c_clk(0) <= '0';
wait for 20 ns;
end loop;
wait for 500 ns;
head_lat(0) <= '1';
wait for 80 ns;
head_lat(0) <= '0';
wait for 500 ns;
two_col <= '1';
head_data <= x"3C";
for i in 0 to 15 loop
c_clk(1) <= '1';
wait for 20 ns;
c_clk(1) <= '0';
wait for 20 ns;
end loop;
wait for 500 ns;
head_lat(1) <= '1';
wait for 80 ns;
head_lat(1) <= '0';
-- toggle alerts to exercise outputs
wait for 1 us;
stm8_alert_in(0) <= '0';
wait for 500 ns;
stm8_alert_in(0) <= '1';
temp_alert_in <= '0';
wait for 500 ns;
temp_alert_in <= '1';
-- simple debug serial activity
wait for 1 us;
dbg_ser_in <= '0';
wait for 8.68 us; -- approx one bit at 115200 baud
dbg_ser_in <= '1';
wait for 10 us;
assert false report "tb_pei_fpga_top completed" severity failure;
end process;
monitor_proc : process(clk25_in)
begin
if rising_edge(clk25_in) then
assert not is_x(nled_g) report "nled_g is unknown" severity warning;
assert not is_x(nled_y) report "nled_y is unknown" severity warning;
assert not is_x(nled_r) report "nled_r is unknown" severity warning;
assert not is_x(alert_out) report "alert_out is unknown" severity warning;
assert not is_x(shutdn) report "shutdn is unknown" severity warning;
end if;
end process;
end architecture;