master/datagram_pair.c
author Florian Pose <fp@igh-essen.com>
Wed, 06 Feb 2013 17:48:54 +0100
branchstable-1.5
changeset 2509 232831b6249b
parent 2453 d461b1f07296
child 2522 ec403cf308eb
permissions -rw-r--r--
More detailed output of configure script.
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/**
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
   \file
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
   EtherCAT datagram pair methods.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
*/
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    37
#include <linux/slab.h>
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    38
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    39
#include "master.h"
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "datagram_pair.h"
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
/*****************************************************************************/
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
/** Datagram pair constructor.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
 */
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    46
int ec_datagram_pair_init(
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    47
        ec_datagram_pair_t *pair, /**< Datagram pair. */
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    48
        ec_domain_t *domain, /**< Parent domain. */
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    49
        uint32_t logical_offset,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    50
        uint8_t *data,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    51
        size_t data_size, /**< Data size. */
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    52
        const unsigned int used[] /**< input/output use count. */
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        )
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
{
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2368
diff changeset
    55
    ec_device_index_t dev_idx;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    56
    int ret;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    INIT_LIST_HEAD(&pair->list);
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    59
    pair->domain = domain;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    61
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    62
            dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    63
        ec_datagram_init(&pair->datagrams[dev_idx]);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    64
        snprintf(pair->datagrams[dev_idx].name,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    65
                EC_DATAGRAM_NAME_SIZE, "domain%u-%u-%s", domain->index,
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    66
                logical_offset, ec_device_names[dev_idx != 0]);
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2368
diff changeset
    67
        pair->datagrams[dev_idx].device_index = dev_idx;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    69
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    70
    pair->expected_working_counter = 0U;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    71
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    72
    for (dev_idx = EC_DEVICE_BACKUP;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    73
            dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    74
        /* backup datagrams have their own memory */
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    75
        ret = ec_datagram_prealloc(&pair->datagrams[dev_idx], data_size);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    76
        if (ret) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    77
            goto out_datagrams;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    78
        }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    79
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    80
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    81
#if EC_MAX_NUM_DEVICES > 1
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    82
    if (!(pair->send_buffer = kmalloc(data_size, GFP_KERNEL))) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    83
        EC_MASTER_ERR(domain->master,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    84
                "Failed to allocate domain send buffer!\n");
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    85
        ret = -ENOMEM;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    86
        goto out_datagrams;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    87
    }
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    88
#endif
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    89
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    90
    /* The ec_datagram_lxx() calls below can not fail, because either the
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    91
     * datagram has external memory or it is preallocated. */
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    92
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    93
    if (used[EC_DIR_OUTPUT] && used[EC_DIR_INPUT]) { // inputs and outputs
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    94
        ec_datagram_lrw_ext(&pair->datagrams[EC_DEVICE_MAIN],
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    95
                logical_offset, data_size, data);
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    96
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    97
        for (dev_idx = EC_DEVICE_BACKUP;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    98
                dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    99
            ec_datagram_lrw(&pair->datagrams[dev_idx],
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   100
                    logical_offset, data_size);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   101
        }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   102
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   103
        // If LRW is used, output FMMUs increment the working counter by 2,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   104
        // while input FMMUs increment it by 1.
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   105
        pair->expected_working_counter =
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   106
            used[EC_DIR_OUTPUT] * 2 + used[EC_DIR_INPUT];
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   107
    } else if (used[EC_DIR_OUTPUT]) { // outputs only
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   108
        ec_datagram_lwr_ext(&pair->datagrams[EC_DEVICE_MAIN],
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   109
                logical_offset, data_size, data);
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   110
        for (dev_idx = EC_DEVICE_BACKUP;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   111
                dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   112
            ec_datagram_lwr(&pair->datagrams[dev_idx],
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   113
                    logical_offset, data_size);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   114
        }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   115
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   116
        pair->expected_working_counter = used[EC_DIR_OUTPUT];
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   117
    } else { // inputs only (or nothing)
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   118
        ec_datagram_lrd_ext(&pair->datagrams[EC_DEVICE_MAIN],
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   119
                logical_offset, data_size, data);
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   120
        for (dev_idx = EC_DEVICE_BACKUP;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   121
                dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   122
            ec_datagram_lrd(&pair->datagrams[dev_idx], logical_offset,
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   123
                    data_size);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   124
        }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   125
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   126
        pair->expected_working_counter = used[EC_DIR_INPUT];
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   127
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   128
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   129
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   130
            dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   131
        ec_datagram_zero(&pair->datagrams[dev_idx]);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   132
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   133
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   134
    return 0;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   135
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   136
out_datagrams:
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   137
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   138
            dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   139
        ec_datagram_clear(&pair->datagrams[dev_idx]);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   140
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   141
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   142
    return ret;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
}
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
/*****************************************************************************/
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
/** Datagram pair destructor.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
 */
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
void ec_datagram_pair_clear(
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
        ec_datagram_pair_t *pair /**< Datagram pair. */
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
        )
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
{
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   153
    unsigned int dev_idx;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   155
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   156
            dev_idx < ec_master_num_devices(pair->domain->master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   157
            dev_idx++) {
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   158
        ec_datagram_clear(&pair->datagrams[dev_idx]);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   159
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   160
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   161
#if EC_MAX_NUM_DEVICES > 1
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   162
    if (pair->send_buffer) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   163
        kfree(pair->send_buffer);
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    }
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   165
#endif
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
}
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
/*****************************************************************************/
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   169
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   170
/** Process received data.
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   171
 */
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   172
uint16_t ec_datagram_pair_process(
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   173
        ec_datagram_pair_t *pair, /**< Datagram pair. */
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   174
        uint16_t wc_sum[] /**< Working counter sums. */
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   175
        )
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   176
{
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   177
    unsigned int dev_idx;
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   178
    uint16_t pair_wc = 0;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   179
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   180
    for (dev_idx = 0; dev_idx < ec_master_num_devices(pair->domain->master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   181
            dev_idx++) {
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   182
        ec_datagram_t *datagram = &pair->datagrams[dev_idx];
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   183
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   184
        ec_datagram_output_stats(datagram);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   185
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   186
        if (datagram->state == EC_DATAGRAM_RECEIVED) {
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   187
            pair_wc += datagram->working_counter;
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   188
            wc_sum[dev_idx] += datagram->working_counter;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   189
        }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   190
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   191
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   192
    return pair_wc;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   193
}
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   194
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   195
/*****************************************************************************/