Improved output when PDO assignment/mapping fails.
authorFlorian Pose <fp@igh-essen.com>
Tue, 23 Feb 2010 15:49:12 +0100
changeset 1823 2bf892fe8080
parent 1822 74e6ac2369f4
child 1824 bbb70ca26f09
Improved output when PDO assignment/mapping fails.
master/fsm_pdo.c
master/fsm_pdo_entry.c
master/fsm_pdo_entry.h
master/pdo.c
master/pdo.h
master/pdo_list.c
--- a/master/fsm_pdo.c	Tue Feb 23 15:13:56 2010 +0100
+++ b/master/fsm_pdo.c	Tue Feb 23 15:49:12 2010 +0100
@@ -99,6 +99,21 @@
 
 /*****************************************************************************/
 
+/** Print the current and desired PDO assignment.
+ */
+void ec_fsm_pdo_print(
+        ec_fsm_pdo_t *fsm /**< PDO configuration state machine. */
+        )
+{
+    printk("Currently assigned PDOs: ");
+    ec_pdo_list_print(&fsm->sync->pdos);
+    printk(". PDOs to assign: ");
+    ec_pdo_list_print(&fsm->pdos);
+    printk("\n");
+}
+
+/*****************************************************************************/
+
 /** Start reading the PDO configuration.
  */
 void ec_fsm_pdo_start_reading(
@@ -501,13 +516,8 @@
         return;
     }
 
-    if (fsm->slave->master->debug_level) {
-        // TODO display diff
-        EC_DBG("Changing mapping of PDO 0x%04X.\n", fsm->pdo->index);
-    }
-
     ec_fsm_pdo_entry_start_configuration(&fsm->fsm_pdo_entry, fsm->slave,
-            fsm->pdo);
+            fsm->pdo, &fsm->slave_pdo);
     fsm->state = ec_fsm_pdo_conf_state_mapping;
     fsm->state(fsm); // execure immediately
 }
@@ -569,12 +579,7 @@
 
     if (fsm->slave->master->debug_level) {
         EC_DBG("PDO assignment of SM%u differs:\n", fsm->sync_index);
-        EC_DBG("Currently assigned PDOs: ");
-        ec_pdo_list_print(&fsm->sync->pdos);
-        printk("\n");
-        EC_DBG("PDOs to assign: ");
-        ec_pdo_list_print(&fsm->pdos);
-        printk("\n");
+        EC_DBG(""); ec_fsm_pdo_print(fsm);
     }
 
     // PDO assignment has to be changed. Does the slave support this?
@@ -583,6 +588,7 @@
                 && !fsm->slave->sii.coe_details.enable_pdo_assign)) {
         EC_WARN("Slave %u does not support assigning PDOs!\n",
                 fsm->slave->ring_position);
+        EC_WARN(""); ec_fsm_pdo_print(fsm);
         ec_fsm_pdo_conf_action_next_sync(fsm);
         return;
     }
@@ -619,6 +625,7 @@
 
     if (!ec_fsm_coe_success(fsm->fsm_coe)) {
         EC_WARN("Failed to clear PDO assignment of SM%u.\n", fsm->sync_index);
+        EC_WARN(""); ec_fsm_pdo_print(fsm);
         fsm->state = ec_fsm_pdo_state_error;
         return;
     }
@@ -680,6 +687,7 @@
     if (!ec_fsm_coe_success(fsm->fsm_coe)) {
         EC_WARN("Failed to assign PDO 0x%04X at position %u of SM%u.\n",
                 fsm->pdo->index, fsm->pdo_pos, fsm->sync_index);
+        EC_WARN(""); ec_fsm_pdo_print(fsm);
         fsm->state = ec_fsm_pdo_state_error;
         return;
     }
@@ -720,6 +728,7 @@
     if (!ec_fsm_coe_success(fsm->fsm_coe)) {
         EC_WARN("Failed to set number of assigned PDOs of SM%u.\n",
                 fsm->sync_index);
+        EC_WARN(""); ec_fsm_pdo_print(fsm);
         fsm->state = ec_fsm_pdo_state_error;
         return;
     }
--- a/master/fsm_pdo_entry.c	Tue Feb 23 15:13:56 2010 +0100
+++ b/master/fsm_pdo_entry.c	Tue Feb 23 15:49:12 2010 +0100
@@ -84,6 +84,21 @@
 
 /*****************************************************************************/
 
+/** Print the current and desired PDO mapping.
+ */
+void ec_fsm_pdo_entry_print(
+        ec_fsm_pdo_entry_t *fsm /**< PDO configuration state machine. */
+        )
+{
+    printk("Currently mapped PDO entries: ");
+    ec_pdo_print_entries(fsm->cur_pdo);
+    printk(". Entries to map: ");
+    ec_pdo_print_entries(fsm->source_pdo);
+    printk("\n");
+}
+
+/*****************************************************************************/
+
 /** Start reading a PDO's entries.
  */
 void ec_fsm_pdo_entry_start_reading(
@@ -107,11 +122,18 @@
 void ec_fsm_pdo_entry_start_configuration(
         ec_fsm_pdo_entry_t *fsm, /**< PDO mapping state machine. */
         ec_slave_t *slave, /**< slave to configure */
-        const ec_pdo_t *pdo /**< PDO with the desired entries. */
+        const ec_pdo_t *pdo, /**< PDO with the desired entries. */
+        const ec_pdo_t *cur_pdo /**< Current PDO mapping. */
         )
 {
     fsm->slave = slave;
     fsm->source_pdo = pdo;
+    fsm->cur_pdo = cur_pdo;
+
+    if (fsm->slave->master->debug_level) {
+        EC_DBG("Changing mapping of PDO 0x%04X.\n", pdo->index);
+        EC_DBG(""); ec_fsm_pdo_entry_print(fsm);
+    }
 
     fsm->state = ec_fsm_pdo_entry_conf_state_start;
 }
@@ -310,6 +332,7 @@
                 && !fsm->slave->sii.coe_details.enable_pdo_configuration)) {
         EC_WARN("Slave %u does not support changing the PDO mapping!\n",
                 fsm->slave->ring_position);
+        EC_WARN(""); ec_fsm_pdo_entry_print(fsm);
         fsm->state = ec_fsm_pdo_entry_state_error;
         return;
     }
@@ -361,6 +384,7 @@
 
     if (!ec_fsm_coe_success(fsm->fsm_coe)) {
         EC_WARN("Failed to clear PDO mapping.\n");
+        EC_WARN(""); ec_fsm_pdo_entry_print(fsm);
         fsm->state = ec_fsm_pdo_entry_state_error;
         return;
     }
@@ -422,6 +446,7 @@
         EC_WARN("Failed to map PDO entry 0x%04X:%02X (%u bit) to "
                 "position %u.\n", fsm->entry->index, fsm->entry->subindex,
                 fsm->entry->bit_length, fsm->entry_pos);
+        EC_WARN(""); ec_fsm_pdo_entry_print(fsm);
         fsm->state = ec_fsm_pdo_entry_state_error;
         return;
     }
@@ -461,7 +486,8 @@
     if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
 
     if (!ec_fsm_coe_success(fsm->fsm_coe)) {
-        EC_ERR("Failed to set number of entries.\n");
+        EC_WARN("Failed to set number of entries.\n");
+        EC_WARN(""); ec_fsm_pdo_entry_print(fsm);
         fsm->state = ec_fsm_pdo_entry_state_error;
         return;
     }
--- a/master/fsm_pdo_entry.h	Tue Feb 23 15:13:56 2010 +0100
+++ b/master/fsm_pdo_entry.h	Tue Feb 23 15:49:12 2010 +0100
@@ -58,6 +58,7 @@
     ec_slave_t *slave; /**< Slave the FSM runs on. */
     ec_pdo_t *target_pdo; /**< PDO to read the mapping for. */
     const ec_pdo_t *source_pdo; /**< PDO with desired mapping. */
+    const ec_pdo_t *cur_pdo; /**< PDO with current mapping (display only). */
     const ec_pdo_entry_t *entry; /**< Current entry. */
     unsigned int entry_count; /**< Number of entries. */
     unsigned int entry_pos; /**< Position in PDO mapping. */
@@ -71,7 +72,7 @@
 void ec_fsm_pdo_entry_start_reading(ec_fsm_pdo_entry_t *, ec_slave_t *,
         ec_pdo_t *);
 void ec_fsm_pdo_entry_start_configuration(ec_fsm_pdo_entry_t *, ec_slave_t *,
-        const ec_pdo_t *);
+        const ec_pdo_t *, const ec_pdo_t *);
 
 int ec_fsm_pdo_entry_exec(ec_fsm_pdo_entry_t *);
 int ec_fsm_pdo_entry_success(const ec_fsm_pdo_entry_t *);
--- a/master/pdo.c	Tue Feb 23 15:13:56 2010 +0100
+++ b/master/pdo.c	Tue Feb 23 15:49:12 2010 +0100
@@ -291,3 +291,25 @@
 }
 
 /*****************************************************************************/
+
+/** Outputs the PDOs in the list.
+ */
+void ec_pdo_print_entries(
+        const ec_pdo_t *pdo /**< PDO. */
+        )
+{
+    const ec_pdo_entry_t *entry;
+
+    if (list_empty(&pdo->entries)) {
+        printk("(none)");
+    } else {
+        list_for_each_entry(entry, &pdo->entries, list) {
+            printk("0x%04X:%02X/%u",
+                    entry->index, entry->subindex, entry->bit_length);
+            if (entry->list.next != &pdo->entries)
+                printk(" ");
+        }
+    }
+}
+
+/*****************************************************************************/
--- a/master/pdo.h	Tue Feb 23 15:13:56 2010 +0100
+++ b/master/pdo.h	Tue Feb 23 15:49:12 2010 +0100
@@ -68,6 +68,8 @@
 const ec_pdo_entry_t *ec_pdo_find_entry_by_pos_const(
         const ec_pdo_t *, unsigned int);
 
+void ec_pdo_print_entries(const ec_pdo_t *);
+
 /*****************************************************************************/
 
 #endif
--- a/master/pdo_list.c	Tue Feb 23 15:13:56 2010 +0100
+++ b/master/pdo_list.c	Tue Feb 23 15:49:12 2010 +0100
@@ -326,11 +326,15 @@
 {
     const ec_pdo_t *pdo;
 
-    list_for_each_entry(pdo, &pl->list, list) {
-        printk("0x%04X", pdo->index);
-        if (pdo->list.next != &pl->list)
-            printk(" ");
-    }
-}
-
-/*****************************************************************************/
+    if (list_empty(&pl->list)) {
+        printk("(none)");
+    } else {
+        list_for_each_entry(pdo, &pl->list, list) {
+            printk("0x%04X", pdo->index);
+            if (pdo->list.next != &pl->list)
+                printk(" ");
+        }
+    }
+}
+
+/*****************************************************************************/