master/pdo_entry.c
author Florian Pose <fp@igh-essen.com>
Wed, 27 Aug 2008 08:06:58 +0000
branchstable-1.4
changeset 1632 31196835d181
parent 1186 ff481f097c97
child 1313 ed15eef57d5c
child 1685 399ef727bf62
permissions -rw-r--r--
Version 1.4.0-rc2.
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
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
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
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  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
    22
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
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
/**
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT process data object entry methods.
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
/*****************************************************************************/
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
#include <linux/slab.h>
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "pdo_entry.h"
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
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
/** Pdo entry constructor.
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
void ec_pdo_entry_init(
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
        ec_pdo_entry_t *entry /**< Pdo entry. */
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
    entry->name = NULL;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
}
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
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
/** Pdo entry copy constructor.
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
int ec_pdo_entry_init_copy(
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
        ec_pdo_entry_t *entry, /**< Pdo entry. */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
        const ec_pdo_entry_t *other /**< Pdo entry to copy from. */
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
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    entry->index = other->index;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    entry->subindex = other->subindex;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    entry->name = NULL;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    entry->bit_length = other->bit_length;
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
    if (ec_pdo_entry_set_name(entry, other->name))
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
        return -1;
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
    return 0;
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
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
/*****************************************************************************/
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
/** Pdo entry destructor.
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
void ec_pdo_entry_clear(ec_pdo_entry_t *entry /**< Pdo entry. */)
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
    if (entry->name)
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
        kfree(entry->name);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
}
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
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
/** Set Pdo entry 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
int ec_pdo_entry_set_name(
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
        ec_pdo_entry_t *entry, /**< Pdo entry. */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
        const char *name /**< New name. */
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
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    unsigned int len;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    97
    if (entry->name && name && !strcmp(entry->name, name))
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    98
        return 0;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    99
    
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    if (entry->name)
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
        kfree(entry->name);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    if (name && (len = strlen(name))) {
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
        if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
            EC_ERR("Failed to allocate Pdo entry name.\n");
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
            return -1;
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
        memcpy(entry->name, name, len + 1);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
    } else {
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
        entry->name = NULL;
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
    return 0;
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
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
/** Compares two Pdo entries.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
 *
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
 * \retval 1 The entries are equal.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
 * \retval 0 The entries differ.
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
int ec_pdo_entry_equal(
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
        const ec_pdo_entry_t *entry1, /**< First Pdo entry. */
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
        const ec_pdo_entry_t *entry2 /**< Second Pdo entry. */
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
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    return entry1->index == entry2->index
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
        && entry1->subindex == entry2->subindex
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
        && entry1->bit_length == entry2->bit_length;
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
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
/*****************************************************************************/