如何构建模块链?

时间:2012-12-29 04:32:37

标签: verilog system-verilog

我在构建一系列模块时遇到了麻烦。我可以手动连接模型列出所有模块,但需要更简洁的表示。以下代码已经尝试但不起作用?我该如何更正代码?

module network(
    input signed [31:0] xi,
    output signed [31:0] yo,
    input clk,
    input reset
    );

    wire signed [31:0] x0, x1, x2, y0, y1, y2, xo;
    wire [3:1] t;
    //working code for chain of pe
//   pe u0(xi, x0, 0, y0, clk, reset);  
//   pe u1(x0, x1, y0, y1, clk, reset);
//   pe u2(x1, x2, y1, y2, clk, reset);
//   pe u3(x2, xo, y2, yo, clk, reset);
    //chain of array not working! how!
    pe p[1:4] ((xi,t), (t, x), (0, t), (t,yo),clk,reset); <- want to improve
endmodule

这里,pe(输入,输出,输入,输出,clk,重置)。

1 个答案:

答案 0 :(得分:1)

试试这个。它应该适用于Verilog的所有版本。在这种情况下,参数PE_NUM必须是值为2或更大的int。如果需要1 pe实例,则必须使用生成块,这需要Verilog-2001或SystemVerilog。当PE_NUM变大时(ex 2 ** 16),一些模拟器可能会遇到内存限制。

/*All Verilog*/
module network(
        input signed [31:0] xi,
        output signed [31:0] yo,
        input clk,
        input reset
        );
    parameter PE_NUM = 4; // limitation PE_NUM must be greater then 1
    wire signed [31:0] xo;
    wire signed [0:PE_NUM-2] [31:0] xN;
    wire signed [0:PE_NUM-2] [31:0] yN;
    pe p[0:PE_NUM-1] ({xi,xN}, {xN,xo}, {32'b0,yN}, {yN,yo}, clk,reset);
endmodule

以下是generate:

的示例
/*Verilog-2001 or SystemVerilog*/
module network(
        input signed [31:0] xi,
        output signed [31:0] yo,
        input clk,
        input reset
        );
    parameter PE_NUM = 4; // no limitation
    wire signed [31:0] xo;
    generate
        if(PE_NUM <2) begin
            pe p (xi, xo, 32'b0, yo, clk,reset);
        end
        else begin
            wire signed [0:PE_NUM-2] [31:0] xN;
            wire signed [0:PE_NUM-2] [31:0] yN;
            pe p[0:PE_NUM-1] ({xi,xN}, {xN,xo}, {32'b0,yN}, {yN,yo}, clk,reset);
        end
    endgenerate
endmodule