152 lines
6.0 KiB
Verilog
152 lines
6.0 KiB
Verilog
// -----------------------------------------------------------------------------
|
|
// z2_demo_ice_top.v -- Palladium Z2 ICE-mode demo top
|
|
//
|
|
// ICE (In-Circuit Emulation) has NO software testbench: everything that runs
|
|
// in the emulator must be hardware. This top therefore wraps the SAME DUT as
|
|
// the SA demo (z2_demo_top) with a small synthesizable stimulus/checker FSM
|
|
// that plays the role the SystemVerilog/Verilog TB played in SA mode:
|
|
//
|
|
// reset -> program LOAD/CMP -> read & check ID -> enable timer
|
|
// -> wait for irq -> check STATUS flags -> check GPIO rotation
|
|
// -> disable, W1C-clear flags, re-check -> PASS/FAIL LEDs
|
|
//
|
|
// Top-level pins (these are what ICE target/clock hookup sees):
|
|
// clk_in design clock (from target or emulator clock configuration)
|
|
// rst_n_in active-low reset
|
|
// led_gpio mirrors DUT gpio_out (the rotating pattern)
|
|
// led_irq mirrors DUT irq
|
|
// led_done sequence finished
|
|
// led_pass all hardware checks passed
|
|
// led_fail a check failed (or irq timed out)
|
|
// -----------------------------------------------------------------------------
|
|
`timescale 1ns/1ps
|
|
|
|
module z2_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;
|
|
|
|
z2_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;
|
|
|
|
// Bus drive is combinational from the state: each WR/RD state lasts
|
|
// exactly one clock, which is one full transaction for this DUT
|
|
// (pready is constant 1 and writes are captured on the clock edge).
|
|
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
|
|
wait_cnt <= wait_cnt + 16'd1;
|
|
if (wait_cnt >= 16'd7) state <= ST_WR_LOAD;
|
|
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: state <= (rd_latched == 32'h5A32_0001) ? ST_WR_CTRL : ST_FAIL;
|
|
ST_WR_CTRL: begin wait_cnt <= 16'd0; state <= ST_WAIT_IRQ; end
|
|
ST_WAIT_IRQ: begin
|
|
wait_cnt <= wait_cnt + 16'd1;
|
|
if (irq) state <= ST_RD_STAT;
|
|
else if (wait_cnt > 16'd200) state <= ST_FAIL; // irq timeout guard
|
|
end
|
|
ST_RD_STAT: begin rd_latched <= prdata; state <= ST_CHK_STAT; end
|
|
ST_CHK_STAT: state <= (rd_latched[1:0] == 2'b11) ? ST_RD_GPIO : ST_FAIL;
|
|
ST_RD_GPIO: begin rd_latched <= prdata; state <= ST_CHK_GPIO; end
|
|
ST_CHK_GPIO: state <= (rd_latched == 32'd2) ? ST_WR_CTRL0 : ST_FAIL;
|
|
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: state <= (rd_latched == 32'd0) ? ST_PASS : ST_FAIL;
|
|
ST_PASS: begin led_done <= 1'b1; led_pass <= 1'b1; state <= ST_PASS; end
|
|
ST_FAIL: begin led_done <= 1'b1; led_fail <= 1'b1; state <= ST_FAIL; end
|
|
default: state <= ST_WAIT;
|
|
endcase
|
|
end
|
|
end
|
|
|
|
wire _unused = &{1'b0, pready, cmp_hit};
|
|
|
|
endmodule
|