fp@39: /****************************************************************************** fp@0: * fp@39: * $Id$ fp@0: * fp@197: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@197: * fp@197: * This file is part of the IgH EtherCAT Master. fp@197: * fp@197: * The IgH EtherCAT Master is free software; you can redistribute it fp@197: * and/or modify it under the terms of the GNU General Public License fp@246: * as published by the Free Software Foundation; either version 2 of the fp@246: * License, or (at your option) any later version. fp@197: * fp@197: * The IgH EtherCAT Master is distributed in the hope that it will be fp@197: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@197: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@197: * GNU General Public License for more details. fp@197: * fp@197: * You should have received a copy of the GNU General Public License fp@197: * along 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@246: * The right to use EtherCAT Technology is granted and comes free of fp@246: * charge under condition of compatibility of product made by fp@246: * Licensee. People intending to distribute/sell products based on the fp@246: * code, have to sign an agreement to guarantee that products using fp@246: * software based on IgH EtherCAT master stay compatible with the actual fp@246: * EtherCAT specification (which are released themselves as an open fp@246: * standard) as the (only) precondition to have the right to use EtherCAT fp@246: * Technology, IP and trade marks. 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@325: #include "../include/ecrt.h" fp@325: 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" fp@0: fp@39: /*****************************************************************************/ fp@0: fp@831: /** Slave state mask. fp@831: * fp@831: * Apply this mask to a slave state byte to get the slave state without fp@831: * the error flag. fp@831: */ fp@831: #define EC_SLAVE_STATE_MASK 0x0F fp@831: fp@831: /*****************************************************************************/ fp@831: fp@792: /** State of an EtherCAT slave. fp@635: */ fp@792: typedef enum { fp@126: EC_SLAVE_STATE_UNKNOWN = 0x00, fp@195: /**< unknown state */ fp@126: EC_SLAVE_STATE_INIT = 0x01, fp@195: /**< INIT state (no mailbox communication, no IO) */ fp@126: EC_SLAVE_STATE_PREOP = 0x02, fp@195: /**< PREOP state (mailbox communication, no IO) */ fp@813: EC_SLAVE_STATE_SAFEOP = 0x04, fp@813: /**< SAFEOP (mailbox communication and input update) */ fp@126: EC_SLAVE_STATE_OP = 0x08, fp@195: /**< OP (mailbox communication and input/output update) */ fp@402: EC_SLAVE_STATE_ACK_ERR = 0x10 fp@406: /**< Acknowledge/Error bit (no actual state) */ fp@792: } ec_slave_state_t; fp@98: fp@626: /*****************************************************************************/ fp@626: fp@792: /** EtherCAT slave online state. fp@626: */ fp@610: typedef enum { fp@610: EC_SLAVE_OFFLINE, fp@610: EC_SLAVE_ONLINE fp@792: } ec_slave_online_state_t; fp@610: fp@98: /*****************************************************************************/ fp@98: fp@792: /** Supported mailbox protocols. fp@635: */ fp@792: enum { fp@145: EC_MBOX_AOE = 0x01, /**< ADS-over-EtherCAT */ fp@145: EC_MBOX_EOE = 0x02, /**< Ethernet-over-EtherCAT */ fp@145: EC_MBOX_COE = 0x04, /**< CANopen-over-EtherCAT */ fp@145: EC_MBOX_FOE = 0x08, /**< File-Access-over-EtherCAT */ fp@145: EC_MBOX_SOE = 0x10, /**< Servo-Profile-over-EtherCAT */ fp@133: EC_MBOX_VOE = 0x20 /**< Vendor specific */ fp@133: }; fp@133: fp@133: /*****************************************************************************/ fp@133: fp@836: /** Slave information interface CANopen-over-EtherCAT details flags. fp@835: */ fp@835: typedef struct { fp@835: uint8_t enable_sdo : 1; /**< Enable Sdo access. */ fp@835: uint8_t enable_sdo_info : 1; /**< SDO information service available. */ fp@835: uint8_t enable_pdo_assign : 1; /**< Pdo mapping configurable. */ fp@835: uint8_t enable_pdo_configuration : 1; /**< Pdo configuration possible. */ fp@836: uint8_t enable_upload_at_startup : 1; /**< ?. */ fp@835: uint8_t enable_sdo_complete_access : 1; /**< Complete access possible. */ fp@835: } ec_sii_coe_details_t; fp@835: fp@835: /*****************************************************************************/ fp@835: fp@836: /** Slave information interface general flags. fp@836: */ fp@836: typedef struct { fp@836: uint8_t enable_safeop : 1; /**< ?. */ fp@836: uint8_t enable_not_lrw : 1; /**< Slave does not support LRW. */ fp@836: } ec_sii_general_flags_t; fp@836: fp@836: /*****************************************************************************/ fp@836: fp@834: /** Slave information interface data. fp@834: */ fp@834: typedef struct { fp@834: // 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@834: uint16_t rx_mailbox_offset; /**< Mailbox address (master to slave). */ fp@834: uint16_t rx_mailbox_size; /**< Mailbox size (master to slave). */ fp@834: uint16_t tx_mailbox_offset; /**< Mailbox address (slave to master). */ fp@834: uint16_t tx_mailbox_size; /**< Mailbox size (slave to master). */ fp@834: uint16_t mailbox_protocols; /**< Supported mailbox protocols. */ fp@834: fp@834: // Strings fp@872: char **strings; /**< Strings in SII categories. */ fp@872: unsigned int string_count; /**< number of SII strings */ fp@834: fp@834: // General fp@835: unsigned int has_general; /**< General category present. */ fp@872: char *group; /**< slave group acc. to SII */ fp@872: char *image; /**< slave image name acc. to SII */ fp@872: char *order; /**< slave order number acc. to SII */ fp@872: char *name; /**< slave name acc. to SII */ fp@835: uint8_t physical_layer[4]; /**< 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@834: int16_t current_on_ebus; /**< power consumption */ fp@834: fp@834: // SyncM fp@872: ec_sync_t *syncs; /**< SII SYNC MANAGER categories */ fp@872: unsigned int sync_count; /**< number of sync managers in SII */ fp@834: fp@834: // [RT]XPDO fp@872: 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@195: struct list_head list; /**< list item */ fp@195: struct kobject kobj; /**< kobject */ fp@195: ec_master_t *master; /**< master owning the slave */ fp@195: fp@195: // addresses fp@195: uint16_t ring_position; /**< ring position */ fp@195: uint16_t station_address; /**< configured station address */ fp@195: 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: ec_slave_online_state_t online_state; /**< online state */ fp@792: unsigned int self_configured; /**< Slave was configured by this master. */ fp@792: unsigned int error_flag; /**< Stop processing after an error. */ fp@792: fp@195: // base data fp@195: uint8_t base_type; /**< slave type */ fp@195: uint8_t base_revision; /**< revision */ fp@195: uint16_t base_build; /**< build number */ fp@195: uint16_t base_fmmu_count; /**< number of supported FMMUs */ fp@195: fp@195: // data link status fp@195: uint8_t dl_link[4]; /**< link detected */ fp@195: uint8_t dl_loop[4]; /**< loop closed */ fp@195: uint8_t dl_signal[4]; /**< detected signal on RX port */ fp@195: fp@872: // SII fp@872: uint8_t *sii_data; /**< Complete SII image */ fp@872: size_t sii_size; /**< size of the SII contents in bytes */ fp@325: fp@195: // slave information interface fp@834: ec_sii_t sii; /**< SII data. */ fp@195: fp@814: struct kobject sdo_kobj; /**< kobject for Sdos */ fp@814: struct list_head sdo_dictionary; /**< Sdo dictionary list */ fp@419: uint8_t sdo_dictionary_fetched; /**< dictionary has been fetched */ fp@742: unsigned long jiffies_preop; /**< time, the slave went to PREOP */ fp@73: }; fp@73: fp@73: /*****************************************************************************/ fp@73: fp@195: // slave construction/destruction fp@182: int ec_slave_init(ec_slave_t *, ec_master_t *, uint16_t, uint16_t); fp@448: void ec_slave_destroy(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@610: void ec_slave_set_online_state(ec_slave_t *, ec_slave_online_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@626: ec_sync_t *ec_slave_get_pdo_sync(ec_slave_t *, ec_direction_t); fp@410: int ec_slave_validate(const ec_slave_t *, uint32_t, uint32_t); 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@799: const ec_pdo_t *ec_slave_find_pdo(const ec_slave_t *, uint16_t); fp@423: fp@39: /*****************************************************************************/ fp@0: fp@0: #endif