Verilog 参数Parameter篇

先说Parameters的三大分类分别是,Module Parameter, Local Parameter 以及Specify Parameter。

1. Module Parameter:

   模块参数的声明语法是:

   1)parameter [ signed ] [ range ] identifier = constant_mintypmax_expression

   2)parameter {integer | real | realtime | time} identifier=constant_mintypmax_expression

   其可以放在模块头上也可以放在模块的内部,他可以通过defparameter的方式或者模块实例化的时候进行重写。

Example:

module fifo
 
#(parameter MSB=3, LSB=0, DEPTH=4)//可以被重写

 (port_list );

 item;

endmodule

module fifo

 (port_list );

 parameter MSB=3, LSB=0, DEPTH=4//可以被重写

endmodule

一旦有模块参数被写在模块头部,则出现在模块内部的模块参数被视为本地参数,不能被重写。

module fifo

 #(parameter MSB=3, LSB=0)//可以被重写

 (port_list );

parameter DEPTH=4; //不能被重写

ndmodule

在上层模块对参数重写的方式如下:

1)F1.MSB=4;F1.LSB=2;fifo F1;
2) fifo #(4,2) F1(port_list);
3) fifo #(.LSB(2), .MSB(4)) fifo(port_list);

2.Local Parameter

本地参数的声明语法和模块参数相似:

   1)localparamr [ signed ] [ range ] identifier = constant_mintypmax_expression

   2)localparam {integer|real|realtime|time} identifier=constant_mintypmax_expression

不过模块参数只能在模块内部被声明,且不能被重写。但本地参数可以引用模块参数,其值随模块参数而改变。

3.Specify Parameter

 Specify Parameter 用specparam关键字来声明,一般用在specify block中。通过 SDF annotation来重写。

你可能感兴趣的:(FPGA学习积累,Verilog,Verilog参数,Verilog语法)