Is it possible to have multiple instances of a module which contain DPI’s. And from each of the instance can I import DPI with a different definition?

Is it possible to have multiple instances of a module which contain DPI’s. And from each of the instance can I import DPI with a different definition?

In reply to anuragre:

No, but you can import the DPI routine with context, or pass a unique argument value through each instance, and branch based on that information inside your C code.

In reply to dave_59:

In reply to anuragre:
No, but you can import the DPI routine with context, or pass a unique argument value through each instance, and branch based on that information inside your C code.

Could you please give me an example if you have or point me to some doc.

Thanks & Regards
Anurag Reddy.

In reply to anuragre:

module containing_dpi #(int Inst)();

import "DPI-C" context function void C_code(int Inst);

initial C_code(Inst);

endmodule
module top;
  containting_dpi #(1) ();
  containting_dpi #(2) ();
endmodule
void C_code(int Inst) {
switch (Inst) {
  case 1: C_impementation1(); break;
  case 2: C_impementation2(); break;
}
}

You could also use pass a sting with the scope name so you don’t have to provide a unique parameter override

module containing_dpi();

import "DPI-C" context function void C_code(string Instname);

initial C_code($sformatf("%m"));

endmodule
module top;
  containting_dpi  ();
  containting_dpi  ();
endmodule
void C_code(char *Inst) {
// I'll leave this for you to figure out to build a function pointer table keyed on string names.
}
}

And it’s also possible to not pass anything and have your C code use the DPI C utility routine svGetScope()

In reply to dave_59:

In reply to anuragre:

module containing_dpi #(int Inst)();
import "DPI-C" context function void C_code(int Inst);
initial C_code(Inst);
endmodule
module top;
containting_dpi #(1) ();
containting_dpi #(2) ();
endmodule
void C_code(int Inst) {
switch (Inst) {
case 1: C_impementation1(); break;
case 2: C_impementation2(); break;
}
}

You could also use pass a sting with the scope name so you don’t have to provide a unique parameter override

module containing_dpi();
import "DPI-C" context function void C_code(string Instname);
initial C_code($sformatf("%m"));
endmodule
module top;
containting_dpi  ();
containting_dpi  ();
endmodule
void C_code(char *Inst) {
// I'll leave this for you to figure out to build a function pointer table keyed on string names.
}
}

And it’s also possible to not pass anything and have your C code use the DPI C utility routine svGetScope()

Thanks Dave. This example helps me.