lib/slave_config.c
author Florian Pose <fp@igh-essen.com>
Tue, 18 Oct 2016 10:20:21 +0200
changeset 2659 8e6fad4f9a74
parent 2635 42b62867574d
permissions -rw-r--r--
Support changed tty_prepare_flip_string() interface from kernel 3.9.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
     2
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     3
 *  $Id$
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
     4
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
     5
 *  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
     6
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     7
 *  This file is part of the IgH EtherCAT master userspace library.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     9
 *  The IgH EtherCAT master userspace library is free software; you can
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    10
 *  redistribute it and/or modify it under the terms of the GNU Lesser General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    11
 *  Public License as published by the Free Software Foundation; version 2.1
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    12
 *  of the License.
1287
cc7b679c74e9 Improved LGPL headers.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    13
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    14
 *  The IgH EtherCAT master userspace library is distributed in the hope that
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    15
 *  it will be useful, but WITHOUT ANY WARRANTY; without even the implied
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    16
 *  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    17
 *  GNU Lesser General Public License for more details.
1287
cc7b679c74e9 Improved LGPL headers.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    18
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    19
 *  You should have received a copy of the GNU Lesser General Public License
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    20
 *  along with the IgH EtherCAT master userspace library. If not, see
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    21
 *  <http://www.gnu.org/licenses/>.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    22
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    23
 *  ---
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    24
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    25
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    26
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    27
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <stdlib.h>
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <stdio.h>
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <string.h>
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    34
#include <errno.h> /* ENOENT */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    35
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    36
#include "ioctl.h"
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "slave_config.h"
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "domain.h"
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    39
#include "sdo_request.h"
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    40
#include "reg_request.h"
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
    41
