In this article I will explain the problem of setting multiple interface instances to their respective agents within your verification environment.
Say you had this kind of a scenario:
You have multiple agents where you wish to set multiple interface instances of the same interface from your testbench file. This is the solution I found that helped me.
First, from your testbench file, set the interfaces in the manner shown below. You see that I instantiated and set all the necessary interfaces for master and slave agents within a for loop. The trick is to set them with a different name using the $sformatf macro to the configuration db that can be easily replicated when getting them. The code is as follows:
Now, when you wish to get the interface instances, you would also use the $sformatf macro but with the get function. You get the interfaces within a queue in your environment and then send pointers to all agents/drives/monitors that need a handle on that particular interface. The code is shown below:
You would get the interface instance within a queue and have them all individually stacked up before you do any other handling. The key is in setting and getting with the $sformatf macro and “i” counters that format the string differently distinguishing the instances from one another.
See how to solve this in the video below: