Implemented ecrt_slave_config_state(); minor changes in
authorFlorian Pose <fp@igh-essen.com>
Wed, 18 Jun 2008 10:13:58 +0000
changeset 1022 8e49b519e6ba
parent 1021 fa5cf205f4f0
child 1023 7b8961141042
Implemented ecrt_slave_config_state(); minor changes in
ec_master_state_t and ec_slave_config_state_t; adapted example.
TODO
examples/mini/mini.c
include/ecrt.h
master/master.c
master/slave_config.c
--- a/TODO	Wed Jun 18 09:27:04 2008 +0000
+++ b/TODO	Wed Jun 18 10:13:58 2008 +0000
@@ -8,8 +8,6 @@
 
 Version 1.4.0:
 
-* Supply new ec_master_state_t.
-* Implement ecrt_slave_config_state().
 * Remove get_cycles() calls and references to cpu_khz to increase
   portability.
 * Make ecrt_master_slave_config() return no error when slave is not present
--- a/examples/mini/mini.c	Wed Jun 18 09:27:04 2008 +0000
+++ b/examples/mini/mini.c	Wed Jun 18 10:13:58 2008 +0000
@@ -60,6 +60,9 @@
 static ec_domain_t *domain1 = NULL;
 static ec_domain_state_t domain1_state = {};
 
+static ec_slave_config_t *sc_ana_in = NULL;
+static ec_slave_config_state_t sc_ana_in_state = {};
+
 static struct timer_list timer;
 static unsigned int counter = 0;
 
@@ -128,14 +131,14 @@
 {
     ec_domain_state_t ds;
 
+    spin_lock(&master_lock);
     ecrt_domain_state(domain1, &ds);
+    spin_unlock(&master_lock);
+
     if (ds.working_counter != domain1_state.working_counter)
-        printk(KERN_INFO PFX "domain1 working_counter changed to %u.\n",
-                ds.working_counter);
-
+        printk(KERN_INFO PFX "Domain1: WC %u.\n", ds.working_counter);
     if (ds.wc_state != domain1_state.wc_state)
-        printk(KERN_INFO PFX "domain1 wc_state changed to %u.\n",
-                ds.wc_state);
+        printk(KERN_INFO PFX "Domain1: State %u.\n", ds.wc_state);
 
     domain1_state = ds;
 }
@@ -150,16 +153,39 @@
     ecrt_master_state(master, &ms);
     spin_unlock(&master_lock);
 
-    if (ms.slaves_responding != master_state.slaves_responding) {
-        printk(KERN_INFO PFX "slaves_responding changed to %u.\n",
-                ms.slaves_responding);
-    }
+    if (ms.slaves_responding != master_state.slaves_responding)
+        printk(KERN_INFO PFX "%u slave(s).\n", ms.slaves_responding);
+    if (ms.al_states != master_state.al_states)
+        printk(KERN_INFO PFX "AL states: 0x%02X.\n", ms.al_states);
+    if (ms.link_up != master_state.link_up)
+        printk(KERN_INFO PFX "Link is %s.\n", ms.link_up ? "up" : "down");
 
     master_state = ms;
 }
 
 /*****************************************************************************/
 
+void check_slave_config_states(void)
+{
+    ec_slave_config_state_t s;
+
+    spin_lock(&master_lock);
+    ecrt_slave_config_state(sc_ana_in, &s);
+    spin_unlock(&master_lock);
+
+    if (s.al_state != sc_ana_in_state.al_state)
+        printk(KERN_INFO PFX "AnaIn: State 0x%02X.\n", s.al_state);
+    if (s.online != sc_ana_in_state.online)
+        printk(KERN_INFO PFX "AnaIn: %s.\n", s.online ? "online" : "offline");
+    if (s.operational != sc_ana_in_state.operational)
+        printk(KERN_INFO PFX "AnaIn: %soperational.\n",
+                s.operational ? "" : "Not ");
+
+    sc_ana_in_state = s;
+}
+
+/*****************************************************************************/
+
 #ifdef SDO_ACCESS
 void read_sdo(void)
 {
@@ -207,6 +233,9 @@
 
         // check for master state (optional)
         check_master_state();
+
+        // check for islave configuration state(s) (optional)
+        check_slave_config_states();
         
 #ifdef SDO_ACCESS
         // read process data Sdo
@@ -269,14 +298,15 @@
         goto out_release_master;
     }
 
