master/master.c
changeset 1942 cd6ff5adae84
parent 1939 1ba48f78a0a5
child 1947 024a3c6aa3f7
equal deleted inserted replaced
1941:e12266a4f473 1942:cd6ff5adae84
   437     }
   437     }
   438 }
   438 }
   439 
   439 
   440 /*****************************************************************************/
   440 /*****************************************************************************/
   441 
   441 
       
   442 /** Clear the configuration applied by the application.
       
   443  */
       
   444 void ec_master_clear_config(
       
   445         ec_master_t *master /**< EtherCAT master. */
       
   446         )
       
   447 {
       
   448     down(&master->master_sem);
       
   449     ec_master_clear_domains(master);
       
   450     ec_master_clear_slave_configs(master);
       
   451     up(&master->master_sem);
       
   452 }
       
   453 
       
   454 /*****************************************************************************/
       
   455 
   442 /** Internal sending callback.
   456 /** Internal sending callback.
   443  */
   457  */
   444 void ec_master_internal_send_cb(
   458 void ec_master_internal_send_cb(
   445         void *cb_data /**< Callback data. */
   459         void *cb_data /**< Callback data. */
   446         )
   460         )
   651  */
   665  */
   652 void ec_master_leave_operation_phase(
   666 void ec_master_leave_operation_phase(
   653         ec_master_t *master /**< EtherCAT master */
   667         ec_master_t *master /**< EtherCAT master */
   654         )
   668         )
   655 {
   669 {
   656     if (master->active)
   670     if (master->active) {
   657         ecrt_master_deactivate(master);
   671         ecrt_master_deactivate(master); // also clears config
       
   672     } else {
       
   673         ec_master_clear_config(master);
       
   674     }
   658 
   675 
   659     EC_MASTER_DBG(master, 1, "OPERATION -> IDLE.\n");
   676     EC_MASTER_DBG(master, 1, "OPERATION -> IDLE.\n");
   660 
   677 
   661     master->phase = EC_IDLE;
   678     master->phase = EC_IDLE;
   662 }
   679 }
   663 
       
   664 
   680 
   665 /*****************************************************************************/
   681 /*****************************************************************************/
   666 
   682 
   667 /** Injects external datagrams that fit into the datagram queue.
   683 /** Injects external datagrams that fit into the datagram queue.
   668  */
   684  */
  1987 #ifdef EC_EOE
  2003 #ifdef EC_EOE
  1988     ec_eoe_t *eoe;
  2004     ec_eoe_t *eoe;
  1989     int eoe_was_running;
  2005     int eoe_was_running;
  1990 #endif
  2006 #endif
  1991 
  2007 
  1992     EC_MASTER_DBG(master, 1, "ecrt_master_deactivate(master = 0x%p)\n",
  2008     EC_MASTER_DBG(master, 1, "%s(master = 0x%p)\n", __func__, master);
  1993             master);
       
  1994 
  2009 
  1995     if (!master->active) {
  2010     if (!master->active) {
  1996         EC_MASTER_WARN(master, "%s: Master not active.\n", __func__);
  2011         EC_MASTER_WARN(master, "%s: Master not active.\n", __func__);
  1997         return;
  2012         return;
  1998     }
  2013     }
  2005     
  2020     
  2006     master->send_cb = ec_master_internal_send_cb;
  2021     master->send_cb = ec_master_internal_send_cb;
  2007     master->receive_cb = ec_master_internal_receive_cb;
  2022     master->receive_cb = ec_master_internal_receive_cb;
  2008     master->cb_data = master;
  2023     master->cb_data = master;
  2009     
  2024     
  2010     down(&master->master_sem);
  2025     ec_master_clear_config(master);
  2011     ec_master_clear_domains(master);
       
  2012     ec_master_clear_slave_configs(master);
       
  2013     up(&master->master_sem);
       
  2014 
  2026 
  2015     for (slave = master->slaves;
  2027     for (slave = master->slaves;
  2016             slave < master->slaves + master->slave_count;
  2028             slave < master->slaves + master->slave_count;
  2017             slave++) {
  2029             slave++) {
  2018 
  2030