Search code examples
vhdlmodelsim

Modelsim / reading a signal value


In my simulation, I want to have RW access to signals whereever there are in the project. To get the write access, I use the "signal_force" procedure from the modelsim_lib library. But to get the read access I havn't find the corresponding function.

The reason why signal_force fit my needs is that I'm working with input text files, so I have the name and the value of the signal from a "string" or a "line" variable and I can directly give these variable to the fonction. I cannot use the "init_signal_spy" procedure because this procedure doesn't give back a value into a string but just duplicates the behavior of a signal onto an other. As my project has to be as generic as possible, I work with variables declared into procedures and I cannot link a signal onto a variable.

Thanks for your help


Solution

  • If you're comfortable writing C code it should be straightforward to achieve what you want using the VHPI, although sadly despite being part of the VHDL standard Mentor are not planning to implement it. However it will also be possible using FLI although you're locked into a proprietary interface.

    Something like this:

    procedure get_signal_value_as_string(
        vhdl_path : IN string;
        vhdl_value: OUT string);
    
    attribute FOREIGN of get_signal_value_as_string : procedure is “my_func mylib.so”;
    
    procedure get_signal_value_as_string(
        vhdl_path : IN string;
        vhdl_value: OUT string) is
    begin
        report “ERROR: foreign subprogram get_signal_value_as_string not called”;
    end;
    

    Then in C:

    #include <stdio.h>
    #include "mti.h"
    
    
    /* Convert a VHDL String array into a NULL terminated string */ 
    static char *get_string(mtiVariableIdT id)
    {
        static char buf[1000];
        mtiTypeIdT type;
        int len;
        mti_GetArrayVarValue(id, buf);
        type = mti_GetVarType(id);
        len = mti_TickLength(type);
        buf[len] = 0;
        return buf;
    }
    
    
    void my_func (
        mtiVariableIdT vhdl_path /* IN string */
        mtiVariableIdT vhdl_value /* OUT string */
        )
    {
        mtiSignalIdT sigID = mti_FindSignal(get_string(vhdl_path));
        mtiInt32T value = mti_GetSignalValue(sigID);
    
        ...
    }
    

    Plenty of example code in the FLI manual.