Better calc. of coupler address; coupler address in SysFS; better output of ec_list
authorFlorian Pose <fp@igh-essen.com>
Tue, 11 Apr 2006 14:12:01 +0000
changeset 188 c0e49f4a1c07
parent 187 01613bde2796
child 189 aabbfdacc2cc
Better calc. of coupler address; coupler address in SysFS; better output of ec_list
master/master.c
master/slave.c
master/slave.h
rt/msr_rt.c
tools/ec_list.pl
--- a/master/master.c	Tue Apr 11 13:03:35 2006 +0000
+++ b/master/master.c	Tue Apr 11 14:12:01 2006 +0000
@@ -455,7 +455,8 @@
     unsigned int i;
     ec_command_t *command;
     ec_eoe_t *eoe;
-    uint16_t buscoupler_index, index_after_buscoupler;
+    uint16_t coupler_index, coupler_subindex;
+    uint16_t reverse_coupler_index, current_coupler_index;
 
     if (!list_empty(&master->slaves)) {
         EC_ERR("Slave scan already done!\n");
@@ -490,8 +491,10 @@
         list_add_tail(&slave->list, &master->slaves);
     }
 
-    buscoupler_index = 0xFFFF;
-    index_after_buscoupler = 0;
+    coupler_index = 0;
+    reverse_coupler_index = 0xFFFF;
+    current_coupler_index = 0x3FFF;
+    coupler_subindex = 0;
 
     // For every slave on the bus
     list_for_each_entry(slave, &master->slaves, list) {
@@ -520,20 +523,22 @@
             ident++;
         }
 
-        if (!slave->type)
+        if (!slave->type) {
             EC_WARN("Unknown slave device (vendor 0x%08X, code 0x%08X) at"
                     " position %i.\n", slave->sii_vendor_id,
                     slave->sii_product_code, i);
-        else {
-            if (slave->type->special == EC_TYPE_BUS_COUPLER) {
-                buscoupler_index++;
-                index_after_buscoupler = 0;
-            }
-        }
-
-        slave->buscoupler_index = buscoupler_index;
-        slave->index_after_buscoupler = index_after_buscoupler;
-        index_after_buscoupler++;
+        }
+        else if (slave->type->special == EC_TYPE_BUS_COUPLER) {
+            if (slave->sii_alias)
+                current_coupler_index = reverse_coupler_index--;
+            else
+                current_coupler_index = coupler_index++;
+            coupler_subindex = 0;
+        }
+
+        slave->coupler_index = current_coupler_index;
+        slave->coupler_subindex = coupler_subindex;
+        coupler_subindex++;
 
         // Does the slave support EoE?
         if (slave->sii_mailbox_protocols & EC_MBOX_EOE) {
@@ -679,10 +684,15 @@
         }
 
         if (alias_requested) {
+            if (!alias_slave->type ||
+                alias_slave->type->special != EC_TYPE_BUS_COUPLER) {
+                EC_ERR("Slave address \"%s\": Alias slave must be bus coupler"
+                       " in colon mode.\n", address);
+                return NULL;
+            }
             list_for_each_entry(slave, &master->slaves, list) {
-                if (slave->buscoupler_index == alias_slave->buscoupler_index
-                    && alias_slave->index_after_buscoupler == 0
-                    && slave->index_after_buscoupler == second)
+                if (slave->coupler_index == alias_slave->coupler_index
+                    && slave->coupler_subindex == second)
                     return slave;
             }
             EC_ERR("Slave address \"%s\" - Bus coupler %i has no %lu. slave"
@@ -692,8 +702,8 @@
         }
         else {
             list_for_each_entry(slave, &master->slaves, list) {
-                if (slave->buscoupler_index == first
-                    && slave->index_after_buscoupler == second) return slave;
+                if (slave->coupler_index == first
+                    && slave->coupler_subindex == second) return slave;
             }
         }
     }
--- a/master/slave.c	Tue Apr 11 13:03:35 2006 +0000
+++ b/master/slave.c	Tue Apr 11 14:12:01 2006 +0000
@@ -29,7 +29,7 @@
 /*****************************************************************************/
 
 EC_SYSFS_READ_ATTR(ring_position);
-EC_SYSFS_READ_ATTR(station_address);
+EC_SYSFS_READ_ATTR(coupler_address);
 EC_SYSFS_READ_ATTR(vendor_name);
 EC_SYSFS_READ_ATTR(product_name);
 EC_SYSFS_READ_ATTR(product_desc);
@@ -37,7 +37,7 @@
 
 static struct attribute *def_attrs[] = {
     &attr_ring_position,
-    &attr_station_address,
+    &attr_coupler_address,
     &attr_vendor_name,
     &attr_product_name,
     &attr_product_desc,
@@ -89,8 +89,8 @@
     }
 
     slave->master = master;
-    slave->buscoupler_index = 0;
-    slave->index_after_buscoupler = 0xFFFF;
+    slave->coupler_index = 0;
+    slave->coupler_subindex = 0xFFFF;
     slave->base_type = 0;
     slave->base_revision = 0;
     slave->base_build = 0;
