Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download(). Thanks to
S. Weiser.
This commit is contained in:
parent
54a04f7841
commit
779c653142
3
NEWS
3
NEWS
|
|
@ -36,6 +36,9 @@ Changes since 1.4.0:
|
|||
* Output device link state in 'ethercat master'.
|
||||
* Added 'ethercat graph' command which outputs the bus topology in
|
||||
DOT language.
|
||||
* Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download() methods to let
|
||||
an application transfer SDOs before activating the master. Thanks to Stefan
|
||||
Weiser.
|
||||
|
||||
Changes in 1.4.0:
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@
|
|||
* - Renamed ec_sdo_request_state_t to ec_request_state_t, because it is also
|
||||
* used by VoE handlers.
|
||||
* - Added ecrt_master_slave() to get information about a certain slave.
|
||||
* - Added ecrt_slave_sdo_upload() and ecrt_slave_sdo_download() methods to
|
||||
* let an application transfer SDOs before activating the master.
|
||||
* - Removed 'const' from argument of ecrt_sdo_request_state(), because the
|
||||
* userspace library has to modify object internals.
|
||||
* - Added 64-bit data access macros.
|
||||
|
|
@ -448,6 +450,8 @@ ec_slave_config_t *ecrt_master_slave_config(
|
|||
uint32_t product_code /**< Expected product code. */
|
||||
);
|
||||
|
||||
#ifndef __KERNEL__
|
||||
|
||||
/** Obtains slave information.
|
||||
*
|
||||
* Tries to find the slave with the given ring position. The obtained
|
||||
|
|
@ -465,6 +469,8 @@ int ecrt_master_slave(
|
|||
information */
|
||||
);
|
||||
|
||||
#endif /* ifndef __KERNEL__ */
|
||||
|
||||
/** Finishes the configuration phase and prepares for cyclic operation.
|
||||
*
|
||||
* This function tells the master that the configuration phase is finished and
|
||||
|
|
@ -551,6 +557,50 @@ void ecrt_master_sync_slave_clocks(
|
|||
ec_master_t *master /**< EtherCAT master. */
|
||||
);
|
||||
|
||||
#ifndef __KERNEL__
|
||||
|
||||
/** Executes an SDO write request to download data.
|
||||
*
|
||||
* This function operates aside of the normal way to request SDOs. Before the
|
||||
* activation of the master, these requests are processed by the master state
|
||||
* machine itself. After activation the user has to ensure cyclic processing.
|
||||
*
|
||||
* \retval 0 Success.
|
||||
* \retval -1 An error occured.
|
||||
*/
|
||||
int ecrt_slave_sdo_download(
|
||||
ec_master_t* master, /**< EtherCAT master. */
|
||||
uint16_t slave_position, /**< Slave position. */
|
||||
uint16_t index, /**< Index of the SDO. */
|
||||
uint8_t subindex, /**< Subindex of the SDO. */
|
||||
uint8_t *data, /**< Data buffer to download. */
|
||||
size_t data_size, /**< Size of the data buffer. */
|
||||
uint32_t *abort_code /**< Abort code of the SDO download. */
|
||||
);
|
||||
|
||||
/** Executes a SDO read request to upload data.
|
||||
*
|
||||
* This function operates aside of the normal way to request SDOs. Before the
|
||||
* activation of the master, these requests are processed by the master state
|
||||
* machine itself. After activation the user have to ensure cyclic
|
||||
* processing.
|
||||
*
|
||||
* \retval 0 Success.
|
||||
* \retval -1 Error occured.
|
||||
*/
|
||||
int ecrt_slave_sdo_upload(
|
||||
ec_master_t* master, /**< EtherCAT master. */
|
||||
uint16_t slave_position, /**< Slave position. */
|
||||
uint16_t index, /**< Index of the SDO. */
|
||||
uint8_t subindex, /**< Subindex of the SDO. */
|
||||
uint8_t *target, /**< Target buffer for the upload. */
|
||||
size_t target_size, /**< Size of the target buffer. */
|
||||
size_t *result_size, /**< Uploaded data size. */
|
||||
uint32_t *abort_code /**< Abort code of the SDO upload. */
|
||||
);
|
||||
|
||||
#endif /* ifndef __KERNEL__ */
|
||||
|
||||
/******************************************************************************
|
||||
* Slave configuration methods
|
||||
*****************************************************************************/
|
||||
|
|
|
|||
57
lib/master.c
57
lib/master.c
|
|
@ -222,3 +222,60 @@ void ecrt_master_sync_slave_clocks(ec_master_t *master)
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
int ecrt_slave_sdo_download(ec_master_t* master, uint16_t slave_position,
|
||||
uint16_t index, uint8_t subindex, uint8_t *data,
|
||||
size_t data_size, uint32_t *abort_code)
|
||||
{
|
||||
ec_ioctl_slave_sdo_download_t download;
|
||||
|
||||
download.slave_position = slave_position;
|
||||
download.sdo_index = index;
|
||||
download.sdo_entry_subindex = subindex;
|
||||
download.data_size = data_size;
|
||||
download.data = data;
|
||||
|
||||
if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, &download) == -1) {
|
||||
if (errno == -EIO) {
|
||||
if (abort_code) {
|
||||
*abort_code = download.abort_code;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "Failed to execute SDO download: %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
int ecrt_slave_sdo_upload(ec_master_t* master, uint16_t slave_position,
|
||||
uint16_t index, uint8_t subindex, uint8_t *target,
|
||||
size_t target_size, size_t *result_size, uint32_t *abort_code)
|
||||
{
|
||||
ec_ioctl_slave_sdo_upload_t upload;
|
||||
|
||||
upload.slave_position = slave_position;
|
||||
upload.sdo_index = index;
|
||||
upload.sdo_entry_subindex = subindex;
|
||||
upload.target_size = target_size;
|
||||
upload.target = target;
|
||||
|
||||
if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_UPLOAD, &upload) == -1) {
|
||||
if (errno == -EIO) {
|
||||
if (abort_code) {
|
||||
*abort_code = upload.abort_code;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "Failed to execute SDO upload: %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
*result_size = upload.data_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
Loading…
Reference in New Issue