Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Passing parameter to `include file

Status
Not open for further replies.

ericew

Newbie level 4
Joined
Jul 30, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,329
Hi,

I would like to pass a parameter to the `include file. The following is my codes

`define HIER testbench.module_1.shift_register.register_bank
parameter TOTAL_ADDR_WIDTH = 43;
`include "../tb/self_check.v"
`undef HIER

`define HIER testbench.module_2.shift_register.register_bank
parameter TOTAL_ADDR_WIDTH = 59;
`include "../tb/self_check.v"
`undef HIER

`define HIER testbench.module_3.shift_register.register_bank
parameter TOTAL_ADDR_WIDTH = 67;
`include "../tb/self_check.v"
`undef HIER

This looks definitely ok but only when i do it once. But if I do it more than once, how do I pass the parameter to the `include file? Defining same parameter for several times will give compilation error.
Btw, I need to stick to the parameter name as TOTAL_ADDR_WIDTH as I would like to reuse the self_check.v.

Question:
1. Is this the correct way of doing it? (reusing the self_check.v in such way)
2. What is the proper way of passing the parameter to the `include file in the case showing above? What exactly syntax I should use?

Thanks!
 

you can pass the parameter when u instantiate the 'self_check.v'

an example:
1、module_name #( parameter1, parameter2) inst_name( port_map);

2、module_name #( .parameter_name(para_value), .parameter_name(para_value)) inst_name (port map);
 

yadog, thanks for the reply.

I have tried that. If I doing that, the `define HIER will not be able to pass into the self_check.v. From my example code you will see that the `define HIER and the TOTAL_ADDR_WIDTH are different every time when it is being `included.
 

if it donot work as i suggest ,put ur code here?
 

Hi yadog, please refer to the code below

module testbench;
......
.....

`define HIER testbench.module_1.shift_register.register_bank
self_check #(
.TOTAL_ADDR_WIDTH (43)
)
self_check_1 ( );
`undef HIER

`define HIER testbench.module_2.shift_register.register_bank
self_check #(
.TOTAL_ADDR_WIDTH (59)
)
self_check_2 ( );
`undef HIER

endmodule




module self_check #(
parameter TOTAL_ADDR_WIDTH = 43
)( );

reg [TOTAL_ADDR_WIDTH -1:0] addr;
.......
......

if (`HIER.addr != {TOTAL_ADDR_WIDTH{1'b0}})
......
....

endmodule



Please advise! Thanks!
 

the probelem may be the "`define",i think
pls refer to the following code,maybe you can revise ur code refer to it,

to be simple,u can just instantiate 'self_check' only once to see if it can work?

AS UR REFERENCE !

module tm1

#(parameter N = 4)

(

clk,rst_n,

pout

);

input clk;
input rst_n;


output[M:0] pout;



localparam M = N-1;



reg[M:0] cnt;



always @(posedge clk or negedge rst_n)

if(!rst_n) cnt <= 0;

else cnt <= cnt+1'b1;



assign pout = cnt;



endmodule


module lvdsprj(

clk,rst_n,

pout

);

input clk;

input rst_n;



output[M:0] pout;



localparam N = 5;

localparam M = N-1;



tm1 #(.N(5))

uut1(

.clk(clk),

.rst_n(rst_n),

.pout(pout)

);



endmodule
 

yadog, thanks for the example.

Indeed, the only problem is the `define that need to pass into the self_check.v.

If I use `include "self_check.v", then it will not have the problem with passing `define HIER into the self_check.v, but will have problem with passing parameter of TOTAL_ADDR_WIDTH into the self_check.v.

If I instantiate the "self_check.v", then it will not have the problem of passing parameter TOTAL_ADDR_WIDTH into the module, but will have problem with passing the `define HIER into the self_check.v.

To answer your question, I need to instantiate/`include the self_check.v for many times, that's why I need to change the `define HIER and TOTAL_ADDR_WIDTH every time I use the self_check.v.

Anyone else can help on this? I'm really running out of idea :-(
 

Your confusing confusion confuses me!

(but that's okay)

I don't really understand why things don't work for you, but forget that....

You manage to get the `define through to your "self_check.v", right?

And you don't manage to get the parameter through? Lets not focus on the parameter then on that level. Use the things that work for you at this point in time. `define works? use that!

So something like:

Code:
`define HIER testbench.module_2.shift_register.register_bank
`define TOTAL_ADDR_WIDTH_HELPER_BECAUSE_AT_LEAST_THIS_WORKS_FOR_ME 42
`include "../tb/self_check.v"
`undef TOTAL_ADDR_WIDTH_HELPER_BECAUSE_AT_LEAST_THIS_WORKS_FOR_ME
`undef HIER

And then in your self_check.v you put something like:

Code:
module self_check #(
parameter TOTAL_ADDR_WIDTH = TOTAL_ADDR_WIDTH_HELPER_BECAUSE_AT_LEAST_THIS_WORKS_FOR_ME
)( );

Not perfect, but should work.
 

Thanks mrflibble for the reply.
I am taking your suggestion as reference but then cannot apply directly. This is due to I have multiple set of `include and `define. All the `include will execute at the time and the `define name cannot be the same, every `define must have a unique name for it. But at least it works for me now.

Thanks everyone for the help :)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top