master/master.c
branchstable-1.5
changeset 2115 2ec1239216e5
parent 2114 b91bb9b96823
child 2124 c4afc5fede19
equal deleted inserted replaced
2114:b91bb9b96823 2115:2ec1239216e5
   156     master->allow_scan = 1;
   156     master->allow_scan = 1;
   157     sema_init(&master->scan_sem, 1);
   157     sema_init(&master->scan_sem, 1);
   158     init_waitqueue_head(&master->scan_queue);
   158     init_waitqueue_head(&master->scan_queue);
   159 
   159 
   160     master->config_busy = 0;
   160     master->config_busy = 0;
   161     master->allow_config = 1;
       
   162     sema_init(&master->config_sem, 1);
   161     sema_init(&master->config_sem, 1);
   163     init_waitqueue_head(&master->config_queue);
   162     init_waitqueue_head(&master->config_queue);
   164     
   163     
   165     INIT_LIST_HEAD(&master->datagram_queue);
   164     INIT_LIST_HEAD(&master->datagram_queue);
   166     master->datagram_index = 0;
   165     master->datagram_index = 0;
   592 #endif
   591 #endif
   593 
   592 
   594     EC_MASTER_DBG(master, 1, "IDLE -> OPERATION.\n");
   593     EC_MASTER_DBG(master, 1, "IDLE -> OPERATION.\n");
   595 
   594 
   596     down(&master->config_sem);
   595     down(&master->config_sem);
   597     master->allow_config = 0; // temporarily disable slave configuration
       
   598     if (master->config_busy) {
   596     if (master->config_busy) {
   599         up(&master->config_sem);
   597         up(&master->config_sem);
   600 
   598 
   601         // wait for slave configuration to complete
   599         // wait for slave configuration to complete
   602         ret = wait_event_interruptible(master->config_queue,
   600         ret = wait_event_interruptible(master->config_queue,
   653     master->app_cb_data = NULL;
   651     master->app_cb_data = NULL;
   654     return ret;
   652     return ret;
   655     
   653     
   656 out_allow:
   654 out_allow:
   657     master->allow_scan = 1;
   655     master->allow_scan = 1;
   658     master->allow_config = 1;
       
   659     return ret;
   656     return ret;
   660 }
   657 }
   661 
   658 
   662 /*****************************************************************************/
   659 /*****************************************************************************/
   663 
   660 
  2011     if (ret < 0) {
  2008     if (ret < 0) {
  2012         EC_MASTER_ERR(master, "Failed to start master thread!\n");
  2009         EC_MASTER_ERR(master, "Failed to start master thread!\n");
  2013         return ret;
  2010         return ret;
  2014     }
  2011     }
  2015 
  2012 
  2016     master->allow_config = 1; // request the current configuration
       
  2017     master->allow_scan = 1; // allow re-scanning on topology change
  2013     master->allow_scan = 1; // allow re-scanning on topology change
  2018     master->active = 1;
  2014     master->active = 1;
  2019 
  2015 
  2020     // notify state machine, that the configuration shall now be applied
  2016     // notify state machine, that the configuration shall now be applied
  2021     master->config_changed = 1;
  2017     master->config_changed = 1;
  2085     if (ec_master_thread_start(master, ec_master_idle_thread,
  2081     if (ec_master_thread_start(master, ec_master_idle_thread,
  2086                 "EtherCAT-IDLE"))
  2082                 "EtherCAT-IDLE"))
  2087         EC_MASTER_WARN(master, "Failed to restart master thread!\n");
  2083         EC_MASTER_WARN(master, "Failed to restart master thread!\n");
  2088 
  2084 
  2089     master->allow_scan = 1;
  2085     master->allow_scan = 1;
  2090     master->allow_config = 1;
       
  2091     master->active = 0;
  2086     master->active = 0;
  2092 }
  2087 }
  2093 
  2088 
  2094 /*****************************************************************************/
  2089 /*****************************************************************************/
  2095 
  2090