master/datagram_pair.c
author Florian Pose <fp@igh-essen.com>
Mon, 19 Mar 2012 10:43:09 +0100
branchredundancy
changeset 2372 d895cd1db2bf
parent 2368 dd84ef164869
child 2374 e898451c054a
permissions -rw-r--r--
Improved/fixed frame statistics (low-pass filters).
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
{
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    55
    unsigned int dev_idx;
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
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    61
    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
    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,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    65
                logical_offset, dev_idx ? "backup" : "main");
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    67
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    68
    pair->expected_working_counter = 0U;
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
    /* backup datagram has its own memory */
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    71
    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
    72
            data_size);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    73
    if (ret) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    74
        goto out_datagrams;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    75
    }
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
    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
    78
        EC_MASTER_ERR(domain->master,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    79
                "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
    80
        ret = -ENOMEM;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    81
        goto out_datagrams;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    82
    }
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
    /* 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
    85
     * 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
    86
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    87
    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
    88
        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
    89
                logical_offset, data_size, data);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    90
        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
    91
                logical_offset, data_size);
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 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
    94
        // 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
    95
        pair->expected_working_counter =
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    96
            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
    97
    } 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
    98
        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
    99
                logical_offset, data_size, data);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   100
        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
   101
                logical_offset, data_size);
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
        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
   104
    } else { // inputs only (or nothing)
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   105
        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
   106
                logical_offset, data_size, data);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   107
        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
   108
                logical_offset, data_size);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   109
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   110
        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
   111
    }
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
    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
   114
        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
   115
    }
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
    return 0;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   118
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   119
out_datagrams:
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   120
    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
   121
        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
   122
    }
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
    return ret;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
}
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
/** Datagram pair destructor.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
 */
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
void ec_datagram_pair_clear(
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
        ec_datagram_pair_t *pair /**< Datagram pair. */
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
        )
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
{
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   135
    unsigned int dev_idx;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   137
    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
   138
        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
   139
    }
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
    if (pair->send_buffer) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   142
        kfree(pair->send_buffer);
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
/*****************************************************************************/
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   147
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   148
/** Process received data.
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   149
 */
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   150
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
   151
        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
   152
        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
   153
        )
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   154
{
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   155
    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
   156
    uint16_t pair_wc = 0;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   157
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   158
    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
   159
        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
   160
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   161
        ec_datagram_output_stats(datagram);
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   162
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   163
        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
   164
            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
   165
            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
   166
        }
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
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   169
    return pair_wc;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   170
}
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
/*****************************************************************************/