lib/slave_config.c
author Florian Pose <fp@igh-essen.com>
Tue, 18 Nov 2008 11:13:49 +0000
changeset 1314 b3d06a8807b3
parent 1313 ed15eef57d5c
child 1326 ef907b0b5125
permissions -rw-r--r--
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
1266
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
     2
 *  
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
     3
 * $Id$
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
     4
 * 
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
     5
 * Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
     6
 * 
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
     7
 * This file is part of the IgH EtherCAT master userspace library.
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
     8
 * 
1287
cc7b679c74e9 Improved LGPL headers.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
     9
 * The IgH EtherCAT master userspace library is free software; you can
1266
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    10
 * redistribute it and/or modify it under the terms of the GNU Lesser General
1287
cc7b679c74e9 Improved LGPL headers.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    11
 * Public License as published by the Free Software Foundation; version 2.1 of
1266
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    12
 * the License.
1287
cc7b679c74e9 Improved LGPL headers.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    13
 *
1266
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    14
 * The IgH EtherCAT master userspace library is distributed in the hope that
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    15
 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    16
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
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
 *
1266
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    19
 * You should have received a copy of the GNU Lesser General Public License
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    20
 * along with the IgH EtherCAT master userspace library. If not, see
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    21
 * <http://www.gnu.org/licenses/>.
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    22
 * 
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    23
 * The right to use EtherCAT Technology is granted and comes free of charge
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    24
 * under condition of compatibility of product made by Licensee. People
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    25
 * intending to distribute/sell products based on the code, have to sign an
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    26
 * agreement to guarantee that products using software based on IgH EtherCAT
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    27
 * master stay compatible with the actual EtherCAT specification (which are
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    28
 * released themselves as an open standard) as the (only) precondition to have
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    29
 * the right to use EtherCAT Technology, IP and trade marks.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <stdlib.h>
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <sys/ioctl.h>
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include <stdio.h>
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include <errno.h>
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <string.h>
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "slave_config.h"
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "domain.h"
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
    41
#include "voe_handler.h"
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "master.h"
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "master/ioctl.h"
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
int ecrt_slave_config_sync_manager(ec_slave_config_t *sc, uint8_t sync_index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
        ec_direction_t dir)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    ec_ioctl_config_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
    unsigned int i;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
    if (sync_index >= EC_MAX_SYNC_MANAGERS)
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
    54
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
    memset(&data, 0x00, sizeof(ec_ioctl_config_t));
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    data.syncs[sync_index].dir = dir;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    if (ioctl(sc->master->fd, EC_IOCTL_SC_SYNC, &data) == -1) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
        fprintf(stderr, "Failed to config sync manager: %s\n",
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
                strerror(errno));
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
    63
        return -1; // FIXME
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
int ecrt_slave_config_pdo_assign_add(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
        uint8_t sync_index, uint16_t pdo_index)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    ec_ioctl_config_pdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    data.sync_index = sync_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    data.index = pdo_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    if (ioctl(sc->master->fd, EC_IOCTL_SC_ADD_PDO, &data) == -1) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        fprintf(stderr, "Failed to add Pdo: %s\n",
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
                strerror(errno));
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
    83
        return -1;  // FIXME
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
void ecrt_slave_config_pdo_assign_clear(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
        uint8_t sync_index)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    ec_ioctl_config_pdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    data.sync_index = sync_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    if (ioctl(sc->master->fd, EC_IOCTL_SC_CLEAR_PDOS, &data) == -1) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        fprintf(stderr, "Failed to clear Pdos: %s\n",
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
                strerror(errno));
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
int ecrt_slave_config_pdo_mapping_add(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
        uint16_t pdo_index, uint16_t entry_index, uint8_t entry_subindex,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        uint8_t entry_bit_length)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    ec_ioctl_add_pdo_entry_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    data.pdo_index = pdo_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    data.entry_index = entry_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    data.entry_subindex = entry_subindex;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    data.entry_bit_length = entry_bit_length;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    if (ioctl(sc->master->fd, EC_IOCTL_SC_ADD_ENTRY, &data) == -1) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
        fprintf(stderr, "Failed to add Pdo entry: %s\n",
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
                strerror(errno));
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   122
        return -1;  // FIXME
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
void ecrt_slave_config_pdo_mapping_clear(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
        uint16_t pdo_index)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    ec_ioctl_config_pdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
    data.index = pdo_index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    if (ioctl(sc->master->fd, EC_IOCTL_SC_CLEAR_ENTRIES, &data) == -1) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
        fprintf(stderr, "Failed to clear Pdo entries: %s\n",
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
                strerror(errno));
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
int ecrt_slave_config_pdos(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
        unsigned int n_syncs, const ec_sync_info_t syncs[])
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   149
    int ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    unsigned int i, j, k;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    const ec_sync_info_t *sync_info;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    const ec_pdo_info_t *pdo_info;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
    const ec_pdo_entry_info_t *entry_info;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    if (!syncs)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
        return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    for (i = 0; i < n_syncs; i++) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
        sync_info = &syncs[i];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
        if (sync_info->index == (uint8_t) EC_END)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
            break;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        if (sync_info->index >= EC_MAX_SYNC_MANAGERS) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
            fprintf(stderr, "Invalid sync manager index %u!\n",
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
                    sync_info->index);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   167
            return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
        }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   170
        ret = ecrt_slave_config_sync_manager(
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   171
                sc, sync_info->index, sync_info->dir);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   172
        if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   173
            return ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
        if (sync_info->n_pdos && sync_info->pdos) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
            ecrt_slave_config_pdo_assign_clear(sc, sync_info->index);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
            for (j = 0; j < sync_info->n_pdos; j++) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
                pdo_info = &sync_info->pdos[j];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   181
                ret = ecrt_slave_config_pdo_assign_add(
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   182
                        sc, sync_info->index, pdo_info->index);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   183
                if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   184
                    return ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
                if (pdo_info->n_entries && pdo_info->entries) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
                    ecrt_slave_config_pdo_mapping_clear(sc, pdo_info->index);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
                    for (k = 0; k < pdo_info->n_entries; k++) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
                        entry_info = &pdo_info->entries[k];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   192
                        ret = ecrt_slave_config_pdo_mapping_add(sc,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   193
                                pdo_info->index, entry_info->index,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   194
                                entry_info->subindex,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   195
                                entry_info->bit_length);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   196
                        if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   197
                            return ret;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
                    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
                }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
            }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
        }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
