Skip to content

Wrapper for SystemVerilog VPI headers sv_vpi_user.h and vpi_user.h

License

Notifications You must be signed in to change notification settings

kaushalmodi/nim-svvpi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wrapper for SystemVerilog VPI headers sv_vpi_user.h and vpi_user.h

Installation

nimble install svvpi

How to get nimble?

Get Nim installation (which includes nimble) from https://nim-lang.org/install.html.

Requirements

User needs to have access to some Verilog/SystemVerilog simulator supporting VPI, like Cadence Xcelium.

Macros

vpiDefine

Defining a system task

vpiDefine task <sys task>:
  setup: # optional
    # declarations of consts that you want to be made available to all procs
  compiletf: # optional
    # body of compiletf proc
  calltf:
    # body of calltf proc
  userdata: # optional
    # string
  more: # optional
    # further code like callback proc definitions and registering those.

At minimum, only the calltf is needed. Here’s one example:

vpiDefine task hello:
  calltf:
    vpiEcho "Hello!"

Defining a system function

vpiDefine function <sys function>:
  setup: # optional
    # declarations of consts that you want to be made available to all procs
  compiletf: # optional
    # body of compiletf proc
  calltf:
    # body of calltf proc
  functype: # optional
    # Valid values: vpiIntFunc, vpiRealFunc, vpiTimeFunc, vpiSizedFunc, vpiSizedSignedFunc
    # If this is not specified, and sizetf is not specified, it defaults to vpiIntFunc.
    # If this is not specified, but sizetf is specified, it defaults to vpiSizedFunc.
  sizetf: # optional
    # integer
    # If this is specified, but functype is not specified, the latter defaults to vpiSizedFunc.
  userdata: # optional
    # string
  more: # optional
    # further code like callback proc definitions and registering those.

At minimum, only the calltf is needed. Here’s one example:

vpiDefine function hello:
  calltf:
    vpiEcho "Hello!"

Special variables

VariableDescription
<100>
userDataIf a vpiDefine has set userdata: <some string>, that string is available as this variable inside compiletf:, calltf: and sizetf:.
systfHandleThis VpiHandle variable is available inside compiletf: and calltf:.
tfNameThis string const is the task/function identifier with a $ prefix. So if you have vpiDefine task mytask, this variable is set to $mytask. This variable is available anywhere in the vpiDefine scope.

Examples

See my nim-systemverilog-vpi repo for example uses of vpiDefine.

Templates

vpiException

Calling this template raises a VpiTfError type exception.

Example usage:

if argIter == nil:
  vpiException &"{tfName} requires 1 argument; has none"

Versions tested

Cadence Xcelium
20.09-s09
OS
CentOS 7.6
Nim
1.5.1 as of 2021-04-30 Fri.