master/datagram_pair.c
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 08 Oct 2018 23:16:34 +0200
branchstable-1.5
changeset 2726 ca80d6dac4c8
parent 2537 298ce9f9050f
permissions -rw-r--r--
devices/rtdmnet.c : abuse RTDM api to allow sendmsg and recvmsg to be called indirectly from userland cobalt process ioctl, while rtdm_socket is created from a kernel thread.
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.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
    45
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
    46
 * \return Zero on success, otherwise a negative error code.
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
 */
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    48
int ec_datagram_pair_init(
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    49
        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
    50
        ec_domain_t *domain, /**< Parent domain. */
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
    51
        uint32_t logical_offset, /**< Logical offset. */
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
    52
        uint8_t *data, /**< Data pointer. */
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    53
        size_t data_size, /**< Data size. */
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    54
        const unsigned int used[] /**< input/output use count. */
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        )
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
{
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2368
diff changeset
    57
    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
    58
    int ret;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    INIT_LIST_HEAD(&pair->list);
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    61
    pair->domain = domain;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    63
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    64
            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
    65
        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
    66
        snprintf(pair->datagrams[dev_idx].name,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    67
                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
    68
                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
    69
        pair->datagrams[dev_idx].device_index = dev_idx;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    71
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    72
    pair->expected_working_counter = 0U;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    73
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    74
    for (dev_idx = EC_DEVICE_BACKUP;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    75
            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
    76
        /* backup datagrams have their own memory */
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    77
        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
    78
        if (ret) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    79
            goto out_datagrams;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    80
        }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    81
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    82
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    83
#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
    84
    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
    85
        EC_MASTER_ERR(domain->master,
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    86
                "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
    87
        ret = -ENOMEM;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    88
        goto out_datagrams;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    89
    }
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    90
#endif
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    91
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    92
    /* 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
    93
     * 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
    94
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
    95
    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
    96
        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
    97
                logical_offset, data_size, data);
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    98
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
    99
        for (dev_idx = EC_DEVICE_BACKUP;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   100
                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
   101
            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
   102
                    logical_offset, data_size);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   103
        }
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   104
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   105
        // 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
   106
        // 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
   107
        pair->expected_working_counter =
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   108
            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
   109
    } 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
   110
        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
   111
                logical_offset, data_size, data);
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   112
        for (dev_idx = EC_DEVICE_BACKUP;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   113
                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
   114
            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
   115
                    logical_offset, data_size);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   116
        }
2367
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
        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
   119
    } else { // inputs only (or nothing)
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   120
        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
   121
                logical_offset, data_size, data);
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   122
        for (dev_idx = EC_DEVICE_BACKUP;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   123
                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
   124
            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
   125
                    data_size);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   126
        }
2367
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
        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
   129
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   130
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   131
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   132
            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
   133
        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
   134
    }
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
    return 0;
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   137
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   138
out_datagrams:
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   139
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   140
            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
   141
        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
   142
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   143
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   144
    return ret;
2269
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
/*****************************************************************************/
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
/** Datagram pair destructor.
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
 */
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
void ec_datagram_pair_clear(
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
        ec_datagram_pair_t *pair /**< Datagram pair. */
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
        )
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
{
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   155
    unsigned int dev_idx;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   157
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   158
            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
   159
            dev_idx++) {
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   160
        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
   161
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   162
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   163
#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
   164
    if (pair->send_buffer) {
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   165
        kfree(pair->send_buffer);
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    }
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   167
#endif
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
}
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
/*****************************************************************************/
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
/** Process received data.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
   173
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
   174
 * \return Working counter sum over all devices.
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   175
 */
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   176
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
   177
        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
   178
        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
   179
        )
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   180
{
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   181
    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
   182
    uint16_t pair_wc = 0;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   183
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   184
    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
   185
            dev_idx++) {
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   186
        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
   187
2537
298ce9f9050f Output datagram stats only if EC_RT_SYSLOG.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   188
#ifdef EC_RT_SYSLOG
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   189
        ec_datagram_output_stats(datagram);
2537
298ce9f9050f Output datagram stats only if EC_RT_SYSLOG.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   190
#endif
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   191
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   192
        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
   193
            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
   194
            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
   195
        }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   196
    }
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   197
2368
dd84ef164869 Loop through datagrams, then FMMUs; redundancy flag in domain state.
Florian Pose <fp@igh-essen.com>
parents: 2367
diff changeset
   198
    return pair_wc;
2367
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   199
}
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   200
8527429b6137 Compare with send buffer; copy changed data.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   201
/*****************************************************************************/