harpv
Member level 4
- Joined
- May 30, 2012
- Messages
- 73
- Helped
- 19
- Reputation
- 38
- Reaction score
- 20
- Trophy points
- 1,288
- Activity points
- 1,838
I’ve been trying to run a simulation for the following sample code.
Requirement: Based on parameters generate a define which will be used further in the design.
Observation : I can make this work if the defines are not used in the port definitions and only in the Behavioral code.
Below is the TB where I've instantiated the module and passed the parameter.
I have a feeling this could be something the language doesn't really support. But I would like to understand what exactly is happening here.
I know the parameter comes into picture only during the elaboration phase. So since the define was not there in the compile phase it wouldn't have created the port for the dut. But in that case how would have the code worked? Still confused about this.
Any help is appreciated.
Thanks.
Requirement: Based on parameters generate a define which will be used further in the design.
Observation : I can make this work if the defines are not used in the port definitions and only in the Behavioral code.
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 module #( parameter PARAM_A_PRESENT = 0) dummy ( `ifdef A_present input A, `endif input B, output C, output D ); generate begin if(PARAM_A_PRESENT == 1) begin `define A_present end end endgenerate /* ---- Behavioral code -------- */ always @ (*) begin `ifdef A_present assign wire_lgi = A; $display("This works! "); `endif end /* ------------------------------- */ endmodule
Below is the TB where I've instantiated the module and passed the parameter.
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 module tb; `define A_PRESENT 1 dummy #(.PARAM_A_PRESENT(`A_PRESENT)) dut ( .A(A), .B(B), .C(C), .D(D) ); /* Signal declaration */ /* test stimulus */ endmodule
I have a feeling this could be something the language doesn't really support. But I would like to understand what exactly is happening here.
I know the parameter comes into picture only during the elaboration phase. So since the define was not there in the compile phase it wouldn't have created the port for the dut. But in that case how would have the code worked? Still confused about this.
Any help is appreciated.
Thanks.