这是一个2端口数据存储器的代码,当我在quartus上编译它时 内存位数为零,并将其全部实现为逻辑元素,并且不会影响 RAM 怎么解决?
module dataMemoryTwoPorts( PAaddress , PBaddress , PAwriteData , PBwriteData , PAreadData , PBreadData,
PAwriteEn , PBwriteEn , PAreadEn , PBreadEn , clk);
// Inputs
// clock
input clk;
// Enables allow reading from memory from port A and port B
input PAreadEn , PBreadEn;
// Enables allow writing on memory through port A and port B
input PAwriteEn , PBwriteEn;
// Address of location to be accessed by port A and port B
input [31:0] PAaddress , PBaddress;
// Data to be written through port A and port B
input [31:0] PAwriteData , PBwriteData;
// Outputs
// Data to be read from port A and port B
output [31:0] PAreadData , PBreadData;
// Creating the memory vector
reg [7:0] dataMemory [0:8191];
//Initialize memory
initial begin
$readmemh("dataMemory.txt", dataMemory);
end
// Read operation, read only if the address is aligned and the read port is activated
assign PAreadData = ( PAreadEn ) ? { dataMemory[ PAaddress + 3 ] , dataMemory[ PAaddress + 2 ] , dataMemory[ PAaddress + 1] , dataMemory[PAaddress] } : 32'bx ;
assign PBreadData = ( PBreadEn ) ? { dataMemory[ PBaddress + 3 ] , dataMemory[ PBaddress + 2 ] , dataMemory[ PBaddress + 1] , dataMemory[PBaddress] } : 32'bx ;
// Write operation
always @ ( posedge clk ) begin
// for port A
if ( PAwriteEn ) begin
dataMemory [PAaddress ] <= PAwriteData[7 :0 ];
dataMemory [PAaddress+1] <= PAwriteData[15:8 ];
dataMemory [PAaddress+2] <= PAwriteData[23:16];
dataMemory [PAaddress+3] <= PAwriteData[31:24];
end
// for port B
if ( PBwriteEn ) begin
dataMemory [PBaddress ] <= PBwriteData[7 :0 ];
dataMemory [PBaddress+1] <= PBwriteData[15:8 ];
dataMemory [PBaddress+2] <= PBwriteData[23:16];
dataMemory [PBaddress+3] <= PBwriteData[31:24];
end
end
endmodule
我不想改变数据存储器的功能。 读操作异步发生 写操作发生在时钟的正沿 内存是字节可寻址的
您尝试构建的架构有 2 个写入端口和 1 个读取端口,需要块 RAM,分布式 RAM 不会执行 2 个写入和读取操作。在 Xilinx 中,块 RAM 读取始终是同步的。 Altera 中可能也是如此(需要研究才能确定)。如果您在 RTL 中对此进行建模,那么该工具所能做的就是为您提供触发器和组合逻辑来提供所请求的行为。 ug901-vivado-synthesis 中的这张表有助于理解。
您的编码方式推断有 8 个用于写入的端口,指定 8 个地址将需要 8 个物理端口。
这里有 4 个端口
dataMemory [PAaddress ] <= PAwriteData[7 :0 ];
dataMemory [PAaddress+1] <= PAwriteData[15:8 ];
dataMemory [PAaddress+2] <= PAwriteData[23:16];
dataMemory [PAaddress+3] <= PAwriteData[31:24];
这里还有 4 个端口
dataMemory [PBaddress ] <= PBwriteData[7 :0 ];
dataMemory [PBaddress+1] <= PBwriteData[15:8 ];
dataMemory [PBaddress+2] <= PBwriteData[23:16];
dataMemory [PBaddress+3] <= PBwriteData[31:24];
物理硬件有两个端口,因此它将再次利用触发器和组合逻辑构建您所描述的内容。
如果您想推断块 RAM,我建议首先通过综合运行供应商模型来验证它是否可以推断块 RAM。从你的设计开始。然后修改该代码以满足您的需要,然后再次综合。如果您对硬件和工具无法实现的东西进行建模(例如异步读取 BRAMS 或 8 端口 RAMS),那么该工具将指示其日志消息传递或它所推断的内容。