master/pdo_entry.c
author Florian Pose <fp@igh-essen.com>
Fri, 03 Mar 2017 16:00:35 +0100
changeset 2675 5944c9a2649d
parent 2589 2b9c78543663
permissions -rw-r--r--
Display alias adressing in graph.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    11
 *  published by the Free Software Foundation.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    16
 *  Public License for more details.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/**
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
   \file
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
   EtherCAT process data object entry methods.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
*/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <linux/slab.h>
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "pdo_entry.h"
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    43
/** PDO entry constructor.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
 */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
void ec_pdo_entry_init(
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    46
        ec_pdo_entry_t *entry /**< PDO entry. */
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
        )
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    entry->name = NULL;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
}
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    54
/** PDO entry copy constructor.
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    55
 *
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    56
 * \retval  0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    57
 * \retval <0 Error code.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
 */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
int ec_pdo_entry_init_copy(
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    60
        ec_pdo_entry_t *entry, /**< PDO entry. */
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    61
        const ec_pdo_entry_t *other /**< PDO entry to copy from. */
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
        )
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    entry->index = other->index;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    entry->subindex = other->subindex;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    entry->name = NULL;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    entry->bit_length = other->bit_length;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    69
    return ec_pdo_entry_set_name(entry, other->name);
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
}
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    74
/** PDO entry destructor.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
 */
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    76
void ec_pdo_entry_clear(ec_pdo_entry_t *entry /**< PDO entry. */)
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    if (entry->name)
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        kfree(entry->name);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
}
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    84
/** Set PDO entry name.
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    85
 *
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    86
 * \retval  0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    87
 * \retval <0 Error code.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
 */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
int ec_pdo_entry_set_name(
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    90
        ec_pdo_entry_t *entry, /**< PDO entry. */
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
        const char *name /**< New name. */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
        )
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    unsigned int len;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    96
    if (entry->name && name && !strcmp(entry->name, name))
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    97
        return 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    98
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    if (entry->name)
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        kfree(entry->name);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    if (name && (len = strlen(name))) {
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   104
            EC_ERR("Failed to allocate PDO entry name.\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   105
            return -ENOMEM;
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
        }
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
        memcpy(entry->name, name, len + 1);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    } else {
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        entry->name = NULL;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    }
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    return 0;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
}
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   117
/** Compares two PDO entries.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
 * \retval 1 The entries are equal.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
 * \retval 0 The entries differ.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
 */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
int ec_pdo_entry_equal(
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   123
        const ec_pdo_entry_t *entry1, /**< First PDO entry. */
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   124
        const ec_pdo_entry_t *entry2 /**< Second PDO entry. */
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
        )
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    return entry1->index == entry2->index
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
        && entry1->subindex == entry2->subindex
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
        && entry1->bit_length == entry2->bit_length;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
}
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
/*****************************************************************************/