lib/voe_handler.c
author Christoph Mathys <ch1010832@ch10pc602>
Thu, 04 Nov 2010 09:32:58 +0100
branchredundancy
changeset 2313 7c5dded8e576
parent 1959 656f114153c2
child 2421 bc2d4bf9cbe5
child 2589 2b9c78543663
permissions -rw-r--r--
Added e1000 port for 2.6.31
1264
e7882f246d7a Implemented VoE handler in userspace.
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
 *  
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: 1314
diff changeset
     3
 *  $Id$
1266
dd1f501c4070 Added LGPL licence headers to userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
     4
 * 
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: 1314
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: 1314
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: 1314
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: 1314
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: 1314
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: 1314
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: 1314
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: 1314
diff changeset
    12
 *  of the License.
1287
cc7b679c74e9 Improved LGPL headers.
Florian Pose <fp@igh-essen.com>
parents: 1271
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: 1314
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: 1314
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: 1314
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: 1314
diff changeset
    17
 *  GNU Lesser General Public License for more details.
1287
cc7b679c74e9 Improved LGPL headers.
Florian Pose <fp@igh-essen.com>
parents: 1271
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: 1314
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: 1314
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: 1314
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: 1314
diff changeset
    22
 *  
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
    23
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
    24
 *  
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1350
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: 1350
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: 1350
diff changeset
    27
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
/** \file
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    32
 * Vendor specific over EtherCAT protocol handler functions.
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    37
#include <stdlib.h>
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    38
#include <sys/ioctl.h>
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include <stdio.h>
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    40
#include <errno.h>
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    41
#include <string.h>
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "voe_handler.h"
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "slave_config.h"
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "master.h"
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
#include "master/ioctl.h"
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    50
void ec_voe_handler_clear(ec_voe_handler_t *voe)
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    51
{
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    52
    if (voe->data)
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    53
        free(voe->data);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    54
}
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    55
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    56
/*****************************************************************************/
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    57
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
void ecrt_voe_handler_send_header(ec_voe_handler_t *voe, uint32_t vendor_id,
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        uint16_t vendor_type)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    data.vendor_id = &vendor_id;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    data.vendor_type = &vendor_type;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    68
    if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_SEND_HEADER, &data) == -1)
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    69
        fprintf(stderr, "Failed to set VoE send header: %s\n",
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    70
                strerror(errno));
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
void ecrt_voe_handler_received_header(const ec_voe_handler_t *voe,
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        uint32_t *vendor_id, uint16_t *vendor_type)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    data.vendor_id = vendor_id;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    data.vendor_type = vendor_type;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    85
    if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_REC_HEADER, &data) == -1)
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    86
        fprintf(stderr, "Failed to get received VoE header: %s\n",
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    87
                strerror(errno));
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
uint8_t *ecrt_voe_handler_data(ec_voe_handler_t *voe)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    return voe->data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
size_t ecrt_voe_handler_data_size(const ec_voe_handler_t *voe)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    return voe->data_size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
void ecrt_voe_handler_read(ec_voe_handler_t *voe)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   113
    if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ, &data) == -1)
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   114
        fprintf(stderr, "Failed to initiate VoE reading: %s\n",
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   115
                strerror(errno));
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   120
void ecrt_voe_handler_read_nosync(ec_voe_handler_t *voe)
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   121
{
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   122
    ec_ioctl_voe_t data;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   123
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   124
    data.config_index = voe->config->index;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   125
    data.voe_index = voe->index;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   126
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   127
    if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ_NOSYNC, &data) == -1)
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   128
        fprintf(stderr, "Failed to initiate VoE reading: %s\n",
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   129
                strerror(errno));
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   130
}
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   131
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   132
/*****************************************************************************/
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   133
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
void ecrt_voe_handler_write(ec_voe_handler_t *voe, size_t size)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
    data.size = size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    data.data = voe->data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   143
    if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_WRITE, &data) == -1)
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   144
        fprintf(stderr, "Failed to initiate VoE writing: %s\n",
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   145
                strerror(errno));
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
ec_request_state_t ecrt_voe_handler_execute(ec_voe_handler_t *voe)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_EXEC, &data) == -1) {
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   158
        fprintf(stderr, "Failed to execute VoE handler: %s\n",
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   159
                strerror(errno));
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
        return EC_REQUEST_ERROR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
    if (data.size) { // new data waiting to be copied
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        if (voe->mem_size < data.size) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
            if (voe->data)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
                free(voe->data);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
            voe->data = malloc(data.size);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
            if (!voe->data) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
                voe->mem_size = 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
                fprintf(stderr, "Failed to allocate VoE data memory!");
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
                return EC_REQUEST_ERROR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
            }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
            voe->mem_size = data.size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
        }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   176
        data.data = voe->data;
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   177
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_DATA, &data) == -1) {
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   179
            fprintf(stderr, "Failed to get VoE data: %s\n", strerror(errno));
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
            return EC_REQUEST_ERROR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
        }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
        voe->data_size = data.size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
    return data.state;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
/*****************************************************************************/