112855Sgabeblack@google.com#include <systemc.h> 212855Sgabeblack@google.com 312855Sgabeblack@google.comSC_MODULE(Rec) { 412855Sgabeblack@google.com sc_event_queue_port E; 512855Sgabeblack@google.com 612855Sgabeblack@google.com SC_CTOR(Rec) { 712855Sgabeblack@google.com SC_METHOD(P); 812855Sgabeblack@google.com sensitive << E; 912855Sgabeblack@google.com dont_initialize(); 1012855Sgabeblack@google.com } 1112855Sgabeblack@google.com void P() { 1212855Sgabeblack@google.com cout << sc_time_stamp() 1312855Sgabeblack@google.com << " delta " << sc_delta_count() 1412855Sgabeblack@google.com << ": P awakes\n"; 1512855Sgabeblack@google.com } 1612855Sgabeblack@google.com}; 1712855Sgabeblack@google.com 1812855Sgabeblack@google.comSC_MODULE(Sender) { 1912855Sgabeblack@google.com sc_in<bool> Clock; 2012855Sgabeblack@google.com sc_event_queue_port E; 2112855Sgabeblack@google.com 2212855Sgabeblack@google.com SC_CTOR(Sender) { 2312855Sgabeblack@google.com SC_METHOD(P); 2412855Sgabeblack@google.com sensitive << Clock.pos(); 2512855Sgabeblack@google.com dont_initialize(); 2612855Sgabeblack@google.com } 2712855Sgabeblack@google.com void P() { 2812855Sgabeblack@google.com // trigger in now (2x), now+1ns (2x) 2912855Sgabeblack@google.com E->notify( 0, SC_NS ); 3012855Sgabeblack@google.com E->notify( 0, SC_NS ); 3112855Sgabeblack@google.com E->notify( 1, SC_NS ); 3212855Sgabeblack@google.com E->notify( 1, SC_NS ); 3312855Sgabeblack@google.com } 3412855Sgabeblack@google.com}; 3512855Sgabeblack@google.com 3612855Sgabeblack@google.comSC_MODULE(xyz) { 3712855Sgabeblack@google.com SC_CTOR(xyz) { 3812855Sgabeblack@google.com SC_THREAD(P); 3912855Sgabeblack@google.com } 4012855Sgabeblack@google.com void P() { 4112855Sgabeblack@google.com wait(15, SC_NS); 4212855Sgabeblack@google.com cout << sc_time_stamp() 4312855Sgabeblack@google.com << " delta " << sc_delta_count() 4412855Sgabeblack@google.com << ": xyz awakes\n"; 4512855Sgabeblack@google.com } 4612855Sgabeblack@google.com}; 4712855Sgabeblack@google.com 4812855Sgabeblack@google.comint sc_main (int agrc, char** argv) 4912855Sgabeblack@google.com{ 5012855Sgabeblack@google.com sc_event_queue E("E"); 5112855Sgabeblack@google.com 5212855Sgabeblack@google.com Rec R("Rec"); 5312855Sgabeblack@google.com R.E(E); 5412855Sgabeblack@google.com 5512855Sgabeblack@google.com sc_clock C1 ("C1", 20, SC_NS); 5612855Sgabeblack@google.com sc_clock C2 ("C2", 40, SC_NS); 5712855Sgabeblack@google.com 5812855Sgabeblack@google.com xyz xyz_obj("xyz"); 5912855Sgabeblack@google.com 6012855Sgabeblack@google.com // Events at 0ns (2x), 1ns (2x), 20ns (2x), 21ns (2x), 40ns (2x), ... 6112855Sgabeblack@google.com Sender S1("S1"); 6212855Sgabeblack@google.com S1.Clock(C1); 6312855Sgabeblack@google.com S1.E(E); 6412855Sgabeblack@google.com 6512855Sgabeblack@google.com // Events at 0ns (2x), 1ns (2x), 40ns (2x), 41ns (2x), 80ns (2x), ... 6612855Sgabeblack@google.com Sender S2("S2"); 6712855Sgabeblack@google.com S2.Clock(C2); 6812855Sgabeblack@google.com S2.E(E); 6912855Sgabeblack@google.com 7012855Sgabeblack@google.com // Events at 3ns, 5ns (2x), 8ns 7112855Sgabeblack@google.com sc_start(10, SC_NS); 7212855Sgabeblack@google.com E.notify( 5,SC_NS ); 7312855Sgabeblack@google.com E.notify( 3,SC_NS ); 7412855Sgabeblack@google.com E.notify( 5,SC_NS ); 7512855Sgabeblack@google.com E.notify( 8,SC_NS) ; 7612855Sgabeblack@google.com 7712855Sgabeblack@google.com // Events would be at 40ns, 43ns (2x), 44ns but all are cancelled 7812855Sgabeblack@google.com sc_start(40, SC_NS); 7912855Sgabeblack@google.com E.notify( 3, SC_NS ); 8012855Sgabeblack@google.com E.notify( 3, SC_NS ); 8112855Sgabeblack@google.com E.notify( 4, SC_NS ); 8212855Sgabeblack@google.com E.notify( SC_ZERO_TIME ); 8312855Sgabeblack@google.com E.cancel_all(); 8412855Sgabeblack@google.com 8512855Sgabeblack@google.com sc_start(40, SC_NS); 8612855Sgabeblack@google.com 8712855Sgabeblack@google.com return 0; 8812855Sgabeblack@google.com} 89