#include "systemc.h"

SC_MODULE(display){
   
   sc_inslave<int> outp1;
   
   sc_event input_event;
   sc_in_clk clk;
   
   int disdata, disprev;
   
   //display: receives data from interface block and display the same 
   //This block has two threads, an input sensitive thread and a clock sensitive 
   //thread. The input slave thread notify an event when an input is received.
   //the clock sensitive threads, wait with dynamic sensitivity to the input 
   //event, and displays the data received. Both threads share the same data 
   //variable.
   
   void displ_f() {
      disdata = outp1;
      if(disprev != disdata){
         disprev = disdata;
	 sc_time t1(0, sc_ns);
         input_event.notify(t1);
      }
   }
   
   void disp_f1(){
      while(true){
         wait(input_event);
         cout << "display: data received = " << disdata 
	      << "  at time = " << sc_time_stamp() << endl;
      }
   }
   
   SC_CTOR(display) {
      SC_SLAVE(displ_f,outp1);
      SC_THREAD(disp_f1);
      sensitive << clk;  //clock in FS
      disprev = disdata = 0;
   }
};
