fp@1264: /******************************************************************************
fp@1266: *
fp@1266: * $Id$
fp@1266: *
fp@1266: * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
fp@1266: *
fp@1266: * This file is part of the IgH EtherCAT master userspace library.
fp@1266: *
fp@1287: * The IgH EtherCAT master userspace library is free software; you can
fp@1266: * redistribute it and/or modify it under the terms of the GNU Lesser General
fp@1287: * Public License as published by the Free Software Foundation; version 2.1 of
fp@1266: * the License.
fp@1287: *
fp@1266: * The IgH EtherCAT master userspace library is distributed in the hope that
fp@1266: * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fp@1266: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fp@1266: * GNU Lesser General Public License for more details.
fp@1287: *
fp@1266: * You should have received a copy of the GNU Lesser General Public License
fp@1266: * along with the IgH EtherCAT master userspace library. If not, see
fp@1266: * .
fp@1266: *
fp@1266: * The right to use EtherCAT Technology is granted and comes free of charge
fp@1266: * under condition of compatibility of product made by Licensee. People
fp@1266: * intending to distribute/sell products based on the code, have to sign an
fp@1266: * agreement to guarantee that products using software based on IgH EtherCAT
fp@1266: * master stay compatible with the actual EtherCAT specification (which are
fp@1266: * released themselves as an open standard) as the (only) precondition to have
fp@1266: * the right to use EtherCAT Technology, IP and trade marks.
fp@1264: *
fp@1264: *****************************************************************************/
fp@1264:
fp@1264: /** \file
fp@1264: * Vendor-specific-over-EtherCAT protocol handler functions.
fp@1264: */
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1271: #include
fp@1271: #include
fp@1264: #include
fp@1271: #include
fp@1271: #include
fp@1264:
fp@1264: #include "voe_handler.h"
fp@1264: #include "slave_config.h"
fp@1264: #include "master.h"
fp@1264: #include "master/ioctl.h"
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1264: void ecrt_voe_handler_send_header(ec_voe_handler_t *voe, uint32_t vendor_id,
fp@1264: uint16_t vendor_type)
fp@1264: {
fp@1264: ec_ioctl_voe_t data;
fp@1264:
fp@1264: data.config_index = voe->config->index;
fp@1264: data.voe_index = voe->index;
fp@1264: data.vendor_id = &vendor_id;
fp@1264: data.vendor_type = &vendor_type;
fp@1264:
fp@1271: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_SEND_HEADER, &data) == -1)
fp@1271: fprintf(stderr, "Failed to set VoE send header: %s\n",
fp@1271: strerror(errno));
fp@1264: }
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1264: void ecrt_voe_handler_received_header(const ec_voe_handler_t *voe,
fp@1264: uint32_t *vendor_id, uint16_t *vendor_type)
fp@1264: {
fp@1264: ec_ioctl_voe_t data;
fp@1264:
fp@1264: data.config_index = voe->config->index;
fp@1264: data.voe_index = voe->index;
fp@1264: data.vendor_id = vendor_id;
fp@1264: data.vendor_type = vendor_type;
fp@1264:
fp@1271: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_REC_HEADER, &data) == -1)
fp@1271: fprintf(stderr, "Failed to get received VoE header: %s\n",
fp@1271: strerror(errno));
fp@1264: }
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1264: uint8_t *ecrt_voe_handler_data(ec_voe_handler_t *voe)
fp@1264: {
fp@1264: return voe->data;
fp@1264: }
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1264: size_t ecrt_voe_handler_data_size(const ec_voe_handler_t *voe)
fp@1264: {
fp@1264: return voe->data_size;
fp@1264: }
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1264: void ecrt_voe_handler_read(ec_voe_handler_t *voe)
fp@1264: {
fp@1264: ec_ioctl_voe_t data;
fp@1264:
fp@1264: data.config_index = voe->config->index;
fp@1264: data.voe_index = voe->index;
fp@1264:
fp@1271: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ, &data) == -1)
fp@1271: fprintf(stderr, "Failed to initiate VoE reading: %s\n",
fp@1271: strerror(errno));
fp@1264: }
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1314: void ecrt_voe_handler_read_nosync(ec_voe_handler_t *voe)
fp@1314: {
fp@1314: ec_ioctl_voe_t data;
fp@1314:
fp@1314: data.config_index = voe->config->index;
fp@1314: data.voe_index = voe->index;
fp@1314:
fp@1314: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ_NOSYNC, &data) == -1)
fp@1314: fprintf(stderr, "Failed to initiate VoE reading: %s\n",
fp@1314: strerror(errno));
fp@1314: }
fp@1314:
fp@1314: /*****************************************************************************/
fp@1314:
fp@1264: void ecrt_voe_handler_write(ec_voe_handler_t *voe, size_t size)
fp@1264: {
fp@1264: ec_ioctl_voe_t data;
fp@1264:
fp@1264: data.config_index = voe->config->index;
fp@1264: data.voe_index = voe->index;
fp@1264: data.size = size;
fp@1264: data.data = voe->data;
fp@1264:
fp@1271: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_WRITE, &data) == -1)
fp@1271: fprintf(stderr, "Failed to initiate VoE writing: %s\n",
fp@1271: strerror(errno));
fp@1264: }
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1264: ec_request_state_t ecrt_voe_handler_execute(ec_voe_handler_t *voe)
fp@1264: {
fp@1264: ec_ioctl_voe_t data;
fp@1264:
fp@1264: data.config_index = voe->config->index;
fp@1264: data.voe_index = voe->index;
fp@1264: data.size = 0;
fp@1264:
fp@1264: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_EXEC, &data) == -1) {
fp@1271: fprintf(stderr, "Failed to execute VoE handler: %s\n",
fp@1271: strerror(errno));
fp@1264: return EC_REQUEST_ERROR;
fp@1264: }
fp@1264:
fp@1264: if (data.size) { // new data waiting to be copied
fp@1264: if (voe->mem_size < data.size) {
fp@1264: if (voe->data)
fp@1264: free(voe->data);
fp@1264: voe->data = malloc(data.size);
fp@1264: if (!voe->data) {
fp@1264: voe->mem_size = 0;
fp@1264: fprintf(stderr, "Failed to allocate VoE data memory!");
fp@1264: return EC_REQUEST_ERROR;
fp@1264: }
fp@1264: voe->mem_size = data.size;
fp@1264: }
fp@1264:
fp@1271: data.data = voe->data;
fp@1271:
fp@1264: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_DATA, &data) == -1) {
fp@1271: fprintf(stderr, "Failed to get VoE data: %s\n", strerror(errno));
fp@1264: return EC_REQUEST_ERROR;
fp@1264: }
fp@1264: voe->data_size = data.size;
fp@1264: }
fp@1264:
fp@1264: return data.state;
fp@1264: }
fp@1264:
fp@1264: /*****************************************************************************/