1
+ #include < iostream>
2
+ #include " systemc.h"
3
+ SC_MODULE (turn_of_events) {
4
+ // Constructor
5
+ SC_CTOR (turn_of_events) {
6
+ SC_THREAD (turn_knob_thread);
7
+ SC_THREAD (stop_signal_thread);
8
+ }
9
+ sc_event signal_stop, signals_off;
10
+ sc_event stop_indicator_on, stop_indicator_off;
11
+ void turn_knob_thread (); // stimulus process
12
+ void stop_signal_thread (); // indicator process
13
+ };// endclass turn_of_events
14
+ void turn_of_events::turn_knob_thread () {
15
+ // This process provides stimulus using stdin
16
+ enum directions {STOP=' S' , OFF=' F' };
17
+ char direction; // Selects appropriate indicator
18
+ bool did_stop = false ;
19
+ // allow other threads to get into waiting state
20
+ wait (SC_ZERO_TIME);
21
+ for (;;) {
22
+ // Sit in an infinite loop awaiting keyboard
23
+ // or STDIN input to drive the stimulus…
24
+ std::cout << " Signal command: " ;
25
+ std::cin >> direction;
26
+ switch (direction) {
27
+ case STOP:
28
+ // Make sure the other signals are off
29
+ signals_off.notify ();
30
+ signal_stop.notify (); // Turn stop light on
31
+ // Wait for acknowledgement of indicator
32
+ wait (stop_indicator_on);
33
+ did_stop = true ;
34
+ break ;
35
+ case OFF:
36
+ // Make the other signals are off
37
+ signals_off.notify () ;
38
+ if (did_stop) wait (stop_indicator_off) ;
39
+ did_stop = false ;
40
+ break ;
41
+ }// endswitch
42
+ }// endforever
43
+ }// end turn_knob_thread()
44
+ int sc_main (int i,char * c[]){
45
+ turn_of_events obj (" 2" );
46
+ sc_start ();
47
+ return 0 ;
48
+ }
0 commit comments