master/mailbox.h
changeset 2046 4cf0161c445a
parent 2045 ff2a13a4603c
child 2094 83e9160319ec
equal deleted inserted replaced
2042:8b358effa78b 2046:4cf0161c445a
    35 /*****************************************************************************/
    35 /*****************************************************************************/
    36 
    36 
    37 #ifndef __EC_MAILBOX_H__
    37 #ifndef __EC_MAILBOX_H__
    38 #define __EC_MAILBOX_H__
    38 #define __EC_MAILBOX_H__
    39 
    39 
    40 #include "slave.h"
    40 #include "globals.h"
       
    41 #include "datagram.h"
    41 
    42 
    42 /*****************************************************************************/
    43 /*****************************************************************************/
    43 
    44 
    44 /** Size of the mailbox header.
    45 /** Size of the mailbox header.
    45  */
    46  */
    46 #define EC_MBOX_HEADER_SIZE 6
    47 #define EC_MBOX_HEADER_SIZE 6
    47 
    48 
    48 /*****************************************************************************/
    49 /*****************************************************************************/
    49 
    50 
    50 uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *, ec_datagram_t *,
    51 /** EtherCAT slave mailbox.
       
    52  */
       
    53 struct ec_mailbox
       
    54 {
       
    55     ec_datagram_t* datagram;    /**< Datagram used for the mailbox content. */
       
    56 #ifdef EC_REDUCE_MBOXFRAMESIZE
       
    57     ec_datagram_t end_datagram; /**< Datagram used for writing the end byte to the mailbox. */
       
    58 #endif
       
    59 };
       
    60 typedef struct ec_mailbox ec_mailbox_t; /**< \see ec_mailbox. */
       
    61 
       
    62 /*****************************************************************************/
       
    63 
       
    64 void     ec_mbox_init(ec_mailbox_t *, ec_datagram_t*);
       
    65 void     ec_mbox_clear(ec_mailbox_t*);
       
    66 /**
       
    67    Checks the datagrams states.
       
    68 */
       
    69 static inline int ec_mbox_is_datagram_state(ec_mailbox_t*mbox,
       
    70                                             ec_datagram_state_t state) {
       
    71     return (mbox->datagram->state == state)
       
    72 #ifdef EC_REDUCE_MBOXFRAMESIZE
       
    73          && (mbox->end_datagram.type == EC_DATAGRAM_NONE || mbox->end_datagram.state == state)
       
    74 #endif
       
    75     ;
       
    76 }
       
    77 
       
    78 /**
       
    79    Checks the datagrams working counter.
       
    80 */
       
    81 static inline int ec_mbox_is_datagram_wc(ec_mailbox_t*mbox,
       
    82                                          size_t wc) {
       
    83     return (mbox->datagram->working_counter == wc)
       
    84 #ifdef EC_REDUCE_MBOXFRAMESIZE
       
    85          && (mbox->end_datagram.type == EC_DATAGRAM_NONE || mbox->end_datagram.working_counter == wc)
       
    86 #endif
       
    87          ;
       
    88 }
       
    89 
       
    90 void     ec_slave_mbox_queue_datagrams(const ec_slave_t*,ec_mailbox_t*);
       
    91 void     ec_master_mbox_queue_datagrams(ec_master_t*, ec_mailbox_t*);
       
    92 uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t*,ec_mailbox_t *,
    51                                     uint8_t, size_t);
    93                                     uint8_t, size_t);
    52 int      ec_slave_mbox_prepare_check(const ec_slave_t *, ec_datagram_t *);
    94 int      ec_slave_mbox_prepare_check(const ec_slave_t*,ec_mailbox_t *);
    53 int      ec_slave_mbox_check(const ec_datagram_t *);
    95 int      ec_slave_mbox_check(ec_mailbox_t *);
    54 int      ec_slave_mbox_prepare_fetch(const ec_slave_t *, ec_datagram_t *);
    96 int      ec_slave_mbox_prepare_fetch(const ec_slave_t*,ec_mailbox_t *);
    55 uint8_t *ec_slave_mbox_fetch(const ec_slave_t *, ec_datagram_t *,
    97 uint8_t *ec_slave_mbox_fetch(const ec_slave_t*,ec_mailbox_t *,
    56                              uint8_t *, size_t *);
    98                              uint8_t *, size_t *);
    57 
    99 
    58 /*****************************************************************************/
   100 /*****************************************************************************/
    59 
   101 
    60 #endif
   102 #endif