mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-02-05 19:39:50 +08:00
Changed Pdo entry registration function - return byte and bit positions
This commit is contained in:
@@ -57,14 +57,13 @@
|
||||
* offers the possibility to use a shared-memory region. Therefore,
|
||||
* added the domain methods ecrt_domain_size() and
|
||||
* ecrt_domain_external_memory().
|
||||
* - Replaced the process data pointers in the Pdo entry registration
|
||||
* functions with a process data offset, that is now returned either byte-
|
||||
* or bitwise by ecrt_slave_config_reg_pdo_entry() or
|
||||
* ecrt_slave_config_reg_pdo_entry_bitwise(), respectively. This was
|
||||
* necessary for the external domain memory. An additional advantage is,
|
||||
* that the returned offset is immediately valid. If the domain's
|
||||
* process data is allocated internally, the start address can be retrieved
|
||||
* with ecrt_domain_data().
|
||||
* - PDO registration functions do not return a process data pointer any
|
||||
* more. Instead an offset is returned by the funtion. In addition, an
|
||||
* optional bit position can be requested.
|
||||
* This was necessary for the external domain memory. An additional
|
||||
* advantage is, that the returned offset is immediately valid.
|
||||
* If the domain's process data is allocated internally, the start
|
||||
* address can be retrieved with ecrt_domain_data().
|
||||
* - Replaced ecrt_slave_pdo_mapping/add/clear() with
|
||||
* ecrt_slave_config_pdo_assign_add() to add a Pdo to a sync manager's Pdo
|
||||
* assignment and ecrt_slave_config_pdo_mapping_add() to add a Pdo entry to a
|
||||
@@ -240,8 +239,7 @@ typedef struct {
|
||||
/** List record type for Pdo entry mass-registration.
|
||||
*
|
||||
* This type is used for the array parameter of the
|
||||
* ecrt_domain_reg_pdo_entry_list() and
|
||||
* ecrt_domain_reg_pdo_entry_list_bitwise() convenience functions.
|
||||
* ecrt_domain_reg_pdo_entry_list()
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t alias; /**< Slave alias address. */
|
||||
@@ -253,8 +251,11 @@ typedef struct {
|
||||
unsigned int *offset; /**< Pointer to a variable to store the Pdo's
|
||||
offset in the process data. This can either be byte-
|
||||
or bitwise, depending on whether
|
||||
ecrt_domain_reg_pdo_entry_list() or
|
||||
ecrt_domain_reg_pdo_entry_list_bitwise() was called. */
|
||||
ecrt_domain_reg_pdo_entry_list() */
|
||||
unsigned int *bitposition; /** Pointer to variable to store a bit
|
||||
position within the address. Can be NULL,
|
||||
in which case an error is raised if the
|
||||
PDO does not byte-align. */
|
||||
} ec_pdo_entry_reg_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -519,7 +520,10 @@ int ecrt_slave_config_pdos(
|
||||
* corresponding sync manager and FMMU configurations are provided for slave
|
||||
* configuration and the respective sync manager's assigned Pdos are appended
|
||||
* to the given domain, if not already done. The offset of the requested Pdo
|
||||
* entry's data inside the domain's process data is returned.
|
||||
* entry's data inside the domain's process data is returned. Optionally, the
|
||||
* Pdo entry bit position can be retrieved if a non-null pointer is passed
|
||||
* to the \a bitposition parameter. If this is null, an error is raised if
|
||||
* the Pdo entry does not byte align.
|
||||
*
|
||||
* \retval >=0 Success: Offset of the Pdo entry's process data.
|
||||
* \retval -1 Error: Pdo entry not found.
|
||||
@@ -530,24 +534,9 @@ int ecrt_slave_config_reg_pdo_entry(
|
||||
ec_slave_config_t *sc, /**< Slave configuration. */
|
||||
uint16_t entry_index, /**< Index of the Pdo entry to register. */
|
||||
uint8_t entry_subindex, /**< Subindex of the Pdo entry to register. */
|
||||
ec_domain_t *domain /**< Domain. */
|
||||
);
|
||||
|
||||
/** Registers a Pdo entry for process data exchange in a domain.
|
||||
*
|
||||
* Bitwise registration function.
|
||||
*
|
||||
* \see ecrt_slave_config_reg_pdo_entry().
|
||||
*
|
||||
* \retval >=0 Success: Bit offset of the Pdo entry's process data.
|
||||
* \retval -1 Error: Pdo entry not found.
|
||||
* \retval -2 Error: Failed to register Pdo entry.
|
||||
*/
|
||||
int ecrt_slave_config_reg_pdo_entry_bitwise(
|
||||
ec_slave_config_t *sc, /**< Slave configuration. */
|
||||
uint16_t entry_index, /**< Index of the Pdo entry to register. */
|
||||
uint8_t entry_subindex, /**< Subindex of the Pdo entry to register. */
|
||||
ec_domain_t *domain /**< Domain. */
|
||||
ec_domain_t *domain, /**< Domain. */
|
||||
unsigned int *bitposition /**< Optional address if bit addressing
|
||||
is desired */
|
||||
);
|
||||
|
||||
/** Add an Sdo configuration.
|
||||
@@ -647,22 +636,6 @@ int ecrt_domain_reg_pdo_entry_list(
|
||||
registrations. */
|
||||
);
|
||||
|
||||
/** Registers a bunch of Pdo entries for a domain.
|
||||
*
|
||||
* Bitwise registration.
|
||||
*
|
||||
* \see ecrt_domain_reg_pdo_entry_list()
|
||||
*
|
||||
* \attention The registration array has to be terminated with an empty
|
||||
* structure, or one with the \a index field set to zero!
|
||||
* \return 0 on success, else non-zero.
|
||||
*/
|
||||
int ecrt_domain_reg_pdo_entry_list_bitwise(
|
||||
ec_domain_t *domain, /**< Domain. */
|
||||
const ec_pdo_entry_reg_t *pdo_entry_regs /**< Array of Pdo
|
||||
registrations. */
|
||||
);
|
||||
|
||||
/** Returns the current size of the domain's process data.
|
||||
*
|
||||
* \return Size of the process data image.
|
||||
|
||||
@@ -390,31 +390,7 @@ int ecrt_domain_reg_pdo_entry_list(ec_domain_t *domain,
|
||||
return -1;
|
||||
|
||||
if ((ret = ecrt_slave_config_reg_pdo_entry(sc, reg->index,
|
||||
reg->subindex, domain)) < 0)
|
||||
return -1;
|
||||
|
||||
*reg->offset = ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
int ecrt_domain_reg_pdo_entry_list_bitwise(ec_domain_t *domain,
|
||||
const ec_pdo_entry_reg_t *regs)
|
||||
{
|
||||
const ec_pdo_entry_reg_t *reg;
|
||||
ec_slave_config_t *sc;
|
||||
int ret;
|
||||
|
||||
for (reg = regs; reg->index; reg++) {
|
||||
if (!(sc = ecrt_master_slave_config(domain->master, reg->alias,
|
||||
reg->position, reg->vendor_id, reg->product_code)))
|
||||
return -1;
|
||||
|
||||
if ((ret = ecrt_slave_config_reg_pdo_entry_bitwise(sc, reg->index,
|
||||
reg->subindex, domain)) < 0)
|
||||
reg->subindex, domain, reg->bitposition)) < 0)
|
||||
return -1;
|
||||
|
||||
*reg->offset = ret;
|
||||
|
||||
@@ -604,34 +604,11 @@ int ecrt_slave_config_pdos(ec_slave_config_t *sc, unsigned int n_infos,
|
||||
/*****************************************************************************/
|
||||
|
||||
int ecrt_slave_config_reg_pdo_entry(
|
||||
ec_slave_config_t *sc, /**< Slave configuration. */
|
||||
uint16_t index, /**< Index of Pdo entry to register. */
|
||||
uint8_t subindex, /**< Subindex of Pdo entry to register. */
|
||||
ec_domain_t *domain /**< Domain. */
|
||||
)
|
||||
{
|
||||
int ret = ecrt_slave_config_reg_pdo_entry_bitwise(
|
||||
sc, index, subindex, domain);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (ret % 8) {
|
||||
EC_ERR("Bytewise Pdo entry registration requested, but the result is "
|
||||
"not byte-aligned.\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
return ret / 8;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
int ecrt_slave_config_reg_pdo_entry_bitwise(
|
||||
ec_slave_config_t *sc, /**< Slave configuration. */
|
||||
uint16_t index, /**< Index of Pdo entry to register. */
|
||||
uint8_t subindex, /**< Subindex of Pdo entry to register. */
|
||||
ec_domain_t *domain /**< Domain. */
|
||||
ec_slave_config_t *sc,
|
||||
uint16_t index,
|
||||
uint8_t subindex,
|
||||
ec_domain_t *domain,
|
||||
unsigned int *bitpos
|
||||
)
|
||||
{
|
||||
ec_direction_t dir;
|
||||
@@ -639,7 +616,7 @@ int ecrt_slave_config_reg_pdo_entry_bitwise(
|
||||
unsigned int bit_offset;
|
||||
ec_pdo_t *pdo;
|
||||
ec_pdo_entry_t *entry;
|
||||
int ret;
|
||||
int sync_offset;
|
||||
|
||||
for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
|
||||
pdos = &sc->pdos[dir];
|
||||
@@ -660,10 +637,20 @@ int ecrt_slave_config_reg_pdo_entry_bitwise(
|
||||
return -1;
|
||||
|
||||
found:
|
||||
if ((ret = ec_slave_config_prepare_fmmu(sc, domain, dir)) < 0)
|
||||
sync_offset = ec_slave_config_prepare_fmmu(sc, domain, dir);
|
||||
if (sync_offset < 0)
|
||||
return -2;
|
||||
return ret * 8 + bit_offset;
|
||||
}
|
||||
|
||||
if (bitpos) {
|
||||
*bitpos = bit_offset % 8;
|
||||
} else if (bit_offset % 8) {
|
||||
EC_ERR("Bytewise Pdo entry registration requested, but the result is "
|
||||
"not byte-aligned.\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
return sync_offset + bit_offset / 8;
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user