master/mailbox.c
changeset 199 04ecf40fc2e9
parent 197 b9a6e2c22745
child 246 0bf7c769de06
equal deleted inserted replaced
198:f7dff1ed01ba 199:04ecf40fc2e9
     1 /******************************************************************************
     1 /******************************************************************************
     2  *
       
     3  *  m a i l b o x . c
       
     4  *
       
     5  *  Mailbox functionality.
       
     6  *
     2  *
     7  *  $Id$
     3  *  $Id$
     8  *
     4  *
     9  *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
     5  *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
    10  *
     6  *
    23  *  along with the IgH EtherCAT Master; if not, write to the Free Software
    19  *  along with the IgH EtherCAT Master; if not, write to the Free Software
    24  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    25  *
    21  *
    26  *****************************************************************************/
    22  *****************************************************************************/
    27 
    23 
       
    24 /**
       
    25    \file
       
    26    Mailbox functionality.
       
    27 */
       
    28 
       
    29 /*****************************************************************************/
       
    30 
    28 #include <linux/slab.h>
    31 #include <linux/slab.h>
    29 #include <linux/delay.h>
    32 #include <linux/delay.h>
    30 
    33 
    31 #include "mailbox.h"
    34 #include "mailbox.h"
    32 #include "command.h"
    35 #include "command.h"
    35 /*****************************************************************************/
    38 /*****************************************************************************/
    36 
    39 
    37 /**
    40 /**
    38    Prepares a mailbox-send command.
    41    Prepares a mailbox-send command.
    39    \return pointer to mailbox command data
    42    \return pointer to mailbox command data
    40    \ingroup Slave
       
    41 */
    43 */
    42 
    44 
    43 uint8_t *ec_slave_mbox_prepare_send(ec_slave_t *slave, /**< slave */
    45 uint8_t *ec_slave_mbox_prepare_send(ec_slave_t *slave, /**< slave */
    44                                     uint8_t type, /**< mailbox protocol */
    46                                     uint8_t type, /**< mailbox protocol */
    45                                     size_t size /**< size of the data */
    47                                     size_t size /**< size of the data */
    76 /*****************************************************************************/
    78 /*****************************************************************************/
    77 
    79 
    78 /**
    80 /**
    79    Prepares a command for checking the mailbox state.
    81    Prepares a command for checking the mailbox state.
    80    \return 0 in case of success, else < 0
    82    \return 0 in case of success, else < 0
    81    \ingroup Slave
       
    82 */
    83 */
    83 
    84 
    84 int ec_slave_mbox_prepare_check(ec_slave_t *slave /**< slave */)
    85 int ec_slave_mbox_prepare_check(ec_slave_t *slave /**< slave */)
    85 {
    86 {
    86     ec_command_t *command = &slave->mbox_command;
    87     ec_command_t *command = &slave->mbox_command;
    95 /*****************************************************************************/
    96 /*****************************************************************************/
    96 
    97 
    97 /**
    98 /**
    98    Processes a mailbox state checking command.
    99    Processes a mailbox state checking command.
    99    \return 0 in case of success, else < 0
   100    \return 0 in case of success, else < 0
   100    \ingroup Slave
       
   101 */
   101 */
   102 
   102 
   103 int ec_slave_mbox_check(const ec_slave_t *slave /**< slave */)
   103 int ec_slave_mbox_check(const ec_slave_t *slave /**< slave */)
   104 {
   104 {
   105     return EC_READ_U8(slave->mbox_command.data + 5) & 8 ? 1 : 0;
   105     return EC_READ_U8(slave->mbox_command.data + 5) & 8 ? 1 : 0;
   108 /*****************************************************************************/
   108 /*****************************************************************************/
   109 
   109 
   110 /**
   110 /**
   111    Prepares a command to fetch mailbox data.
   111    Prepares a command to fetch mailbox data.
   112    \return 0 in case of success, else < 0
   112    \return 0 in case of success, else < 0
   113    \ingroup Slave
       
   114 */
   113 */
   115 
   114 
   116 int ec_slave_mbox_prepare_fetch(ec_slave_t *slave /**< slave */)
   115 int ec_slave_mbox_prepare_fetch(ec_slave_t *slave /**< slave */)
   117 {
   116 {
   118     ec_command_t *command = &slave->mbox_command;
   117     ec_command_t *command = &slave->mbox_command;
   126 /*****************************************************************************/
   125 /*****************************************************************************/
   127 
   126 
   128 /**
   127 /**
   129    Processes received mailbox data.
   128    Processes received mailbox data.
   130    \return pointer to the received data
   129    \return pointer to the received data
   131    \ingroup Slave
       
   132 */
   130 */
   133 
   131 
   134 uint8_t *ec_slave_mbox_fetch(ec_slave_t *slave, /**< slave */
   132 uint8_t *ec_slave_mbox_fetch(ec_slave_t *slave, /**< slave */
   135                              uint8_t type, /**< expected mailbox protocol */
   133                              uint8_t type, /**< expected mailbox protocol */
   136                              size_t *size /**< size of the received data */
   134                              size_t *size /**< size of the received data */
   159 /*****************************************************************************/
   157 /*****************************************************************************/
   160 
   158 
   161 /**
   159 /**
   162    Sends a mailbox command and waits for its reception.
   160    Sends a mailbox command and waits for its reception.
   163    \return pointer to the received data
   161    \return pointer to the received data
   164    \ingroup Slave
       
   165 */
   162 */
   166 
   163 
   167 uint8_t *ec_slave_mbox_simple_io(ec_slave_t *slave, /**< slave */
   164 uint8_t *ec_slave_mbox_simple_io(ec_slave_t *slave, /**< slave */
   168                                  size_t *size /**< size of the received data */
   165                                  size_t *size /**< size of the received data */
   169                                  )
   166                                  )
   186 /*****************************************************************************/
   183 /*****************************************************************************/
   187 
   184 
   188 /**
   185 /**
   189    Waits for the reception of a mailbox command.
   186    Waits for the reception of a mailbox command.
   190    \return pointer to the received data
   187    \return pointer to the received data
   191    \ingroup Slave
       
   192 */
   188 */
   193 
   189 
   194 uint8_t *ec_slave_mbox_simple_receive(ec_slave_t *slave, /**< slave */
   190 uint8_t *ec_slave_mbox_simple_receive(ec_slave_t *slave, /**< slave */
   195                                       uint8_t type, /**< expected protocol */
   191                                       uint8_t type, /**< expected protocol */
   196                                       size_t *size /**< received data size */
   192                                       size_t *size /**< received data size */