Added ecrt_master_read_idn() and ecrt_master_write_idn() to read/write SoE

IDNs ad-hoc using the library.
This commit is contained in:
Florian Pose 2010-04-27 10:37:32 +02:00
parent a43c7c4934
commit 21b95323d9
2 changed files with 89 additions and 1 deletions

View File

@ -75,7 +75,9 @@
* - Removed 'const' from argument of ecrt_sdo_request_state(), because the
* userspace library has to modify object internals.
* - Added 64-bit data access macros.
* - Added ecrt_slave_config_idn() method for storing SoE IDN configurations.
* - Added ecrt_slave_config_idn() method for storing SoE IDN configurations,
* and ecrt_master_read_idn() and ecrt_master_write_idn() to read/write IDNs
* ad-hoc via the user-space library.
*
* @{
*/
@ -661,6 +663,44 @@ int ecrt_master_sdo_upload(
uint32_t *abort_code /**< Abort code of the SDO upload. */
);
/** Executes an SoE write request.
*
* Starts writing an IDN and blocks until the request was processed, or an
* error occurred.
*
* \retval 0 Success.
* \retval -1 An error occured.
*/
int ecrt_master_write_idn(
ec_master_t *master, /**< EtherCAT master. */
uint16_t slave_position, /**< Slave position. */
uint16_t idn, /**< SoE IDN (see ecrt_slave_config_idn()). */
uint8_t *data, /**< Pointer to data to write. */
size_t data_size, /**< Size of data to write. */
uint32_t *error_code /**< Pointer to variable, where an SoE error code
can be stored. */
);
/** Executes an SoE read request.
*
* Starts reading an IDN and blocks until the request was processed, or an
* error occurred.
*
* \retval 0 Success.
* \retval -1 An error occured.
*/
int ecrt_master_read_idn(
ec_master_t *master, /**< EtherCAT master. */
uint16_t slave_position, /**< Slave position. */
uint16_t idn, /**< SoE IDN (see ecrt_slave_config_idn()). */
uint8_t *target, /**< Pointer to memory where the read data can be
stored. */
size_t target_size, /**< Size of the memory \a target points to. */
size_t *result_size, /**< Actual size of the received data. */
uint32_t *error_code /**< Pointer to variable, where an SoE error code
can be stored. */
);
#endif /* #ifndef __KERNEL__ */
/** Finishes the configuration phase and prepares for cyclic operation.

View File

@ -304,6 +304,54 @@ int ecrt_master_sdo_upload(ec_master_t *master, uint16_t slave_position,
/*****************************************************************************/
int ecrt_master_write_idn(ec_master_t *master, uint16_t slave_position,
uint16_t idn, uint8_t *data, size_t data_size, uint32_t *error_code)
{
ec_ioctl_slave_soe_write_t io;
io.slave_position = slave_position;
io.idn = idn;
io.data_size = data_size;
io.data = data;
if (ioctl(master->fd, EC_IOCTL_SLAVE_SOE_WRITE, &io) == -1) {
if (errno == EIO && error_code) {
*error_code = io.error_code;
}
fprintf(stderr, "Failed to write IDN: %s\n", strerror(errno));
return -1;
}
return 0;
}
/*****************************************************************************/
int ecrt_master_read_idn(ec_master_t *master, uint16_t slave_position,
uint16_t idn, uint8_t *target, size_t target_size,
size_t *result_size, uint32_t *error_code)
{
ec_ioctl_slave_soe_read_t io;
io.slave_position = slave_position;
io.idn = idn;
io.mem_size = target_size;
io.data = target;
if (ioctl(master->fd, EC_IOCTL_SLAVE_SOE_READ, &io) == -1) {
if (errno == EIO && error_code) {
*error_code = io.error_code;
}
fprintf(stderr, "Failed to read IDN: %s\n", strerror(errno));
return -1;
}
*result_size = io.data_size;
return 0;
}
/*****************************************************************************/
int ecrt_master_activate(ec_master_t *master)
{
if (ioctl(master->fd, EC_IOCTL_ACTIVATE,