Moved fetching domain offset to ecrt_master_activate().

This commit is contained in:
Florian Pose
2024-02-07 15:27:47 +01:00
parent 4bab54a336
commit a5df1c38d1
4 changed files with 18 additions and 17 deletions

View File

@@ -1866,7 +1866,7 @@ void ecrt_domain_external_memory(
* \return Pointer to the process data memory.
*/
EC_PUBLIC_API uint8_t *ecrt_domain_data(
ec_domain_t *domain /**< Domain. */
const ec_domain_t *domain /**< Domain. */
);
/** Determines the states of the domain's datagrams.

View File

@@ -83,22 +83,8 @@ size_t ecrt_domain_size(const ec_domain_t *domain)
/****************************************************************************/
uint8_t *ecrt_domain_data(ec_domain_t *domain)
uint8_t *ecrt_domain_data(const ec_domain_t *domain)
{
if (!domain->process_data) {
int offset = 0;
offset = ioctl(domain->master->fd, EC_IOCTL_DOMAIN_OFFSET,
domain->index);
if (EC_IOCTL_IS_ERROR(offset)) {
fprintf(stderr, "Failed to get domain offset: %s\n",
strerror(EC_IOCTL_ERRNO(offset)));
return NULL;
}
domain->process_data = domain->master->process_data + offset;
}
return domain->process_data;
}

View File

@@ -585,6 +585,21 @@ int ecrt_master_activate(ec_master_t *master)
master->process_data[0] = 0x00;
}
// pick up process data pointers for all created domains
ec_domain_t *domain = master->first_domain;
while (domain) {
int offset = ioctl(domain->master->fd, EC_IOCTL_DOMAIN_OFFSET,
domain->index);
if (EC_IOCTL_IS_ERROR(offset)) {
fprintf(stderr, "Failed to get domain offset: %s\n",
strerror(EC_IOCTL_ERRNO(offset)));
return -EC_IOCTL_ERRNO(offset);
}
domain->process_data = master->process_data + offset;
domain = domain->next;
}
return 0;
}

View File

@@ -440,7 +440,7 @@ void ecrt_domain_external_memory(ec_domain_t *domain, uint8_t *mem)
/****************************************************************************/
uint8_t *ecrt_domain_data(ec_domain_t *domain)
uint8_t *ecrt_domain_data(const ec_domain_t *domain)
{
return domain->data;
}