master/pdo_entry.c
author Florian Pose <fp@igh-essen.com>
Mon, 26 Jan 2009 11:51:53 +0000
changeset 1331 7cd33a77f926
parent 1327 4d179b06dd3c
child 1363 11c0b2caa253
permissions -rw-r--r--
merge -c1609 branches/stable-1.4: INSTALL, README.
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
 *
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
    22
 *  Using the EtherCAT technology and brand is permitted in compliance with
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
    23
 *  the 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
    24
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
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
   \file
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
   EtherCAT process data object entry methods.
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
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
/*****************************************************************************/
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
#include <linux/slab.h>
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
#include "pdo_entry.h"
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
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
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    40
/** PDO entry constructor.
933
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
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
    43
        ec_pdo_entry_t *entry /**< PDO entry. */
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
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
    entry->name = NULL;
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
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    51
/** PDO entry copy constructor.
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    52
 *
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    53
 * \retval  0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    54
 * \retval <0 Error code.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
 */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
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
    57
        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
    58
        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
    59
        )
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
    entry->index = other->index;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
    entry->subindex = other->subindex;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    entry->name = NULL;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    entry->bit_length = other->bit_length;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    66
    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
    67
}
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    71
/** PDO entry destructor.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
 */
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    73
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
    74
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    if (entry->name)
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        kfree(entry->name);
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
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    81
/** Set PDO entry name.
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    82
 *
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    83
 * \retval  0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    84
 * \retval <0 Error code.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
 */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
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
    87
        ec_pdo_entry_t *entry, /**< PDO entry. */
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        const char *name /**< New name. */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        )
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    unsigned int len;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    93
    if (entry->name && name && !strcmp(entry->name, name))
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    94
        return 0;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    95
    
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    if (entry->name)
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
        kfree(entry->name);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    if (name && (len = strlen(name))) {
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        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
   101
            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
   102
            return -ENOMEM;
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        }
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
        memcpy(entry->name, name, len + 1);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    } else {
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
        entry->name = NULL;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    }
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
    return 0;
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
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   114
/** Compares two PDO entries.
933
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
 * \retval 1 The entries are equal.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
 * \retval 0 The entries differ.
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
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
   120
        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
   121
        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
   122
        )
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    return entry1->index == entry2->index
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
        && entry1->subindex == entry2->subindex
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
        && entry1->bit_length == entry2->bit_length;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
}
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
/*****************************************************************************/