@@ -1211,8 +1211,9 @@
     if (attr == &attr_ring_position) {
         return sprintf(buffer, "%i\n", slave->ring_position);
     }
-    else if (attr == &attr_station_address) {
-        return sprintf(buffer, "%i\n", slave->station_address);
+    else if (attr == &attr_coupler_address) {
+        return sprintf(buffer, "%i:%i\n", slave->coupler_index,
+                       slave->coupler_subindex);
     }
     else if (attr == &attr_vendor_name) {
         if (slave->type)
--- a/master/slave.h	Tue Apr 11 13:03:35 2006 +0000
+++ b/master/slave.h	Tue Apr 11 14:12:01 2006 +0000
@@ -196,8 +196,8 @@
     // Addresses
     uint16_t ring_position; /**< Position des Slaves im Bus */
     uint16_t station_address; /**< Konfigurierte Slave-Adresse */
-    uint16_t buscoupler_index; /**< Letzter Buskoppler */
-    uint16_t index_after_buscoupler; /**< Index hinter letztem Buskoppler */
+    uint16_t coupler_index; /**< Letzter Buskoppler */
+    uint16_t coupler_subindex; /**< Index hinter letztem Buskoppler */
 
     // Base data
     uint8_t base_type; /**< Slave-Typ */
--- a/rt/msr_rt.c	Tue Apr 11 13:03:35 2006 +0000
+++ b/rt/msr_rt.c	Tue Apr 11 14:12:01 2006 +0000
@@ -62,8 +62,8 @@
 uint32_t k_ssi_st;
 
 ec_field_init_t domain1_fields[] = {
-    {&r_ssi,    "5", "Beckhoff", "EL5001", "InputValue", 0},
-    {&r_ssi_st, "5", "Beckhoff", "EL5001", "Status",     0},
+    {&r_ssi,    "0:3", "Beckhoff", "EL5001", "InputValue", 0},
+    {&r_ssi_st, "0:3", "Beckhoff", "EL5001", "Status",     0},
     {}
 };
 
@@ -183,7 +183,7 @@
 #endif
 
 #if 1
-    if (!(slave = ecrt_master_get_slave(master, "5"))) {
+    if (!(slave = ecrt_master_get_slave(master, "0:3"))) {
         printk(KERN_ERR "Failed to get slave!\n");
         goto out_deactivate;
     }
@@ -205,6 +205,17 @@
     }
 #endif
 
+#if 0
+    if (!(slave = ecrt_master_get_slave(master, "1:0"))) {
+        printk(KERN_ERR "Failed to get slave!\n");
+        goto out_deactivate;
+    }
+    if (ecrt_slave_write_alias(slave, 0x5678)) {
+        printk(KERN_ERR "Failed to write alias!\n");
+        goto out_deactivate;
+    }
+#endif
+
 #ifdef ASYNC
     // Einmal senden und warten...
     ecrt_master_prepare_async_io(master);
--- a/tools/ec_list.pl	Tue Apr 11 13:03:35 2006 +0000
+++ b/tools/ec_list.pl	Tue Apr 11 14:12:01 2006 +0000
@@ -42,6 +42,7 @@
     my $vendor_name;
     my @slaves;
     my $slave;
+    my $abs;
 
     unless (opendir $dirhandle, $master_dir) {
 	print "Failed to open directory \"$master_dir\".\n";
@@ -55,8 +56,8 @@
 	$slave = {};
 	$slave->{'ring_position'} =
 	    &read_integer("$slave_dir/ring_position");
-	$slave->{'station_address'} =
-	    &read_integer("$slave_dir/station_address");
+	$slave->{'coupler_address'} =
+	    &read_string("$slave_dir/coupler_address");
 	$slave->{'vendor_name'} =
 	    &read_string("$slave_dir/vendor_name");
 	$slave->{'product_name'} =
@@ -72,31 +73,17 @@
 
     @slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves;
 
-    my $coupler_index = -1;
-    my $slave_index = 0;
-    my $abs;
-    my $rel;
     print "EtherCAT bus listing for master $master_index:\n";
     for $slave (@slaves) {
 	if ($slave->{'type'} eq "coupler") {
 	    print "--------------------------------------------------------\n";
-	    $coupler_index++;
-	    $slave_index = 0;
 	}
 
 	$abs = sprintf "%i", $slave->{'ring_position'};
-	$rel = sprintf "%i:%i", $coupler_index, $slave_index;
-	printf("%4s %6s   %-15s %-15s %-15s\n", $abs, $rel,
-	       $slave->{'vendor_name'}, $slave->{'product_name'},
-	       $slave->{'product_desc'});
-
-	if ($slave->{'type'} eq "coupler") {
-	    print "--------------------------------------------------------\n";
-	}
-
-	$slave_index++;
+	printf(" %3s %8s   %-12s %-10s %s\n", $abs,
+	       $slave->{'coupler_address'}, $slave->{'vendor_name'},
+	       $slave->{'product_name'}, $slave->{'product_desc'});
     }
-    print "--------------------------------------------------------\n";
 }
 
 #------------------------------------------------------------------------------