fp@1244: /****************************************************************************** fp@1244: * fp@1244: * $Id$ fp@1244: * fp@1244: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@1244: * fp@1244: * This file is part of the IgH EtherCAT Master. fp@1244: * fp@1244: * The IgH EtherCAT Master is free software; you can redistribute it fp@1244: * and/or modify it under the terms of the GNU General Public License fp@1244: * as published by the Free Software Foundation; either version 2 of the fp@1244: * License, or (at your option) any later version. fp@1244: * fp@1244: * The IgH EtherCAT Master is distributed in the hope that it will be fp@1244: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1244: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@1244: * GNU General Public License for more details. fp@1244: * fp@1244: * You should have received a copy of the GNU General Public License fp@1244: * along with the IgH EtherCAT Master; if not, write to the Free Software fp@1244: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@1244: * fp@1244: * The right to use EtherCAT Technology is granted and comes free of fp@1244: * charge under condition of compatibility of product made by fp@1244: * Licensee. People intending to distribute/sell products based on the fp@1244: * code, have to sign an agreement to guarantee that products using fp@1244: * software based on IgH EtherCAT master stay compatible with the actual fp@1244: * EtherCAT specification (which are released themselves as an open fp@1244: * standard) as the (only) precondition to have the right to use EtherCAT fp@1244: * Technology, IP and trade marks. fp@1244: * fp@1244: *****************************************************************************/ fp@1244: fp@1244: #include fp@1244: #include fp@1244: #include fp@1244: #include fp@1244: #include fp@1244: fp@1244: #include "master.h" fp@1244: #include "domain.h" fp@1246: #include "slave_config.h" fp@1244: #include "master/ioctl.h" fp@1244: fp@1244: /*****************************************************************************/ fp@1244: fp@1244: ec_domain_t *ecrt_master_create_domain(ec_master_t *master) fp@1244: { fp@1244: ec_domain_t *domain; fp@1244: int index; fp@1244: fp@1244: domain = malloc(sizeof(ec_domain_t)); fp@1244: if (!domain) { fp@1244: fprintf(stderr, "Failed to allocate memory.\n"); fp@1244: return 0; fp@1244: } fp@1244: fp@1244: index = ioctl(master->fd, EC_IOCTL_CREATE_DOMAIN, NULL); fp@1244: if (index == -1) { fp@1244: fprintf(stderr, "Failed to create domain: %s\n", strerror(errno)); fp@1244: free(domain); fp@1244: return 0; fp@1244: } fp@1244: fp@1244: domain->index = (unsigned int) index; fp@1244: return domain; fp@1244: } fp@1244: fp@1244: /*****************************************************************************/ fp@1244: fp@1244: ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master, fp@1244: uint16_t alias, uint16_t position, uint32_t vendor_id, fp@1244: uint32_t product_code) fp@1244: { fp@1246: ec_ioctl_config_t data; fp@1246: ec_slave_config_t *sc; fp@1246: int index; fp@1246: fp@1246: sc = malloc(sizeof(ec_slave_config_t)); fp@1246: if (!sc) { fp@1246: fprintf(stderr, "Failed to allocate memory.\n"); fp@1246: return 0; fp@1246: } fp@1246: fp@1246: data.alias = alias; fp@1246: data.position = position; fp@1246: data.vendor_id = vendor_id; fp@1246: data.product_code = product_code; fp@1246: fp@1246: if (ioctl(master->fd, EC_IOCTL_CREATE_SLAVE_CONFIG, &data) == -1) { fp@1246: fprintf(stderr, "Failed to create slave config: %s\n", fp@1246: strerror(errno)); fp@1246: free(sc); fp@1246: return 0; fp@1246: } fp@1246: fp@1246: sc->index = data.config_index; fp@1246: return sc; fp@1244: } fp@1244: fp@1244: /*****************************************************************************/ fp@1244: fp@1244: int ecrt_master_activate(ec_master_t *master) fp@1244: { fp@1247: if (ioctl(master->fd, EC_IOCTL_ACTIVATE, NULL) == -1) { fp@1247: fprintf(stderr, "Failed to activate master: %s\n", fp@1247: strerror(errno)); fp@1247: return -1; fp@1247: } fp@1247: fp@1244: return 0; fp@1244: } fp@1244: fp@1244: /*****************************************************************************/ fp@1244: fp@1244: void ecrt_master_send(ec_master_t *master) fp@1244: { fp@1247: if (ioctl(master->fd, EC_IOCTL_SEND, NULL) == -1) { fp@1247: fprintf(stderr, "Failed to send: %s\n", strerror(errno)); fp@1247: } fp@1244: } fp@1244: fp@1244: /*****************************************************************************/ fp@1244: fp@1244: void ecrt_master_receive(ec_master_t *master) fp@1244: { fp@1247: if (ioctl(master->fd, EC_IOCTL_RECEIVE, NULL) == -1) { fp@1247: fprintf(stderr, "Failed to receive: %s\n", strerror(errno)); fp@1247: } fp@1244: } fp@1244: fp@1244: /*****************************************************************************/ fp@1244: fp@1244: void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state) fp@1244: { fp@1244: } fp@1244: fp@1244: /*****************************************************************************/