Removed slave pointer from ec_sdo_request_t class.
authorFlorian Pose <fp@igh-essen.com>
Fri, 29 Feb 2008 16:20:12 +0000
changeset 849 4b712ec8929d
parent 848 ae0829882a72
child 850 f8e19594f4d0
Removed slave pointer from ec_sdo_request_t class.
master/fsm_coe_map.c
master/fsm_master.c
master/fsm_master.h
master/master.c
master/master.h
master/sdo_entry.c
master/sdo_request.c
master/sdo_request.h
--- a/master/fsm_coe_map.c	Fri Feb 29 12:20:49 2008 +0000
+++ b/master/fsm_coe_map.c	Fri Feb 29 16:20:12 2008 +0000
@@ -179,7 +179,7 @@
 
         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 @@
         )
 {
     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 @@
 
     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 @@
         )
 {
     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
--- a/master/fsm_master.c	Fri Feb 29 12:20:49 2008 +0000
+++ b/master/fsm_master.c	Fri Feb 29 16:20:12 2008 +0000
@@ -44,6 +44,7 @@
 #ifdef EC_EOE
 #include "ethernet.h"
 #endif
+
 #include "fsm_master.h"
 
 /*****************************************************************************/
@@ -370,45 +371,44 @@
         )
 {
     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_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)
--- a/master/fsm_master.h	Fri Feb 29 12:20:49 2008 +0000
+++ b/master/fsm_master.h	Fri Feb 29 16:20:12 2008 +0000
@@ -65,6 +65,16 @@
 
 /*****************************************************************************/
 
+/** 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 @@
     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 */
--- a/master/master.c	Fri Feb 29 12:20:49 2008 +0000
+++ b/master/master.c	Fri Feb 29 16:20:12 2008 +0000
@@ -175,7 +175,7 @@
     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);
 
--- a/master/master.h	Fri Feb 29 12:20:49 2008 +0000
+++ b/master/master.h	Fri Feb 29 16:20:12 2008 +0000
@@ -59,8 +59,7 @@
     EC_MASTER_MODE_ORPHANED,
     EC_MASTER_MODE_IDLE,
     EC_MASTER_MODE_OPERATION
-}
-ec_master_mode_t;
+} ec_master_mode_t;
 
 /*****************************************************************************/
 
@@ -72,8 +71,7 @@
     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 @@
  *
  * 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 @@
     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
--- a/master/sdo_entry.c	Fri Feb 29 12:20:49 2008 +0000
+++ b/master/sdo_entry.c	Fri Feb 29 16:20:12 2008 +0000
@@ -264,23 +264,23 @@
 {
     ec_master_t *master = entry->sdo->slave->master;
     off_t off = 0;
-    ec_sdo_request_t request;
-
-    ec_sdo_request_init(&request, entry->sdo->slave,
-            entry->sdo->index, entry->subindex);
+    ec_master_sdo_request_t request;
+
+    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 @@
     }
 
     // wait until master FSM has finished processing
-    wait_event(master->sdo_queue, request.state != EC_REQUEST_IN_PROGRESS);
-
-    if (request.state != EC_REQUEST_COMPLETE)
+    wait_event(master->sdo_queue, request.req.state != EC_REQUEST_IN_PROGRESS);
+
+    if (request.req.state != EC_REQUEST_COMPLETE)
         return -EIO;
 
-    off += ec_sdo_entry_format_data(entry, &request, buffer);
-
-    ec_sdo_request_clear(&request);
+    off += ec_sdo_entry_format_data(entry, &request.req, buffer);
+
+    ec_sdo_request_clear(&request.req);
     return off;
 }
 
--- a/master/sdo_request.c	Fri Feb 29 12:20:49 2008 +0000
+++ b/master/sdo_request.c	Fri Feb 29 16:20:12 2008 +0000
@@ -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;
--- a/master/sdo_request.h	Fri Feb 29 12:20:49 2008 +0000
+++ b/master/sdo_request.h	Fri Feb 29 16:20:12 2008 +0000
@@ -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 @@
 
 /*****************************************************************************/
 
-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 *);
 
 /*****************************************************************************/