# HG changeset patch # User Stefan Weiser # Date 1272617636 -7200 # Node ID 3967e3eb75b0b0fba8cab2fe74ca272b7cf77414 # Parent dc82f7d09767528fabfc17b307fb6d13f882a834 Insert port information into slave info. diff -r dc82f7d09767 -r 3967e3eb75b0 include/ecrt.h --- a/include/ecrt.h Mon Jan 09 17:42:28 2012 +0100 +++ b/include/ecrt.h Fri Apr 30 10:53:56 2010 +0200 @@ -5,7 +5,7 @@ * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH * * This file is part of the IgH EtherCAT master userspace library. - * + * * The IgH EtherCAT master userspace library is free software; you can * redistribute it and/or modify it under the terms of the GNU Lesser General * Public License as published by the Free Software Foundation; version 2.1 @@ -19,9 +19,9 @@ * You should have received a copy of the GNU Lesser General Public License * along with the IgH EtherCAT master userspace library. If not, see * . - * + * * --- - * + * * The license mentioned above concerns the source code only. Using the * EtherCAT technology and brand is only permitted in compliance with the * industrial property and similar rights of Beckhoff Automation GmbH. @@ -47,7 +47,7 @@ * ecrt_master_sync_slave_clocks() for offset and drift compensation. The * EC_TIMEVAL2NANO() macro can be used for epoch time conversion, while the * ecrt_master_sync_monitor_queue() and ecrt_master_sync_monitor_process() - * methods can be used to monitor the synchrony. + * methods can be used to monitor the synchrony. * - Improved the callback mechanism. ecrt_master_callbacks() now takes two * callback functions for sending and receiving datagrams. * ecrt_master_send_ext() is used to execute the sending of non-application @@ -137,6 +137,9 @@ */ #define EC_MAX_STRING_LENGTH 64 +/** Maximum number of slave ports. */ +#define EC_MAX_PORTS 4 + /** Timeval to nanoseconds conversion. * * This macro converts a Unix epoch time to EtherCAT DC time. @@ -149,7 +152,7 @@ (((TV).tv_sec - 946684800ULL) * 1000000000ULL + (TV).tv_usec * 1000ULL) /****************************************************************************** - * Data types + * Data types *****************************************************************************/ struct ec_master; @@ -194,7 +197,7 @@ /** Slave configuration state. * * This is used as an output parameter of ecrt_slave_config_state(). - * + * * \see ecrt_slave_config_state(). */ typedef struct { @@ -222,12 +225,33 @@ typedef struct { unsigned int slave_count; /**< Number of slaves in the bus. */ unsigned int link_up : 1; /**< \a true, if the network link is up. */ - uint8_t scan_busy; /**< \a true, while the master is scanning the bus */ + uint8_t scan_busy; /**< \a true, while the master is scanning the bus */ uint64_t app_time; /**< Application time. */ } ec_master_info_t; /*****************************************************************************/ +/** EtherCAT slave port descriptor. + */ +typedef enum { + EC_PORT_NOT_IMPLEMENTED, /**< Port is not implemented. */ + EC_PORT_NOT_CONFIGURED, /**< Port is not configured. */ + EC_PORT_EBUS, /**< Port is an e-bus. */ + EC_PORT_MII /**< Port is a mii. */ +} ec_slave_port_desc_t; + +/*****************************************************************************/ + +/** EtherCAT slave port information. + */ +typedef struct { + uint8_t link_up; /**< Link detected. */ + uint8_t loop_closed; /**< Loop closed. */ + uint8_t signal_detected; /**< Detected signal on RX port. */ +} ec_slave_port_link_t; + +/*****************************************************************************/ + /** Slave information. * * This is used as an output parameter of ecrt_master_get_slave(). @@ -242,6 +266,13 @@ uint32_t serial_number; /**< Serial-Number stored on the slave. */ uint16_t alias; /**< The slaves alias if not equal to 0. */ int16_t current_on_ebus; /**< Used current in mA. */ + struct { + ec_slave_port_desc_t desc; + ec_slave_port_link_t link; + uint32_t receive_time; + uint16_t next_slave; + uint32_t delay_to_next_dc; + } ports[EC_MAX_PORTS]; uint8_t al_state; /**< Current state of the slave. */ uint8_t error_flag; /**< Error flag for that slave. */ uint8_t sync_count; /**< Number of sync managers. */ @@ -313,9 +344,9 @@ /*****************************************************************************/ /** PDO configuration information. - * + * * This is the data type of the \a pdos field in ec_sync_info_t. - * + * * \see ecrt_slave_config_pdos(). */ typedef struct { @@ -364,7 +395,7 @@ uint8_t subindex; /**< PDO entry subindex. */ unsigned int *offset; /**< Pointer to a variable to store the PDO entry's (byte-)offset in the process data. */ - unsigned int *bit_position; /**< Pointer to a variable to store a bit + unsigned int *bit_position; /**< Pointer to a variable to store a bit position (0-7) within the \a offset. Can be NULL, in which case an error is raised if the PDO entry does not byte-align. */ @@ -410,7 +441,7 @@ unsigned int ecrt_version_magic(void); /** Requests an EtherCAT master for realtime operation. - * + * * Before an application can access an EtherCAT master, it has to reserve one * for exclusive use. * @@ -826,12 +857,12 @@ * The master has to know the application's time when operating slaves with * distributed clocks. The time is not incremented by the master itself, so * this method has to be called cyclically. - * + * * The time is used when setting the slaves' System Time Offset and * Cyclic Operation Start Time registers and when synchronizing the * DC reference clock to the application time via * ecrt_master_sync_reference_clock(). - * + * * The time is defined as nanoseconds from 2000-01-01 00:00. Converting an * epoch time can be done with the EC_TIMEVAL2NANO() macro. */ @@ -940,7 +971,7 @@ * This can be called before assigning PDOs via * ecrt_slave_config_pdo_assign_add(), to clear the default assignment of a * sync manager. - * + * * \see ecrt_slave_config_pdos() */ void ecrt_slave_config_pdo_assign_clear( @@ -994,28 +1025,28 @@ * {0x3101, 1, 8}, // status * {0x3101, 2, 16} // value * }; - * + * * ec_pdo_entry_info_t el3162_channel2[] = { * {0x3102, 1, 8}, // status * {0x3102, 2, 16} // value * }; - * + * * ec_pdo_info_t el3162_pdos[] = { * {0x1A00, 2, el3162_channel1}, * {0x1A01, 2, el3162_channel2} * }; - * + * * ec_sync_info_t el3162_syncs[] = { * {2, EC_DIR_OUTPUT}, * {3, EC_DIR_INPUT, 2, el3162_pdos}, * {0xff} * }; - * + * * if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_syncs)) { * // handle error * } * \endcode - * + * * The next example shows, how to configure the PDO assignment only. The * entries for each assigned PDO are taken from the PDO's default mapping. * Please note, that PDO entry registration will fail, if the PDO @@ -1026,11 +1057,11 @@ * {0x1600}, // Channel 1 * {0x1601} // Channel 2 * }; - * + * * ec_sync_info_t syncs[] = { * {3, EC_DIR_INPUT, 2, pdos}, * }; - * + * * if (ecrt_slave_config_pdos(slave_config_ana_in, 1, syncs)) { * // handle error * } @@ -1072,7 +1103,7 @@ uint16_t entry_index, /**< Index of the PDO entry to register. */ uint8_t entry_subindex, /**< Subindex of the PDO entry to register. */ ec_domain_t *domain, /**< Domain. */ - unsigned int *bit_position /**< Optional address if bit addressing + unsigned int *bit_position /**< Optional address if bit addressing is desired */ ); diff -r dc82f7d09767 -r 3967e3eb75b0 lib/master.c --- a/lib/master.c Mon Jan 09 17:42:28 2012 +0100 +++ b/lib/master.c Fri Apr 30 10:53:56 2010 +0200 @@ -1,11 +1,11 @@ /****************************************************************************** - * + * * $Id$ - * + * * Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH - * + * * This file is part of the IgH EtherCAT master userspace library. - * + * * The IgH EtherCAT master userspace library is free software; you can * redistribute it and/or modify it under the terms of the GNU Lesser General * Public License as published by the Free Software Foundation; version 2.1 @@ -19,9 +19,9 @@ * You should have received a copy of the GNU Lesser General Public License * along with the IgH EtherCAT master userspace library. If not, see * . - * + * * --- - * + * * The license mentioned above concerns the source code only. Using the * EtherCAT technology and brand is only permitted in compliance with the * industrial property and similar rights of Beckhoff Automation GmbH. @@ -118,12 +118,12 @@ fprintf(stderr, "Failed to allocate memory.\n"); return 0; } - + index = ioctl(master->fd, EC_IOCTL_CREATE_DOMAIN, NULL); if (index == -1) { fprintf(stderr, "Failed to create domain: %s\n", strerror(errno)); free(domain); - return 0; + return 0; } domain->next = NULL; @@ -166,17 +166,17 @@ fprintf(stderr, "Failed to allocate memory.\n"); return 0; } - + data.alias = alias; data.position = position; data.vendor_id = vendor_id; data.product_code = product_code; - + if (ioctl(master->fd, EC_IOCTL_CREATE_SLAVE_CONFIG, &data) == -1) { fprintf(stderr, "Failed to create slave config: %s\n", strerror(errno)); free(sc); - return 0; + return 0; } sc->next = NULL; @@ -232,6 +232,7 @@ slave_info->serial_number = data.serial_number; slave_info->alias = data.alias; slave_info->current_on_ebus = data.current_on_ebus; + strncpy((char*) slave_info->ports, (char*) data.ports, sizeof(slave_info->ports)); slave_info->al_state = data.al_state; slave_info->error_flag = data.error_flag; slave_info->sync_count = data.sync_count; diff -r dc82f7d09767 -r 3967e3eb75b0 master/globals.h --- a/master/globals.h Mon Jan 09 17:42:28 2012 +0100 +++ b/master/globals.h Fri Apr 30 10:53:56 2010 +0200 @@ -97,9 +97,6 @@ /** Word offset of first SII category. */ #define EC_FIRST_SII_CATEGORY_OFFSET 0x40 -/** Maximum number of slave ports. */ -#define EC_MAX_PORTS 4 - /** Size of a sync manager configuration page. */ #define EC_SYNC_PAGE_SIZE 8 @@ -173,23 +170,6 @@ uint8_t enable_not_lrw : 1; /**< Slave does not support LRW. */ } ec_sii_general_flags_t; -/** EtherCAT slave port descriptor. - */ -typedef enum { - EC_PORT_NOT_IMPLEMENTED, - EC_PORT_NOT_CONFIGURED, - EC_PORT_EBUS, - EC_PORT_MII -} ec_slave_port_desc_t; - -/** EtherCAT slave port information. - */ -typedef struct { - uint8_t link_up; /**< Link detected. */ - uint8_t loop_closed; /**< Loop closed. */ - uint8_t signal_detected; /**< Detected signal on RX port. */ -} ec_slave_port_link_t; - /** EtherCAT slave distributed clocks range. */ typedef enum {