dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / fsm / scd_stm_time_req.cpp
diff --git a/dol/src/dol/visitor/hdsd/scd/fsm/scd_stm_time_req.cpp b/dol/src/dol/visitor/hdsd/scd/fsm/scd_stm_time_req.cpp
new file mode 100644 (file)
index 0000000..fb96b26
--- /dev/null
@@ -0,0 +1,64 @@
+#include "fsm/scd_stm_time_req.h"
+
+#include "scd_logging.h"
+#include "scd_exception.h"
+#include "scd_cont_man_master.h"
+
+
+void scd_stm_time_req::set_busy()
+{
+    _send_time_nack();
+    _fsm.load_state();
+}
+
+
+void scd_stm_time_req::process()
+{
+    if (!_check_slaves())
+            return;
+
+    std::list<scd_cont_slave_wrapper*>::iterator iter;
+    sc_core::sc_time min_step = _time_step;
+
+    for (iter = _slaves.begin(); iter != _slaves.end(); iter++)
+    {
+        if ( !(*iter)->time_req() && !(*iter)->time_ack() )
+        {
+            // received time_nack from this slave
+            _send_time_nack();
+            _fsm.load_state();
+            return;
+        }
+        else if ( !(*iter)->time_ack() )
+        {
+            // this slave did not respond yet
+            return;
+        }
+        else
+        {
+            // received time_ack => search the smallest step
+            sc_core::sc_time time_slave = (*iter)->get_time_step();
+            if (min_step == sc_core::SC_ZERO_TIME)
+                min_step = time_slave;
+            else if (min_step > time_slave &&
+                    time_slave != sc_core::SC_ZERO_TIME)
+                min_step = time_slave;
+        }
+    }
+
+    // all slaves acknkowledged
+    _time_step = min_step;
+    for (iter = _slaves.begin(); iter != _slaves.end(); iter++)
+        (*iter)->send_time(min_step);
+
+    _fsm.set_state(_st_time);
+}
+
+
+void scd_stm_time_req::_send_time_nack()
+{
+    std::list<scd_cont_slave_wrapper*>::iterator iter;
+
+    for (iter = _slaves.begin(); iter != _slaves.end(); iter++)
+        (*iter)->send_time_nack();
+}