include/ecrt.h
changeset 925 939f3e9bba1e
parent 923 a6b51990e7e6
child 1007 b6c3527697c3
equal deleted inserted replaced
924:d8d9a1056afa 925:939f3e9bba1e
    55  *   ecrt_slave_config_state().
    55  *   ecrt_slave_config_state().
    56  * - Process data memory for a domain can now be allocated externally. This
    56  * - Process data memory for a domain can now be allocated externally. This
    57  *   offers the possibility to use a shared-memory region. Therefore,
    57  *   offers the possibility to use a shared-memory region. Therefore,
    58  *   added the domain methods ecrt_domain_size() and
    58  *   added the domain methods ecrt_domain_size() and
    59  *   ecrt_domain_external_memory().
    59  *   ecrt_domain_external_memory().
    60  * - PDO registration functions do not return a process data pointer any
    60  * - Pdo entry registration functions do not return a process data pointer,
    61  *   more. Instead an offset is returned by the funtion. In addition, an 
    61  *   but an offset in the domain's process data. In addition, an optional bit
    62  *   optional bit position can be requested.
    62  *   position can be requested. This was necessary for the external domain
    63  *   This was necessary for the external domain memory. An additional 
    63  *   memory. An additional advantage is, that the returned offset is
    64  *   advantage is, that the returned offset is immediately valid. 
    64  *   immediately valid. If the domain's process data is allocated internally,
    65  *   If the domain's process data is allocated internally, the start 
    65  *   the start address can be retrieved with ecrt_domain_data().
    66  *   address can be retrieved with ecrt_domain_data().
       
    67  * - Replaced ecrt_slave_pdo_mapping/add/clear() with
    66  * - Replaced ecrt_slave_pdo_mapping/add/clear() with
    68  *   ecrt_slave_config_pdo_assign_add() to add a Pdo to a sync manager's Pdo
    67  *   ecrt_slave_config_pdo_assign_add() to add a Pdo to a sync manager's Pdo
    69  *   assignment and ecrt_slave_config_pdo_mapping_add() to add a Pdo entry to a
    68  *   assignment and ecrt_slave_config_pdo_mapping_add() to add a Pdo entry to a
    70  *   Pdo's mapping. ecrt_slave_config_pdos() is a convenience function
    69  *   Pdo's mapping. ecrt_slave_config_pdos() is a convenience function
    71  *   for both, that uses the new data types ec_pdo_info_t and
    70  *   for both, that uses the new data types ec_pdo_info_t and
    79  *   information, if the process data was exchanged completely.
    78  *   information, if the process data was exchanged completely.
    80  * - Former "Pdo registration" meant Pdo entry registration in fact, therefore
    79  * - Former "Pdo registration" meant Pdo entry registration in fact, therefore
    81  *   renamed ec_pdo_reg_t to ec_pdo_entry_reg_t and ecrt_domain_register_pdo()
    80  *   renamed ec_pdo_reg_t to ec_pdo_entry_reg_t and ecrt_domain_register_pdo()
    82  *   to ecrt_slave_config_reg_pdo_entry().
    81  *   to ecrt_slave_config_reg_pdo_entry().
    83  * - Removed ecrt_domain_register_pdo_range(), because it's functionality can
    82  * - Removed ecrt_domain_register_pdo_range(), because it's functionality can
    84  *   be reached by specifying an explicit Pdo mapping and registering those
    83  *   be reached by specifying an explicit Pdo assignment/mapping and
    85  *   Pdo entries.
    84  *   registering the mapped Pdo entries.
    86  * - Added an Sdo access interface, working with Sdo requests. These can be
    85  * - Added an Sdo access interface, working with Sdo requests. These can be
    87  *   scheduled for reading and writing during realtime operation.
    86  *   scheduled for reading and writing during realtime operation.
    88  * - Exported ecrt_slave_config_sdo(), the generic Sdo configuration function.
    87  * - Exported ecrt_slave_config_sdo(), the generic Sdo configuration function.
    89  * - Removed the bus_state and bus_tainted flags from ec_master_state_t.
    88  * - Removed the bus_state and bus_tainted flags from ec_master_state_t.
    90  *
    89  *
   124  */
   123  */
   125 #define ECRT_VERSION_MAGIC ECRT_VERSION(ECRT_VER_MAJOR, ECRT_VER_MINOR)
   124 #define ECRT_VERSION_MAGIC ECRT_VERSION(ECRT_VER_MAJOR, ECRT_VER_MINOR)
   126 
   125 
   127 /*****************************************************************************/
   126 /*****************************************************************************/
   128 
   127 
   129 /** End of the Pdo list.
   128 /** End of the Pdo entry list.
   130  *
   129  *
   131  * This is used in ecrt_slave_config_pdos().
   130  * This is used in ecrt_slave_config_pdos().
   132  */
   131  */
   133 #define EC_END ~0U
   132 #define EC_END ~0U
   134 
   133 
   175 /** Domain working counter interpretation.
   174 /** Domain working counter interpretation.
   176  *
   175  *
   177  * This is used in ec_domain_state_t.
   176  * This is used in ec_domain_state_t.
   178  */
   177  */
   179 typedef enum {
   178 typedef enum {
   180     EC_WC_ZERO = 0,   /**< No Pdos were exchanged. */
   179     EC_WC_ZERO = 0,   /**< No registered process data were exchanged. */
   181     EC_WC_INCOMPLETE, /**< Some of the registered Pdos were exchanged. */
   180     EC_WC_INCOMPLETE, /**< Some of the registered process data were
   182     EC_WC_COMPLETE    /**< All registered Pdos were exchanged. */
   181                         exchanged. */
       
   182     EC_WC_COMPLETE    /**< All registered process data were exchanged. */
   183 } ec_wc_state_t;
   183 } ec_wc_state_t;
   184 
   184 
   185 /*****************************************************************************/
   185 /*****************************************************************************/
   186 
   186 
   187 /** Domain state.
   187 /** Domain state.
   193     ec_wc_state_t wc_state; /**< Working counter interpretation. */
   193     ec_wc_state_t wc_state; /**< Working counter interpretation. */
   194 } ec_domain_state_t;
   194 } ec_domain_state_t;
   195 
   195 
   196 /*****************************************************************************/
   196 /*****************************************************************************/
   197 
   197 
   198 /** Direction type for Pdo mapping functions.
   198 /** Direction type for Pdo assignment functions.
   199  */
   199  */
   200 typedef enum {
   200 typedef enum {
   201     EC_DIR_OUTPUT, /**< Values written by the master. */
   201     EC_DIR_OUTPUT, /**< Values written by the master. */
   202     EC_DIR_INPUT   /**< Values read by the master. */
   202     EC_DIR_INPUT   /**< Values read by the master. */
   203 } ec_direction_t;
   203 } ec_direction_t;
   209  * This can be used to map multiple Pdo entries into a given Pdo using
   209  * This can be used to map multiple Pdo entries into a given Pdo using
   210  * ecrt_slave_config_pdos().
   210  * ecrt_slave_config_pdos().
   211  */
   211  */
   212 typedef struct {
   212 typedef struct {
   213     uint16_t index; /**< Index of the Pdo entry to add to the Pdo
   213     uint16_t index; /**< Index of the Pdo entry to add to the Pdo
   214                             configuration. */
   214                             mapping. */
   215     uint8_t subindex; /**< Subindex of the Pdo entry to add to the
   215     uint8_t subindex; /**< Subindex of the Pdo entry. */
   216                               Pdo configuration. */
       
   217     uint8_t bit_length; /**< Size of the Pdo entry in bit. */
   216     uint8_t bit_length; /**< Size of the Pdo entry in bit. */
   218 } ec_pdo_entry_info_t;
   217 } ec_pdo_entry_info_t;
   219 
   218 
   220 /*****************************************************************************/
   219 /*****************************************************************************/
   221 
   220 
   224  * This can be use to assign multiple Pdos to a sync manager using
   223  * This can be use to assign multiple Pdos to a sync manager using
   225  * ecrt_slave_config_pdos().
   224  * ecrt_slave_config_pdos().
   226  */
   225  */
   227 typedef struct {
   226 typedef struct {
   228     ec_direction_t dir; /**< Pdo direction (input/output). */
   227     ec_direction_t dir; /**< Pdo direction (input/output). */
   229     uint16_t index; /**< Index of the Pdo to map. */
   228     uint16_t index; /**< Index of the Pdo to assign. */
   230     unsigned int n_entries; /**< Number of Pdo entries in \a entries to map.
   229     unsigned int n_entries; /**< Number of Pdo entries in \a entries to map.
   231                               Zero means, that the default mapping shall be
   230                               Zero means, that the default mapping shall be
   232                               used. */
   231                               used (this can only be done if the slave is
       
   232                               present at bus configuration time). */
   233     ec_pdo_entry_info_t *entries; /**< Array of Pdo entries to map. This must
   233     ec_pdo_entry_info_t *entries; /**< Array of Pdo entries to map. This must
   234                                     contain at least \a n_entries values. */
   234                                     contain at least \a n_entries values. */
   235 } ec_pdo_info_t;
   235 } ec_pdo_info_t;
   236 
   236 
   237 /*****************************************************************************/
   237 /*****************************************************************************/
   246     uint16_t position; /**< Slave position. */
   246     uint16_t position; /**< Slave position. */
   247     uint32_t vendor_id; /**< Slave vendor ID. */
   247     uint32_t vendor_id; /**< Slave vendor ID. */
   248     uint32_t product_code; /**< Slave product code. */
   248     uint32_t product_code; /**< Slave product code. */
   249     uint16_t index; /**< Pdo entry index. */
   249     uint16_t index; /**< Pdo entry index. */
   250     uint8_t subindex; /**< Pdo entry subindex. */
   250     uint8_t subindex; /**< Pdo entry subindex. */
   251     unsigned int *offset; /**< Pointer to a variable to store the Pdo's
   251     unsigned int *offset; /**< Pointer to a variable to store the Pdo entry's
   252                        offset in the process data. This can either be byte-
   252                        (byte-)offset in the process data. */
   253                        or bitwise, depending on whether
   253     unsigned int *bit_position; /** Pointer to a variable to store a bit 
   254                        ecrt_domain_reg_pdo_entry_list() */
   254                                  position (0-7) within the \a offset. Can be
   255     unsigned int *bitposition; /** Pointer to variable to store a bit 
   255                                  NULL, in which case an error is raised if the
   256                                  position within the address. Can be NULL,
   256                                  Pdo entry does not byte-align. */
   257                                 in which case an error is raised if the 
       
   258                                 PDO does not byte-align. */
       
   259 } ec_pdo_entry_reg_t;
   257 } ec_pdo_entry_reg_t;
   260 
   258 
   261 /*****************************************************************************/
   259 /*****************************************************************************/
   262 
   260 
   263 /** Sdo request state.
   261 /** Sdo request state.
   355         uint32_t product_code /**< Expected product code. */
   353         uint32_t product_code /**< Expected product code. */
   356         );
   354         );
   357 
   355 
   358 /** Finishes the configuration phase and prepares for realtime mode.
   356 /** Finishes the configuration phase and prepares for realtime mode.
   359  *
   357  *
   360  * This function has to be called after all Pdo entries are registered. It
   358  * This function tells the master that the configuration phase is finished and
   361  * tells the master that the configuration phase is finished and the realtime
   359  * the realtime operation will begin. The function allocates internal memory
   362  * operation will begin. The function allocates internal memory for the
   360  * for the domains and calculates the logical FMMU addresses for domain
   363  * domains and calculates the logical FMMU addresses for domain members. It
   361  * members. It tells the master state machine that the bus configuration is
   364  * tells the master state machine that the bus configuration is now to be
   362  * now to be applied.
   365  * applied.
       
   366  *
   363  *
   367  * \attention After this function has been called, the realtime application is
   364  * \attention After this function has been called, the realtime application is
   368  * in charge of cyclically calling ecrt_master_send() and
   365  * in charge of cyclically calling ecrt_master_send() and
   369  * ecrt_master_receive() to ensure bus communication. Before calling this
   366  * ecrt_master_receive() to ensure bus communication. Before calling this
   370  * function, the master thread is responsible for that, so these functions may
   367  * function, the master thread is responsible for that, so these functions may
   513         const ec_pdo_info_t pdo_infos[] /**< List with Pdos. */
   510         const ec_pdo_info_t pdo_infos[] /**< List with Pdos. */
   514         );
   511         );
   515 
   512 
   516 /** Registers a Pdo entry for process data exchange in a domain.
   513 /** Registers a Pdo entry for process data exchange in a domain.
   517  *
   514  *
   518  * Searches the current Pdo assignment and Pdo mappings for the given Pdo
   515  * Searches the assigned Pdos for the given Pdo entry. An error is raised, if
   519  * entry. An error is raised, if the given entry is not mapped. Otherwise, the
   516  * the given entry is not mapped. Otherwise, the corresponding sync manager
   520  * corresponding sync manager and FMMU configurations are provided for slave
   517  * and FMMU configurations are provided for slave configuration and the
   521  * configuration and the respective sync manager's assigned Pdos are appended
   518  * respective sync manager's assigned Pdos are appended to the given domain,
   522  * to the given domain, if not already done. The offset of the requested Pdo
   519  * if not already done. The offset of the requested Pdo entry's data inside
   523  * entry's data inside the domain's process data is returned. Optionally, the
   520  * the domain's process data is returned. Optionally, the Pdo entry bit
   524  * Pdo entry bit position can be retrieved if a non-null pointer is passed
   521  * position (0-7) can be retrieved via the \a bit_position output parameter.
   525  * to the \a bitposition parameter. If this is null, an error is raised if
   522  * This pointer may be \a NULL, in this case an error is raised if the Pdo
   526  * the Pdo entry does not byte align.
   523  * entry does not byte-align.
   527  *
   524  *
   528  * \retval >=0 Success: Offset of the Pdo entry's process data.
   525  * \retval >=0 Success: Offset of the Pdo entry's process data.
   529  * \retval -1  Error: Pdo entry not found.
   526  * \retval -1  Error: Pdo entry not found.
   530  * \retval -2  Error: Failed to register Pdo entry.
   527  * \retval -2  Error: Failed to register Pdo entry.
   531  * \retval -3  Error: Pdo entry is not byte-aligned.
   528  * \retval -3  Error: Pdo entry is not byte-aligned.
   533 int ecrt_slave_config_reg_pdo_entry(
   530 int ecrt_slave_config_reg_pdo_entry(
   534         ec_slave_config_t *sc, /**< Slave configuration. */
   531         ec_slave_config_t *sc, /**< Slave configuration. */
   535         uint16_t entry_index, /**< Index of the Pdo entry to register. */
   532         uint16_t entry_index, /**< Index of the Pdo entry to register. */
   536         uint8_t entry_subindex, /**< Subindex of the Pdo entry to register. */
   533         uint8_t entry_subindex, /**< Subindex of the Pdo entry to register. */
   537         ec_domain_t *domain, /**< Domain. */
   534         ec_domain_t *domain, /**< Domain. */
   538         unsigned int *bitposition /**< Optional address if bit addressing 
   535         unsigned int *bit_position /**< Optional address if bit addressing 
   539                                  is desired */
   536                                  is desired */
   540         );
   537         );
   541 
   538 
   542 /** Add an Sdo configuration.
   539 /** Add an Sdo configuration.
   543  *
   540  *