5.5 KiB
5.5 KiB
Iverilog 工具集成说明
本插件已集成 Icarus Verilog (iverilog) 工具,用于 Verilog 代码的编译和仿真,以及 VCD 波形文件的生成。
目录结构
tools/
└── iverilog/
├── bin/ # 可执行文件目录(已包含 iverilog 工具)
│ ├── iverilog.exe # Verilog 编译器 (Windows)
│ ├── vvp.exe # Verilog 仿真器 (Windows)
│ └── ... # 其他依赖文件
└── README.md # 本说明文件
工具说明
插件包中已包含 Windows x64 版本的 iverilog 工具,无需额外安装。
- 版本: Icarus Verilog 11.0 (或更高)
- 平台: Windows x64
- 许可证: GPL v2+
Windows 安装
- 访问 Icarus Verilog 官方网站:http://bleyer.org/icarus/
- 下载最新的 Windows 安装包(例如:iverilog-v11-20210204-x64_setup.exe)
- 运行安装程序,按照提示完成安装
- 安装完成后,将以下文件复制到插件的
tools/iverilog/bin/目录:iverilog.exevvp.exe- 以及相关的 DLL 文件(如果有)
或者,将 iverilog 安装目录添加到系统 PATH 环境变量中,插件会自动使用系统安装的版本。
macOS 安装
使用 Homebrew 安装:
brew install icarus-verilog
安装完成后,iverilog 会自动添加到系统 PATH 中,插件可以直接使用。
可选:如果想将 iverilog 打包到插件中,可以将以下文件复制到 tools/iverilog/bin/:
/usr/local/bin/iverilog/usr/local/bin/vvp
Linux 安装
Ubuntu/Debian
sudo apt-get update
sudo apt-get install iverilog
Fedora/CentOS
sudo yum install iverilog
Arch Linux
sudo pacman -S iverilog
安装完成后,iverilog 会自动添加到系统 PATH 中,插件可以直接使用。
使用方法
1. 准备 Verilog 项目
确保您的项目包含以下文件:
- 顶层模块文件:包含您的设计代码(例如:
counter.v) - Testbench 文件:包含测试代码,文件名通常包含
tb或test(例如:counter_tb.v)
2. Testbench 要求
为了生成 VCD 波形文件,您的 testbench 必须包含以下语句:
module counter_tb;
// ... 信号声明 ...
initial begin
// 生成 VCD 文件
$dumpfile("output.vcd"); // 指定 VCD 文件名
$dumpvars(0, counter_tb); // 记录所有信号
// ... 测试代码 ...
#1000 $finish; // 结束仿真
end
// ... 其他测试代码 ...
endmodule
3. 生成 VCD 文件
在 IC Coder 插件的聊天界面中,输入以下任一命令:
生成 VCD创建 VCD运行仿真执行仿真生成波形
插件会自动:
- 检查项目文件完整性
- 使用 iverilog 编译所有 Verilog 文件
- 使用 vvp 运行仿真
- 在项目根目录生成
output.vcd文件
4. 查看波形
生成的 VCD 文件可以使用以下工具查看:
-
GTKWave(推荐):开源波形查看器
- Windows: http://gtkwave.sourceforge.net/
- macOS:
brew install gtkwave - Linux:
sudo apt-get install gtkwave
-
其他工具:
- ModelSim
- Vivado
- 在线 VCD 查看器
示例项目
counter.v(顶层模块)
module counter (
input clk,
input rst_n,
output reg [3:0] count
);
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
count <= 4'b0000;
else
count <= count + 1;
end
endmodule
counter_tb.v(Testbench)
`timescale 1ns/1ps
module counter_tb;
reg clk;
reg rst_n;
wire [3:0] count;
// 实例化被测模块
counter uut (
.clk(clk),
.rst_n(rst_n),
.count(count)
);
// 生成时钟信号
initial begin
clk = 0;
forever #5 clk = ~clk; // 10ns 周期
end
// 测试序列
initial begin
// 生成 VCD 文件
$dumpfile("output.vcd");
$dumpvars(0, counter_tb);
// 初始化
rst_n = 0;
#20;
// 释放复位
rst_n = 1;
#200;
// 结束仿真
$finish;
end
// 监控输出
initial begin
$monitor("Time=%0t rst_n=%b count=%d", $time, rst_n, count);
end
endmodule
故障排除
问题:提示 "iverilog 不可用"
解决方案:
- 确认已安装 iverilog
- 检查 iverilog 是否在系统 PATH 中:
- Windows: 在命令提示符中运行
iverilog -V - macOS/Linux: 在终端中运行
iverilog -V
- Windows: 在命令提示符中运行
- 或者将 iverilog 可执行文件复制到
tools/iverilog/bin/目录
问题:提示 "项目文件不完整"
解决方案:
- 确保项目中至少有一个
.v或.sv文件 - 确保有 testbench 文件(文件名包含
tb或test) - 确保 testbench 中包含
$dumpfile和$dumpvars语句
问题:编译失败
解决方案:
- 检查 Verilog 代码语法错误
- 查看错误输出信息
- 确保所有模块都正确实例化
问题:VCD 文件未生成
解决方案:
- 确保 testbench 中包含
$dumpfile("output.vcd")语句 - 确保 testbench 中包含
$dumpvars语句 - 确保仿真运行了足够的时间(使用
#时间 $finish;)
版本信息
- 推荐 Icarus Verilog 版本:v11.0 或更高
- 支持的 Verilog 标准:Verilog-1995, Verilog-2001, Verilog-2005, SystemVerilog (部分)
相关链接
- Icarus Verilog 官网:http://iverilog.icarus.com/
- GTKWave 官网:http://gtkwave.sourceforge.net/
- Verilog 教程:https://www.asic-world.com/verilog/
许可证
Icarus Verilog 是开源软件,遵循 GPL 许可证。