master/sync.c
author Florian Pose <fp@igh-essen.com>
Thu, 19 Jun 2008 10:18:58 +0000
changeset 1040 d2527675cdd5
parent 943 1d9e2663e087
child 1055 2be8918682fa
permissions -rw-r--r--
Disable use of CPU timestamp counter by default.
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    34
/** \file
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    35
 * EtherCAT sync manager methods.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    36
 */
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
/*****************************************************************************/
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "globals.h"
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "slave.h"
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "master.h"
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
    43
#include "pdo.h"
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "sync.h"
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/*****************************************************************************/
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    48
/** Constructor.
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
 */
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
void ec_sync_init(
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    51
        ec_sync_t *sync, /**< EtherCAT sync manager. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    52
        ec_slave_t *slave, /**< EtherCAT slave. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    53
        unsigned int index /**< Sync manager index. */
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        )
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
{
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
    sync->slave = slave;
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    sync->index = index;    
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
    59
    ec_pdo_list_init(&sync->pdos);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
    60
    sync->assign_source = EC_ASSIGN_NONE;
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
}
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
/*****************************************************************************/
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
873
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    65
/** Copy constructor.
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    66
 */
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    67
void ec_sync_init_copy(
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    68
        ec_sync_t *sync, /**< EtherCAT sync manager. */
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    69
        const ec_sync_t *other /**< Sync manager to copy from. */
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    70
        )
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    71
{
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    72
   sync->slave = other->slave;
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    73
   sync->index = other->index;
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    74
   sync->physical_start_address = other->physical_start_address;
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    75
   sync->length = other->length;
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    76
   sync->control_register = other->control_register;
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    77
   sync->enable = other->enable;
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    78
   
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
    79
   ec_pdo_list_init(&sync->pdos);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
    80
   ec_pdo_list_copy(&sync->pdos, &other->pdos);
873
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    81
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
    82
   sync->assign_source = other->assign_source;
873
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    83
}
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    84
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    85
/*****************************************************************************/
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
    86
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    87
/** Destructor.
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
 */
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
void ec_sync_clear(
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    90
        ec_sync_t *sync /**< EtherCAT sync manager. */
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
        )
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
{
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
    93
    ec_pdo_list_clear(&sync->pdos);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
    94
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
    95
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
    96
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
    97
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 838
diff changeset
    98
/** Initializes a sync manager configuration page with SII data.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
    99
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   100
 * The referenced memory (\a data) must be at least \a EC_SYNC_SIZE bytes.
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   101
 */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   102
void ec_sync_config(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   103
        const ec_sync_t *sync, /**< Sync manager. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   104
        uint16_t data_size, /**< Data size. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   105
        uint8_t *data /**> Configuration memory. */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   106
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   107
{
943
1d9e2663e087 Enable sync managers only if SII enable is set and size is greater zero.
Florian Pose <fp@igh-essen.com>
parents: 912
diff changeset
   108
    // enable only if SII enable is set and size is > 0.
1d9e2663e087 Enable sync managers only if SII enable is set and size is greater zero.
Florian Pose <fp@igh-essen.com>
parents: 912
diff changeset
   109
    uint16_t enable = sync->enable && data_size;
1d9e2663e087 Enable sync managers only if SII enable is set and size is greater zero.
Florian Pose <fp@igh-essen.com>
parents: 912
diff changeset
   110
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    if (sync->slave->master->debug_level) {
943
1d9e2663e087 Enable sync managers only if SII enable is set and size is greater zero.
Florian Pose <fp@igh-essen.com>
parents: 912
diff changeset
   112
        EC_DBG("SM%u: Addr 0x%04X, Size %3u, Ctrl 0x%02X, En %u\n",
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
               sync->index, sync->physical_start_address,
943
1d9e2663e087 Enable sync managers only if SII enable is set and size is greater zero.
Florian Pose <fp@igh-essen.com>
parents: 912
diff changeset
   114
               data_size, sync->control_register, enable);
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    }
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    EC_WRITE_U16(data,     sync->physical_start_address);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   118
    EC_WRITE_U16(data + 2, data_size);
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    EC_WRITE_U8 (data + 4, sync->control_register);
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    EC_WRITE_U8 (data + 5, 0x00); // status byte (read only)
943
1d9e2663e087 Enable sync managers only if SII enable is set and size is greater zero.
Florian Pose <fp@igh-essen.com>
parents: 912
diff changeset
   121
    EC_WRITE_U16(data + 6, enable);
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
}
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
/*****************************************************************************/
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   125
814
a51f857b1b2d Renamed [PS]DO to [PS]do.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   126
/** Adds a Pdo to the list of known mapped Pdos.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   127
 *
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 748
diff changeset
   128
 * \return 0 on success, else < 0
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   129
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   130
int ec_sync_add_pdo(
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   131
        ec_sync_t *sync, /**< EtherCAT sync manager. */
814
a51f857b1b2d Renamed [PS]DO to [PS]do.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   132
        const ec_pdo_t *pdo /**< Pdo to map. */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   133
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   134
{
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   135
    return ec_pdo_list_add_pdo_copy(&sync->pdos, pdo);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   136
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   137
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   138
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   139
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   140
/** Get direction covered by sync manager.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   141
 *
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   142
 * \return Direction covered by the given sync manager.
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   143
 */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   144
ec_direction_t ec_sync_direction(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   145
        const ec_sync_t *sync /**< EtherCAT sync manager. */
748
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   146
        )
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   147
{
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   148
    int index = sync->index;
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   149
912
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   150
    if (sync->slave->sii.sync_count != 1) {
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   151
        if (sync->slave && sync->slave->sii.mailbox_protocols) {
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   152
            index -= 2;
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   153
        }
748
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   154
912
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   155
        if (index < 0 || index > 1) {
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   156
            EC_WARN("ec_sync_get_direction(): invalid sync manager index.\n");
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   157
            return EC_DIR_OUTPUT;
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   158
        }
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   159
    } else { // sync_count == 1
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   160
        if (!list_empty(&sync->pdos.list)) {
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   161
            const ec_pdo_t *pdo =
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   162
                list_entry(sync->pdos.list.next, ec_pdo_t, list);
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   163
            return pdo->dir;
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   164
        }
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   165
        
748
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   166
    }
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   167
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 762
diff changeset
   168
    return (ec_direction_t) index;
748
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   169
}
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   170
6c8801bd547f Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents: 746
diff changeset
   171
/*****************************************************************************/