Verilog generate/genvar in an always block

前端 未结 6 906
鱼传尺愫
鱼传尺愫 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 08:52

    Within a module, Verilog contains essentially two constructs: items and statements. Statements are always found in procedural contexts, which include anything in between begin..end, functions, tasks, always blocks and initial blocks. Items, such as generate constructs, are listed directly in the module. For loops and most variable/constant declarations can exist in both contexts.

    In your code, it appears that you want the for loop to be evaluated as a generate item but the loop is actually part of the procedural context of the always block. For a for loop to be treated as a generate loop it must be in the module context. The generate..endgenerate keywords are entirely optional(some tools require them) and have no effect. See this answer for an example of how generate loops are evaluated.

    //Compiler sees this
    parameter ROWBITS = 4;
    reg [ROWBITS-1:0] temp;
    genvar c;
    
        always @(posedge sysclk) //Procedural context starts here
        begin
            for (c = 0; c < ROWBITS; c = c + 1) begin: test
                temp[c] <= 1'b0; //Still a genvar
            end
        end
    

提交回复
热议问题