fp@39: /****************************************************************************** fp@0: * fp@39: * $Id$ fp@0: * fp@2443: * Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH fp@197: * fp@197: * This file is part of the IgH EtherCAT Master. fp@197: * fp@1326: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1326: * modify it under the terms of the GNU General Public License version 2, as fp@1326: * published by the Free Software Foundation. fp@197: * fp@1326: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1326: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1326: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1326: * Public License for more details. fp@197: * fp@1326: * You should have received a copy of the GNU General Public License along fp@1326: * with the IgH EtherCAT Master; if not, write to the Free Software fp@197: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@197: * fp@1363: * --- fp@1363: * 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@246: * fp@39: *****************************************************************************/ fp@0: fp@199: /** fp@199: \file fp@791: EtherCAT slave structure. fp@199: */ fp@199: fp@199: /*****************************************************************************/ fp@199: fp@883: #ifndef __EC_SLAVE_H__ fp@883: #define __EC_SLAVE_H__ fp@0: fp@145: #include fp@182: #include fp@145: fp@145: #include "globals.h" fp@293: #include "datagram.h" fp@627: #include "pdo.h" fp@628: #include "sync.h" fp@847: #include "sdo.h" martin@1583: #include "fsm_slave.h" fp@0: fp@39: /*****************************************************************************/ fp@0: fp@1921: /** Convenience macro for printing slave-specific information to syslog. fp@1921: * fp@1921: * This will print the message in \a fmt with a prefixed fp@1921: * "EtherCAT -: ", where INDEX is the master index and fp@1921: * POSITION is the slave's ring position. fp@1921: * fp@1921: * \param slave EtherCAT slave fp@1921: * \param fmt format string (like in printf()) fp@1921: * \param args arguments (optional) fp@1921: */ fp@1921: #define EC_SLAVE_INFO(slave, fmt, args...) \ fp@1921: printk(KERN_INFO "EtherCAT %u-%u: " fmt, slave->master->index, \ fp@1921: slave->ring_position, ##args) fp@1921: fp@1921: /** Convenience macro for printing slave-specific errors to syslog. fp@1921: * fp@1921: * This will print the message in \a fmt with a prefixed fp@1921: * "EtherCAT -: ", where INDEX is the master index and fp@1921: * POSITION is the slave's ring position. fp@1921: * fp@1921: * \param slave EtherCAT slave fp@1921: * \param fmt format string (like in printf()) fp@1921: * \param args arguments (optional) fp@1921: */ fp@1921: #define EC_SLAVE_ERR(slave, fmt, args...) \ fp@1921: printk(KERN_ERR "EtherCAT ERROR %u-%u: " fmt, slave->master->index, \ fp@1921: slave->ring_position, ##args) fp@1921: fp@1921: /** Convenience macro for printing slave-specific warnings to syslog. fp@1921: * fp@1921: * This will print the message in \a fmt with a prefixed fp@1921: * "EtherCAT -: ", where INDEX is the master index and fp@1921: * POSITION is the slave's ring position. fp@1921: * fp@1921: * \param slave EtherCAT slave fp@1921: * \param fmt format string (like in printf()) fp@1921: * \param args arguments (optional) fp@1921: */ fp@1921: #define EC_SLAVE_WARN(slave, fmt, args...) \ fp@1921: printk(KERN_WARNING "EtherCAT WARNING %u-%u: " fmt, \ fp@1921: slave->master->index, slave->ring_position, ##args) fp@1921: fp@1921: /** Convenience macro for printing slave-specific debug messages to syslog. fp@1921: * fp@1921: * This will print the message in \a fmt with a prefixed fp@1921: * "EtherCAT -: ", where INDEX is the master index and fp@1921: * POSITION is the slave's ring position. fp@1921: * fp@1921: * \param slave EtherCAT slave fp@2522: * \param level Debug level. Master's debug level must be >= \a level for fp@2522: * output. fp@1921: * \param fmt format string (like in printf()) fp@1921: * \param args arguments (optional) fp@1921: */ fp@1921: #define EC_SLAVE_DBG(slave, level, fmt, args...) \ fp@1921: do { \ fp@1921: if (slave->master->debug_level >= level) { \ fp@1921: printk(KERN_DEBUG "EtherCAT DEBUG %u-%u: " fmt, \ fp@1921: slave->master->index, slave->ring_position, ##args); \ fp@1921: } \ fp@1921: } while (0) fp@1921: fp@1921: /*****************************************************************************/ fp@1921: fp@1425: /** Slave port. fp@1425: */ fp@1425: typedef struct { fp@1425: ec_slave_port_desc_t desc; /**< Port descriptors. */ fp@1425: ec_slave_port_link_t link; /**< Port link status. */ fp@1425: ec_slave_t *next_slave; /**< Connected slaves. */ fp@1425: uint32_t receive_time; /**< Port receive times for delay fp@1425: measurement. */ fp@1425: uint32_t delay_to_next_dc; /**< Delay to next slave with DC support behind fp@1425: this port [ns]. */ fp@1425: } ec_slave_port_t; fp@1425: fp@1425: /*****************************************************************************/ fp@1425: fp@834: /** Slave information interface data. fp@834: */ fp@834: typedef struct { fp@2421: // Non-category data fp@834: uint16_t alias; /**< Configured station alias. */ fp@834: uint32_t vendor_id; /**< Vendor ID. */ fp@834: uint32_t product_code; /**< Vendor-specific product code. */ fp@834: uint32_t revision_number; /**< Revision number. */ fp@834: uint32_t serial_number; /**< Serial number. */ fp@1337: uint16_t boot_rx_mailbox_offset; /**< Bootstrap receive mailbox address. */ fp@1337: uint16_t boot_rx_mailbox_size; /**< Bootstrap receive mailbox size. */ fp@1337: uint16_t boot_tx_mailbox_offset; /**< Bootstrap transmit mailbox address. */ fp@1337: uint16_t boot_tx_mailbox_size; /**< Bootstrap transmit mailbox size. */ fp@1337: uint16_t std_rx_mailbox_offset; /**< Standard receive mailbox address. */ fp@1337: uint16_t std_rx_mailbox_size; /**< Standard receive mailbox size. */ fp@1337: uint16_t std_tx_mailbox_offset; /**< Standard transmit mailbox address. */ fp@1337: uint16_t std_tx_mailbox_size; /**< Standard transmit mailbox size. */ fp@834: uint16_t mailbox_protocols; /**< Supported mailbox protocols. */ fp@834: fp@834: // Strings fp@872: char **strings; /**< Strings in SII categories. */ fp@1000: unsigned int string_count; /**< Number of SII strings. */ fp@834: fp@834: // General fp@835: unsigned int has_general; /**< General category present. */ fp@1000: char *group; /**< Group name. */ fp@1000: char *image; /**< Image name. */ fp@1000: char *order; /**< Order number. */ fp@1000: char *name; /**< Slave name. */ fp@1055: uint8_t physical_layer[EC_MAX_PORTS]; /**< Port media. */ fp@835: ec_sii_coe_details_t coe_details; /**< CoE detail flags. */ fp@836: ec_sii_general_flags_t general_flags; /**< General flags. */ fp@1000: int16_t current_on_ebus; /**< Power consumption in mA. */ fp@834: fp@834: // SyncM fp@1000: ec_sync_t *syncs; /**< SYNC MANAGER categories. */ fp@1000: unsigned int sync_count; /**< Number of sync managers. */ fp@834: fp@834: // [RT]XPDO fp@1000: struct list_head pdos; /**< SII [RT]XPDO categories. */ fp@834: } ec_sii_t; fp@834: fp@834: /*****************************************************************************/ fp@834: fp@792: /** EtherCAT slave. fp@635: */ fp@73: struct ec_slave fp@73: { fp@1000: ec_master_t *master; /**< Master owning the slave. */ fp@2374: ec_device_index_t device_index; /**< Index of device the slave responds fp@2374: on. */ fp@195: fp@195: // addresses fp@1000: uint16_t ring_position; /**< Ring position. */ fp@1000: uint16_t station_address; /**< Configured station address. */ fp@1909: uint16_t effective_alias; /**< Effective alias address. */ fp@195: fp@1425: ec_slave_port_t ports[EC_MAX_PORTS]; /**< Ports. */ fp@1425: fp@792: // configuration fp@792: ec_slave_config_t *config; /**< Current configuration. */ fp@792: ec_slave_state_t requested_state; /**< Requested application state. */ fp@792: ec_slave_state_t current_state; /**< Current application state. */ fp@792: unsigned int error_flag; /**< Stop processing after an error. */ fp@908: unsigned int force_config; /**< Force (re-)configuration. */ fp@1465: uint16_t configured_rx_mailbox_offset; /**< Configured receive mailbox fp@1465: offset. */ fp@1465: uint16_t configured_rx_mailbox_size; /**< Configured receive mailbox size. fp@1465: */ fp@1465: uint16_t configured_tx_mailbox_offset; /**< Configured send mailbox fp@1465: offset. */ fp@1465: uint16_t configured_tx_mailbox_size; /**< Configured send mailbox size. */ fp@792: fp@195: // base data fp@1000: uint8_t base_type; /**< Slave type. */ fp@1000: uint8_t base_revision; /**< Revision. */ fp@1000: uint16_t base_build; /**< Build number. */ fp@1379: uint8_t base_fmmu_count; /**< Number of supported FMMUs. */ fp@1379: uint8_t base_sync_count; /**< Number of supported sync managers. */ fp@1379: uint8_t base_fmmu_bit_operation; /**< FMMU bit operation is supported. */ fp@1379: uint8_t base_dc_supported; /**< Distributed clocks are supported. */ fp@1379: ec_slave_dc_range_t base_dc_range; /**< DC range. */ fp@1419: uint8_t has_dc_system_time; /**< The slave supports the DC system time fp@1419: register. Otherwise it can only be used for fp@1419: delay measurement. */ fp@1426: uint32_t transmission_delay; /**< DC system time transmission delay fp@1426: (offset from reference clock). */ fp@195: fp@872: // SII fp@977: uint16_t *sii_words; /**< Complete SII image. */ fp@977: size_t sii_nwords; /**< Size of the SII contents in words. */ fp@325: fp@1000: // Slave information interface fp@1000: ec_sii_t sii; /**< Extracted SII data. */ fp@195: fp@1327: struct list_head sdo_dictionary; /**< SDO dictionary list */ fp@1000: uint8_t sdo_dictionary_fetched; /**< Dictionary has been fetched. */ fp@1000: unsigned long jiffies_preop; /**< Time, the slave went to PREOP. */ martin@1583: fp@2460: struct list_head sdo_requests; /**< SDO access requests. */ fp@2443: struct list_head reg_requests; /**< Register access requests. */ martin@1597: struct list_head foe_requests; /**< FoE write requests. */ fp@2467: struct list_head soe_requests; /**< SoE write requests. */ fp@2467: martin@1583: ec_fsm_slave_t fsm; /**< Slave state machine. */ fp@73: }; fp@73: fp@73: /*****************************************************************************/ fp@73: fp@195: // slave construction/destruction fp@2374: void ec_slave_init(ec_slave_t *, ec_master_t *, ec_device_index_t, fp@2374: uint16_t, uint16_t); fp@992: void ec_slave_clear(ec_slave_t *); fp@73: fp@870: void ec_slave_clear_sync_managers(ec_slave_t *); fp@870: fp@446: void ec_slave_request_state(ec_slave_t *, ec_slave_state_t); fp@610: void ec_slave_set_state(ec_slave_t *, ec_slave_state_t); fp@446: fp@325: // SII categories fp@742: int ec_slave_fetch_sii_strings(ec_slave_t *, const uint8_t *, size_t); fp@742: int ec_slave_fetch_sii_general(ec_slave_t *, const uint8_t *, size_t); fp@620: int ec_slave_fetch_sii_syncs(ec_slave_t *, const uint8_t *, size_t); fp@620: int ec_slave_fetch_sii_pdos(ec_slave_t *, const uint8_t *, size_t, fp@792: ec_direction_t); fp@238: fp@195: // misc. fp@2421: ec_sync_t *ec_slave_get_sync(ec_slave_t *, uint8_t); fp@1055: fp@423: void ec_slave_sdo_dict_info(const ec_slave_t *, fp@635: unsigned int *, unsigned int *); fp@740: ec_sdo_t *ec_slave_get_sdo(ec_slave_t *, uint16_t); fp@967: const ec_sdo_t *ec_slave_get_sdo_const(const ec_slave_t *, uint16_t); fp@964: const ec_sdo_t *ec_slave_get_sdo_by_pos_const(const ec_slave_t *, uint16_t); fp@964: uint16_t ec_slave_sdo_count(const ec_slave_t *); fp@799: const ec_pdo_t *ec_slave_find_pdo(const ec_slave_t *, uint16_t); fp@1186: void ec_slave_attach_pdo_names(ec_slave_t *); fp@423: fp@1425: void ec_slave_calc_port_delays(ec_slave_t *); fp@1426: void ec_slave_calc_transmission_delays_rec(ec_slave_t *, uint32_t *); fp@1425: fp@39: /*****************************************************************************/ fp@0: fp@0: #endif