Introduced topology_change_pending to delay bus scanning until IDLE mode
authorFlorian Pose <fp@igh-essen.com>
Tue, 13 Feb 2007 10:51:40 +0000
changeset 553 a4e0267825e3
parent 552 029546740810
child 554 46ff4bff08ea
Introduced topology_change_pending to delay bus scanning until IDLE mode
has been reached.
TODO
master/fsm_master.c
master/fsm_master.h
--- a/TODO	Mon Feb 12 14:42:36 2007 +0000
+++ b/TODO	Tue Feb 13 10:51:40 2007 +0000
@@ -7,7 +7,6 @@
 -------------------------------------------------------------------------------
 
 * Release 1.2:
-  - Introduce topology_change_pending.
   - Update feature lists.
 
 * Release 1.3:
--- a/master/fsm_master.c	Mon Feb 12 14:42:36 2007 +0000
+++ b/master/fsm_master.c	Tue Feb 13 10:51:40 2007 +0000
@@ -75,6 +75,7 @@
     fsm->datagram = datagram;
     fsm->state = ec_fsm_master_state_start;
     fsm->slaves_responding = 0;
+    fsm->topology_change_pending = 0;
     fsm->slave_states = EC_SLAVE_STATE_UNKNOWN;
     fsm->validate = 0;
 
@@ -170,7 +171,7 @@
 void ec_fsm_master_state_broadcast(ec_fsm_master_t *fsm /**< master state machine */)
 {
     ec_datagram_t *datagram = fsm->datagram;
-    unsigned int topology_change, states_change, i;
+    unsigned int i;
     ec_slave_t *slave;
     ec_master_t *master = fsm->master;
 
@@ -190,14 +191,11 @@
         return;
     }
 
-    topology_change = (datagram->working_counter !=
-                       fsm->slaves_responding);
-    states_change = (EC_READ_U8(datagram->data) != fsm->slave_states);
-
-    fsm->slave_states = EC_READ_U8(datagram->data);
-    fsm->slaves_responding = datagram->working_counter;
-
-    if (topology_change) {
+    // bus topology change?
+    if (datagram->working_counter != fsm->slaves_responding) {
+        fsm->topology_change_pending = 1;
+        fsm->slaves_responding = datagram->working_counter;
+
         EC_INFO("%i slave%s responding.\n",
                 fsm->slaves_responding,
                 fsm->slaves_responding == 1 ? "" : "s");
@@ -212,14 +210,18 @@
         }
     }
 
-    if (states_change) {
+    // slave states changed?
+    if (EC_READ_U8(datagram->data) != fsm->slave_states) {
         char states[EC_STATE_STRING_SIZE];
+        fsm->slave_states = EC_READ_U8(datagram->data);
         ec_state_string(fsm->slave_states, states);
         EC_INFO("Slave states: %s.\n", states);
     }
 
     // topology change in idle mode: clear all slaves and scan the bus
-    if (topology_change && master->mode == EC_MASTER_MODE_IDLE) {
+    if (fsm->topology_change_pending &&
+            master->mode == EC_MASTER_MODE_IDLE) {
+        fsm->topology_change_pending = 0;
 
         ec_master_eoe_stop(master);
         ec_master_destroy_slaves(master);
--- a/master/fsm_master.h	Mon Feb 12 14:42:36 2007 +0000
+++ b/master/fsm_master.h	Tue Feb 13 10:51:40 2007 +0000
@@ -65,6 +65,7 @@
 
     void (*state)(ec_fsm_master_t *); /**< master state function */
     unsigned int slaves_responding; /**< number of responding slaves */
+    unsigned int topology_change_pending; /**< bus topology changed */
     ec_slave_state_t slave_states; /**< states of responding slaves */
     unsigned int validate; /**< non-zero, if validation to do */
     ec_slave_t *slave; /**< current slave */