Skip to content

Commit

Permalink
fix(mem): generate if for RAMS when HEXFILE="none"
Browse files Browse the repository at this point in the history
- addresses IObundle#95
  • Loading branch information
P-Miranda committed Dec 27, 2024
1 parent 617b18d commit cd002cb
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,18 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
localparam INIT_RAM = (HEXFILE != "none") ? 1 : 0;
// Declare the RAM
reg [DATA_W-1:0] ram[(2**ADDR_W)-1:0];
reg [DATA_W-1:0] r_data_o_reg;
assign r_data_o=r_data_o_reg;
// Initialize the RAM
initial begin
if (MEM_INIT_FILE_INT != "none") begin
$readmemh(MEM_INIT_FILE_INT, ram, 0, (2 ** ADDR_W) - 1);
generate
if (INIT_RAM) begin : mem_init
initial $readmemh(MEM_INIT_FILE_INT, ram, 0, (2 ** ADDR_W) - 1);
end
end
endgenerate
//write
always @(posedge w_clk_i) begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
localparam INIT_RAM = (MEM_INIT_FILE_INT != "none") ? 1 : 0;
// Declare the RAM
reg [DATA_W-1:0] ram[2**ADDR_W-1:0];
reg [DATA_W-1:0] dA_o_reg;
Expand All @@ -145,7 +146,11 @@ def setup(py_params_dict):
assign dB_o=dB_o_reg;
// Initialize the RAM
initial if (MEM_INIT_FILE_INT != "none") $readmemh(MEM_INIT_FILE_INT, ram, 0, 2 ** ADDR_W - 1);
generate
if (INIT_RAM) begin : mem_init
initial $readmemh(MEM_INIT_FILE_INT, ram, 0, 2 ** ADDR_W - 1);
end
endgenerate
//read port
always @(posedge clkA_i) begin // Port A
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,20 @@ def setup(py_params_dict):
endgenerate
`else // !IOB_MEM_NO_READ_ON_WRITE
// this allow ISE 14.7 to work; do not remove
localparam INIT_RAM = (mem_init_file_int != "none.hex") ? 1 : 0;
localparam mem_init_file_int = {HEXFILE, ".hex"};
// Core Memory
reg [DATA_W-1:0] ram_block[(2**ADDR_W)-1:0];
// Initialize the RAM
initial
if (mem_init_file_int != "none.hex")
$readmemh(mem_init_file_int, ram_block, 0, 2 ** ADDR_W - 1);
generate
if (INIT_RAM) begin : mem_init
initial
if (mem_init_file_int != "none.hex")
$readmemh(mem_init_file_int, ram_block, 0, 2 ** ADDR_W - 1);
end
endgenerate
// Port-A Operation
reg [DATA_W-1:0] dA_o_int;
Expand Down
7 changes: 6 additions & 1 deletion py2hwsw/lib/hardware/memories/ram/iob_ram_sp/iob_ram_sp.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,18 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
localparam INIT_RAM = (MEM_INIT_FILE_INT != "none") ? 1 : 0;
// Declare the RAM
reg [DATA_W-1:0] ram[2**ADDR_W-1:0];
reg [DATA_W-1:0] d_o_reg;
assign d_o=d_o_reg;
// Initialize the RAM
initial if (MEM_INIT_FILE_INT != "none") $readmemh(MEM_INIT_FILE_INT, ram, 0, 2 ** ADDR_W - 1);
generate
if (INIT_RAM) begin : mem_init
initial $readmemh(MEM_INIT_FILE_INT, ram, 0, 2 ** ADDR_W - 1);
end
endgenerate
// Operate the RAM
always @(posedge clk_i)
Expand Down
12 changes: 8 additions & 4 deletions py2hwsw/lib/hardware/memories/ram/iob_ram_sp_be/iob_ram_sp_be.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
// Operation
`ifdef IOB_MEM_NO_READ_ON_WRITE
localparam file_suffix = {"7", "6", "5", "4", "3", "2", "1", "0"};
Expand Down Expand Up @@ -113,15 +113,19 @@ def setup(py_params_dict):
endgenerate
`else // !IOB_MEM_NO_READ_ON_WRITE
// this allows ISE 14.7 to work; do not remove
localparam INIT_RAM = (HEXFILE != "none") ? 1 : 0;
localparam mem_init_file_int = {HEXFILE, ".hex"};
// Core Memory
reg [DATA_W-1:0] ram_block[(2**ADDR_W)-1:0];
// Initialize the RAM
initial
if (mem_init_file_int != "none.hex")
$readmemh(mem_init_file_int, ram_block, 0, 2 ** ADDR_W - 1);
generate
if (INIT_RAM) begin : mem_init
initial
$readmemh(mem_init_file_int, ram_block, 0, 2 ** ADDR_W - 1);
end
endgenerate
reg [DATA_W-1:0] d_o_int;
integer i;
Expand Down
13 changes: 9 additions & 4 deletions py2hwsw/lib/hardware/memories/ram/iob_ram_sp_se/iob_ram_sp_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
// Operation
`ifdef IOB_MEM_NO_READ_ON_WRITE
Expand Down Expand Up @@ -114,15 +114,20 @@ def setup(py_params_dict):
endgenerate
`else // !IOB_MEM_NO_READ_ON_WRITE
// this allows ISE 14.7 to work; do not remove
localparam INIT_RAM = (HEXFILE != "none") ? 1 : 0;
localparam mem_init_file_int = {HEXFILE, ".hex"};
// Core Memory
reg [DATA_W-1:0] ram_block[(2**ADDR_W)-1:0];
// Initialize the RAM
initial
if (mem_init_file_int != "none.hex")
$readmemh(mem_init_file_int, ram_block, 0, 2 ** ADDR_W - 1);
generate
if (INIT_RAM) begin : mem_init
initial
if (mem_init_file_int != "none.hex")
$readmemh(mem_init_file_int, ram_block, 0, 2 ** ADDR_W - 1);
end
endgenerate
reg [DATA_W-1:0] d_o_int;
integer i;
Expand Down
11 changes: 6 additions & 5 deletions py2hwsw/lib/hardware/memories/ram/iob_ram_t2p/iob_ram_t2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,20 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
localparam INIT_RAM = (MEM_INIT_FILE_INT != "none") ? 1 : 0;
// Declare the RAM
reg [DATA_W-1:0] mem [(2**ADDR_W)-1:0];
reg [DATA_W-1:0] r_data;
// Initialize the RAM
initial begin
if (MEM_INIT_FILE_INT != "none") begin
$readmemh(MEM_INIT_FILE_INT, mem, 0, (2 ** ADDR_W) - 1);
generate
if (INIT_RAM) begin : mem_init
initial $readmemh(MEM_INIT_FILE_INT, mem, 0, (2 ** ADDR_W) - 1);
end
end
endgenerate
//read port
always @(posedge clk_i) begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,19 @@ def setup(py_params_dict):
endgenerate
`else // !IOB_MEM_NO_READ_ON_WRITE
//this allows ISE 14.7 to work; do not remove
localparam INIT_RAM = (HEXFILE != "none") ? 1 : 0;
localparam mem_init_file_int = HEXFILE;
// Declare the RAM
reg [DATA_W-1:0] mem[(2**ADDR_W)-1:0];
// Initialize the RAM
initial if (mem_init_file_int != "none") $readmemh(mem_init_file_int, mem, 0, (2 ** ADDR_W) - 1);
generate
if (INIT_RAM) begin : mem_init
initial
$readmemh(mem_init_file_int, mem, 0, (2 ** ADDR_W) - 1);
end
endgenerate
//read port
always @(posedge clk_i) if (r_en_i) r_data_o_reg <= mem[r_addr_i];
Expand Down
7 changes: 6 additions & 1 deletion py2hwsw/lib/hardware/memories/ram/iob_ram_tdp/iob_ram_tdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
localparam INIT_RAM = (MEM_INIT_FILE_INT != "none") ? 1 : 0;
reg [DATA_W-1:0] dA_o_reg;
reg [DATA_W-1:0] dB_o_reg;
assign dA_o=dA_o_reg;
Expand All @@ -146,7 +147,11 @@ def setup(py_params_dict):
reg [DATA_W-1:0] ram[2**ADDR_W-1:0];
// Initialize the RAM
initial if (MEM_INIT_FILE_INT != "none") $readmemh(MEM_INIT_FILE_INT, ram, 0, 2 ** ADDR_W - 1);
generate
if (INIT_RAM) begin : mem_init
initial $readmemh(MEM_INIT_FILE_INT, ram, 0, 2 ** ADDR_W - 1);
end
endgenerate
generate
if (MEM_NO_READ_ON_WRITE) begin : with_MEM_NO_READ_ON_WRITE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
localparam INIT_RAM = (MEM_INIT_FILE_INT != "none.hex") ? 1 : 0;
// Core Memory
reg [DATA_W-1:0] ram_block[(2**ADDR_W)-1:0];
// Initialize the RAM
initial
if (MEM_INIT_FILE_INT != "none.hex")
$readmemh(MEM_INIT_FILE_INT, ram_block, 0, 2 ** ADDR_W - 1);
generate
if (INIT_RAM) begin : mem_init
initial $readmemh(MEM_INIT_FILE_INT, ram_block, 0, 2 ** ADDR_W - 1);
end
endgenerate
// Port-A Operation
reg [DATA_W-1:0] dA_o_int;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
localparam INIT_RAM = (MEM_INIT_FILE_INT != "none") ? 1 : 0;
// Declare the ROM
reg [DATA_W-1:0] rom[2**ADDR_W-1:0];
// Initialize the ROM
initial if ( MEM_INIT_FILE_INT != "none") $readmemh( MEM_INIT_FILE_INT, rom, 0, 2 ** ADDR_W - 1);
generate
if (INIT_RAM) begin : mem_init
initial $readmemh( MEM_INIT_FILE_INT, rom, 0, 2 ** ADDR_W - 1);
end
endgenerate
always @(posedge clk_a_i) // Port A
if (r_en_a_i)
Expand Down
9 changes: 7 additions & 2 deletions py2hwsw/lib/hardware/memories/rom/iob_rom_sp/iob_rom_sp.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,19 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
localparam INIT_RAM = (MEM_INIT_FILE_INT != "none") ? 1 : 0;
// Declare the ROM
reg [DATA_W-1:0] rom[(2**ADDR_W)-1:0];
// Initialize the ROM
initial if ( MEM_INIT_FILE_INT != "none") $readmemh( MEM_INIT_FILE_INT, rom, 0, (2 ** ADDR_W) - 1);
generate
if (INIT_RAM) begin : mem_init
initial $readmemh( MEM_INIT_FILE_INT, rom, 0, (2 ** ADDR_W) - 1);
end
endgenerate
// Operate the ROM
always @(posedge clk_i) if (r_en_i)
always @(posedge clk_i) if (r_en_i)
r_data_o <= rom[addr_i];
""",
},
Expand Down
9 changes: 5 additions & 4 deletions py2hwsw/lib/hardware/memories/rom/iob_rom_tdp/iob_rom_tdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@ def setup(py_params_dict):
"snippets": [
{
"verilog_code": """
localparam INIT_RAM = (MEM_INIT_FILE_INT != "none") ? 1 : 0;
// Declare the ROM
reg [DATA_W-1:0] rom[(2**ADDR_W)-1:0];
// Initialize the ROM
initial begin
if (MEM_INIT_FILE_INT != "none") begin
$readmemh(MEM_INIT_FILE_INT, rom, 0, (2 ** ADDR_W) - 1);
generate
if (INIT_RAM) begin : mem_init
initial $readmemh(MEM_INIT_FILE_INT, rom, 0, (2 ** ADDR_W) - 1);
end
end
endgenerate
always @(posedge clk_i) begin // Port A
if (r_en_a_i) begin
Expand Down

0 comments on commit cd002cb

Please sign in to comment.