Removed ktype for module kobject; added backup device for master; device
authorFlorian Pose <fp@igh-essen.com>
Tue, 20 Feb 2007 13:42:44 +0000
changeset 578 f402b4bd2f4d
parent 577 db34078f34cc
child 579 17c6fd3b076e
Removed ktype for module kobject; added backup device for master; device
connection information and IDs in master info file.
master/master.c
master/master.h
master/module.c
--- a/master/master.c	Tue Feb 20 13:40:30 2007 +0000
+++ b/master/master.c	Tue Feb 20 13:42:44 2007 +0000
@@ -116,6 +116,7 @@
 
     master->device = NULL;
     master->main_device_id = main_id;
+    master->backup_device = NULL;
     master->backup_device_id = backup_id;
     init_MUTEX(&master->device_sem);
 
@@ -849,6 +850,38 @@
     complete_and_exit(&master->thread_exit, 0);
 }
 
+
+/*****************************************************************************/
+
+ssize_t ec_master_device_info(const ec_device_t *device,
+        const ec_device_id_t *dev_id,
+        char *buffer)
+{
+    unsigned int frames_lost;
+    off_t off = 0;
+    
+    off += ec_device_id_print(dev_id, buffer + off);
+    
+    if (device) {
+        off += sprintf(buffer + off, " (connected).\n");      
+        off += sprintf(buffer + off, "    Frames sent:     %u\n",
+                device->tx_count);
+        off += sprintf(buffer + off, "    Frames received: %u\n",
+                device->rx_count);
+        frames_lost = device->tx_count - device->rx_count;
+        if (frames_lost) frames_lost--;
+        off += sprintf(buffer + off, "    Frames lost:     %u\n", frames_lost);
+    }
+    else if (dev_id->type != ec_device_id_empty) {
+        off += sprintf(buffer + off, " (WAITING).\n");      
+    }
+    else {
+        off += sprintf(buffer + off, ".\n");
+    }
+    
+    return off;
+}
+
 /*****************************************************************************/
 
 /**
@@ -863,9 +896,7 @@
     off_t off = 0;
     ec_eoe_t *eoe;
     uint32_t cur, sum, min, max, pos, i;
-    unsigned int frames_lost;
-
-    off += sprintf(buffer + off, "\nVersion: %s", ec_master_version_str);
+
     off += sprintf(buffer + off, "\nMode: ");
     switch (master->mode) {
         case EC_MASTER_MODE_ORPHANED:
@@ -881,14 +912,22 @@
 
     off += sprintf(buffer + off, "\nSlaves: %i\n",
                    master->slave_count);
-    off += sprintf(buffer + off, "\nDevice:\n");
-    off += sprintf(buffer + off, "  Frames sent:     %u\n",
-		   master->device->tx_count);
-    off += sprintf(buffer + off, "  Frames received: %u\n",
-		   master->device->rx_count);
-    frames_lost = master->device->tx_count - master->device->rx_count;
-    if (frames_lost) frames_lost--;
-    off += sprintf(buffer + off, "  Frames lost:     %u\n", frames_lost);
+
+    off += sprintf(buffer + off, "\nDevices:\n");
+    
+    if (down_interruptible(&master->device_sem)) {
+        EC_ERR("Interrupted while waiting for device!\n");
+        return -EINVAL;
+    }
+    
+    off += sprintf(buffer + off, "  Main: ");
+    off += ec_master_device_info(master->device,
+            master->main_device_id, buffer + off);
+    off += sprintf(buffer + off, "  Backup: ");
+    off += ec_master_device_info(master->backup_device,
+            master->backup_device_id, buffer + off);
+
+    up(&master->device_sem);
 
     off += sprintf(buffer + off, "\nTiming (min/avg/max) [us]:\n");
 
--- a/master/master.h	Tue Feb 20 13:40:30 2007 +0000
+++ b/master/master.h	Tue Feb 20 13:42:44 2007 +0000
@@ -101,6 +101,7 @@
 
     ec_device_t *device; /**< EtherCAT device */
     const ec_device_id_t *main_device_id; /**< ID of main device */
+    ec_device_t *backup_device; /**< EtherCAT backup device */
     const ec_device_id_t *backup_device_id; /**< ID of backup device */
     struct semaphore device_sem; /**< device semaphore */
 
