00001
00002
00003
00004
00005
00006
00014 #include <systemc>
00015 #include "during.h"
00016
00017 using namespace std;
00018 using namespace sc_core;
00019
00020 SC_MODULE(A), sc_during
00021 {
00022 int x;
00023 void producer() {
00024 L_COUT << "A: 1" << endl;
00025 wait(10, SC_NS);
00026 usleep(100000);
00027 L_COUT << "A: before x = 10, " << sc_time_stamp() << endl;
00028 x = 10;
00029 wait(15, SC_NS);
00030 usleep(100000);
00031 L_COUT << "A: before x = 25, " << sc_time_stamp() << endl;
00032 x = 20;
00033 usleep(100000);
00034 wait(100, SC_NS);
00035 usleep(100000);
00036 L_COUT << "A: before x = 300, " << sc_time_stamp() << endl;
00037 x = 300;
00038 }
00039
00040 void consumer() {
00041 during(16, SC_NS, bind_this(&A::f));
00042 assert(x == 300);
00043 L_COUT << "// TEST-EXPECT: consumer: " << 16 + 8 + 2 + 101 << " ns" << endl;
00044 L_COUT << "consumer: " << sc_time_stamp() << endl;
00045 }
00046
00047 SC_CTOR(A) {
00048 x = 0;
00049 SC_THREAD(producer);
00050 SC_THREAD(consumer);
00051 }
00052
00053 void f(void) {
00054
00055 catch_up(5, SC_NS);
00056 L_COUT << "f: at t \\in [11, 16], x == " << x << endl;
00057 assert(x == 10);
00058 L_COUT << "f: assertion OK at t=11" << endl;
00059 usleep(100000);
00060
00061
00062 assert(x == 10);
00063 extra_time(8, SC_NS);
00064 L_COUT << "f: at t \\in [11, 24], x == " << x << endl;
00065 assert(x == 10);
00066 L_COUT << "f: assertion OK at t \\in [11, 24]" << endl;
00067 extra_time(2, SC_NS);
00068 catch_up();
00069 L_COUT << "f: at t=21, x == " << x << endl;
00070 assert(x == 20);
00071 for (int i = 0; i < 50; i++)
00072 extra_time(1, SC_NS);
00073 for (int i = 0; i < 5; i++) {
00074 usleep(10000);
00075 for (int j = 0; j < 10; j++)
00076 extra_time(1, SC_NS);
00077 catch_up(50, SC_NS);
00078 }
00079 extra_time(1, SC_NS);
00080 catch_up();
00081 assert(x == 300);
00082 };
00083 };
00084
00085 int sc_main(int argc, char *argv[])
00086 {
00087 (void)argc; (void)argv;
00088 A a("a");
00089 {
00090 measure_time t;
00091 sc_start();
00092 }
00093
00094 return 0;
00095 }