This repository has been archived on 2026-08-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ciciec2026/rtl/ip/bram0/my_bram0.v

47 lines
1.6 KiB
Verilog
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
`timescale 1ns / 1ps
module my_bram0 #(
parameter DATA_WIDTH = 32, // 数据位宽,默认 32 bit
parameter ADDR_WIDTH = 10 // 地址位宽 10 bit,对应深度 1024
)(
// ======== Port A (Write Only) ========
input wire clka,
input wire ena,
input wire wea,
input wire [ADDR_WIDTH-1:0] addra,
input wire [DATA_WIDTH-1:0] dina,
// ======== Port B (Read Only) ========
input wire clkb,
input wire enb,
input wire [ADDR_WIDTH-1:0] addrb,
output reg [DATA_WIDTH-1:0] doutb
);
// 声明二维数组作为存储介质
// 使用 (* ram_style = "block" *) 强制 Vivado 综合器将其映射为 BRAM 资源
(* ram_style = "block" *) reg [DATA_WIDTH-1:0] ram [0:(1<<ADDR_WIDTH)-1];
//-------------------------------------------------------
// Port A: 同步写入逻辑
//-------------------------------------------------------
always @(posedge clka) begin
// ena 是整个端口的使能,wea 是具体的写使能标志
// 在你的例化中 wea 恒为 1'b1,所以实际由 ena 控制写入
if (ena) begin
if (wea) begin
ram[addra] <= dina;
end
end
end
//-------------------------------------------------------
// Port B: 同步读出逻辑
//-------------------------------------------------------
always @(posedge clkb) begin
if (enb) begin
doutb <= ram[addrb];
end
end
endmodule