SystemVerilog:自动变量不能为静态 reg 出现非阻塞赋值

SystemVerilog: Automatic variables cannot have non-blocking assignments appearing for static reg

我实际将寄存器设置为静态后开始出现此错误。

这在 Quartus 中符合要求:

task InitAutoRefresh;

       reg [$clog2(AUTOREFRESH_CLOCKS):0] AutoRefreshCounter = 0;

       AutoRefreshCounter <= AutoRefreshCounter + 1;
       InitState <= (AutoRefreshCounter < AUTOREFRESH_CLOCKS) ? InitState : InitState + 1;       

       InitCmd <= (AutoRefreshCounter == 0) ? CMD_AR : CMD_NOP;

endtask

但是 Modelsim 给我这个错误:

# ** Error (suppressible): C:/projects/Camera-RAM-VGA/Ram.sv(137): (vlog-2244) Variable 'AutoRefreshCounter' is implicitly static. You must either explicitly declare it as static or automatic
# or remove the initialization in the declaration of variable.

现在,当我在 reg [$clog2(AUTOREFRESH_CLOCKS):0] AutoRefreshCounter = 0; 前面添加 static 时,Quartus 给我这个错误(看起来与我的更改相反):

Error (10959): SystemVerilog error at Ram.sv(139): illegal assignment - automatic variables can't have non-blocking assignments

这指向我刚刚添加 static 关键字的寄存器!

我能想到的唯一可能的解释是,当我将 static 添加到这个 reg 时,它开始将其他 regs 视为 automatic,但随后报错信息不对。

我只是将 AutoRefreshCounter 的声明移到任务之外。那么很明显,变量只在时间 0 被初始化一次。(这就是首先出现 "Implicitly static" 错误消息的原因)。