@@ -28,19 +28,11 @@ module tb_memory_axi #(
28
28
`include " axi/assign.svh"
29
29
`include " axi/typedef.svh"
30
30
31
- `include " register_interface/typedef.svh"
32
- `include " register_interface/assign.svh"
33
-
34
31
`include " common_cells/assertions.svh"
35
32
36
33
localparam int NumBytes = AxiDataWidth/ 8 ;
37
34
localparam int BusAlign = $clog2 (NumBytes);
38
35
39
- REG_BUS # (
40
- .ADDR_WIDTH ( AxiAddrWidth ),
41
- .DATA_WIDTH ( AxiDataWidth )
42
- ) regb (clk_i);
43
-
44
36
AXI_BUS # (
45
37
.AXI_ADDR_WIDTH ( AxiAddrWidth ),
46
38
.AXI_DATA_WIDTH ( AxiDataWidth ),
@@ -88,43 +80,80 @@ module tb_memory_axi #(
88
80
.out (axi_wo_atomics_cut)
89
81
);
90
82
91
- // Convert AXI to a trivial register interface.
92
- axi_to_reg_intf # (
93
- .ADDR_WIDTH ( AxiAddrWidth ),
94
- .DATA_WIDTH ( AxiDataWidth ),
95
- .ID_WIDTH ( AxiIdWidth ),
96
- .USER_WIDTH ( AxiUserWidth ),
97
- .DECOUPLE_W ( 1 ),
98
- .FULL_BW ( 1 ),
99
- .AXI_MAX_WRITE_TXNS ( 32'd128 ),
100
- .AXI_MAX_READ_TXNS ( 32'd128 )
101
- ) i_axi_to_reg (
102
- .clk_i,
103
- .rst_ni,
104
- .testmode_i ( 1'b0 ),
105
- .in ( axi_wo_atomics_cut ),
106
- .reg_o ( regb )
83
+ logic mem_req;
84
+ logic mem_gnt;
85
+ logic [AxiAddrWidth- 1 : 0 ] mem_addr;
86
+ logic [AxiDataWidth- 1 : 0 ] mem_wdata;
87
+ logic [AxiDataWidth/ 8 - 1 : 0 ] mem_strb;
88
+ 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 ;
95
+
96
+ axi_to_mem_intf # (
97
+ .ADDR_WIDTH (AxiAddrWidth),
98
+ .DATA_WIDTH (AxiDataWidth),
99
+ .ID_WIDTH (AxiIdWidth),
100
+ .USER_WIDTH (AxiUserWidth),
101
+ .NUM_BANKS (1 )
102
+ ) i_axi_to_mem_intf (
103
+ .clk_i (clk_i),
104
+ .rst_ni (rst_ni),
105
+ .busy_o ( ),
106
+ .slv (axi_wo_atomics_cut),
107
+ .mem_req_o (mem_req),
108
+ .mem_gnt_i (mem_gnt),
109
+ .mem_addr_o (mem_addr),
110
+ .mem_wdata_o (mem_wdata),
111
+ .mem_strb_o (mem_strb),
112
+ .mem_atop_o ( ), // ATOPs are resolved before
113
+ .mem_we_o (mem_we),
114
+ .mem_rvalid_i (mem_req),
115
+ .mem_rdata_i (mem_rdata)
107
116
);
108
117
109
- `REG_BUS_TYPEDEF_ALL (regbus,
110
- logic [AxiAddrWidth- 1 : 0 ], logic [AxiDataWidth- 1 : 0 ], logic [NumBytes- 1 : 0 ])
111
-
112
- regbus_req_t regbus_req;
113
- regbus_rsp_t regbus_rsp;
118
+ import " DPI-C" function void tb_memory_read (
119
+ input longint addr,
120
+ input int len,
121
+ output byte data[]
122
+ );
123
+ import " DPI-C" function void tb_memory_write (
124
+ input longint addr,
125
+ input int len,
126
+ input byte data[],
127
+ input bit strb[]
128
+ );
114
129
115
- `REG_BUS_ASSIGN_TO_REQ (regbus_req, regb)
116
- `REG_BUS_ASSIGN_FROM_RSP (regb, regbus_rsp)
130
+ // Handle write requests on the mem bus.
131
+ always_ff @ (posedge clk_i) begin
132
+ if (rst_ni && mem_req) begin
133
+ automatic byte data[NumBytes];
134
+ automatic bit strb[NumBytes];
135
+ if (mem_we) begin
136
+ for (int i = 0 ; i < NumBytes; i++ ) begin
137
+ // verilog_lint: waive-start always-ff-non-blocking
138
+ data[i] = mem_wdata[i* 8 + : 8 ];
139
+ strb[i] = mem_strb[i];
140
+ // verilog_lint: waive-start always-ff-non-blocking
141
+ end
142
+ tb_memory_write ((mem_addr >> BusAlign) << BusAlign, NumBytes, data, strb);
143
+ end
144
+ end
145
+ end
117
146
118
- tb_memory_regbus # (
119
- . AddrWidth (AxiAddrWidth),
120
- . DataWidth (AxiDataWidth),
121
- . req_t (regbus_req_t),
122
- . rsp_t (regbus_rsp_t)
123
- ) i_tb_memory_regbus (
124
- .clk_i,
125
- .rst_ni,
126
- . req_i (regbus_req),
127
- . rsp_o (regbus_rsp)
128
- );
147
+ // Handle read requests combinatorial on the mem bus.
148
+ always_comb begin
149
+ mem_rdata = '0 ;
150
+ if (mem_req) begin
151
+ automatic byte data[NumBytes];
152
+ tb_memory_read ((mem_addr >> BusAlign) << BusAlign, NumBytes, data);
153
+ for ( int i = 0 ; i < NumBytes; i ++ ) begin
154
+ mem_rdata[i * 8 + : 8 ] = data[i];
155
+ end
156
+ end
157
+ end
129
158
130
159
endmodule
0 commit comments