Layed out PDO structures to own files.
authorFlorian Pose <fp@igh-essen.com>
Wed, 07 Mar 2007 11:46:02 +0000
changeset 627 4793ca94f082
parent 626 a5e838c30733
child 628 e94a16bc52ce
Layed out PDO structures to own files.
master/Kbuild
master/Makefile.am
master/pdo.c
master/pdo.h
master/slave.c
master/slave.h
--- a/master/Kbuild	Wed Mar 07 11:30:09 2007 +0000
+++ b/master/Kbuild	Wed Mar 07 11:46:02 2007 +0000
@@ -35,9 +35,9 @@
 
 obj-m := ec_master.o
 
-ec_master-objs := module.o master.o device.o device_id.o slave.o datagram.o \
-    domain.o mailbox.o canopen.o ethernet.o fsm_sii.o fsm_change.o fsm_coe.o \
-    fsm_slave.o fsm_master.o xmldev.o
+ec_master-objs := module.o master.o device.o device_id.o pdo.o slave.o \
+    datagram.o domain.o mailbox.o canopen.o ethernet.o fsm_sii.o fsm_change.o \
+    fsm_coe.o fsm_slave.o fsm_master.o xmldev.o
 
 ifeq ($(EC_DBG_IF),1)
 	ec_master-objs += debug.o
--- a/master/Makefile.am	Wed Mar 07 11:30:09 2007 +0000
+++ b/master/Makefile.am	Wed Mar 07 11:46:02 2007 +0000
@@ -38,6 +38,7 @@
 	debug.c	debug.h \
 	device.c device.h \
 	device_id.c device_id.h \
+	pdo.c pdo.h \
 	domain.c domain.h \
 	doxygen.c \
 	ethernet.c ethernet.h \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/pdo.c	Wed Mar 07 11:46:02 2007 +0000