+    if (!(sc_ana_in = ecrt_master_slave_config(
+                    master, 0, 1, Beckhoff_EL3162))) {
+        printk(KERN_ERR PFX "Failed to get slave configuration.\n");
+        goto out_release_master;
+    }
+
 #ifdef CONFIGURE_PDOS
     printk(KERN_INFO PFX "Configuring Pdos...\n");
-    if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) {
-        printk(KERN_ERR PFX "Failed to get slave configuration.\n");
-        goto out_release_master;
-    }
-
-    if (ecrt_slave_config_pdos(sc, EC_END, el3162_pdos)) {
+    if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_pdos)) {
         printk(KERN_ERR PFX "Failed to configure Pdos.\n");
         goto out_release_master;
     }
--- a/include/ecrt.h	Wed Jun 18 09:27:04 2008 +0000
+++ b/include/ecrt.h	Wed Jun 18 10:13:58 2008 +0000
@@ -157,15 +157,16 @@
  */
 typedef struct {
     unsigned int slaves_responding; /**< Number of slaves in the bus. */
-    uint8_t slave_states; /**< Application-layer states of all slaves.
-                            The states are coded in the lower 4 bits. If a bit
-                            is set, it means that at least one slave in the
-                            bus is in the corresponding state:
-                            - Bit 0: \a INIT
-                            - Bit 1: \a PREOP
-                            - Bit 2: \a SAFEOP
-                            - Bit 3: \a OP */
-    uint8_t link_up; /**< \a true, if the network link is up. */
+    unsigned int al_states : 4; /**< Application-layer states of all slaves.
+                                  The states are coded in the lower 4 bits.
+                                  If a bit is set, it means that at least one
+                                  slave in the bus is in the corresponding
+                                  state:
+                                  - Bit 0: \a INIT
+                                  - Bit 1: \a PREOP
+                                  - Bit 2: \a SAFEOP
+                                  - Bit 3: \a OP */
+    unsigned int link_up : 1; /**< \a true, if the network link is up. */
 } ec_master_state_t;
 
 /*****************************************************************************/
@@ -177,17 +178,17 @@
  * \see ecrt_slave_config_state().
  */
 typedef struct  {
-    uint8_t slave_state; /**< The application-layer state of the slave.
-                           - 1: \a INIT
-                           - 2: \a PREOP
-                           - 4: \a SAFEOP
-                           - 8: \a OP
-
-                           Note that each state is coded in a different
-                           bit! */
     unsigned int online : 1; /**< The slave is online. */
     unsigned int operational : 1; /**< The slave was brought into \a OP state
                                     using the specified configuration. */
+    unsigned int al_state : 4; /**< The application-layer state of the slave.
+                                 - 1: \a INIT
+                                 - 2: \a PREOP
+                                 - 4: \a SAFEOP
+                                 - 8: \a OP
+
+                                 Note that each state is coded in a different
+                                 bit! */
 } ec_slave_config_state_t;
 
 /*****************************************************************************/
--- a/master/master.c	Wed Jun 18 09:27:04 2008 +0000
+++ b/master/master.c	Wed Jun 18 10:13:58 2008 +0000
@@ -1372,7 +1372,7 @@
 void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
 {
     state->slaves_responding = master->fsm.slaves_responding;
-    state->slave_states = master->fsm.slave_states;
+    state->al_states = master->fsm.slave_states;
     state->link_up = master->main_device.link_state;
 }
 
--- a/master/slave_config.c	Wed Jun 18 09:27:04 2008 +0000
+++ b/master/slave_config.c	Wed Jun 18 10:13:58 2008 +0000
@@ -618,6 +618,22 @@
 
 /*****************************************************************************/
 
+void ecrt_slave_config_state(const ec_slave_config_t *sc,
+        ec_slave_config_state_t *state)
+{
+    state->online = sc->slave ? 1 : 0;
+    if (state->online) {
+        state->operational =
+            sc->slave->current_state == EC_SLAVE_STATE_OP;
+        state->al_state = sc->slave->current_state;
+    } else {
+        state->operational = 0;
+        state->al_state = EC_SLAVE_STATE_UNKNOWN;
+    }
+}
+
+/*****************************************************************************/
+
 /** \cond */
 
 EXPORT_SYMBOL(ecrt_slave_config_pdo_assign_add);
@@ -631,6 +647,7 @@
 EXPORT_SYMBOL(ecrt_slave_config_sdo16);
 EXPORT_SYMBOL(ecrt_slave_config_sdo32);
 EXPORT_SYMBOL(ecrt_slave_config_create_sdo_request);
+EXPORT_SYMBOL(ecrt_slave_config_state);
 
 /** \endcond */