4

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.

11
  • 1
    Verilog is no programming language. Commented Aug 16, 2015 at 3:05
  • 3
    @Olaf: Verilog is a simulation language, and functions can be called during simulation just like in a programming language. It's not a weird question if you remember that Verilog isn't just a hardware description language. Commented Aug 16, 2015 at 6:08
  • @Mehrdad: It is a hardware description language, like VHDL. The functions still describe the hardware. OP might refer to System-Verilog (as the tag indicated, but that is not Verilog as his headline and text states. Anyway, the question is clearly OT. Commented Aug 16, 2015 at 13:33
  • 4
    @Olaf: it is both a hardware description language and a language to aid simulating the described hardware. Only a portion of the language is used to describe hardware that can actually be synthesized. The rest is used for simulation and can contain calls to PLI, which can be written in C. Commented Aug 16, 2015 at 14:18
  • 2
    Just the opposite - DPI runs much faster than the equivalent VPI. And if you stick with passing C compatible types (int byte and arrays of these) it could be orders of magnitude faster. Commented Aug 19, 2015 at 21:00

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.