Broadcast MAC address accepts first device.
--- a/NEWS Fri Aug 10 14:36:16 2007 +0000
+++ b/NEWS Fri Aug 10 15:04:06 2007 +0000
@@ -13,7 +13,8 @@
dynamically instead.
* Added "main" and "backup" parameters to master module to hand over the
MAC addresses of the devices to wait for. This made the ec_device_index
- parameter of the ethernet drivers obsolete.
+ parameter of the ethernet drivers obsolete. The broadcast MAC address means,
+ that the master accepts the first device offered by any ethernet driver.
* Changed format of sysconfig file and accordingly adjusted functionality
of the init script to handle the above MAC address lists.
* Realtime interface changes:
--- a/TODO Fri Aug 10 14:36:16 2007 +0000
+++ b/TODO Fri Aug 10 15:04:06 2007 +0000
@@ -6,9 +6,6 @@
-------------------------------------------------------------------------------
-* Issues for release 1.3.0:
- - Take broadcast MAC address to register the first ethernet device.
-
* Future features:
- Interface/buffers for asynchronous domain IO.
- Distributed clocks.
--- a/master/module.c Fri Aug 10 14:36:16 2007 +0000
+++ b/master/module.c Fri Aug 10 15:04:06 2007 +0000
@@ -248,6 +248,19 @@
/*****************************************************************************/
+int ec_mac_is_broadcast(const uint8_t *mac)
+{
+ unsigned int i;
+
+ for (i = 0; i < ETH_ALEN; i++)
+ if (mac[i] != 0xff)
+ return 0;
+
+ return 1;
+}
+
+/*****************************************************************************/
+
static int ec_mac_parse(uint8_t *mac, const char *src, int allow_empty)
{
unsigned int i, value;
@@ -400,19 +413,19 @@
for (i = 0; i < master_count; i++) {
master = &masters[i];
- if (ec_mac_equal(master->main_mac, net_dev->dev_addr)) {
- ec_mac_print(master->main_mac, str);
+
+ down(&master->device_sem);
+ if (master->main_device.dev) { // master already has a device
+ up(&master->device_sem);
+ continue;
+ }
+
+ if (ec_mac_equal(master->main_mac, net_dev->dev_addr)
+ || ec_mac_is_broadcast(master->main_mac)) {
+ ec_mac_print(net_dev->dev_addr, str);
EC_INFO("Accepting device %s for master %u.\n",
str, master->index);
- down(&master->device_sem);
- if (master->main_device.dev) {
- EC_ERR("Master %u already has a device attached.\n",
- master->index);
- up(&master->device_sem);
- return -1;
- }
-
ec_device_attach(&master->main_device, net_dev, poll, module);
up(&master->device_sem);
@@ -420,9 +433,13 @@
*ecdev = &master->main_device; // offer accepted
return 0; // no error
}
- else if (master->debug_level) {
- ec_mac_print(master->main_mac, str);
- EC_DBG("Master %u declined device %s.\n", master->index, str);
+ else {
+ up(&master->device_sem);
+
+ if (master->debug_level) {
+ ec_mac_print(net_dev->dev_addr, str);
+ EC_DBG("Master %u declined device %s.\n", master->index, str);
+ }
}
}
@@ -446,8 +463,7 @@
ec_master_t *master = device->master;
char str[20];
- ec_mac_print(master->main_mac, str);
-
+ ec_mac_print(device->dev->dev_addr, str);
EC_INFO("Master %u releasing main device %s.\n", master->index, str);
down(&master->device_sem);
--- a/script/sysconfig/ethercat Fri Aug 10 14:36:16 2007 +0000
+++ b/script/sysconfig/ethercat Fri Aug 10 15:04:06 2007 +0000
@@ -16,6 +16,9 @@
# Specify the MAC address (hexadecimal with colons) of the Ethernet device to
# use. Example: "00:00:08:44:ab:66"
#
+# The broadcast address "ff:ff:ff:ff:ff:ff" has a special meaning: It tells
+# the master to accept the first device offered by any ethernet driver.
+#
# The MASTER<X>_DEVICE variables also determine, how many masters will be
# created: A non-empty variable MASTER0_DEVICE will create one master, adding
# a non-empty variable MASTER1_DEVICE will create a second master, and so on.