master/pdo_list.c
author Florian Pose <fp@igh-essen.com>
Fri, 06 Jun 2008 09:22:57 +0000
changeset 964 957f21465052
parent 932 dbcc06156a60
child 1049 91a0d7226e0b
permissions -rw-r--r--
Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
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
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    36
   EtherCAT Pdo list methods.
792
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
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    48
#include "pdo_list.h"
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    49
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    50
/*****************************************************************************/
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    51
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    52
/** Pdo list constructor.
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    53
 */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    54
void ec_pdo_list_init(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    55
        ec_pdo_list_t *pl /**< Pdo list. */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    56
        )
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    57
{
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    58
    INIT_LIST_HEAD(&pl->list);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    59
}
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    60
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    61
/*****************************************************************************/
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    62
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    63
/** Pdo list destructor.
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    64
 */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    65
void ec_pdo_list_clear(ec_pdo_list_t *pl /**< Pdo list. */)
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    66
{
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    67
    ec_pdo_list_clear_pdos(pl);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
}
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
/** 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
    73
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    74
void ec_pdo_list_clear_pdos(ec_pdo_list_t *pl /**< Pdo list. */)
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    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
    77
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    78
    list_for_each_entry_safe(pdo, next, &pl->list, list) {
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        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
    80
        ec_pdo_clear(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        kfree(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    }
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
814
a51f857b1b2d Renamed [PS]DO to [PS]do.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
    87
/** Calculates the total size of the mapped Pdo entries.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
 * \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
    90
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    91
uint16_t ec_pdo_list_total_size(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
    92
        const ec_pdo_list_t *pl /**< Pdo list. */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
        )
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
    unsigned int bit_size;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    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
    97
    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
    98
    uint16_t byte_size;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    bit_size = 0;
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   101
    list_for_each_entry(pdo, &pl->list, list) {
792
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_entry, &pdo->entries, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
            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
   104
        }
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
    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
   108
        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
   109
    else
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
        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
   111
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    return byte_size;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
}
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
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   117
/** Add a new Pdo to the list.
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   118
 *
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   119
 * \retval >0 Pointer to new Pdo.
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   120
 * \retval NULL No memory.
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   121
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   122
ec_pdo_t *ec_pdo_list_add_pdo(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   123
        ec_pdo_list_t *pl, /**< Pdo list. */
844
8839ba8bfeb4 Fixed 2 bugs in new Pdo mapping function.
Florian Pose <fp@igh-essen.com>
parents: 842
diff changeset
   124
        ec_direction_t dir, /**< Direction. */
