fp@1255: /******************************************************************************
fp@2421: *
fp@1326: * $Id$
fp@2421: *
fp@1326: * Copyright (C) 2006-2009 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@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@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@1313: return -1; // FIXME
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@1313: return -1; // FIXME
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@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@1258: if (ioctl(domain->master->fd, EC_IOCTL_DOMAIN_PROCESS,
fp@1258: domain->index) == -1) {
fp@1313: fprintf(stderr, "Failed to process domain: %s\n", 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@1313: fprintf(stderr, "Failed to queue domain: %s\n", 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@2421:
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: /*****************************************************************************/