cverilogsystem-verilogsystem-verilog-dpiedaplayground

How to compile and run a verilog program which calls C function?


I am not trying to use a DPI call, but a simple Verilog program which internally uses its PLI to call a function written in C language. I don't know about static linking. I am using edaplayground.

Can anyone tell me which simulator should I use and switch should I pass to link both Verilog and C? Should I include the C file in the Verilog?

The sample code is as follows

// C function implementation
#include <stdio.h>  
void hello() {
   printf ("\nHello world\n");
 }

// SV function call
module sv_pli ();

  initial begin
    $hello;
     #10  $finish;
  end

 endmodule

I would like to know if there was any need to register the pli since currently the pli call hello is not detected.


Solution

  • I put your C code in a new file named test.c, and added SV-DPI to your Verilog code, removed dollar sign from $hello task to become a DPI call.

    See the simulator output and it should be the expected result from your sample code.