Home > Community > Forums > Functional Verification > Manipulating Strings Using DPI


* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 Manipulating Strings Using DPI 

Last post Tue, Feb 13 2007 7:40 AM by archive. 0 replies.
Started by archive 13 Feb 2007 07:40 AM. Topic has 0 replies and 1266 views
Page 1 of 1 (1 items)
Sort Posts:
  • Tue, Feb 13 2007 7:40 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    Manipulating Strings Using DPI Reply

    I'm sharing this code. This is an example of passing strings back and forth from SystemVerilog and DPI. Some of these features aren't available until IUS6.0. ----file top.v-------- module top (); import "DPI-C" context pass_string_c= task pass_string_sv(input string a); import "DPI-C" context string_c2v_c= function string string_c2v_sv(); string some_string; // This doesnt work in IUS583, will work in IUS6.0 export "DPI-C" print_string_c = function print_string_sv; function void print_string_sv(input string aaa); $display("Exported Verilog String= %s", aaa); endfunction initial begin some_string = "pass it ON"; // enable when running IUS6.0 pass_string_sv(some_string); // pass string to C $display("Verilog: %s \n", string_c2v_sv() ); // get string from C $finish; end endmodule -----file main_task.c----- #include #include // to use io_printf (prints to ncsim.log) #include void pass_string_c(const char* a) { io_printf("DPI: %s\n", a); // now call exported function print_string_c("string passed from C"); // This wont work in IUS583 } const char* string_c2v_c(void) { io_printf("C: give up a string\n"); return "Gimme String"; } -----file: RUN_NC (script)------ rm -r INCA_libs rm *.so rm *.log rm *.h # Create .h file for Exported tasks/functions only # (imported function do NOT need .h file): ncverilog +sv top.v +ncdpiheader+dpi.h +elaborate +ncelabargs+-messages # ncvlog -sv top.v -mess # ncelab top -sv -dpiheader dpi.h -mess gcc -fPIC -shared -o main_task.so main_task.c -I/`ncroot`/tools/inca/include ncverilog +sv top.v +sv_lib=main_task.so +access+r +ncsimargs+"-sv_root ./" ----file: ncverilog.log (IUS6.02)----------- ncsim> run DPI: pass it ON Exported Verilog String= string passed from C Verilog: C: give up a string Gimme String Simulation complete via $finish(1) at time 0 FS + 0 ./top.v:22 $finish; ncsim> exit

    Originally posted in cdnusers.org by tmackett
    • Post Points: 0
Page 1 of 1 (1 items)
Sort Posts:
Started by archive at 13 Feb 2007 07:40 AM. Topic has 0 replies.