• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Using DPI to get the current value of a signal

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 65
  • Views 16017
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using DPI to get the current value of a signal

sdav
sdav over 15 years ago
I'm using a C++ interface with SystemVerilog DPI to drive my Verilog simulation. From C++ I'd like to call a function which returns the current value of a Verilog signal. Ideally this function would take a string as an input parameter (e.g. "testbench.u1.u2.dout") and then return the reg value of the signal. I'm just not sure how to implement this in Verilog. $display, $monitor, $strobe all display to stdout (I know there are "file" versions of these system tasks, too). The TCL command "value" seems ideal, but how can I access the returned data in Verilog and then return it to C++? Anyway, I'm posting here because I've thought about this for a while and can't come up with an elegant way to do it. But, I'm convinced that there is a way and I'm not seeing it. Thanks, Shirley
  • Cancel
  • StephenH
    StephenH over 15 years ago

    Hi Shirley.

    I think you need to use some VPI functions to convert the hierarchical path string into a VPI handle to the object (signal). Then there are VPI functions that let you get/set the value of that object.

    It's perfectly OK to call VPI funtions from the DPI, you "just" need to figure out the right functions to call. I was looking for a good worked example but couldn't spot on immediately, sorry. However I suggest you take a look at the examples that ship with IUS, in IUS92/tools.lnx86/examples/vpi/*.

    The NCSim docs also have a whole bunch of info on DPI and VPI, including tutorials and "engineering notebooks" (app notes to use mere mortals) which give a nice cook-book approach to explaining the system.

    Hope this helps.

    Steve.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sdav
    sdav over 15 years ago

    Thank you for the quick response and the pointer to VPI -- I'll take a look at it.  I have used the tutorials and engineering notebooks for DPI, but not for VPI.  I am using vpi_printf already, so it doesn't seem too foreign a concept to use more VPI functions in my environment.

    Shirley
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sdav
    sdav over 15 years ago

    I was eventually able to get this to work using VPI.  Here's some of the code from the C++ side:

    # include "vpi_user.h"

    vpiHandle net;              // name of signal to probe
    s_vpi_value cur_val;  // current value of the signal


    net = vpi_handle_by_name("testbench.u1.u2.dout", NULL);  // set the name of the signal you are probing
    vector_size = vpi_get(vpiSize, net);    // returns the size of the signal you are probing
    cur_val.format = vpiVectorVal;             // set the format you want for the returned data
    vpi_get_value(net, &cur_val);              // probe the signal and return the value into cur_val structure

    // The value of the probed net is available in:

    cur_val.value.vector[0].aval   // bits [31:0] of the probed signal
    cur_val.value.vector[0].bval
    cur_val.value.vector[1].aval   // bits [63:32] of the probed signal
    cur_val.value.vector[1].bval
    ... and so on, depending on the vector_size of the net you probed
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information