fp@1352: /******************************************************************************
fp@1352: *
fp@1352: * $Id$
fp@1352: *
fp@2433: * Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH
fp@2421: *
fp@1363: * This file is part of the IgH EtherCAT master userspace library.
fp@2421: *
fp@1363: * The IgH EtherCAT master userspace library is free software; you can
fp@1363: * redistribute it and/or modify it under the terms of the GNU Lesser General
fp@1363: * Public License as published by the Free Software Foundation; version 2.1
fp@1363: * of the License.
fp@1352: *
fp@1363: * The IgH EtherCAT master userspace library is distributed in the hope that
fp@1363: * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fp@1363: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fp@1363: * GNU Lesser General Public License for more details.
fp@1352: *
fp@1363: * You should have received a copy of the GNU Lesser General Public License
fp@1363: * along with the IgH EtherCAT master userspace library. If not, see
fp@1363: * .
fp@2421: *
fp@1363: * ---
fp@2421: *
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@1352: *
fp@1352: *****************************************************************************/
fp@1352:
fp@1352: /** \file
fp@1352: * Canopen over EtherCAT SDO request functions.
fp@1352: */
fp@1352:
fp@1352: /*****************************************************************************/
fp@1352:
fp@1352: #include
fp@1352: #include
fp@1352:
fp@2433: #include "ioctl.h"
fp@1352: #include "sdo_request.h"
fp@1352: #include "slave_config.h"
fp@1352: #include "master.h"
fp@1352:
fp@1959: /*****************************************************************************/
fp@1959:
fp@1959: void ec_sdo_request_clear(ec_sdo_request_t *req)
fp@1959: {
fp@1959: if (req->data) {
fp@1959: free(req->data);
fp@1959: }
fp@1959: }
fp@1959:
fp@1352: /*****************************************************************************
fp@1959: * Application interface.
fp@1352: ****************************************************************************/
fp@1352:
fp@2434: void ecrt_sdo_request_index(ec_sdo_request_t *req, uint16_t index,
fp@2434: uint8_t subindex)
fp@2434: {
fp@2434: ec_ioctl_sdo_request_t data;
fp@2434: int ret;
fp@2434:
fp@2434: data.config_index = req->config->index;
fp@2434: data.request_index = req->index;
fp@2434: data.sdo_index = index;
fp@2434: data.sdo_subindex = subindex;
fp@2434:
fp@2434: ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_INDEX, &data);
fp@2434: if (EC_IOCTL_IS_ERROR(ret)) {
fp@2434: fprintf(stderr, "Failed to set SDO request index/subindex: %s\n",
fp@2434: strerror(EC_IOCTL_ERRNO(ret)));
fp@2434: }
fp@2434: }
fp@2434:
fp@2434: /*****************************************************************************/
fp@2434:
fp@1352: void ecrt_sdo_request_timeout(ec_sdo_request_t *req, uint32_t timeout)
fp@1352: {
fp@1352: ec_ioctl_sdo_request_t data;
fp@2433: int ret;
fp@1352:
fp@1352: data.config_index = req->config->index;
fp@1352: data.request_index = req->index;
fp@1352: data.timeout = timeout;
fp@1352:
fp@2433: ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_TIMEOUT, &data);
fp@2433: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1352: fprintf(stderr, "Failed to set SDO request timeout: %s\n",
fp@2433: strerror(EC_IOCTL_ERRNO(ret)));
fp@2433: }
fp@1352: }
fp@1352:
fp@1352: /*****************************************************************************/
fp@1352:
fp@1352: uint8_t *ecrt_sdo_request_data(ec_sdo_request_t *req)
fp@1352: {
fp@1352: return req->data;
fp@1352: }
fp@1352:
fp@1352: /*****************************************************************************/
fp@1352:
fp@1352: size_t ecrt_sdo_request_data_size(const ec_sdo_request_t *req)
fp@1352: {
fp@1352: return req->data_size;
fp@1352: }
fp@1352:
fp@1352: /*****************************************************************************/
fp@1352:
fp@1352: ec_request_state_t ecrt_sdo_request_state(ec_sdo_request_t *req)
fp@1352: {
fp@1352: ec_ioctl_sdo_request_t data;
fp@2433: int ret;
fp@1352:
fp@1352: data.config_index = req->config->index;
fp@1352: data.request_index = req->index;
fp@1352:
fp@2433: ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_STATE, &data);
fp@2433: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1352: fprintf(stderr, "Failed to get SDO request state: %s\n",
fp@2433: strerror(EC_IOCTL_ERRNO(ret)));
fp@2433: return EC_REQUEST_ERROR;
fp@2433: }
fp@1352:
fp@1352: if (data.size) { // new data waiting to be copied
fp@1352: if (req->mem_size < data.size) {
fp@2431: fprintf(stderr, "Received %u bytes do not fit info SDO data"
fp@2431: " memory (%u bytes)!\n", data.size, req->mem_size);
fp@2431: return EC_REQUEST_ERROR;
fp@1352: }
fp@1352:
fp@1352: data.data = req->data;
fp@1352:
fp@2433: ret = ioctl(req->config->master->fd,
fp@2433: EC_IOCTL_SDO_REQUEST_DATA, &data);
fp@2433: if (EC_IOCTL_IS_ERROR(ret)) {
fp@2433: fprintf(stderr, "Failed to get SDO data: %s\n",
fp@2433: strerror(EC_IOCTL_ERRNO(ret)));
fp@1352: return EC_REQUEST_ERROR;
fp@1352: }
fp@1352: req->data_size = data.size;
fp@1352: }
fp@1352:
fp@1352: return data.state;
fp@1352: }
fp@1352:
fp@1352: /*****************************************************************************/
fp@1352:
fp@1352: void ecrt_sdo_request_read(ec_sdo_request_t *req)
fp@1352: {
fp@1352: ec_ioctl_sdo_request_t data;
fp@2433: int ret;
fp@1352:
fp@1352: data.config_index = req->config->index;
fp@1352: data.request_index = req->index;
fp@1352:
fp@2433: ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_READ, &data);
fp@2433: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1352: fprintf(stderr, "Failed to command an SDO read operation : %s\n",
fp@2433: strerror(EC_IOCTL_ERRNO(ret)));
fp@2433: }
fp@1352: }
fp@1352:
fp@1352: /*****************************************************************************/
fp@1352:
fp@1352: void ecrt_sdo_request_write(ec_sdo_request_t *req)
fp@1352: {
fp@1352: ec_ioctl_sdo_request_t data;
fp@2433: int ret;
fp@1352:
fp@1352: data.config_index = req->config->index;
fp@1352: data.request_index = req->index;
fp@1352: data.data = req->data;
fp@1352: data.size = req->data_size;
fp@1352:
fp@2433: ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_WRITE, &data);
fp@2433: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1352: fprintf(stderr, "Failed to command an SDO write operation : %s\n",
fp@2433: strerror(EC_IOCTL_ERRNO(ret)));
fp@2433: }
fp@1352: }
fp@1352:
fp@1352: /*****************************************************************************/