@@ -0,0 +1,109 @@
+/******************************************************************************
+ *
+ *  $Id$
+ *
+ *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it
+ *  and/or modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  The IgH EtherCAT Master is distributed in the hope that it will be
+ *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  The right to use EtherCAT Technology is granted and comes free of
+ *  charge under condition of compatibility of product made by
+ *  Licensee. People intending to distribute/sell products based on the
+ *  code, have to sign an agreement to guarantee that products using
+ *  software based on IgH EtherCAT master stay compatible with the actual
+ *  EtherCAT specification (which are released themselves as an open
+ *  standard) as the (only) precondition to have the right to use EtherCAT
+ *  Technology, IP and trade marks.
+ *
+ *****************************************************************************/
+
+/**
+   \file
+   EtherCAT process data object methods.
+*/
+
+/*****************************************************************************/
+
+#include <linux/slab.h>
+
+#include "pdo.h"
+
+/*****************************************************************************/
+
+/**
+ * PDO constructor.
+ */
+
+void ec_pdo_init(ec_pdo_t *pdo /**< EtherCAT PDO */)
+{
+    pdo->name = NULL;
+    INIT_LIST_HEAD(&pdo->entries);
+}
+
+/*****************************************************************************/
+
+/**
+ * PDO destructor.
+ */
+
+void ec_pdo_clear(ec_pdo_t *pdo /**< EtherCAT PDO */)
+{
+    ec_pdo_entry_t *entry, *next;
+
+    // free all PDO entries
+    list_for_each_entry_safe(entry, next, &pdo->entries, list) {
+        list_del(&entry->list);
+        kfree(entry);
+    }
+}
+
+/*****************************************************************************/
+
+/**
+ * Makes a deep copy of a PDO.
+ */
+
+int ec_pdo_copy(ec_pdo_t *pdo, const ec_pdo_t *other_pdo)
+{
+    ec_pdo_entry_t *entry, *other_entry, *next;
+
+    // make flat copy
+    *pdo = *other_pdo;
+
+    INIT_LIST_HEAD(&pdo->entries);
+    list_for_each_entry(other_entry, &other_pdo->entries, list) {
+        if (!(entry = (ec_pdo_entry_t *)
+                    kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) {
+            EC_ERR("Failed to allocate memory for PDO entry copy.\n");
+            goto out_free;
+        }
+
+        *entry = *other_entry; // flat copy is sufficient
+        list_add_tail(&entry->list, &pdo->entries);
+    }
+
+    return 0;
+
+out_free:
+    list_for_each_entry_safe(entry, next, &pdo->entries, list) {
+        list_del(&entry->list);
+        kfree(entry);
+    }
+    return -1;
+}
+
+/*****************************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/pdo.h	Wed Mar 07 11:46:02 2007 +0000
@@ -0,0 +1,102 @@
+/******************************************************************************
+ *
+ *  $Id$
+ *
+ *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it
+ *  and/or modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  The IgH EtherCAT Master is distributed in the hope that it will be
+ *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  The right to use EtherCAT Technology is granted and comes free of
+ *  charge under condition of compatibility of product made by
+ *  Licensee. People intending to distribute/sell products based on the
+ *  code, have to sign an agreement to guarantee that products using
+ *  software based on IgH EtherCAT master stay compatible with the actual
+ *  EtherCAT specification (which are released themselves as an open
+ *  standard) as the (only) precondition to have the right to use EtherCAT
+ *  Technology, IP and trade marks.
+ *
+ *****************************************************************************/
+
+/**
+   \file
+   EtherCAT Process data object structure.
+*/
+
+/*****************************************************************************/
+
+#ifndef _EC_PDO_H_
+#define _EC_PDO_H_
+
+#include <linux/list.h>
+
+#include "globals.h"
+
+/*****************************************************************************/
+
+/**
+ * PDO type.
+ */
+
+typedef enum
+{
+    EC_RX_PDO, /**< Reveive PDO */
+    EC_TX_PDO /**< Transmit PDO */
+}
+ec_pdo_type_t;
+
+/*****************************************************************************/
+
+/**
+ * PDO description.
+ */
+
+typedef struct
+{
+    struct list_head list; /**< list item */
+    ec_pdo_type_t type; /**< PDO type */
+    uint16_t index; /**< PDO index */
+    int8_t sync_index; /**< assigned sync manager */
+    char *name; /**< PDO name */
+    struct list_head entries; /**< entry list */
+}
+ec_pdo_t;
+
+/*****************************************************************************/
+
+/**
+ * PDO entry description.
+ */
+
+typedef struct
+{
+    struct list_head list; /**< list item */
+    uint16_t index; /**< PDO entry index */
+    uint8_t subindex; /**< PDO entry subindex */
+    char *name; /**< entry name */
+    uint8_t bit_length; /**< entry length in bit */
+}
+ec_pdo_entry_t;
+
+/*****************************************************************************/
+
+void ec_pdo_init(ec_pdo_t *);
+void ec_pdo_clear(ec_pdo_t *);
+int ec_pdo_copy(ec_pdo_t *, const ec_pdo_t *);
+
+/*****************************************************************************/
+
+#endif
--- a/master/slave.c	Wed Mar 07 11:30:09 2007 +0000
+++ b/master/slave.c	Wed Mar 07 11:46:02 2007 +0000
@@ -242,7 +242,6 @@
 {
     ec_slave_t *slave;
     ec_pdo_t *pdo, *next_pdo;
-    ec_pdo_entry_t *entry, *next_ent;
     ec_sdo_data_t *sdodata, *next_sdodata;
     unsigned int i;
 
@@ -261,13 +260,7 @@
     // free all PDOs
     list_for_each_entry_safe(pdo, next_pdo, &slave->sii_pdos, list) {
         list_del(&pdo->list);
-
-        // free all PDO entries
-        list_for_each_entry_safe(entry, next_ent, &pdo->entries, list) {
-            list_del(&entry->list);
-            kfree(entry);
-        }
-
+        ec_pdo_clear(pdo);
         kfree(pdo);
     }
 
@@ -532,14 +525,12 @@
             return -1;
         }
 
-        INIT_LIST_HEAD(&pdo->entries);
+        ec_pdo_init(pdo);
         pdo->type = pdo_type;
-
         pdo->index = EC_READ_U16(data);
         entry_count = EC_READ_U8(data + 2);
         pdo->sync_index = EC_READ_U8(data + 3);
         pdo->name = ec_slave_sii_string(slave, EC_READ_U8(data + 5));
-
         list_add_tail(&pdo->list, &slave->sii_pdos);
 
         word_count -= 4;
@@ -555,7 +546,6 @@
             entry->subindex = EC_READ_U8(data + 2);
             entry->name = ec_slave_sii_string(slave, EC_READ_U8(data + 3));
             entry->bit_length = EC_READ_U8(data + 5);
-
             list_add_tail(&entry->list, &pdo->entries);
 
             word_count -= 4;
@@ -1071,8 +1061,8 @@
                                  /**< sync manager */
                                  )
 {
-    ec_pdo_t *pdo;
-    ec_pdo_entry_t *pdo_entry;
+    const ec_pdo_t *pdo;
+    const ec_pdo_entry_t *pdo_entry;
     unsigned int bit_size, byte_size;
 
     if (sync->length) return sync->length;
--- a/master/slave.h	Wed Mar 07 11:30:09 2007 +0000
+++ b/master/slave.h	Wed Mar 07 11:46:02 2007 +0000
@@ -48,6 +48,7 @@
 
 #include "globals.h"
 #include "datagram.h"
+#include "pdo.h"
 
 /*****************************************************************************/
 
@@ -122,52 +123,6 @@
 /*****************************************************************************/
 
 /**
-   PDO type.
-*/
-
-typedef enum
-{
-    EC_RX_PDO, /**< Reveive PDO */
-    EC_TX_PDO /**< Transmit PDO */
-}
-ec_pdo_type_t;
-
-/*****************************************************************************/
-
-/**
-   PDO description.
-*/
-
-typedef struct
-{
-    struct list_head list; /**< list item */
-    ec_pdo_type_t type; /**< PDO type */
-    uint16_t index; /**< PDO index */
-    uint8_t sync_index; /**< assigned sync manager */
-    char *name; /**< PDO name */
-    struct list_head entries; /**< entry list */
-}
-ec_pdo_t;
-
-/*****************************************************************************/
-
-/**
-   PDO entry description.
-*/
-
-typedef struct
-{
-    struct list_head list; /**< list item */
-    uint16_t index; /**< PDO index */
-    uint8_t subindex; /**< entry subindex */
-    char *name; /**< entry name */
-    uint8_t bit_length; /**< entry length in bit */
-}
-ec_pdo_entry_t;
-
-/*****************************************************************************/
-
-/**
    FMMU configuration.
 */