简体   繁体   中英

Verilog - increment local parameter in generate block

I'm getting an error in my Verilog generate block, on the line where it says j = j+1; stating `j is an unknown type'

genvar i;
generate
    localparam integer j = 0;
    for (i = 0; i < BUFFER; i=i+1) begin
        if((i%DATA_WIDTH) < (KERNEL_SIZE-1)) begin
            assign o_input_matrix[((j+1)*DATA_WIDTH)-1:j*DATA_WIDTH] = 
buffer[((i+1)*DATA_WIDTH)-1:i*DATA_WIDTH];
            j = j+1;
        end
    end
endgenerate

BUFFER, DATA_WIDTH, and KERNEL_SIZE are local parameters I have in my module.

I've been looking at ways I could have a 2nd parameter in my generate block, I've found out that I can only use genvar variables in a for loop, so I couldnt make a 2nd genvar variable for j.

I came across this question: Incrementing Multiple Genvars in Verilog Generate Statement

I tried basing my code of the 2nd answer, but my situation is slightly different because I'm only incrementing it in an if statement.

Any help would be appreciated.

You are going to have to make a function to define the value of j .

genvar i;
for (i = 0; i < BUFFER; i=i+1)
   if((i%DATA_WIDTH) < (KERNEL_SIZE-1)) begin
      localparam j = func(i);
      assign o_input_matrix[((j+1)*DATA_WIDTH)-1:j*DATA_WIDTH] = 
buffer[((i+1)*DATA_WIDTH)-1:i*DATA_WIDTH];
        end
    end
function integer func(integer ii);
   for (ii = 0;ii < BUFFER; ii++)
     if ((ii %DATA_WIDTH) < (KERNEL_SIZE-1)) ii++;
endfunction

Didn't try this, but hope it gets you close to what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM