Verilog 正在退出generate语句内的for循环

Verilog 正在退出generate语句内的for循环,verilog,Verilog,我正在尝试在generate语句中使用无限for循环。但问题是,我无法使用某些条件停止或退出它。我用了“禁用”和“中断”。两者都不起作用 它显示了一个错误: 意外标记:“禁用” 请帮我解决这个问题或建议一个替代方案。这是我的Verilog代码: module top(a1,a3,wj,d4,d10,d2,dc,dtot); input [11:0]a1,a3,wj; input [3:0]d4; input [9:0]d10; input [1:0]d2; input [25:0]dc; out

我正在尝试在generate语句中使用无限for循环。但问题是,我无法使用某些条件停止或退出它。我用了“禁用”和“中断”。两者都不起作用

它显示了一个错误:

意外标记:“禁用”

请帮我解决这个问题或建议一个替代方案。这是我的Verilog代码:

module top(a1,a3,wj,d4,d10,d2,dc,dtot);
input [11:0]a1,a3,wj;
input [3:0]d4;
input [9:0]d10;
input [1:0]d2;
input [25:0]dc;
output reg[25:0]dtot;

reg [25:0]dt,error;
reg [11:0]alpha1,alpha3;

genvar i;
generate

    for (i=1;i>0;i=i+1-1)begin:test
    assign a1[11:0]=alpha1[11:0];
    assign a3[11:0]=alpha3[11:0];

    calb_top t1(a1,a3,wj,d4,d10,d2,dc,dt,error,alpha1,alpha3);

    if(error==26'b00000000000000000000000000)begin
    disable test;
    //break;
    end

end
endgenerate         
assign dtot=dt;
endmodule

Verilog
generate
块用于描述物理硬件。因此,
generate
块中的有限循环将需要无限的资源

generate
语句中的
for
循环必须具有固定的有限大小,可以在合成过程中确定

请记住,HDL不是按顺序执行的,而是描述物理电路之间的连接。由于您似乎只需要
calb_top
模块的一个实例,因此不需要
generate
块或
for
循环


编辑: 由于您打算执行一个迭代过程,正如Greg在下面的评论中指出的那样,您有两个选择-您可以实例化固定数量的
calb_top
块(因为无限数量将需要无限的空间),或者多次重复使用同一块

这是一些样品。我没有模拟或合成它们,但它们在逻辑上是正确的

N块解决方案

module top(a1,a3,wj,d4,d10,d2,dc,dtot,clock,done);

parameter NUM_BLOCKS = 10;

input [11:0]a1,a3,wj;
input [3:0]d4;
input [9:0]d10;
input [1:0]d2;
input [25:0]dc;
output [25:0]dtot;

wire [11:0] a1s [NUM_BLOCKS:0];
wire [11:0] a3s [NUM_BLOCKS:0];
wire [25:0] dt [NUM_BLOCKS-1:0];
wire [25:0] error [NUM_BLOCKS-1:0];

assign a1s[0]=a1;
assign a3s[0]=a3;

genvar i;
generate

    for (i=0;i<NUM_BLOCKS;i=i+1)begin:test
    calb_top t1(a1s[i],a3s[i],wj,d4,d10,d2,dc,dt[i],error[i],a1s[i+1],a3s[i+1]);

    end
endgenerate   

assign dtot=dt[NUM_BLOCKS-1];

endmodule

每个时钟周期,我们运行一次通过
calb_top
。如果
start
为1,则将
a1
a3
用作输入。否则,将使用先前的输出
alpha1
alpha3
。当
error
为0时,设置
dtot
。注意,我在端口列表中添加了
clock
start

好的,我知道了。但是我不希望只需要calb_top模块的一个实例,而是希望继续生成它的实例,直到错误变为零。此错误是calb_top模块的输出,我使用它作为退出循环的条件。当
错误
为零时,您希望捕获哪些信号?另外,
calb_top
的原型是什么(哪些信号是
input
s vs
output
s)?@vishi,在
error
为零之前,您无法生成模块实例<代码>生成必须在编译时进行静态展开<代码>错误将在模拟之前进行评估。您必须生成足够的
calb_top
,以解决最坏情况。在最坏的情况下,可能需要不合理的硬件数量,并且大多数逻辑将未得到充分利用。使用顺序逻辑将允许通过触发反馈来重用
calb_top
实例。@wilcroft当错误为零时,我想捕获calb_top模块的“dt”。下面是calb_top的输入和输出:输入:-a1、a3、wj、d4、d10、d2、dc……输出是:-dt、error、alpha1、alpha3……因此,我想停止循环,即停止实例化calb_top……dt将被分配到generate语句之外的dtot。@Greg谢谢……我理解你的意思。无限生成是不可能的
module top(clock,start,a1,a3,wj,d4,d10,d2,dc,dtot);
input clock;
input start;
input [11:0]a1,a3,wj;
input [3:0]d4;
input [9:0]d10;
input [1:0]d2;
input [25:0]dc;
output reg[25:0]dtot;

wire [25:0]dt,error;
reg [11:0] a1in, a3in;
wire [11:0] alpha1,alpha3;

calb_top t1(a1in,a3in,wj,d4,d10,d2,dc,dt,error,alpha1,alpha3);

always @(posedge clock)
begin
    if (start)
    begin
        a1in <= a1;
        a3in <= a3;
    end
    else
    begin
        a1in <= alpha1;
        a3in <= alpha3;
    end
end

always @(posedge clock)
    if (start)
        dtot <= 0;
    else if (error == 0)
        dtot <= dt;
    else
        dtot <= dtot;


endmodule