lib/master.c
author Florian Pose <fp@igh-essen.com>
Mon, 02 Feb 2009 13:32:48 +0000
changeset 1350 cd278db5a872
parent 1341 32ba7ffb6c7f
child 1363 11c0b2caa253
permissions -rw-r--r--
Minor fix in VoE handler.
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
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: 1259
diff changeset
     2
 *  
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     3
 *  $Id$
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
     4
 *  
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
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
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
     6
 *  
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.
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
     8
 *  
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/>.
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
    22
 *  
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
    23
 *  Using the EtherCAT technology and brand is permitted in compliance with
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
    24
 *  the 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
    25
 *
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
#include <stdlib.h>
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#include <sys/ioctl.h>
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <stdio.h>
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <errno.h>
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <string.h>
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    33
#include <sys/mman.h>
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include "master.h"
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include "domain.h"
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    37
#include "slave_config.h"
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "master/ioctl.h"
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
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
    43
{
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
    ec_domain_t *domain;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
    int index;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    domain = malloc(sizeof(ec_domain_t));
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    if (!domain) {
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
        fprintf(stderr, "Failed to allocate memory.\n");
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
        return 0;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
    }
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
    
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
    index = ioctl(master->fd, EC_IOCTL_CREATE_DOMAIN, NULL);
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
    if (index == -1) {
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        fprintf(stderr, "Failed to create domain: %s\n", strerror(errno));
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        free(domain);
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        return 0; 
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    }
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    domain->index = (unsigned int) index;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    61
    domain->master = master;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    62
    domain->process_data = NULL;
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    return domain;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
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
    69
        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
    70
        uint32_t product_code)
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
{
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    72
    ec_ioctl_config_t data;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    73
    ec_slave_config_t *sc;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    74
    int index;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    75
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    76
    sc = malloc(sizeof(ec_slave_config_t));
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    77
    if (!sc) {
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    78
        fprintf(stderr, "Failed to allocate memory.\n");
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    79
        return 0;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    80
    }
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    81
    
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    82
    data.alias = alias;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    83
    data.position = position;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    84
    data.vendor_id = vendor_id;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    85
    data.product_code = product_code;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    86
    
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    87
    if (ioctl(master->fd, EC_IOCTL_CREATE_SLAVE_CONFIG, &data) == -1) {
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    88
        fprintf(stderr, "Failed to create slave config: %s\n",
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    89
                strerror(errno));
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    90
        free(sc);
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    91
        return 0; 
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    92
    }
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    93
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    94
    sc->master = master;
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    95
    sc->index = data.config_index;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    96
    sc->alias = alias;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
    97
    sc->position = position;
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
    98
    return sc;
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
1341
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   103
int ecrt_master_slave(ec_master_t *master, uint16_t position,
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   104
        ec_slave_info_t *slave_info)
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   105
{
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   106
    ec_ioctl_slave_t data;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   107
    int index;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   108
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   109
    data.position = position;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   110
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   111
    if (ioctl(master->fd, EC_IOCTL_SLAVE, &data) == -1) {
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   112
        fprintf(stderr, "Failed to get slave info: %s\n",
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   113
                strerror(errno));
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   114
        return -1;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   115
    }
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   116
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   117
    slave_info->position = data.position;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   118
    slave_info->vendor_id = data.vendor_id;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   119
    slave_info->product_code = data.product_code;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   120
    slave_info->revision_number = data.revision_number;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   121
    slave_info->serial_number = data.serial_number;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   122
    slave_info->alias = data.alias;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   123
    slave_info->current_on_ebus = data.current_on_ebus;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   124
    slave_info->al_state = data.al_state;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   125
    slave_info->error_flag = data.error_flag;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   126
    slave_info->sync_count = data.sync_count;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   127
    slave_info->sdo_count = data.sdo_count;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   128
    strncpy(slave_info->name, data.name, EC_IOCTL_STRING_SIZE);
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   129
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   130
    return 0;
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   131
}
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   132
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   133
/*****************************************************************************/
32ba7ffb6c7f Added ecrt_master_slave().
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   134
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
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
   136
{
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   137
    if (ioctl(master->fd, EC_IOCTL_ACTIVATE,
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   138
                &master->process_data_size) == -1) {
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   139
        fprintf(stderr, "Failed to activate master: %s\n",
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   140
                strerror(errno));
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   141
        return -1; // FIXME
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   142
    }
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   143
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   144
    if (master->process_data_size) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   145
        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
   146
                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
   147
        if (master->process_data == MAP_FAILED) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   148
            fprintf(stderr, "Failed to map process data: %s", strerror(errno));
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   149
            master->process_data = NULL;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   150
            master->process_data_size = 0;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   151
            return -1; // FIXME
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   152
        }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   153
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   154
        // Access the mapped region to cause the initial page fault
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   155
        printf("pd: %x\n", master->process_data[0]);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   156
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
   157
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    return 0;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
void ecrt_master_send(ec_master_t *master)
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
{
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   165
    if (ioctl(master->fd, EC_IOCTL_SEND, NULL) == -1) {
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   166
        fprintf(stderr, "Failed to send: %s\n", strerror(errno));
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   167
    }
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
void ecrt_master_receive(ec_master_t *master)
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
{
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   174
    if (ioctl(master->fd, EC_IOCTL_RECEIVE, NULL) == -1) {
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   175
        fprintf(stderr, "Failed to receive: %s\n", strerror(errno));
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
   176
    }
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
{
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   183
    if (ioctl(master->fd, EC_IOCTL_MASTER_STATE, state) == -1) {
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   184
        fprintf(stderr, "Failed to get master state: %s\n", strerror(errno));
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
   185
    }
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
/*****************************************************************************/