2021-07-02 00:49:13 -06:00
|
|
|
`timescale 1ns/1ps
|
2020-09-27 16:04:16 -06:00
|
|
|
|
|
|
|
module core_tb();
|
|
|
|
|
2020-10-11 23:03:14 -06:00
|
|
|
initial $timeformat(-9, 2, " ns", 20);
|
2021-07-02 02:02:11 -06:00
|
|
|
initial begin: dump
|
|
|
|
integer i;
|
2021-07-02 00:49:13 -06:00
|
|
|
$dumpfile("core_tb.vcd");
|
2021-07-02 02:02:11 -06:00
|
|
|
$dumpvars(0, core_tb);
|
|
|
|
for (i=0; i<32; i=i+1) begin
|
|
|
|
$dumpvars(0, dut.regfile[i]);
|
|
|
|
end
|
2021-07-02 00:49:13 -06:00
|
|
|
end
|
2020-10-11 23:03:14 -06:00
|
|
|
|
2020-11-10 00:19:42 -07:00
|
|
|
wire dummy_out;
|
|
|
|
|
|
|
|
localparam MEM_INST_LENGTH = 256; // words
|
|
|
|
localparam MEM_DATA_LENGTH = 256; // words
|
2020-09-27 16:04:16 -06:00
|
|
|
|
2020-11-14 23:21:33 -07:00
|
|
|
localparam MEM_DATA_BASE = 32'h00100000;
|
|
|
|
|
2020-11-10 00:19:42 -07:00
|
|
|
localparam INST_NOP = 32'h00000013; // nop
|
2020-11-14 23:04:24 -07:00
|
|
|
localparam DATA_DEFAULT = 32'h00000000;
|
|
|
|
localparam DATA_INVALID = 32'hdeadbeef;
|
2020-10-11 23:03:14 -06:00
|
|
|
|
2020-09-27 16:04:16 -06:00
|
|
|
reg clk, reset;
|
2020-11-10 00:19:42 -07:00
|
|
|
|
|
|
|
// Instruction memory
|
2020-10-11 23:03:14 -06:00
|
|
|
reg [31:0] mem_inst [0:MEM_INST_LENGTH-1];
|
2020-09-27 16:04:16 -06:00
|
|
|
wire [31:0] mem_inst_addr;
|
|
|
|
wire [31:0] mem_inst_idx = mem_inst_addr >> 2;
|
2020-10-11 23:03:14 -06:00
|
|
|
wire [31:0] mem_inst_data = mem_inst_idx < MEM_INST_LENGTH ? mem_inst[mem_inst_idx] : INST_NOP;
|
2020-09-27 16:04:16 -06:00
|
|
|
|
2020-10-11 23:03:14 -06:00
|
|
|
initial begin: mem_inst_init
|
|
|
|
integer i;
|
2020-09-27 16:04:16 -06:00
|
|
|
for (i=0; i<MEM_INST_LENGTH; i=i+1) begin
|
|
|
|
mem_inst[i] = INST_NOP;
|
|
|
|
end
|
2021-07-02 01:42:11 -06:00
|
|
|
$readmemh("text.hex", mem_inst);
|
2020-09-27 18:38:35 -06:00
|
|
|
end
|
|
|
|
|
2020-11-10 00:19:42 -07:00
|
|
|
// Data memory
|
2020-10-11 23:03:14 -06:00
|
|
|
reg [31:0] mem_data [0:MEM_DATA_LENGTH-1];
|
2020-11-14 23:04:24 -07:00
|
|
|
wire [31:0] mem_data_addr;
|
|
|
|
reg [31:0] mem_data_rdata;
|
2020-10-11 23:03:14 -06:00
|
|
|
wire [31:0] mem_data_wdata;
|
|
|
|
wire [3:0] mem_data_wmask;
|
|
|
|
wire mem_data_we;
|
2020-09-27 16:04:16 -06:00
|
|
|
|
2020-11-10 00:19:42 -07:00
|
|
|
initial begin: mem_data_init
|
|
|
|
integer i;
|
|
|
|
for (i=0; i<MEM_DATA_LENGTH; i=i+1) begin
|
|
|
|
mem_data[i] = DATA_DEFAULT;
|
|
|
|
end
|
2021-07-02 01:42:11 -06:00
|
|
|
$readmemh("data.hex", mem_data);
|
2020-11-10 00:19:42 -07:00
|
|
|
end
|
|
|
|
|
2020-09-27 16:04:16 -06:00
|
|
|
initial begin
|
|
|
|
#0
|
|
|
|
clk = 0;
|
|
|
|
reset = 1;
|
|
|
|
|
2020-11-09 23:38:22 -07:00
|
|
|
#10
|
2020-09-27 16:04:16 -06:00
|
|
|
reset = 0;
|
|
|
|
|
2020-11-14 23:36:23 -07:00
|
|
|
#5000
|
2020-09-27 16:04:16 -06:00
|
|
|
reset = 1;
|
2021-07-02 00:49:13 -06:00
|
|
|
$finish;
|
2020-09-27 16:04:16 -06:00
|
|
|
end
|
|
|
|
|
2020-11-09 23:38:22 -07:00
|
|
|
always #2 clk = !clk;
|
2020-09-27 16:04:16 -06:00
|
|
|
|
|
|
|
core dut(
|
|
|
|
.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
|
|
|
|
.mem_inst_addr(mem_inst_addr),
|
2020-11-06 23:18:37 -07:00
|
|
|
.mem_inst_data(mem_inst_data),
|
2020-10-11 23:03:14 -06:00
|
|
|
|
2020-11-14 23:04:24 -07:00
|
|
|
.mem_data_addr(mem_data_addr),
|
|
|
|
.mem_data_rdata(mem_data_rdata),
|
|
|
|
.mem_data_wdata(mem_data_wdata),
|
|
|
|
.mem_data_wmask(mem_data_wmask),
|
|
|
|
.mem_data_we(mem_data_we),
|
|
|
|
|
2020-10-11 23:03:14 -06:00
|
|
|
// .mem_data_addr(mem_data_addr),
|
|
|
|
// .mem_data_wdata(mem_data_wdata),
|
|
|
|
// .mem_data_rdata(mem_data_rdata),
|
|
|
|
// .mem_data_en(mem_data_en),
|
|
|
|
// .mem_data_we(mem_data_we),
|
|
|
|
// .mem_data_valid(mem_data_valid),
|
|
|
|
// .mem_data_done(mem_data_done)
|
2020-11-06 23:18:37 -07:00
|
|
|
|
|
|
|
.dummy_out(dummy_out)
|
2020-10-11 23:03:14 -06:00
|
|
|
);
|
|
|
|
|
2020-11-14 23:04:24 -07:00
|
|
|
// wire axi_mem_data_awvalid;
|
|
|
|
// wire [11:0] axi_mem_data_awaddr;
|
|
|
|
// wire [2:0] axi_mem_data_awprot;
|
|
|
|
// wire axi_mem_data_awready;
|
|
|
|
// wire axi_mem_data_wvalid;
|
|
|
|
// wire [31:0] axi_mem_data_wdata;
|
|
|
|
// wire [3:0] axi_mem_data_wstrb;
|
|
|
|
// wire axi_mem_data_wready;
|
|
|
|
// wire axi_mem_data_bvalid;
|
|
|
|
// wire axi_mem_data_bready;
|
|
|
|
// wire [1:0] axi_mem_data_bresp;
|
|
|
|
// wire axi_mem_data_arvalid;
|
|
|
|
// wire [11:0] axi_mem_data_araddr;
|
|
|
|
// wire [2:0] axi_mem_data_arprot;
|
|
|
|
// wire axi_mem_data_arready;
|
|
|
|
// wire axi_mem_data_rvalid;
|
|
|
|
// wire [31:0] axi_mem_data_rdata;
|
|
|
|
// wire [1:0] axi_mem_data_resp;
|
|
|
|
// wire axi_mem_data_rready;
|
|
|
|
|
|
|
|
// axi_lite_memory axi_mem_data(
|
|
|
|
// .ACLK(clk),
|
|
|
|
// .ARESETn(!reset),
|
|
|
|
// .AWVALID(axi_mem_data_awvalid),
|
|
|
|
// .AWADDR(axi_mem_data_awaddr),
|
|
|
|
// .AWPROT(axi_mem_data_awprot),
|
|
|
|
// .AWREADY(axi_mem_data_awready),
|
|
|
|
// .WVALID(axi_mem_data_wvalid),
|
|
|
|
// .WDATA(axi_mem_data_wdata),
|
|
|
|
// .WSTRB(axi_mem_data_wstrb),
|
|
|
|
// .WREADY(axi_mem_data_wready),
|
|
|
|
// .BVALID(axi_mem_data_bvalid),
|
|
|
|
// .BREADY(axi_mem_data_bready),
|
|
|
|
// .BRESP(axi_mem_data_bresp),
|
|
|
|
// .ARVALID(axi_mem_data_arvalid),
|
|
|
|
// .ARADDR(axi_mem_data_araddr),
|
|
|
|
// .ARPROT(axi_mem_data_arprot),
|
|
|
|
// .ARREADY(axi_mem_data_arready),
|
|
|
|
// .RVALID(axi_mem_data_rvalid),
|
|
|
|
// .RDATA(axi_mem_data_rdata),
|
|
|
|
// .RRESP(axi_mem_data_resp),
|
|
|
|
// .RREADY(axi_mem_data_rready),
|
|
|
|
|
|
|
|
// .WB_WADDR(mem_data_waddr),
|
|
|
|
// .WB_WPROT(),
|
|
|
|
// .WB_WDATA(mem_data_wdata),
|
|
|
|
// .WB_WSTRB(mem_data_wmask),
|
|
|
|
// .WB_WVALID(mem_data_we),
|
|
|
|
// .WB_WREADY(1'b1),
|
|
|
|
|
|
|
|
// .WB_RADDR(mem_data_raddr),
|
|
|
|
// .WB_RDATA(mem_data_rdata),
|
|
|
|
// .WB_RVALID(1'b1),
|
|
|
|
// .WB_RREADY()
|
|
|
|
// );
|
|
|
|
|
2020-11-14 23:21:33 -07:00
|
|
|
wire [31:0] mem_data_idx = (mem_data_addr - MEM_DATA_BASE) >> 2;
|
|
|
|
always @(*) begin
|
2020-11-14 23:04:24 -07:00
|
|
|
if (mem_data_idx < MEM_DATA_LENGTH) begin
|
|
|
|
mem_data_rdata = mem_data[mem_data_idx];
|
2020-11-14 23:21:33 -07:00
|
|
|
end else begin
|
|
|
|
mem_data_rdata = DATA_INVALID;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (mem_data_idx < MEM_DATA_LENGTH) begin
|
2020-11-14 23:04:24 -07:00
|
|
|
if (mem_data_we) begin
|
|
|
|
if (mem_data_wmask[0]) begin
|
|
|
|
mem_data[mem_data_idx][7:0] <= mem_data_wdata[7:0];
|
|
|
|
end
|
|
|
|
if (mem_data_wmask[1]) begin
|
|
|
|
mem_data[mem_data_idx][15:8] <= mem_data_wdata[15:8];
|
|
|
|
end
|
|
|
|
if (mem_data_wmask[2]) begin
|
|
|
|
mem_data[mem_data_idx][23:16] <= mem_data_wdata[23:16];
|
|
|
|
end
|
|
|
|
if (mem_data_wmask[3]) begin
|
|
|
|
mem_data[mem_data_idx][31:24] <= mem_data_wdata[31:24];
|
|
|
|
end
|
2020-10-11 23:03:14 -06:00
|
|
|
end
|
|
|
|
end else begin
|
2020-11-14 23:04:24 -07:00
|
|
|
// ignore illegal writes
|
2020-10-11 23:03:14 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-27 16:04:16 -06:00
|
|
|
endmodule
|