Made ec_sync_config() and ec_fmmu_config() to methods of ec_slave_t.

This commit is contained in:
Florian Pose 2007-02-13 11:48:46 +00:00
parent 4ae39d6287
commit e643409867
6 changed files with 79 additions and 82 deletions

1
TODO
View File

@ -23,7 +23,6 @@ $Id$
* Implement interface for alternative PDO mapping.
* Simplify FSMs with <state>_enter() functions.
* Make ec_sync_config() and ec_fmmu_config() to methods of ec_slave_t.
* Rename "sysconfig" file to "sysconfig/ethercat".
* Dynamic creation of EoE handlers.
* Output intermediate results during lsec.

View File

@ -696,24 +696,24 @@ void ec_fsm_slave_conf_enter_sync(ec_fsm_slave_t *fsm /**< slave state machine *
mbox_sync.control_register = 0x26;
mbox_sync.enable = 0x01;
mbox_sync.est_length = 0;
ec_sync_config(&mbox_sync, slave,
datagram->data + EC_SYNC_SIZE * mbox_sync.index);
ec_slave_sync_config(slave, &mbox_sync,
datagram->data + EC_SYNC_SIZE * mbox_sync.index);
mbox_sync.index = 1;
mbox_sync.physical_start_address = slave->sii_rx_mailbox_offset;
mbox_sync.length = slave->sii_rx_mailbox_size;
mbox_sync.control_register = 0x22;
mbox_sync.enable = 0x01;
mbox_sync.est_length = 0;
ec_sync_config(&mbox_sync, slave,
datagram->data + EC_SYNC_SIZE * mbox_sync.index);
ec_slave_sync_config(slave, &mbox_sync,
datagram->data + EC_SYNC_SIZE * mbox_sync.index);
}
}
else if (slave->sii_mailbox_protocols) { // mailboxes present
list_for_each_entry(sync, &slave->sii_syncs, list) {
// only configure mailbox sync-managers
if (sync->index != 0 && sync->index != 1) continue;
ec_sync_config(sync, slave,
datagram->data + EC_SYNC_SIZE * sync->index);
ec_slave_sync_config(slave, sync,
datagram->data + EC_SYNC_SIZE * sync->index);
}
}
@ -828,8 +828,8 @@ void ec_fsm_slave_conf_enter_sync2(ec_fsm_slave_t *fsm /**< slave state machine
memset(datagram->data, 0x00, EC_SYNC_SIZE * slave->base_sync_count);
list_for_each_entry(sync, &slave->sii_syncs, list) {
ec_sync_config(sync, slave,
datagram->data + EC_SYNC_SIZE * sync->index);
ec_slave_sync_config(slave, sync,
datagram->data + EC_SYNC_SIZE * sync->index);
}
ec_master_queue_datagram(fsm->slave->master, datagram);
@ -894,8 +894,8 @@ void ec_fsm_slave_conf_enter_fmmu(ec_fsm_slave_t *fsm /**< slave state machine *
0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
memset(datagram->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count);
for (j = 0; j < slave->fmmu_count; j++) {
ec_fmmu_config(&slave->fmmus[j], slave,
datagram->data + EC_FMMU_SIZE * j);
ec_slave_fmmu_config(slave, &slave->fmmus[j],
datagram->data + EC_FMMU_SIZE * j);
}
ec_master_queue_datagram(master, datagram);

View File

@ -855,71 +855,6 @@ static int ec_master_thread(void *data)
/*****************************************************************************/
/**
Initializes a sync manager configuration page with EEPROM data.
The referenced memory (\a data) must be at least EC_SYNC_SIZE bytes.
*/
void ec_sync_config(const ec_sii_sync_t *sync, /**< sync manager */
const ec_slave_t *slave, /**< EtherCAT slave */
uint8_t *data /**> configuration memory */
)
{
size_t sync_size;
sync_size = ec_slave_calc_sync_size(slave, sync);
if (slave->master->debug_level) {
EC_DBG("Slave %3i, SM %i: Addr 0x%04X, Size %3i, Ctrl 0x%02X, En %i\n",
slave->ring_position, sync->index, sync->physical_start_address,
sync_size, sync->control_register, sync->enable);
}
EC_WRITE_U16(data, sync->physical_start_address);
EC_WRITE_U16(data + 2, sync_size);
EC_WRITE_U8 (data + 4, sync->control_register);
EC_WRITE_U8 (data + 5, 0x00); // status byte (read only)
EC_WRITE_U16(data + 6, sync->enable ? 0x0001 : 0x0000); // enable
}
/*****************************************************************************/
/**
Initializes an FMMU configuration page.
The referenced memory (\a data) must be at least EC_FMMU_SIZE bytes.
*/
void ec_fmmu_config(const ec_fmmu_t *fmmu, /**< FMMU */
const ec_slave_t *slave, /**< EtherCAT slave */
uint8_t *data /**> configuration memory */
)
{
size_t sync_size;
sync_size = ec_slave_calc_sync_size(slave, fmmu->sync);
if (slave->master->debug_level) {
EC_DBG("Slave %3i, FMMU %2i:"
" LogAddr 0x%08X, Size %3i, PhysAddr 0x%04X, Dir %s\n",
slave->ring_position, fmmu->index, fmmu->logical_start_address,
sync_size, fmmu->sync->physical_start_address,
((fmmu->sync->control_register & 0x04) ? "out" : "in"));
}
EC_WRITE_U32(data, fmmu->logical_start_address);
EC_WRITE_U16(data + 4, sync_size); // size of fmmu
EC_WRITE_U8 (data + 6, 0x00); // logical start bit
EC_WRITE_U8 (data + 7, 0x07); // logical end bit
EC_WRITE_U16(data + 8, fmmu->sync->physical_start_address);
EC_WRITE_U8 (data + 10, 0x00); // physical start bit
EC_WRITE_U8 (data + 11, ((fmmu->sync->control_register & 0x04)
? 0x02 : 0x01));
EC_WRITE_U16(data + 12, 0x0001); // enable
EC_WRITE_U16(data + 14, 0x0000); // reserved
}
/*****************************************************************************/
/**
Formats master information for SysFS read access.
\return number of bytes written

View File

@ -172,10 +172,6 @@ void ec_master_output_stats(ec_master_t *);
void ec_master_destroy_slaves(ec_master_t *);
void ec_master_calc_addressing(ec_master_t *);
// helper functions
void ec_sync_config(const ec_sii_sync_t *, const ec_slave_t *, uint8_t *);
void ec_fmmu_config(const ec_fmmu_t *, const ec_slave_t *, uint8_t *);
/*****************************************************************************/
#endif

View File

@ -980,6 +980,71 @@ uint16_t ec_slave_calc_sync_size(const ec_slave_t *slave,
/*****************************************************************************/
/**
Initializes a sync manager configuration page with EEPROM data.
The referenced memory (\a data) must be at least EC_SYNC_SIZE bytes.
*/
void ec_slave_sync_config(const ec_slave_t *slave, /**< EtherCAT slave */
const ec_sii_sync_t *sync, /**< sync manager */
uint8_t *data /**> configuration memory */
)
{
size_t sync_size;
sync_size = ec_slave_calc_sync_size(slave, sync);
if (slave->master->debug_level) {
EC_DBG("Slave %3i, SM %i: Addr 0x%04X, Size %3i, Ctrl 0x%02X, En %i\n",
slave->ring_position, sync->index, sync->physical_start_address,
sync_size, sync->control_register, sync->enable);
}
EC_WRITE_U16(data, sync->physical_start_address);
EC_WRITE_U16(data + 2, sync_size);
EC_WRITE_U8 (data + 4, sync->control_register);
EC_WRITE_U8 (data + 5, 0x00); // status byte (read only)
EC_WRITE_U16(data + 6, sync->enable ? 0x0001 : 0x0000); // enable
}
/*****************************************************************************/
/**
Initializes an FMMU configuration page.
The referenced memory (\a data) must be at least EC_FMMU_SIZE bytes.
*/
void ec_slave_fmmu_config(const ec_slave_t *slave, /**< EtherCAT slave */
const ec_fmmu_t *fmmu, /**< FMMU */
uint8_t *data /**> configuration memory */
)
{
size_t sync_size;
sync_size = ec_slave_calc_sync_size(slave, fmmu->sync);
if (slave->master->debug_level) {
EC_DBG("Slave %3i, FMMU %2i:"
" LogAddr 0x%08X, Size %3i, PhysAddr 0x%04X, Dir %s\n",
slave->ring_position, fmmu->index, fmmu->logical_start_address,
sync_size, fmmu->sync->physical_start_address,
((fmmu->sync->control_register & 0x04) ? "out" : "in"));
}
EC_WRITE_U32(data, fmmu->logical_start_address);
EC_WRITE_U16(data + 4, sync_size); // size of fmmu
EC_WRITE_U8 (data + 6, 0x00); // logical start bit
EC_WRITE_U8 (data + 7, 0x07); // logical end bit
EC_WRITE_U16(data + 8, fmmu->sync->physical_start_address);
EC_WRITE_U8 (data + 10, 0x00); // physical start bit
EC_WRITE_U8 (data + 11, ((fmmu->sync->control_register & 0x04)
? 0x02 : 0x01));
EC_WRITE_U16(data + 12, 0x0001); // enable
EC_WRITE_U16(data + 14, 0x0000); // reserved
}
/*****************************************************************************/
/**
\return non-zero if slave is a bus coupler
*/

View File

@ -278,8 +278,10 @@ int ec_slave_fetch_pdo(ec_slave_t *, const uint8_t *, size_t,
int ec_slave_locate_string(ec_slave_t *, unsigned int, char **);
// misc.
uint16_t ec_slave_calc_sync_size(const ec_slave_t *,
const ec_sii_sync_t *);
void ec_slave_sync_config(const ec_slave_t *, const ec_sii_sync_t *,
uint8_t *);
void ec_slave_fmmu_config(const ec_slave_t *, const ec_fmmu_t *, uint8_t *);
uint16_t ec_slave_calc_sync_size(const ec_slave_t *, const ec_sii_sync_t *);
int ec_slave_is_coupler(const ec_slave_t *);
int ec_slave_has_subbus(const ec_slave_t *);