fp@1255: /******************************************************************************
fp@1266: *
fp@1266: * $Id$
fp@1266: *
fp@1266: * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
fp@1266: *
fp@1266: * This file is part of the IgH EtherCAT master userspace library.
fp@1266: *
fp@1287: * The IgH EtherCAT master userspace library is free software; you can
fp@1266: * redistribute it and/or modify it under the terms of the GNU Lesser General
fp@1287: * Public License as published by the Free Software Foundation; version 2.1 of
fp@1266: * the License.
fp@1287: *
fp@1266: * The IgH EtherCAT master userspace library is distributed in the hope that
fp@1266: * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fp@1266: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fp@1266: * GNU Lesser General Public License for more details.
fp@1287: *
fp@1266: * You should have received a copy of the GNU Lesser General Public License
fp@1266: * along with the IgH EtherCAT master userspace library. If not, see
fp@1266: * .
fp@1266: *
fp@1266: * The right to use EtherCAT Technology is granted and comes free of charge
fp@1266: * under condition of compatibility of product made by Licensee. People
fp@1266: * intending to distribute/sell products based on the code, have to sign an
fp@1266: * agreement to guarantee that products using software based on IgH EtherCAT
fp@1266: * master stay compatible with the actual EtherCAT specification (which are
fp@1266: * released themselves as an open standard) as the (only) precondition to have
fp@1266: * the right to use EtherCAT Technology, IP and trade marks.
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@1258: #include
fp@1258: #include
fp@1258: #include
fp@1258:
fp@1255: #include "domain.h"
fp@1258: #include "master.h"
fp@1258: #include "master/ioctl.h"
fp@1255:
fp@1255: /*****************************************************************************/
fp@1255:
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@1255:
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@1255: return -1;
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@1255: return -1;
fp@1255:
fp@1255: *reg->offset = ret;
fp@1255: }
fp@1255:
fp@1255: return 0;
fp@1255: }
fp@1255:
fp@1255: /*****************************************************************************/
fp@1255:
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@1258: if (offset == -1) {
fp@1258: fprintf(stderr, "Failed to get domain offset: %s\n",
fp@1258: strerror(errno));
fp@1258: return NULL;
fp@1258: }
fp@1258:
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@1258: if (ioctl(domain->master->fd, EC_IOCTL_DOMAIN_PROCESS,
fp@1258: domain->index) == -1) {
fp@1258: fprintf(stderr, "Failed to process domain offset: %s\n",
fp@1258: strerror(errno));
fp@1258: }
fp@1255: }
fp@1255:
fp@1255: /*****************************************************************************/
fp@1255:
fp@1255: void ecrt_domain_queue(ec_domain_t *domain)
fp@1255: {
fp@1258: if (ioctl(domain->master->fd, EC_IOCTL_DOMAIN_QUEUE,
fp@1258: domain->index) == -1) {
fp@1258: fprintf(stderr, "Failed to queue domain offset: %s\n",
fp@1258: strerror(errno));
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@1259:
fp@1259: data.domain_index = domain->index;
fp@1259: data.state = state;
fp@1259:
fp@1259: if (ioctl(domain->master->fd, EC_IOCTL_DOMAIN_STATE, &data) == -1) {
fp@1259: fprintf(stderr, "Failed to get domain state: %s\n",
fp@1259: strerror(errno));
fp@1259: }
fp@1255: }
fp@1255:
fp@1255: /*****************************************************************************/