Thursday, January 08, 2009     Register | Login | Search | Contact Us
     

Many of you already received communications about the move of the Cadence user community into cadence.com. And many of you have already joined, with over 4000 registrations in the first two weeks.

The new Cadence Community enhances the ability of Cadence users to connect and collaborate. In addition to moving the community into cadence.com -- enabling single sign-on for community, Sourcelink and Cadence events -- the new site is organized around nine technology segments, giving you easy access to product information, training, forums and blogs. Some of the new features include:
  • Ability to respond to posts via e-mail
  • Technology-specific blogs
  • Latest Web 2.0 social networking capabilities
  • Public profile options
  • Private messaging
  • Friends lists
Visit the new Cadence Community today at www.cadence.com/community and join the discussions!

Registration note: Due to the scope of the enhancements and the new SSO registration system, we were not able to migrate existing cdnusers.org member accounts. So new registrations are required, but this enables a broader set of functionality we think you'll enjoy.

Forum note: Under the guidance of forum moderators, we have taken the 20+ cdnusers.org forums and consolidated them into 11 forums on the new site. Posts have been brought over so you can leverage that posting history. CDNusers forums will be set to read only starting 7/30, and cdnusers.org will be redirected to the new community on 8/4.

Best regards,
Mike and Tom

Michael A. Catrambone - Steering Committee Chairman
Distinguished Engineer
PCB/Mechanical
UTStarcom, Inc.

Tom Diederich
Cadence Community Manager
Home
Forums
Subject: Manipulating Strings Using DPI
Posting to forums is available to community members only.
Login or Register
Rate this topic:
   
Author Messages
tmackett
Posts: 34
Online: User is Offline
2/13/2007 7:40 AM  

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 <stdio.h>
#include <svdpi.h>

// to use io_printf (prints to ncsim.log)
#include <veriuser.h>

 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




Todd Mackett
Cadence Incisive
Posting to forums is available to community members only.
Login or Register

Forums > Functional Verification > SystemVerilog > Manipulating Strings Using DPI


ActiveForums 3.6
     
Copyright 2006 Cadence Design Systems, Inc.