master/pdo_mapping.c
author Florian Pose <fp@igh-essen.com>
Thu, 21 Feb 2008 09:24:56 +0000
changeset 806 ab8daaabbe48
parent 799 068a58b96965
child 814 a51f857b1b2d
permissions -rw-r--r--
Renamed master module parameters, re-formatted code documentation.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT Pdo mapping methods.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/module.h>
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "globals.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "pdo.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "slave_config.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
#include "master.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
#include "pdo_mapping.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
/** Pdo mapping constructor.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
void ec_pdo_mapping_init(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        ec_pdo_mapping_t *pm /**< Pdo mapping. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    INIT_LIST_HEAD(&pm->pdos);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    pm->default_mapping = 1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
/** Pdo mapping destructor.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
void ec_pdo_mapping_clear(ec_pdo_mapping_t *pm /**< Pdo mapping. */)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    ec_pdo_mapping_clear_pdos(pm);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
/** Clears the list of mapped Pdos.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
void ec_pdo_mapping_clear_pdos(ec_pdo_mapping_t *pm /**< Pdo mapping. */)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    ec_pdo_t *pdo, *next;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    list_for_each_entry_safe(pdo, next, &pm->pdos, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        list_del_init(&pdo->list);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        ec_pdo_clear(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
        kfree(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
/** Calculates the total size of the mapped PDO entries.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
 * \retval Data size in byte.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
uint16_t ec_pdo_mapping_total_size(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
        const ec_pdo_mapping_t *pm /**< Pdo mapping. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    unsigned int bit_size;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    const ec_pdo_t *pdo;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    const ec_pdo_entry_t *pdo_entry;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    uint16_t byte_size;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    bit_size = 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    list_for_each_entry(pdo, &pm->pdos, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        list_for_each_entry(pdo_entry, &pdo->entries, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
            bit_size += pdo_entry->bit_length;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    if (bit_size % 8) // round up to full bytes
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        byte_size = bit_size / 8 + 1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    else
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
        byte_size = bit_size / 8;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    return byte_size;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
/** Adds a Pdo to the mapping.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
 * \return 0 on success, else < 0
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
int ec_pdo_mapping_add_pdo(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
        ec_pdo_mapping_t *pm, /**< Pdo mapping. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
        const ec_pdo_t *pdo /**< PDO to add. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    ec_pdo_t *mapped_pdo;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    // PDO already mapped?
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
    list_for_each_entry(mapped_pdo, &pm->pdos, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
        if (mapped_pdo->index != pdo->index) continue;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
        EC_ERR("PDO 0x%04X is already mapped!\n", pdo->index);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
        return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
    
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
    if (!(mapped_pdo = kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
        EC_ERR("Failed to allocate memory for PDO mapping.\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
        return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    if (ec_pdo_init_copy(mapped_pdo, pdo)) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
        kfree(mapped_pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
        return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    list_add_tail(&mapped_pdo->list, &pm->pdos);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    return 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
/** Add a Pdo to the mapping.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
 * The first call of this method will clear the default mapping.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
 * \retval 0 Success.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
 * \retval -1 Error.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
int ec_pdo_mapping_add_pdo_info(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
        ec_pdo_mapping_t *pm, /**< Pdo mapping. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
        const ec_pdo_info_t *pdo_info, /**< Pdo information. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
        const ec_slave_config_t *config /**< Slave configuration, to load
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
                                          default entries. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    unsigned int i;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    ec_pdo_t *pdo;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    ec_pdo_entry_t *entry;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
    const ec_pdo_entry_info_t *entry_info;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    if (pm->default_mapping) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
        pm->default_mapping = 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
        ec_pdo_mapping_clear_pdos(pm);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    if (!(pdo = (ec_pdo_t *) kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
        EC_ERR("Failed to allocate memory for Pdo.\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        goto out_return;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
    ec_pdo_init(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
    pdo->dir = pdo_info->dir;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    pdo->index = pdo_info->index;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
    if (config->master->debug_level)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
        EC_INFO("Adding Pdo 0x%04X to mapping.\n", pdo->index);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
793
3b297ff8284f Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   188
    if (pdo_info->n_entries && pdo_info->entries) { // configuration provided
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
        if (config->master->debug_level)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
            EC_INFO("  Pdo configuration provided.\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
        for (i = 0; i < pdo_info->n_entries; i++) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
            entry_info = &pdo_info->entries[i];
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
            if (!(entry = kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
                EC_ERR("Failed to allocate memory for PDO entry.\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
                goto out_free;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
            }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
            ec_pdo_entry_init(entry);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
            entry->index = entry_info->index;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
            entry->subindex = entry_info->subindex;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
            entry->bit_length = entry_info->bit_length;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
            list_add_tail(&entry->list, &pdo->entries);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
    } else { // use default Pdo configuration
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
        if (config->master->debug_level)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
            EC_INFO("  Using default Pdo configuration.\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
        if (config->slave) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
            ec_sync_t *sync;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
            ec_pdo_t *default_pdo;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
            if ((sync = ec_slave_get_pdo_sync(config->slave, pdo->dir))) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
                list_for_each_entry(default_pdo, &sync->mapping.pdos, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
                    if (default_pdo->index != pdo->index)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
                        continue;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
                    if (config->master->debug_level)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
                        EC_INFO("  Found Pdo name \"%s\".\n",
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
                                default_pdo->name);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
                    // try to take Pdo name from mapped one
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
                    if (ec_pdo_set_name(pdo, default_pdo->name))
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
                        goto out_free;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
                    // copy entries (= default Pdo configuration)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
                    if (ec_pdo_copy_entries(pdo, default_pdo))
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
                        goto out_free;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
                    if (config->master->debug_level) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
                        const ec_pdo_entry_t *entry;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
                        list_for_each_entry(entry, &pdo->entries, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
                            EC_INFO("    Entry 0x%04X:%u.\n",
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
                                    entry->index, entry->subindex);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
                        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
                    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
                }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
            } else {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
                EC_WARN("Slave %u does not provide a default Pdo"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
                        " configuration!\n", config->slave->ring_position);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
            }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
        } else {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
            EC_WARN("Failed to load default Pdo configuration for %u:%u:"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
                    " Slave not found.\n", config->alias, config->position);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
    list_add_tail(&pdo->list, &pm->pdos);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
    return 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
out_free:
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
    ec_pdo_clear(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    kfree(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
out_return:
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
    return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
/** Makes a deep copy of another Pdo mapping.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
 * \return 0 on success, else < 0
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
int ec_pdo_mapping_copy(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
        ec_pdo_mapping_t *pm, /**< Pdo mapping. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
        const ec_pdo_mapping_t *other /**< PDO mapping to copy from. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    ec_pdo_t *other_pdo;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    ec_pdo_mapping_clear_pdos(pm);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
    // PDO already mapped?
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    list_for_each_entry(other_pdo, &other->pdos, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
        if (ec_pdo_mapping_add_pdo(pm, other_pdo))
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
            return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
    
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
    return 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
/** Compares two Pdo mappings.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
 * Only the mapping is compared, not the Pdo entries (i. e. the Pdo
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
 * configuration).
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
 * \retval 1 The given Pdo mappings are equal.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
 * \retval 0 The given Pdo mappings differ.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
int ec_pdo_mapping_equal(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
        const ec_pdo_mapping_t *pm1, /**< First mapping. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
        const ec_pdo_mapping_t *pm2 /**< Second mapping. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
    const struct list_head *h1, *h2, *l1, *l2;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
    const ec_pdo_t *p1, *p2;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
    h1 = l1 = &pm1->pdos;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
    h2 = l2 = &pm2->pdos;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
    while (1) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
        l1 = l1->next;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
        l2 = l2->next;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
        if ((l1 == h1) ^ (l2 == h2)) // unequal lengths
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
            return 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
        if (l1 == h1 && l2 == h2) // both finished
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
            break;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
        p1 = list_entry(l1, ec_pdo_t, list);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
        p2 = list_entry(l2, ec_pdo_t, list);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
        if (p1->index != p2->index)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
            return 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
    return 1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
/*****************************************************************************/
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   320
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   321
/** Finds a Pdo with the given index.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   322
 */
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   323
const ec_pdo_t *ec_pdo_mapping_find_pdo(
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   324
        const ec_pdo_mapping_t *pm, /**< Pdo mapping. */
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   325
        uint16_t index /**< Pdo index. */
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   326
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   327
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   328
    ec_pdo_t *pdo;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   329
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   330
    list_for_each_entry(pdo, &pm->pdos, list) {
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   331
        if (pdo->index != index)
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   332
            continue;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   333
        return pdo;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   334
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   335
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   336
    return NULL;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   337
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   338
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   339
/*****************************************************************************/