Jump to content

sc_fifo_in inputs are not working with sc_sensitive


Recommended Posts

Hi,

 

I am a beginner in SystemC. I am trying to create a small testcase to add two numbers. The inputs are defined as sc_fifo_in, and these are added to the sensitivity list for SC_THREAD. SC_THREAD process is somehow not responding to the sensitivity list

Is there any way I can define the two sc_fifo_in signals (A_val_in and B_val_in) the sensitivity list of do_sum process?

 

class sum : public sc_core::sc_module
{
public:
    SC_HAS_PROCESS(sum);
    sc_core::sc_fifo_in<sc_int<10>> A_val_in;
    sc_core::sc_fifo_in<sc_int<10>> B_val_in;
    sc_core::sc_fifo_out<sc_int<10>> S_val_out;
    sc_event sum_finished;
    sc_event input_event;


    void do_sum();
    sum (const char* name) : sc_core::sc_module(name) {
        std::cout << "DBG: Inside constructor\n";
        SC_THREAD(do_sum);
            sensitive << A_val_in << B_val_in;
    }   

};
 

void sum::do_sum() {
    while(true) {
        wait();
    std::cout << "DBG: Inside do_sum\n";
    unsigned int Sint = A_val_in.read() + B_val_in.read();
    S_val_out.write(Sint);
    std::cout << "DBG: Inside do_sum: Sum = " << Sint << std::endl;
    sum_finished.notify(SC_ZERO_TIME);
    }

}

 

Please let me know if you need any more information.

 

Thanks in advance,

Nithin

Link to post
Share on other sites

Your do_sum() is sensistive to A_val_in and B_val_in which means wati() finishes as soon as A_val_in or B_val_in gets data. Then you read the data using blocking read. This means the function waits until data in the fifo is available anyways. Your loop could be simplified as

 void sum::do_sum() {
    while(true) {
    	unsigned int Sint = A_val_in.read() + B_val_in.read();
      	S_val_out.write(Sint);
      	sum_finished.notify(SC_ZERO_TIME);
    }
} 

and you don't need a sensitivity list at all. This can be done also in a non-blocking way:

void sum::do_sum() {
    unsigned int A_val=0, B_val=0;
    while(true) {
        wait(A_val_in.data_written_event() && B_val_in.data_written_event()); // this creates an sc_event_and_list
        if(A_val_in.nb_read(A_val) && B_val_in.nb_read(B_val)){
            unsigned int Sint = A_val + B_val;
            S_val_out.write(Sint);
            sum_finished.notify(SC_ZERO_TIME);
        }
    }
} 

You may also remove the sum_finished event since fifos provide a data_written event (part of the sc_fifo_nonblocking_in_if).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...