Files
Palladium-Z3-demo_ice_top/tb/tb_z3_demo.v
T

193 lines
6.0 KiB
Verilog

// -----------------------------------------------------------------------------
// tb_z3_demo.v -- Simulation Acceleration testbench for z3_demo_top
//
// When compiled for Palladium SA mode:
// ixcom -ua +dut+z3_demo_top -f rtl.f -f tb.f
// this module runs on the host (Xcelium), driving transactions across the
// Palladium InfiniBand/PCIe link to z3_demo_top which runs inside Palladium Z3.
//
// The testbench can also be run locally on a workstation (iverilog / xrun)
// via scripts/run_local.sh without Palladium hardware.
// -----------------------------------------------------------------------------
`timescale 1ns/1ps
module tb_z3_demo;
reg clk;
reg rst_n;
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;
// Instantiate DUT
z3_demo_top dut (
.clk (clk),
.rst_n (rst_n),
.paddr (paddr),
.psel (psel),
.penable (penable),
.pwrite (pwrite),
.pwdata (pwdata),
.prdata (prdata),
.pready (pready),
.gpio_out (gpio_out),
.irq (irq),
.cmp_hit (cmp_hit)
);
// 100 MHz clock
always #5 clk = ~clk;
// APB write task
task apb_write(input [7:0] addr, input [31:0] data);
begin
@(posedge clk);
paddr <= addr;
pwrite <= 1'b1;
psel <= 1'b1;
pwdata <= data;
@(posedge clk);
penable <= 1'b1;
@(posedge clk);
while (!pready) @(posedge clk);
psel <= 1'b0;
penable <= 1'b0;
pwrite <= 1'b0;
end
endtask
// APB read task
task apb_read(input [7:0] addr, output [31:0] data);
begin
@(posedge clk);
paddr <= addr;
pwrite <= 1'b0;
psel <= 1'b1;
@(posedge clk);
penable <= 1'b1;
@(posedge clk);
while (!pready) @(posedge clk);
data = prdata;
psel <= 1'b0;
penable <= 1'b0;
end
endtask
reg [31:0] rdata;
integer pass_count;
integer fail_count;
initial begin
pass_count = 0;
fail_count = 0;
clk = 0;
rst_n = 0;
paddr = 0;
psel = 0;
penable = 0;
pwrite = 0;
pwdata = 0;
`ifdef LOCAL_SIM
$dumpfile("sim_local/z3_demo.vcd");
$dumpvars(0, tb_z3_demo);
`endif
$display("==========================================================");
$display(" Palladium Z3 SA-Mode Verification Start (z3_demo_top) ");
$display("==========================================================");
// Reset DUT
#100;
rst_n = 1;
#20;
// Check 1: ID Register Verification (Z3 signature 0x5A33_0001)
apb_read(8'h18, rdata);
if (rdata == 32'h5A33_0001) begin
$display("[PASS] Check 1: Z3 ID register match (0x%08X)", rdata);
pass_count = pass_count + 1;
end else begin
$display("[FAIL] Check 1: Z3 ID mismatch! Expected 0x5A330001, got 0x%08X", rdata);
fail_count = fail_count + 1;
end
// Check 2: Default LOAD and COUNT value
apb_read(8'h08, rdata);
if (rdata == 32'd9) begin
$display("[PASS] Check 2: Default COUNT is 9");
pass_count = pass_count + 1;
end else begin
$display("[FAIL] Check 2: Default COUNT error: 0x%08X", rdata);
fail_count = fail_count + 1;
end
// Check 3: Configure Timer: LOAD=5, CMP=2, CTRL=(enable|irq_en|pattern_en)
apb_write(8'h04, 32'd5); // LOAD = 5
apb_write(8'h0C, 32'd2); // CMP = 2
apb_write(8'h00, 32'h07); // CTRL: enable=1, irq_en=1, pattern_en=1
// Wait for timer interrupt
@(posedge irq);
$display("[PASS] Check 3: Timer interrupt (irq) asserted!");
pass_count = pass_count + 1;
// Check 4: Status Register (timeout and cmp flags should be set)
apb_read(8'h10, rdata);
if ((rdata & 32'h03) == 32'h03) begin
$display("[PASS] Check 4: STATUS register bits set (timeout & cmp: 0x%08X)", rdata);
pass_count = pass_count + 1;
end else begin
$display("[FAIL] Check 4: STATUS register error: 0x%08X", rdata);
fail_count = fail_count + 1;
end
// Check 5: Clear status (W1C)
apb_write(8'h10, 32'h03);
apb_read(8'h10, rdata);
if ((rdata & 32'h03) == 32'h00) begin
$display("[PASS] Check 5: STATUS cleared via W1C");
pass_count = pass_count + 1;
end else begin
$display("[FAIL] Check 5: STATUS W1C failed: 0x%08X", rdata);
fail_count = fail_count + 1;
end
// Check 6: GPIO Rotating Pattern (0x01 -> 0x02 on first timeout)
apb_read(8'h14, rdata);
if (rdata[7:0] == 8'h02) begin
$display("[PASS] Check 6: GPIO pattern rotated to 0x02");
pass_count = pass_count + 1;
end else begin
$display("[FAIL] Check 6: GPIO pattern error: 0x%02X", rdata[7:0]);
fail_count = fail_count + 1;
end
#200;
$display("==========================================================");
if (fail_count == 0) begin
$display(" TEST PASSED: ALL %0d CHECKS COMPLETED ON Z3 ! ", pass_count);
end else begin
$display(" TEST FAILED: %0d PASSED, %0d FAILED ", pass_count, fail_count);
end
$display("==========================================================");
$finish;
end
// Safety timeout
initial begin
#100000;
$display("[TIMEOUT] Simulation reached max time limit (watchdog)!");
$finish;
end
endmodule