I am designing some hardware in Verilog, but in an effort to keep things flexible, I am using parameters to set widths so that I can modify widths as needed without modifying code. One problem I have run into is in a section of code where I want to be able to do a parallel write into multiple cells.
parameter DATA_WIDTH = 16;
parameter BUFFER_SIZE = 16;
parameter LOAD_WIDTH = DATA_WIDTH*BUFFER_SIZE;
input [LOAD_WIDTH-1:0] i_load_data;
reg [DATA_WIDTH-1:0] r_data_buf[BUFFER_SIZE-1:0];
...
always@(posedge clk) begin
....
else if (i_load_flag) begin
for(i = 0; i < BUFFER_SIZE; i = i + 1)
r_data_buf[i] <= i_load_data[i * BUFFER_SIZE + BUFFER_SIZE - 1:i * BUFFER_SIZE];
end
end
I need to keep r_data_buf as an array because of the way the data has to be read. It is also not clear to me why verilog doesn't like this code since everything is a constant at compile time or how I can fix it and still get the behavior I want.