master FSM enables slave FSM
authorMartin Troxler <martin.troxler@komaxgroup.com>
Tue, 15 Dec 2009 10:59:07 +0100
changeset 1601 a784812c787f
parent 1600 e36c92cf58a9
child 1602 2f6683e9181f
child 1603 8e528f806dc5
master FSM enables slave FSM
slave FSM should not be active when master is scanning or configuring the slaves
master/fsm_master.c
master/fsm_slave.c
master/fsm_slave.h
--- a/master/fsm_master.c	Tue Dec 15 10:55:36 2009 +0100
+++ b/master/fsm_master.c	Tue Dec 15 10:59:07 2009 +0100
@@ -471,7 +471,14 @@
     if (ec_fsm_master_action_process_sdo(fsm))
         return;
 
-    // check, if slaves have an SDO dictionary to read out.
+	// enable processing of SDO/FOE requests
+	for (slave = master->slaves;
+			slave < master->slaves + master->slave_count;
+			slave++) {
+		ec_fsm_slave_ready(&slave->fsm);
+	}
+
+	// check, if slaves have an SDO dictionary to read out.
     for (slave = master->slaves;
             slave < master->slaves + master->slave_count;
             slave++) {
--- a/master/fsm_slave.c	Tue Dec 15 10:55:36 2009 +0100
+++ b/master/fsm_slave.c	Tue Dec 15 10:59:07 2009 +0100
@@ -42,6 +42,7 @@
 /*****************************************************************************/
 
 void ec_fsm_slave_state_idle(ec_fsm_slave_t *);
+void ec_fsm_slave_state_ready(ec_fsm_slave_t *);
 int ec_fsm_slave_action_process_sdo(ec_fsm_slave_t *);
 int ec_fsm_slave_action_process_foe(ec_fsm_slave_t *);
 void ec_fsm_slave_state_sdo_request(ec_fsm_slave_t *);
@@ -102,6 +103,25 @@
     return;
 }
 
+
+/*****************************************************************************/
+
+/** Sets the current state of the state machine to READY
+ *
+ */
+void ec_fsm_slave_ready(
+		ec_fsm_slave_t *fsm /**< Slave state machine. */
+		)
+{
+	if (fsm->state == ec_fsm_slave_state_idle) {
+		if (fsm->slave->master->debug_level) {
+			EC_DBG("Slave %u ready for SDO/FOE.\n",fsm->slave->ring_position);
+		}
+		fsm->state = ec_fsm_slave_state_ready;
+	}
+	return;
+}
+
 /******************************************************************************
  * Slave state machine
  *****************************************************************************/
@@ -113,15 +133,29 @@
  *
  */
 void ec_fsm_slave_state_idle(
-        ec_fsm_slave_t *fsm /**< Slave state machine. */
-        )
-{
-    // Check for pending external SDO requests
-    if (ec_fsm_slave_action_process_sdo(fsm))
-        return;
-    // Check for pending FOE requests
-    if (ec_fsm_slave_action_process_foe(fsm))
-        return;
+		ec_fsm_slave_t *fsm /**< Slave state machine. */
+        )
+{
+	// do nothing
+}
+
+
+/*****************************************************************************/
+
+/** Slave state: READY.
+ *
+ *
+ */
+void ec_fsm_slave_state_ready(
+		ec_fsm_slave_t *fsm /**< Slave state machine. */
+		)
+{
+	// Check for pending external SDO requests
+	if (ec_fsm_slave_action_process_sdo(fsm))
+		return;
+	// Check for pending FOE requests
+	if (ec_fsm_slave_action_process_foe(fsm))
+		return;
 
 }
 
@@ -143,10 +177,17 @@
     // search the first external request to be processed
     list_for_each_entry_safe(request, next, &slave->slave_sdo_requests, list) {
 
-        if (slave->current_state == EC_SLAVE_STATE_INIT) {
+		if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
+			EC_WARN("Postponing SDO request, slave %u has ERROR.\n",
+					slave->ring_position);
+			fsm->state = ec_fsm_slave_state_idle;
+			return 0;
+		}
+		if (slave->current_state == EC_SLAVE_STATE_INIT) {
             EC_WARN("Postponing SDO request, slave %u is in INIT.\n",
                     slave->ring_position);
-            return 0;
+			fsm->state = ec_fsm_slave_state_idle;
+			return 0;
         }
         list_del_init(&request->list); // dequeue
         request->req.state = EC_INT_REQUEST_BUSY;
@@ -184,11 +225,17 @@
 
     // search the first request to be processed
     list_for_each_entry_safe(request, next, &slave->foe_requests, list) {
-        list_del_init(&request->list); // dequeue
+		if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
+			EC_WARN("Postponing FOE request, slave %u has ERROR.\n",
+					slave->ring_position);
+			fsm->state = ec_fsm_slave_state_idle;
+			return 0;
+		}
+		list_del_init(&request->list); // dequeue
         request->req.state = EC_INT_REQUEST_BUSY;
 
         if (master->debug_level)
-            EC_DBG("Processing FoE request for slave %u.\n",
+			EC_DBG("Processing FOE request for slave %u.\n",
                     slave->ring_position);
 
         fsm->foe_request = &request->req;
@@ -239,7 +286,7 @@
     wake_up(&slave->sdo_queue);
 
     fsm->sdo_request = NULL;
-    fsm->state = ec_fsm_slave_state_idle;
+	fsm->state = ec_fsm_slave_state_ready;
 }
 
 
@@ -280,6 +327,6 @@
     wake_up(&slave->foe_queue);
 
     fsm->foe_request = NULL;
-    fsm->state = ec_fsm_slave_state_idle;
-}
-
+	fsm->state = ec_fsm_slave_state_ready;
+}
+
--- a/master/fsm_slave.h	Tue Dec 15 10:55:36 2009 +0100
+++ b/master/fsm_slave.h	Tue Dec 15 10:59:07 2009 +0100
@@ -65,7 +65,7 @@
 void ec_fsm_slave_clear(ec_fsm_slave_t *);
 
 void ec_fsm_slave_exec(ec_fsm_slave_t *);
-int ec_fsm_slave_idle(const ec_fsm_slave_t *);
+void ec_fsm_slave_ready(ec_fsm_slave_t *);
 
 /*****************************************************************************/