Modelsim / reading a signal value

你说的曾经没有我的故事 提交于 2020-01-17 08:03:33

问题


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


回答1:


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.




回答2:


edited

Sorry, I win the "did not read very carefully" award for the day...

Just for completeness, I'm leaving the part of my answer that deals with signal spy (which is a proprietary ModelSim method), even though you said it wouldn't work for you:

library modelsim_lib;
use modelsim_lib.util.all;

architecture ...
  signal local_sig ...
begin

  process
  begin
    init_signal_spy("/sim/path/to/signal/internal_sig", "local_sig");

With VHDL-2008 (if you have support for it), the standard way to access signals not in scope is hierarchical/external names, and as a bonus, it does both "write" and "read". I may be a bit rusty on the nuances, but you access them like:

<<signal .sim.path.to.signal.internal_sig : std_logic>>

And you should be able to use that in place of any normal in-scope identifier, I believe. Aliases, assignments, etc.



来源:https://stackoverflow.com/questions/24491317/modelsim-reading-a-signal-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!