[英]How to determine which port has invoked an sc_thread if the thread is sensitive to multiple ports in SystemC?
I have a thread which is sensitive to an array of ports.我有一个对端口数组敏感的线程。 In this thread I want to find out which port had triggered this thread so that i can read the value of that port?在这个线程中,我想找出哪个端口触发了这个线程,以便我可以读取该端口的值?
Is there a way to determine this?有没有办法确定这一点?
Example code given below.下面给出示例代码。 What should be the logic to determine which port triggered thread_name()?判断哪个端口触发thread_name()的逻辑应该是什么?
tb.h ----------------
class tb :: public sc_core :: sc_module
{
sc_core :: sc_out<uint32_t> port_name[10];
void thread_name();
};
tb.cpp --------------
tb :: tb (...)
{
SC_THREAD(thread_name);
for(int i=0;i<10;i++)
sensitive >> port[i];
dont_initialize();
}
void tb::thread_name()
{
// print data of the port that triggered this thread
// in this case, only port[2] should be read and data 5 should be printed
}
int main()
{
tb tb("");
tb->port_name[2]->write(5);
}
There is no standard way of identifying what triggered a particular process.没有标准的方法来识别是什么触发了一个特定的过程。 You have several alternatives to choose from if you do need this ability.如果您确实需要此功能,您有多种选择可供选择。 Here is one such alternative.这是一个这样的选择。
Note: I did not compile this code.注意:我没有编译这段代码。 This is just to give you a starting point.这只是给你一个起点。
tb::tb(...) {
for(int i = 0; i != 10; ++i) {
// Options for a thread statically sensitive to ports[i]. According to the
// standard, "the application is not obliged to keep the sc_spawn_options
// object valid after the return from function sc_spawn"
sc_core::sc_spawn_options opts;
opts.dont_initialize();
opts.set_sensitivity(&ports[i]);
// We bind the current value of i to a call to thread_name function,
// and create a spawned process out of this call.
sc_core::sc_spawn(std::bind(thread_name, this, i), "", &opts);
}
}
void tb::thread_name(std::size_t _port_id) {
// _port_id tells you which port spawned an instance of this thread.
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.