lib/voe_handler.c
author Florian Pose <fp@igh-essen.com>
Tue, 24 Feb 2009 08:53:13 +0000
changeset 1356 ce338c278809
parent 1350 cd278db5a872
child 1363 11c0b2caa253
permissions -rw-r--r--
TODO.
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
 *  
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
    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: 1314
diff changeset
    24
 *  the 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
    25
 *
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
/** \file
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    29
 * Vendor specific over EtherCAT protocol handler functions.
1264
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
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    34
#include <stdlib.h>
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    35
#include <sys/ioctl.h>
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include <stdio.h>
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    37
#include <errno.h>
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    38
#include <string.h>
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "voe_handler.h"
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "slave_config.h"
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "master.h"
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "master/ioctl.h"
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
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
    48
        uint16_t vendor_type)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
    data.vendor_id = &vendor_id;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
    data.vendor_type = &vendor_type;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    57
    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
    58
        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
    59
                strerror(errno));
1264
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
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
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
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
    65
        uint32_t *vendor_id, uint16_t *vendor_type)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    data.vendor_id = vendor_id;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    data.vendor_type = vendor_type;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
    74
    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
    75
        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
    76
                strerror(errno));
1264
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
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
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
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
    82
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    return voe->data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
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
    89
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    return voe->data_size;
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
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
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
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
    96
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    ec_ioctl_voe_t data;
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
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   102
    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
   103
        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
   104
                strerror(errno));
1264
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
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
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   109
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
   110
{
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   111
    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
   112
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   113
    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
   114
    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
   115
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   116
    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
   117
        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
   118
                strerror(errno));
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   119
}
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1287
diff changeset
   120
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
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
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
   124
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    data.size = size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
    data.data = voe->data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   132
    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
   133
        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
   134
                strerror(errno));
1264
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
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
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
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
   140
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    data.config_index = voe->config->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    data.voe_index = voe->index;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    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
   147
        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
   148
                strerror(errno));
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
        return EC_REQUEST_ERROR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    }
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
    if (data.size) { // new data waiting to be copied
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
        if (voe->mem_size < data.size) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
            if (voe->data)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
                free(voe->data);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
            voe->data = malloc(data.size);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
            if (!voe->data) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
                voe->mem_size = 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
                fprintf(stderr, "Failed to allocate VoE data memory!");
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
            voe->mem_size = data.size;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
        }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
1271
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   165
        data.data = voe->data;
19f9e9b6cf2c Fixed VoE data reading in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1266
diff changeset
   166
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
        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
   168
            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
   169
            return EC_REQUEST_ERROR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
        }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
        voe->data_size = data.size;
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
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    return data.state;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
/*****************************************************************************/