fp@1264: /******************************************************************************
fp@2589: *
fp@1326: * $Id$
fp@2589: *
fp@2589: * Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH
fp@2589: *
fp@1326: * This file is part of the IgH EtherCAT master userspace library.
fp@2589: *
fp@1326: * The IgH EtherCAT master userspace library is free software; you can
fp@1326: * redistribute it and/or modify it under the terms of the GNU Lesser General
fp@1326: * Public License as published by the Free Software Foundation; version 2.1
fp@1326: * of the License.
fp@1287: *
fp@1326: * The IgH EtherCAT master userspace library is distributed in the hope that
fp@1326: * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fp@1326: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fp@1326: * GNU Lesser General Public License for more details.
fp@1287: *
fp@1326: * You should have received a copy of the GNU Lesser General Public License
fp@1326: * along with the IgH EtherCAT master userspace library. If not, see
fp@1326: * .
fp@2589: *
fp@1363: * ---
fp@2589: *
fp@1363: * The license mentioned above concerns the source code only. Using the
fp@1363: * EtherCAT technology and brand is only permitted in compliance with the
fp@1363: * industrial property and similar rights of Beckhoff Automation GmbH.
fp@1264: *
fp@1264: *****************************************************************************/
fp@1264:
fp@1264: /** \file
fp@1327: * Vendor specific over EtherCAT protocol handler functions.
fp@1264: */
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1271: #include
fp@1264: #include
fp@1271: #include
fp@1264:
fp@2589: #include "ioctl.h"
fp@1264: #include "voe_handler.h"
fp@1264: #include "slave_config.h"
fp@1264: #include "master.h"
fp@1264:
fp@1264: /*****************************************************************************/
fp@1264:
fp@1959: void ec_voe_handler_clear(ec_voe_handler_t *voe)
fp@1959: {
fp@2589: if (voe->data) {
fp@1959: free(voe->data);
fp@2589: }
fp@1959: }
fp@1959:
fp@1959: /*****************************************************************************/
fp@1959:
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@2589: int ret;
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@2589: ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_SEND_HEADER, &data);
fp@2589: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1271: fprintf(stderr, "Failed to set VoE send header: %s\n",
fp@2589: strerror(EC_IOCTL_ERRNO(ret)));
fp@2589: }
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@2589: int ret;
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@2589: ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_REC_HEADER, &data);
fp@2589: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1271: fprintf(stderr, "Failed to get received VoE header: %s\n",
fp@2589: strerror(EC_IOCTL_ERRNO(ret)));
fp@2589: }
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@2589: int ret;
fp@2589:
fp@2589: data.config_index = voe->config->index;
fp@2589: data.voe_index = voe->index;
fp@2589:
fp@2589: ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ, &data);
fp@2589: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1271: fprintf(stderr, "Failed to initiate VoE reading: %s\n",
fp@2589: strerror(EC_IOCTL_ERRNO(ret)));
fp@2589: }
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@2589: int ret;
fp@2589:
fp@2589: data.config_index = voe->config->index;
fp@2589: data.voe_index = voe->index;
fp@2589:
fp@2589: ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_READ_NOSYNC, &data);
fp@2589: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1314: fprintf(stderr, "Failed to initiate VoE reading: %s\n",
fp@2589: strerror(EC_IOCTL_ERRNO(ret)));
fp@2589: }
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@2589: int ret;
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@2589: ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_WRITE, &data);
fp@2589: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1271: fprintf(stderr, "Failed to initiate VoE writing: %s\n",
fp@2589: strerror(EC_IOCTL_ERRNO(ret)));
fp@2589: }
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@2589: int ret;
fp@2589:
fp@2589: data.config_index = voe->config->index;
fp@2589: data.voe_index = voe->index;
fp@2589:
fp@2589: ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_EXEC, &data);
fp@2589: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1271: fprintf(stderr, "Failed to execute VoE handler: %s\n",
fp@2589: strerror(EC_IOCTL_ERRNO(ret)));
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@2589: fprintf(stderr, "Received %zu bytes do not fit info VoE data"
fp@2589: " memory (%zu bytes)!\n", data.size, voe->mem_size);
fp@2589: return EC_REQUEST_ERROR;
fp@1264: }
fp@1264:
fp@1271: data.data = voe->data;
fp@1271:
fp@2589: ret = ioctl(voe->config->master->fd, EC_IOCTL_VOE_DATA, &data);
fp@2589: if (EC_IOCTL_IS_ERROR(ret)) {
fp@2589: fprintf(stderr, "Failed to get VoE data: %s\n",
fp@2589: strerror(EC_IOCTL_ERRNO(ret)));
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: /*****************************************************************************/