master/sync.c
author Florian Pose <fp@igh-essen.com>
Thu, 02 Oct 2008 09:56:39 +0000
branchstable-1.3
changeset 1760 036f19bde00b
parent 1753 124eb40a2818
permissions -rw-r--r--
Fixed lsec for terminals that do not support getting the terminal width.
1744
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT sync manager methods.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "globals.h"
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "slave.h"
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "master.h"
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "pdo.h"
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "sync.h"
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
/*****************************************************************************/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
/**
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
 * Constructor.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
 */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
void ec_sync_init(
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        ec_sync_t *sync, /**< EtherCAT sync manager */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        ec_slave_t *slave, /**< EtherCAT slave */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        unsigned int index /**< sync manager index */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        )
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
{
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    sync->slave = slave;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    sync->index = index;    
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
    sync->est_length = 0;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    INIT_LIST_HEAD(&sync->pdos);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    sync->alt_mapping = 0;
1749
696dd9f22777 merge -r972:974 trunk -> branches/stable-1.3 (mapping source, new slave info file)
Florian Pose <fp@igh-essen.com>
parents: 1746
diff changeset
    65
    sync->mapping_source = EC_SYNC_MAPPING_NONE;
1744
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
}
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
/*****************************************************************************/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
/**
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
 * Destructor.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
 */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
void ec_sync_clear(
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
        ec_sync_t *sync /**< EtherCAT sync manager */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        )
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
{
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    ec_sync_clear_pdos(sync);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
}
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
/*****************************************************************************/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
/**
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
 * Calculates the size of a sync manager by evaluating PDO sizes.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
 * \return sync manager size
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
 */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
uint16_t ec_sync_size(
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        const ec_sync_t *sync /**< sync manager */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
        )
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
{
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    const ec_pdo_t *pdo;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    const ec_pdo_entry_t *pdo_entry;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    unsigned int bit_size, byte_size;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
1753
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
    96
    // if an estimated length is specified, return it
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
    97
    if (sync->est_length)
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
    98
        return sync->est_length;
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
    99
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   100
    // calculate total Pdo size in bit
1744
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    bit_size = 0;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    list_for_each_entry(pdo, &sync->pdos, list) {
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        list_for_each_entry(pdo_entry, &pdo->entries, list) {
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
            bit_size += pdo_entry->bit_length;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
        }
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    }
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
1753
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   108
    // bits to bytes
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   109
    if (bit_size % 8) {
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   110
        // round up to full bytes
1744
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
        byte_size = bit_size / 8 + 1;
1753
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   112
    } else {
1744
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
        byte_size = bit_size / 8;
1753
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   114
    }
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   115
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   116
    if (byte_size) {
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   117
        // return total Pdo size, if there are Pdos assigned
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   118
        return byte_size;
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   119
    } else {
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   120
        // return sync manager default size, if no Pdos are assigned
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   121
        return sync->length;
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   122
    }
1744
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
}
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
/*****************************************************************************/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
/**
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
   Initializes a sync manager configuration page with EEPROM data.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
   The referenced memory (\a data) must be at least EC_SYNC_SIZE bytes.
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
*/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
void ec_sync_config(
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
        const ec_sync_t *sync, /**< sync manager */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
        uint8_t *data /**> configuration memory */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
        )
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
{
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    size_t sync_size = ec_sync_size(sync);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    if (sync->slave->master->debug_level) {
1753
124eb40a2818 Sync manager size is always the total size of the assigned Pdos, if
Florian Pose <fp@igh-essen.com>
parents: 1749
diff changeset
   140
        EC_DBG("SM%u: Addr 0x%04X, Size %3u, Ctrl 0x%02X, En %u\n",
1744
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
               sync->index, sync->physical_start_address,
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
               sync_size, sync->control_register, sync->enable);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    }
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    EC_WRITE_U16(data,     sync->physical_start_address);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    EC_WRITE_U16(data + 2, sync_size);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    EC_WRITE_U8 (data + 4, sync->control_register);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    EC_WRITE_U8 (data + 5, 0x00); // status byte (read only)
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    EC_WRITE_U16(data + 6, sync->enable ? 0x0001 : 0x0000); // enable
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
}
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
/*****************************************************************************/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
/**
1746
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   155
 * Adds a PDO to the list of known mapped PDOs.
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   156
 * \return 0 on success, else < 0
1744
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
 */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
int ec_sync_add_pdo(
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
        ec_sync_t *sync, /**< EtherCAT sync manager */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
        const ec_pdo_t *pdo /**< PDO to map */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
        )
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
{
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    ec_pdo_t *mapped_pdo;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    // PDO already mapped?
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    list_for_each_entry(mapped_pdo, &sync->pdos, list) {
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
        if (mapped_pdo->index != pdo->index) continue;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
        EC_ERR("PDO 0x%04X is already mapped!\n", pdo->index);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
        return -1;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    }
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
    
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    if (!(mapped_pdo = kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) {
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
        EC_ERR("Failed to allocate memory for PDO mapping.\n");
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
        return -1;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    }
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
    ec_pdo_init(mapped_pdo);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
    if (ec_pdo_copy(mapped_pdo, pdo)) {
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
        ec_pdo_clear(mapped_pdo);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
        kfree(mapped_pdo);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
        return -1;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    }
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
    // set appropriate sync manager index
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
    mapped_pdo->sync_index = sync->index;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
    list_add_tail(&mapped_pdo->list, &sync->pdos);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    return 0;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
}
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
/*****************************************************************************/
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
/**
1746
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   195
 * Clears the list of known mapped PDOs.
1744
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
 */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
void ec_sync_clear_pdos(
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
        ec_sync_t *sync /**< EtherCAT sync manager */
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
        )
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
{
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
    ec_pdo_t *pdo, *next;
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
    // free all mapped PDOs
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
    list_for_each_entry_safe(pdo, next, &sync->pdos, list) {
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
        list_del(&pdo->list);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
        ec_pdo_clear(pdo);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
        kfree(pdo);
7bc131b92039 MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
    }
1746
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   210
}
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   211
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   212
/*****************************************************************************/
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   213
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   214
/**
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   215
 * \return Type of PDOs covered by the given sync manager.
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   216
 */
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   217
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   218
ec_pdo_type_t ec_sync_get_pdo_type(
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   219
        const ec_sync_t *sync /**< EtherCAT sync manager */
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   220
        )
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   221
{
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   222
    int index = sync->index;
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   223
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   224
    if (sync->slave && sync->slave->sii_mailbox_protocols) {
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   225
        index -= 2;
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   226
    }
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   227
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   228
    if (index < 0 || index > 1) {
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   229
        EC_WARN("ec_sync_get_pdo_type(): invalid sync manager index.\n");
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   230
        return EC_RX_PDO;
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   231
    }
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   232
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   233
    return (ec_pdo_type_t) index;
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   234
}
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   235
72e7507b3f1b merge -r931:HEAD svn://yak/vol/projekte/msr_messen_steuern_regeln/ethercat/rep/trunk .
Florian Pose <fp@igh-essen.com>
parents: 1744
diff changeset
   236
/*****************************************************************************/