#include "systemc.h"

SC_MODULE(intrface) {
   sc_inslave<int> inp2;
   sc_outmaster<int> outp2;
   
   sc_event input_event;
   sc_in_clk clk;

   int data, prev;
   
   //intrface : receives data from transmit block and send the same to display block
   //This block has two threads, an input sensitive slave thread and a clock
   //sensitive autonomous thread. The input slvae thread notify an input reception
   //the autonomous thread waits for an input event to pass data to display block.
   //both the threads share the same variable, data.
   
   void inter_f0() {
      data = inp2;
      if (prev != data) {
        prev = data;
	sc_time t1(0, sc_ns);
        input_event.notify(t1);
      }
   }

   void inter_f1() {
      while(true){
         wait(input_event);
         outp2 = data;
      }
   }
    

   SC_CTOR(intrface) {
      SC_SLAVE(inter_f0, inp2);
      SC_THREAD(inter_f1);
      sensitive << clk;  //clock in PS
      prev = data = 0;
   }
};
   
