From 1e696ced3df33216007f128c42625539c5ac0cf6 Mon Sep 17 00:00:00 2001 From: Florian Pose <fp@igh-essen.com> Date: Tue, 19 Feb 2008 09:58:48 +0000 Subject: [PATCH] Allow bus configuration when link is down. --- examples/mini/mini.c | 2 +- master/fsm_master.c | 2 ++ master/master.c | 39 +++++++++++++++++++++++---------------- master/module.c | 5 ----- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/examples/mini/mini.c b/examples/mini/mini.c index 93373a22..df6ce92b 100644 --- a/examples/mini/mini.c +++ b/examples/mini/mini.c @@ -86,7 +86,7 @@ static uint8_t off_ana_out; const static ec_pdo_entry_reg_t domain1_regs[] = { {0, 1, Beckhoff_EL3162, 0x3101, 2, &off_ana_in}, - {0, 2, Beckhoff_EL4102, 0x3001, 1, &off_ana_out}, + //{0, 2, Beckhoff_EL4102, 0x3001, 1, &off_ana_out}, {} }; #endif diff --git a/master/fsm_master.c b/master/fsm_master.c index 70b5e98a..fd20a004 100644 --- a/master/fsm_master.c +++ b/master/fsm_master.c @@ -845,6 +845,8 @@ void ec_fsm_master_state_clear_addresses( if (datagram->state != EC_DATAGRAM_RECEIVED) { EC_ERR("Failed to receive address clearing datagram (state %i).\n", datagram->state); + master->scan_state = EC_REQUEST_FAILURE; + wake_up_interruptible(&master->scan_queue); fsm->state = ec_fsm_master_state_error; return; } diff --git a/master/master.c b/master/master.c index 19b59324..52e351d7 100644 --- a/master/master.c +++ b/master/master.c @@ -126,7 +126,7 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */ INIT_LIST_HEAD(&master->configs); - master->scan_state = EC_REQUEST_IN_PROGRESS; + master->scan_state = EC_REQUEST_COMPLETE; master->allow_scan = 1; init_MUTEX(&master->scan_sem); init_waitqueue_head(&master->scan_queue); @@ -454,15 +454,20 @@ int ec_master_enter_operation_mode(ec_master_t *master /**< EtherCAT master */) if (master->debug_level) EC_DBG("Waiting for pending slave configuration returned.\n"); + if (master->debug_level) + EC_DBG("Disable scanning, current scan state: %u\n", + master->scan_state); down(&master->scan_sem); master->allow_scan = 0; // 'lock' the slave list up(&master->scan_sem); - // wait for slave scan to complete - if (wait_event_interruptible(master->scan_queue, - master->scan_state != EC_REQUEST_IN_PROGRESS)) { - EC_INFO("Waiting for slave scan interrupted by signal.\n"); - goto out_allow; + if (master->scan_state == EC_REQUEST_IN_PROGRESS) { + // wait for slave scan to complete + if (wait_event_interruptible(master->scan_queue, + master->scan_state != EC_REQUEST_IN_PROGRESS)) { + EC_INFO("Waiting for slave scan interrupted by signal.\n"); + goto out_allow; + } } if (master->debug_level) @@ -1347,19 +1352,21 @@ int ecrt_master_activate(ec_master_t *master) // request slave configuration down(&master->config_sem); master->allow_config = 1; // request the current configuration - master->config_state = EC_REQUEST_IN_PROGRESS; up(&master->config_sem); - // wait for configuration to complete - if (wait_event_interruptible(master->config_queue, - master->config_state != EC_REQUEST_IN_PROGRESS)) { - EC_INFO("Waiting for configuration interrupted by signal.\n"); - return -1; - } + if (master->main_device.link_state) { + // wait for configuration to complete + master->config_state = EC_REQUEST_IN_PROGRESS; + if (wait_event_interruptible(master->config_queue, + master->config_state != EC_REQUEST_IN_PROGRESS)) { + EC_INFO("Waiting for configuration interrupted by signal.\n"); + return -1; + } - if (master->config_state != EC_REQUEST_COMPLETE) { - EC_ERR("Failed to configure slaves.\n"); - return -1; + if (master->config_state != EC_REQUEST_COMPLETE) { + EC_ERR("Failed to configure slaves.\n"); + return -1; + } } // restart EoE process and master thread with new locking diff --git a/master/module.c b/master/module.c index e7310efa..f52bb2b2 100644 --- a/master/module.c +++ b/master/module.c @@ -577,11 +577,6 @@ ec_master_t *ecrt_request_master(unsigned int master_index) up(&master->device_sem); - if (!master->main_device.link_state) { - EC_ERR("Link is DOWN.\n"); - goto out_module_put; - } - if (ec_master_enter_operation_mode(master)) { EC_ERR("Failed to enter OPERATION mode!\n"); goto out_module_put; -- GitLab