Introduced EC_MBOX_HEADER_SIZE.
authorFlorian Pose <fp@igh-essen.com>
Mon, 22 Sep 2008 15:26:54 +0000
changeset 1217 e8a9785e63c3
parent 1216 e70c4d71cebd
child 1218 6f3a973fc29e
Introduced EC_MBOX_HEADER_SIZE.
master/globals.h
master/mailbox.c
--- a/master/globals.h	Mon Sep 22 14:43:40 2008 +0000
+++ b/master/globals.h	Mon Sep 22 15:26:54 2008 +0000
@@ -88,6 +88,9 @@
 #define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE \
                           - EC_DATAGRAM_HEADER_SIZE - EC_DATAGRAM_FOOTER_SIZE)
 
+/** Mailbox header size.  */
+#define EC_MBOX_HEADER_SIZE 6
+
 /** Word offset of first SII category. */
 #define EC_FIRST_SII_CATEGORY_OFFSET 0x40
 
--- a/master/mailbox.c	Mon Sep 22 14:43:40 2008 +0000
+++ b/master/mailbox.c	Mon Sep 22 15:26:54 2008 +0000
@@ -66,7 +66,7 @@
         return NULL;
     }
 
-    total_size = size + 6;
+    total_size = EC_MBOX_HEADER_SIZE + size;
     if (unlikely(total_size > slave->sii.rx_mailbox_size)) {
         EC_ERR("Data size does not fit in mailbox!\n");
         return NULL;
@@ -82,7 +82,7 @@
     EC_WRITE_U8 (datagram->data + 4, 0x00); // channel & priority
     EC_WRITE_U8 (datagram->data + 5, type); // underlying protocol type
 
-    return datagram->data + 6;
+    return datagram->data + EC_MBOX_HEADER_SIZE;
 }
 
 /*****************************************************************************/
@@ -167,7 +167,7 @@
 
     data_size = EC_READ_U16(datagram->data);
 
-    if (data_size > slave->sii.tx_mailbox_size - 6) {
+    if (data_size + EC_MBOX_HEADER_SIZE > slave->sii.tx_mailbox_size) {
         EC_ERR("Corrupt mailbox response received from slave %u!\n",
                slave->ring_position);
         ec_print_data(datagram->data, slave->sii.tx_mailbox_size);
@@ -179,12 +179,12 @@
 
     if (*type == 0x00) {
         const ec_code_msg_t *mbox_msg;
-	uint16_t code = EC_READ_U16(datagram->data + 8);
+        uint16_t code = EC_READ_U16(datagram->data + 8);
 
         EC_ERR("Mailbox error response received from slave %u - ",
-               slave->ring_position);
-
-	for (mbox_msg = mbox_error_messages; mbox_msg->code; mbox_msg++) {
+                slave->ring_position);
+
+        for (mbox_msg = mbox_error_messages; mbox_msg->code; mbox_msg++) {
             if (mbox_msg->code != code) continue;
             printk("Code 0x%04X: \"%s\".\n",
                    mbox_msg->code, mbox_msg->message);
@@ -195,12 +195,12 @@
             printk("Unknown error reply code 0x%04X.\n", code);
 
         if (slave->master->debug_level)
-            ec_print_data(datagram->data + 6, data_size);
-
-        return NULL;
-    }
-
-    return datagram->data + 6;
-}
-
-/*****************************************************************************/
+            ec_print_data(datagram->data + EC_MBOX_HEADER_SIZE, data_size);
+
+        return NULL;
+    }
+
+    return datagram->data + EC_MBOX_HEADER_SIZE;
+}
+
+/*****************************************************************************/