--- a/master/module.c	Tue Feb 20 13:40:30 2007 +0000
+++ b/master/module.c	Tue Feb 20 13:42:44 2007 +0000
@@ -52,33 +52,6 @@
 int __init ec_init_module(void);
 void __exit ec_cleanup_module(void);
 
-ssize_t ec_show_attribute(struct kobject *, struct attribute *, char *);
-
-/*****************************************************************************/
-
-/** \cond */
-
-EC_SYSFS_READ_ATTR(info);
-
-static struct attribute *ec_def_attrs[] = {
-    &attr_info,
-    NULL,
-};
-
-static struct sysfs_ops ec_sysfs_ops = {
-    .show = &ec_show_attribute,
-    .store = NULL 
-};
-
-static struct kobj_type ktype_ec_module = {
-    .release = NULL, // this is ok, because the module can not be unloaded
-                     // if the reference count is greater zero.
-    .sysfs_ops = &ec_sysfs_ops,
-    .default_attrs = ec_def_attrs
-};
-
-/** \endcond */
-
 /*****************************************************************************/
 
 struct kobject ec_kobj; /**< kobject for master module */
@@ -128,8 +101,7 @@
 
     // init kobject and add it to the hierarchy
     memset(&ec_kobj, 0x00, sizeof(struct kobject));
-    kobject_init(&ec_kobj);
-    ec_kobj.ktype = &ktype_ec_module;
+    kobject_init(&ec_kobj); // no ktype
     
     if (kobject_set_name(&ec_kobj, "ethercat")) {
         EC_ERR("Failed to set module kobject name.\n");
@@ -234,42 +206,6 @@
 /*****************************************************************************/
 
 /**
-   Formats module information for SysFS read access.
-   \return number of bytes written
-*/
-
-ssize_t ec_info(char *buffer /**< memory to store data */)
-{
-    off_t off = 0;
-
-    off += sprintf(buffer + off, "\nVersion: %s", ec_master_version_str);
-    off += sprintf(buffer + off, "\n");
-
-    return off;
-}
-
-/*****************************************************************************/
-
-/**
-   Formats attribute data for SysFS read access.
-   \return number of bytes to read
-*/
-
-ssize_t ec_show_attribute(struct kobject *kobj, /**< kobject */
-        struct attribute *attr, /**< attribute */
-        char *buffer /**< memory to store data */
-        )
-{
-    if (attr == &attr_info)
-        return ec_info(buffer);
-
-    return 0;
-}
-
-
-/*****************************************************************************/
-
-/**
    Gets a handle to a certain master.
    \returns pointer to master
 */
@@ -403,7 +339,7 @@
         )
 {
     ec_master_t *master;
-    unsigned int i;
+    char str[50]; // FIXME
 
     list_for_each_entry(master, &masters, list) {
         if (down_interruptible(&master->device_sem)) {
@@ -414,15 +350,12 @@
         if (ec_device_id_check(master->main_device_id, net_dev,
                     driver_name, device_index)) {
 
-            EC_INFO("Accepting device %s:%u (", driver_name, device_index);
-            for (i = 0; i < ETH_ALEN; i++) {
-                printk("%02X", net_dev->dev_addr[i]);
-                if (i < ETH_ALEN - 1) printk(":");
-            }
-            printk(") for master %u.\n", master->index);
+            ec_device_id_print(master->main_device_id, str);
+            EC_INFO("Accepting device %s for master %u.\n",
+                    str, master->index);
 
             if (master->device) {
-                EC_ERR("Master already has a device.\n");
+                EC_ERR("Master %u already has a device.\n", master->index);
                 goto out_up;
             }
             
@@ -473,22 +406,18 @@
 void ecdev_withdraw(ec_device_t *device /**< EtherCAT device */)
 {
     ec_master_t *master = device->master;
-    unsigned int i;
-
+    char str[50]; // FIXME
+
+    ec_device_id_print(master->main_device_id, str);
+    
+    EC_INFO("Master %u releasing main device %s.\n", master->index, str);
+    
     down(&master->device_sem);
-    
-    EC_INFO("Master %u releasing device ", master->index);
-    for (i = 0; i < ETH_ALEN; i++) {
-        printk("%02X", device->dev->dev_addr[i]);
-        if (i < ETH_ALEN - 1) printk(":");
-    }
-    printk(".\n");
-    
-    ec_device_clear(master->device);
-    kfree(master->device);
     master->device = NULL;
-    
     up(&master->device_sem);
+    
+    ec_device_clear(device);
+    kfree(device);
 }
 
 /*****************************************************************************/