master/mailbox.c
branchstable-1.0
changeset 1624 9dc190591c0f
parent 1621 4bbe090553f7
--- a/master/mailbox.c	Mon Jun 26 16:07:07 2006 +0000
+++ b/master/mailbox.c	Wed Aug 02 12:25:25 2006 +0000
@@ -42,18 +42,18 @@
 #include <linux/delay.h>
 
 #include "mailbox.h"
-#include "command.h"
+#include "datagram.h"
 #include "master.h"
 
 /*****************************************************************************/
 
 /**
-   Prepares a mailbox-send command.
-   \return pointer to mailbox command data
+   Prepares a mailbox-send datagram.
+   \return pointer to mailbox datagram data
 */
 
 uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *slave, /**< slave */
-                                    ec_command_t *command, /**< command */
+                                    ec_datagram_t *datagram, /**< datagram */
                                     uint8_t type, /**< mailbox protocol */
                                     size_t size /**< size of the data */
                                     )
@@ -72,32 +72,32 @@
         return NULL;
     }
 
-    if (ec_command_npwr(command, slave->station_address,
-                        slave->sii_rx_mailbox_offset,
-                        slave->sii_rx_mailbox_size))
-        return NULL;
-
-    EC_WRITE_U16(command->data,     size); // mailbox service data length
-    EC_WRITE_U16(command->data + 2, slave->station_address); // station address
-    EC_WRITE_U8 (command->data + 4, 0x00); // channel & priority
-    EC_WRITE_U8 (command->data + 5, type); // underlying protocol type
-
-    return command->data + 6;
-}
-
-/*****************************************************************************/
-
-/**
-   Prepares a command for checking the mailbox state.
+    if (ec_datagram_npwr(datagram, slave->station_address,
+                         slave->sii_rx_mailbox_offset,
+                         slave->sii_rx_mailbox_size))
+        return NULL;
+
+    EC_WRITE_U16(datagram->data,     size); // mailbox service data length
+    EC_WRITE_U16(datagram->data + 2, slave->station_address); // station addr.
+    EC_WRITE_U8 (datagram->data + 4, 0x00); // channel & priority
+    EC_WRITE_U8 (datagram->data + 5, type); // underlying protocol type
+
+    return datagram->data + 6;
+}
+
+/*****************************************************************************/
+
+/**
+   Prepares a datagram for checking the mailbox state.
    \return 0 in case of success, else < 0
 */
 
 int ec_slave_mbox_prepare_check(const ec_slave_t *slave, /**< slave */
-                                ec_command_t *command /**< command */
+                                ec_datagram_t *datagram /**< datagram */
                                 )
 {
     // FIXME: second sync manager?
-    if (ec_command_nprd(command, slave->station_address, 0x808, 8))
+    if (ec_datagram_nprd(datagram, slave->station_address, 0x808, 8))
         return -1;
 
     return 0;
@@ -106,29 +106,29 @@
 /*****************************************************************************/
 
 /**
-   Processes a mailbox state checking command.
+   Processes a mailbox state checking datagram.
    \return 0 in case of success, else < 0
 */
 
-int ec_slave_mbox_check(const ec_command_t *command /**< command */)
-{
-    return EC_READ_U8(command->data + 5) & 8 ? 1 : 0;
-}
-
-/*****************************************************************************/
-
-/**
-   Prepares a command to fetch mailbox data.
+int ec_slave_mbox_check(const ec_datagram_t *datagram /**< datagram */)
+{
+    return EC_READ_U8(datagram->data + 5) & 8 ? 1 : 0;
+}
+
+/*****************************************************************************/
+
+/**
+   Prepares a datagram to fetch mailbox data.
    \return 0 in case of success, else < 0
 */
 
 int ec_slave_mbox_prepare_fetch(const ec_slave_t *slave, /**< slave */
-                                ec_command_t *command /**< command */
+                                ec_datagram_t *datagram /**< datagram */
                                 )
 {
-    if (ec_command_nprd(command, slave->station_address,
-                        slave->sii_tx_mailbox_offset,
-                        slave->sii_tx_mailbox_size)) return -1;
+    if (ec_datagram_nprd(datagram, slave->station_address,
+                         slave->sii_tx_mailbox_offset,
+                         slave->sii_tx_mailbox_size)) return -1;
     return 0;
 }
 
