fp@145: /****************************************************************************** fp@145: * fp@145: * $Id$ fp@145: * fp@1326: * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH fp@197: * fp@197: * This file is part of the IgH EtherCAT Master. fp@197: * fp@1326: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1326: * modify it under the terms of the GNU General Public License version 2, as fp@1326: * published by the Free Software Foundation. fp@197: * fp@1326: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1326: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1326: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1326: * Public License for more details. fp@197: * fp@1326: * You should have received a copy of the GNU General Public License along fp@1326: * with the IgH EtherCAT Master; if not, write to the Free Software fp@197: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@197: * fp@1363: * --- fp@1363: * fp@1363: * The license mentioned above concerns the source code only. Using the fp@1363: * EtherCAT technology and brand is only permitted in compliance with the fp@1363: * industrial property and similar rights of Beckhoff Automation GmbH. fp@246: * fp@145: *****************************************************************************/ fp@145: fp@199: /** fp@199: \file fp@199: Mailbox functionality. fp@199: */ fp@199: fp@199: /*****************************************************************************/ fp@199: fp@883: #ifndef __EC_MAILBOX_H__ fp@883: #define __EC_MAILBOX_H__ fp@145: ch1010277@2045: #include "globals.h" ch1010277@2045: #include "datagram.h" fp@145: fp@145: /*****************************************************************************/ fp@145: fp@1907: /** Size of the mailbox header. fp@1907: */ fp@1563: #define EC_MBOX_HEADER_SIZE 6 fp@1563: fp@1563: /*****************************************************************************/ fp@1563: ch1010277@2045: /** EtherCAT slave mailbox. ch1010277@2045: */ ch1010277@2045: struct ec_mailbox ch1010277@2045: { fp@2094: ec_datagram_t *datagram; /**< Datagram used for the mailbox content. */ ch1010277@2045: #ifdef EC_REDUCE_MBOXFRAMESIZE fp@2094: ec_datagram_t end_datagram; /**< Datagram used for writing the end byte to fp@2094: the mailbox. */ ch1010277@2045: #endif ch1010277@2045: }; ch1010277@2045: typedef struct ec_mailbox ec_mailbox_t; /**< \see ec_mailbox. */ ch1010277@2045: ch1010277@2045: /*****************************************************************************/ ch1010277@2045: fp@2094: void ec_mbox_init(ec_mailbox_t *, ec_datagram_t *); fp@2094: void ec_mbox_clear(ec_mailbox_t *); fp@2094: ch1010277@2045: /** ch1010277@2045: Checks the datagrams states. ch1010277@2045: */ fp@2094: static inline int ec_mbox_is_datagram_state( fp@2094: ec_mailbox_t *mbox, fp@2094: ec_datagram_state_t state fp@2094: ) fp@2094: { ch1010277@2045: return (mbox->datagram->state == state) ch1010277@2045: #ifdef EC_REDUCE_MBOXFRAMESIZE fp@2094: && (mbox->end_datagram.type == EC_DATAGRAM_NONE fp@2094: || mbox->end_datagram.state == state) ch1010277@2045: #endif fp@2094: ; ch1010277@2045: } ch1010277@2045: ch1010277@2045: /** ch1010277@2045: Checks the datagrams working counter. ch1010277@2045: */ fp@2094: static inline int ec_mbox_is_datagram_wc( fp@2094: ec_mailbox_t *mbox, fp@2094: size_t wc fp@2094: ) fp@2094: { ch1010277@2045: return (mbox->datagram->working_counter == wc) ch1010277@2045: #ifdef EC_REDUCE_MBOXFRAMESIZE fp@2094: && (mbox->end_datagram.type == EC_DATAGRAM_NONE fp@2094: || mbox->end_datagram.working_counter == wc) ch1010277@2045: #endif ch1010277@2045: ; ch1010277@2045: } ch1010277@2045: fp@2094: void ec_slave_mbox_queue_datagrams(const ec_slave_t *, ec_mailbox_t *); fp@2094: void ec_master_mbox_queue_datagrams(ec_master_t *, ec_mailbox_t *); fp@2094: uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *, ec_mailbox_t *, fp@279: uint8_t, size_t); fp@2094: int ec_slave_mbox_prepare_check(const ec_slave_t *, ec_mailbox_t *); fp@2094: int ec_slave_mbox_check(ec_mailbox_t *); fp@2094: int ec_slave_mbox_prepare_fetch(const ec_slave_t *, ec_mailbox_t *); fp@2094: uint8_t *ec_slave_mbox_fetch(const ec_slave_t *, ec_mailbox_t *, fp@390: uint8_t *, size_t *); fp@145: fp@145: /*****************************************************************************/ fp@145: fp@145: #endif