master/datagram_pair.c
author Florian Pose <fp@igh-essen.com>
Wed, 19 Sep 2012 19:46:58 +0200
branchstable-1.5
changeset 2425 6a6dec6fc806
parent 2374 e898451c054a
child 2453 d461b1f07296
permissions -rw-r--r--
Avoided use of AM_CFLAGS, which is not used in some situations; fixed warning.
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
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2368
diff changeset
    61
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < EC_NUM_DEVICES; dev_idx++) {
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    62
        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
    63
        snprintf(pair->datagrams[dev_idx].name,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    64
                EC_DATAGRAM_NAME_SIZE, "domain%u-%u-%s", domain->index,
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2368
diff changeset
    65
                logical_offset, ec_device_names[dev_idx]);
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2368
diff changeset
    66
        pair->datagrams[dev_idx].device_index = dev_idx;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    68
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    69
    pair->expected_working_counter = 0U;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    70
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    71
    /* backup datagram has its own memory */
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    72
    ret = ec_datagram_prealloc(&pair->datagrams[EC_DEVICE_BACKUP],
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    73
            data_size);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    74
    if (ret) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    75
        goto out_datagrams;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    76
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    77
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    78
    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
    79
        EC_MASTER_ERR(domain->master,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    80
                "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
    81
        ret = -ENOMEM;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    82
        goto out_datagrams;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    83
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    84
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    85
    /* 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
    86
     * 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
    87
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    88
    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
    89
        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
    90
                logical_offset, data_size, data);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    91
        ec_datagram_lrw(&pair->datagrams[EC_DEVICE_BACKUP],
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    92
                logical_offset, data_size);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    93
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    94
        // 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
    95
        // 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
    96
        pair->expected_working_counter =
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    97
            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
    98
    } 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
    99
        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
   100
                logical_offset, data_size, data);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   101
        ec_datagram_lwr(&pair->datagrams[EC_DEVICE_BACKUP],
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   102
                logical_offset, data_size);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   103
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   104
        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
   105
    } else { // inputs only (or nothing)
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   106
        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
   107
                logical_offset, data_size, data);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   108
        ec_datagram_lrd(&pair->datagrams[EC_DEVICE_BACKUP],
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   109
                logical_offset, data_size);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   110
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   111
        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
   112
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   113
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   114
    for (dev_idx = 0; dev_idx < EC_NUM_DEVICES; dev_idx++) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   115
        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
   116
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   117
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   118
    return 0;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   119
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   120
out_datagrams:
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   121
    for (dev_idx = 0; dev_idx < EC_NUM_DEVICES; dev_idx++) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   122
        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
   123
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   124
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   125
    return ret;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
}
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
/*****************************************************************************/
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
/** Datagram pair destructor.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
 */
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
void ec_datagram_pair_clear(
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
        ec_datagram_pair_t *pair /**< Datagram pair. */
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
        )
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
{
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   136
    unsigned int dev_idx;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   138
    for (dev_idx = 0; dev_idx < EC_NUM_DEVICES; dev_idx++) {
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
    if (pair->send_buffer) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   143
        kfree(pair->send_buffer);
2269
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
/*****************************************************************************/
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   148
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   149
/** Process received data.
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   150
 */
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   151
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
   152
        ec_datagram_pair_t *pair, /**< Datagram pair. */
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   153
        uint16_t wc_sum[EC_NUM_DEVICES] /**< Working counter sums. */
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   154
        )
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   155
{
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   156
    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
   157
    uint16_t pair_wc = 0;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   158
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   159
    for (dev_idx = 0; dev_idx < EC_NUM_DEVICES; dev_idx++) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   160
        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
   161
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   162
        ec_datagram_output_stats(datagram);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   163
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   164
        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
   165
            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
   166
            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
   167
        }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   168
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   169
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   170
    return pair_wc;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   171
}
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   172
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   173
/*****************************************************************************/