diff --git a/master/fsm_coe_map.c b/master/fsm_coe_map.c index afd1ab28e3b0af673fbe33876a2fd0b446802405..84a83645abe5b4a2d61ac679e327925b070821c7 100644 --- a/master/fsm_coe_map.c +++ b/master/fsm_coe_map.c @@ -179,7 +179,7 @@ void ec_fsm_coe_map_action_next_dir( ec_pdo_mapping_clear_pdos(&fsm->mapping); - ec_sdo_request_init(&fsm->request, slave, fsm->sync_sdo_index, 0); + ec_sdo_request_init(&fsm->request, fsm->sync_sdo_index, 0); fsm->state = ec_fsm_coe_map_state_pdo_count; ec_fsm_coe_upload(fsm->fsm_coe, fsm->slave, &fsm->request); ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately @@ -233,8 +233,8 @@ void ec_fsm_coe_map_action_next_pdo( ) { if (fsm->sync_subindex <= fsm->sync_subindices) { - ec_sdo_request_init(&fsm->request, fsm->slave, - fsm->sync_sdo_index, fsm->sync_subindex); + ec_sdo_request_init(&fsm->request, fsm->sync_sdo_index, + fsm->sync_subindex); fsm->state = ec_fsm_coe_map_state_pdo; ec_fsm_coe_upload(fsm->fsm_coe, fsm->slave, &fsm->request); ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately @@ -290,7 +290,7 @@ void ec_fsm_coe_map_state_pdo( list_add_tail(&fsm->pdo->list, &fsm->mapping.pdos); - ec_sdo_request_init(&fsm->request, fsm->slave, fsm->pdo->index, 0); + ec_sdo_request_init(&fsm->request, fsm->pdo->index, 0); fsm->state = ec_fsm_coe_map_state_pdo_entry_count; ec_fsm_coe_upload(fsm->fsm_coe, fsm->slave, &fsm->request); ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately @@ -336,8 +336,7 @@ void ec_fsm_coe_map_action_next_pdo_entry( ) { if (fsm->pdo_subindex <= fsm->pdo_subindices) { - ec_sdo_request_init(&fsm->request, fsm->slave, - fsm->pdo->index, fsm->pdo_subindex); + ec_sdo_request_init(&fsm->request, fsm->pdo->index, fsm->pdo_subindex); fsm->state = ec_fsm_coe_map_state_pdo_entry; ec_fsm_coe_upload(fsm->fsm_coe, fsm->slave, &fsm->request); ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately diff --git a/master/fsm_master.c b/master/fsm_master.c index 1d1cc2d678e28dcf3c44ade9687293ab0dc69518..4c383d628ff8a3230b4aab15eb240047fb47c10b 100644 --- a/master/fsm_master.c +++ b/master/fsm_master.c @@ -44,6 +44,7 @@ #ifdef EC_EOE #include "ethernet.h" #endif + #include "fsm_master.h" /*****************************************************************************/ @@ -370,45 +371,44 @@ int ec_fsm_master_action_process_sdo( ) { ec_master_t *master = fsm->master; - ec_sdo_request_t *request; + ec_master_sdo_request_t *request; ec_slave_t *slave; // search the first request to be processed while (1) { down(&master->sdo_sem); - if (list_empty(&master->sdo_requests)) { + if (list_empty(&master->slave_sdo_requests)) { up(&master->sdo_sem); break; } // get first request - request = - list_entry(master->sdo_requests.next, ec_sdo_request_t, list); + request = list_entry(master->slave_sdo_requests.next, + ec_master_sdo_request_t, list); list_del_init(&request->list); // dequeue - request->state = EC_REQUEST_IN_PROGRESS; + request->req.state = EC_REQUEST_IN_PROGRESS; up(&master->sdo_sem); slave = request->slave; if (slave->current_state == EC_SLAVE_STATE_INIT || slave->online_state == EC_SLAVE_OFFLINE || slave->error_flag) { - EC_ERR("Discarding Sdo request, slave %i not ready.\n", + EC_ERR("Discarding Sdo request, slave %u not ready.\n", slave->ring_position); - request->state = EC_REQUEST_FAILURE; + request->req.state = EC_REQUEST_FAILURE; wake_up(&master->sdo_queue); continue; } - // found pending Sdo request. execute it! + // Found pending Sdo request. Execute it! if (master->debug_level) EC_DBG("Processing Sdo request for slave %i...\n", slave->ring_position); - // start uploading Sdo + // Start uploading Sdo fsm->idle = 0; - fsm->slave = slave; fsm->sdo_request = request; fsm->state = ec_fsm_master_state_sdo_request; - ec_fsm_coe_upload(&fsm->fsm_coe, slave, fsm->sdo_request); + ec_fsm_coe_upload(&fsm->fsm_coe, slave, &request->req); ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately return 1; } @@ -1022,21 +1022,21 @@ void ec_fsm_master_state_sdodict(ec_fsm_master_t *fsm /**< master state machine void ec_fsm_master_state_sdo_request(ec_fsm_master_t *fsm /**< master state machine */) { ec_master_t *master = fsm->master; - ec_sdo_request_t *request = fsm->sdo_request; + ec_master_sdo_request_t *request = fsm->sdo_request; if (ec_fsm_coe_exec(&fsm->fsm_coe)) return; if (!ec_fsm_coe_success(&fsm->fsm_coe)) { EC_DBG("Failed to process Sdo request for slave %i.\n", fsm->slave->ring_position); - request->state = EC_REQUEST_FAILURE; + request->req.state = EC_REQUEST_FAILURE; wake_up(&master->sdo_queue); fsm->state = ec_fsm_master_state_error; return; } // Sdo request finished - request->state = EC_REQUEST_COMPLETE; + request->req.state = EC_REQUEST_COMPLETE; wake_up(&master->sdo_queue); if (master->debug_level) diff --git a/master/fsm_master.h b/master/fsm_master.h index f7e16bc4817b611bb51c91a8134974d272992940..b844023b9d4a2b23ad46b2679cbf2d95126bf174 100644 --- a/master/fsm_master.h +++ b/master/fsm_master.h @@ -65,6 +65,16 @@ typedef struct { /*****************************************************************************/ +/** Slave/Sdo request record for master's Sdo request list. + */ +typedef struct { + struct list_head list; /**< List element. */ + ec_slave_t *slave; /**< Slave. */ + ec_sdo_request_t req; /**< Sdo request. */ +} ec_master_sdo_request_t; + +/*****************************************************************************/ + typedef struct ec_fsm_master ec_fsm_master_t; /**< \see ec_fsm_master */ /** Finite state machine of an EtherCAT master. @@ -87,7 +97,7 @@ struct ec_fsm_master { ec_slave_t *slave; /**< current slave */ ec_eeprom_write_request_t *eeprom_request; /**< EEPROM write request */ off_t eeprom_index; /**< index to EEPROM write request data */ - ec_sdo_request_t *sdo_request; /**< Sdo request to process */ + ec_master_sdo_request_t *sdo_request; /**< Sdo request to process. */ ec_fsm_slave_config_t fsm_slave_config; /**< slave state machine */ ec_fsm_slave_scan_t fsm_slave_scan; /**< slave state machine */ diff --git a/master/master.c b/master/master.c index a71cdc25d898137379dba442f63c4e26d8cc1e07..050079b2115ebdedc6ddaf7e64f7b2524088162f 100644 --- a/master/master.c +++ b/master/master.c @@ -175,7 +175,7 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */ init_MUTEX(&master->eeprom_sem); init_waitqueue_head(&master->eeprom_queue); - INIT_LIST_HEAD(&master->sdo_requests); + INIT_LIST_HEAD(&master->slave_sdo_requests); init_MUTEX(&master->sdo_sem); init_waitqueue_head(&master->sdo_queue); diff --git a/master/master.h b/master/master.h index 94db916164b0d3ac027f70d511950043c2b0177e..c15758df2bbc80c9a3d128870f54e09882a8b817 100644 --- a/master/master.h +++ b/master/master.h @@ -59,8 +59,7 @@ typedef enum { EC_MASTER_MODE_ORPHANED, EC_MASTER_MODE_IDLE, EC_MASTER_MODE_OPERATION -} -ec_master_mode_t; +} ec_master_mode_t; /*****************************************************************************/ @@ -72,8 +71,7 @@ typedef struct { unsigned int unmatched; /**< unmatched datagrams (received, but not queued any longer) */ unsigned long output_jiffies; /**< time of last output */ -} -ec_stats_t; +} ec_stats_t; /*****************************************************************************/ @@ -81,8 +79,7 @@ ec_stats_t; * * Manages slaves, domains and IO. */ -struct ec_master -{ +struct ec_master { struct kobject kobj; /**< kobject */ unsigned int index; /**< master index */ unsigned int reserved; /**< non-zero, if the master is reserved for RT */ @@ -161,7 +158,7 @@ struct ec_master wait_queue_head_t eeprom_queue; /**< wait queue for EEPROM write requests from user space */ - struct list_head sdo_requests; /**< Sdo access requests */ + struct list_head slave_sdo_requests; /**< Sdo access requests. */ struct semaphore sdo_sem; /**< semaphore protecting the list of Sdo access requests */ wait_queue_head_t sdo_queue; /**< wait queue for Sdo access requests diff --git a/master/sdo_entry.c b/master/sdo_entry.c index d0d84aea8b5bb2c9ac4c267d35284ae5028863c8..340f491e157dbc23891de5be27983695f3cc7452 100644 --- a/master/sdo_entry.c +++ b/master/sdo_entry.c @@ -264,23 +264,23 @@ ssize_t ec_sdo_entry_read_value( { ec_master_t *master = entry->sdo->slave->master; off_t off = 0; - ec_sdo_request_t request; + ec_master_sdo_request_t request; - ec_sdo_request_init(&request, entry->sdo->slave, - entry->sdo->index, entry->subindex); + request.slave = entry->sdo->slave; + ec_sdo_request_init(&request.req, entry->sdo->index, entry->subindex); // schedule request. down(&master->sdo_sem); - list_add_tail(&request.list, &master->sdo_requests); + list_add_tail(&request.list, &master->slave_sdo_requests); up(&master->sdo_sem); // wait for processing through FSM if (wait_event_interruptible(master->sdo_queue, - request.state != EC_REQUEST_QUEUED)) { + request.req.state != EC_REQUEST_QUEUED)) { // interrupted by signal down(&master->sdo_sem); - if (request.state == EC_REQUEST_QUEUED) { - list_del(&request.list); + if (request.req.state == EC_REQUEST_QUEUED) { + list_del(&request.req.list); up(&master->sdo_sem); return -EINTR; } @@ -289,14 +289,14 @@ ssize_t ec_sdo_entry_read_value( } // wait until master FSM has finished processing - wait_event(master->sdo_queue, request.state != EC_REQUEST_IN_PROGRESS); + wait_event(master->sdo_queue, request.req.state != EC_REQUEST_IN_PROGRESS); - if (request.state != EC_REQUEST_COMPLETE) + if (request.req.state != EC_REQUEST_COMPLETE) return -EIO; - off += ec_sdo_entry_format_data(entry, &request, buffer); + off += ec_sdo_entry_format_data(entry, &request.req, buffer); - ec_sdo_request_clear(&request); + ec_sdo_request_clear(&request.req); return off; } diff --git a/master/sdo_request.c b/master/sdo_request.c index 7ba3ce4177cf4da1afe2a05e303b0fbf025edc8b..bf220dd04d7a80186592a706cdcb086041bfda92 100644 --- a/master/sdo_request.c +++ b/master/sdo_request.c @@ -48,12 +48,10 @@ */ void ec_sdo_request_init( ec_sdo_request_t *req, /**< Sdo request. */ - ec_slave_t *slave, /**< Slave owning the Sdo. */ uint16_t index, /**< Sdo index. */ uint8_t subindex /**< Sdo subindex. */ ) { - req->slave = slave; req->index = index; req->subindex = subindex; req->data = NULL; diff --git a/master/sdo_request.h b/master/sdo_request.h index 0e37fe70dfd15d557ced9354dd2089a718f7a745..f0b773c347ebb718e2574c8205fdb229ba90f410 100644 --- a/master/sdo_request.h +++ b/master/sdo_request.h @@ -51,7 +51,6 @@ */ typedef struct { struct list_head list; /**< List item. */ - ec_slave_t *slave; /**< Slave. */ uint16_t index; /**< Sdo index. */ uint8_t subindex; /**< Sdo subindex. */ uint8_t *data; /**< Pointer to Sdo data. */ @@ -61,7 +60,7 @@ typedef struct { /*****************************************************************************/ -void ec_sdo_request_init(ec_sdo_request_t *, ec_slave_t *, uint16_t, uint8_t); +void ec_sdo_request_init(ec_sdo_request_t *, uint16_t, uint8_t); void ec_sdo_request_clear(ec_sdo_request_t *); /*****************************************************************************/