master/slave.h
changeset 325 7833cf70c4f2
parent 298 d491d1f84ebc
child 329 d004349777fc
equal deleted inserted replaced
324:9aa51cbdbfae 325:7833cf70c4f2
    42 #define _EC_SLAVE_H_
    42 #define _EC_SLAVE_H_
    43 
    43 
    44 #include <linux/list.h>
    44 #include <linux/list.h>
    45 #include <linux/kobject.h>
    45 #include <linux/kobject.h>
    46 
    46 
       
    47 #include "../include/ecrt.h"
       
    48 
    47 #include "globals.h"
    49 #include "globals.h"
    48 #include "datagram.h"
    50 #include "datagram.h"
    49 #include "types.h"
       
    50 
    51 
    51 /*****************************************************************************/
    52 /*****************************************************************************/
    52 
    53 
    53 /**
    54 /**
    54    State of an EtherCAT slave.
    55    State of an EtherCAT slave.
    88 };
    89 };
    89 
    90 
    90 /*****************************************************************************/
    91 /*****************************************************************************/
    91 
    92 
    92 /**
    93 /**
    93    FMMU configuration.
       
    94 */
       
    95 
       
    96 typedef struct
       
    97 {
       
    98     const ec_domain_t *domain; /**< domain */
       
    99     const ec_sync_t *sync; /**< sync manager */
       
   100     uint32_t logical_start_address; /**< logical start address */
       
   101 }
       
   102 ec_fmmu_t;
       
   103 
       
   104 /*****************************************************************************/
       
   105 
       
   106 /**
       
   107    String object (EEPROM).
    94    String object (EEPROM).
   108 */
    95 */
   109 
    96 
   110 typedef struct
    97 typedef struct
   111 {
    98 {
   112     struct list_head list; /**< list item */
    99     struct list_head list; /**< list item */
   113     size_t size; /**< size in bytes */
   100     size_t size; /**< size in bytes */
   114     char *data; /**< string data */
   101     char *data; /**< string data */
   115 }
   102 }
   116 ec_eeprom_string_t;
   103 ec_sii_string_t;
   117 
   104 
   118 /*****************************************************************************/
   105 /*****************************************************************************/
   119 
   106 
   120 /**
   107 /**
   121    Sync manager configuration (EEPROM).
   108    Sync manager configuration (EEPROM).
   128     uint16_t physical_start_address; /**< physical start address */
   115     uint16_t physical_start_address; /**< physical start address */
   129     uint16_t length; /**< data length in bytes */
   116     uint16_t length; /**< data length in bytes */
   130     uint8_t control_register; /**< control register value */
   117     uint8_t control_register; /**< control register value */
   131     uint8_t enable; /**< enable bit */
   118     uint8_t enable; /**< enable bit */
   132 }
   119 }
   133 ec_eeprom_sync_t;
   120 ec_sii_sync_t;
   134 
   121 
   135 /*****************************************************************************/
   122 /*****************************************************************************/
   136 
   123 
   137 /**
   124 /**
   138    PDO type.
   125    PDO type.
   141 typedef enum
   128 typedef enum
   142 {
   129 {
   143     EC_RX_PDO, /**< Reveive PDO */
   130     EC_RX_PDO, /**< Reveive PDO */
   144     EC_TX_PDO /**< Transmit PDO */
   131     EC_TX_PDO /**< Transmit PDO */
   145 }
   132 }
   146 ec_pdo_type_t;
   133 ec_sii_pdo_type_t;
   147 
   134 
   148 /*****************************************************************************/
   135 /*****************************************************************************/
   149 
   136 
   150 /**
   137 /**
   151    PDO description (EEPROM).
   138    PDO description (EEPROM).
   152 */
   139 */
   153 
   140 
   154 typedef struct
   141 typedef struct
   155 {
   142 {
   156     struct list_head list; /**< list item */
   143     struct list_head list; /**< list item */
   157     ec_pdo_type_t type; /**< PDO type */
   144     ec_sii_pdo_type_t type; /**< PDO type */
   158     uint16_t index; /**< PDO index */
   145     uint16_t index; /**< PDO index */
   159     uint8_t sync_manager; /**< assigned sync manager */
   146     uint8_t sync_index; /**< assigned sync manager */
   160     char *name; /**< PDO name */
   147     char *name; /**< PDO name */
   161     struct list_head entries; /**< entry list */
   148     struct list_head entries; /**< entry list */
   162 }
   149 }
   163 ec_eeprom_pdo_t;
   150 ec_sii_pdo_t;
   164 
   151 
   165 /*****************************************************************************/
   152 /*****************************************************************************/
   166 
   153 
   167 /**
   154 /**
   168    PDO entry description (EEPROM).
   155    PDO entry description (EEPROM).
   174     uint16_t index; /**< PDO index */
   161     uint16_t index; /**< PDO index */
   175     uint8_t subindex; /**< entry subindex */
   162     uint8_t subindex; /**< entry subindex */
   176     char *name; /**< entry name */
   163     char *name; /**< entry name */
   177     uint8_t bit_length; /**< entry length in bit */
   164     uint8_t bit_length; /**< entry length in bit */
   178 }
   165 }
   179 ec_eeprom_pdo_entry_t;
   166 ec_sii_pdo_entry_t;
   180 
   167 
   181 /*****************************************************************************/
   168 /*****************************************************************************/
   182 
   169 
   183 /**
   170 /**
   184    CANopen SDO.
   171    CANopen SDO.
   186 
   173 
   187 typedef struct
   174 typedef struct
   188 {
   175 {
   189     struct list_head list; /**< list item */
   176     struct list_head list; /**< list item */
   190     uint16_t index; /**< SDO index */
   177     uint16_t index; /**< SDO index */
   191     //uint16_t type;
       
   192     uint8_t object_code; /**< object code */
   178     uint8_t object_code; /**< object code */
   193     char *name; /**< SDO name */
   179     char *name; /**< SDO name */
   194     struct list_head entries; /**< entry list */
   180     struct list_head entries; /**< entry list */
   195 }
   181 }
   196 ec_sdo_t;
   182 ec_sdo_t;
   212 ec_sdo_entry_t;
   198 ec_sdo_entry_t;
   213 
   199 
   214 /*****************************************************************************/
   200 /*****************************************************************************/
   215 
   201 
   216 /**
   202 /**
       
   203    FMMU configuration.
       
   204 */
       
   205 
       
   206 typedef struct
       
   207 {
       
   208     const ec_domain_t *domain; /**< domain */
       
   209     const ec_sii_sync_t *sync; /**< sync manager */
       
   210     uint32_t logical_start_address; /**< logical start address */
       
   211 }
       
   212 ec_fmmu_t;
       
   213 
       
   214 /*****************************************************************************/
       
   215 
       
   216 /**
   217    Variable-sized field information.
   217    Variable-sized field information.
   218 */
   218 */
   219 
   219 
   220 typedef struct
   220 typedef struct
   221 {
   221 {
   222     struct list_head list; /**< list item */
   222     struct list_head list; /**< list item */
   223     const ec_field_t *field; /**< data field */
   223     const ec_sii_pdo_t *pdo; /**< PDO */
   224     size_t size; /**< field size */
   224     size_t size; /**< field size */
   225 }
   225 }
   226 ec_varsize_t;
   226 ec_varsize_t;
   227 
   227 
   228 /*****************************************************************************/
   228 /*****************************************************************************/
   234 struct ec_slave
   234 struct ec_slave
   235 {
   235 {
   236     struct list_head list; /**< list item */
   236     struct list_head list; /**< list item */
   237     struct kobject kobj; /**< kobject */
   237     struct kobject kobj; /**< kobject */
   238     ec_master_t *master; /**< master owning the slave */
   238     ec_master_t *master; /**< master owning the slave */
       
   239 
       
   240     ec_slave_state_t requested_state; /**< requested slave state */
       
   241     ec_slave_state_t current_state; /**< current slave state */
       
   242     unsigned int error_flag; /**< stop processing after an error */
       
   243     unsigned int online; /**< non-zero, if the slave responds. */
       
   244     uint8_t registered; /**< true, if slave has been registered */
   239 
   245 
   240     // addresses
   246     // addresses
   241     uint16_t ring_position; /**< ring position */
   247     uint16_t ring_position; /**< ring position */
   242     uint16_t station_address; /**< configured station address */
   248     uint16_t station_address; /**< configured station address */
   243     uint16_t coupler_index; /**< index of the last bus coupler */
   249     uint16_t coupler_index; /**< index of the last bus coupler */
   252 
   258 
   253     // data link status
   259     // data link status
   254     uint8_t dl_link[4]; /**< link detected */
   260     uint8_t dl_link[4]; /**< link detected */
   255     uint8_t dl_loop[4]; /**< loop closed */
   261     uint8_t dl_loop[4]; /**< loop closed */
   256     uint8_t dl_signal[4]; /**< detected signal on RX port */
   262     uint8_t dl_signal[4]; /**< detected signal on RX port */
       
   263 
       
   264     // EEPROM
       
   265     uint8_t *eeprom_data; /**< Complete EEPROM image */
       
   266     uint16_t eeprom_size; /**< size of the EEPROM contents in byte */
       
   267     uint16_t *new_eeprom_data; /**< new EEPROM data to write */
       
   268     uint16_t new_eeprom_size; /**< size of new EEPROM data in words */
   257 
   269 
   258     // slave information interface
   270     // slave information interface
   259     uint16_t sii_alias; /**< configured station alias */
   271     uint16_t sii_alias; /**< configured station alias */
   260     uint32_t sii_vendor_id; /**< vendor id */
   272     uint32_t sii_vendor_id; /**< vendor id */
   261     uint32_t sii_product_code; /**< vendor's product code */
   273     uint32_t sii_product_code; /**< vendor's product code */
   265     uint16_t sii_rx_mailbox_size; /**< mailbox size (master to slave) */
   277     uint16_t sii_rx_mailbox_size; /**< mailbox size (master to slave) */
   266     uint16_t sii_tx_mailbox_offset; /**< mailbox address (slave to master) */
   278     uint16_t sii_tx_mailbox_offset; /**< mailbox address (slave to master) */
   267     uint16_t sii_tx_mailbox_size; /**< mailbox size (slave to master) */
   279     uint16_t sii_tx_mailbox_size; /**< mailbox size (slave to master) */
   268     uint16_t sii_mailbox_protocols; /**< supported mailbox protocols */
   280     uint16_t sii_mailbox_protocols; /**< supported mailbox protocols */
   269     uint8_t sii_physical_layer[4]; /**< port media */
   281     uint8_t sii_physical_layer[4]; /**< port media */
   270 
   282     struct list_head sii_strings; /**< EEPROM STRING categories */
   271     const ec_slave_type_t *type; /**< pointer to slave type object */
   283     struct list_head sii_syncs; /**< EEPROM SYNC MANAGER categories */
   272 
   284     struct list_head sii_pdos; /**< EEPROM [RT]XPDO categories */
   273     uint8_t registered; /**< true, if slave has been registered */
   285     char *sii_group; /**< slave group acc. to EEPROM */
       
   286     char *sii_image; /**< slave image name acc. to EEPROM */
       
   287     char *sii_order; /**< slave order number acc. to EEPROM */
       
   288     char *sii_name; /**< slave name acc. to EEPROM */
   274 
   289 
   275     ec_fmmu_t fmmus[EC_MAX_FMMUS]; /**< FMMU configurations */
   290     ec_fmmu_t fmmus[EC_MAX_FMMUS]; /**< FMMU configurations */
   276     uint8_t fmmu_count; /**< number of FMMUs used */
   291     uint8_t fmmu_count; /**< number of FMMUs used */
   277 
   292 
   278     uint8_t *eeprom_data; /**< Complete EEPROM image */
       
   279     uint16_t eeprom_size; /**< size of the EEPROM contents in byte */
       
   280     struct list_head eeprom_strings; /**< EEPROM STRING categories */
       
   281     struct list_head eeprom_syncs; /**< EEPROM SYNC MANAGER categories */
       
   282     struct list_head eeprom_pdos; /**< EEPROM [RT]XPDO categories */
       
   283     char *eeprom_group; /**< slave group acc. to EEPROM */
       
   284     char *eeprom_image; /**< slave image name acc. to EEPROM */
       
   285     char *eeprom_order; /**< slave order number acc. to EEPROM */
       
   286     char *eeprom_name; /**< slave name acc. to EEPROM */
       
   287 
       
   288     uint16_t *new_eeprom_data; /**< new EEPROM data to write */
       
   289     size_t new_eeprom_size; /**< size of new EEPROM data in words */
       
   290 
       
   291     struct list_head sdo_dictionary; /**< SDO directory list */
   293     struct list_head sdo_dictionary; /**< SDO directory list */
   292 
       
   293     ec_slave_state_t requested_state; /**< requested slave state */
       
   294     ec_slave_state_t current_state; /**< current slave state */
       
   295     unsigned int error_flag; /**< stop processing after an error */
       
   296     unsigned int online; /**< non-zero, if the slave responds. */
       
   297 
   294 
   298     struct list_head varsize_fields; /**< size information for variable-sized
   295     struct list_head varsize_fields; /**< size information for variable-sized
   299                                         data fields. */
   296                                         data fields. */
   300 };
   297 };
   301 
   298 
   303 
   300 
   304 // slave construction/destruction
   301 // slave construction/destruction
   305 int ec_slave_init(ec_slave_t *, ec_master_t *, uint16_t, uint16_t);
   302 int ec_slave_init(ec_slave_t *, ec_master_t *, uint16_t, uint16_t);
   306 void ec_slave_clear(struct kobject *);
   303 void ec_slave_clear(struct kobject *);
   307 
   304 
   308 // slave control
       
   309 int ec_slave_fetch(ec_slave_t *);
       
   310 int ec_slave_sii_read16(ec_slave_t *, uint16_t, uint16_t *);
       
   311 int ec_slave_sii_read32(ec_slave_t *, uint16_t, uint32_t *);
       
   312 int ec_slave_sii_write16(ec_slave_t *, uint16_t, uint16_t);
       
   313 int ec_slave_state_change(ec_slave_t *, uint8_t);
       
   314 int ec_slave_prepare_fmmu(ec_slave_t *, const ec_domain_t *,
   305 int ec_slave_prepare_fmmu(ec_slave_t *, const ec_domain_t *,
   315                           const ec_sync_t *);
   306                           const ec_sii_sync_t *);
   316 
   307 
   317 // CoE
   308 // CoE
   318 int ec_slave_fetch_sdo_list(ec_slave_t *);
   309 //int ec_slave_fetch_sdo_list(ec_slave_t *);
   319 
   310 
   320 // state machine
   311 // SII categories
   321 int ec_slave_fetch_strings(ec_slave_t *, const uint8_t *);
   312 int ec_slave_fetch_strings(ec_slave_t *, const uint8_t *);
   322 int ec_slave_fetch_general(ec_slave_t *, const uint8_t *);
   313 void ec_slave_fetch_general(ec_slave_t *, const uint8_t *);
   323 int ec_slave_fetch_sync(ec_slave_t *, const uint8_t *, size_t);
   314 int ec_slave_fetch_sync(ec_slave_t *, const uint8_t *, size_t);
   324 int ec_slave_fetch_pdo(ec_slave_t *, const uint8_t *, size_t, ec_pdo_type_t);
   315 int ec_slave_fetch_pdo(ec_slave_t *, const uint8_t *, size_t,
       
   316                        ec_sii_pdo_type_t);
   325 int ec_slave_locate_string(ec_slave_t *, unsigned int, char **);
   317 int ec_slave_locate_string(ec_slave_t *, unsigned int, char **);
   326 
   318 
   327 // misc.
   319 // misc.
   328 size_t ec_slave_calc_sync_size(const ec_slave_t *, const ec_sync_t *);
   320 uint16_t ec_slave_calc_sync_size(const ec_slave_t *,
   329 uint16_t ec_slave_calc_eeprom_sync_size(const ec_slave_t *,
   321                                  const ec_sii_sync_t *);
   330                                         const ec_eeprom_sync_t *);
       
   331 
   322 
   332 void ec_slave_print(const ec_slave_t *, unsigned int);
   323 void ec_slave_print(const ec_slave_t *, unsigned int);
   333 int ec_slave_check_crc(ec_slave_t *);
   324 int ec_slave_is_coupler(const ec_slave_t *);
       
   325 //int ec_slave_check_crc(ec_slave_t *);
   334 
   326 
   335 /*****************************************************************************/
   327 /*****************************************************************************/
   336 
   328 
   337 #endif
   329 #endif