SystemVerilog DPI Tutorial

[The C-Layer]

Previous: Examples of passing arguments

C Side Library Functions

A number of library functions are available that help you get information about the SystemVerilog side from the C side. Some of these library functions are also useful in controlling the SystemVerilog side of the interface. Some of these functions are described below.

Library functions related to scope

Function: svGetScope
Use: Gets the current SystemVerilog scope of an imported function.
Function prototype: svScope svGetScope();

Function: svSetScope
Use: Sets the current SystemVerilog scope of an imported function.
Function prototype: svScope svSetScope(const svScope);

Function: svGetNameFromScope
Use: Gets the fully qualified current SystemVerilog path of an imported function from a scope handle.
Function prototype: const char* svGetNameFromScope(const svScope);

Function: svGetScopeFromName
Use: Sets the current SystemVerilog scope of an imported function.
Function prototype: svScope svGetScopeFromName(const char*);

Library functions related to packed arrays

Function: svGetSelectBit
Use: Reads a bit-select index i of an array reference svBitPackedArrRef of type Bit.
Function prototype: svBit svGetSelectBit(const svBitPackedArrRef s, int i);

Function: svPutSelectBit
Use: Writes the value of a bit s to a bit-select index i of an array reference svBitPackedArrRef of type Bit.
Function prototype: void svPetSelectBit(svBitPackedArrRef d, int i, svBit s);

Function: svGetSelectLogic
Use: Reads a bit-select index i of an array reference svLogicPackedArrRef of type Logic.
Function prototype: svLogic svGetSelectLogic(const svLogicPackedArrRef s, int i);

Function: svPutSelectLogic
Use: Writes the value of a bit s to a bit-select index i of an array reference svLogicPackedArrRef of type Logic.
Function prototype: void svPutSelectLogic(svLogicPackedArrRef d, int i, svLogic s);

Function: svSizeOfArray
Use: Returns the total size of an array in bytes or 0 if the array is not in C layout.
Function prototype: int svSizeOfArray(const svOpenArrayHandle);

Function: svGetArrElemPtr
Use: Returns a pointer to an element [index1][index2]... of an array or NULL if the array is not in C layout. The array does not have to be packed.
Function prototype: void *svGetArrElemPtr(const svOpenArrayHandle, int index1, int index2,...);

Function: svGetArrElemPtr
Use: Returns a pointer to an element [index1][index2]... of an array or NULL if the array is not in C layout.
Function prototype: void *svGetArrElemPtr(const svOpenArrayHandle, int index1, int index2,...);

We wrap up our DPI tutorial with this. One word of caution: although this tutorial has covered materials that will help you kick start your DPI knowledge, this is only tip of the iceberg. DPI provides more facilities in addition to what have been discissed here. You are encouraged to explore those advanced topics from a SystemVerilog text or the Language Reference Manual.

Previous: Examples of passing arguments

Share/Save/Bookmark



Verification Management
Join Verification Management Group


Talk UVM with Friends
Shop Amazon - Contract Cell Phones & Service Plans


Fun Stuffs!