- 新增 cpu21_board_top.v:上板顶层。处理器顶层暴露了 775 位调试端口,直接作为
实现顶层会因 IO 超限无法布局布线([Place 30-415] IO Placement failed due to
overutilization),本模块只引出板上真正需要的 23 个引脚
(clk100 / rst_n / go / irq_sw[2:0] / led[15:0] / led_we)。
* 100 MHz 经 CLK_DIV=16 分频到 6.25 MHz:ALU 的除法/取余是组合电路,
100 MHz 下 WNS=-84.126 ns(325 级逻辑)无法收敛,分频后 WNS=+6.083 ns。
* 分频时钟由 Vivado 自动插入 BUFG;RTL 中不例化原语,以便跨工具仿真。
* 复位同步器、片内 ROM(1024x32,组合读,`include cpu21_board_rom.vh`)、
片内 RAM(1024x32,字节写使能,只响应地址 <4KB,避免与 MMIO 地址别名)。
- 新增 cpu21_board_top.xdc:Nexys4DDR 引脚约束 + create_generated_clock。
- 新增 tools/hex2vh.py:把 hex 机器码转成 rom[i] = 32'h...; 初始化包含文件。
- 新增 testbench/programs/board_demo.asm 与 testbench/tb_board_top.v:
16 步跑马灯演示程序(通过 MMIO 写 LED)。仿真验证:默认 ROM 下首次写入
LED=0001,快速 ROM 下完整序列 0001..8000 循环。
- 新增 cpu21_board_rom.vh / cpu21_board_rom_fast.vh,由 BOARD_ROM_FAST 宏选择。
- tools/rv_asm.py:读源文件时兼容带 BOM 的 UTF-8。
- 测试资源:补齐 lui_test.expected;修正 mmio_test.expected(print 由
lui+sw 实现,本身就是一次 LED 写,共 5 次)。三个回归全部通过:
isa_test 24/24、lui_test 4/4、mmio_test 5/5。
- .gitignore:忽略 _tmp/、_vivado/、*.vcd、*.pb、*.hex.lst。
- 说明文档:模块划分表补上上板相关模块,新增“上板(Nexys4DDR + Vivado)”
章节(引脚分配、分频原因、ROM/RAM 组织、ROM 生成流程、Vivado 工程设置、
实现结果)。
实现结果:synth_design / route_design / write_bitstream 全部完成,
LUT 5400 (8.52%)、LUTRAM 512、FF 2507、DSP 12、IOB 23 (10.95%),
bit 文件为 pipelined-cpu/pipelined-cpu.runs/impl_1/cpu21_board_top.bit
(Vivado 工程目录被 .gitignore 排除,不入库)。
57 lines
1.8 KiB
Verilog
57 lines
1.8 KiB
Verilog
`timescale 1ns / 1ps
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// cpu21_board_top 的仿真测试(不上板,纯 RTL 仿真)
|
|
//
|
|
// 检查内容:
|
|
// 1) 复位释放后 CPU 能从片内 ROM 取指(ROM 由 cpu21_board_rom.vh 初始化);
|
|
// 2) 程序通过 MMIO 写 LED,板载 LED 端口上能看到 16 位跑马灯序列。
|
|
//
|
|
// 默认的 board_demo 程序带约 20 ms 软件延时,仿真只需确认第一次写入;
|
|
// 若要完整验证跑马灯序列,可生成一份短延时的 ROM 并用 -d BOARD_ROM_FAST 编译:
|
|
// xvlog -d BOARD_ROM_FAST <RTL...> cpu21_board_top.v testbench/tb_board_top.v
|
|
// -----------------------------------------------------------------------------
|
|
module tb_board_top;
|
|
reg clk100 = 1'b0;
|
|
reg rst_n = 1'b0;
|
|
reg go = 1'b0;
|
|
reg [2:0] irq_sw = 3'b000;
|
|
|
|
wire [15:0] led;
|
|
wire led_we;
|
|
|
|
always #5 clk100 = ~clk100; // 100 MHz
|
|
|
|
cpu21_board_top #(
|
|
.LED_ADDR(32'h0000_1000)
|
|
) dut (
|
|
.clk100(clk100),
|
|
.rst_n (rst_n),
|
|
.go (go),
|
|
.irq_sw(irq_sw),
|
|
.led (led),
|
|
.led_we(led_we)
|
|
);
|
|
|
|
integer changes = 0;
|
|
reg [15:0] led_prev = 16'hxxxx;
|
|
|
|
always @(posedge clk100) begin
|
|
if (led !== led_prev) begin
|
|
changes = changes + 1;
|
|
led_prev = led;
|
|
$display("t=%t LED=%04h led_we=%b", $time, led, led_we);
|
|
end
|
|
end
|
|
|
|
initial begin
|
|
$timeformat(-9, 3, " ns", 12); // %t 按 ns 显示(默认按精度 ps 显示)
|
|
$display("NOTE: 复位后观察 LED(默认程序首次写入应为 0001)");
|
|
repeat (10) @(posedge clk100);
|
|
rst_n = 1'b1;
|
|
repeat (30000) @(posedge clk100); // 300 us(CPU 时钟经 16 分频,需要更长窗口)
|
|
$display("FINAL: LED 变化次数=%0d 当前 LED=%04h", changes, led);
|
|
$finish;
|
|
end
|
|
endmodule
|