master/master.c
changeset 2117 afb40fd6018e
parent 2116 1448a40b5af5
child 2150 5144a4bc6184
equal deleted inserted replaced
2116:1448a40b5af5 2117:afb40fd6018e
   159     master->dc_jiffies_app_start_time = 0;
   159     master->dc_jiffies_app_start_time = 0;
   160     master->app_start_time = 0ULL;
   160     master->app_start_time = 0ULL;
   161     master->has_app_time = 0;
   161     master->has_app_time = 0;
   162 
   162 
   163     master->scan_busy = 0;
   163     master->scan_busy = 0;
   164     master->allow_scan = 1;
       
   165     ec_mutex_init(&master->scan_mutex);
   164     ec_mutex_init(&master->scan_mutex);
   166     init_waitqueue_head(&master->scan_queue);
   165     init_waitqueue_head(&master->scan_queue);
   167 
   166 
   168     master->config_busy = 0;
   167     master->config_busy = 0;
   169     master->allow_config = 1;
       
   170     ec_mutex_init(&master->config_mutex);
   168     ec_mutex_init(&master->config_mutex);
   171     init_waitqueue_head(&master->config_queue);
   169     init_waitqueue_head(&master->config_queue);
   172     
   170     
   173     INIT_LIST_HEAD(&master->datagram_queue);
   171     INIT_LIST_HEAD(&master->datagram_queue);
   174     master->datagram_index = 0;
   172     master->datagram_index = 0;
   581 #endif
   579 #endif
   582 
   580 
   583     EC_MASTER_DBG(master, 1, "IDLE -> OPERATION.\n");
   581     EC_MASTER_DBG(master, 1, "IDLE -> OPERATION.\n");
   584 
   582 
   585     ec_mutex_lock(&master->config_mutex);
   583     ec_mutex_lock(&master->config_mutex);
   586     master->allow_config = 0; // temporarily disable slave configuration
       
   587     if (master->config_busy) {
   584     if (master->config_busy) {
   588         ec_mutex_unlock(&master->config_mutex);
   585         ec_mutex_unlock(&master->config_mutex);
   589 
   586 
   590         // wait for slave configuration to complete
   587         // wait for slave configuration to complete
   591         ret = wait_event_interruptible(master->config_queue,
   588         ret = wait_event_interruptible(master->config_queue,
   642     master->app_fsm_queue_locking_data = NULL;
   639     master->app_fsm_queue_locking_data = NULL;
   643     return ret;
   640     return ret;
   644     
   641     
   645 out_allow:
   642 out_allow:
   646     master->allow_scan = 1;
   643     master->allow_scan = 1;
   647     master->allow_config = 1;
       
   648     return ret;
   644     return ret;
   649 }
   645 }
   650 
   646 
   651 /*****************************************************************************/
   647 /*****************************************************************************/
   652 
   648 
  2032     if (ret < 0) {
  2028     if (ret < 0) {
  2033         EC_MASTER_ERR(master, "Failed to start master thread!\n");
  2029         EC_MASTER_ERR(master, "Failed to start master thread!\n");
  2034         return ret;
  2030         return ret;
  2035     }
  2031     }
  2036 
  2032 
  2037     master->allow_config = 1; // request the current configuration
       
  2038     master->allow_scan = 1; // allow re-scanning on topology change
  2033     master->allow_scan = 1; // allow re-scanning on topology change
  2039     master->active = 1;
  2034     master->active = 1;
  2040 
  2035 
  2041     // notify state machine, that the configuration shall now be applied
  2036     // notify state machine, that the configuration shall now be applied
  2042     master->config_changed = 1;
  2037     master->config_changed = 1;
  2105     if (ec_master_thread_start(master, ec_master_idle_thread,
  2100     if (ec_master_thread_start(master, ec_master_idle_thread,
  2106                 "EtherCAT-IDLE"))
  2101                 "EtherCAT-IDLE"))
  2107         EC_MASTER_WARN(master, "Failed to restart master thread!\n");
  2102         EC_MASTER_WARN(master, "Failed to restart master thread!\n");
  2108 
  2103 
  2109     master->allow_scan = 1;
  2104     master->allow_scan = 1;
  2110     master->allow_config = 1;
       
  2111     master->active = 0;
  2105     master->active = 0;
  2112 }
  2106 }
  2113 
  2107 
  2114 /*****************************************************************************/
  2108 /*****************************************************************************/
  2115 
  2109