2021-12-16 20:07:50 +08:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Copyright 2019 Western Digital Corporation or its affiliates.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
module axi_slv #(
|
|
|
|
TAGW = 1
|
|
|
|
) (
|
|
|
|
input aclk,
|
|
|
|
input rst_l,
|
|
|
|
input arvalid,
|
|
|
|
output reg arready,
|
|
|
|
input [ 31:0] araddr,
|
|
|
|
input [TAGW-1:0] arid,
|
|
|
|
input [ 7:0] arlen,
|
|
|
|
input [ 1:0] arburst,
|
|
|
|
input [ 2:0] arsize,
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
output reg rvalid,
|
|
|
|
input rready,
|
|
|
|
output reg [ 63:0] rdata,
|
|
|
|
output reg [ 1:0] rresp,
|
|
|
|
output reg [TAGW-1:0] rid,
|
|
|
|
output rlast,
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
input awvalid,
|
|
|
|
output awready,
|
|
|
|
input [ 31:0] awaddr,
|
|
|
|
input [TAGW-1:0] awid,
|
|
|
|
input [ 7:0] awlen,
|
|
|
|
input [ 1:0] awburst,
|
|
|
|
input [ 2:0] awsize,
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
input [63:0] wdata,
|
|
|
|
input [ 7:0] wstrb,
|
|
|
|
input wvalid,
|
|
|
|
output wready,
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
output reg bvalid,
|
|
|
|
input bready,
|
|
|
|
output reg [ 1:0] bresp,
|
|
|
|
output reg [TAGW-1:0] bid
|
|
|
|
);
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
parameter MEM_DEPTH = 15; // memory size = 0x8000 = 32k
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
bit [7:0] mem[bit [MEM_DEPTH-1:0]];
|
|
|
|
bit [63:0] memdata;
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
wire [MEM_DEPTH-1:0] saraddr = araddr[MEM_DEPTH-1:0];
|
|
|
|
wire [MEM_DEPTH-1:0] sawaddr = awaddr[MEM_DEPTH-1:0];
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
always @(posedge aclk or negedge rst_l) begin
|
|
|
|
if (!rst_l) begin
|
|
|
|
rvalid <= 0;
|
|
|
|
bvalid <= 0;
|
|
|
|
end else begin
|
|
|
|
bid <= awid;
|
|
|
|
rid <= arid;
|
|
|
|
rvalid <= arvalid;
|
|
|
|
bvalid <= awvalid;
|
|
|
|
rdata <= memdata;
|
2021-12-16 20:07:50 +08:00
|
|
|
end
|
2022-02-17 19:35:01 +08:00
|
|
|
end
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
always @(negedge aclk) begin
|
|
|
|
if (arvalid)
|
|
|
|
memdata <= {
|
|
|
|
mem[saraddr+7],
|
|
|
|
mem[saraddr+6],
|
|
|
|
mem[saraddr+5],
|
|
|
|
mem[saraddr+4],
|
|
|
|
mem[saraddr+3],
|
|
|
|
mem[saraddr+2],
|
|
|
|
mem[saraddr+1],
|
|
|
|
mem[saraddr]
|
|
|
|
};
|
|
|
|
if (awvalid) begin
|
|
|
|
if (wstrb[7]) mem[sawaddr+7] = wdata[63:56];
|
|
|
|
if (wstrb[6]) mem[sawaddr+6] = wdata[55:48];
|
|
|
|
if (wstrb[5]) mem[sawaddr+5] = wdata[47:40];
|
|
|
|
if (wstrb[4]) mem[sawaddr+4] = wdata[39:32];
|
|
|
|
if (wstrb[3]) mem[sawaddr+3] = wdata[31:24];
|
|
|
|
if (wstrb[2]) mem[sawaddr+2] = wdata[23:16];
|
|
|
|
if (wstrb[1]) mem[sawaddr+1] = wdata[15:08];
|
|
|
|
if (wstrb[0]) mem[sawaddr+0] = wdata[07:00];
|
2021-12-16 20:07:50 +08:00
|
|
|
end
|
2022-02-17 19:35:01 +08:00
|
|
|
end
|
|
|
|
|
2021-12-16 20:07:50 +08:00
|
|
|
|
2022-02-17 19:35:01 +08:00
|
|
|
assign arready = 1'b1;
|
|
|
|
assign awready = 1'b1;
|
|
|
|
assign wready = 1'b1;
|
|
|
|
assign rresp = 2'b0;
|
|
|
|
assign bresp = 2'b0;
|
|
|
|
assign rlast = 1'b1;
|
2021-12-16 20:07:50 +08:00
|
|
|
|
|
|
|
endmodule
|