master/master.c
changeset 500 f9e6d119463f
parent 496 b2aee2241952
child 502 5f4a2fd3b180
equal deleted inserted replaced
499:fb005e975181 500:f9e6d119463f
   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] == '#') {
  1519         address++;
  1522         address++;
  1520     }
  1523     }
  1521 
  1524 
  1522     first = simple_strtoul(address, &remainder, 0);
  1525     first = simple_strtoul(address, &remainder, 0);
  1523     if (remainder == address) {
  1526     if (remainder == address) {
  1524         EC_ERR("Slave address \"%s\" - First number empty!\n", address);
  1527         EC_ERR("Slave address \"%s\" - First number empty!\n", original);
  1525         return NULL;
  1528         return NULL;
  1526     }
  1529     }
  1527 
  1530 
  1528     if (alias_requested) {
  1531     if (alias_requested) {
  1529         alias_found = 0;
  1532         alias_found = 0;
  1532                 alias_found = 1;
  1535                 alias_found = 1;
  1533                 break;
  1536                 break;
  1534             }
  1537             }
  1535         }
  1538         }
  1536         if (!alias_found) {
  1539         if (!alias_found) {
  1537             EC_ERR("Slave address \"%s\" - Alias not found!\n", address);
  1540             EC_ERR("Slave address \"%s\" - Alias not found!\n", original);
  1538             return NULL;
  1541             return NULL;
  1539         }
  1542         }
  1540     }
  1543     }
  1541 
  1544 
  1542     if (!remainder[0]) { // absolute position
  1545     if (!remainder[0]) { // absolute position
  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) {
  1587                     && slave->coupler_subindex == second) return slave;
  1590                     && slave->coupler_subindex == second) return slave;
  1588             }
  1591             }
  1589         }
  1592         }
  1590     }
  1593     }
  1591     else
  1594     else
  1592         EC_ERR("Slave address \"%s\" - Invalid format!\n", address);
  1595         EC_ERR("Slave address \"%s\" - Invalid format!\n", original);
  1593 
  1596 
  1594     return NULL;
  1597     return NULL;
  1595 }
  1598 }
  1596 
  1599 
  1597 /*****************************************************************************/
  1600 /*****************************************************************************/