@@ -140,64 +140,64 @@
 */
 
 uint8_t *ec_slave_mbox_fetch(const ec_slave_t *slave, /**< slave */
-                             ec_command_t *command, /**< command */
+                             ec_datagram_t *datagram, /**< datagram */
                              uint8_t type, /**< expected mailbox protocol */
                              size_t *size /**< size of the received data */
                              )
 {
     size_t data_size;
 
-    if ((EC_READ_U8(command->data + 5) & 0x0F) != type) {
+    if ((EC_READ_U8(datagram->data + 5) & 0x0F) != type) {
         EC_ERR("Unexpected mailbox protocol 0x%02X (exp.: 0x%02X) at"
-               " slave %i!\n", EC_READ_U8(command->data + 5), type,
-               slave->ring_position);
-        return NULL;
-    }
-
-    if ((data_size = EC_READ_U16(command->data)) >
+               " slave %i!\n", EC_READ_U8(datagram->data + 5), type,
+               slave->ring_position);
+        return NULL;
+    }
+
+    if ((data_size = EC_READ_U16(datagram->data)) >
         slave->sii_tx_mailbox_size - 6) {
         EC_ERR("Currupt mailbox response detected!\n");
         return NULL;
     }
 
     *size = data_size;
-    return command->data + 6;
-}
-
-/*****************************************************************************/
-
-/**
-   Sends a mailbox command and waits for its reception.
+    return datagram->data + 6;
+}
+
+/*****************************************************************************/
+
+/**
+   Sends a mailbox datagram and waits for its reception.
    \return pointer to the received data
 */
 
 uint8_t *ec_slave_mbox_simple_io(const ec_slave_t *slave, /**< slave */
-                                 ec_command_t *command, /**< command */
+                                 ec_datagram_t *datagram, /**< datagram */
                                  size_t *size /**< size of the received data */
                                  )
 {
     uint8_t type;
 
-    type = EC_READ_U8(command->data + 5);
-
-    if (unlikely(ec_master_simple_io(slave->master, command))) {
+    type = EC_READ_U8(datagram->data + 5);
+
+    if (unlikely(ec_master_simple_io(slave->master, datagram))) {
         EC_ERR("Mailbox checking failed on slave %i!\n",
                slave->ring_position);
         return NULL;
     }
 
-    return ec_slave_mbox_simple_receive(slave, command, type, size);
-}
-
-/*****************************************************************************/
-
-/**
-   Waits for the reception of a mailbox command.
+    return ec_slave_mbox_simple_receive(slave, datagram, type, size);
+}
+
+/*****************************************************************************/
+
+/**
+   Waits for the reception of a mailbox datagram.
    \return pointer to the received data
 */
 
 uint8_t *ec_slave_mbox_simple_receive(const ec_slave_t *slave, /**< slave */
-                                      ec_command_t *command, /**< command */
+                                      ec_datagram_t *datagram, /**< datagram */
                                       uint8_t type, /**< expected protocol */
                                       size_t *size /**< received data size */
                                       )
@@ -209,8 +209,8 @@
 
     while (1)
     {
-        if (ec_slave_mbox_prepare_check(slave, command)) return NULL;
-        if (unlikely(ec_master_simple_io(slave->master, command))) {
+        if (ec_slave_mbox_prepare_check(slave, datagram)) return NULL;
+        if (unlikely(ec_master_simple_io(slave->master, datagram))) {
             EC_ERR("Mailbox checking failed on slave %i!\n",
                    slave->ring_position);
             return NULL;
@@ -218,7 +218,7 @@
 
         end = get_cycles();
 
-        if (ec_slave_mbox_check(command))
+        if (ec_slave_mbox_check(datagram))
             break; // proceed with receiving data
 
         if ((end - start) >= timeout) {
@@ -230,18 +230,18 @@
         udelay(100);
     }
 
-    if (ec_slave_mbox_prepare_fetch(slave, command)) return NULL;
-    if (unlikely(ec_master_simple_io(slave->master, command))) {
+    if (ec_slave_mbox_prepare_fetch(slave, datagram)) return NULL;
+    if (unlikely(ec_master_simple_io(slave->master, datagram))) {
         EC_ERR("Mailbox receiving failed on slave %i!\n",
                slave->ring_position);
         return NULL;
     }
 
     if (unlikely(slave->master->debug_level) > 1)
-        EC_DBG("Mailbox receive took %ius.\n", ((u32) (end - start) * 1000
-                                                / cpu_khz));
-
-    return ec_slave_mbox_fetch(slave, command, type, size);
-}
-
-/*****************************************************************************/
+        EC_DBG("Mailbox receive took %ius.\n",
+               ((unsigned int) (end - start) * 1000 / cpu_khz));
+
+    return ec_slave_mbox_fetch(slave, datagram, type, size);
+}
+
+/*****************************************************************************/