0

我发现这在 Verilog 代码中经常发生:

wire my_module_output_1;
wire my_module_output_2;
wire my_module_output_3;
...

MyModule my_module(
    .output_1(my_module_output_1),
    .output_2(my_module_output_2),
    .output_3(my_module_output_3),
    ...
);

MyOtherModule my_other_module(
    .input_1(my_module_output_1),
    .input_2(my_module_output_2),
    .input_3(my_module_output_3),
    ...
);

希望我能做的是:

MyModule my_module();
MyOtherModule my_other_module(
    .input_1(my_module.output_1),
    .input_2(my_module.output_2),
    .input_3(my_module.output_3),
    ...
);

有没有这样的方法可以让我达到同样的效果,即避免每次我需要从某个地方连接的某个模块的输出时一遍又一遍地重复自己?

4

2 回答 2

4

您可以使用以下几种方法来减少重复次数。

起点

这是一个连接两个子模块的简单示例。正如您在问题中指出的那样,将它们缝合在一起需要大量重复。

module source(output A, output B);
  assign A = 0;
  assign B = 1;
endmodule

module sink(input A, input B);
  initial begin
    #1 $display("A=%0d B=%0d", A, B);
  end
endmodule

module top();

  wire A;
  wire B;

  source the_source(
    .A(A),
    .B(B)
  );

  sink the_sink(
    .A(A),
    .B(B)
  );

endmodule

使用隐式连线

Verilog 允许隐式声明连线。因此,如下所示,您不需要将Aand声明B为连线。如果它们出现在端口映射中,它们将被隐式声明。唯一的问题是它们总是被声明为单比特线/网。因此,虽然这对单比特信号很有效,但对于总线,仍然需要明确声明互连。

// Verilog, implicit wires
module top();

source the_source(
  .A(A),
  .B(B)
);

sink the_sink(
  .A(A),
  .B(B)
);

endmodule

使用 Verilog 模式 AUTO

Verilog-Mode emacs 包可以极大地帮助减少将模块拼接在一起所需的输入量。这是上面使用 AUTO 的示例。

在扩展 AUTO 之前:

// Verilog, explicit connections using AUTOs
module top();

  /*AUTOWIRE*/

  source the_source (/*AUTOINST*/);

  sink the_sink (/*AUTOINST*/);

endmodule

展开 AUTO 后:

// Verilog, explicit using AUTOs
module top();

  /*AUTOWIRE*/
  // Beginning of automatic wires (for undeclared instantiated-module outputs)
  wire                A;                      // From the_source of source.v
  wire                B;                      // From the_source of source.v
  // End of automatics

  source the_source (/*AUTOINST*/
                     // Outputs
                     .A               (A),
                     .B               (B));

  sink the_sink (/*AUTOINST*/
                 // Inputs
                 .A                   (A),
                 .B                   (B));

endmodule

正如布赖恩在他的回答中指出的那样,您不需要使用 emacs 来使用 Verilog-Mode。我也使用 Vim 并使用这个 Vim 脚本在 Vim 中启用 Verilog-Mode。


SystemVerilog 选项

如果可以使用 SystemVerilog,则可以使用点星符号按名称连接端口。这非常方便,但您仍然必须声明对等模块之间的互连线。

// SystemVerilog, dot-star notation
module top();

  wire A;
  wire B;

  source the_source(.*);
  sink the_sink(.*);

endmodule
于 2013-03-27T04:13:11.510 回答
2

人们仍然没有到处使用 Verilog AUTOs 吗?

http://www.veripool.org/wiki/verilog-mode/Verilog-mode-Help

特别要注意关于 AUTOINST 的部分。这并不能解决你所有的问题,但是明智地使用 AUTO 可以减少生成结构 Verilog 的大量乏味。

不要介意它是一个 Emacs 节点。我自己是一个 vim 人,但是当我需要更新我的 AUTOs 时,我只是通过 emacs 管道加载我的缓冲区并加载此模式。

于 2013-03-27T01:08:37.340 回答