|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



PARAMETERISED MACROS




How do we get rid of the typing repeating functionality which should be present at compilation level ?

You can Use generate block. But Generate will not help always.

Look at the example.
There are four modules and_gate,or_gate,xor_gate,nand_gate. They are instantiated in top modules.

Each module has 2 inputs a,b and one output c. Instance port are connected wires which are prefixed with getname to signal name.
Example

and_gate a_g (.a(and_a), .b(and_b), .c(and_c) );

and is prefexed to signal "a","b" and "c".

The following is what a novice engineer will do.


CODE:

module top();
wire and_a, or_a, xor_a, nand_a ;
wire and_b, or_b, xor_b, nand_b ;
wire and_c, or_c, xor_c, nand_c ;

and_gate a_g (.a(and_a), .b(and_b), .c(and_c) );
or_gate o_g (.a(or_a), .b(or_b), .c(or_c) );
xor_gate x_g (.a(xor_a), .b(xor_b), .c(xor_c) );
nand_gate n_g (.a(nand_a),.b(nand_b),.c(nand_c) );


endmodule


module and_gate(a,b,c);
input a,b;
output c;
endmodule

module or_gate(a,b,c);
input a,b;
output c;
endmodule

module xor_gate(a,b,c);
input a,b;
output c;
endmodule

module nand_gate(a,b,c);
input a,b;
output c;
endmodule




This looks easy to do, as there are 3 inputs only. Real time projects doesnt have this much less. One may probable spend half day to connect all the ports. Sometime later if there is change in any of the ports, then all the instances needs to be changed.

Using parameterized macros, this job can be done easily. The directive ~Qdefine creates a macro for text substitution. This directive can be used both inside and outside module definitions. After a text macro is defined, it can be used in the source description by using the (~Q) character, followed by the macro name. The compiler shall substitute the text of the macro for the string `macro_name. All compiler directives shall be considered predefined macro names; it shall be illegal to redefine a compiler directive as a macro name.

A text macro can be defined with arguments. This allows the macro to be customized for each use individually. If a one-line comment (that is, a comment specified with the characters //) is included in the text, then the comment shall not become part of the substituted text.




EXAMPLE:
~Qdefine max(a,b)((a) > (b) ? (a) : (b))
n = ~Qmax(p+q, r+s) ;



To use this for the above discussed example,

First step is declare a parameterized macro.
Second step is just use macro instance.



CODE:
`define GATE(M) M\
_gate M\
_g (.a(M\
_a), .b(M\
_b), .c(M\
_c));

`define SIG(S) and_\
S, or_\
S,xor_\
S,nand_\
S; \

module top();
wire `SIG(a)
wire `SIG(b)
wire `SIG(c)

`GATE(and)
`GATE(or)
`GATE(xor)
`GATE(nand)

endmodule



Index
Introduction
Linear Tb
File Io Tb
State Machine Based Tb
Task Based Tb
Self Checking Testbench
Verification Flow
Clock Generator
Simulation
Incremental Compilation
Store And Restore
Event Cycle Simulation
Time Scale And Precision
Stimulus Generation
System Function Random A Myth
Race Condition
Checker
Task And Function
Process Control
Disableing The Block
Watchdog
Compilation N Simulation Switchs
Debugging
About Code Coverage
Testing Stratigies
File Handling
Verilog Semaphore
Finding Testsenarious
Handling Testcase Files
Terimination
Error Injuction
Register Verification
Parameterised Macros
White Gray Black Box
Regression
Tips

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer