-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsensitivity.cpp
More file actions
47 lines (44 loc) · 1.34 KB
/
sensitivity.cpp
File metadata and controls
47 lines (44 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Learn with Examples, 2020, MIT license
#include <systemc>
using namespace sc_core;
SC_MODULE(SENSITIVITY) {
sc_event e1, e2; // events for inter-process triggering
SC_CTOR(SENSITIVITY) {
SC_THREAD(trigger_1); // register processes
SC_THREAD(trigger_2);
SC_THREAD(catch_1or2_dyn);
SC_THREAD(catch_1or2_static);
sensitive << e1 << e2; // static sensitivity for the preceeding process, can only "OR" the triggers
}
void trigger_1() {
wait(SC_ZERO_TIME); // delay trigger by a delta cycle, make sure catcher is ready
while (true) {
e1.notify(); // trigger e1
wait(2, SC_SEC); // dynamic sensitivity, re-trigger after 2 s
}
}
void trigger_2() { // delay trigger by a delta cycle
wait(SC_ZERO_TIME);
while (true) {
e2.notify(); // trigger e2
wait(3, SC_SEC); // dynamic sensitivity, re-trigger after 3 s
}
}
void catch_1or2_dyn() {
while (true) {
wait(e1 | e2); // dynamic sensitivity
std::cout << "Dynamic sensitivty: e1 or e2 @ " << sc_time_stamp() << std::endl;
}
}
void catch_1or2_static(void) {
while (true) {
wait(); // static sensitivity
std::cout << "Static sensitivity: e1 or e2 @ " << sc_time_stamp() << std::endl;
}
}
};
int sc_main(int, char*[]) {
SENSITIVITY sensitivity("sensitivity");
sc_start(7, SC_SEC);
return 0;
}