数据类型:
logic为四值逻辑表示为0、1、X、Z
bit为二值逻辑表示为0、1
四值逻辑类型:integer、reg、logic、net-type(wire、tri)
二值逻辑类型:byte、shortint、int、longint、bit
有符号类型:byte、shortint、int、longint、integer
无符号类型:bit、logic、reg、net-type
模块定义与例化
模块定义
module test(
input clk,
input rst,
input [3:0] data,
output [2:0] y
);
endmodule
模块例化
test u0(
.clk(clks),
.rst(rst),
.data(data_s),
.y(y_s)
);
参数化模块
module test
#(parameter int addr_width = 8,
parameter int data_width = 32)
(
input clk,
input rst,
input [addr_width:0] data,
output [data_width:0] y
);
endmodule
宏定义
'define addr_width 8
'define data_width 32
module test
(
input clk,
input rst,
input ['addr_width:0] data,
output ['data_width:0] y
);
endmodule
接口
interface使用
interface regs_cr_if;
logic clk;
logic rst;
initial begin
clk<=0;
forever begin
#5ns clk<=!clk;
end
end
initial begin
#20ns;
rst<=1;
#40ns;
rst<=0
#40ns;
rst<=1;
end
endinterface: regs_cr_if
对interface例化
reg_cr_if cr_if();
test u0(
.clk(cr_if.clk),
.rst(cr_if.rst),
.......
)
任务与函数
Task与function可声明多个input、output、inout和ref类型
- function
- 默认数据类型是logic
- 数组可以作为形式参数传递
- 可以返回或不返回结果
- 只有数据变量可以在形式参数列表中声明为ref类型
- 不可内置耗时语句
- 用function或者task均可调用
- task
- 无法通过return返回结果只能通过output、inout、或者ref参数返回
- 可以内置耗时语句
- 可能用于需要耗时信号采样或驱动场景
- 若内含耗时语句只能用task调用