sync_reset.cpp revision 12855:588919e0e4aa
1#define SC_INCLUDE_DYNAMIC_PROCESSES
2
3#include <systemc>
4
5using namespace sc_core;
6using std::cout;
7using std::endl;
8
9struct M: sc_module
10{
11  M(sc_module_name _name)
12  {
13    SC_THREAD(ticker);
14    SC_THREAD(calling);
15    SC_THREAD(target);
16      t = sc_get_current_process_handle();
17  }
18
19  sc_process_handle t;
20  sc_event ev;
21
22  void ticker()
23  {
24    for (;;)
25    {
26      wait(10, SC_NS);
27      ev.notify();
28    }
29  }
30
31  void calling()
32  {
33    wait(15, SC_NS);
34    // Target runs at time 10 NS due to notification
35
36    t.sync_reset_on();
37    // Target does not run at time 15 NS
38
39    wait(10, SC_NS);
40    // Target is reset at time 20 NS due to notification
41
42    wait(10, SC_NS);
43    // Target is reset again at time 30 NS due to notification
44
45    t.sync_reset_off();
46    // Target does not run at time 35 NS
47
48    wait(10, SC_NS);
49    // Target runs at time 40 NS due to notification
50
51    sc_stop();
52  }
53
54  void target()
55  {
56    cout << "Target called/reset at " << sc_time_stamp() << endl;
57    for (;;)
58    {
59      wait(ev);
60      cout << "Target awoke at " << sc_time_stamp() << endl;
61    }
62  }
63
64  SC_HAS_PROCESS(M);
65};
66
67int sc_main(int argc, char* argv[])
68{
69  M m("m");
70
71  sc_start();
72
73  return 0;
74}
75
76