164 |
164 |
165 INIT_LIST_HEAD(&slave->eeprom_strings); |
165 INIT_LIST_HEAD(&slave->eeprom_strings); |
166 INIT_LIST_HEAD(&slave->eeprom_syncs); |
166 INIT_LIST_HEAD(&slave->eeprom_syncs); |
167 INIT_LIST_HEAD(&slave->eeprom_pdos); |
167 INIT_LIST_HEAD(&slave->eeprom_pdos); |
168 INIT_LIST_HEAD(&slave->sdo_dictionary); |
168 INIT_LIST_HEAD(&slave->sdo_dictionary); |
|
169 INIT_LIST_HEAD(&slave->varsize_fields); |
169 |
170 |
170 for (i = 0; i < 4; i++) { |
171 for (i = 0; i < 4; i++) { |
171 slave->dl_link[i] = 0; |
172 slave->dl_link[i] = 0; |
172 slave->dl_loop[i] = 0; |
173 slave->dl_loop[i] = 0; |
173 slave->dl_signal[i] = 0; |
174 slave->dl_signal[i] = 0; |
190 ec_eeprom_sync_t *sync, *next_sync; |
191 ec_eeprom_sync_t *sync, *next_sync; |
191 ec_eeprom_pdo_t *pdo, *next_pdo; |
192 ec_eeprom_pdo_t *pdo, *next_pdo; |
192 ec_eeprom_pdo_entry_t *entry, *next_ent; |
193 ec_eeprom_pdo_entry_t *entry, *next_ent; |
193 ec_sdo_t *sdo, *next_sdo; |
194 ec_sdo_t *sdo, *next_sdo; |
194 ec_sdo_entry_t *en, *next_en; |
195 ec_sdo_entry_t *en, *next_en; |
|
196 ec_varsize_t *var, *next_var; |
195 |
197 |
196 slave = container_of(kobj, ec_slave_t, kobj); |
198 slave = container_of(kobj, ec_slave_t, kobj); |
197 |
199 |
198 // free all string objects |
200 // free all string objects |
199 list_for_each_entry_safe(string, next_str, &slave->eeprom_strings, list) { |
201 list_for_each_entry_safe(string, next_str, &slave->eeprom_strings, list) { |
236 list_for_each_entry_safe(en, next_en, &sdo->entries, list) { |
238 list_for_each_entry_safe(en, next_en, &sdo->entries, list) { |
237 list_del(&en->list); |
239 list_del(&en->list); |
238 kfree(en); |
240 kfree(en); |
239 } |
241 } |
240 kfree(sdo); |
242 kfree(sdo); |
|
243 } |
|
244 |
|
245 // free information about variable sized data fields |
|
246 list_for_each_entry_safe(var, next_var, &slave->varsize_fields, list) { |
|
247 list_del(&var->list); |
|
248 kfree(var); |
241 } |
249 } |
242 |
250 |
243 if (slave->eeprom_data) kfree(slave->eeprom_data); |
251 if (slave->eeprom_data) kfree(slave->eeprom_data); |
244 if (slave->new_eeprom_data) kfree(slave->new_eeprom_data); |
252 if (slave->new_eeprom_data) kfree(slave->new_eeprom_data); |
245 |
253 |
1445 } |
1453 } |
1446 |
1454 |
1447 return -EINVAL; |
1455 return -EINVAL; |
1448 } |
1456 } |
1449 |
1457 |
|
1458 /*****************************************************************************/ |
|
1459 |
|
1460 /** |
|
1461 \return size of sync manager contents |
|
1462 */ |
|
1463 |
|
1464 size_t ec_slave_calc_sync_size(const ec_slave_t *slave, /**< EtherCAT slave */ |
|
1465 const ec_sync_t *sync /**< sync manager */ |
|
1466 ) |
|
1467 { |
|
1468 unsigned int i, found; |
|
1469 const ec_field_t *field; |
|
1470 const ec_varsize_t *var; |
|
1471 size_t size; |
|
1472 |
|
1473 // if size is specified, return size |
|
1474 if (sync->size) return sync->size; |
|
1475 |
|
1476 // sync manager has variable size (size == 0). |
|
1477 |
|
1478 size = 0; |
|
1479 for (i = 0; (field = sync->fields[i]); i++) { |
|
1480 found = 0; |
|
1481 list_for_each_entry(var, &slave->varsize_fields, list) { |
|
1482 if (var->field != field) continue; |
|
1483 size += var->size; |
|
1484 found = 1; |
|
1485 } |
|
1486 |
|
1487 if (!found) { |
|
1488 EC_WARN("Variable data field \"%s\" of slave %i has no size" |
|
1489 " information!\n", field->name, slave->ring_position); |
|
1490 } |
|
1491 } |
|
1492 return size; |
|
1493 } |
|
1494 |
1450 /****************************************************************************** |
1495 /****************************************************************************** |
1451 * Realtime interface |
1496 * Realtime interface |
1452 *****************************************************************************/ |
1497 *****************************************************************************/ |
1453 |
1498 |
1454 /** |
1499 /** |
1464 return ec_slave_sii_write16(slave, 0x0004, alias); |
1509 return ec_slave_sii_write16(slave, 0x0004, alias); |
1465 } |
1510 } |
1466 |
1511 |
1467 /*****************************************************************************/ |
1512 /*****************************************************************************/ |
1468 |
1513 |
|
1514 /** |
|
1515 \return 0 in case of success, else < 0 |
|
1516 \ingroup RealtimeInterface |
|
1517 */ |
|
1518 |
|
1519 int ecrt_slave_field_size(ec_slave_t *slave, /**< EtherCAT slave */ |
|
1520 const char *field_name, /**< data field name */ |
|
1521 unsigned int field_index, /**< data field index */ |
|
1522 size_t size /**< new data field size */ |
|
1523 ) |
|
1524 { |
|
1525 unsigned int i, j, field_counter; |
|
1526 const ec_sync_t *sync; |
|
1527 const ec_field_t *field; |
|
1528 ec_varsize_t *var; |
|
1529 |
|
1530 if (!slave->type) { |
|
1531 EC_ERR("Slave %i has no type information!\n", slave->ring_position); |
|
1532 return -1; |
|
1533 } |
|
1534 |
|
1535 field_counter = 0; |
|
1536 for (i = 0; (sync = slave->type->sync_managers[i]); i++) { |
|
1537 for (j = 0; (field = sync->fields[j]); j++) { |
|
1538 if (!strcmp(field->name, field_name)) { |
|
1539 if (field_counter++ == field_index) { |
|
1540 // is the size of this field variable? |
|
1541 if (field->size) { |
|
1542 EC_ERR("Field \"%s\"[%i] of slave %i has no variable" |
|
1543 " size!\n", field->name, field_index, |
|
1544 slave->ring_position); |
|
1545 return -1; |
|
1546 } |
|
1547 // does a size specification already exist? |
|
1548 list_for_each_entry(var, &slave->varsize_fields, list) { |
|
1549 if (var->field == field) { |
|
1550 EC_WARN("Resizing field \"%s\"[%i] of slave %i.\n", |
|
1551 field->name, field_index, |
|
1552 slave->ring_position); |
|
1553 var->size = size; |
|
1554 return 0; |
|
1555 } |
|
1556 } |
|
1557 // create a new size specification... |
|
1558 if (!(var = kmalloc(sizeof(ec_varsize_t), GFP_KERNEL))) { |
|
1559 EC_ERR("Failed to allocate memory for varsize_t!\n"); |
|
1560 return -1; |
|
1561 } |
|
1562 var->field = field; |
|
1563 var->size = size; |
|
1564 list_add_tail(&var->list, &slave->varsize_fields); |
|
1565 return 0; |
|
1566 } |
|
1567 } |
|
1568 } |
|
1569 } |
|
1570 |
|
1571 EC_ERR("Slave %i (\"%s %s\") has no field \"%s\"[%i]!\n", |
|
1572 slave->ring_position, slave->type->vendor_name, |
|
1573 slave->type->product_name, field_name, field_index); |
|
1574 return -1; |
|
1575 } |
|
1576 |
|
1577 /*****************************************************************************/ |
|
1578 |
1469 /**< \cond */ |
1579 /**< \cond */ |
1470 |
1580 |
1471 EXPORT_SYMBOL(ecrt_slave_write_alias); |
1581 EXPORT_SYMBOL(ecrt_slave_write_alias); |
|
1582 EXPORT_SYMBOL(ecrt_slave_field_size); |
1472 |
1583 |
1473 /**< \endcond */ |
1584 /**< \endcond */ |
1474 |
1585 |
1475 /*****************************************************************************/ |
1586 /*****************************************************************************/ |