Is there a way to force an arbitrary wire to a certain value in a Verilog task without specifying what the wire's name is or its hierarchical path ahead of time? Preferably without having to write a ton of if-statements for each possible wire.
My goal is to be modular enough such that this task could be used to drive any wire from a testbench perspective.
Example of what I hope to do:
task force;
input value;
input [8*N-1:0] string; // Assume N is large enough
begin
force ... = value;
end
endtask
Where the three dots '...' would be the path of the wire passed in (e.g. counter0.clk0.in_enable).
Let's say I have 64 wires and I want to force some of them high. They are not on a single bus and they all have different names or hierarchical paths. In a testbench setup, I would write a C function that reads a table of the wires I care to drive to a certain value and pass each wire to this Verilog task, but how can I tell the simulator which wire to drive high without having to write out every single wire everytime in the task itself?
If I can do this, what is the correct way to do it? If I can't do this, what could you suggest instead?
There very well may be a PLI/VPI method to do this, but I'm not very experienced with it, so take this with a grain of salt. I'm also not aware of any reflection in verilog either to turn a string into a wire reference.
Having said that, what I would do is just use a scripting language to read your table, and spit out a procedurally generated .v file with a gigantic case statement.
You could have a PLI call like force_wire(int wireId), release_wire(int wireId) where the wire id could just be the row of the table or something.
In C routine you could lookup the id from the string name, and then this would call the verilog task with the id, and the id would select from the generated case statement what to force. Maybe something like:
task force
input forceVal;
input wireId
begin
case (wireId)
//AUTOGENERATED BELOW
0 : force foo.bar = forceVal;
1 : force foo.baz = forceVal;
2 : force bar.foo = forceVal;
...
endcase
end