master/master.c
changeset 1530 96629de2202b
parent 1516 e3b09f847512
child 1535 0c484ee12d89
equal deleted inserted replaced
1529:079de3453c92 1530:96629de2202b
   119     master->main_mac = main_mac;
   119     master->main_mac = main_mac;
   120     master->backup_mac = backup_mac;
   120     master->backup_mac = backup_mac;
   121     init_MUTEX(&master->device_sem);
   121     init_MUTEX(&master->device_sem);
   122 
   122 
   123     master->phase = EC_ORPHANED;
   123     master->phase = EC_ORPHANED;
       
   124     master->active = 0;
   124     master->injection_seq_fsm = 0;
   125     master->injection_seq_fsm = 0;
   125     master->injection_seq_rt = 0;
   126     master->injection_seq_rt = 0;
   126 
   127 
   127     master->slaves = NULL;
   128     master->slaves = NULL;
   128     master->slave_count = 0;
   129     master->slave_count = 0;
   590 
   591 
   591 /*****************************************************************************/
   592 /*****************************************************************************/
   592 
   593 
   593 /** Transition function from OPERATION to IDLE phase.
   594 /** Transition function from OPERATION to IDLE phase.
   594  */
   595  */
   595 void ec_master_leave_operation_phase(ec_master_t *master
   596 void ec_master_leave_operation_phase(
   596                                     /**< EtherCAT master */)
   597         ec_master_t *master /**< EtherCAT master */
   597 {
   598         )
   598     ec_slave_t *slave;
   599 {
   599 #ifdef EC_EOE
   600     if (master->active)
   600     ec_eoe_t *eoe;
   601         ecrt_master_deactivate(master);
   601 #endif
       
   602 
   602 
   603     if (master->debug_level)
   603     if (master->debug_level)
   604         EC_DBG("OPERATION -> IDLE.\n");
   604         EC_DBG("OPERATION -> IDLE.\n");
   605 
   605 
   606     master->phase = EC_IDLE;
   606     master->phase = EC_IDLE;
   607 
       
   608 #ifdef EC_EOE
       
   609     ec_master_eoe_stop(master);
       
   610 #endif
       
   611     ec_master_thread_stop(master);
       
   612     
       
   613     master->send_cb = ec_master_internal_send_cb;
       
   614     master->receive_cb = ec_master_internal_receive_cb;
       
   615     master->cb_data = master;
       
   616     
       
   617     down(&master->master_sem);
       
   618     ec_master_clear_domains(master);
       
   619     ec_master_clear_slave_configs(master);
       
   620     up(&master->master_sem);
       
   621 
       
   622     for (slave = master->slaves;
       
   623             slave < master->slaves + master->slave_count;
       
   624             slave++) {
       
   625 
       
   626         // set states for all slaves
       
   627         ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
       
   628 
       
   629         // mark for reconfiguration, because the master could have no
       
   630         // possibility for a reconfiguration between two sequential operation
       
   631         // phases.
       
   632         slave->force_config = 1;
       
   633     }
       
   634 
       
   635 #ifdef EC_EOE
       
   636     // ... but leave EoE slaves in OP
       
   637     list_for_each_entry(eoe, &master->eoe_handlers, list) {
       
   638         if (ec_eoe_is_open(eoe))
       
   639             ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
       
   640     }
       
   641 #endif
       
   642 
       
   643     master->app_time = 0ULL;
       
   644     master->app_start_time = 0ULL;
       
   645     master->has_start_time = 0;
       
   646 
       
   647     if (ec_master_thread_start(master, ec_master_idle_thread,
       
   648                 "EtherCAT-IDLE"))
       
   649         EC_WARN("Failed to restart master thread!\n");
       
   650 #ifdef EC_EOE
       
   651     ec_master_eoe_start(master);
       
   652 #endif
       
   653 
       
   654     master->allow_scan = 1;
       
   655     master->allow_config = 1;
       
   656 }
   607 }
   657 
   608 
   658 /*****************************************************************************/
   609 /*****************************************************************************/
   659 
   610 
   660 /** Places a datagram in the datagram queue.
   611 /** Places a datagram in the datagram queue.
  1633     int ret;
  1584     int ret;
  1634 
  1585 
  1635     if (master->debug_level)
  1586     if (master->debug_level)
  1636         EC_DBG("ecrt_master_activate(master = 0x%x)\n", (u32) master);
  1587         EC_DBG("ecrt_master_activate(master = 0x%x)\n", (u32) master);
  1637 
  1588 
       
  1589     if (master->active) {
       
  1590         EC_WARN("%s: Master already active!\n", __func__);
       
  1591         return 0;
       
  1592     }
       
  1593 
  1638     down(&master->master_sem);
  1594     down(&master->master_sem);
  1639 
  1595 
  1640     // finish all domains
  1596     // finish all domains
  1641     domain_offset = 0;
  1597     domain_offset = 0;
  1642     list_for_each_entry(domain, &master->domains, list) {
  1598     list_for_each_entry(domain, &master->domains, list) {
  1682     ec_master_eoe_start(master);
  1638     ec_master_eoe_start(master);
  1683 #endif
  1639 #endif
  1684 
  1640 
  1685     master->allow_config = 1; // request the current configuration
  1641     master->allow_config = 1; // request the current configuration
  1686     master->allow_scan = 1; // allow re-scanning on topology change
  1642     master->allow_scan = 1; // allow re-scanning on topology change
       
  1643     master->active = 1;
  1687     return 0;
  1644     return 0;
       
  1645 }
       
  1646 
       
  1647 /*****************************************************************************/
       
  1648 
       
  1649 void ecrt_master_deactivate(ec_master_t *master)
       
  1650 {
       
  1651     ec_slave_t *slave;
       
  1652 #ifdef EC_EOE
       
  1653     ec_eoe_t *eoe;
       
  1654 #endif
       
  1655 
       
  1656     if (master->debug_level)
       
  1657         EC_DBG("ecrt_master_deactivate(master = 0x%x)\n", (u32) master);
       
  1658 
       
  1659     if (!master->active) {
       
  1660         EC_WARN("%s: Master not active.\n", __func__);
       
  1661         return;
       
  1662     }
       
  1663 
       
  1664 #ifdef EC_EOE
       
  1665     ec_master_eoe_stop(master);
       
  1666 #endif
       
  1667     ec_master_thread_stop(master);
       
  1668     
       
  1669     master->send_cb = ec_master_internal_send_cb;
       
  1670     master->receive_cb = ec_master_internal_receive_cb;
       
  1671     master->cb_data = master;
       
  1672     
       
  1673     down(&master->master_sem);
       
  1674     ec_master_clear_domains(master);
       
  1675     ec_master_clear_slave_configs(master);
       
  1676     up(&master->master_sem);
       
  1677 
       
  1678     for (slave = master->slaves;
       
  1679             slave < master->slaves + master->slave_count;
       
  1680             slave++) {
       
  1681 
       
  1682         // set states for all slaves
       
  1683         ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
       
  1684 
       
  1685         // mark for reconfiguration, because the master could have no
       
  1686         // possibility for a reconfiguration between two sequential operation
       
  1687         // phases.
       
  1688         slave->force_config = 1;
       
  1689     }
       
  1690 
       
  1691 #ifdef EC_EOE
       
  1692     // ... but leave EoE slaves in OP
       
  1693     list_for_each_entry(eoe, &master->eoe_handlers, list) {
       
  1694         if (ec_eoe_is_open(eoe))
       
  1695             ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
       
  1696     }
       
  1697 #endif
       
  1698 
       
  1699     master->app_time = 0ULL;
       
  1700     master->app_start_time = 0ULL;
       
  1701     master->has_start_time = 0;
       
  1702 
       
  1703     if (ec_master_thread_start(master, ec_master_idle_thread,
       
  1704                 "EtherCAT-IDLE"))
       
  1705         EC_WARN("Failed to restart master thread!\n");
       
  1706 #ifdef EC_EOE
       
  1707     ec_master_eoe_start(master);
       
  1708 #endif
       
  1709 
       
  1710     master->allow_scan = 1;
       
  1711     master->allow_config = 1;
       
  1712     master->active = 0;
  1688 }
  1713 }
  1689 
  1714 
  1690 /*****************************************************************************/
  1715 /*****************************************************************************/
  1691 
  1716 
  1692 void ecrt_master_send(ec_master_t *master)
  1717 void ecrt_master_send(ec_master_t *master)
  1901 
  1926 
  1902 /** \cond */
  1927 /** \cond */
  1903 
  1928 
  1904 EXPORT_SYMBOL(ecrt_master_create_domain);
  1929 EXPORT_SYMBOL(ecrt_master_create_domain);
  1905 EXPORT_SYMBOL(ecrt_master_activate);
  1930 EXPORT_SYMBOL(ecrt_master_activate);
       
  1931 EXPORT_SYMBOL(ecrt_master_deactivate);
  1906 EXPORT_SYMBOL(ecrt_master_send);
  1932 EXPORT_SYMBOL(ecrt_master_send);
  1907 EXPORT_SYMBOL(ecrt_master_send_ext);
  1933 EXPORT_SYMBOL(ecrt_master_send_ext);
  1908 EXPORT_SYMBOL(ecrt_master_receive);
  1934 EXPORT_SYMBOL(ecrt_master_receive);
  1909 EXPORT_SYMBOL(ecrt_master_callbacks);
  1935 EXPORT_SYMBOL(ecrt_master_callbacks);
  1910 EXPORT_SYMBOL(ecrt_master_slave_config);
  1936 EXPORT_SYMBOL(ecrt_master_slave_config);