Search the Community
Showing results for tags 'sc_inout'.
Found 1 result
-
I am using sc_inout<struct T> to emulate a handshake flow of 'ready' and 'valid'. 'ready' flows in Responder --> Initiator and 'valid' flows in Initiator --> Responder. The setup doesnt work and causes the simulation to hang at 'Waiting'. I don't get a waveform because the simulation never completes. I suspect Can someone tell me if there are things I am overlooking: Can struct contain signals that flow in different directions? Can sc_inout<struct T> also map directly to another module with the same sc_inout<struct T>? Am I also setting the struct contents correctly? I eventually want to expand this handshake to several more signals (20+ more) which will connect directly to another module. Any alternate suggestions will also help a lot. #include <systemc.h> #include <iostream> struct hs { bool ready; bool valid; inline friend void SetValid(hs & pt, bool value) { pt.valid = value; } inline friend void SetReady(hs & pt, bool value) { pt.ready = value; } // inline friend bool GetReady(const hs& pt) { inline friend bool GetReady(const hs & pt) { return pt.ready; } inline friend bool GetValid(const hs & pt) { return pt.valid; } inline bool operator == (const hs & rhs) const { return false; } inline hs& operator = (const hs& rhs) { ready = rhs.ready; valid = rhs.valid; return *this; } inline friend void sc_trace(sc_trace_file *tf, const hs & v, const std::string& NAME ) { sc_trace(tf,v.ready, NAME + ".ready"); sc_trace(tf,v.valid, NAME + ".valid"); } inline friend ostream& operator << ( ostream& os, hs const & v ) { os << v.ready << " " << v.valid << endl; return os; } }; SC_MODULE(initiator) { sc_in <bool> clk; sc_inout<hs> handshake; void func1(); SC_CTOR(initiator) { SC_THREAD(func1); sensitive << clk; dont_initialize(); }; }; SC_MODULE(responder) { sc_in <bool> clk; sc_inout<hs> handshake; void func2(); SC_CTOR(responder) { SC_THREAD(func2) sensitive << clk; dont_initialize(); }; }; void initiator::func1() { cout << "Initator started\n"; SetValid((hs&)handshake, false); while(GetReady(handshake) == false) { cout << "Waiting" << endl; wait(clk->posedge_event()); } SetValid((hs&)handshake, true); cout << "Initator valid set to HIGH\n"; } void responder::func2() { int sleep_i; SetReady((hs&)handshake, false); cout << "Responder started\n"; for(sleep_i = 0; sleep_i < 40; sleep_i++) wait(clk->posedge_event()); SetReady((hs&)handshake, true); } The instantiation looks like this: int sc_main(int argc, char* argv[]) { sc_clock clock("clock", 10, SC_NS); sc_signal<hs, SC_MANY_WRITERS> intf; initiator init("init"); responder resp("resp"); init.handshake(intf); resp.handshake(intf); init.clk (clock); resp.clk (clock); // Open a trace file sc_trace_file *fp; fp = sc_create_vcd_trace_file("wave"); sc_trace(fp, intf, "intf"); sc_start(); sc_start(600, SC_NS); sc_close_vcd_trace_file(fp); cout << "Simulation finished @ " << sc_time_stamp() << endl; sc_stop(); return 0; };