Verilog generate/genvar in an always block

前端 未结 6 877
鱼传尺愫
鱼传尺愫 2020-12-01 08:19

I\'m trying to get a module to pass the syntax check in ISE 12.4, and it gives me an error I don\'t understand. First a code snippet:

parameter ROWBITS = 4;
         


        
6条回答
  •  眼角桃花
    2020-12-01 09:01

    You need to reverse the nesting inside the generate block:

    genvar c;
    generate
        for (c = 0; c < ROWBITS; c = c + 1) begin: test
            always @(posedge sysclk) begin
                temp[c] <= 1'b0;
            end
        end
    endgenerate
    

    Technically, this generates four always blocks:

    always @(posedge sysclk) temp[0] <= 1'b0;
    always @(posedge sysclk) temp[1] <= 1'b0;
    always @(posedge sysclk) temp[2] <= 1'b0;
    always @(posedge sysclk) temp[3] <= 1'b0;
    

    In this simple example, there's no difference in behavior between the four always blocks and a single always block containing four assignments, but in other cases there could be.

    The genvar-dependent operation needs to be resolved when constructing the in-memory representation of the design (in the case of a simulator) or when mapping to logic gates (in the case of a synthesis tool). The always @posedge doesn't have meaning until the design is operating.

    Subject to certain restrictions, you can put a for loop inside the always block, even for synthesizable code. For synthesis, the loop will be unrolled. However, in that case, the for loop needs to work with a reg, integer, or similar. It can't use a genvar, because having the for loop inside the always block describes an operation that occurs at each edge of the clock, not an operation that can be expanded statically during elaboration of the design.

提交回复
热议问题