测试平台 tb_riscv_soc.sv :在testbench中直接将要执行的指令load进入Memory中。
//`timescale 1ns / 1ps
// Company: // Engineer: // // Create Date: 2021/03/13 // Author Name: Sniper // Module Name: tb_riscv_soc // Project Name: // Target Devices: // Tool Versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: //
module tb_riscv_soc;
//parameter parameter MEM_SIZE = 8192; parameter FIRMWARE = "";
//DUT signals reg clk; reg reset; wire lock; reg uart_rx; wire uart_tx; reg [31:0] gpio_in; wire [31:0] gpio_out;
initial begin clk = 1; reset = 1; uart_rx = 1'b1; gpio_in = 32'hABCD5678;
#100; @(posedge clk); reset <= 0; end
//clock always #5 clk = ~clk;
localparam INSTR_CNT = 30'd24; wire [0:INSTR_CNT-1] [31:0] instr_rom_cell = { 32'h000062b3, // 0x00000000 32'h200002b7, // 0x00000004 32'h12345337, // 0x00000008 32'h67836313, // 0x0000000c 32'h0062a023, // 0x00000010 32'h00006e33, // 0x00000014 32'h008e6e13, // 0x00000018 32'h00006333, // 0x0000001c 32'h0fe36313, // 0x00000020 32'h01c31333, // 0x00000024 32'h0dc36313, // 0x00000028 32'h0062a023, // 0x0000002c 32'h0002a383, // 0x00000030 32'h000062b3, // 0x00000034 32'h00006333, // 0x00000038 32'h000063b3, // 0x0000003c 32'h00006e33, // 0x00000040 32'h000062b3, // 0x00000044 32'h0082e293, // 0x00000048 32'h12345337, // 0x0000004c 32'h67836313, // 0x00000050 32'h0062a023, // 0x00000054 32'h0002a383, // 0x00000058 32'hfa5ff06f // 0x0000005c };
//Instructions integer i; initial begin for(i=0;i<INSTR_CNT;i++) begin u_riscv_soc.u_memory.mem_r = instr_rom_cell; $display("mem[%0d] = %32x", i, u_riscv_soc.u_memory.mem_r); end end
//DUT riscv_soc #( .MEM_SIZE(MEM_SIZE), .FIRMWARE(FIRMWARE) ) u_riscv_soc ( .clk_i(clk), .reset_i(reset), .lock_o(lock), .uart_rx_i(uart_rx), .uart_tx_o(uart_tx), .gpio_in_i(gpio_in), .gpio_out_o(gpio_out) );
initial begin $dumpfile("tb_riscv_soc.vcd"); $dumpvars(0,tb_riscv_soc); end
initial #5000 $finish;
endmodule
|