fp@1255: /******************************************************************************
fp@2421: *
fp@1326: * $Id$
fp@2421: *
fp@2433: * Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH
fp@2421: *
fp@1326: * This file is part of the IgH EtherCAT master userspace library.
fp@2421: *
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@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@1255: *
fp@1255: *****************************************************************************/
fp@1255:
fp@1255: /**
fp@1255: \file
fp@1255: EtherCAT domain methods.
fp@1255: */
fp@1255:
fp@1255: /*****************************************************************************/
fp@1255:
fp@1258: #include
fp@1258: #include
fp@2433: #include /* ENOENT */
fp@1258:
fp@2433: #include "ioctl.h"
fp@1255: #include "domain.h"
fp@1258: #include "master.h"
fp@1255:
fp@1255: /*****************************************************************************/
fp@1255:
fp@1959: void ec_domain_clear(ec_domain_t *domain)
fp@1959: {
fp@1959: // nothing to do
fp@1959: }
fp@1959:
fp@1959: /*****************************************************************************/
fp@1959:
fp@1255: int ecrt_domain_reg_pdo_entry_list(ec_domain_t *domain,
fp@1255: const ec_pdo_entry_reg_t *regs)
fp@1255: {
fp@1255: const ec_pdo_entry_reg_t *reg;
fp@1255: ec_slave_config_t *sc;
fp@1255: int ret;
fp@2421:
fp@1255: for (reg = regs; reg->index; reg++) {
fp@1255: if (!(sc = ecrt_master_slave_config(domain->master, reg->alias,
fp@1255: reg->position, reg->vendor_id, reg->product_code)))
fp@2433: return -ENOENT;
fp@1255:
fp@1255: if ((ret = ecrt_slave_config_reg_pdo_entry(sc, reg->index,
fp@1255: reg->subindex, domain, reg->bit_position)) < 0)
fp@2433: return ret;
fp@1255:
fp@1255: *reg->offset = ret;
fp@1255: }
fp@1255:
fp@1255: return 0;
fp@1255: }
fp@1255:
fp@1255: /*****************************************************************************/
fp@1255:
fp@2504: size_t ecrt_domain_size(const ec_domain_t *domain)
fp@2504: {
fp@2504: int ret;
fp@2504:
fp@2504: ret = ioctl(domain->master->fd, EC_IOCTL_DOMAIN_SIZE, domain->index);
fp@2504: if (EC_IOCTL_IS_ERROR(ret)) {
fp@2504: fprintf(stderr, "Failed to get domain size: %s\n",
fp@2504: strerror(EC_IOCTL_ERRNO(ret)));
fp@2504: }
fp@2504:
fp@2504: return ret;
fp@2504: }
fp@2504:
fp@2504: /*****************************************************************************/
fp@2504:
fp@1255: uint8_t *ecrt_domain_data(ec_domain_t *domain)
fp@1255: {
fp@1258: if (!domain->process_data) {
fp@1258: int offset = 0;
fp@1258:
fp@1258: offset = ioctl(domain->master->fd, EC_IOCTL_DOMAIN_OFFSET,
fp@1258: domain->index);
fp@2433: if (EC_IOCTL_IS_ERROR(offset)) {
fp@1258: fprintf(stderr, "Failed to get domain offset: %s\n",
fp@2433: strerror(EC_IOCTL_ERRNO(offset)));
fp@2421: return NULL;
fp@1258: }
fp@2421:
fp@1258: domain->process_data = domain->master->process_data + offset;
fp@1258: }
fp@1258:
fp@1258: return domain->process_data;
fp@1255: }
fp@1255:
fp@1255: /*****************************************************************************/
fp@1255:
fp@1255: void ecrt_domain_process(ec_domain_t *domain)
fp@1255: {
fp@2433: int ret;
fp@2433:
fp@2433: ret = ioctl(domain->master->fd, EC_IOCTL_DOMAIN_PROCESS, domain->index);
fp@2433: if (EC_IOCTL_IS_ERROR(ret)) {
fp@2433: fprintf(stderr, "Failed to process domain: %s\n",
fp@2433: strerror(EC_IOCTL_ERRNO(ret)));
fp@1258: }
fp@1255: }
fp@1255:
fp@1255: /*****************************************************************************/
fp@1255:
fp@1255: void ecrt_domain_queue(ec_domain_t *domain)
fp@1255: {
fp@2433: int ret;
fp@2433:
fp@2433: ret = ioctl(domain->master->fd, EC_IOCTL_DOMAIN_QUEUE, domain->index);
fp@2433: if (EC_IOCTL_IS_ERROR(ret)) {
fp@2433: fprintf(stderr, "Failed to queue domain: %s\n",
fp@2433: strerror(EC_IOCTL_ERRNO(ret)));
fp@1258: }
fp@1255: }
fp@1255:
fp@1255: /*****************************************************************************/
fp@1255:
fp@1255: void ecrt_domain_state(const ec_domain_t *domain, ec_domain_state_t *state)
fp@1255: {
fp@1259: ec_ioctl_domain_state_t data;
fp@2433: int ret;
fp@1259:
fp@1259: data.domain_index = domain->index;
fp@1259: data.state = state;
fp@2421:
fp@2433: ret = ioctl(domain->master->fd, EC_IOCTL_DOMAIN_STATE, &data);
fp@2433: if (EC_IOCTL_IS_ERROR(ret)) {
fp@1259: fprintf(stderr, "Failed to get domain state: %s\n",
fp@2433: strerror(EC_IOCTL_ERRNO(ret)));
fp@1259: }
fp@1255: }
fp@1255:
fp@1255: /*****************************************************************************/