fp@2443: /****************************************************************************** fp@2443: * fp@2443: * $Id$ fp@2443: * fp@2443: * Copyright (C) 2012 Florian Pose, Ingenieurgemeinschaft IgH fp@2443: * fp@2443: * This file is part of the IgH EtherCAT master userspace library. fp@2443: * fp@2443: * The IgH EtherCAT master userspace library is free software; you can fp@2443: * redistribute it and/or modify it under the terms of the GNU Lesser General fp@2443: * Public License as published by the Free Software Foundation; version 2.1 fp@2443: * of the License. fp@2443: * fp@2443: * The IgH EtherCAT master userspace library is distributed in the hope that fp@2443: * it will be useful, but WITHOUT ANY WARRANTY; without even the implied fp@2443: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@2443: * GNU Lesser General Public License for more details. fp@2443: * fp@2443: * You should have received a copy of the GNU Lesser General Public License fp@2443: * along with the IgH EtherCAT master userspace library. If not, see fp@2443: * . fp@2443: * fp@2443: * --- fp@2443: * fp@2443: * The license mentioned above concerns the source code only. Using the fp@2443: * EtherCAT technology and brand is only permitted in compliance with the fp@2443: * industrial property and similar rights of Beckhoff Automation GmbH. fp@2443: * fp@2443: *****************************************************************************/ fp@2443: fp@2443: /** \file fp@2443: * EtherCAT register request functions. fp@2443: */ fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: #include fp@2443: #include fp@2443: fp@2443: #include "ioctl.h" fp@2443: #include "reg_request.h" fp@2443: #include "slave_config.h" fp@2443: #include "master.h" fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: void ec_reg_request_clear(ec_reg_request_t *reg) fp@2443: { fp@2443: if (reg->data) { fp@2443: free(reg->data); fp@2443: } fp@2443: } fp@2443: fp@2443: /***************************************************************************** fp@2443: * Application interface. fp@2443: ****************************************************************************/ fp@2443: fp@2443: uint8_t *ecrt_reg_request_data(ec_reg_request_t *reg) fp@2443: { fp@2443: return reg->data; fp@2443: } fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: ec_request_state_t ecrt_reg_request_state(ec_reg_request_t *reg) fp@2443: { fp@2443: ec_ioctl_reg_request_t io; fp@2443: int ret; fp@2443: fp@2443: io.config_index = reg->config->index; fp@2443: io.request_index = reg->index; fp@2443: fp@2443: ret = ioctl(reg->config->master->fd, EC_IOCTL_REG_REQUEST_STATE, &io); fp@2443: if (EC_IOCTL_IS_ERROR(ret)) { fp@2443: fprintf(stderr, "Failed to get register request state: %s\n", fp@2443: strerror(EC_IOCTL_ERRNO(ret))); fp@2443: return EC_REQUEST_ERROR; fp@2443: } fp@2443: fp@2443: if (io.new_data) { // new data waiting to be copied fp@2443: fp@2443: io.data = reg->data; fp@2443: io.mem_size = reg->mem_size; fp@2443: fp@2443: ret = ioctl(reg->config->master->fd, fp@2443: EC_IOCTL_REG_REQUEST_DATA, &io); fp@2443: if (EC_IOCTL_IS_ERROR(ret)) { fp@2443: fprintf(stderr, "Failed to get register data: %s\n", fp@2443: strerror(EC_IOCTL_ERRNO(ret))); fp@2443: return EC_REQUEST_ERROR; fp@2443: } fp@2443: } fp@2443: fp@2443: return io.state; fp@2443: } fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: void ecrt_reg_request_write(ec_reg_request_t *reg, uint16_t address, fp@2443: size_t size) fp@2443: { fp@2443: ec_ioctl_reg_request_t io; fp@2443: int ret; fp@2443: fp@2443: io.config_index = reg->config->index; fp@2443: io.request_index = reg->index; fp@2443: io.data = reg->data; fp@2443: io.address = address; fp@2443: io.transfer_size = size; fp@2443: fp@2443: ret = ioctl(reg->config->master->fd, EC_IOCTL_REG_REQUEST_WRITE, &io); fp@2443: if (EC_IOCTL_IS_ERROR(ret)) { fp@2443: fprintf(stderr, "Failed to command an register write operation: %s\n", fp@2443: strerror(EC_IOCTL_ERRNO(ret))); fp@2443: } fp@2443: } fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: void ecrt_reg_request_read(ec_reg_request_t *reg, uint16_t address, fp@2443: size_t size) fp@2443: { fp@2443: ec_ioctl_reg_request_t io; fp@2443: int ret; fp@2443: fp@2443: io.config_index = reg->config->index; fp@2443: io.request_index = reg->index; fp@2443: io.address = address; fp@2443: io.transfer_size = size; fp@2443: fp@2443: ret = ioctl(reg->config->master->fd, EC_IOCTL_REG_REQUEST_READ, &io); fp@2443: if (EC_IOCTL_IS_ERROR(ret)) { fp@2443: fprintf(stderr, "Failed to command an register read operation: %s\n", fp@2443: strerror(EC_IOCTL_ERRNO(ret))); fp@2443: } fp@2443: } fp@2443: fp@2443: /*****************************************************************************/