lib/master.c
author Philipp Weyer <pw@igh-essen.com>
Fri, 18 Aug 2017 12:30:16 +0200
changeset 2679 33b922ec1871
parent 2630 a380cce7d6f0
permissions -rw-r--r--
Fixed lib include paths
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
     1
/*****************************************************************************
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
diff changeset
     2
 *
2246
6f5bfbcc2010 Minor: Line wrapping.
Florian Pose <fp@igh-essen.com>
parents: 2150
diff changeset
     3
 *  $Id$
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
diff changeset
     4
 *
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
     5
 *  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
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.
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
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/>.
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
diff changeset
    22
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1341
diff changeset
    23
 *  ---
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
diff changeset
    24
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1341
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: 1341
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: 1341
diff changeset
    27
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    29
 ****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    30
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    31
#include <unistd.h> /* close() */
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <stdlib.h>
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <stdio.h>
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <errno.h>
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include <string.h>
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    36
#include <sys/mman.h>
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    38
#include "ioctl.h"
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "master.h"
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "domain.h"
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    41
#include "slave_config.h"
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    42
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    43
/****************************************************************************/
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
1497
c9308eb34c0e Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
    45
int ecrt_master_reserve(ec_master_t *master)
c9308eb34c0e Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
    46
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    47
    int ret = ioctl(master->fd, EC_IOCTL_REQUEST, NULL);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    48
    if (EC_IOCTL_IS_ERROR(ret)) {
1497
c9308eb34c0e Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
    49
        fprintf(stderr, "Failed to reserve master: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    50
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    51
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    52
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    53
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    54
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    55
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    56
/****************************************************************************/
1497
c9308eb34c0e Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
    57
1960
6c4269dca1c2 Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    58
void ec_master_clear_config(ec_master_t *master)
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    59
{
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    60
    ec_domain_t *d, *next_d;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    61
    ec_slave_config_t *c, *next_c;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    62
2616
f99e5b11806c Moved userspace domain unmap to deactivate instead of release, fixing memory/ref leak.
Gavin Lambert <gavinl@compacsort.com>
parents: 2589
diff changeset
    63
    if (master->process_data)  {
f99e5b11806c Moved userspace domain unmap to deactivate instead of release, fixing memory/ref leak.
Gavin Lambert <gavinl@compacsort.com>
parents: 2589
diff changeset
    64
        munmap(master->process_data, master->process_data_size);
f99e5b11806c Moved userspace domain unmap to deactivate instead of release, fixing memory/ref leak.
Gavin Lambert <gavinl@compacsort.com>
parents: 2589
diff changeset
    65
        master->process_data = NULL;
f99e5b11806c Moved userspace domain unmap to deactivate instead of release, fixing memory/ref leak.
Gavin Lambert <gavinl@compacsort.com>
parents: 2589
diff changeset
    66
    }
f99e5b11806c Moved userspace domain unmap to deactivate instead of release, fixing memory/ref leak.
Gavin Lambert <gavinl@compacsort.com>
parents: 2589
diff changeset
    67
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    68
    d = master->first_domain;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    69
    while (d) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    70
        next_d = d->next;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    71
        ec_domain_clear(d);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    72
        d = next_d;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    73
    }
1960
6c4269dca1c2 Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    74
    master->first_domain = NULL;
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    75
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    76
    c = master->first_config;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    77
    while (c) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    78
        next_c = c->next;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    79
        ec_slave_config_clear(c);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    80
        c = next_c;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    81
    }
1960
6c4269dca1c2 Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    82
    master->first_config = NULL;
6c4269dca1c2 Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    83
}
6c4269dca1c2 Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    84
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    85
/****************************************************************************/
1960
6c4269dca1c2 Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    86
6c4269dca1c2 Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    87
void ec_master_clear(ec_master_t *master)
6c4269dca1c2 Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    88
{
6c4269dca1c2 Clear configuration on deactivation; also in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    89
    ec_master_clear_config(master);
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    90
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    91
    if (master->fd != -1) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    92
#if USE_RTDM
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    93
        rt_dev_close(master->fd);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    94
#else
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
    95
        close(master->fd);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    96
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    97
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    98
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
    99
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   100
/****************************************************************************/
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   101
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   102
void ec_master_add_domain(ec_master_t *master, ec_domain_t *domain)
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   103
{
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   104
    if (master->first_domain) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   105
        ec_domain_t *d = master->first_domain;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   106
        while (d->next) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   107
            d = d->next;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   108
        }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   109
        d->next = domain;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   110
    } else {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   111
        master->first_domain = domain;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   112
    }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   113
}
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   114
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   115
/****************************************************************************/
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   116
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
ec_domain_t *ecrt_master_create_domain(ec_master_t *master)
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
{
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    ec_domain_t *domain;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    int index;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
    domain = malloc(sizeof(ec_domain_t));
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    if (!domain) {
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
        fprintf(stderr, "Failed to allocate memory.\n");
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
        return 0;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    }
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
diff changeset
   127
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    index = ioctl(master->fd, EC_IOCTL_CREATE_DOMAIN, NULL);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   129
    if (EC_IOCTL_IS_ERROR(index)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   130
        fprintf(stderr, "Failed to create domain: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   131
                strerror(EC_IOCTL_ERRNO(index)));
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
        free(domain);
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
diff changeset
   133
        return 0;
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    }
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   136
    domain->next = NULL;
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    domain->index = (unsigned int) index;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   138
    domain->master = master;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   139
    domain->process_data = NULL;
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   140
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   141
    ec_master_add_domain(master, domain);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   142
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    return domain;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   146
/****************************************************************************/
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   148
void ec_master_add_slave_config(ec_master_t *master, ec_slave_config_t *sc)
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   149
{
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   150
    if (master->first_config) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   151
        ec_slave_config_t *c = master->first_config;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   152
        while (c->next) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   153
            c = c->next;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   154
        }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   155
        c->next = sc;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   156
    } else {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   157
        master->first_config = sc;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   158
    }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   159
}
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   160
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   161
/****************************************************************************/
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   162
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        uint16_t alias, uint16_t position, uint32_t vendor_id,
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
        uint32_t product_code)
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
{
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   167
    ec_ioctl_config_t data;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   168
    ec_slave_config_t *sc;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   169
    int ret;
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   170
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   171
    sc = malloc(sizeof(ec_slave_config_t));
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   172
    if (!sc) {
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   173
        fprintf(stderr, "Failed to allocate memory.\n");
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   174
        return 0;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   175
    }
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
diff changeset
   176
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   177
    data.alias = alias;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   178
    data.position = position;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   179
    data.vendor_id = vendor_id;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   180
    data.product_code = product_code;
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
diff changeset
   181
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   182
    ret = ioctl(master->fd, EC_IOCTL_CREATE_SLAVE_CONFIG, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   183
    if (EC_IOCTL_IS_ERROR(ret)) {
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   184
        fprintf(stderr, "Failed to create slave config: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   185
                strerror(EC_IOCTL_ERRNO(ret)));
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   186
        free(sc);
1982
7421bca39b6d Insert port information into slave info.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1980
diff changeset
   187
        return 0;
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   188
    }
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   189
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   190
    sc->next = NULL;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   191
    sc->master = master;
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   192
    sc->index = data.config_index;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   193
    sc->alias = alias;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
   194
    sc->position = position;
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   195
    sc->first_sdo_request = NULL;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   196
    sc->first_reg_request = NULL;
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   197
    sc->first_voe_handler = NULL;
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   198
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   199
    ec_master_add_slave_config(master, sc);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   200
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
   201
    return sc;
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   206
int ecrt_master_select_reference_clock(ec_master_t *master,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   207
        ec_slave_config_t *sc)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   208
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   209
    uint32_t config_index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   210
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   211
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   212
    if (sc) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   213
        config_index = sc->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   214
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   215
    else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   216
        config_index = 0xFFFFFFFF;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   217
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   218
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   219
    ret = ioctl(master->fd, EC_IOCTL_SELECT_REF_CLOCK, config_index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   220
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   221
        fprintf(stderr, "Failed to select reference clock: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   222
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   223
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   224
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   225
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   226
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   227
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   228
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   229
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   230
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   231
int ecrt_master(ec_master_t *master, ec_master_info_t *master_info)
1497
c9308eb34c0e Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
   232
{
1508
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1497
diff changeset
   233
    ec_ioctl_master_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   234
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   235
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   236
    ret = ioctl(master->fd, EC_IOCTL_MASTER, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   237
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   238
        fprintf(stderr, "Failed to get master info: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   239
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   240
        return -EC_IOCTL_ERRNO(ret);
1508
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1497
diff changeset
   241
    }
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1497
diff changeset
   242
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1497
diff changeset
   243
    master_info->slave_count = data.slave_count;
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1497
diff changeset
   244
    master_info->link_up = data.devices[0].link_state;
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1510
diff changeset
   245
    master_info->scan_busy = data.scan_busy;
1508
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1497
diff changeset
   246
    master_info->app_time = data.app_time;
60a116ed3897 Removed more tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1497
diff changeset
   247
    return 0;
1497
c9308eb34c0e Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
   248
}
c9308eb34c0e Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
   249
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   250
/****************************************************************************/
1497
c9308eb34c0e Separated master requesting into open and reserve for userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
   251
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   252
int ecrt_master_get_slave(ec_master_t *master, uint16_t slave_position,
1341
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   253
        ec_slave_info_t *slave_info)
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   254
{
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   255
    ec_ioctl_slave_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   256
    int ret, i;
1341
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   257
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   258
    data.position = slave_position;
1341
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   259
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   260
    ret = ioctl(master->fd, EC_IOCTL_SLAVE, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   261
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   262
        fprintf(stderr, "Failed to get slave info: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   263
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   264
        return -EC_IOCTL_ERRNO(ret);
1341
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   265
    }
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   266
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   267
    slave_info->position = data.position;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   268
    slave_info->vendor_id = data.vendor_id;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   269
    slave_info->product_code = data.product_code;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   270
    slave_info->revision_number = data.revision_number;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   271
    slave_info->serial_number = data.serial_number;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   272
    slave_info->alias = data.alias;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   273
    slave_info->current_on_ebus = data.current_on_ebus;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   274
    for (i = 0; i < EC_MAX_PORTS; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   275
        slave_info->ports[i].desc = data.ports[i].desc;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   276
        slave_info->ports[i].link.link_up = data.ports[i].link.link_up;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   277
        slave_info->ports[i].link.loop_closed =
2246
6f5bfbcc2010 Minor: Line wrapping.
Florian Pose <fp@igh-essen.com>
parents: 2150
diff changeset
   278
            data.ports[i].link.loop_closed;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   279
        slave_info->ports[i].link.signal_detected =
2246
6f5bfbcc2010 Minor: Line wrapping.
Florian Pose <fp@igh-essen.com>
parents: 2150
diff changeset
   280
            data.ports[i].link.signal_detected;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   281
        slave_info->ports[i].receive_time = data.ports[i].receive_time;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   282
        slave_info->ports[i].next_slave = data.ports[i].next_slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   283
        slave_info->ports[i].delay_to_next_dc =
2246
6f5bfbcc2010 Minor: Line wrapping.
Florian Pose <fp@igh-essen.com>
parents: 2150
diff changeset
   284
            data.ports[i].delay_to_next_dc;
1983
df270de292e1 Fixed copying port information.
Stefan Weiser <ch1010858@ch10pc584>
parents: 1982
diff changeset
   285
    }
1341
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   286
    slave_info->al_state = data.al_state;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   287
    slave_info->error_flag = data.error_flag;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   288
    slave_info->sync_count = data.sync_count;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   289
    slave_info->sdo_count = data.sdo_count;
1593
fb8337e664fb Fixed string length constant bug.
Florian Pose <fp@igh-essen.com>
parents: 1585
diff changeset
   290
    strncpy(slave_info->name, data.name, EC_MAX_STRING_LENGTH);
1341
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   291
    return 0;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   292
}
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   293
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   294
/****************************************************************************/
1341
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   295
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   296
int ecrt_master_get_sync_manager(ec_master_t *master, uint16_t slave_position,
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   297
        uint8_t sync_index, ec_sync_info_t *sync)
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   298
{
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   299
    ec_ioctl_slave_sync_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   300
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   301
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   302
    if (sync_index >= EC_MAX_SYNC_MANAGERS) {
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   303
        return -ENOENT;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   304
    }
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   305
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   306
    memset(&data, 0x00, sizeof(ec_ioctl_slave_sync_t));
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   307
    data.slave_position = slave_position;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   308
    data.sync_index = sync_index;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   309
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   310
    ret = ioctl(master->fd, EC_IOCTL_SLAVE_SYNC, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   311
    if (EC_IOCTL_IS_ERROR(ret)) {
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   312
        fprintf(stderr, "Failed to get sync manager information: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   313
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   314
        return -EC_IOCTL_ERRNO(ret);
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   315
    }
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   316
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   317
    sync->index = sync_index;
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   318
    sync->dir = EC_READ_BIT(&data.control_register, 2) ?
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   319
        EC_DIR_OUTPUT : EC_DIR_INPUT;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   320
    sync->n_pdos = data.pdo_count;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   321
    sync->pdos = NULL;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   322
    sync->watchdog_mode = EC_READ_BIT(&data.control_register, 6) ?
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   323
        EC_WD_ENABLE : EC_WD_DISABLE;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   324
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   325
    return 0;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   326
}
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   327
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   328
/****************************************************************************/
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   329
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   330
int ecrt_master_get_pdo(ec_master_t *master, uint16_t slave_position,
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   331
        uint8_t sync_index, uint16_t pos, ec_pdo_info_t *pdo)
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   332
{
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   333
    ec_ioctl_slave_sync_pdo_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   334
    int ret;
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   335
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   336
    if (sync_index >= EC_MAX_SYNC_MANAGERS)
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   337
        return -ENOENT;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   338
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   339
    memset(&data, 0x00, sizeof(ec_ioctl_slave_sync_pdo_t));
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   340
    data.slave_position = slave_position;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   341
    data.sync_index = sync_index;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   342
    data.pdo_pos = pos;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   343
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   344
    ret = ioctl(master->fd, EC_IOCTL_SLAVE_SYNC_PDO, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   345
    if (EC_IOCTL_IS_ERROR(ret)) {
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   346
        fprintf(stderr, "Failed to get pdo information: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   347
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   348
        return -EC_IOCTL_ERRNO(ret);
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   349
    }
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   350
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   351
    pdo->index = data.index;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   352
    pdo->n_entries = data.entry_count;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   353
    pdo->entries = NULL;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   354
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   355
    return 0;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   356
}
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   357
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   358
/****************************************************************************/
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   359
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   360
int ecrt_master_get_pdo_entry(ec_master_t *master, uint16_t slave_position,
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   361
        uint8_t sync_index, uint16_t pdo_pos, uint16_t entry_pos,
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   362
        ec_pdo_entry_info_t *entry)
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   363
{
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   364
    ec_ioctl_slave_sync_pdo_entry_t data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   365
    int ret;
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   366
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   367
    if (sync_index >= EC_MAX_SYNC_MANAGERS)
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   368
        return -ENOENT;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   369
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   370
    memset(&data, 0x00, sizeof(ec_ioctl_slave_sync_pdo_entry_t));
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   371
    data.slave_position = slave_position;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   372
    data.sync_index = sync_index;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   373
    data.pdo_pos = pdo_pos;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   374
    data.entry_pos = entry_pos;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   375
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   376
    ret = ioctl(master->fd, EC_IOCTL_SLAVE_SYNC_PDO_ENTRY, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   377
    if (EC_IOCTL_IS_ERROR(ret)) {
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   378
        fprintf(stderr, "Failed to get pdo entry information: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   379
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   380
        return -EC_IOCTL_ERRNO(ret);
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   381
    }
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   382
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   383
    entry->index = data.index;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   384
    entry->subindex = data.subindex;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   385
    entry->bit_length = data.bit_length;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   386
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   387
    return 0;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   388
}
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   389
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   390
/****************************************************************************/
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   391
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   392
int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position,
2622
1aee02c1e294 Mark download data as const.
Gavin Lambert <uecasm@users.sourceforge.net>
parents: 2618
diff changeset
   393
        uint16_t index, uint8_t subindex, const uint8_t *data,
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   394
        size_t data_size, uint32_t *abort_code)
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   395
{
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   396
    ec_ioctl_slave_sdo_download_t download;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   397
    int ret;
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   398
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   399
    download.slave_position = slave_position;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   400
    download.sdo_index = index;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   401
    download.sdo_entry_subindex = subindex;
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   402
    download.complete_access = 0;
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   403
    download.data_size = data_size;
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   404
    download.data = data;
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   405
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   406
    ret = ioctl(master->fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, &download);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   407
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   408
        if (EC_IOCTL_ERRNO(ret) == EIO && abort_code) {
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   409
            *abort_code = download.abort_code;
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   410
        }
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   411
        fprintf(stderr, "Failed to execute SDO download: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   412
            strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   413
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   414
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   415
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   416
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   417
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   418
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   419
/****************************************************************************/
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   420
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   421
int ecrt_master_sdo_download_complete(ec_master_t *master,
2622
1aee02c1e294 Mark download data as const.
Gavin Lambert <uecasm@users.sourceforge.net>
parents: 2618
diff changeset
   422
        uint16_t slave_position, uint16_t index, const uint8_t *data,
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   423
        size_t data_size, uint32_t *abort_code)
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   424
{
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   425
    ec_ioctl_slave_sdo_download_t download;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   426
    int ret;
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   427
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   428
    download.slave_position = slave_position;
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   429
    download.sdo_index = index;
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   430
    download.sdo_entry_subindex = 0;
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2066
diff changeset
   431
    download.complete_access = 1;
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   432
    download.data_size = data_size;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   433
    download.data = data;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   434
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   435
    ret = ioctl(master->fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, &download);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   436
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   437
        if (EC_IOCTL_ERRNO(ret) == EIO && abort_code) {
1911
460baca4df83 Fixed errno usage in user library.
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   438
            *abort_code = download.abort_code;
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   439
        }
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   440
        fprintf(stderr, "Failed to execute SDO download: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   441
            strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   442
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   443
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   444
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   445
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   446
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   447
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   448
/****************************************************************************/
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   449
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   450
int ecrt_master_sdo_upload(ec_master_t *master, uint16_t slave_position,
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   451
        uint16_t index, uint8_t subindex, uint8_t *target,
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   452
        size_t target_size, size_t *result_size, uint32_t *abort_code)
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   453
{
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   454
    ec_ioctl_slave_sdo_upload_t upload;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   455
    int ret;
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   456
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   457
    upload.slave_position = slave_position;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   458
    upload.sdo_index = index;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   459
    upload.sdo_entry_subindex = subindex;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   460
    upload.target_size = target_size;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   461
    upload.target = target;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   462
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   463
    ret = ioctl(master->fd, EC_IOCTL_SLAVE_SDO_UPLOAD, &upload);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   464
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   465
        if (EC_IOCTL_ERRNO(ret) == EIO && abort_code) {
1911
460baca4df83 Fixed errno usage in user library.
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   466
            *abort_code = upload.abort_code;
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   467
        }
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   468
        fprintf(stderr, "Failed to execute SDO upload: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   469
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   470
        return -EC_IOCTL_ERRNO(ret);
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   471
    }
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   472
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   473
    *result_size = upload.data_size;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   474
    return 0;
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   475
}
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   476
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   477
/****************************************************************************/
1510
88b608a1a7f3 Improved bus information API.
Florian Pose <fp@igh-essen.com>
parents: 1508
diff changeset
   478
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   479
int ecrt_master_write_idn(ec_master_t *master, uint16_t slave_position,
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
   480
        uint8_t drive_no, uint16_t idn, uint8_t *data, size_t data_size,
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
   481
        uint16_t *error_code)
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   482
{
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   483
    ec_ioctl_slave_soe_write_t io;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   484
    int ret;
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   485
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   486
    io.slave_position = slave_position;
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
   487
    io.drive_no = drive_no;
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   488
    io.idn = idn;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   489
    io.data_size = data_size;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   490
    io.data = data;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   491
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   492
    ret = ioctl(master->fd, EC_IOCTL_SLAVE_SOE_WRITE, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   493
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   494
        if (EC_IOCTL_ERRNO(ret) == EIO && error_code) {
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   495
            *error_code = io.error_code;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   496
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   497
        fprintf(stderr, "Failed to write IDN: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   498
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   499
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   500
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   501
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   502
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   503
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   504
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   505
/****************************************************************************/
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   506
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   507
int ecrt_master_read_idn(ec_master_t *master, uint16_t slave_position,
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
   508
        uint8_t drive_no, uint16_t idn, uint8_t *target, size_t target_size,
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1913
diff changeset
   509
        size_t *result_size, uint16_t *error_code)
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   510
{
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   511
    ec_ioctl_slave_soe_read_t io;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   512
    int ret;
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   513
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   514
    io.slave_position = slave_position;
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
   515
    io.drive_no = drive_no;
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   516
    io.idn = idn;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   517
    io.mem_size = target_size;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   518
    io.data = target;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   519
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   520
    ret = ioctl(master->fd, EC_IOCTL_SLAVE_SOE_READ, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   521
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   522
        if (EC_IOCTL_ERRNO(ret) == EIO && error_code) {
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   523
            *error_code = io.error_code;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   524
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   525
        fprintf(stderr, "Failed to read IDN: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   526
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   527
        return -EC_IOCTL_ERRNO(ret);
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   528
    }
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   529
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   530
    *result_size = io.data_size;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   531
    return 0;
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   532
}
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   533
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   534
/****************************************************************************/
1913
cbef34ba142b Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE
Florian Pose <fp@igh-essen.com>
parents: 1911
diff changeset
   535
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   536
int ecrt_master_activate(ec_master_t *master)
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   537
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   538
    ec_ioctl_master_activate_t io;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   539
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   540
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   541
    ret = ioctl(master->fd, EC_IOCTL_ACTIVATE, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   542
    if (EC_IOCTL_IS_ERROR(ret)) {
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   543
        fprintf(stderr, "Failed to activate master: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   544
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   545
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   546
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   547
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   548
    master->process_data_size = io.process_data_size;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   549
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   550
    if (master->process_data_size) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   551
#ifdef USE_RTDM
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   552
        /* memory-mapping was already done in kernel. The user-space addess is
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   553
         * provided in the ioctl data.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   554
         */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   555
        master->process_data = io.process_data;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   556
#else
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   557
        master->process_data = mmap(0, master->process_data_size,
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   558
                PROT_READ | PROT_WRITE, MAP_SHARED, master->fd, 0);
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   559
        if (master->process_data == MAP_FAILED) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   560
            fprintf(stderr, "Failed to map process data: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   561
                    strerror(errno));
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   562
            master->process_data = NULL;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   563
            master->process_data_size = 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   564
            return -errno;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   565
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   566
#endif
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   567
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   568
        // Access the mapped region to cause the initial page fault
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   569
        master->process_data[0] = 0x00;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   570
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   571
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   572
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   573
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   574
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   575
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   576
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   577
void ecrt_master_deactivate(ec_master_t *master)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   578
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   579
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   580
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   581
    ret = ioctl(master->fd, EC_IOCTL_DEACTIVATE, NULL);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   582
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   583
        fprintf(stderr, "Failed to deactivate master: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   584
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   585
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   586
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   587
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   588
    ec_master_clear_config(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   589
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   590
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   591
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   592
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   593
int ecrt_master_set_send_interval(ec_master_t *master,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   594
        size_t send_interval_us)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   595
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   596
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   597
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   598
    ret = ioctl(master->fd, EC_IOCTL_SET_SEND_INTERVAL, &send_interval_us);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   599
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   600
        fprintf(stderr, "Failed to set send interval: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   601
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   602
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   603
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   604
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   605
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   606
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   607
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   608
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   609
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   610
size_t ecrt_master_send(ec_master_t *master)
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   611
{
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   612
    int ret;
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   613
    size_t sent_bytes = 0;
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   614
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   615
    ret = ioctl(master->fd, EC_IOCTL_SEND, &sent_bytes);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   616
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   617
        fprintf(stderr, "Failed to send: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   618
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   619
    }
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   620
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   621
    return sent_bytes;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   622
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   623
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   624
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   625
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   626
void ecrt_master_receive(ec_master_t *master)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   627
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   628
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   629
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   630
    ret = ioctl(master->fd, EC_IOCTL_RECEIVE, NULL);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   631
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   632
        fprintf(stderr, "Failed to receive: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   633
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   634
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   635
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   636
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   637
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   638
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   639
void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   640
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   641
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   642
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   643
    ret = ioctl(master->fd, EC_IOCTL_MASTER_STATE, state);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   644
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   645
        fprintf(stderr, "Failed to get master state: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   646
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   647
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   648
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   649
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   650
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   651
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   652
int ecrt_master_link_state(const ec_master_t *master, unsigned int dev_idx,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   653
        ec_master_link_state_t *state)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   654
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   655
    ec_ioctl_link_state_t io;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   656
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   657
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   658
    io.dev_idx = dev_idx;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   659
    io.state = state;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   660
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   661
    ret = ioctl(master->fd, EC_IOCTL_MASTER_LINK_STATE, &io);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   662
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   663
        fprintf(stderr, "Failed to get link state: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   664
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   665
        return -EC_IOCTL_ERRNO(ret);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   666
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   667
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   668
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   669
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   670
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   671
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   672
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   673
void ecrt_master_application_time(ec_master_t *master, uint64_t app_time)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   674
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   675
    ec_ioctl_app_time_t data;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   676
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   677
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   678
    data.app_time = app_time;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   679
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   680
    ret = ioctl(master->fd, EC_IOCTL_APP_TIME, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   681
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   682
        fprintf(stderr, "Failed to set application time: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   683
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   684
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   685
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   686
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   687
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   688
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   689
void ecrt_master_sync_reference_clock(ec_master_t *master)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   690
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   691
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   692
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   693
    ret = ioctl(master->fd, EC_IOCTL_SYNC_REF, NULL);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   694
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   695
        fprintf(stderr, "Failed to sync reference clock: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   696
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   697
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   698
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   699
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   700
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   701
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   702
void ecrt_master_sync_slave_clocks(ec_master_t *master)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   703
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   704
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   705
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   706
    ret = ioctl(master->fd, EC_IOCTL_SYNC_SLAVES, NULL);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   707
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   708
        fprintf(stderr, "Failed to sync slave clocks: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   709
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   710
    }
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   711
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   712
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   713
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   714
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   715
int ecrt_master_reference_clock_time(ec_master_t *master, uint32_t *time)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   716
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   717
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   718
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   719
    ret = ioctl(master->fd, EC_IOCTL_REF_CLOCK_TIME, time);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   720
    if (EC_IOCTL_IS_ERROR(ret)) {
2618
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   721
        ret = EC_IOCTL_ERRNO(ret);
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   722
        if (ret != EIO && ret != ENXIO) {
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   723
            // do not log if no refclk or no refclk time yet
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   724
            fprintf(stderr, "Failed to get reference clock time: %s\n",
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   725
                    strerror(ret));
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   726
        }
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   727
        return -ret;
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   728
    }
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   729
3affe9cd0b66 Ignore NXIO error otherwise this causes spam if network is empty or refclk not
Gavin Lambert <gavinl@compacsort.com>
parents: 2616
diff changeset
   730
    return 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   731
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   732
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   733
/****************************************************************************/
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   734
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   735
void ecrt_master_sync_monitor_queue(ec_master_t *master)
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   736
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   737
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   738
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   739
    ret = ioctl(master->fd, EC_IOCTL_SYNC_MON_QUEUE, NULL);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   740
    if (EC_IOCTL_IS_ERROR(ret)) {
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   741
        fprintf(stderr, "Failed to queue sync monitor datagram: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   742
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   743
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   744
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   745
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   746
/****************************************************************************/
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   747
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   748
uint32_t ecrt_master_sync_monitor_process(ec_master_t *master)
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   749
{
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   750
    uint32_t time_diff;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   751
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   752
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   753
    ret = ioctl(master->fd, EC_IOCTL_SYNC_MON_PROCESS, &time_diff);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   754
    if (EC_IOCTL_IS_ERROR(ret)) {
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   755
        time_diff = 0xffffffff;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   756
        fprintf(stderr, "Failed to process sync monitor datagram: %s\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   757
                strerror(EC_IOCTL_ERRNO(ret)));
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   758
    }
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   759
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   760
    return time_diff;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   761
}
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
   762
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   763
/****************************************************************************/
2009
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1975
diff changeset
   764
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1975
diff changeset
   765
void ecrt_master_reset(ec_master_t *master)
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1975
diff changeset
   766
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   767
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   768
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   769
    ret = ioctl(master->fd, EC_IOCTL_RESET, NULL);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   770
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   771
        fprintf(stderr, "Failed to reset master: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   772
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   773
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   774
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   775
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2246
diff changeset
   776
/****************************************************************************/