422 ec_fsm_t *fsm = &master->fsm; |
422 ec_fsm_t *fsm = &master->fsm; |
423 ec_datagram_t *datagram = &master->fsm.datagram; |
423 ec_datagram_t *datagram = &master->fsm.datagram; |
424 |
424 |
425 // wait for FSM datagram |
425 // wait for FSM datagram |
426 if (datagram->state == EC_DATAGRAM_SENT) { |
426 if (datagram->state == EC_DATAGRAM_SENT) { |
|
427 // active waiting |
427 while (get_cycles() - datagram->cycles_sent |
428 while (get_cycles() - datagram->cycles_sent |
428 < (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000)) {} |
429 < (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000)); |
429 ecrt_master_receive(master); |
430 ecrt_master_receive(master); |
430 } |
431 } |
431 |
432 |
432 // finish running master FSM |
433 // finish running master FSM |
433 if (ec_fsm_running(fsm)) { |
434 if (ec_fsm_running(fsm)) { |
1505 ec_slave_t *ecrt_master_get_slave(const ec_master_t *master, /**< Master */ |
1506 ec_slave_t *ecrt_master_get_slave(const ec_master_t *master, /**< Master */ |
1506 const char *address /**< address string */ |
1507 const char *address /**< address string */ |
1507 ) |
1508 ) |
1508 { |
1509 { |
1509 unsigned long first, second; |
1510 unsigned long first, second; |
1510 char *remainder, *remainder2; |
1511 char *remainder, *remainder2, original; |
1511 unsigned int alias_requested, alias_found; |
1512 unsigned int alias_requested, alias_found; |
1512 ec_slave_t *alias_slave = NULL, *slave; |
1513 ec_slave_t *alias_slave = NULL, *slave; |
|
1514 |
|
1515 original = address; |
1513 |
1516 |
1514 if (!address || address[0] == 0) return NULL; |
1517 if (!address || address[0] == 0) return NULL; |
1515 |
1518 |
1516 alias_requested = 0; |
1519 alias_requested = 0; |
1517 if (address[0] == '#') { |
1520 if (address[0] == '#') { |
1546 else { |
1549 else { |
1547 list_for_each_entry(slave, &master->slaves, list) { |
1550 list_for_each_entry(slave, &master->slaves, list) { |
1548 if (slave->ring_position == first) return slave; |
1551 if (slave->ring_position == first) return slave; |
1549 } |
1552 } |
1550 EC_ERR("Slave address \"%s\" - Absolute position invalid!\n", |
1553 EC_ERR("Slave address \"%s\" - Absolute position invalid!\n", |
1551 address); |
1554 original); |
1552 } |
1555 } |
1553 } |
1556 } |
1554 else if (remainder[0] == ':') { // field position |
1557 else if (remainder[0] == ':') { // field position |
1555 remainder++; |
1558 remainder++; |
1556 second = simple_strtoul(remainder, &remainder2, 0); |
1559 second = simple_strtoul(remainder, &remainder2, 0); |
1557 |
1560 |
1558 if (remainder2 == remainder) { |
1561 if (remainder2 == remainder) { |
1559 EC_ERR("Slave address \"%s\" - Second number empty!\n", address); |
1562 EC_ERR("Slave address \"%s\" - Second number empty!\n", original); |
1560 return NULL; |
1563 return NULL; |
1561 } |
1564 } |
1562 |
1565 |
1563 if (remainder2[0]) { |
1566 if (remainder2[0]) { |
1564 EC_ERR("Slave address \"%s\" - Invalid trailer!\n", address); |
1567 EC_ERR("Slave address \"%s\" - Invalid trailer!\n", original); |
1565 return NULL; |
1568 return NULL; |
1566 } |
1569 } |
1567 |
1570 |
1568 if (alias_requested) { |
1571 if (alias_requested) { |
1569 if (!ec_slave_is_coupler(alias_slave)) { |
1572 if (!ec_slave_is_coupler(alias_slave)) { |
1570 EC_ERR("Slave address \"%s\": Alias slave must be bus coupler" |
1573 EC_ERR("Slave address \"%s\": Alias slave must be bus coupler" |
1571 " in colon mode.\n", address); |
1574 " in colon mode.\n", original); |
1572 return NULL; |
1575 return NULL; |
1573 } |
1576 } |
1574 list_for_each_entry(slave, &master->slaves, list) { |
1577 list_for_each_entry(slave, &master->slaves, list) { |
1575 if (slave->coupler_index == alias_slave->coupler_index |
1578 if (slave->coupler_index == alias_slave->coupler_index |
1576 && slave->coupler_subindex == second) |
1579 && slave->coupler_subindex == second) |
1577 return slave; |
1580 return slave; |
1578 } |
1581 } |
1579 EC_ERR("Slave address \"%s\" - Bus coupler %i has no %lu. slave" |
1582 EC_ERR("Slave address \"%s\" - Bus coupler %i has no %lu. slave" |
1580 " following!\n", address, alias_slave->ring_position, |
1583 " following!\n", original, alias_slave->ring_position, |
1581 second); |
1584 second); |
1582 return NULL; |
1585 return NULL; |
1583 } |
1586 } |
1584 else { |
1587 else { |
1585 list_for_each_entry(slave, &master->slaves, list) { |
1588 list_for_each_entry(slave, &master->slaves, list) { |