• 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. Xcelium simulator is not running when vhpi application is...

Stats

  • Locked Locked
  • Replies 9
  • Subscribers 65
  • Views 10108
  • 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

Xcelium simulator is not running when vhpi application is loaded.

John Davis
John Davis over 2 years ago

I am able to load and execute a vhpi application that can read the vhdl hierarchy, and can put and get values.

The problem I am having is that when I put a value on to. say an input,  it does not propagate even though I have used the vhpiDepositPropagate or vhpiForcePropagate flags.
I know I am setting the value because I can read it back via vhpi_get_value() and because at the end of my application the simulator does run and the last values I applied are used.

It seems like my application is running but the simulator is not.  The other reason I suspect this is because if I call vhpi_control(vhpiReset) I get a warning:

WARNING: VHPI NOTRUN
vhpi_control with vhpiReset called while simulator is not running.
xcelium> run
xmsim: *W,RNQUIE: Simulation is complete.
xcelium> exit

I feel I am missing something very basic.

  • Cancel
  • John Davis
    John Davis over 2 years ago

    The following is the vhpi application followed by the vhdl test case.

    #include "vhpi_user.h"
    #include <stdio.h>

    void full_adder_tb(void)
    {
    long time;

    vhpiValueT a_set_val, a_get_val;
    vhpiValueT b_val, cin_val, s_val, cout_val;
    vhpiHandleT a_sig, b_sig, cin_sig, s_sig, cout_sig;
    vhpiHandleT root;

    vhpiValueT *a_set_val_ptr = &a_set_val;
    vhpiValueT *a_get_val_ptr = &a_get_val;
    vhpiValueT *b_val_ptr = &b_val;
    vhpiValueT *cin_val_ptr = &cin_val;
    vhpiValueT *s_val_ptr = &s_val;
    vhpiValueT *cout_val_ptr = &cout_val;

    a_set_val_ptr->format = vhpiLogicVal;
    a_get_val_ptr->format = vhpiLogicVal;
    b_val_ptr->format = vhpiLogicVal;
    cin_val_ptr->format = vhpiLogicVal;
    s_val_ptr->format = vhpiLogicVal;
    cout_val_ptr->format = vhpiLogicVal;

    a_set_val_ptr->value.enumv = vhpi0;
    b_val_ptr->value.enumv = vhpi0;
    cin_val_ptr->value.enumv = vhpi0;

    root = vhpi_handle(vhpiRootInst, NULL);
    a_sig = vhpi_handle_by_name(":A", root);
    b_sig = vhpi_handle_by_name(":B", root);
    cin_sig = vhpi_handle_by_name(":CIN", root);
    s_sig = vhpi_handle_by_name(":S", root);
    cout_sig = vhpi_handle_by_name(":COUT", root);

    vhpi_put_value(a_sig, a_set_val_ptr, vhpiDepositPropagate);
    vhpi_put_value(b_sig, b_val_ptr, vhpiDepositPropagate);
    vhpi_put_value(cin_sig, cin_val_ptr, vhpiDepositPropagate);

    vhpi_get_value(a_sig, a_get_val_ptr);
    vhpi_printf("value of A after initial setting to %d = %d\n", a_set_val_ptr->value.enumv, a_get_val_ptr->value.enumv);

    // loop a few times chaning the value on A
    for(int i = 0; i <2; i++) {
    a_set_val_ptr->value.enumv = vhpi1;
    vhpi_put_value(a_sig, a_set_val_ptr, vhpiDepositPropagate);
    vhpi_get_value(s_sig, s_val_ptr);
    vhpi_get_value(a_sig, a_get_val_ptr);
    vhpi_get_time(NULL, &time);
    vhpi_printf("Time = %d\n", time);
    vhpi_printf("value of A after setting to %d = %d\n", a_set_val_ptr->value.enumv, a_get_val_ptr->value.enumv);
    vhpi_printf("sum = %d\n", s_val_ptr->value.enumv);
    a_set_val_ptr->value.enumv = vhpi0;
    vhpi_put_value(a_sig, a_set_val_ptr, vhpiDepositPropagate);
    vhpi_get_value(s_sig, s_val_ptr);
    vhpi_get_value(a_sig, a_get_val_ptr);
    vhpi_printf("Time = %d\n", time);
    vhpi_printf("value of A after setting to %d = %d\n", a_set_val_ptr->value.enumv, a_get_val_ptr->value.enumv);
    vhpi_printf("sum = %d\n", s_val_ptr->value.enumv);
    }
    vhpi_printf("End Time = %d\n", time);
    vhpi_printf("Trying a reset at the end to confirm we are not running\n");
    vhpi_control(vhpiReset);
    }
    vhdl test file
    library IEEE;

    use IEEE.STD_LOGIC_1164.ALL;

    entity full_adder is
    Port ( A : in STD_ULOGIC;
    B : in STD_ULOGIC;
    Cin : in STD_ULOGIC;
    S : out STD_ULOGIC;
    Cout : out STD_ULOGIC);
    end full_adder;

    architecture full_adder of full_adder is
    signal a1 : std_logic;
    begin
    a1 <= a;
    S <= A1 XOR B XOR Cin ;
    Cout <= (A1 AND B) OR (Cin AND A1 ) OR (Cin AND B) ;

    end full_adder;

    And here are the results I get.
    xmsim(64): 22.09-a071: (c) Copyright 1995-2022 Cadence Design Systems, Inc.
    xmsim: *W,DLNOHV: Unable to find an 'hdl.var' file to load in.
    xmsim: *W,AMSNEWSFE: You have set the environment variable AMS_NEW_SFE. This is no longer needed as IUS 9.2 and above only works in new SFE mode.
    value of A after initial setting to 2 = 2
    Time = 0
    value of A after setting to 3 = 3
    sum = 0
    Time = 0
    value of A after setting to 2 = 2
    sum = 0
    Time = 0
    value of A after setting to 3 = 3
    sum = 0
    Time = 0
    value of A after setting to 2 = 2
    sum = 0
    End Time = 0
    Trying a reset at the end to confirm we are not running
    WARNING: VHPI NOTRUN
    vhpi_control with vhpiReset called while simulator is not running.
    xcelium> run
    xmsim: *W,RNQUIE: Simulation is complete.
    xcelium> exit
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • John Davis
    John Davis over 2 years ago

    Here is an example of the how I invoke the simulator.

    The function is loaded via -vhpiload.
    It seems to load and run and then after it exits the simulator runs.

    Is there some other way I should be calling a function to drive the simulation?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • John Davis
    John Davis over 2 years ago in reply to John Davis

    xmsim -loadvhpi /full_path_to_shared_object_directory/full_adder_tb:full_adder_tb full_adder

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 2 years ago in reply to John Davis

    Can you try adding some time-consuming VHDL code, e.g. a simple clock generator in VHDL? I'm not seeing anything in your code that would cause time to advance, so the simulator is simply exiting at time 0 because there are no events to process.

    You might also need to add the xrun option "-access +rw" so that nets can be driven from VHPI, though in this trivial case it's likely that the nets won't get optimised without this switch.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • John Davis
    John Davis over 2 years ago in reply to StephenH

    I tried to add a simple clock generator and did not see any affect but will try more if you think that is the issue after reading the following.

    I am wondering if my basic misunderstanding is this.

    I was sort of expecting to find a vhpi_evaluate_model() function, but there does not seem to be one,  so I assumed that this was automatic.

    For example I assumed this was happening.

    I assumed vhpi_put_value() was a blocking call that would return after the simulator completed updating the model with the new value applied.

    Is this my incorrect assumption?

    I was able to get some results but I had to follow this process using callbacks.

    I create a callback function that fires after a specified delay

    In that function I set the call vhpi_put_value() on a set of signals

    At the end of that function,  I register a new callback that fires after another specified delay.

    This new callback makes further updates using calls to vhpi_put_value() and also registers another callback that fires after a specified delay.

    I would the repeat this process until my test bench is done.

    Which if any of these assumptions are correct?

    1. vhpi_put_value() is blocking and waits for the for the simulator to evaluate the update.
    2. There is some other blocking function that I can call to tell the simulator to evaluate the model with the current inputs
    3. There is no blocking function and I need to use callbacks to get control back from the simulator after some event, like a delay
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 2 years ago in reply to John Davis

    To be honest, this is the first time I've ever (in 18 years doing this job) come across anyone trying to build a testbench in VHPI, so this is testing my knowledge! Most users use the VHDL or SystemVerilog language for testbench creation and only use VHPI or VPI for connecting bespoke models into an HDL testbench...

    That aside, here are some thoughts which may help you...

    • The simulator doesn't automatically wind time forwards, you need to schedule events for some future time so that time will advance. This is why I suggested adding a clock generator in the VHDL code.
    • If you did create a clock generator in VHDL, you should be able to observe time advancing (e.g. in batch mode, use the "run 10us" command to run for 10 microseconds. If you have no VHDL statements that actually cause future events, time will remain at 0 and the simulator will tell you that the simulation has finished. If your clock generator works, you should find that time advances to 10us.
    • Registering a VHPI callback on a time doesn't (I think) actually schedule an event to happen at that time, so the callback won't itself cause time to advance.
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • John Davis
    John Davis over 2 years ago in reply to StephenH

    Registering a VHPI callback on a time doesn't (I think) actually schedule an event to happen at that time, so the callback won't itself cause time to advance.

    This seems to be true,  time is advanced only if the values I set affect the model.  I still do seem to get control back even if the values I set don't affect the model.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 2 years ago in reply to John Davis

    In case you'd not found this in the docs, there is an example of driving values here.

    I see there is also a function vhpi_schedule_transaction() which schedules a future transaction; I would assume that this would have the effect of causing simulation time to advance, because it's putting an event into a future time slot in the simulator's event list. The call wouldn't advance time itself, it simply tells the simulator to schedule an event for a future time, much like a delayed assignment in HDL code.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • John Davis
    John Davis over 2 years ago in reply to StephenH

    yes I did see vhpi_schedule_transaction(),  I will try that next to see how that works.

    • 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