master/pdo.c
author Florian Pose <fp@igh-essen.com>
Mon, 26 Jan 2009 12:04:49 +0000
branch1.4-foe
changeset 1713 df6cdc79ea56
parent 1686 e206f4485f60
permissions -rw-r--r--
Removed todo line.
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
4793ca94f082 Layed out PDO structures to own files.
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
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
4793ca94f082 Layed out PDO structures to own files.
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.
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
    12
 *
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.
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
    17
 *
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
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4793ca94f082 Layed out PDO structures to own files.
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.
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *****************************************************************************/
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
/**
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
   \file
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
   EtherCAT process data object methods.
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
*/
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
/*****************************************************************************/
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <linux/slab.h>
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include "pdo.h"
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
/*****************************************************************************/
4793ca94f082 Layed out PDO structures to own files.
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 constructor.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    41
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    42
void ec_pdo_init(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    43
        ec_pdo_t *pdo /**< EtherCAT PDO */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    44
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    45
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    46
    pdo->sync_index = -1; // not assigned 
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    pdo->name = NULL;
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    INIT_LIST_HEAD(&pdo->entries);
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
}
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
/*****************************************************************************/
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    53
/** PDO copy constructor.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    54
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    55
int ec_pdo_init_copy(ec_pdo_t *pdo, const ec_pdo_t *other_pdo)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    56
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    57
    pdo->index = other_pdo->index;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    58
    pdo->sync_index = other_pdo->sync_index;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    59
    pdo->name = NULL;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    60
    INIT_LIST_HEAD(&pdo->entries);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    61
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    62
    if (ec_pdo_set_name(pdo, other_pdo->name))
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    63
        goto out_return;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    64
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    65
    if (ec_pdo_copy_entries(pdo, other_pdo))
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    66
        goto out_clear;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    67
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    68
    return 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    69
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    70
out_clear:
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    71
    ec_pdo_clear(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    72
out_return:
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    73
    return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    74
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    75
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    76
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    77
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    78
/** PDO destructor.
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    79
 */
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    80
void ec_pdo_clear(ec_pdo_t *pdo /**< EtherCAT PDO. */)
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    82
    if (pdo->name)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    83
        kfree(pdo->name);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    84
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    85
    ec_pdo_clear_entries(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    86
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    87
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    88
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    89
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    90
/** Clear PDO entry list.
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    91
 */
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    92
void ec_pdo_clear_entries(ec_pdo_t *pdo /**< EtherCAT PDO. */)
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    93
{
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    ec_pdo_entry_t *entry, *next;
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    96
    // free all PDO entries
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    list_for_each_entry_safe(entry, next, &pdo->entries, list) {
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
        list_del(&entry->list);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
    99
        ec_pdo_entry_clear(entry);
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        kfree(entry);
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    }
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
}
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
/*****************************************************************************/
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   106
/** Set PDO name.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   107
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   108
int ec_pdo_set_name(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   109
        ec_pdo_t *pdo, /**< PDO. */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   110
        const char *name /**< New name. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   111
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   112
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   113
    unsigned int len;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   114
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   115
    if (pdo->name && name && !strcmp(pdo->name, name))
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   116
        return 0;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   117
    
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   118
    if (pdo->name)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   119
        kfree(pdo->name);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   120
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   121
    if (name && (len = strlen(name))) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   122
        if (!(pdo->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   123
            EC_ERR("Failed to allocate PDO name.\n");
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   124
            return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   125
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   126
        memcpy(pdo->name, name, len + 1);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   127
    } else {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   128
        pdo->name = NULL;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   129
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   130
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   131
    return 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   132
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   133
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   134
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   135
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   136
/** Add a new PDO entry to the configuration.
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   137
 */
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   138
ec_pdo_entry_t *ec_pdo_add_entry(
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   139
        ec_pdo_t *pdo,
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   140
        uint16_t index,
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   141
        uint8_t subindex,
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   142
        uint8_t bit_length
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   143
        )
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   144
{
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   145
    ec_pdo_entry_t *entry;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   146
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   147
    if (!(entry = kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) {
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   148
        EC_ERR("Failed to allocate memory for PDO entry.\n");
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   149
        return NULL;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   150
    }
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   151
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   152
    ec_pdo_entry_init(entry);
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   153
    entry->index = index;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   154
    entry->subindex = subindex;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   155
    entry->bit_length = bit_length;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   156
    list_add_tail(&entry->list, &pdo->entries);
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   157
    return entry;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   158
}
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   159
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   160
/*****************************************************************************/
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 826
diff changeset
   161
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   162
/** Copy PDO entries from another PDO.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   163
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   164
int ec_pdo_copy_entries(ec_pdo_t *pdo, const ec_pdo_t *other)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   165
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   166
    ec_pdo_entry_t *entry, *other_entry;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   167
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   168
    ec_pdo_clear_entries(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   169
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   170
    list_for_each_entry(other_entry, &other->entries, list) {
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
        if (!(entry = (ec_pdo_entry_t *)
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
                    kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) {
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   173
            EC_ERR("Failed to allocate memory for PDO entry copy.\n");
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   174
            return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   175
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   176
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   177
        if (ec_pdo_entry_init_copy(entry, other_entry)) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   178
            kfree(entry);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   179
            return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   180
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   181
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
        list_add_tail(&entry->list, &pdo->entries);
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    }
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
    return 0;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   186
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   187
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   188
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 627
diff changeset
   189
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   190
/** Compares the entries of two PDOs.
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   191
 *
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   192
 * \retval 1 The entries of the given PDOs are equal.
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   193
 * \retval 0 The entries of the given PDOs differ.
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   194
 */
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   195
int ec_pdo_equal_entries(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   196
        const ec_pdo_t *pdo1, /**< First PDO. */
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   197
        const ec_pdo_t *pdo2 /**< Second PDO. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   198
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   199
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   200
    const struct list_head *head1, *head2, *item1, *item2;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   201
    const ec_pdo_entry_t *entry1, *entry2;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   202
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   203
    head1 = item1 = &pdo1->entries;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   204
    head2 = item2 = &pdo2->entries;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   205
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   206
    while (1) {
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   207
        item1 = item1->next;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   208
        item2 = item2->next;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   209
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   210
        if ((item1 == head1) ^ (item2 == head2)) // unequal lengths
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   211
            return 0;
826
70aeae0de217 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   212
        if (item1 == head1) // both finished
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   213
            break;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   214
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   215
        entry1 = list_entry(item1, ec_pdo_entry_t, list);
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   216
        entry2 = list_entry(item2, ec_pdo_entry_t, list);
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   217
        if (!ec_pdo_entry_equal(entry1, entry2))
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   218
            return 0;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   219
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   220
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   221
    return 1;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   222
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   223
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   224
/*****************************************************************************/
934
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   225
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   226
/** Get the number of PDO entries.
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   227
 *
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   228
 * \return Number of PDO entries.
934
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   229
 */
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   230
unsigned int ec_pdo_entry_count(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   231
        const ec_pdo_t *pdo /**< PDO. */
934
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   232
        )
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   233
{
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   234
    const ec_pdo_entry_t *entry;
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   235
    unsigned int num = 0;
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   236
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   237
    list_for_each_entry(entry, &pdo->entries, list) {
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   238
        num++;
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   239
    }
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   240
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   241
    return num;
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   242
}
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   243
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   244
/*****************************************************************************/
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   245
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   246
/** Finds a PDO entry via its position in the list.
934
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   247
 *
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   248
 * Const version.
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   249
 */
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   250
const ec_pdo_entry_t *ec_pdo_find_entry_by_pos_const(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   251
        const ec_pdo_t *pdo, /**< PDO. */
934
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   252
        unsigned int pos /**< Position in the list. */
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   253
        )
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   254
{
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   255
    const ec_pdo_entry_t *entry;
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   256
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   257
    list_for_each_entry(entry, &pdo->entries, list) {
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   258
        if (pos--)
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   259
            continue;
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   260
        return entry;
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   261
    }
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   262
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   263
    return NULL;
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   264
}
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   265
96241b092fac Added entry access functions.
Florian Pose <fp@igh-essen.com>
parents: 933
diff changeset
   266
/*****************************************************************************/