8839ba8bfeb4 Fixed 2 bugs in new Pdo mapping function.
Florian Pose <fp@igh-essen.com>
parents: 842
diff changeset
   125
        uint16_t index /**< Pdo index. */
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   126
        )
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   127
{
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   128
    ec_pdo_t *pdo;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   129
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   130
    if (!(pdo = (ec_pdo_t *) kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) {
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   131
        EC_ERR("Failed to allocate memory for Pdo.\n");
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   132
        return NULL;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   133
    }
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   134
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   135
    ec_pdo_init(pdo);
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   136
    pdo->dir = dir;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   137
    pdo->index = index;
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   138
    list_add_tail(&pdo->list, &pl->list);
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   139
    return pdo;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   140
}
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   141
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   142
/*****************************************************************************/
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   143
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   144
/** Add the copy of an existing Pdo to the list.
792
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
 * \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
   147
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   148
int ec_pdo_list_add_pdo_copy(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   149
        ec_pdo_list_t *pl, /**< Pdo list. */
814
a51f857b1b2d Renamed [PS]DO to [PS]do.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   150
        const ec_pdo_t *pdo /**< Pdo to add. */
792
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
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
    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
   154
814
a51f857b1b2d Renamed [PS]DO to [PS]do.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   155
    // Pdo already mapped?
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   156
    list_for_each_entry(mapped_pdo, &pl->list, list) {
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
        if (mapped_pdo->index != pdo->index) continue;
814
a51f857b1b2d Renamed [PS]DO to [PS]do.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   158
        EC_ERR("Pdo 0x%04X is already mapped!\n", pdo->index);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
        return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    if (!(mapped_pdo = kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) {
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   163
        EC_ERR("Failed to allocate Pdo memory.\n");
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        return -1;
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
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    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
   168
        kfree(mapped_pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
        return -1;
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
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   172
    list_add_tail(&mapped_pdo->list, &pl->list);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    return 0;
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
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   178
/** Makes a deep copy of another Pdo list.
792
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
 * \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
   181
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   182
int ec_pdo_list_copy(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   183
        ec_pdo_list_t *pl, /**< Pdo list. */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   184
        const ec_pdo_list_t *other /**< Pdo list to copy from. */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
    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
   188
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   189
    ec_pdo_list_clear_pdos(pl);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
814
a51f857b1b2d Renamed [PS]DO to [PS]do.
Florian Pose <fp@igh-essen.com>
parents: 799
diff changeset
   191
    // Pdo already mapped?
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   192
    list_for_each_entry(other_pdo, &other->list, list) {
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   193
        if (ec_pdo_list_add_pdo_copy(pl, other_pdo))
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
            return -1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
    
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
    return 0;
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
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   202
/** Compares two Pdo lists.
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   203
 *
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   204
 * Only the list is compared, not the Pdo entries (i. e. the Pdo
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
 * configuration).
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
 *
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   207
 * \retval 1 The given Pdo lists are equal.
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   208
 * \retval 0 The given Pdo lists differ.
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   209
 */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   210
int ec_pdo_list_equal(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   211
        const ec_pdo_list_t *pl1, /**< First list. */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   212
        const ec_pdo_list_t *pl2 /**< Second list. */
792
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
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
    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
   216
    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
   217
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   218
    h1 = l1 = &pl1->list;
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   219
    h2 = l2 = &pl2->list;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    while (1) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
        l1 = l1->next;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
        l2 = l2->next;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
        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
   226
            return 0;
826
70aeae0de217 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   227
        if (l1 == h1) // both finished
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
            break;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
        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
   231
        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
   232
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
        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
   234
            return 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
    return 1;
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
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
/*****************************************************************************/
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   241
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   242
/** Finds a Pdo with the given index.
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   243
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   244
ec_pdo_t *ec_pdo_list_find_pdo(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   245
        const ec_pdo_list_t *pl, /**< Pdo list. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   246
        uint16_t index /**< Pdo index. */
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   247
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   248
{
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   249
    ec_pdo_t *pdo;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   250
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   251
    list_for_each_entry(pdo, &pl->list, list) {
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   252
        if (pdo->index != index)
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   253
            continue;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   254
        return pdo;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   255
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   256
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   257
    return NULL;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   258
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   259
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 793
diff changeset
   260
/*****************************************************************************/
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   261
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   262
/** Finds a Pdo with the given index and returns a const pointer.
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   263
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   264
const ec_pdo_t *ec_pdo_list_find_pdo_const(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   265
        const ec_pdo_list_t *pl, /**< Pdo list. */
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   266
        uint16_t index /**< Pdo index. */
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   267
        )
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   268
{
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   269
    const ec_pdo_t *pdo;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   270
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 844
diff changeset
   271
    list_for_each_entry(pdo, &pl->list, list) {
842
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   272
        if (pdo->index != index)
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   273
            continue;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   274
        return pdo;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   275
    }
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   276
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   277
    return NULL;
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   278
}
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   279
40e27e5a8dce Added ecrt_slave_config_pdo() and ecrt_slave_config_pdo_entry().
Florian Pose <fp@igh-essen.com>
parents: 839
diff changeset
   280
/*****************************************************************************/
931
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   281
932
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   282
/** Finds a Pdo via its position in the list.
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   283
 *
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   284
 * Const version.
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   285
 */
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   286
const ec_pdo_t *ec_pdo_list_find_pdo_by_pos_const(
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   287
        const ec_pdo_list_t *pl, /**< Pdo list. */
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   288
        unsigned int pos /**< Position in the list. */
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   289
        )
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   290
{
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   291
    const ec_pdo_t *pdo;
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   292
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   293
    list_for_each_entry(pdo, &pl->list, list) {
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   294
        if (pos--)
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   295
            continue;
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   296
        return pdo;
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   297
    }
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   298
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   299
    return NULL;
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   300
}
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   301
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   302
/*****************************************************************************/
dbcc06156a60 Added ec_pdo_list_find_by_pos_const().
Florian Pose <fp@igh-essen.com>
parents: 931
diff changeset
   303
931
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   304
/**
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   305
 */
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   306
unsigned int ec_pdo_list_count(
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   307
        const ec_pdo_list_t *pl /**< Pdo list. */
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   308
        )
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   309
{
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   310
    const ec_pdo_t *pdo;
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   311
    unsigned int num = 0;
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   312
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   313
    list_for_each_entry(pdo, &pl->list, list) {
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   314
        num++;
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   315
    }
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   316
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   317
    return num;
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   318
}
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   319
482bbaf3e76b Added ec_pdo_list_count().
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   320
/*****************************************************************************/