A parameter is a constant value that can be declared and assigned a value at the module level. It's typically used to define constants or configure module behavior.
Delaration syntaxs:
parameter size = 16;
module dut_ip
#(
parameter ADDR_WIDTH = 16,
parameter DATA_WIDTH = 32)
(
input [ADDR-1:0] address,
input [DATA_WIDTH-1:0] data...);
Overwrite syntaxs:
// Module instantiation overwrite
dut_ip #(ADDR_WIDTH=8, DATA_WIDTH=16) inst_dut(<module port list..>);
// Using defparam
defparam inst_dut.ADDR_WIDTH = 32;
2. User-defined
The user can define a new type using typedef, as in C.
typedef int intP;
This can then be instantiated as:
intP a, b;
A type can be used before it is defined, provided it is first identified as a type by an empty typedef:
typedef foo;
foo f = 1;
typedef int foo;
Note that this does not apply to enumeration values, which must be defined before they are used.
User-defined type identifiers have the same scoping rules as data identifiers, except that hierarchical reference to type identifiers shall not be allowed. References to type identifiers defined within an interface through ports are allowed provided they are locally re-defined before being used.
interface intf_i;
typedef int data_t;
endinterface
module sub(intf_i p)
typedef p.data_t my_data_t;
my_data_t data; // type of ’data’ will be int when connected to interface above
endmodule
User-defined type names must be used for complex data types in casting, which only allows simple type names, and as type parameter values when unpacked array types are used.
Sometimes a user defined type needs to be declared before the contents of the type has been defined. This is of use with user defined types derived from enum, struct, union, and class. Support for this is provided by the following forms for typedef:
typedef enum type_declaration_identifier;
typedef struct type_declaration_identifier;
typedef union type_declaration_identifier;
typedef class type_declaration_identifier;
typedef type_declaration_identifier;
Note that, while this is useful for coupled definitions of classes, it cannot be used for coupled definitions of structures, since structures are statically declared and there is no support for pointers to structures.
The last form shows that the type of the user defined type does not have to be defined in the forward declaration.
A typedef inside a generate shall not define the actual type of a forward definition that exists outside the scope of the forward definition.