master/pdo_entry.c
author Florian Pose <fp@igh-essen.com>
Mon, 19 Jan 2009 14:46:55 +0000
branch1.4-foe
changeset 1709 63e4bc918640
parent 1686 e206f4485f60
permissions -rw-r--r--
Implemented going to bootstrap state BOOT.
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    22
 *  Using the EtherCAT technology and brand is permitted in compliance with
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1186
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
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
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(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
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
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    51
/** PDO entry copy constructor.
933
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
int ec_pdo_entry_init_copy(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    54
        ec_pdo_entry_t *entry, /**< PDO entry. */
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    55
        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
    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
    entry->index = other->index;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    entry->subindex = other->subindex;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    entry->name = NULL;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
    entry->bit_length = other->bit_length;
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
    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
    64
        return -1;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    return 0;
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
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    71
/** PDO entry destructor.
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
 */
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
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
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    81
/** Set PDO entry name.
933
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
int ec_pdo_entry_set_name(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    84
        ec_pdo_entry_t *entry, /**< PDO entry. */
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
        const char *name /**< New name. */
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
    unsigned int len;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    90
    if (entry->name && name && !strcmp(entry->name, name))
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    91
        return 0;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
    92
    
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    if (entry->name)
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
        kfree(entry->name);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    if (name && (len = strlen(name))) {
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
        if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    98
            EC_ERR("Failed to allocate PDO entry name.\n");
933
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
            return -1;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        }
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
        memcpy(entry->name, name, len + 1);
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    } else {
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        entry->name = NULL;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    }
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    return 0;
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
/*****************************************************************************/
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   111
/** Compares two PDO entries.
933
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
 * \retval 1 The entries are equal.
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
 * \retval 0 The entries differ.
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
int ec_pdo_entry_equal(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   117
        const ec_pdo_entry_t *entry1, /**< First PDO entry. */
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   118
        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
   119
        )
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
{
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    return entry1->index == entry2->index
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
        && entry1->subindex == entry2->subindex
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
        && entry1->bit_length == entry2->bit_length;
618ab9e03321 Separated Pdo and Pdo entry classes.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
}
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
/*****************************************************************************/