在 Verilog 中可以将模块的输出用作子模块的输入吗?

Is it okay to use module's output as an input of submodule in Verilog?

您好,我是 Verilog 的新手,我对设计模块有一些疑问。
是否可以将顶层模块的输出用作子模块的输入(将两个模块作为时序逻辑)?
根据我对触发器的直觉,它似乎没问题,但我不确定这种方法在 verilog 编码中是否可以接受(无论如何在逻辑或常规方面)。应该避免这种编码吗?

module sample_top(
    input a,
    input b,
    input c,
    output d,
    output e
    );
    
    //sequential
    sample_submodule_1 SAMPLE_SUBMODULE_1(
        //input of submodule
        .A(a),
        .B(b),
        //output of submodule
        .D(d)
        );

    //sequential
    sample_submodule_2 SAMPLE_SUBMODULE_2(
        //input of submodule
        .C(c),
        .D(d),
        //output of submodule
        .E(e)
        );

感谢您的回答。

Verilog 语言并不真正关心端口方向。层次结构仅用于创建名称空间和行为容器。端口连接成为 aA 到单个线对象的符号命名。

VHDL 等其他 HDL 确实对读取值输出设置了限制。这些 HDL 之间的区别是这些语言如何解析多个驱动程序的产物(这将花费太多时间来进入这里)。在 Verilog 中,如果端口的一侧是变量 (reg),而另一侧是电线,则可以看到多个驱动器解析的效果。只有端口的有线端才能看到多个驱动程序的解析值。

不应引用输出信号。这是建议(最佳实践)。许多专业 linter 将其视为警告或通知。

  • 输出和子模块输出直接连接就可以了(你的子模块1)。
  • 输出和子模块输入的直接连接是违规的(您的子模块 2)。
  • 输出与函数直接连接return即可
  • 输出和函数输入参数的直接连接是违规的。
  • 直接连接输出和任务输出参数即可。
  • 直接连接输出和任务输入参数是违规的。
  • 其他对输出端口的引用是违规的。

例如:

module SOME_MODULE(
    clk,
    rstn,
    a,
    b,
    y
);

    input clk;
    input rstn;
    input [3 : 0] a;
    input [3 : 0] b;
    output reg [5 : 0] y;

    always @(posedge clk or negedge rstn) begin
        if (~rstn)
            y <= 5'd 0;
        else
            y <= y + a + b;  // Reference to output port detected
    end

endmodule

应描述为:

module SOME_MODULE(
    clk,
    rstn,
    a,
    b,
    y
);

    input clk;
    input rstn;
    input [3 : 0] a;
    input [3 : 0] b;
    output [5 : 0] y;

    reg [5 : 0] y_reg;
    assign y = y_reg;

    always @(posedge clk or negedge rstn) begin
        if (~rstn)
            y_reg <= 5'd 0;
        else
            y_reg <= y_reg + a + b;
    end

endmodule