Jump to content
wasim6691

Notify() Using Event Between Two modules

Recommended Posts

//  MODULE 1  WRITING THE OUT1 to Value 1

SC_MODULE(MODULE_1){

public:
    //-------------PORTS DECLARATIONS---------------------------
            sc_in<bool> reset;
            sc_out<bool>  out1  ;  

     // ---event

     sc_event   sig_written;

     public:

      void Process();

public:
    SC_CTOR(MODULE_1){

        SC_METHOD(Process);
        sensitive << reset;

}  

void Process() {

if (reset == 1)

    out1.write(1);

     sig_written.notify();    // to make it runnable within the execution phase and not in the Next delta cycle

}

};

 

//----------------------------------------------------------------------------------------------------------

//  MODULE 2  READING OUTPUT VALUE FROM MODULE_1

SC_MODULE(MODULE_2){

public:
    //-------------PORTS DECLARATIONS---------------------------
            sc_in<bool>  input1;
            sc_out<bool>  out2  ;  

     public:

// HOW TO DEFINE EVENT HERE ?

// PROCESS

void Process();

public:
    SC_CTOR(MODULE_2){

        SC_METHOD(Process);
        sensitive << input1; 

}  

void Process() {

bool x;

x = input1.read();   // reading the Output Value from Module 1. I want to read here 1 because of output

// written in the MODULE_1 is 1

if (x == 1)

    out2.write(1);

   // HOW TO USE EVENT HERE ?   SHARED EVENT

}

};

Hi  I am outputting One value from MODULE 1 and notifying it through sig_written.notify() event to make it detectable in the same execution phase and not in the next delta cycle. Can You tell me How to use the event in the MODULE_2 to detect this event and read the value immediately without going into next delta cycle. thanks  

Share this post


Link to post
Share on other sites

Do you want to write something like this ?:

Producer process:

out1.write(42);
sig_written.notify();

Consumer process:

wait(sig_written);
out1.read();

In that case you will read current value of signal, not new one (42).

If you want to transfer data immediately between processes, use plain C++ variables. 

 

Share this post


Link to post
Share on other sites

Yes I want to read the new ( 42)  value in the MODULE_2. Can You help me how to modify the above code to read the value immediately. If I use wait()  then console keeps on running towards other processes or the next module which i do not want. thanks

 

Share this post


Link to post
Share on other sites
10 minutes ago, wasim6691 said:

And The MODULE-1(producer) and MODULE-2(consumer) are different Classes in my code. they are not the processes within one MODULE

Use pointers, references, or write your sc_interface and then use ports/exports.

 

Example with references:

#include <systemc.h>

struct recv_mod : sc_module {

    sc_event &write_event;
    sc_event &recv_event;
    int      &value ;

    recv_mod(::sc_core::sc_module_name, sc_event &write_event, sc_event &recv_event, int &value )
        : write_event(write_event), recv_event(recv_event), value(value)
    {
        SC_HAS_PROCESS(recv_mod);
        SC_THREAD(receiver_thread);
    }

    void receiver_thread() {
        while (1) {
            wait(write_event);
            cout << "Read " << value << " at delta: " << sc_delta_count() << endl;
            recv_event.notify();
        }
    }
};

struct trans_mod : sc_module {

    SC_CTOR(trans_mod) {
        SC_THREAD(transmitter_thread);
    }

    sc_event write_event{"write_event"};
    sc_event recv_event{"recv_event"};
    int value = 0;

    recv_mod recv{"recv", write_event, recv_event, value};

    void transmitter_thread() {
        wait(SC_ZERO_TIME); // need to wait to guarantee that reciever is waiting for event

        for (int i = 0; i < 4; i++) {
            cout << "Write " << i << " at delta: " << sc_delta_count() << endl;
            value = i;
            write_event.notify();
            wait(recv_event);
        }
        sc_stop();
    }
    
};


int sc_main (int argc, char** argv) {
    trans_mod t{"t"};
    sc_start();
}

Simulation result:

Write 0 at delta: 1
Read 0 at delta: 1
Write 1 at delta: 1
Read 1 at delta: 1
Write 2 at delta: 1
Read 2 at delta: 1
Write 3 at delta: 1
Read 3 at delta: 1

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×