feat: complete Palladium Z3 demo (SA & ICE dual-mode) and 24.05 hardware compilation fix

This commit is contained in:
xuejin.wang
2026-10-20 19:01:16 +08:00
commit 1cc994fac4
18 changed files with 1445 additions and 0 deletions
+190
View File
@@ -0,0 +1,190 @@
// -----------------------------------------------------------------------------
// z3_demo_ice_top.v -- Palladium Z3 ICE-mode demo top
//
// ICE (In-Circuit Emulation) has NO software testbench: everything that runs
// in the emulator must be synthesizable hardware.
//
// This top-level module wraps z3_demo_top with an on-chip hardware self-checking
// FSM that autonomously stimulates and verifies the DUT:
// reset -> program LOAD/CMP -> verify Z3 ID -> start timer
// -> wait for irq -> verify STATUS flags -> verify GPIO rotation
// -> disable, clear W1C flags -> assert led_pass/led_fail
// -----------------------------------------------------------------------------
`timescale 1ns/1ps
module z3_demo_ice_top (
input wire clk_in,
input wire rst_n_in,
output wire [7:0] led_gpio,
output wire led_irq,
output reg led_done,
output reg led_pass,
output reg led_fail
);
// ------------------------------------------------------------ DUT signals
reg [7:0] paddr;
reg psel;
reg penable;
reg pwrite;
reg [31:0] pwdata;
wire [31:0] prdata;
wire pready;
wire [7:0] gpio_out;
wire irq;
wire cmp_hit;
z3_demo_top dut (
.clk (clk_in),
.rst_n (rst_n_in),
.paddr (paddr),
.psel (psel),
.penable (penable),
.pwrite (pwrite),
.pwdata (pwdata),
.prdata (prdata),
.pready (pready),
.gpio_out (gpio_out),
.irq (irq),
.cmp_hit (cmp_hit)
);
assign led_gpio = gpio_out;
assign led_irq = irq;
// ------------------------------------------------------------ FSM
localparam ST_WAIT = 5'd0;
localparam ST_WR_LOAD = 5'd1;
localparam ST_WR_CMP = 5'd2;
localparam ST_RD_ID = 5'd3;
localparam ST_CHK_ID = 5'd4;
localparam ST_WR_CTRL = 5'd5;
localparam ST_WAIT_IRQ = 5'd6;
localparam ST_RD_STAT = 5'd7;
localparam ST_CHK_STAT = 5'd8;
localparam ST_RD_GPIO = 5'd9;
localparam ST_CHK_GPIO = 5'd10;
localparam ST_WR_CTRL0 = 5'd11;
localparam ST_WR_W1C = 5'd12;
localparam ST_RD_STAT2 = 5'd13;
localparam ST_CHK_STAT2 = 5'd14;
localparam ST_PASS = 5'd15;
localparam ST_FAIL = 5'd16;
reg [4:0] state;
reg [15:0] wait_cnt;
reg [31:0] rd_latched;
always @(*) begin
paddr = 8'd0;
pwdata = 32'd0;
pwrite = 1'b0;
psel = 1'b0;
penable = 1'b0;
case (state)
ST_WR_LOAD: begin psel=1; penable=1; pwrite=1; paddr=8'h04; pwdata=32'd19; end
ST_WR_CMP: begin psel=1; penable=1; pwrite=1; paddr=8'h0C; pwdata=32'd5; end
ST_RD_ID: begin psel=1; penable=1; pwrite=0; paddr=8'h18; end
ST_WR_CTRL: begin psel=1; penable=1; pwrite=1; paddr=8'h00; pwdata=32'd7; end
ST_RD_STAT: begin psel=1; penable=1; pwrite=0; paddr=8'h10; end
ST_RD_GPIO: begin psel=1; penable=1; pwrite=0; paddr=8'h14; end
ST_WR_CTRL0: begin psel=1; penable=1; pwrite=1; paddr=8'h00; pwdata=32'd0; end
ST_WR_W1C: begin psel=1; penable=1; pwrite=1; paddr=8'h10; pwdata=32'd3; end
ST_RD_STAT2: begin psel=1; penable=1; pwrite=0; paddr=8'h10; end
default: ;
endcase
end
always @(posedge clk_in or negedge rst_n_in) begin
if (!rst_n_in) begin
state <= ST_WAIT;
wait_cnt <= 16'd0;
rd_latched <= 32'd0;
led_done <= 1'b0;
led_pass <= 1'b0;
led_fail <= 1'b0;
end else begin
case (state)
ST_WAIT: begin
if (wait_cnt == 16'd10) begin
wait_cnt <= 16'd0;
state <= ST_WR_LOAD;
end else begin
wait_cnt <= wait_cnt + 16'd1;
end
end
ST_WR_LOAD: state <= ST_WR_CMP;
ST_WR_CMP: state <= ST_RD_ID;
ST_RD_ID: begin rd_latched <= prdata; state <= ST_CHK_ID; end
ST_CHK_ID: begin
// Verify Palladium Z3 signature
if (rd_latched == 32'h5A33_0001)
state <= ST_WR_CTRL;
else
state <= ST_FAIL;
end
ST_WR_CTRL: begin
wait_cnt <= 16'd0;
state <= ST_WAIT_IRQ;
end
ST_WAIT_IRQ: begin
if (irq) begin
state <= ST_RD_STAT;
end else if (wait_cnt >= 16'd1000) begin
state <= ST_FAIL; // watchdog timeout
end else begin
wait_cnt <= wait_cnt + 16'd1;
end
end
ST_RD_STAT: begin rd_latched <= prdata; state <= ST_CHK_STAT; end
ST_CHK_STAT: begin
if ((rd_latched & 32'd3) == 32'd3)
state <= ST_RD_GPIO;
else
state <= ST_FAIL;
end
ST_RD_GPIO: begin rd_latched <= prdata; state <= ST_CHK_GPIO; end
ST_CHK_GPIO: begin
if (rd_latched[7:0] == 8'h02)
state <= ST_WR_CTRL0;
else
state <= ST_FAIL;
end
ST_WR_CTRL0: state <= ST_WR_W1C;
ST_WR_W1C: state <= ST_RD_STAT2;
ST_RD_STAT2: begin rd_latched <= prdata; state <= ST_CHK_STAT2; end
ST_CHK_STAT2: begin
if ((rd_latched & 32'd3) == 32'd0)
state <= ST_PASS;
else
state <= ST_FAIL;
end
ST_PASS: begin
led_done <= 1'b1;
led_pass <= 1'b1;
led_fail <= 1'b0;
end
ST_FAIL: begin
led_done <= 1'b1;
led_pass <= 1'b0;
led_fail <= 1'b1;
end
default: state <= ST_FAIL;
endcase
end
end
endmodule
+108
View File
@@ -0,0 +1,108 @@
// -----------------------------------------------------------------------------
// z3_demo_top.v -- Palladium Z3 emulation demo DUT
// (Identical to root rtl/z3_demo_top.v)
// -----------------------------------------------------------------------------
`timescale 1ns/1ps
module z3_demo_top (
input wire clk,
input wire rst_n,
// APB-like slave bus
input wire [7:0] paddr,
input wire psel,
input wire penable,
input wire pwrite,
input wire [31:0] pwdata,
output reg [31:0] prdata,
output wire pready,
// Observable outputs
output wire [7:0] gpio_out,
output wire irq,
output wire cmp_hit
);
reg ctrl_enable;
reg ctrl_irq_en;
reg ctrl_pattern_en;
reg [31:0] reg_load;
reg [31:0] reg_count;
reg [31:0] reg_cmp;
reg status_timeout;
reg status_cmp;
reg [7:0] reg_gpio;
assign pready = 1'b1;
assign gpio_out = reg_gpio;
assign irq = status_timeout & ctrl_irq_en;
wire bus_write = psel & penable & pwrite;
wire bus_read = psel & penable & ~pwrite;
wire timeout_now = ctrl_enable & (reg_count == 32'd0);
assign cmp_hit = ctrl_enable & (reg_count == reg_cmp);
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
ctrl_enable <= 1'b0;
ctrl_irq_en <= 1'b0;
ctrl_pattern_en <= 1'b0;
reg_load <= 32'd9;
reg_cmp <= 32'd3;
reg_gpio <= 8'h01;
status_timeout <= 1'b0;
status_cmp <= 1'b0;
end else begin
if (timeout_now)
status_timeout <= 1'b1;
if (cmp_hit)
status_cmp <= 1'b1;
if (bus_write) begin
case (paddr[7:0])
8'h00: begin
ctrl_enable <= pwdata[0];
ctrl_irq_en <= pwdata[1];
ctrl_pattern_en <= pwdata[2];
end
8'h04: begin
reg_load <= pwdata;
reg_count <= pwdata;
end
8'h0C: reg_cmp <= pwdata;
8'h10: begin
if (pwdata[0]) status_timeout <= 1'b0;
if (pwdata[1]) status_cmp <= 1'b0;
end
8'h14: reg_gpio <= pwdata[7:0];
default: ;
endcase
end else if (ctrl_enable) begin
if (reg_count == 32'd0) begin
reg_count <= reg_load;
if (ctrl_pattern_en)
reg_gpio <= {reg_gpio[6:0], reg_gpio[7]};
end else begin
reg_count <= reg_count - 32'd1;
end
end
end
end
always @(*) begin
if (bus_read) begin
case (paddr[7:0])
8'h00: prdata = {29'b0, ctrl_pattern_en, ctrl_irq_en, ctrl_enable};
8'h04: prdata = reg_load;
8'h08: prdata = reg_count;
8'h0C: prdata = reg_cmp;
8'h10: prdata = {30'b0, status_cmp, status_timeout};
8'h14: prdata = {24'b0, reg_gpio};
8'h18: prdata = 32'h5A33_0001; // Z3 ID
default: prdata = 32'hDEAD_BEEF;
endcase
end else begin
prdata = 32'h0;
end
end
endmodule
+42
View File
@@ -0,0 +1,42 @@
#!/bin/sh
# =============================================================================
# compile_ice.sh -- Palladium Z3 ICE 模式硬件编译脚本
# =============================================================================
set -e
cd "$(dirname "$0")/../.."
ROOT="$(pwd)"
export XE_HOST="${XE_HOST:-z7f1x8c-5k9p3m}"
echo "======================================================================"
echo " [Palladium Z3 ICE] 开始硬件全逻辑编译"
echo " Target Host : $XE_HOST"
echo " Top Module : z3_demo_ice_top"
echo " 当前使用 ixcom : $(which ixcom 2>/dev/null || echo '未检测到')"
echo " 当前使用 xeCompile : $(which xeCompile 2>/dev/null || echo '未检测到,请 export PATH')"
echo "======================================================================"
set +e
ixcom -clean -ua +dut+z3_demo_ice_top \
-z3 \
-ignoreSimSetupCheck \
-ignoreHWPlatformSetupCheck \
-ignoreVersionCheck \
"$ROOT/ice/rtl/z3_demo_top.v" \
"$ROOT/ice/rtl/z3_demo_ice_top.v" \
> compile_ice.log 2>&1
rc=$?
set -e
cat compile_ice.log
if [ $rc -ne 0 ] || grep -q -E '\*E,|ERROR|FATAL|FLOW_FAILED' compile_ice.log; then
echo "======================================================================"
echo " [FAIL] IXCOM ICE 编译失败 (rc=$rc)!请查看日志: compile_ice.log"
echo "======================================================================"
exit 1
fi
echo "======================================================================"
echo " [SUCCESS] Palladium Z3 ICE 硬件编译成功!"
echo " 下一步: 执行 xeDebug 进行上机运行与状态机自检"
echo "======================================================================"
+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
# =============================================================================
# run_local_ice.sh -- 本地免硬件验证 ICE 自检状态机逻辑
# =============================================================================
set -e
cd "$(dirname "$0")/../.."
mkdir -p ice/sim_local
echo "=========================================================="
echo " 本地离线验证 ICE 自检状态机 (z3_demo_ice_top) "
echo "=========================================================="
if command -v iverilog >/dev/null 2>&1; then
echo "使用 Icarus Verilog 进行本地编译与仿真..."
iverilog -g2005 -DLOCAL_SIM -o ice/sim_local/z3_demo_ice.vvp \
ice/rtl/z3_demo_top.v \
ice/rtl/z3_demo_ice_top.v \
ice/tb/tb_z3_demo_ice.v
vvp ice/sim_local/z3_demo_ice.vvp | tee ice/sim_local/ice_run.log
[ -f ice/sim_local/z3_demo_ice.vcd ] || [ -f z3_demo_ice.vcd ] && mv -f z3_demo_ice.vcd ice/sim_local/ 2>/dev/null || true
elif command -v xrun >/dev/null 2>&1; then
echo "使用 Cadence xrun 进行本地仿真..."
xrun -64bit -define LOCAL_SIM -access +rwc \
ice/rtl/z3_demo_top.v \
ice/rtl/z3_demo_ice_top.v \
ice/tb/tb_z3_demo_ice.v \
-logfile ice/sim_local/ice_run.log
else
echo "未检测到 iverilog 或 xrun!"
exit 1
fi
echo ""
if grep -q "ICE Self-Check FSM Passed Successfully" ice/sim_local/ice_run.log; then
echo "===> [SUCCESS] ICE 状态机本地验证全部通过!"
else
echo "===> [FAIL] ICE 验证未通过,请查看日志: ice/sim_local/ice_run.log"
exit 1
fi
+43
View File
@@ -0,0 +1,43 @@
# =============================================================================
# run_xedebug_ice.tcl -- Palladium Z3 ICE 标准上机运行脚本
#
# 官方标准流程:
# 1. debug . -- 进入调试上下文
# 2. host <XE_HOST> -- 连接 Palladium Z3 物理机台
# 3. xc on -run -- 下载网表到硬件并启动运行
# =============================================================================
# 1. 进入调试上下文
debug .
# 2. 连接 Palladium Z3 物理机台
if {[info exists env(XE_HOST)]} {
host $env(XE_HOST)
} else {
host z7f1x8c-5k9p3m
}
# 3. 下载设计到硬件并启动
xc on -run
# 4. 运行 2000 个时钟周期供自检 FSM 判定
run 2000
# 5. 读取硬件引脚判定结果
set done_val [value /z3_demo_ice_top/led_done]
set pass_val [value /z3_demo_ice_top/led_pass]
set fail_val [value /z3_demo_ice_top/led_fail]
set gpio_val [value /z3_demo_ice_top/led_gpio]
puts "=========================================================="
puts " led_done : $done_val"
puts " led_pass : $pass_val"
puts " led_fail : $fail_val"
puts " led_gpio : $gpio_val"
if {$pass_val == 1 && $fail_val == 0} {
puts "===> [TEST PASSED] Palladium Z3 ICE 全硬件测试通过!"
} else {
puts "===> [TEST FAILED] ICE 硬件自检未通过"
}
puts "=========================================================="
+71
View File
@@ -0,0 +1,71 @@
// -----------------------------------------------------------------------------
// tb_z3_demo_ice.v -- Local testbench for z3_demo_ice_top
//
// Used to verify that the hardware self-checking FSM inside z3_demo_ice_top
// runs correctly to completion and asserts led_pass BEFORE downloading into
// Palladium Z3 hardware.
// -----------------------------------------------------------------------------
`timescale 1ns/1ps
module tb_z3_demo_ice;
reg clk;
reg rst_n;
wire [7:0] led_gpio;
wire led_irq;
wire led_done;
wire led_pass;
wire led_fail;
z3_demo_ice_top u_ice_top (
.clk_in (clk),
.rst_n_in (rst_n),
.led_gpio (led_gpio),
.led_irq (led_irq),
.led_done (led_done),
.led_pass (led_pass),
.led_fail (led_fail)
);
always #5 clk = ~clk;
initial begin
clk = 0;
rst_n = 0;
`ifdef LOCAL_SIM
$dumpfile("ice/sim_local/z3_demo_ice.vcd");
$dumpvars(0, tb_z3_demo_ice);
`endif
$display("==========================================================");
$display(" Palladium Z3 ICE Self-Check FSM Verification Start ");
$display("==========================================================");
#100;
rst_n = 1;
// Wait for FSM completion
@(posedge led_done);
#50;
$display("==========================================================");
$display(" [ICE Status] led_done=%b, led_pass=%b, led_fail=%b", led_done, led_pass, led_fail);
$display(" [ICE Status] led_gpio=0x%02X, led_irq=%b", led_gpio, led_irq);
if (led_pass && !led_fail) begin
$display("===> [PASS] ICE Self-Check FSM Passed Successfully!");
end else begin
$display("===> [FAIL] ICE Self-Check FSM Reported Failure!");
end
$display("==========================================================");
$finish;
end
initial begin
#50000;
$display("[TIMEOUT] ICE Simulation watchdog expired!");
$finish;
end
endmodule