From e9ff40325525f212906cd728b6d41e95150e4ad3 Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Wed, 16 Apr 2008 08:33:04 +0000 Subject: [PATCH] Exported ecrt_slave_config_sdo(); added documentation. --- NEWS | 2 ++ include/ecrt.h | 30 ++++++++++++++-- master/slave_config.c | 79 +++++++++++++++++++++---------------------- 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/NEWS b/NEWS index 8484960f..ae04f7a7 100644 --- a/NEWS +++ b/NEWS @@ -46,6 +46,8 @@ Changes in version 1.4.0: Pdo entries. - Added an Sdo access interface, working with Sdo requests. These can be scheduled for reading and writing during realtime operation. + - Exported ecrt_slave_config_sdo(), the generic Sdo configuration + function. * Pdo configuration is now supported. * Current Pdo mapping/configuration is now read via CoE during bus scan, using direct Sdo access, independent of the dictionary. diff --git a/include/ecrt.h b/include/ecrt.h index 8876a5e6..d531d633 100644 --- a/include/ecrt.h +++ b/include/ecrt.h @@ -84,6 +84,7 @@ * Pdo entries. * - Added an Sdo access interface, working with Sdo requests. These can be * scheduled for reading and writing during realtime operation. + * - Exported ecrt_slave_config_sdo(), the generic Sdo configuration function. * * @{ */ @@ -541,9 +542,32 @@ int ecrt_slave_config_reg_pdo_entry( ec_domain_t *domain /**< Domain. */ ); +/** Add an Sdo configuration. + * + * An Sdo configuration is stored in the slave configuration object and is + * downloaded to the slave whenever the slave is being configured by the + * master. This usually happens once on master activation, but can be repeated + * subsequently, for example after the slave's power supply failed. + * + * This is the generic function for adding an Sdo configuration. Please note + * that the this function does not do any endianess correction. If + * datatype-specific functions are needed (that automatically correct the + * endianess), have a look at ecrt_slave_config_sdo8(), + * ecrt_slave_config_sdo16() and ecrt_slave_config_sdo32(). + * + * \return 0 in case of success, else < 0 + */ +int ecrt_slave_config_sdo( + ec_slave_config_t *sc, /**< Slave configuration. */ + uint16_t index, /**< Index of the Sdo to configure. */ + uint8_t subindex, /**< Subindex of the Sdo to configure. */ + const uint8_t *data, /**< Pointer to the data. */ + size_t size /**< Size of the \a data. */ + ); + /** Add a configuration value for an 8-bit SDO. * - * \todo doc + * \see ecrt_slave_config_sdo(). * \return 0 in case of success, else < 0 */ int ecrt_slave_config_sdo8( @@ -555,7 +579,7 @@ int ecrt_slave_config_sdo8( /** Add a configuration value for a 16-bit SDO. * - * \todo doc + * \see ecrt_slave_config_sdo(). * \return 0 in case of success, else < 0 */ int ecrt_slave_config_sdo16( @@ -567,7 +591,7 @@ int ecrt_slave_config_sdo16( /** Add a configuration value for a 32-bit SDO. * - * \todo doc + * \see ecrt_slave_config_sdo(). * \return 0 in case of success, else < 0 */ int ecrt_slave_config_sdo32( diff --git a/master/slave_config.c b/master/slave_config.c index aaa2237c..8fd776ab 100644 --- a/master/slave_config.c +++ b/master/slave_config.c @@ -320,40 +320,6 @@ ssize_t ec_show_slave_config_attribute( /*****************************************************************************/ -/** Adds an Sdo configuration. - */ -int ec_slave_config_sdo(ec_slave_config_t *sc, uint16_t index, - uint8_t subindex, const uint8_t *data, size_t size) -{ - ec_slave_t *slave = sc->slave; - ec_sdo_request_t *req; - - if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) { - EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); - return -1; - } - - if (!(req = (ec_sdo_request_t *) - kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) { - EC_ERR("Failed to allocate memory for Sdo configuration!\n"); - return -1; - } - - ec_sdo_request_init(req); - ec_sdo_request_address(req, index, subindex); - - if (ec_sdo_request_copy_data(req, data, size)) { - ec_sdo_request_clear(req); - kfree(req); - return -1; - } - - list_add_tail(&req->list, &sc->sdo_configs); - return 0; -} - -/*****************************************************************************/ - /** Attaches the configuration to the addressed slave object. * * \retval 0 Success. @@ -677,32 +643,64 @@ found: /*****************************************************************************/ -int ecrt_slave_config_sdo8(ec_slave_config_t *slave, uint16_t index, +int ecrt_slave_config_sdo(ec_slave_config_t *sc, uint16_t index, + uint8_t subindex, const uint8_t *data, size_t size) +{ + ec_slave_t *slave = sc->slave; + ec_sdo_request_t *req; + + if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) { + EC_ERR("Slave %u does not support CoE!\n", slave->ring_position); + return -1; + } + + if (!(req = (ec_sdo_request_t *) + kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) { + EC_ERR("Failed to allocate memory for Sdo configuration!\n"); + return -1; + } + + ec_sdo_request_init(req); + ec_sdo_request_address(req, index, subindex); + + if (ec_sdo_request_copy_data(req, data, size)) { + ec_sdo_request_clear(req); + kfree(req); + return -1; + } + + list_add_tail(&req->list, &sc->sdo_configs); + return 0; +} + +/*****************************************************************************/ + +int ecrt_slave_config_sdo8(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, uint8_t value) { uint8_t data[1]; EC_WRITE_U8(data, value); - return ec_slave_config_sdo(slave, index, subindex, data, 1); + return ecrt_slave_config_sdo(sc, index, subindex, data, 1); } /*****************************************************************************/ -int ecrt_slave_config_sdo16(ec_slave_config_t *slave, uint16_t index, +int ecrt_slave_config_sdo16(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, uint16_t value) { uint8_t data[2]; EC_WRITE_U16(data, value); - return ec_slave_config_sdo(slave, index, subindex, data, 2); + return ecrt_slave_config_sdo(sc, index, subindex, data, 2); } /*****************************************************************************/ -int ecrt_slave_config_sdo32(ec_slave_config_t *slave, uint16_t index, +int ecrt_slave_config_sdo32(ec_slave_config_t *sc, uint16_t index, uint8_t subindex, uint32_t value) { uint8_t data[4]; EC_WRITE_U32(data, value); - return ec_slave_config_sdo(slave, index, subindex, data, 4); + return ecrt_slave_config_sdo(sc, index, subindex, data, 4); } /*****************************************************************************/ @@ -745,6 +743,7 @@ EXPORT_SYMBOL(ecrt_slave_config_pdo_mapping_add); EXPORT_SYMBOL(ecrt_slave_config_pdo_mapping_clear); EXPORT_SYMBOL(ecrt_slave_config_pdos); EXPORT_SYMBOL(ecrt_slave_config_reg_pdo_entry); +EXPORT_SYMBOL(ecrt_slave_config_sdo); EXPORT_SYMBOL(ecrt_slave_config_sdo8); EXPORT_SYMBOL(ecrt_slave_config_sdo16); EXPORT_SYMBOL(ecrt_slave_config_sdo32);