简体   繁体   中英

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()?

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.
    // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM