Files
palladium_z2_demo/testbench/testbench.v02
T
Wang Xuejin f5bf2e30fc maste
2025-09-22 15:30:52 +08:00

50 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
`timescale 1ns/1ps
module testbench;
// 1. 声明变量(纯 Verilog
reg clk;
reg reset_n;
wire [31:0] pc_out;
integer fd; // 文件描述符
reg [8*80:1] dump_path; // 用 reg 数组模拟字符串
// 实例化被测设计
top uut (
.clk(clk),
.reset_n(reset_n),
.pc_out(pc_out)
);
// 2. 生成时钟
initial begin
clk = 0;
forever #5 clk = ~clk; // 100MHz 时钟
end
// 3. 波形生成和错误处理
initial begin
// 初始化路径(用字符串拼接模拟)
dump_path = "/tmp/wave.vcd"; // Verilog 中直接赋值 reg 数组
// 尝试创建文件
fd = $fopen(dump_path, "w");
if (fd == 0) begin
$display("ERROR: Cannot open ", dump_path, " for writing!"); // 字符串拼接
$finish;
end
$fclose(fd);
// 初始化波形记录
$dumpfile(dump_path);
$dumpvars(0, testbench);
$display("Waveform will be saved to ", dump_path); // 字符串拼接
// 复位和仿真控制
reset_n = 0;
#100 reset_n = 1;
#1000 $finish;
end
endmodule