[英]How to determine which port has invoked an sc_thread if the thread is sensitive to multiple ports in SystemC?
我有一个对端口数组敏感的线程。 在这个线程中,我想找出哪个端口触发了这个线程,以便我可以读取该端口的值?
有没有办法确定这一点?
下面给出示例代码。 判断哪个端口触发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);
}
没有标准的方法来识别是什么触发了一个特定的过程。 如果您确实需要此功能,您有多种选择可供选择。 这是一个这样的选择。
注意:我没有编译这段代码。 这只是给你一个起点。
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.