【问题标题】:How can I build a chain of modules?如何构建模块链?
【发布时间】:2013-06-22 02:53:03
【问题描述】:

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

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、reset)。

【问题讨论】:

  • 如果您使用 Verilog-2001 或更高版本,您可以使用“生成”语句来实现此目的。您可能必须对 xk 和 yk 信号进行矢量化(k=0,1,2)。只需查找生成语句。
  • 我发现可以修改代码以适应连接网络。 “电线 [32*3:1] t,s;”和“pe p[1:3' ((t,xi), ((xo,t), (s,yi), (yo,s), clk, reset);”。无论如何感谢 cmets。连接列表起初很难理解,但似乎相当合乎逻辑。

标签: verilog system-verilog


【解决方案1】:

试试这个。它应该适用于所有版本的 Verilog。在这种情况下,参数 PE_NUM 必须是值为 2 或更大的 int。如果需要 1 pe 实例,则必须使用生成块,这需要 Verilog-2001 或 SystemVerilog。当 PE_NUM 变大时(例如 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

以下是带有生成的示例:

/*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

【讨论】:

  • 语法wire [0:a] [b:0] name是什么意思?我只见过wire [b:0] name [0:a]
  • 这意味着双重支持。声明左侧的任何[] 都被打包,右侧的任何[] 都被解包。请参阅 IEEE LRMs for Verilog 和 SystemVerilog 了解 mote 详细信息
  • 我假设这是“双包装”的拼写错误?
  • Syntax 4.1 of IEEE.1364-2005 似乎暗示range (您所说的打包)只允许出现一次,至少在verilog 2005中。
  • This page 建议它是 SystemVerilog 中的一个新功能
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-30
  • 2017-02-02
  • 2011-05-22
  • 2023-04-06
  • 1970-01-01
  • 2020-06-02
  • 1970-01-01
相关资源
最近更新 更多