fp@1264: /****************************************************************************** fp@1264: * fp@1264: * $Id$ fp@1264: * fp@1264: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@1264: * fp@1264: * This file is part of the IgH EtherCAT Master. fp@1264: * fp@1264: * The IgH EtherCAT Master is free software; you can redistribute it fp@1264: * and/or modify it under the terms of the GNU General Public License fp@1264: * as published by the Free Software Foundation; either version 2 of the fp@1264: * License, or (at your option) any later version. fp@1264: * fp@1264: * The IgH EtherCAT Master is distributed in the hope that it will be fp@1264: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1264: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@1264: * GNU General Public License for more details. fp@1264: * fp@1264: * You should have received a copy of the GNU General Public License fp@1264: * along with the IgH EtherCAT Master; if not, write to the Free Software fp@1264: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@1264: * fp@1264: * The right to use EtherCAT Technology is granted and comes free of fp@1264: * charge under condition of compatibility of product made by fp@1264: * Licensee. People intending to distribute/sell products based on the fp@1264: * code, have to sign an agreement to guarantee that products using fp@1264: * software based on IgH EtherCAT master stay compatible with the actual fp@1264: * EtherCAT specification (which are released themselves as an open fp@1264: * standard) as the (only) precondition to have the right to use EtherCAT fp@1264: * 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@1264: #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@1264: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_SEND_HEADER, &data) == -1) { fp@1264: fprintf(stderr, "Failed to set VoE send header.\n"); fp@1264: } 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@1264: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_REC_HEADER, &data) == -1) { fp@1264: fprintf(stderr, "Failed to get received VoE header.\n"); fp@1264: } 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@1264: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ, &data) == -1) { fp@1264: fprintf(stderr, "Failed to initiate VoE reading.\n"); fp@1264: } fp@1264: } fp@1264: fp@1264: /*****************************************************************************/ fp@1264: 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@1264: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_WRITE, &data) == -1) { fp@1264: fprintf(stderr, "Failed to initiate VoE reading.\n"); fp@1264: } 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@1264: fprintf(stderr, "Failed to initiate VoE reading.\n"); 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@1264: if (ioctl(voe->config->master->fd, EC_IOCTL_VOE_DATA, &data) == -1) { fp@1264: fprintf(stderr, "Failed to get VoE data!\n"); 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: /*****************************************************************************/