Skip to content

Commit 776bef7

Browse files
authored
tb_memory: Respond with one cycle delay (#237)
1 parent 2b417fd commit 776bef7

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

target/common/test/tb_memory_axi.sv

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module tb_memory_axi #(
2929
`include "axi/typedef.svh"
3030

3131
`include "common_cells/assertions.svh"
32+
`include "common_cells/registers.svh"
3233

3334
localparam int NumBytes = AxiDataWidth/8;
3435
localparam int BusAlign = $clog2(NumBytes);
@@ -80,18 +81,12 @@ module tb_memory_axi #(
8081
.out (axi_wo_atomics_cut)
8182
);
8283

83-
logic mem_req;
84-
logic mem_gnt;
84+
logic mem_req, mem_req_q;
8585
logic [AxiAddrWidth-1:0] mem_addr;
8686
logic [AxiDataWidth-1:0] mem_wdata;
8787
logic [AxiDataWidth/8-1:0] mem_strb;
8888
logic mem_we;
89-
logic mem_rvalid;
90-
logic [AxiDataWidth-1:0] mem_rdata;
91-
92-
// Testbench memory is always ready
93-
assign mem_gnt = 1'b1;
94-
assign mem_rvalid = 1'b1;
89+
logic [AxiDataWidth-1:0] mem_rdata_q;
9590

9691
axi_to_mem_intf #(
9792
.ADDR_WIDTH (AxiAddrWidth),
@@ -105,14 +100,14 @@ module tb_memory_axi #(
105100
.busy_o ( ),
106101
.slv (axi_wo_atomics_cut),
107102
.mem_req_o (mem_req),
108-
.mem_gnt_i (mem_gnt),
103+
.mem_gnt_i (1'b1), // Always ready
109104
.mem_addr_o (mem_addr),
110105
.mem_wdata_o (mem_wdata),
111106
.mem_strb_o (mem_strb),
112107
.mem_atop_o ( ), // ATOPs are resolved before
113108
.mem_we_o (mem_we),
114-
.mem_rvalid_i(mem_req),
115-
.mem_rdata_i (mem_rdata)
109+
.mem_rvalid_i(mem_req_q),
110+
.mem_rdata_i (mem_rdata_q)
116111
);
117112

118113
import "DPI-C" function void tb_memory_read(
@@ -127,6 +122,9 @@ module tb_memory_axi #(
127122
input bit strb[]
128123
);
129124

125+
// Respond in the next cycle to the request.
126+
`FF(mem_req_q, mem_req, '0)
127+
130128
// Handle write requests on the mem bus.
131129
always_ff @(posedge clk_i) begin
132130
if (rst_ni && mem_req) begin
@@ -144,14 +142,14 @@ module tb_memory_axi #(
144142
end
145143
end
146144

147-
// Handle read requests combinatorial on the mem bus.
148-
always_comb begin
149-
mem_rdata = '0;
150-
if (mem_req) begin
145+
// Handle read requests on the mem bus.
146+
always_ff @(posedge clk_i) begin
147+
mem_rdata_q <= '0;
148+
if (rst_ni && mem_req) begin
151149
automatic byte data[NumBytes];
152150
tb_memory_read((mem_addr >> BusAlign) << BusAlign, NumBytes, data);
153151
for (int i = 0; i < NumBytes; i++) begin
154-
mem_rdata[i*8+:8] = data[i];
152+
mem_rdata_q[i*8+:8] <= data[i];
155153
end
156154
end
157155
end

0 commit comments

Comments
 (0)