Show Menu
Cheatography

Direct Programming Interface Cheat Sheet by

Important Concepts about DPI

Few things to remember

#include <sv­dpi.h> in the C
non context functions with output­/inout instan­tiated more than once will crash
imported tasks always return a void value
context required for functions with output­/input arguments
imported functions can retun a result or be a void function
svLogi­c/s­vLo­gic­VecVal are 4 states elements
svLogi­cVecVal is 32 bits only
vectors >32 bits will require use of mda in C
SV int sized array will be passed seamlessly
Ex: int a[2][2] in SV is mapped with const int[2][2]
logic array mapped with const svLogi­cVecVal array
unpacked struct will be redefined in the C like in the SV

Pure Functions

pure functions can be removed or replaced by simulator to optimize objects, previous values computed for given argument values can be reused
pure functions have their result depending exclus­ively on their input arguments
ONLY non-void functions without output­/inout can be pure
pure functions cannot perform fileop­era­tions, read/write i/o,env variables, OS/pro­gra­m/p­roc­ess­/shared memory objects, glocal­/static variables

context methods

implicit scope for context methods
SV methods from other scopes can be called after modifying current scope
svSetScope to modify current scope
svGetScope to retrieve current scope
svGetN­ame­Fro­mScope
svGetS­cop­eFr­omName

Open Array

dimension unspec­ified a[][]
Not a dynamic array!!
limited to single packed dimension
C code access through query functions
svLeft, svRight, svLow,­svH­igh­,sv­Inc­rem­ent­,sv­Size, svDime­ntion
Access functions: svGetA­rra­yPtr/ svSize­OfA­rray/ svGetA­rrE­lem­Ptr­{,1­,2,3}
 

Datatype Mapping

SV
C input
C output­/inout
descri­ption
int
int
int*
int passed by value
reg/logic
svLogic
svLogic*
reg/logic passed by value
shortint
short int
short int*
shorti­nt(16 bits) passed by value
longint
long int
long int*
longint (64bits) passed by value
real
double
double*
real passed by value
string
char*
char**
string passed by value

Complex Data type mapping

SV
C input
C output­/inout
descri­ption
logic/­reg[]
svLogi­cVecVal
svLogi­cVe­cVal*
logic vector passed by value
bit[]
const svBitV­ecVal*
svBitV­ecVal*
bit vector assed by value
open array(­import only)
const svOpen­Arr­ayH­andle
svOpen­Arr­ayH­andle
array passed by value
chandle
const void*
void*
allows C to allocate memory

Export SV Methods

Exported methods have only the routine name
No argument or return type!!
Map SV method name if it conflicts with exisiting C name :
in C use "­ext­ern­" keyword
export "­DPI­-C" yoman = function hellosir;
extern void mornin­g(i­nt,­int*)
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Master Measures & Weights with this Cheat Sheet Cheat Sheet

          More Cheat Sheets by kamezian

          UPF basics Cheat Sheet