Sunday, October 12, 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 Unpacked Arrays 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/05/2007 12:27 PM  

I'm sharing this code which is a demo of how to manipulate a
SystemVerilog Unpacked Array using DPI. This code will work with
IUS5.83.

-----file top.v--------
module top ();

`define ARRAY_LO 4
`define ARRAY_HI 13
int xyz[`ARRAY_HI: `ARRAY_LO]  

// define import function to pass reference to 
// open array of int's.  This makes the call generic for
// any array size.
import "DPI-C" context function void doArray(inout int abc[] );

initial
begin
 // stuff the packed structure with data
   for (int i = `ARRAY_LO; i<= `ARRAY_HI ; i++)
     xyz[i] = i + 32'h7777_5555 ;  // fill up the array

  doArray( xyz );  // call dpi function, pass array formal name
   
  // allow the above dpi call to modify array contents, now print it out
  for (int i = `ARRAY_LO; i<= `ARRAY_HI ; i++)
   $display("Vlog: %d %x",i, xyz[i] );

end

endmodule

---file mydpi.c----------
#include <stdio.h>
#include <svdpi.h>
 
// Created by Todd Mackett (tmackett@cadence.com) with some help from
// Abhishek Raheja

void doArray(const svOpenArrayHandle x ) {   // pass in open handle
  io_printf("Array Handle is %x \n", x);
  io_printf("Array Pointer is %x \n", svGetArrayPtr(x) );
  io_printf("Array Left %d, Array Right %d \n", svLeft(x,1), svRight(x, 1) );
  io_printf("Array Low %d, Array High %d \n", svLow(x,1), svHigh(x, 1) );
  //io_printf("Length %d \n", svLength(x,1) ); // not implemented 6.02v138 
  // io_printf("%d \n", svDimensions(x ));  // not implemented 6.02v138

  io_printf("Size of Array in bytes %d \n", svSizeOfArray(x)  );  // returns bytes

  // Print out 1Darray contents using Array Low to High indexes
  int i;
  for (i= svLow(x,1); i <= svHigh(x,1); i++) {
  io_printf("DPI: %d is: %x \n", i,  *(int*)svGetArrElemPtr1(x, i) );
  }

  int *p;
  p = (int*)svGetArrayPtr(x);

  // the Array Index is normalized from 0 (not Vlog array index)
  //   at this point
  for (i= 0; i <= (svHigh(x,1) - svLow(x,1)); i++) {
    p[i] = 0x22221111 + i;
    io_printf("DPI2: %d %x\n", i, p[i]);
     } 
}

-----file RUN_NC (script)----
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 mydpi.so  mydpi.c  -I/`ncroot`/tools/inca/include

ncverilog +sv top.v +sv_lib=mydpi.so  +ncsimargs+"-sv_root ./" +linedebug 

----file ncverilog.log-------
ncsim> run
Array Handle is 938d8c8 
Array Pointer is 93f6a00 
Array Left 13, Array Right 4 
Array Low 4, Array High 13 
Size of Array in bytes 40 
DPI: 4 is: 77775559 
DPI: 5 is: 7777555a 
DPI: 6 is: 7777555b 
DPI: 7 is: 7777555c 
DPI: 8 is: 7777555d 
DPI: 9 is: 7777555e 
DPI: 10 is: 7777555f 
DPI: 11 is: 77775560 
DPI: 12 is: 77775561 
DPI: 13 is: 77775562 
DPI2: 0 22221111
DPI2: 1 22221112
DPI2: 2 22221113
DPI2: 3 22221114
DPI2: 4 22221115
DPI2: 5 22221116
DPI2: 6 22221117
DPI2: 7 22221118
DPI2: 8 22221119
DPI2: 9 2222111a
Vlog:           4 22221111
Vlog:           5 22221112
Vlog:           6 22221113
Vlog:           7 22221114
Vlog:           8 22221115
Vlog:           9 22221116
Vlog:          10 22221117
Vlog:          11 22221118
Vlog:          12 22221119
Vlog:          13 2222111a
ncsim: *W,RNQUIE: Simulation is complete.
ncsim> exit
TOOL:    ncverilog    05.83-p003: Exiting on Feb 05, 2007 at 11:29:36 EST  (total: 00:00:03)


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

Forums > Functional Verification > SystemVerilog > Manipulating Unpacked Arrays using DPI


ActiveForums 3.6
     
Copyright 2006 Cadence Design Systems, Inc.