feat: complete Palladium Z3 demo (SA & ICE dual-mode) and 24.05 hardware compilation fix
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// z3_demo_top.v -- Palladium Z3 emulation demo DUT
|
||||
//
|
||||
// A small, fully synthesizable, register-mapped timer peripheral used to
|
||||
// demonstrate the Cadence Palladium Z3 flow end to end:
|
||||
// IXCOM compile (SA mode) -> download with xeDebug -> run -> check results
|
||||
//
|
||||
// Bus: APB-like (single-cycle ready). Low 8 address bits decoded.
|
||||
//
|
||||
// Register map (byte addresses):
|
||||
// 0x00 CTRL [0]=enable [1]=irq_en [2]=pattern_en (RW)
|
||||
// 0x04 LOAD reload value of the down counter (RW)
|
||||
// 0x08 COUNT current counter value (RO)
|
||||
// 0x0C CMP compare value: pulse cmp_hit when COUNT==CMP (RW)
|
||||
// 0x10 STATUS [0]=timeout flag (W1C) [1]=cmp flag (W1C) (RW/RO)
|
||||
// 0x14 GPIO 8-bit rotating pattern output register (RW)
|
||||
// 0x18 ID constant 0x5A33_0001 (Z3 Signature) (RO)
|
||||
//
|
||||
// Behaviour:
|
||||
// * When CTRL.enable=1, COUNT decrements every clock. When it reaches 0 it
|
||||
// sets STATUS.timeout, raises irq (if irq_en), and reloads from LOAD.
|
||||
// * When COUNT==CMP, STATUS.cmp is set and cmp_hit pulses for one cycle.
|
||||
// * When CTRL.pattern_en=1, GPIO rotates left by one bit on every timeout,
|
||||
// giving a visible "running light" to observe in xeDebug / waveforms.
|
||||
// -----------------------------------------------------------------------------
|
||||
`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
|
||||
);
|
||||
|
||||
// ------------------------------------------------------------------ regs
|
||||
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);
|
||||
|
||||
// ------------------------------------------------------------- write path
|
||||
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; // default period: 10 cycles
|
||||
reg_cmp <= 32'd3;
|
||||
reg_gpio <= 8'h01;
|
||||
status_timeout <= 1'b0;
|
||||
status_cmp <= 1'b0;
|
||||
end else begin
|
||||
// sticky flags: set by hardware events, cleared by W1C writes
|
||||
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; // direct reload on LOAD write
|
||||
end
|
||||
8'h0C: reg_cmp <= pwdata;
|
||||
8'h10: begin
|
||||
if (pwdata[0]) status_timeout <= 1'b0; // W1C
|
||||
if (pwdata[1]) status_cmp <= 1'b0; // W1C
|
||||
end
|
||||
8'h14: reg_gpio <= pwdata[7:0];
|
||||
default: ;
|
||||
endcase
|
||||
end else if (ctrl_enable) begin
|
||||
// down counter operation
|
||||
if (reg_count == 32'd0) begin
|
||||
reg_count <= reg_load;
|
||||
if (ctrl_pattern_en)
|
||||
reg_gpio <= {reg_gpio[6:0], reg_gpio[7]}; // barrel roll
|
||||
end else begin
|
||||
reg_count <= reg_count - 32'd1;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
// -------------------------------------------------------------- read path
|
||||
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 signature
|
||||
default: prdata = 32'hDEAD_BEEF;
|
||||
endcase
|
||||
end else begin
|
||||
prdata = 32'h0;
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
Reference in New Issue
Block a user