fp@1352: /******************************************************************************
fp@1352: *
fp@1352: * $Id$
fp@1352: *
fp@1352: * Copyright (C) 2006-2009 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: #include
fp@1352:
fp@1352: #include "sdo_request.h"
fp@1352: #include "master/ioctl.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@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@1352:
fp@1352: data.config_index = req->config->index;
fp@1352: data.request_index = req->index;
fp@1352: data.timeout = timeout;
fp@1352:
fp@1352: if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_TIMEOUT,
fp@1352: &data) == -1)
fp@1352: fprintf(stderr, "Failed to set SDO request timeout: %s\n",
fp@1352: strerror(errno));
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@1352:
fp@1352: data.config_index = req->config->index;
fp@1352: data.request_index = req->index;
fp@1352:
fp@1352: if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_STATE,
fp@1352: &data) == -1)
fp@1352: fprintf(stderr, "Failed to get SDO request state: %s\n",
fp@1352: strerror(errno));
fp@1352:
fp@1352: if (data.size) { // new data waiting to be copied
fp@1352: if (req->mem_size < data.size) {
fp@1352: if (req->data)
fp@1352: free(req->data);
fp@1352: req->data = malloc(data.size);
fp@1352: if (!req->data) {
fp@1352: req->mem_size = 0;
fp@1352: fprintf(stderr, "Failed to allocate %u bytes of SDO data"
fp@1352: " memory!\n", data.size);
fp@1352: return EC_REQUEST_ERROR;
fp@1352: }
fp@1352: req->mem_size = data.size;
fp@1352: }
fp@1352:
fp@1352: data.data = req->data;
fp@1352:
fp@1352: if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_DATA,
fp@1352: &data) == -1) {
fp@1352: fprintf(stderr, "Failed to get SDO data: %s\n", strerror(errno));
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@1352:
fp@1352: data.config_index = req->config->index;
fp@1352: data.request_index = req->index;
fp@1352:
fp@1352: if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_READ,
fp@1352: &data) == -1)
fp@1352: fprintf(stderr, "Failed to command an SDO read operation : %s\n",
fp@1352: strerror(errno));
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@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@1352: if (ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_WRITE,
fp@1352: &data) == -1)
fp@1352: fprintf(stderr, "Failed to command an SDO write operation : %s\n",
fp@1352: strerror(errno));
fp@1352: }
fp@1352:
fp@1352: /*****************************************************************************/