#include "voe_handler.h"
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "master.h"
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    46
void ec_slave_config_clear(ec_slave_config_t *sc)
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    47
{
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    48
    ec_sdo_request_t *r, *next_r;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    49
    ec_reg_request_t *e, *next_e;
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    50
    ec_voe_handler_t *v, *next_v;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    51
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    52
    r = sc->first_sdo_request;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    53
    while (r) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    54
        next_r = r->next;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    55
        ec_sdo_request_clear(r);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    56
        r = next_r;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    57
    }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    58
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    59
    e = sc->first_reg_request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    60
    while (e) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    61
        next_e = e->next;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    62
        ec_reg_request_clear(e);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    63
        e = next_e;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    64
    }
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    65
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    66
    v = sc->first_voe_handler;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    67
    while (v) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    68
        next_v = v->next;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    69
        ec_voe_handler_clear(v);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    70
        v = next_v;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    71
    }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    72
}
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    73
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    74
/*****************************************************************************/
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
    75
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
int ecrt_slave_config_sync_manager(ec_slave_config_t *sc, uint8_t sync_index,
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
    77
        ec_direction_t dir, ec_watchdog_mode_t watchdog_mode)
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    ec_ioctl_config_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    80
    int ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    if (sync_index >= EC_MAX_SYNC_MANAGERS)
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
    83
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    memset(&data, 0x00, sizeof(ec_ioctl_config_t));
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    data.syncs[sync_index].dir = dir;
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
    88
    data.syncs[sync_index].watchdog_mode = watchdog_mode;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
    89
    data.syncs[sync_index].config_this = 1;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    91
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_SYNC, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    92
    if (EC_IOCTL_IS_ERROR(ret)) {
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
        fprintf(stderr, "Failed to config sync manager: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    94
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    95
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    96
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
    97
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   103
void ecrt_slave_config_watchdog(ec_slave_config_t *sc,
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   104
        uint16_t divider, uint16_t intervals)
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   105
{
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   106
    ec_ioctl_config_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   107
    int ret;
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   108
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   109
    memset(&data, 0x00, sizeof(ec_ioctl_config_t));
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   110
    data.config_index = sc->index;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   111
    data.watchdog_divider = divider;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   112
    data.watchdog_intervals = intervals;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   113
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   114
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_WATCHDOG, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   115
    if (EC_IOCTL_IS_ERROR(ret)) {
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   116
        fprintf(stderr, "Failed to config watchdog: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   117
                strerror(EC_IOCTL_ERRNO(ret)));
1981
c14b6bb14fdf Inplace I/O: let input Pdos use the same bus space as Output Pdos
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1862
diff changeset
   118
    }
c14b6bb14fdf Inplace I/O: let input Pdos use the same bus space as Output Pdos
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1862
diff changeset
   119
}
c14b6bb14fdf Inplace I/O: let input Pdos use the same bus space as Output Pdos
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1862
diff changeset
   120
c14b6bb14fdf Inplace I/O: let input Pdos use the same bus space as Output Pdos
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1862
diff changeset
   121
/*****************************************************************************/
c14b6bb14fdf Inplace I/O: let input Pdos use the same bus space as Output Pdos
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1862
diff changeset
   122
2609
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   123
void ecrt_slave_config_overlapping_pdos(ec_slave_config_t *sc,
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   124
        uint8_t allow_overlapping_pdos)
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   125
{
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   126
    ec_ioctl_config_t data;
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   127
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   128
    memset(&data, 0, sizeof(ec_ioctl_config_t));
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   129
    data.config_index = sc->index;
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   130
    data.allow_overlapping_pdos = allow_overlapping_pdos;
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   131
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   132
    if (ioctl(sc->master->fd, EC_IOCTL_SC_OVERLAPPING_IO, &data) == -1) {
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   133
        fprintf(stderr, "Failed to config overlapping PDOs: %s\n",
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   134
                strerror(errno));
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   135
    }
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   136
}
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   137
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   138
/*****************************************************************************/
777d1a8b3a27 Integrate skeleton of allow_overlapping_pdos from af21f0bdc7c9
Dave Page <dave.page@gleeble.com>
parents: 2589
diff changeset
   139
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
int ecrt_slave_config_pdo_assign_add(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
        uint8_t sync_index, uint16_t pdo_index)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    ec_ioctl_config_pdo_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   144
    int ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    data.sync_index = sync_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    data.index = pdo_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   150
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_ADD_PDO, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   151
    if (EC_IOCTL_IS_ERROR(ret)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   152
        fprintf(stderr, "Failed to add PDO: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   153
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   154
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   155
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   156
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
void ecrt_slave_config_pdo_assign_clear(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
        uint8_t sync_index)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    ec_ioctl_config_pdo_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   166
    int ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
    data.sync_index = sync_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   171
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_CLEAR_PDOS, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   172
    if (EC_IOCTL_IS_ERROR(ret)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   173
        fprintf(stderr, "Failed to clear PDOs: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   174
                strerror(EC_IOCTL_ERRNO(ret)));
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
int ecrt_slave_config_pdo_mapping_add(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
        uint16_t pdo_index, uint16_t entry_index, uint8_t entry_subindex,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
        uint8_t entry_bit_length)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    ec_ioctl_add_pdo_entry_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   185
    int ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
    data.pdo_index = pdo_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    data.entry_index = entry_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
    data.entry_subindex = entry_subindex;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    data.entry_bit_length = entry_bit_length;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   193
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_ADD_ENTRY, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   194
    if (EC_IOCTL_IS_ERROR(ret)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   195
        fprintf(stderr, "Failed to add PDO entry: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   196
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   197
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   198
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   199
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
void ecrt_slave_config_pdo_mapping_clear(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
        uint16_t pdo_index)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
    ec_ioctl_config_pdo_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   209
    int ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
    data.index = pdo_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   214
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_CLEAR_ENTRIES, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   215
    if (EC_IOCTL_IS_ERROR(ret)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   216
        fprintf(stderr, "Failed to clear PDO entries: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   217
                strerror(EC_IOCTL_ERRNO(ret)));
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
int ecrt_slave_config_pdos(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
        unsigned int n_syncs, const ec_sync_info_t syncs[])
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   226
    int ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
    unsigned int i, j, k;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
    const ec_sync_info_t *sync_info;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
    const ec_pdo_info_t *pdo_info;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
    const ec_pdo_entry_info_t *entry_info;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
    if (!syncs)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
        return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
    for (i = 0; i < n_syncs; i++) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
        sync_info = &syncs[i];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
        if (sync_info->index == (uint8_t) EC_END)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
            break;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
        if (sync_info->index >= EC_MAX_SYNC_MANAGERS) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
            fprintf(stderr, "Invalid sync manager index %u!\n",
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
                    sync_info->index);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   244
            return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
        }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   247
        ret = ecrt_slave_config_sync_manager(sc, sync_info->index,
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   248
                sync_info->dir, sync_info->watchdog_mode);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   249
        if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   250
            return ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
2634
f859d567f94e Always clear PDO assignment of configured sync managers.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   252
        ecrt_slave_config_pdo_assign_clear(sc, sync_info->index);
f859d567f94e Always clear PDO assignment of configured sync managers.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   253
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
        if (sync_info->n_pdos && sync_info->pdos) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
            for (j = 0; j < sync_info->n_pdos; j++) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
                pdo_info = &sync_info->pdos[j];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   259
                ret = ecrt_slave_config_pdo_assign_add(
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   260
                        sc, sync_info->index, pdo_info->index);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   261
                if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   262
                    return ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
                if (pdo_info->n_entries && pdo_info->entries) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
                    ecrt_slave_config_pdo_mapping_clear(sc, pdo_info->index);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
                    for (k = 0; k < pdo_info->n_entries; k++) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
                        entry_info = &pdo_info->entries[k];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   270
                        ret = ecrt_slave_config_pdo_mapping_add(sc,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   271
                                pdo_info->index, entry_info->index,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   272
                                entry_info->subindex,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   273
                                entry_info->bit_length);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   274
                        if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   275
                            return ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
                    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
                }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
            }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
        }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
int ecrt_slave_config_reg_pdo_entry(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
        ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
        uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
        uint8_t subindex,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
        ec_domain_t *domain,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
        unsigned int *bit_position
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
    ec_ioctl_reg_pdo_entry_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
    int ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
    data.entry_index = index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
    data.entry_subindex = subindex;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
    data.domain_index = domain->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_REG_PDO_ENTRY, &data);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   304
    if (EC_IOCTL_IS_ERROR(ret)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   305
        fprintf(stderr, "Failed to register PDO entry: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   306
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   307
        return -EC_IOCTL_ERRNO(ret);
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
    if (bit_position) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
        *bit_position = data.bit_position;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
    } else {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
        if (data.bit_position) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   314
            fprintf(stderr, "PDO entry 0x%04X:%02X does not byte-align "
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
                    "in config %u:%u.\n", index, subindex,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
                    sc->alias, sc->position);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   317
            return -EFAULT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
        }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
    return ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   326
int ecrt_slave_config_reg_pdo_entry_pos(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   327
        ec_slave_config_t *sc,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   328
        uint8_t sync_index,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   329
        unsigned int pdo_pos,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   330
        unsigned int entry_pos,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   331
        ec_domain_t *domain,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   332
        unsigned int *bit_position
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   333
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   334
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   335
    ec_ioctl_reg_pdo_pos_t io;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   336
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   337
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   338
    io.config_index = sc->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   339
    io.sync_index = sync_index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   340
    io.pdo_pos = pdo_pos;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   341
    io.entry_pos = entry_pos;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   342
    io.domain_index = domain->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   343
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   344
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_REG_PDO_POS, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   345
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   346
        fprintf(stderr, "Failed to register PDO entry: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   347
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   348
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   349
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   350
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   351
    if (bit_position) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   352
        *bit_position = io.bit_position;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   353
    } else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   354
        if (io.bit_position) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   355
            fprintf(stderr, "PDO entry %u/%u/%u does not byte-align "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   356
                    "in config %u:%u.\n", sync_index, pdo_pos, entry_pos,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   357
                    sc->alias, sc->position);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   358
            return -EFAULT;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   359
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   360
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   361
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   362
    return ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   363
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   364
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   365
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   366
1448
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
   367
void ecrt_slave_config_dc(ec_slave_config_t *sc, uint16_t assign_activate,
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   368
        uint32_t sync0_cycle_time, int32_t sync0_shift_time,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   369
        uint32_t sync1_cycle_time, int32_t sync1_shift_time)
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1371
diff changeset
   370
{
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
   371
    ec_ioctl_config_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   372
    int ret;
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
   373
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
   374
    data.config_index = sc->index;
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
   375
    data.dc_assign_activate = assign_activate;
1508
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1455
diff changeset
   376
    data.dc_sync[0].cycle_time = sync0_cycle_time;
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1455
diff changeset
   377
    data.dc_sync[0].shift_time = sync0_shift_time;
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1455
diff changeset
   378
    data.dc_sync[1].cycle_time = sync1_cycle_time;
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1455
diff changeset
   379
    data.dc_sync[1].shift_time = sync1_shift_time;
1438
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1413
diff changeset
   380
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   381
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_DC, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   382
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   383
        fprintf(stderr, "Failed to set DC parameters: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   384
                strerror(EC_IOCTL_ERRNO(ret)));
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1371
diff changeset
   385
    }
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1371
diff changeset
   386
}
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1371
diff changeset
   387
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1371
diff changeset
   388
/*****************************************************************************/
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1371
diff changeset
   389
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
int ecrt_slave_config_sdo(ec_slave_config_t *sc, uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
        uint8_t subindex, const uint8_t *sdo_data, size_t size)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   392
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   393
    ec_ioctl_sc_sdo_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   394
    int ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   396
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   397
    data.index = index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   398
    data.subindex = subindex;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   399
    data.data = sdo_data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   400
    data.size = size;
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   401
    data.complete_access = 0;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   402
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   403
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_SDO, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   404
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   405
        fprintf(stderr, "Failed to configure SDO: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   406
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   407
        return -EC_IOCTL_ERRNO(ret);
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   408
    }
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   409
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   410
    return 0;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   411
}
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   412
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   413
/*****************************************************************************/
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   414
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   415
int ecrt_slave_config_complete_sdo(ec_slave_config_t *sc, uint16_t index,
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   416
        const uint8_t *sdo_data, size_t size)
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   417
{
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   418
    ec_ioctl_sc_sdo_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   419
    int ret;
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   420
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   421
    data.config_index = sc->index;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   422
    data.index = index;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   423
    data.subindex = 0;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   424
    data.data = sdo_data;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   425
    data.size = size;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
   426
    data.complete_access = 1;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   428
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_SDO, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   429
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   430
        fprintf(stderr, "Failed to configure SDO: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   431
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   432
        return -EC_IOCTL_ERRNO(ret);
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   435
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   436
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   437
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   438
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   439
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   440
int ecrt_slave_config_sdo8(ec_slave_config_t *sc, uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   441
        uint8_t subindex, uint8_t value)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   442
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   443
    uint8_t data[1];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   444
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   445
    EC_WRITE_U8(data, value);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   446
    return ecrt_slave_config_sdo(sc, index, subindex, data, 1);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   447
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   449
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
int ecrt_slave_config_sdo16(ec_slave_config_t *sc, uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
        uint8_t subindex, uint16_t value)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
    uint8_t data[2];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
    EC_WRITE_U16(data, value);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   457
    return ecrt_slave_config_sdo(sc, index, subindex, data, 2);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   459
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
int ecrt_slave_config_sdo32(ec_slave_config_t *sc, uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
        uint8_t subindex, uint32_t value)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   464
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   465
    uint8_t data[4];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   466
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   467
    EC_WRITE_U32(data, value);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
    return ecrt_slave_config_sdo(sc, index, subindex, data, 4);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   470
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   471
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   472
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   473
int ecrt_slave_config_emerg_size(ec_slave_config_t *sc, size_t elements)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   474
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   475
    ec_ioctl_sc_emerg_t io;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   476
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   477
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   478
    io.config_index = sc->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   479
    io.size = elements;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   480
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   481
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_EMERG_SIZE, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   482
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   483
        fprintf(stderr, "Failed to set emergency ring size: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   484
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   485
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   486
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   487
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   488
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   489
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   490
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   491
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   492
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   493
int ecrt_slave_config_emerg_pop(ec_slave_config_t *sc, uint8_t *target)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   494
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   495
    ec_ioctl_sc_emerg_t io;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   496
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   497
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   498
    io.config_index = sc->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   499
    io.target = target;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   500
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   501
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_EMERG_POP, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   502
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   503
        if (EC_IOCTL_ERRNO(ret) != ENOENT) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   504
            fprintf(stderr, "Failed to get emergency message: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   505
                    strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   506
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   507
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   508
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   509
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   510
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   511
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   512
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   513
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   514
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   515
int ecrt_slave_config_emerg_clear(ec_slave_config_t *sc)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   516
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   517
    ec_ioctl_sc_emerg_t io;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   518
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   519
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   520
    io.config_index = sc->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   521
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   522
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_EMERG_CLEAR, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   523
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   524
        fprintf(stderr, "Failed to clear emergency ring: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   525
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   526
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   527
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   528
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   529
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   530
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   531
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   532
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   533
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   534
int ecrt_slave_config_emerg_overruns(ec_slave_config_t *sc)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   535
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   536
    ec_ioctl_sc_emerg_t io;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   537
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   538
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   539
    io.config_index = sc->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   540
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   541
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_EMERG_OVERRUNS, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   542
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   543
        fprintf(stderr, "Failed to get emergency overruns: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   544
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   545
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   546
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   547
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   548
    return io.overruns;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   549
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   550
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   551
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   552
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   553
void ec_slave_config_add_sdo_request(ec_slave_config_t *sc,
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   554
        ec_sdo_request_t *req)
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   555
{
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   556
    if (sc->first_sdo_request) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   557
        ec_sdo_request_t *r = sc->first_sdo_request;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   558
        while (r->next) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   559
            r = r->next;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   560
        }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   561
        r->next = req;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   562
    } else {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   563
        sc->first_sdo_request = req;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   564
    }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   565
}
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   566
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   567
/*****************************************************************************/
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   568
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   569
ec_sdo_request_t *ecrt_slave_config_create_sdo_request(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   570
        uint16_t index, uint8_t subindex, size_t size)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   571
{
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   572
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   573
    ec_sdo_request_t *req;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   574
    int ret;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   575
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   576
    req = malloc(sizeof(ec_sdo_request_t));
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   577
    if (!req) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   578
        fprintf(stderr, "Failed to allocate memory.\n");
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   579
        return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   580
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   581
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   582
    if (size) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   583
        req->data = malloc(size);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   584
        if (!req->data) {
2025
2d7e29d82e9a fixed warning due to 64bit size_t
Martin Troxler <ch1010277@ch10pc446>
parents: 1995
diff changeset
   585
            fprintf(stderr, "Failed to allocate %zu bytes of SDO data"
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   586
                    " memory.\n", size);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   587
            free(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   588
            return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   589
        }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   590
    } else {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   591
        req->data = NULL;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   592
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   593
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   594
    data.config_index = sc->index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   595
    data.sdo_index = index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   596
    data.sdo_subindex = subindex;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   597
    data.size = size;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   598
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   599
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_SDO_REQUEST, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   600
    if (EC_IOCTL_IS_ERROR(ret)) {
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   601
        fprintf(stderr, "Failed to create SDO request: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   602
                strerror(EC_IOCTL_ERRNO(ret)));
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   603
        ec_sdo_request_clear(req);
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   604
        free(req);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   605
        return NULL;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   606
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   607
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   608
    req->next = NULL;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   609
    req->config = sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   610
    req->index = data.request_index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   611
    req->sdo_index = data.sdo_index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   612
    req->sdo_subindex = data.sdo_subindex;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   613
    req->data_size = size;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   614
    req->mem_size = size;
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   615
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   616
    ec_slave_config_add_sdo_request(sc, req);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   617
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   618
    return req;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   619
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   620
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   621
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   622
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   623
void ec_slave_config_add_reg_request(ec_slave_config_t *sc,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   624
        ec_reg_request_t *reg)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   625
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   626
    if (sc->first_reg_request) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   627
        ec_reg_request_t *r = sc->first_reg_request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   628
        while (r->next) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   629
            r = r->next;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   630
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   631
        r->next = reg;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   632
    } else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   633
        sc->first_reg_request = reg;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   634
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   635
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   636
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   637
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   638
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   639
ec_reg_request_t *ecrt_slave_config_create_reg_request(ec_slave_config_t *sc,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   640
        size_t size)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   641
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   642
    ec_ioctl_reg_request_t io;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   643
    ec_reg_request_t *reg;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   644
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   645
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   646
    reg = malloc(sizeof(ec_reg_request_t));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   647
    if (!reg) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   648
        fprintf(stderr, "Failed to allocate memory.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   649
        return NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   650
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   651
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   652
    if (size) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   653
        reg->data = malloc(size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   654
        if (!reg->data) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   655
            fprintf(stderr, "Failed to allocate %zu bytes of register data"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   656
                    " memory.\n", size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   657
            free(reg);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   658
            return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   659
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   660
    } else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   661
        reg->data = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   662
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   663
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   664
    io.config_index = sc->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   665
    io.mem_size = size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   666
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   667
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_REG_REQUEST, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   668
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   669
        fprintf(stderr, "Failed to create register request: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   670
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   671
        ec_reg_request_clear(reg);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   672
        free(reg);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   673
        return NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   674
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   675
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   676
    reg->next = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   677
    reg->config = sc;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   678
    reg->index = io.request_index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   679
    reg->mem_size = size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   680
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   681
    ec_slave_config_add_reg_request(sc, reg);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   682
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   683
    return reg;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   684
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   685
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   686
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   687
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   688
void ec_slave_config_add_voe_handler(ec_slave_config_t *sc,
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   689
        ec_voe_handler_t *voe)
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   690
{
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   691
    if (sc->first_voe_handler) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   692
        ec_voe_handler_t *v = sc->first_voe_handler;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   693
        while (v->next) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   694
            v = v->next;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   695
        }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   696
        v->next = voe;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   697
    } else {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   698
        sc->first_voe_handler = voe;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   699
    }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   700
}
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   701
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   702
/*****************************************************************************/
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   703
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   704
ec_voe_handler_t *ecrt_slave_config_create_voe_handler(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   705
        size_t size)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   706
{
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   707
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   708
    ec_voe_handler_t *voe;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   709
    int ret;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   710
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   711
    voe = malloc(sizeof(ec_voe_handler_t));
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   712
    if (!voe) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   713
        fprintf(stderr, "Failed to allocate memory.\n");
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   714
        return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   715
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   716
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   717
    if (size) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   718
        voe->data = malloc(size);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   719
        if (!voe->data) {
2025
2d7e29d82e9a fixed warning due to 64bit size_t
Martin Troxler <ch1010277@ch10pc446>
parents: 1995
diff changeset
   720
            fprintf(stderr, "Failed to allocate %zu bytes of VoE data"
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   721
                    " memory.\n", size);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   722
            free(voe);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   723
            return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   724
        }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   725
    } else {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   726
        voe->data = NULL;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   727
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   728
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   729
    data.config_index = sc->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   730
    data.size = size;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   731
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   732
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_VOE, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   733
    if (EC_IOCTL_IS_ERROR(ret)) {
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   734
        fprintf(stderr, "Failed to create VoE handler: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   735
                strerror(EC_IOCTL_ERRNO(ret)));
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   736
        ec_voe_handler_clear(voe);
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   737
        free(voe);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   738
        return NULL;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   739
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   740
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   741
    voe->next = NULL;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   742
    voe->config = sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   743
    voe->index = data.voe_index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   744
    voe->data_size = size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   745
    voe->mem_size = size;
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   746
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   747
    ec_slave_config_add_voe_handler(sc, voe);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   748
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   749
    return voe;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   750
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   751
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   752
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   753
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   754
void ecrt_slave_config_state(const ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   755
        ec_slave_config_state_t *state)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   756
{
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   757
    ec_ioctl_sc_state_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   758
    int ret;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   759
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   760
    data.config_index = sc->index;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   761
    data.state = state;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   762
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   763
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_STATE, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   764
    if (EC_IOCTL_IS_ERROR(ret)) {
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   765
        fprintf(stderr, "Failed to get slave configuration state: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   766
                strerror(EC_IOCTL_ERRNO(ret)));
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   767
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   768
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   769
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   770
/*****************************************************************************/
1862
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   771
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   772
int ecrt_slave_config_idn(ec_slave_config_t *sc, uint8_t drive_no,
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   773
        uint16_t idn, ec_al_state_t al_state, const uint8_t *data, size_t size)
1862
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   774
{
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   775
    ec_ioctl_sc_idn_t io;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   776
    int ret;
1862
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   777
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   778
    io.config_index = sc->index;
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   779
    io.drive_no = drive_no;
1862
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   780
    io.idn = idn;
1945
f9204699e799 Incremented ioctl interface version; Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 1944
diff changeset
   781
    io.al_state = al_state;
1862
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   782
    io.data = data;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   783
    io.size = size;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   784
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   785
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_IDN, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   786
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   787
        fprintf(stderr, "Failed to configure IDN: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   788
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   789
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   790
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   791
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   792
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   793
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   794
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2025
diff changeset
   795
/*****************************************************************************/