Skip to content
Snippets Groups Projects
Commit 0257f808 authored by Florian Pose's avatar Florian Pose
Browse files

Better calc. of coupler address; coupler address in SysFS; better output of ec_list

parent ca6c0c83
No related branches found
No related tags found
No related merge requests found
...@@ -455,7 +455,8 @@ int ec_master_bus_scan(ec_master_t *master /**< EtherCAT-Master */) ...@@ -455,7 +455,8 @@ int ec_master_bus_scan(ec_master_t *master /**< EtherCAT-Master */)
unsigned int i; unsigned int i;
ec_command_t *command; ec_command_t *command;
ec_eoe_t *eoe; 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)) { if (!list_empty(&master->slaves)) {
EC_ERR("Slave scan already done!\n"); EC_ERR("Slave scan already done!\n");
...@@ -490,8 +491,10 @@ int ec_master_bus_scan(ec_master_t *master /**< EtherCAT-Master */) ...@@ -490,8 +491,10 @@ int ec_master_bus_scan(ec_master_t *master /**< EtherCAT-Master */)
list_add_tail(&slave->list, &master->slaves); list_add_tail(&slave->list, &master->slaves);
} }
buscoupler_index = 0xFFFF; coupler_index = 0;
index_after_buscoupler = 0; reverse_coupler_index = 0xFFFF;
current_coupler_index = 0x3FFF;
coupler_subindex = 0;
// For every slave on the bus // For every slave on the bus
list_for_each_entry(slave, &master->slaves, list) { list_for_each_entry(slave, &master->slaves, list) {
...@@ -520,20 +523,22 @@ int ec_master_bus_scan(ec_master_t *master /**< EtherCAT-Master */) ...@@ -520,20 +523,22 @@ int ec_master_bus_scan(ec_master_t *master /**< EtherCAT-Master */)
ident++; ident++;
} }
if (!slave->type) if (!slave->type) {
EC_WARN("Unknown slave device (vendor 0x%08X, code 0x%08X) at" EC_WARN("Unknown slave device (vendor 0x%08X, code 0x%08X) at"
" position %i.\n", slave->sii_vendor_id, " position %i.\n", slave->sii_vendor_id,
slave->sii_product_code, i); slave->sii_product_code, i);
else { }
if (slave->type->special == EC_TYPE_BUS_COUPLER) { else if (slave->type->special == EC_TYPE_BUS_COUPLER) {
buscoupler_index++; if (slave->sii_alias)
index_after_buscoupler = 0; current_coupler_index = reverse_coupler_index--;
} else
current_coupler_index = coupler_index++;
coupler_subindex = 0;
} }
slave->buscoupler_index = buscoupler_index; slave->coupler_index = current_coupler_index;
slave->index_after_buscoupler = index_after_buscoupler; slave->coupler_subindex = coupler_subindex;
index_after_buscoupler++; coupler_subindex++;
// Does the slave support EoE? // Does the slave support EoE?
if (slave->sii_mailbox_protocols & EC_MBOX_EOE) { if (slave->sii_mailbox_protocols & EC_MBOX_EOE) {
...@@ -679,10 +684,15 @@ ec_slave_t *ecrt_master_get_slave(const ec_master_t *master, /**< Master */ ...@@ -679,10 +684,15 @@ ec_slave_t *ecrt_master_get_slave(const ec_master_t *master, /**< Master */
} }
if (alias_requested) { 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) { list_for_each_entry(slave, &master->slaves, list) {
if (slave->buscoupler_index == alias_slave->buscoupler_index if (slave->coupler_index == alias_slave->coupler_index
&& alias_slave->index_after_buscoupler == 0 && slave->coupler_subindex == second)
&& slave->index_after_buscoupler == second)
return slave; return slave;
} }
EC_ERR("Slave address \"%s\" - Bus coupler %i has no %lu. slave" EC_ERR("Slave address \"%s\" - Bus coupler %i has no %lu. slave"
...@@ -692,8 +702,8 @@ ec_slave_t *ecrt_master_get_slave(const ec_master_t *master, /**< Master */ ...@@ -692,8 +702,8 @@ ec_slave_t *ecrt_master_get_slave(const ec_master_t *master, /**< Master */
} }
else { else {
list_for_each_entry(slave, &master->slaves, list) { list_for_each_entry(slave, &master->slaves, list) {
if (slave->buscoupler_index == first if (slave->coupler_index == first
&& slave->index_after_buscoupler == second) return slave; && slave->coupler_subindex == second) return slave;
} }
} }
} }
......
...@@ -29,7 +29,7 @@ ssize_t ec_show_slave_attribute(struct kobject *, struct attribute *, char *); ...@@ -29,7 +29,7 @@ ssize_t ec_show_slave_attribute(struct kobject *, struct attribute *, char *);
/*****************************************************************************/ /*****************************************************************************/
EC_SYSFS_READ_ATTR(ring_position); 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(vendor_name);
EC_SYSFS_READ_ATTR(product_name); EC_SYSFS_READ_ATTR(product_name);
EC_SYSFS_READ_ATTR(product_desc); EC_SYSFS_READ_ATTR(product_desc);
...@@ -37,7 +37,7 @@ EC_SYSFS_READ_ATTR(type); ...@@ -37,7 +37,7 @@ EC_SYSFS_READ_ATTR(type);
static struct attribute *def_attrs[] = { static struct attribute *def_attrs[] = {
&attr_ring_position, &attr_ring_position,
&attr_station_address, &attr_coupler_address,
&attr_vendor_name, &attr_vendor_name,
&attr_product_name, &attr_product_name,
&attr_product_desc, &attr_product_desc,
...@@ -89,8 +89,8 @@ int ec_slave_init(ec_slave_t *slave, /**< EtherCAT-Slave */ ...@@ -89,8 +89,8 @@ int ec_slave_init(ec_slave_t *slave, /**< EtherCAT-Slave */
} }
slave->master = master; slave->master = master;
slave->buscoupler_index = 0; slave->coupler_index = 0;
slave->index_after_buscoupler = 0xFFFF; slave->coupler_subindex = 0xFFFF;
slave->base_type = 0; slave->base_type = 0;
slave->base_revision = 0; slave->base_revision = 0;
slave->base_build = 0; slave->base_build = 0;
...@@ -1211,8 +1211,9 @@ ssize_t ec_show_slave_attribute(struct kobject *kobj, /**< KObject */ ...@@ -1211,8 +1211,9 @@ ssize_t ec_show_slave_attribute(struct kobject *kobj, /**< KObject */
if (attr == &attr_ring_position) { if (attr == &attr_ring_position) {
return sprintf(buffer, "%i\n", slave->ring_position); return sprintf(buffer, "%i\n", slave->ring_position);
} }
else if (attr == &attr_station_address) { else if (attr == &attr_coupler_address) {
return sprintf(buffer, "%i\n", slave->station_address); return sprintf(buffer, "%i:%i\n", slave->coupler_index,
slave->coupler_subindex);
} }
else if (attr == &attr_vendor_name) { else if (attr == &attr_vendor_name) {
if (slave->type) if (slave->type)
......
...@@ -196,8 +196,8 @@ struct ec_slave ...@@ -196,8 +196,8 @@ struct ec_slave
// Addresses // Addresses
uint16_t ring_position; /**< Position des Slaves im Bus */ uint16_t ring_position; /**< Position des Slaves im Bus */
uint16_t station_address; /**< Konfigurierte Slave-Adresse */ uint16_t station_address; /**< Konfigurierte Slave-Adresse */
uint16_t buscoupler_index; /**< Letzter Buskoppler */ uint16_t coupler_index; /**< Letzter Buskoppler */
uint16_t index_after_buscoupler; /**< Index hinter letztem Buskoppler */ uint16_t coupler_subindex; /**< Index hinter letztem Buskoppler */
// Base data // Base data
uint8_t base_type; /**< Slave-Typ */ uint8_t base_type; /**< Slave-Typ */
......
...@@ -62,8 +62,8 @@ uint32_t k_ssi; ...@@ -62,8 +62,8 @@ uint32_t k_ssi;
uint32_t k_ssi_st; uint32_t k_ssi_st;
ec_field_init_t domain1_fields[] = { ec_field_init_t domain1_fields[] = {
{&r_ssi, "5", "Beckhoff", "EL5001", "InputValue", 0}, {&r_ssi, "0:3", "Beckhoff", "EL5001", "InputValue", 0},
{&r_ssi_st, "5", "Beckhoff", "EL5001", "Status", 0}, {&r_ssi_st, "0:3", "Beckhoff", "EL5001", "Status", 0},
{} {}
}; };
...@@ -183,7 +183,7 @@ int __init init_rt_module(void) ...@@ -183,7 +183,7 @@ int __init init_rt_module(void)
#endif #endif
#if 1 #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"); printk(KERN_ERR "Failed to get slave!\n");
goto out_deactivate; goto out_deactivate;
} }
...@@ -205,6 +205,17 @@ int __init init_rt_module(void) ...@@ -205,6 +205,17 @@ int __init init_rt_module(void)
} }
#endif #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 #ifdef ASYNC
// Einmal senden und warten... // Einmal senden und warten...
ecrt_master_prepare_async_io(master); ecrt_master_prepare_async_io(master);
......
...@@ -42,6 +42,7 @@ sub query_slaves ...@@ -42,6 +42,7 @@ sub query_slaves
my $vendor_name; my $vendor_name;
my @slaves; my @slaves;
my $slave; my $slave;
my $abs;
unless (opendir $dirhandle, $master_dir) { unless (opendir $dirhandle, $master_dir) {
print "Failed to open directory \"$master_dir\".\n"; print "Failed to open directory \"$master_dir\".\n";
...@@ -55,8 +56,8 @@ sub query_slaves ...@@ -55,8 +56,8 @@ sub query_slaves
$slave = {}; $slave = {};
$slave->{'ring_position'} = $slave->{'ring_position'} =
&read_integer("$slave_dir/ring_position"); &read_integer("$slave_dir/ring_position");
$slave->{'station_address'} = $slave->{'coupler_address'} =
&read_integer("$slave_dir/station_address"); &read_string("$slave_dir/coupler_address");
$slave->{'vendor_name'} = $slave->{'vendor_name'} =
&read_string("$slave_dir/vendor_name"); &read_string("$slave_dir/vendor_name");
$slave->{'product_name'} = $slave->{'product_name'} =
...@@ -72,31 +73,17 @@ sub query_slaves ...@@ -72,31 +73,17 @@ sub query_slaves
@slaves = sort { $a->{'ring_position'} <=> $b->{'ring_position'} } @slaves; @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"; print "EtherCAT bus listing for master $master_index:\n";
for $slave (@slaves) { for $slave (@slaves) {
if ($slave->{'type'} eq "coupler") { if ($slave->{'type'} eq "coupler") {
print "--------------------------------------------------------\n"; print "--------------------------------------------------------\n";
$coupler_index++;
$slave_index = 0;
} }
$abs = sprintf "%i", $slave->{'ring_position'}; $abs = sprintf "%i", $slave->{'ring_position'};
$rel = sprintf "%i:%i", $coupler_index, $slave_index; printf(" %3s %8s %-12s %-10s %s\n", $abs,
printf("%4s %6s %-15s %-15s %-15s\n", $abs, $rel, $slave->{'coupler_address'}, $slave->{'vendor_name'},
$slave->{'vendor_name'}, $slave->{'product_name'}, $slave->{'product_name'}, $slave->{'product_desc'});
$slave->{'product_desc'});
if ($slave->{'type'} eq "coupler") {
print "--------------------------------------------------------\n";
}
$slave_index++;
} }
print "--------------------------------------------------------\n";
} }
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment