Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00014 #include <systemc>
00015 #include "during.h"
00016 #include <boost/bind.hpp>
00017 #include "utils/io-lock.h"
00018 #include "utils/atomic-variable.h"
00019 
00020 using namespace std;
00021 using namespace sc_core;
00022 
00023 SC_MODULE(A), sc_during
00024 {
00025         void compute() {
00026                 L_COUT << "// TEST-EXPECT: A 1: 0 s" << endl;
00027                 L_COUT << "A 1: " << sc_time_stamp() << endl;
00028                 during(10, SC_NS, boost::bind(&A::f, this));
00029                 L_COUT << "// TEST-EXPECT: A 2: 16 ns" << endl;
00030                 L_COUT << "A 2: " << sc_time_stamp() << endl;
00031         }
00032 
00033         void g() {
00034                 L_COUT << "// TEST-EXPECT: A.g(): 0 s" << endl;
00035                 L_COUT << "A.g(): " << sc_time_stamp() << endl;
00036                 g_done.write(true);
00037         }
00038         
00039         void tick() {
00040                 for (int i = 0; i <= 10; i++) {
00041                         while (i == 0 && !g_done.read()) {
00042                                 
00043                                 
00044                                 wait(SC_ZERO_TIME);
00045                         }
00046                         wait(2, SC_NS);
00047                 }
00048         }
00049 
00050         SC_CTOR(A) {
00051                 SC_THREAD(compute);
00052                 SC_THREAD(tick);
00053                 f_done.write(false);
00054                 g_done.write(false);
00055         }
00056 
00057         void A_wait(sc_time t) {
00058                 L_COUT << "// TEST-IGNORE: A.A_wait(): " << sc_time_stamp() << endl;
00059                 sc_module::wait(t);
00060                 L_COUT << "// TEST-IGNORE: A.A_wait(): done " << sc_time_stamp() << endl;
00061         }
00062         
00063         void f() {
00064                 L_COUT << "A.f(): " << sc_time_stamp() << endl;
00065                 sc_call(boost::bind(&A::g, this));
00066                 sc_call(boost::bind(&A::A_wait, this, sc_time(6, SC_NS)));
00067                 L_COUT << "A.f() end: " << endl; 
00068                                                  
00069                 f_done.write(1);
00070         };
00071         atomic_variable<bool> g_done, f_done;
00072 };
00073 
00074 int sc_main(int, char **)
00075 {
00076 #ifndef SC_CALL_USES_ASYNC_REQUEST_UPDATE
00077         
00078         L_COUT << "Test skipped since SC_CALL_USES_ASYNC_REQUEST_UPDATE is not used" << endl;
00079         return 0;
00080 #endif
00081         A a("a");
00082         L_COUT << "elaboration done, start simulation" << endl;
00083         {
00084                 measure_time t;
00085                 sc_start();
00086         }
00087         L_COUT << "Simulation terminated. Terminating threads" << endl;
00088         return 0;
00089 }