Verilog Ports

端口是一组信号,作为特定模块的输入和输出,是与模块通信的主要方式。把一个模块想象成一个放置在PCB上的预制芯片,很明显,与芯片通信的唯一方式就是通过它的引脚。端口就像大头针,被设计用来发送和接收来自外部世界的信号。
在这里插入图片描述

端口类型

Port Description
Input 设计模块只能使用其输入端口从外部接收值
Output 设计模块只能使用其输出端口将值发送到外部
Inout 设计模块可以使用其输入端口发送或接收值

默认情况下,端口被视为wire线网类型。

Syntax

声明为inout的端口可以同时充当输入和输出。

 input  [net_type] [range] list_of_names;   // Input port
  inout  [net_type] [range] list_of_names;   // Input & Output port
  output [net_type] [range] list_of_names;   // Output port driven by a wire
  output [var_type] [range] list_of_names;   // Output port driven by a variable

在下面显示的代码中,有三个输入端口,一个输出端口和一个inout端口。

module  my_design ( input wire      clk,
                    input           en,
                    input           rw,
                    inout [15:0]    data,
                    output           int );
 
  // Design behavior as Verilog code
 
endmodule
 

对多个端口使用相同的名称是非法的。

 input  aport;         // First declaration - valid
  input  aport;         // Error - already declared
  output aport;         // Error - already declared

Signed ports(signed端口)

可以将signed属性附加到端口声明或net / reg声明或两者。默认情况下,隐式网络是未签名的。

module ( input      a, 
                    b,
         output     c);
 
  // 默认情况下,端口a,b和c不是未signed的
endmodule

如果net / reg声明中的任何一个具有署名属性,则另一个也应视为已署名。

module ( input signed a, b,
           output c);
    wire a, b;          // a, b are signed from port declaration
    reg signed c;       // c is signed from reg declaration
  endmodule

端口变化

Verilog 1995

Verilog经过了一些修改,1995年的原始IEEE版本采用以下方式声明端口。 在这里,模块声明必须首先在方括号内列出端口的名称,然后再在模块主体内定义这些端口的方向。

module test (a, b, c);
 
  input   [7:0] a;            // inputs "a" and "b" are wires
  input   [7:0] b;  
  output   [7:0] c;       // output "c" by default is a wire
 
  // Still, you can declare them again as wires to avoid confusion
  wire   [7:0] a;
  wire   [7:0] b;
  wire   [7:0] c;
endmodule
 
 
module test (a, b, c);
 
  input  [7:0] a, b;
  output [7:0] c;           // By default c is of type wire
 
  // port "c" is changed to a reg type
  reg    [7:0] c;           
endmodule

Verilog 2001

ANSI-C样式的端口命名是在2001年引入的,并允许在端口列表中指定类型。

module test ( input [7:0]  a,
                            b,     // "b" is considered an 8-bit input
              output [7:0]  c);
 
  // Design content        
endmodule
 
module test ( input wire [7:0]  a,   
              input wire [7:0]  b,     
              output reg [7:0]  c);
 
  // Design content
endmodule

如果端口声明包含net或变量类型,则认为该端口已完全声明。 在net或变量类型声明中重新声明相同的端口是非法的。

module test ( input      [7:0] a,       // a, e are implicitly declared of type wire
            output reg [7:0] e );
 
   wire signed [7:0] a;     // illegal - declaration of a is already complete -> simulator dependent
   wire        [7:0] e;     // illegal - declaration of e is already complete
 
   // Rest of the design code
endmodule
 

如果端口声明不包含net或变量类型,则可以再次在net或变量类型声明中声明端口。

module test ( input      [7:0] a,
              output     [7:0] e);
 
     reg [7:0] e;              // Okay - net_type was not declared before
 
     // Rest of the design code
endmodule

参考文献:
【1】https://www.chipverify.com/verilog/verilog-ports

发布了124 篇原创文章 · 获赞 8 · 访问量 6681

猜你喜欢

转载自blog.csdn.net/qq_43042339/article/details/104556787
今日推荐