master/canopen.c
changeset 145 11a82e4fd31b
parent 144 fdc24bf62f80
child 157 37c6dd0ff0b1
--- a/master/canopen.c	Mon Apr 03 10:03:34 2006 +0000
+++ b/master/canopen.c	Mon Apr 03 14:12:45 2006 +0000
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 
 #include "master.h"
+#include "mailbox.h"
 
 /*****************************************************************************/
 
@@ -51,18 +52,15 @@
     size_t rec_size;
     uint8_t *data;
 
-    if (!(data = ec_slave_prepare_mailbox_send(slave, 0x03, 6))) return -1;
+    if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 6))) return -1;
+
     EC_WRITE_U16(data, 0x2 << 12); // SDO request
     EC_WRITE_U8 (data + 2, (0x1 << 1 // expedited transfer
                             | 0x2 << 5));  // initiate upload request
     EC_WRITE_U16(data + 3, sdo_index);
     EC_WRITE_U8 (data + 5, sdo_subindex);
-    if (unlikely(ec_master_simple_io(slave->master))) {
-        EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position);
-        return -1;
-    }
-
-    if (!(data = ec_slave_mailbox_receive(slave, 0x03, &rec_size))) return -1;
+
+    if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
 
     if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
         EC_READ_U8 (data + 2) >> 5 == 0x4) { // Abort SDO transfer request
@@ -107,7 +105,8 @@
         return -1;
     }
 
-    if (!(data = ec_slave_prepare_mailbox_send(slave, 0x03, 0x0A))) return -1;
+    if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 0x0A))) return -1;
+
     EC_WRITE_U16(data, 0x2 << 12); // SDO request
     EC_WRITE_U8 (data + 2, (0x1 // size specified
                             | 0x1 << 1 // expedited transfer
@@ -117,12 +116,8 @@
     EC_WRITE_U8 (data + 5, sdo_subindex);
     memcpy(data + 6, sdo_data, size);
     if (size < 4) memset(data + 6 + size, 0x00, 4 - size);
-    if (unlikely(ec_master_simple_io(slave->master))) {
-        EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position);
-        return -1;
-    }
-
-    if (!(data = ec_slave_mailbox_receive(slave, 0x03, &rec_size))) return -1;
+
+    if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
 
     if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
         EC_READ_U8 (data + 2) >> 5 == 0x4) { // Abort SDO transfer request
@@ -164,17 +159,14 @@
     size_t rec_size, data_size;
     uint32_t complete_size;
 
-    if (!(data = ec_slave_prepare_mailbox_send(slave, 0x03, 6))) return -1;
+    if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 6))) return -1;
+
     EC_WRITE_U16(data, 0x2 << 12); // SDO request
     EC_WRITE_U8 (data + 2, 0x2 << 5); // initiate upload request
     EC_WRITE_U16(data + 3, sdo_index);
     EC_WRITE_U8 (data + 5, sdo_subindex);
-    if (unlikely(ec_master_simple_io(slave->master))) {
-        EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position);
-        return -1;
-    }
-
-    if (!(data = ec_slave_mailbox_receive(slave, 0x03, &rec_size))) return -1;
+
+    if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
 
     if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
         EC_READ_U8 (data + 2) >> 5 == 0x4) { // Abort SDO transfer request
@@ -232,19 +224,22 @@
     ec_sdo_t *sdo;
     uint16_t sdo_index;
 
-    if (!(data = ec_slave_prepare_mailbox_send(slave, 0x03, 8))) return -1;
+    if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 8))) return -1;
+
     EC_WRITE_U16(data, 0x8 << 12); // SDO information
     EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request
     EC_WRITE_U8 (data + 3, 0x00);
     EC_WRITE_U16(data + 4, 0x0000);
     EC_WRITE_U16(data + 6, 0x0001); // Deliver all SDOs!
-    if (unlikely(ec_master_simple_io(slave->master))) {
-        EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position);
+
+    if (unlikely(ec_master_simple_io(slave->master, &slave->mbox_command))) {
+        EC_ERR("Mailbox checking failed on slave %i!\n",
+               slave->ring_position);
         return -1;
     }
 
     do {
-        if (!(data = ec_slave_mailbox_receive(slave, 0x03, &rec_size)))
+        if (!(data = ec_slave_mbox_simple_receive(slave, 0x03, &rec_size)))
             return -1;
 
         if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
@@ -302,20 +297,14 @@
     ec_sdo_t *sdo;
 
     list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
-        if (!(data = ec_slave_prepare_mailbox_send(slave, 0x03, 8))) return -1;
+        if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 8))) return -1;
         EC_WRITE_U16(data, 0x8 << 12); // SDO information
         EC_WRITE_U8 (data + 2, 0x03); // Get object description request
         EC_WRITE_U8 (data + 3, 0x00);
         EC_WRITE_U16(data + 4, 0x0000);
         EC_WRITE_U16(data + 6, sdo->index); // SDO index
-        if (unlikely(ec_master_simple_io(slave->master))) {
-            EC_ERR("Mailbox sending failed on slave %i!\n",
-                   slave->ring_position);
-            return -1;
-        }
-
-        if (!(data = ec_slave_mailbox_receive(slave, 0x03, &rec_size)))
-            return -1;
+
+        if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
 
         if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
             (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // Error response
@@ -386,8 +375,9 @@
     ec_sdo_entry_t *entry;
 
     for (i = 1; i <= subindices; i++) {
-        if (!(data = ec_slave_prepare_mailbox_send(slave, 0x03, 10)))
-            return -1;
+        if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 10)))
+            return -1;
+
         EC_WRITE_U16(data, 0x8 << 12); // SDO information
         EC_WRITE_U8 (data + 2, 0x05); // Get entry description request
         EC_WRITE_U8 (data + 3, 0x00);
@@ -395,14 +385,8 @@
         EC_WRITE_U16(data + 6, sdo->index); // SDO index
         EC_WRITE_U8 (data + 8, i); // SDO subindex
         EC_WRITE_U8 (data + 9, 0x00); // value info (no values)
-        if (unlikely(ec_master_simple_io(slave->master))) {
-            EC_ERR("Mailbox sending failed on slave %i!\n",
-                   slave->ring_position);
-            return -1;
-        }
-
-        if (!(data = ec_slave_mailbox_receive(slave, 0x03, &rec_size)))
-            return -1;
+
+        if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
 
         if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
             (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // Error response