• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. SystemVerilog DPI in NCSim?

Stats

  • Locked Locked
  • Replies 13
  • Subscribers 64
  • Views 25018
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SystemVerilog DPI in NCSim?

archive
archive over 18 years ago

Hi all, Because it will take some time waiting download IUS583, I tried to use SystemVerilog DPI (mostly imported functions). I heard that Synopsys can simply include C file in file list with SystemVerilog file and run simulation. But Cadence NC seems need C code compile and link to a lib. I have read the NCsim document and find a switch "-sv_lib". But I cannot find a simple example. Is there any step by step tutorial about how to compile, link and run SystemVerilog DPI C file in NCsim? Best regards, Davy


Originally posted in cdnusers.org by davyzhu
  • Cancel
Parents
  • archive
    archive over 18 years ago

    Here’s the basics of creating a simple dpi file and using it from Ncsim.  In this example the simulator gets a real value from dpi and then passes it back to the dpi code.  I have numerous other examples using strings, integers...etc (tmackett@cadence.com)

     

    Here’s the Verilog file (real_test.sv) :

    module real_test ();

     

    // map the C function name to the Verilog function name

    import "DPI-C" context get_real_c = function real get_real_v ();

    import "DPI-C" context put_real_c = function void put_real_v (real x);     

     

    real pi;

     

    initial

    begin

    $display("real_test");

     

    pi = get_real_v();        // get a real number from the C code

    $display("pi = %f", pi);  // display it

     

    put_real_v(pi);           // send the real number back to C code  

      

    end

     

    endmodule

     

     

    Here’s the dpi code (real_dpi.c).  Notice there is NO c main:

     

    #include "svdpi.h"

    // since we are using math functions, include the math library

    #include         

     

    // can use io_printf() instead of printf() to put into ncsim.log file

    double get_real_c() {  // imported SV function

      // exercise DPI function - get calling scope

      printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );

      return 3.14159;

    }

     

    void put_real_c(double n) {  // imported SV function

      // exercise DPI function - get calling scope

      printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );

      printf("pi + 5.0 = %f\n", n+5.0);      

    }

     

    Here’s the script to compile everything:

    rm -r INCA_libs

    rm -r waves.shm

    rm *.so

     

    # make sure LD_LIBRARY_PATH includes . (or where the real_dpi.so lives)

    # make sure using useful gcc version like 3.2.2, 3.3.3 etc

     

    #create single header file for multiple dpi.c sources

     

    ncvlog real_test.v -sv

     

    # -dpiheader produces nothing for imported functions

    ncelab -dpiheader dpi.h worklib.real_test:module

     

    gcc -m32 -fPIC -g -shared -o real_dpi.so  real_dpi.c  -I/`ncroot`/tools/include

     

    # use the Incisive supplied gdb

    #xterm -e `ncroot`/tools/systemc/bin/gdb `ncroot`/tools/bin/ncsim &

     

    ncsim worklib.real_test:module -sv_lib real_dpi.so  -sv_root .

    Here’s the resulting log file:

     

    ncsim> run

    real_test

    Function Calling HDL scope is real_test

    pi = 3.141590

    Function Calling HDL scope is real_test

    pi + 5.0 = 8.141590

    ncsim: *W,RNQUIE: Simulation is complete.

    ncsim> exit


    Originally posted in cdnusers.org by tmackett
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • archive
    archive over 18 years ago

    Here’s the basics of creating a simple dpi file and using it from Ncsim.  In this example the simulator gets a real value from dpi and then passes it back to the dpi code.  I have numerous other examples using strings, integers...etc (tmackett@cadence.com)

     

    Here’s the Verilog file (real_test.sv) :

    module real_test ();

     

    // map the C function name to the Verilog function name

    import "DPI-C" context get_real_c = function real get_real_v ();

    import "DPI-C" context put_real_c = function void put_real_v (real x);     

     

    real pi;

     

    initial

    begin

    $display("real_test");

     

    pi = get_real_v();        // get a real number from the C code

    $display("pi = %f", pi);  // display it

     

    put_real_v(pi);           // send the real number back to C code  

      

    end

     

    endmodule

     

     

    Here’s the dpi code (real_dpi.c).  Notice there is NO c main:

     

    #include "svdpi.h"

    // since we are using math functions, include the math library

    #include         

     

    // can use io_printf() instead of printf() to put into ncsim.log file

    double get_real_c() {  // imported SV function

      // exercise DPI function - get calling scope

      printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );

      return 3.14159;

    }

     

    void put_real_c(double n) {  // imported SV function

      // exercise DPI function - get calling scope

      printf("Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );

      printf("pi + 5.0 = %f\n", n+5.0);      

    }

     

    Here’s the script to compile everything:

    rm -r INCA_libs

    rm -r waves.shm

    rm *.so

     

    # make sure LD_LIBRARY_PATH includes . (or where the real_dpi.so lives)

    # make sure using useful gcc version like 3.2.2, 3.3.3 etc

     

    #create single header file for multiple dpi.c sources

     

    ncvlog real_test.v -sv

     

    # -dpiheader produces nothing for imported functions

    ncelab -dpiheader dpi.h worklib.real_test:module

     

    gcc -m32 -fPIC -g -shared -o real_dpi.so  real_dpi.c  -I/`ncroot`/tools/include

     

    # use the Incisive supplied gdb

    #xterm -e `ncroot`/tools/systemc/bin/gdb `ncroot`/tools/bin/ncsim &

     

    ncsim worklib.real_test:module -sv_lib real_dpi.so  -sv_root .

    Here’s the resulting log file:

     

    ncsim> run

    real_test

    Function Calling HDL scope is real_test

    pi = 3.141590

    Function Calling HDL scope is real_test

    pi + 5.0 = 8.141590

    ncsim: *W,RNQUIE: Simulation is complete.

    ncsim> exit


    Originally posted in cdnusers.org by tmackett
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information