Friday, November 21, 2008     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 C Global Variables 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
6/04/2007 3:07 PM  

I'm sharing this code as an example of how two different DPI calls (calls to same function in two different parts of the hierarchy) can both manipulate a C global variable.<br>

----file: my_dpi.c----
#include "stdio.h"
#include "svdpi.h"

// any function or variable declared 'static' - which is outside the
// scope of any DPI function, is a global func/var.
static int my_global_int = 4;

// FYI - VPI function io_printf() will print to ncsim.log file

// This function can be called from any Verilog Hierarchy
// and manipulate my_global_in

int c_func () {  
  my_global_int++;  // increment the global variable via DPI call
  io_printf("C: Function Calling HDL scope is %s \n", svGetNameFromScope(svGetScope() ) );

  io_printf("C: increment my_global_in to %d \n", my_global_int);
  return my_global_int;
}
---------------
----file: test_dut.sv
// this example developed to test if DPI can manipulate 
// a C global variable from different hierarchies

module dut ();

import "DPI-C" context c_func = function int sv_func ();
int b;

initial
 begin
 b = sv_func();
 $display("Verilog: %m %d", b);
 end

endmodule
// ------------------------

module test();
import "DPI-C" context c_func = function int sv_func ();
int b;

initial
 begin
 b = sv_func();
 $display("Verilog: %m %d", b);
 end

endmodule
// ------------------------

module top();

test U1();
dut  U2();

endmodule
----------------

ncsim: 05.83-s006: (c) Copyright 1995-2007 Cadence Design Systems, Inc.
ncsim> run
C: Function Calling HDL scope is top.U1 
C: increment my_global_in to 5 
Verilog: top.U1           5
C: Function Calling HDL scope is top.U2 
C: increment my_global_in to 6 
Verilog: top.U2           6
ncsim: *W,RNQUIE: Simulation is complete.
ncsim> exit

-------script: -------------

ncvlog -sv -linedebug test_dut.sv
ncelab top

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

ncsim top -sv_lib ./my_dpi.so 


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

Forums > Functional Verification > SystemVerilog > Manipulating C Global Variables Using DPI


ActiveForums 3.6
     
Copyright 2006 Cadence Design Systems, Inc.