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