int ecrt_slave_config_reg_pdo_entry(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
        ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
        uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
        uint8_t subindex,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
        ec_domain_t *domain,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
        unsigned int *bit_position
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
    ec_ioctl_reg_pdo_entry_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
    int ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    data.entry_index = index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
    data.entry_subindex = subindex;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
    data.domain_index = domain->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
    ret = ioctl(sc->master->fd, EC_IOCTL_SC_REG_PDO_ENTRY, &data);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
    if (ret == -1) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
        fprintf(stderr, "Failed to register Pdo entry: %s\n",
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
                strerror(errno));
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   229
        return -2; // FIXME
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
    if (bit_position) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
        *bit_position = data.bit_position;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    } else {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
        if (data.bit_position) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
            fprintf(stderr, "Pdo entry 0x%04X:%02X does not byte-align "
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
                    "in config %u:%u.\n", index, subindex,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
                    sc->alias, sc->position);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   239
            return -3; // FIXME
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
        }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
    return ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
int ecrt_slave_config_sdo(ec_slave_config_t *sc, uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
        uint8_t subindex, const uint8_t *sdo_data, size_t size)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
    ec_ioctl_sc_sdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
    data.config_index = sc->index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
    data.index = index;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
    data.subindex = subindex;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
    data.data = sdo_data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
    data.size = size;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
    if (ioctl(sc->master->fd, EC_IOCTL_SC_REG_PDO_ENTRY, &data) == -1) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
        fprintf(stderr, "Failed to configure Sdo.\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   261
        return -1; // FIXME
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
int ecrt_slave_config_sdo8(ec_slave_config_t *sc, uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
        uint8_t subindex, uint8_t value)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
    uint8_t data[1];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
    EC_WRITE_U8(data, value);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
    return ecrt_slave_config_sdo(sc, index, subindex, data, 1);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
int ecrt_slave_config_sdo16(ec_slave_config_t *sc, uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
        uint8_t subindex, uint16_t value)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
    uint8_t data[2];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
    EC_WRITE_U16(data, value);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
    return ecrt_slave_config_sdo(sc, index, subindex, data, 2);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
int ecrt_slave_config_sdo32(ec_slave_config_t *sc, uint16_t index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
        uint8_t subindex, uint32_t value)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
    uint8_t data[4];
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
    EC_WRITE_U32(data, value);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
    return ecrt_slave_config_sdo(sc, index, subindex, data, 4);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
ec_sdo_request_t *ecrt_slave_config_create_sdo_request(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
        uint16_t index, uint8_t subindex, size_t size)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
{
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   305
    return 0; // TODO
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
ec_voe_handler_t *ecrt_slave_config_create_voe_handler(ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
        size_t size)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
{
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   313
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   314
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   315
    unsigned int index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   316
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   317
    voe = malloc(sizeof(ec_voe_handler_t));
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   318
    if (!voe) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   319
        fprintf(stderr, "Failed to allocate memory.\n");
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   320
        return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   321
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   322
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   323
    if (size) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   324
        voe->data = malloc(size);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   325
        if (!voe->data) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   326
            fprintf(stderr, "Failed to allocate %u bytes of VoE data"
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   327
                    " memory.\n", size);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   328
            free(voe);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   329
            return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   330
        }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   331
    } else {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   332
        voe->data = NULL;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   333
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   334
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   335
    data.config_index = sc->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   336
    data.size = size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   337
    
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   338
    if (ioctl(sc->master->fd, EC_IOCTL_SC_VOE, &data) == -1) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   339
        fprintf(stderr, "Failed to create VoE handler: %s\n",
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   340
                strerror(errno));
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   341
        if (voe->data)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   342
            free(voe->data);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   343
        free(voe);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   344
        return NULL; 
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   345
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   346
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   347
    voe->config = sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   348
    voe->index = data.voe_index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   349
    voe->data_size = size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   350
    voe->mem_size = size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
   351
    return voe;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
void ecrt_slave_config_state(const ec_slave_config_t *sc,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
        ec_slave_config_state_t *state)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
{
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   359
    ec_ioctl_sc_state_t data;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   360
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   361
    data.config_index = sc->index;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   362
    data.state = state;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   363
    
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   364
    if (ioctl(sc->master->fd, EC_IOCTL_SC_STATE, &data) == -1) {
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   365
        fprintf(stderr, "Failed to get slave configuration state: %s\n",
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   366
                strerror(errno));
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   367
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   368
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   369
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   370
/*****************************************************************************/