2022-03-10 11:56:21 +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.
|
|
|
|
//
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
output reg rvalid,
|
|
|
|
input rready,
|
|
|
|
output reg [ 63:0] rdata,
|
|
|
|
output reg [ 1:0] rresp,
|
|
|
|
output reg [TAGW-1:0] rid,
|
|
|
|
output rlast,
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
input [63:0] wdata,
|
|
|
|
input [ 7:0] wstrb,
|
|
|
|
input wvalid,
|
|
|
|
output wready,
|
|
|
|
|
|
|
|
output reg bvalid,
|
|
|
|
input bready,
|
|
|
|
output reg [ 1:0] bresp,
|
|
|
|
output reg [TAGW-1:0] bid
|
|
|
|
);
|
|
|
|
|
2022-03-22 14:08:34 +08:00
|
|
|
parameter MEM_DEPTH = 15; // memory size = 0x8000 = 32k WIDTH=15
|
|
|
|
parameter MEM_DEPTH_EACH = MEM_DEPTH - 3; // memory size = 0x8000 = 32k WIDTH=15
|
2022-03-10 11:56:21 +08:00
|
|
|
|
2022-03-22 14:08:34 +08:00
|
|
|
bit [7:0] mem0[(1<<MEM_DEPTH_EACH)-1:0];
|
|
|
|
bit [7:0] mem1[(1<<MEM_DEPTH_EACH)-1:0];
|
|
|
|
bit [7:0] mem2[(1<<MEM_DEPTH_EACH)-1:0];
|
|
|
|
bit [7:0] mem3[(1<<MEM_DEPTH_EACH)-1:0];
|
|
|
|
bit [7:0] mem4[(1<<MEM_DEPTH_EACH)-1:0];
|
|
|
|
bit [7:0] mem5[(1<<MEM_DEPTH_EACH)-1:0];
|
|
|
|
bit [7:0] mem6[(1<<MEM_DEPTH_EACH)-1:0];
|
|
|
|
bit [7:0] mem7[(1<<MEM_DEPTH_EACH)-1:0];
|
2022-03-10 11:56:21 +08:00
|
|
|
|
|
|
|
bit [63:0] memdata;
|
|
|
|
|
2022-03-22 14:08:34 +08:00
|
|
|
wire [MEM_DEPTH-1:0] saraddr = araddr[MEM_DEPTH - 1:0];
|
|
|
|
wire [MEM_DEPTH-1:0] sawaddr = awaddr[MEM_DEPTH - 1:0];
|
2022-03-10 11:56:21 +08:00
|
|
|
|
2022-03-22 14:08:34 +08:00
|
|
|
initial begin
|
|
|
|
mem0[0]= 8'h0;
|
|
|
|
mem0[1]= 8'h0;
|
|
|
|
mem0[2]= 8'h0;
|
|
|
|
mem0[3]= 8'h63;
|
|
|
|
mem0[5]= 8'h0;
|
|
|
|
mem0[6]= 8'h0;
|
|
|
|
mem0[7]= 8'h0;
|
|
|
|
mem0[8]= 8'h0;
|
|
|
|
end
|
2022-03-10 11:56:21 +08:00
|
|
|
always @(posedge aclk or negedge rst_l) begin
|
|
|
|
if (!rst_l) begin
|
|
|
|
rvalid <= 0;
|
|
|
|
bvalid <= 0;
|
|
|
|
end else begin
|
2022-03-22 14:08:34 +08:00
|
|
|
bid <= awid;
|
|
|
|
rid <= arid;
|
2022-03-10 11:56:21 +08:00
|
|
|
rvalid <= arvalid;
|
|
|
|
bvalid <= awvalid;
|
2022-03-22 14:08:34 +08:00
|
|
|
rdata <= memdata;
|
2022-03-10 11:56:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(negedge aclk) begin
|
|
|
|
if (arvalid)
|
|
|
|
memdata <= {
|
2022-03-22 14:08:34 +08:00
|
|
|
mem7[saraddr + 7],
|
|
|
|
mem6[saraddr + 6],
|
|
|
|
mem5[saraddr + 5],
|
|
|
|
mem4[saraddr + 4],
|
|
|
|
mem3[saraddr + 3],
|
|
|
|
mem2[saraddr + 2],
|
|
|
|
mem1[saraddr + 1],
|
|
|
|
mem0[saraddr]
|
2022-03-10 11:56:21 +08:00
|
|
|
};
|
|
|
|
if (awvalid) begin
|
2022-03-22 14:08:34 +08:00
|
|
|
if (wstrb[7]) mem7[sawaddr + 7] = wdata[63:56];
|
|
|
|
if (wstrb[6]) mem6[sawaddr + 6] = wdata[55:48];
|
|
|
|
if (wstrb[5]) mem5[sawaddr + 5] = wdata[47:40];
|
|
|
|
if (wstrb[4]) mem4[sawaddr + 4] = wdata[39:32];
|
|
|
|
if (wstrb[3]) mem3[sawaddr + 3] = wdata[31:24];
|
|
|
|
if (wstrb[2]) mem2[sawaddr + 2] = wdata[23:16];
|
|
|
|
if (wstrb[1]) mem1[sawaddr + 1] = wdata[15:08];
|
|
|
|
if (wstrb[0]) mem0[sawaddr + 0] = wdata[07:00];
|
2022-03-10 11:56:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
assign arready = 1'b1;
|
|
|
|
assign awready = 1'b1;
|
2022-03-22 14:08:34 +08:00
|
|
|
assign wready = 1'b1;
|
|
|
|
assign rresp = 2'b0;
|
|
|
|
assign bresp = 2'b0;
|
|
|
|
assign rlast = 1'b1;
|
2022-03-10 11:56:21 +08:00
|
|
|
|
|
|
|
endmodule
|