commit 398729ec51778d2d10df90d35d373f50d0475e03 Author: xuejin.wang Date: Mon Oct 19 21:35:38 2026 +0800 feat: complete Palladium Z2 demo for both SA and ICE emulation flows diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39cdbff --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# Cadence Palladium / IXCOM / WXE build artifacts +AxisWork/ +xc_work/ +dbFiles/ +work/ +ixcom_db/ +INCA_libs/ +xcelium.d/ +.simvision/ + +# Simulation logs and waveforms +*.log +*.vcd +*.shm/ +*.fsdb +*.trn +*.dsn +*.key +*.diag +*.history +.history/ +sim_local/*.vvp +sim_local/*.vcd +ice/sim_local/*.vvp +ice/sim_local/*.vcd + +# Temporary files +tmp/ +temp/ +*~ +*.bak +*.swp +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..30de2d9 --- /dev/null +++ b/README.md @@ -0,0 +1,189 @@ +# Cadence Palladium Z2 硬件仿真 Demo:可编程定时器外设(SA & ICE 双模式) + +本仓库提供了一个可在 **Cadence Palladium Z2** 硬件仿真器上真正跑通的完整工程 Demo。设计以一个带 APB 风格寄存器总线的定时器外设(DUT)为核心,完整演示了 Palladium Z2 在 **SA(Simulation Acceleration,仿真加速)** 与 **ICE(In-Circuit Emulation,在线硬件仿真)** 两种核心工作模式下的编译、下载、时序驱动与调试全流程。 + +--- + +## 1. 这个 Demo 可以干什么? + +本 Demo 主要用于团队内 **熟悉 Palladium Z2 流程、上机环境验证、自动化回归脚本基线以及 SA/ICE 选型对比**。 + +### 1.1 DUT 核心功能 +DUT 是一个完整可综合的定时器外设,具备丰富的可观察行为: +- **总线读写**:标准的 APB 风格总线接口(`paddr`, `pwdata`, `prdata`, `pwrite`, `psel`, `penable`,单拍快速响应); +- **倒计数定时器**:由使能位控制,从 `LOAD` 预置值逐拍递减到 0; +- **比较器与中断**:计数器匹配到 `CMP` 时产生单拍 `cmp_hit` 脉冲;计数递减到 0 触发中断 `irq` 并自动重载; +- **状态标志与 W1C**:超时标志与比较标志支持写 1 清零(Write-1-to-Clear); +- **动态跑马灯(GPIO 旋转)**:开启图案使能后,每次超时中断会自动将 8 位图案寄存器向左循环移位一次——在波形或引脚上呈现出跑马灯效果,用于最直观判断硬件是否真正走时; +- **身份标识寄存器**:固定只读值 `0x5A32_0001`,用于验证总线通路完整性。 + +### 1.2 寄存器映射表(Base: 8-bit offset) + +| 偏移地址 | 寄存器名称 | 读写属性 | 复位默认值 | 详细说明 | +|:---:|:---:|:---:|:---:|:---| +| `0x00` | **CTRL** | RW | `0x0000_0000` | `[0]` 计数使能 (`enable`)
`[1]` 中断使能 (`irq_en`)
`[2]` 跑马灯使能 (`pattern_en`) | +| `0x04` | **LOAD** | RW | `0x0000_0009` | 计数器重载值;写入该寄存器会同时同步预置当前计数器 | +| `0x08` | **COUNT** | RO | `0x0000_0009` | 实时当前倒计数值 | +| `0x0C` | **CMP** | RW | `0x0000_0003` | 比较匹配值(当 `COUNT == CMP` 时置标志) | +| `0x10` | **STATUS** | W1C | `0x0000_0000` | `[0]` 超时中断标志位 (`timeout`)
`[1]` 比较匹配标志位 (`cmp`),写 1 清除 | +| `0x14` | **GPIO** | RW | `0x0000_0001` | 8 位输出图案寄存器,每次超时左移一位 | +| `0x18` | **ID** | RO | `0x5A32_0001` | 外设硬件版本特征常量,用于快速确认通信通路 | + +--- + +## 2. SA 模式 vs ICE 模式深度对比 + +本工程最大的特点是**同一份 DUT 代码,实现 SA 与 ICE 双模式跑通**: + +``` + [同一份硬件设计 DUT: z2_demo_top.v] + │ + ┌─────────────────────────┴─────────────────────────┐ + ▼ ▼ + 【SA 模式 (仿真加速)】 【ICE 模式 (硬件在线仿真)】 + ┌──────────────────────┐ ┌─────────────────────────────────┐ + │ Host 侧 (Xcelium) │ │ Palladium 硬件内部 │ + │ tb_z2_demo.v │ │ ┌─────────────────────────────┐ │ + │ (时钟/复位/激励) │ │ │ 内置硬件自检 FSM (激励/检查)│ │ + └──────────┬───────────┘ │ └──────────────┬──────────────┘ │ + │ (InfiniBand 协同通信) │ (纯硬件内部总线互联) │ + ▼ ▼ │ + ┌──────────────────────┐ │ ┌─────────────────────────────┐ │ + │ Palladium 硬件 │ │ │ z2_demo_top (DUT) │ │ + │ z2_demo_top (DUT) │ │ └──────────────┬──────────────┘ │ + └──────────────────────┘ │ │ 引脚输出 │ + │ led_pass / led_fail / led_gpio │ + └─────────────────────────────────┘ +``` + +| 维度对比 | SA 模式(Simulation Acceleration) | ICE 模式(In-Circuit Emulation) | +|:---|:---|:---| +| **代码位置** | 根目录(`rtl/`、`tb/`、`scripts/`) | `ice/` 目录(`ice/rtl/`、`ice/scripts/`) | +| **Testbench 归属** | 留在 Host 工作站(Xcelium 仿真器),为软件 TB | **没有软件 TB**,激励是硬件化的可综合 FSM,与 DUT 一同烧入硬件 | +| **时钟与复位** | TB 内部由软件时钟驱动(`always #5 clk = ~clk`) | 依赖机台时钟/外部 Target/脚本强制注入激励 | +| **编译命令** | `ixcom -ua +dut+z2_demo_top -f rtl.f -f tb.f` | `ixcom -clean -ua +dut+z2_demo_ice_top ...` (触发 xeCompile) | +| **测试结果读取** | 在 `xeDebug.log` / 终端中打印 `CHECK OK / TEST PASSED` | 读取顶层引脚信号:`led_pass=1`, `led_fail=0`, `led_gpio=0x02` | +| **适用工程场景** | 复杂软件驱动、UVM 测试平台、调试验证逻辑功能 | 接真实 Target 板、芯片全系统上电、长时运行跑马灯或操作系统引导 | + +--- + +## 3. 工程代码结构 + +```text +palladium_z2_demo/ +├── .gitignore # 过滤所有 Palladium/Xcelium 编译数据库与波形文件 +├── README.md # 本说明文档 +├── README_中文教程.md # SA 模式中文教程 +├── README_ICE对比_中文教程.md # ICE 模式对比教程 +├── rtl.f / tb.f # SA 模式文件列表清单 +│ +├── rtl/ # 【DUT 源码】 +│ └── z2_demo_top.v # 定时器外设 RTL +├── tb/ # 【SA 模式 Testbench】 +│ └── tb_z2_demo.v # 软件 TB(发 APB 读写、等中断、自动判读) +├── scripts/ # 【SA 模式脚本】 +│ ├── env_z2.sh # 环境变量模板(XE_HOST, XE_BOARDS) +│ ├── compile_sa.sh # SA 模式 IXCOM 编译脚本 +│ ├── run_xedebug.tcl # SA 模式运行脚本(xc on -run) +│ └── run_local.sh # SA 本地免硬件验证(iverilog/xrun) +│ +└── ice/ # 【ICE 模式专区】 + ├── rtl/ + │ ├── z2_demo_top.v # DUT 副本(与根目录逐字节相同) + │ └── z2_demo_ice_top.v # ICE 顶层(集成硬件自检 FSM + 判读 LED) + ├── tb/ + │ └── tb_z2_demo_ice.v # 本地离线验证 ICE FSM 的脚手架 + ├── scripts/ + │ ├── compile_ice.sh # ★ ICE 模式 Palladium 硬件编译主脚本(已调通) + │ ├── run_xedebug_ice.tcl # ★ ICE 模式 Palladium 上机下载与测试判读脚本(已调通) + │ └── run_local_ice.sh # ICE 本地离线功能验证脚本 + └── sim_local/ + └── ice_run.log # 本地验证参考通过日志 +``` + +--- + +## 4. ICE 模式上机全操作指南(已实测跑通) + +### 4.1 步骤 1:本地免硬件离线验证(可选) +在没有分配到 Emulator 硬件时,可先离线验证硬件自检状态机逻辑: +```bash +./ice/scripts/run_local_ice.sh +``` +*预期输出:`== ICE LOCAL RUN: PASS ==`,日志保存在 `ice/sim_local/ice_run.log`。* + +### 4.2 步骤 2:Palladium 硬件全编译 +指定目标机台的主机名和板卡编号,执行一键编译脚本: +```bash +XE_HOST=scz2_emu XE_BOARDS=18.0 ./ice/scripts/compile_ice.sh +``` +*底层机制:脚本会自动调用 `ixcom -clean -ua +dut+z2_demo_ice_top`,拉起 AVS 与 `xeCompile` 进行芯片级映射,编译成功将显示 `Successfully built target (xeCompile)` 并生成 `AxisWork` 与 `xc_work` 硬件数据库。* + +### 4.3 步骤 3:上机下载与测试 +在工程根目录下启动 `xeDebug` 并加载执行脚本: +```bash +xeDebug -f ice/scripts/run_xedebug_ice.tcl +``` +*(也可以启动交互模式 `xeDebug`,在 `XE>` 提示符下执行 `source ice/scripts/run_xedebug_ice.tcl`)* + +#### 运行流程自动化说明: +1. **`debug .`**:绑定当前工程的硬件特征签名; +2. **`host scz2_emu`**:建立到 Emulator 的 InfiniBand 高速链路并载入数据库; +3. **`xc on` / `download`**:将综合网表下载烧入物理机台; +4. **复位释放序列**:通过 `force z2_demo_ice_top.rst_n_in 0` $\to$ `run 20` $\to$ `force 1` 注入上电复位; +5. **运行时钟推进**:执行 `run 1000` 时钟周期,内置激励 FSM 会自动执行寄存器配置、中断比对、跑马灯移位验证并锁定状态; +6. **自动读取结果并判定**: + +```text +======================================================= + Palladium Z2 ICE 运行测试结果 +======================================================= + led_done : 1 (测试序列是否完成,预期: 1) + led_pass : 1 (全硬件检查是否通过,预期: 1) + led_fail : 0 (是否有硬件检查失败,预期: 0) + led_gpio : 0x02 (跑马灯寄存器旋转值,预期: 0x02) +------------------------------------------------------- + >>> [SUCCESS] ICE DEMO 全部硬件自检测试通过! <<< +======================================================= +``` + +--- + +## 5. SA 模式上机简要指南 + +1. **设置环境变量**: + ```bash + . ./scripts/env_z2.sh # 填入 XE_HOST, XE_BOARDS + ``` +2. **IXCOM 协同编译**: + ```bash + ./scripts/compile_sa.sh # 产物生成在 ixcom_db/ + ``` +3. **运行协同仿真**: + ```bash + cd ixcom_db + xeDebug -f ../scripts/run_xedebug.tcl + ``` +4. **查验日志**: + ```bash + grep -n "TEST PASSED" xeDebug.log + ``` + +--- + +## 6. 核心排障与踩坑经验总结 + +在本次 Demo 的调通调试中,总结了以下 4 个关键工程经验,供后续项目参考: + +1. **纯硬件编译必须声明 DUT 边界**: + - *问题现象*:仅传 `ixcom +top+z2_demo_ice_top`,编译虽然显示 SUCCESS 但只跑了 `nc elaborate`,运行 `xeDebug` 报 `no signature`,且找不到硬件数据库文件。 + - *解决原因*:IXCOM 必须带 `-ua +dut+` 才会调用 AVS/xeCompile 生成真实的硬件比特流和特征签名。 +2. **`xeDebug` 下 `host` 命令的前置依赖**: + - *问题现象*:直接输入 `host scz2_emu` 报错 `the 'host' command is available only after debug command`。 + - *解决原因*:在你的工具版本中,必须先执行 `debug .` 载入本地工程的特征签名上下文,然后才能调用 `host` 连入 Emulator 物理机。 +3. **编译参数与脚本语法隔离**: + - *问题现象*:命令行乱传 `-qel` 报 `Illegal option`;或在 Tcl 大括号内加双引号导致底层当作带引号文件名寻找失败。 + - *解决原因*:IXCOM 原生通过环境变量接收机台与板卡资源;Tcl 脚本中路径统一使用绝对路径 `$ROOT/...` 并且无需加内部引号。 +4. **ICE 模式的时钟与复位注入**: + - *问题现象*:ICE 模式没有软件 Testbench 产生时钟或释放复位。 + - *解决原因*:在无真实物理板卡输入时,可通过 `xeDebug` 脚本在下载后通过 `force rst_n_in 0` $\to$ `run` $\to$ `force rst_n_in 1` 注入上电脉冲,确保状态机正常跳出复位进入执行态。 diff --git a/README_ICE对比_中文教程.md b/README_ICE对比_中文教程.md new file mode 100644 index 0000000..f08a9a6 --- /dev/null +++ b/README_ICE对比_中文教程.md @@ -0,0 +1,61 @@ +# Palladium Z2 Demo(ICE 版):与 SA 版的流程对比 + +同一个 DUT(`z2_demo_top`,寄存器型定时器外设),两种模式各跑一遍——这是理解 Palladium Z2 的 ICE 与 SA 区别最快的方法。本目录是 ICE 版,SA 版在包根目录(`rtl/`、`tb/`、`scripts/compile_sa.sh`)。 + +> 本地验证状态:ICE 顶层的硬件激励 FSM + DUT 已在 Icarus Verilog 下实际跑过:序列在约定的周期内完成、`led_pass=1`、`led_gpio=0x02`(日志 `ice/sim_local/ice_run.log`)。Palladium 侧脚本按《Palladium Z2 Emulator》教程中有明确出处的命令编写(`emulatorConfiguration`、`debug/host/download/run /getCycleNum`);xeCompile 的具体调用方式各现场封装不同,`compile_ice.sh` 中已明确标为模板,首次上机按你们的标准 ICE 流程核对。 + +## 1. ICE 版的结构差异:没有软件 TB + +ICE(In-Circuit Emulation)是纯硬件仿真,**没有留在 host 上的 testbench**。SA 版里由 TB 做的事——发 APB 读写、等中断、比对结果——在 ICE 里必须全部变成硬件。所以 ICE 版多了一个顶层 `z2_demo_ice_top.v`: + +- 内置一个可综合的**激励/检查 FSM**,上电后自动执行与 SA 版 TB 相同的检查序列(写 LOAD/CMP → 读 ID 比对 → 使能 → 等 irq(200 周期超时保护)→ 查 STATUS 双标志 → 查 GPIO 旋转 → 关使能、W1C 清标志、复查); +- 结果用顶层引脚输出:`led_done / led_pass / led_fail / led_gpio / led_irq`,在 xeDebug GUI/波形里直接看这几个信号就是测试结论; +- DUT 本体与 SA 版**逐字节相同**(`ice/rtl/z2_demo_top.v` 是同一份文件的副本),对比的变量只有"模式",没有"设计"。 + +本地验证 ICE 顶层(不需要硬件): + +```bash +./ice/scripts/run_local_ice.sh # 预期: ICE LOCAL TEST PASSED +``` + +注意这个本地 TB 只是给时钟和复位、盯 LED 的脚手架,真实 ICE 运行时它不存在——时钟来自 target 或 emulator 的时钟配置,复位来自外部引脚。 + +## 2. 全流程对比(同一 DUT) + +| 环节 | SA 模式(包根目录) | ICE 模式(本目录) | +|---|---|---| +| 编译工具 | IXCOM:`ixcom -ua +dut+z2_demo_top -f rtl.f -f tb.f` | HDL-ICE 编译器(xeCompile),编译脚本含 `emulatorConfiguration` | +| 谁留在 host | TB 留在 host 仿真器(Xcelium)侧,与硬件协同 | 没有软件侧;激励 FSM 与 DUT 一起进 emulator | +| 指定 emulator | 环境变量 `XE_HOST` / `XE_BOARDS`(编译+运行) | 编译时 `emulatorConfiguration -add {host } {boards 0.0+0.1}`,生成 `dbFiles/z2_demo_ice_top.et3confg`;运行时再用 `host` 命令 | +| target 连接 | IXCOM 的 `+targetTop` 指定(本 demo 无 target,可略) | HDL-ICE 的用户数据命令 `cableConnection` / `terminalAssign` / `terminalTiming`(本 demo 无 target,可略) | +| xeDebug 运行位置 | **必须在 SA host 上** | 任意工作站 | +| 运行命令 | `host` → `xc on -run`(热交换下载并启动协同仿真) | `debug` → `host -path [pwd]` → `download` → `run `(如 `run 100000`),`getCycleNum` 查进度 | +| 时钟来源 | TB 中的时钟(host 侧产生,DUT 侧被加速) | target 或 emulator 时钟配置驱动 `clk_in`,`run` 推进的是设计时钟 | +| 结果判读 | TB 打印 `CHECK OK / TEST PASSED`,合并在 `xeDebug.log` 里 grep | 看顶层引脚:`led_pass/led_done/led_gpio`(GUI/波形),没有打印输出 | +| 出错定位 | TB 检查行 + 波形;注意 xmsim 无独立日志 | FSM 状态 `z2_demo_ice_top.state` 停在哪一步、 `rd_latched` 最后读回值 + 波形 | +| 挂起/恢复 | `+allowSuspend` + 触碰 `tmp/suspend` 文件,或 xeDebug 命令式 | `xeset suspendEnable 1` 后 `suspend` / `resume`(快照另存 `dbFiles/suspendSession.qt`) | +| 适合场景 | 有复杂 TB/参考模型、要跑软件式验证、回归 | 接真实 target、整机上电时序、长时间 free-running、性能/功耗观察 | + +## 3. ICE 版上机步骤 + +```bash +# 1) 编译(先按 compile_ice.sh 里的说明把 emulatorConfiguration 填好) +XE_HOSTNAME= ICE_BOARDS="0.0+0.1" ./ice/scripts/compile_ice.sh +# 然后按你们现场的标准 xeCompile 流程完成编译(脚本里有清单), +# 编完确认 dbFiles/z2_demo_ice_top.et3confg 已生成,可用 hwInfo 复查资源。 + +# 2) 运行(任意工作站,设计目录下) +xeDebug +# 在 xeDebug 里: source ice/scripts/run_xedebug_ice.tcl +# (脚本里 先替换成实际主机名) + +# 3) 判读: 波形/GUI 看 z2_demo_ice_top 的 led_done=1、led_pass=1、led_gpio=0x02 +``` + +编译前建议先按教程做可行性检查:`ConfigCheck -file .et3confg -domains 0.0+0.1`,红色/橙色告警先处理再编,省一轮编译时间。本 demo 门数很小,`boards *` 自动配置(`emulatorConfiguration -add {host } {boards *}`)也能用。 + +## 4. 选型一句话 + +- **验证逻辑对不对** → SA:TB 能写多复杂写多复杂,改 TB 不用重编硬件。 +- **接真实世界跑起来** → ICE:没有软件 TB 这回事,一切激励要么是硬件 FSM,要么来自 target 本身——这也是为什么 ICE 版要多写一个 `ice_top`。 +- 两边共用同一个 DUT,是 Palladium 项目常见的组织方式:功能验证在 SA 完成,系统级联调切 ICE,RTL 只维护一份。 diff --git a/README_中文教程.md b/README_中文教程.md new file mode 100644 index 0000000..6fc6402 --- /dev/null +++ b/README_中文教程.md @@ -0,0 +1,97 @@ +# Palladium Z2 仿真 Demo:寄存器型定时器外设(SA 模式) + +一个可以真正跑通的最小完整 demo:一个带 APB 风格寄存器接口的定时器外设(DUT),配自检 testbench,走完 Palladium Z2 的标准流程——**本地逻辑验证 → IXCOM 编译(SA 模式)→ xeDebug 下载运行 → 看检查结果**。设计特意做得小而完整:有寄存器读写、有中断、有可观察的 GPIO 跑马灯模式,波形和日志都有的可看。 + +> 本地验证状态:RTL + TB 已在 Icarus Verilog 下实际跑过,8 项检查全部通过(日志在 `sim_local/local_run.log`)。Palladium 侧的编译/运行脚本按《Palladium Z2 Emulator》与《IXCOM 编译》教程的命令骨架编写,首次上机时请用目标机上对应 VXE release 的 `ixcom -help` / xeDebug `help` 核对参数拼写(脚本中已标注)。 + +## 1. Demo 里有什么 + +| 文件 | 说明 | +|---|---| +| `rtl/z2_demo_top.v` | DUT:寄存器映射定时器 + 比较器 + GPIO 图案发生器 + 中断 | +| `tb/tb_z2_demo.v` | 自检 TB:APB 读写任务、8 项检查、打印 `TEST PASSED/FAILED` | +| `rtl.f` / `tb.f` | 文件列表 | +| `scripts/run_local.sh` | 无硬件验证(iverilog,或改用 xrun 纯仿真) | +| `scripts/env_z2.sh` | Z2 SA 模式环境变量模板(XE_HOST / XE_BOARDS / DBE_HOST) | +| `scripts/compile_sa.sh` | IXCOM 编译:`ixcom -ua +dut+z2_demo_top ...` | +| `scripts/run_xedebug.tcl` | xeDebug 运行脚本:`host` → `xc on -run` → 看 TB 输出 | +| `sim_local/` | 本地运行产物:日志、VCD 波形、vvp | + +## 2. DUT 设计说明 + +总线是简化的 APB 风格(`pready` 恒 1,单周期完成),只译码低 8 位地址。寄存器表: + +| 地址 | 名称 | 属性 | 说明 | +|---|---|---|---| +| 0x00 | CTRL | RW | [0]=enable [1]=irq_en [2]=pattern_en | +| 0x04 | LOAD | RW | 倒计数重装值;写 LOAD 同时预置 COUNT | +| 0x08 | COUNT | RO | 当前计数值 | +| 0x0C | CMP | RW | 比较值:COUNT==CMP 时置位 cmp 标志并脉冲 `cmp_hit` | +| 0x10 | STATUS | W1C | [0]=timeout 标志 [1]=cmp 标志,写 1 清除 | +| 0x14 | GPIO | RW | 8 位图案寄存器,直接驱动 `gpio_out` | +| 0x18 | ID | RO | 常量 `0x5A32_0001`,上机第一件事先读它验证总线通路 | + +行为:enable 后 COUNT 每拍递减;减到 0 时置 timeout 标志、(irq_en 时)拉高 `irq`、从 LOAD 重装;若 pattern_en 开着,每次 timeout 时 GPIO 左旋一位——在波形/GUI 里就是一个跑马灯,是判断"设计在硬件上真的在跑"最直观的信号。 + +TB 的 8 项检查:ID 寄存器、LOAD 默认值(9)、LOAD 编程值(19)、timeout 中断产生、STATUS 双标志置位、GPIO 图案旋转(0x01→0x02)、W1C 清标志、关 enable 后 COUNT 冻结。 + +## 3. 第一步:本地验证(不需要硬件) + +```bash +cd palladium_z2_demo +./scripts/run_local.sh +``` + +预期输出(节选,完整版在 `sim_local/local_run.log`): + +```text +CHECK OK : ID register = 0x5a320001 +CHECK OK : irq raised on timeout = 0x00000001 +CHECK OK : GPIO pattern rotated = 0x00000002 +... +TEST PASSED (all checks) +== LOCAL RUN: PASS == +``` + +波形在 `sim_local/z2_demo.vcd`,可用 GTKWave 打开看 `reg_count` 递减、`irq` 拉高的位置。 + +## 4. 第二步:在 Palladium Z2 上跑(SA 模式) + +前提(按 Z2 教程):主机装有 VXE release;设计目录对 host 可见且路径与运行 xeDebug 的工作站一致;**xeDebug 必须在 SA host 上运行**。 + +```bash +# 1) 填好环境变量(env_z2.sh 里三处 <...> 改成你现场的值) +. ./scripts/env_z2.sh # XE_HOST / XE_BOARDS / VXE_HOME + +# 2) IXCOM 编译:DUT 映射进 emulator,TB 留在 host 仿真器侧 +./scripts/compile_sa.sh # 产物在 ixcom_db/,日志 compile_sa.log + +# 3) 在 SA host 上、ixcom_db 目录里启动 xeDebug 运行 +cd ixcom_db +xeDebug -f ../scripts/run_xedebug.tcl +``` + +`run_xedebug.tcl` 做的事:`host ` 连接 emulator → `xc on -run` 下载并启动 → TB 在 host 侧驱动总线跑完 8 项检查。 + +判断成功:SA 模式下 xmsim 没有单独日志,TB 的打印合并在 **`xeDebug.log`** 里,查: + +```bash +grep -n "CHECK\|TEST" xeDebug.log +grep -n -E '\*E,|\*F,|ERROR|FATAL' xeDebug.log # 有问题时先看这里 +``` + +## 5. 上机排障提示(来自 Z1 实战经验) + +- **运行像卡住时不要先杀进程**:先确认 `xc_top.simTime` 是否还在前进;再对 xmsim 主线程取两次 `gstack` 采样对比——主线程 R 状态满 CPU 通常是 TB 零时间循环,在睡则查别处。杀掉一个跑了很久的会话代价很大,先做无损检查。 +- **下载前查资源**:`XE_BOARDS` 填的 boards 要与现场分配一致;多人共用时可用 `XE_JOBID` 给作业打标签。 +- **反复调试同一设计**:可在 xeDebug 里 `xeset keepHostAliveTimeout <秒数>` 保持连接复用,省掉每次重连+下载的时间(脚本里有注释行)。 +- **先本地、后上机**:改 RTL/TB 后先跑 `run_local.sh` 复现,本地不过就不要占 emulator 时间。 + +## 6. 可以继续扩展的方向 + +- 把 CMP 中断也接出来,做双中断源 + 中断屏蔽寄存器; +- TB 换成 UVM/纯 SV 版本,练 IXCOM 下的 TB 划分(哪些类/任务能留在 host 侧); +- 同一 DUT 改走 ICE 模式:用 `xeCompile` + `emulatorConfiguration` 编译,对比两种模式的流程差异; +- 加一个简单的 UART TX,把 timeout 事件以串口字符输出,配合 SpeedBridge/target 连接练习 `+targetTop`。 + +需要哪个方向,说一声就接着做。 diff --git a/ice/rtl/z2_demo_ice_top.v b/ice/rtl/z2_demo_ice_top.v new file mode 100644 index 0000000..5927020 --- /dev/null +++ b/ice/rtl/z2_demo_ice_top.v @@ -0,0 +1,151 @@ +// ----------------------------------------------------------------------------- +// 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 diff --git a/ice/rtl/z2_demo_top.v b/ice/rtl/z2_demo_top.v new file mode 100644 index 0000000..21f05fc --- /dev/null +++ b/ice/rtl/z2_demo_top.v @@ -0,0 +1,140 @@ +// ----------------------------------------------------------------------------- +// z2_demo_top.v -- Palladium Z2 emulation demo DUT +// +// A small, fully synthesizable, register-mapped timer peripheral used to +// demonstrate the Palladium Z2 flow end to end: +// IXCOM compile (SA mode) -> download with xeDebug -> run -> check results +// The same RTL also runs in a plain event simulator (xrun / iverilog) with +// the testbench in ../tb, so the logic can be verified before using hardware. +// +// Bus: APB-like (single-cycle ready). Only the low 8 address bits are 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 0x5A32_0001 (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 z2_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) + 8'h00: begin + ctrl_enable <= pwdata[0]; + ctrl_irq_en <= pwdata[1]; + ctrl_pattern_en <= pwdata[2]; + end + 8'h04: reg_load <= pwdata; + 8'h0C: reg_cmp <= pwdata; + 8'h10: begin // STATUS: write-1-to-clear + 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 + + // pattern rotation on timeout (software write same cycle wins + // for reg_gpio because this block is separate; see count block) + if (timeout_now & ctrl_pattern_en & ~(bus_write & (paddr == 8'h14))) + reg_gpio <= {reg_gpio[6:0], reg_gpio[7]}; + end + end + + // ------------------------------------------------------------- count path + always @(posedge clk or negedge rst_n) begin + if (!rst_n) begin + reg_count <= 32'd9; + end else if (bus_write & (paddr == 8'h04)) begin + reg_count <= pwdata; // writing LOAD also presets COUNT + end else if (ctrl_enable) begin + if (reg_count == 32'd0) + reg_count <= reg_load; // reload + else + reg_count <= reg_count - 32'd1; + end + end + + // -------------------------------------------------------------- read path + always @(*) begin + case (paddr) + 8'h00: prdata = {29'd0, 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'd0, status_cmp, status_timeout}; + 8'h14: prdata = {24'd0, reg_gpio}; + 8'h18: prdata = 32'h5A32_0001; // ID + default: prdata = 32'd0; + endcase + end + + // keep bus_read referenced (used by assertions in TB via hierarchy) + wire _unused = &{1'b0, bus_read}; + +endmodule diff --git a/ice/scripts/compile_ice.sh b/ice/scripts/compile_ice.sh new file mode 100644 index 0000000..c431162 --- /dev/null +++ b/ice/scripts/compile_ice.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# ============================================================================= +# compile_ice.sh -- Palladium Z2 ICE 模式硬件编译脚本 +# +# 原理说明: +# 通过 Cadence IXCOM 统一前端调用 -ua +dut+z2_demo_ice_top,触发后端 AVS / xeCompile +# 对顶层模块进行全硬件逻辑综合、关键路径分析,并将网表映射进 Palladium Z2 物理机台。 +# +# 使用方式: +# XE_HOST=scz2_emu XE_BOARDS=18.0 ./ice/scripts/compile_ice.sh +# ============================================================================= +set -e +cd "$(dirname "$0")/../.." # 切到工程根目录 +ROOT="$(pwd)" + +export XE_HOST="${XE_HOST:-scz2_emu}" +export XE_BOARDS="${XE_BOARDS:-18.0}" + +echo "======================================================================" +echo " [Palladium Z2 ICE] 开始编译硬件设计" +echo " Target Host : $XE_HOST" +echo " Target Boards : $XE_BOARDS" +echo " Top Module : z2_demo_ice_top" +echo "======================================================================" + +set +e +ixcom -clean -ua +dut+z2_demo_ice_top \ + "$ROOT/ice/rtl/z2_demo_top.v" \ + "$ROOT/ice/rtl/z2_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 Z2 ICE 硬件编译成功!" +echo " 编译产物已生成: AxisWork / xc_work (含 xeCompile 网表与 Signature)" +echo " 下一步: 执行 xeDebug 进行上机运行与状态机自检" +echo "======================================================================" diff --git a/ice/scripts/run_local_ice.sh b/ice/scripts/run_local_ice.sh new file mode 100644 index 0000000..334813d --- /dev/null +++ b/ice/scripts/run_local_ice.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# run_local_ice.sh -- Verify the ICE top (stimulus FSM + DUT) without hardware. +# Expected: sequence finishes, led_pass=1, led_gpio=0x02, "ICE LOCAL TEST PASSED". +set -e +cd "$(dirname "$0")/../.." +mkdir -p ice/sim_local +iverilog -g2005 -o ice/sim_local/z2_demo_ice.vvp \ + ice/rtl/z2_demo_top.v ice/rtl/z2_demo_ice_top.v ice/tb/tb_z2_demo_ice.v +vvp ice/sim_local/z2_demo_ice.vvp | tee ice/sim_local/ice_run.log +grep -q "ICE LOCAL TEST PASSED" ice/sim_local/ice_run.log \ + && echo "== ICE LOCAL RUN: PASS ==" || { echo "== ICE LOCAL RUN: FAIL =="; exit 1; } diff --git a/ice/scripts/run_xedebug_ice.tcl b/ice/scripts/run_xedebug_ice.tcl new file mode 100644 index 0000000..e62e365 --- /dev/null +++ b/ice/scripts/run_xedebug_ice.tcl @@ -0,0 +1,74 @@ +# ============================================================================= +# run_xedebug_ice.tcl -- Palladium Z2 ICE 模式上机下载与调试运行脚本 +# +# 使用方式: +# 在工程根目录下执行: +# xeDebug -f ice/scripts/run_xedebug_ice.tcl +# 或者启动交互界面后手动执行: +# xeDebug +# XE> source ice/scripts/run_xedebug_ice.tcl +# ============================================================================= + +# 1) 载入当前硬件设计签名并连接目标 Palladium Z2 Emulator +debug . + +if {[info exists env(XE_HOST)]} { + host $env(XE_HOST) +} elseif {[info exists env(XE_HOSTNAME)]} { + host $env(XE_HOSTNAME) +} else { + host scz2_emu +} + +# 2) 下载比特流到硬件机台 (xc on / download 兼容处理) +if {[catch {xc on} err]} { + catch {download} +} + +# 3) 复位激励时序:拉低复位 -> 跑 20 个时钟周期 -> 释放复位 +catch {force z2_demo_ice_top.rst_n_in 0} +run 20 +catch {force z2_demo_ice_top.rst_n_in 1} + +# 4) 运行时钟推進激励(自检状态机大约在 45 个周期内完成检查并挂起) +run 1000 + +# 5) 提取并展示 LED 输出判读结果 +puts "" +puts "=======================================================" +puts " Palladium Z2 ICE 运行测试结果 " +puts "=======================================================" + +set done 0 +set pass 0 +set fail 0 +set gpio "??" + +# 兼容 get 与 value 命令 +if {![catch {get -radix bin z2_demo_ice_top.led_done} val]} { + set done $val + set pass [get -radix bin z2_demo_ice_top.led_pass] + set fail [get -radix bin z2_demo_ice_top.led_fail] + set gpio [get -radix hex z2_demo_ice_top.led_gpio] +} elseif {![catch {value z2_demo_ice_top.led_done} val]} { + set done $val + catch {set pass [value z2_demo_ice_top.led_pass]} + catch {set fail [value z2_demo_ice_top.led_fail]} + catch {set gpio [value z2_demo_ice_top.led_gpio]} +} + +puts " led_done : $done (测试序列是否完成,预期: 1)" +puts " led_pass : $pass (全硬件检查是否通过,预期: 1)" +puts " led_fail : $fail (是否有硬件检查失败,预期: 0)" +puts " led_gpio : 0x$gpio (跑马灯寄存器旋转值,预期: 0x02)" +puts "-------------------------------------------------------" + +if {$pass == 1 && $fail == 0} { + puts " >>> [SUCCESS] ICE DEMO 全部硬件自检测试通过! <<<" +} else { + puts " >>> [FAIL] ICE DEMO 硬件检查未通过,请排查状态机停滞位置 <<<" + catch {puts " FSM State : [get -radix dec z2_demo_ice_top.state]"} + catch {puts " Last Latched: 0x[get -radix hex z2_demo_ice_top.rd_latched]"} +} +puts "=======================================================" +puts "" diff --git a/ice/tb/tb_z2_demo_ice.v b/ice/tb/tb_z2_demo_ice.v new file mode 100644 index 0000000..0f57688 --- /dev/null +++ b/ice/tb/tb_z2_demo_ice.v @@ -0,0 +1,72 @@ +// ----------------------------------------------------------------------------- +// tb_z2_demo_ice.v -- Local-only bench for the ICE top. +// In real ICE mode there is no testbench at all: clk/rst come from the target +// or emulator clock setup and the result is the PASS/FAIL LEDs. This bench +// only supplies clock/reset locally and watches the LEDs, so the stimulus +// FSM itself can be verified before an ICE compile. +// ----------------------------------------------------------------------------- +`timescale 1ns/1ps + +module tb_z2_demo_ice; + reg clk; + reg rst_n; + wire [7:0] led_gpio; + wire led_irq; + wire led_done; + wire led_pass; + wire led_fail; + integer cycles; + integer errors; + + z2_demo_ice_top 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) + ); + + initial clk = 1'b0; + always #5 clk = ~clk; + + initial begin + $dumpfile("ice/sim_local/z2_demo_ice.vcd"); + $dumpvars(0, tb_z2_demo_ice); + errors = 0; + rst_n = 1'b0; + repeat (4) @(negedge clk); + rst_n = 1'b1; + + // wait for the hardware sequence to finish (guard: 1000 cycles) + cycles = 0; + while (!led_done && cycles < 1000) begin + @(negedge clk); + cycles = cycles + 1; + end + + if (!led_done) begin + $display("CHECK FAIL : ICE sequence did not finish in 1000 cycles"); + errors = errors + 1; + end else begin + $display("CHECK OK : ICE sequence finished in %0d cycles", cycles); + end + if (led_pass && !led_fail) + $display("CHECK OK : led_pass=1 led_fail=0"); + else begin + $display("CHECK FAIL : led_pass=%b led_fail=%b", led_pass, led_fail); + errors = errors + 1; + end + if (led_gpio === 8'h02) + $display("CHECK OK : led_gpio pattern = 0x02 (rotated once)"); + else begin + $display("CHECK FAIL : led_gpio = 0x%02h, expected 0x02", led_gpio); + errors = errors + 1; + end + + if (errors == 0) $display("ICE LOCAL TEST PASSED"); + else $display("ICE LOCAL TEST FAILED (%0d)", errors); + $finish; + end +endmodule diff --git a/rtl.f b/rtl.f new file mode 100644 index 0000000..7e3058c --- /dev/null +++ b/rtl.f @@ -0,0 +1 @@ +rtl/z2_demo_top.v diff --git a/rtl/z2_demo_top.v b/rtl/z2_demo_top.v new file mode 100644 index 0000000..21f05fc --- /dev/null +++ b/rtl/z2_demo_top.v @@ -0,0 +1,140 @@ +// ----------------------------------------------------------------------------- +// z2_demo_top.v -- Palladium Z2 emulation demo DUT +// +// A small, fully synthesizable, register-mapped timer peripheral used to +// demonstrate the Palladium Z2 flow end to end: +// IXCOM compile (SA mode) -> download with xeDebug -> run -> check results +// The same RTL also runs in a plain event simulator (xrun / iverilog) with +// the testbench in ../tb, so the logic can be verified before using hardware. +// +// Bus: APB-like (single-cycle ready). Only the low 8 address bits are 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 0x5A32_0001 (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 z2_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) + 8'h00: begin + ctrl_enable <= pwdata[0]; + ctrl_irq_en <= pwdata[1]; + ctrl_pattern_en <= pwdata[2]; + end + 8'h04: reg_load <= pwdata; + 8'h0C: reg_cmp <= pwdata; + 8'h10: begin // STATUS: write-1-to-clear + 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 + + // pattern rotation on timeout (software write same cycle wins + // for reg_gpio because this block is separate; see count block) + if (timeout_now & ctrl_pattern_en & ~(bus_write & (paddr == 8'h14))) + reg_gpio <= {reg_gpio[6:0], reg_gpio[7]}; + end + end + + // ------------------------------------------------------------- count path + always @(posedge clk or negedge rst_n) begin + if (!rst_n) begin + reg_count <= 32'd9; + end else if (bus_write & (paddr == 8'h04)) begin + reg_count <= pwdata; // writing LOAD also presets COUNT + end else if (ctrl_enable) begin + if (reg_count == 32'd0) + reg_count <= reg_load; // reload + else + reg_count <= reg_count - 32'd1; + end + end + + // -------------------------------------------------------------- read path + always @(*) begin + case (paddr) + 8'h00: prdata = {29'd0, 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'd0, status_cmp, status_timeout}; + 8'h14: prdata = {24'd0, reg_gpio}; + 8'h18: prdata = 32'h5A32_0001; // ID + default: prdata = 32'd0; + endcase + end + + // keep bus_read referenced (used by assertions in TB via hierarchy) + wire _unused = &{1'b0, bus_read}; + +endmodule diff --git a/scripts/compile_sa.sh b/scripts/compile_sa.sh new file mode 100644 index 0000000..c6b2bd7 --- /dev/null +++ b/scripts/compile_sa.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# ============================================================================= +# compile_sa.sh -- IXCOM compile for Palladium Z2, SA (Simulation Acceleration) +# +# . ./scripts/env_z2.sh # XE_HOST / XE_BOARDS must be set first +# ./scripts/compile_sa.sh +# +# What IXCOM does here: +# -ua unified acceleration compile (design + testbench) +# +dut+z2_demo_top the DUT partition that is mapped into the emulator; +# everything else (the TB) stays on the host simulator +# The compile runs inside ./ixcom_db (AxisWork and the design database land +# there) -- run xeDebug from that directory afterwards. +# +# FIX (2026-10-19): the file lists rtl.f/tb.f contain paths relative to the +# PACKAGE ROOT, but vlan resolves them against the compile working directory +# (ixcom_db/), which produced: +# Error! [FILE_OPEN_ERR] Could not open file (rtl/z2_demo_top.v) +# This script therefore generates ABSOLUTE-path file lists for the compile. +# It also checks the ixcom exit status / log explicitly, because piping to +# tee would otherwise mask a failed compile behind a "finished" message. +# ============================================================================= +set -e +cd "$(dirname "$0")/.." +ROOT="$PWD" + +: "${XE_HOST:?set XE_HOST first: . ./scripts/env_z2.sh}" +: "${XE_BOARDS:?set XE_BOARDS first: . ./scripts/env_z2.sh}" + +mkdir -p ixcom_db + +# Build absolute-path file lists (relative entries are prefixed with $ROOT; +# entries that are already absolute, blank lines and comments pass through). +for f in rtl tb; do + out="ixcom_db/${f}_abs.f" + : > "$out" + while IFS= read -r line || [ -n "$line" ]; do + case "$line" in + /*) echo "$line" >> "$out" ;; + ""|\#*) [ -n "$line" ] && echo "$line" >> "$out" ;; + *) echo "$ROOT/$line" >> "$out" ;; + esac + done < "${f}.f" +done + +cd ixcom_db + +set +e +ixcom -ua +dut+z2_demo_top \ + -f ./rtl_abs.f -f ./tb_abs.f \ + > compile_sa.log 2>&1 +rc=$? +set -e +cat compile_sa.log + +if [ "$rc" -ne 0 ] || grep -q "FLOW_FAILED" compile_sa.log; then + echo "== IXCOM compile FAILED (rc=$rc) -- see ixcom_db/compile_sa.log ==" + exit 1 +fi +echo "== IXCOM compile finished OK, log: ixcom_db/compile_sa.log ==" diff --git a/scripts/env_z2.sh b/scripts/env_z2.sh new file mode 100644 index 0000000..fee3513 --- /dev/null +++ b/scripts/env_z2.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# ============================================================================= +# env_z2.sh -- Palladium Z2 SA-mode environment (source this file, don't run it) +# +# . ./scripts/env_z2.sh +# +# Fill in the three values marked <...> for your site before first use. +# (csh users: the same variables are set with `setenv XE_HOST ...` etc.) +# ============================================================================= + +# VXE release on the host. On the SCD this is the "red" link target, e.g. +# /et3mach/Cadence/red ; on a workstation it is your VXE install path. +export VXE_HOME="${VXE_HOME:-}" +export PATH="$VXE_HOME/bin:$PATH" + +# SA mode: which emulation host / boards to use (compile AND run). +# XE_HOST names the emulation host; xeDebug must run on the SA host. +export XE_HOST="${XE_HOST:-}" +export XE_BOARDS="${XE_BOARDS:-}" # e.g. 0-3, per your allocation + +# DBEngine host for xrun-based SA runs. Defaults to the local workstation +# (which must be on the InfiniBand network) when left unset. +# export DBE_HOST="${DBE_HOST:-}" + +# Optional: tag this job in a shared-emulator environment (no spaces allowed). +# export XE_JOBID="z2_demo_$USER" diff --git a/scripts/run_local.sh b/scripts/run_local.sh new file mode 100644 index 0000000..c7e6ddc --- /dev/null +++ b/scripts/run_local.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# ============================================================================= +# run_local.sh -- Verify the demo logic WITHOUT Palladium hardware. +# +# Works with Icarus Verilog (used to validate this package) or, on a Cadence +# host, with xrun in pure simulation mode (swap the two lines marked below). +# Expected result: 8 "CHECK OK" lines and "TEST PASSED". +# ============================================================================= +set -e +cd "$(dirname "$0")/.." + +mkdir -p sim_local + +# --- Option A: Icarus Verilog ------------------------------------------------- +iverilog -g2005 -DLOCAL_SIM -o sim_local/z2_demo.vvp -f rtl.f -f tb.f +vvp sim_local/z2_demo.vvp | tee sim_local/local_run.log +[ -f z2_demo.vcd ] && mv z2_demo.vcd sim_local/z2_demo.vcd + +# --- Option B: Cadence xrun (comment out Option A, uncomment this) ------------ +# xrun -64bit -define LOCAL_SIM -access +rwc -f rtl.f -f tb.f -logfile sim_local/xrun.log + +grep -q "TEST PASSED" sim_local/local_run.log && echo "== LOCAL RUN: PASS ==" \ + || { echo "== LOCAL RUN: FAIL =="; exit 1; } diff --git a/scripts/run_xedebug.tcl b/scripts/run_xedebug.tcl new file mode 100644 index 0000000..ba37129 --- /dev/null +++ b/scripts/run_xedebug.tcl @@ -0,0 +1,38 @@ +# ============================================================================= +# run_xedebug.tcl -- Run the demo on Palladium Z2 (SA mode) from xeDebug. +# +# Launch (ON THE SA HOST, from the ixcom_db directory made by compile_sa.sh): +# xeDebug -f run_xedebug.tcl +# or start xeDebug interactively and `source run_xedebug.tcl`. +# +# SA-mode notes: +# * xeDebug MUST run on the SA host (not on an arbitrary workstation). +# * There is no separate xmsim log in SA mode: simulator output is merged +# into xeDebug.log -- grep it for "CHECK" / "TEST PASSED" / *E,*F errors. +# * Command spellings (host / xc on -run) follow the Z2 guide and field +# practice; confirm with xeDebug `help` on your VXE release if needed. +# ============================================================================= + +# 1) Connect to the emulation host (same value as $XE_HOST). +# Use `host .` instead if xeDebug is already running on that host. +host + +# 2) Download the design into the emulator and start it (hot-swap download). +xc on -run + +# 3) The testbench (host side) now drives the APB bus, waits for the timer +# interrupt, and prints its checks. A successful run ends with: +# CHECK OK : ID register = 0x5a320001 +# ... (8 checks) ... +# TEST PASSED (all checks) +# Watch xeDebug.log, or in the GUI open the waveform on: +# tb_z2_demo.dut.reg_count / gpio_out / irq +# +# If the run appears stuck, do NOT kill it blindly: first check whether +# xc_top.simTime is still advancing and take two gstack samples of the +# xmsim main thread (a spinning main thread points to a zero-time loop +# in the TB, a blocked one points elsewhere). + +# 4) Optional: keep the host connection warm for the next xeDebug session +# (default reuse window is 180 s): +# xeset keepHostAliveTimeout 600 diff --git a/tb.f b/tb.f new file mode 100644 index 0000000..d5d64a9 --- /dev/null +++ b/tb.f @@ -0,0 +1 @@ +tb/tb_z2_demo.v diff --git a/tb/tb_z2_demo.v b/tb/tb_z2_demo.v new file mode 100644 index 0000000..e90864d --- /dev/null +++ b/tb/tb_z2_demo.v @@ -0,0 +1,184 @@ +// ----------------------------------------------------------------------------- +// tb_z2_demo.v -- Self-checking testbench for z2_demo_top +// +// Runs unchanged in three environments: +// 1. Local event simulation (iverilog / xrun) -- logic verification +// 2. Palladium Z2 SA mode: this TB stays on the host (Xcelium side), +// the DUT is mapped into the emulator by IXCOM (+dut+z2_demo_top) +// 3. Palladium Z2 ICE mode is NOT covered by this TB (no software TB there) +// +// The TB prints one "CHECK ..." line per check and finishes with +// "TEST PASSED" or "TEST FAILED" so scripts can grep the log. +// ----------------------------------------------------------------------------- +`timescale 1ns/1ps + +module tb_z2_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; + + integer errors; + integer i; + reg [31:0] rdata; + reg [31:0] count_a, count_b; + reg saw_irq; + + z2_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 + initial clk = 1'b0; + always #5 clk = ~clk; + + // ------------------------------------------------------------- APB tasks + task apb_write; + input [7:0] addr; + input [31:0] data; + begin + @(negedge clk); + paddr = addr; + pwdata = data; + pwrite = 1'b1; + psel = 1'b1; + penable = 1'b1; + @(negedge clk); + psel = 1'b0; + penable = 1'b0; + pwrite = 1'b0; + end + endtask + + task apb_read; + input [7:0] addr; + output [31:0] data; + begin + @(negedge clk); + paddr = addr; + pwrite = 1'b0; + psel = 1'b1; + penable = 1'b1; + #1 data = prdata; // combinational read data + @(negedge clk); + psel = 1'b0; + penable = 1'b0; + end + endtask + + task check; + input [31:0] got; + input [31:0] exp; + input [8*40-1:0] name; + begin + if (got === exp) begin + $display("CHECK OK : %0s = 0x%08h", name, got); + end else begin + $display("CHECK FAIL : %0s got 0x%08h, expected 0x%08h", name, got, exp); + errors = errors + 1; + end + end + endtask + + // ------------------------------------------------------------- stimulus + initial begin +`ifdef LOCAL_SIM + // Waveform dump is a local-simulation debug aid only; it is compiled + // out of the IXCOM build (run_local.sh defines LOCAL_SIM). + $dumpfile("z2_demo.vcd"); + $dumpvars(0, tb_z2_demo); +`endif + errors = 0; + rst_n = 1'b0; + paddr = 8'd0; + psel = 1'b0; + penable = 1'b0; + pwrite = 1'b0; + pwdata = 32'd0; + + repeat (4) @(negedge clk); + rst_n = 1'b1; + repeat (2) @(negedge clk); + $display("---- z2_demo: reset released ----"); + + // 1) ID register + apb_read(8'h18, rdata); + check(rdata, 32'h5A32_0001, "ID register"); + + // 2) Default LOAD after reset = 9 + apb_read(8'h04, rdata); + check(rdata, 32'd9, "LOAD default"); + + // 3) Program the timer: period 20 cycles, compare at 5 + apb_write(8'h04, 32'd19); // LOAD = 19 (also presets COUNT) + apb_write(8'h0C, 32'd5); // CMP = 5 + apb_read (8'h04, rdata); + check(rdata, 32'd19, "LOAD programmed"); + + // 4) Enable timer + irq + pattern rotation (CTRL = 0b111) + apb_write(8'h00, 32'd7); + + // 5) Wait for the timeout interrupt (COUNT: 19 -> 0) + saw_irq = 1'b0; + for (i = 0; i < 100 && !saw_irq; i = i + 1) begin + @(negedge clk); + if (irq) saw_irq = 1'b1; + end + check({31'd0, saw_irq}, 32'd1, "irq raised on timeout"); + + // 6) STATUS: both timeout and compare flags must be set by now + apb_read(8'h10, rdata); + check({30'd0, rdata[1:0]}, 32'd3, "STATUS timeout+cmp flags"); + + // 7) Pattern rotated once: GPIO 0x01 -> 0x02 + apb_read(8'h14, rdata); + check(rdata, 32'h0000_0002, "GPIO pattern rotated"); + + // 8) Stop the timer, W1C the flags, verify they stay cleared + apb_write(8'h00, 32'd0); // CTRL = 0 (disable) + apb_write(8'h10, 32'd3); // clear both flags + apb_read (8'h10, rdata); + check(rdata, 32'd0, "STATUS cleared by W1C"); + + // 9) With enable=0 the counter must be frozen + apb_read(8'h08, count_a); + repeat (5) @(negedge clk); + apb_read(8'h08, count_b); + check(count_b, count_a, "COUNT frozen when disabled"); + + // ------------------------------------------------------------ verdict + if (errors == 0) + $display("TEST PASSED (all checks)"); + else + $display("TEST FAILED (%0d check(s) failed)", errors); + $finish; + end + + // global watchdog so a hung run still terminates with a failure + initial begin + #100000; + $display("TEST FAILED (watchdog timeout)"); + $finish; + end + +endmodule