I've been scratching my head trying to figure out how I can initialize inferred RAM.
Here's my InitializedBank.v resource for my BlackBox.
/**
* This is an initialized bank in a syntax that both Xilinx and Verilator undrestands.
*
* Ideally we'd be able to pass in the ram initialization data as a parameter, so that we didn't
* need the bank.txt files.
*
* TODO make number of address lines a parameter
*/
module InitializedBank(
input clock,
input reset,
input [15:0] bank_In,
output [15:0] bank_Out,
input bank_ReadEna,
input [13:0] bank_ReadRow,
input bank_WriteEna,
input [13:0] bank_WriteRow
);
reg [15:0] ram [0:16383];
reg [15:0] out;
assign bank_Out = out;
parameter INITIAL_VALUE = "bank1.txt";
integer initvar;
initial $readmemh(INITIAL_VALUE, ram, 0, 16383);
always @(posedge clock) begin
if (bank_WriteEna) begin
ram[bank_WriteRow] <= bank_In;
end
if (bank_ReadEna) begin
out <= ram[bank_ReadRow];
end
end
endmodule
class InitializedBank(rows : Int, initial : Array[Byte], bankNum : Int)
extends BlackBox(Map("INITIAL_VALUE" -> Helper.bankString(rows, initial, bankNum))) with HasBlackBoxResource
{
val io = IO(new Bundle()
{
val clock = Input(Clock())
val reset = Input(Bool())
val bank = new BankBundle(rows)
})
setResource("/InitializedBank.v")
}