master/mailbox.h
author Florian Pose <fp@igh-essen.com>
Wed, 04 Jan 2012 12:30:30 +0100
changeset 2183 b784af1203a4
parent 2094 83e9160319ec
child 2589 2b9c78543663
permissions -rw-r--r--
Fixed crash on loading e100 driver for 2.6.33 (allocating cbs_pool).
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
    11
 *  published by the Free Software Foundation.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    12
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
    16
 *  Public License for more details.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    17
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 883
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    27
 *
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    30
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    31
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    32
   Mailbox functionality.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    33
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    34
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    35
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
883
4963e22a267a Equalized defines against duplicated header inclusion.
Florian Pose <fp@igh-essen.com>
parents: 390
diff changeset
    37
#ifndef __EC_MAILBOX_H__
4963e22a267a Equalized defines against duplicated header inclusion.
Florian Pose <fp@igh-essen.com>
parents: 390
diff changeset
    38
#define __EC_MAILBOX_H__
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    40
#include "globals.h"
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    41
#include "datagram.h"
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
1907
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1563
diff changeset
    45
/** Size of the mailbox header.
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1563
diff changeset
    46
 */
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    47
#define EC_MBOX_HEADER_SIZE 6
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    48
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    49
/*****************************************************************************/
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    50
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    51
/** EtherCAT slave mailbox.
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    52
 */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    53
struct ec_mailbox
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    54
{
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    55
    ec_datagram_t *datagram; /**< Datagram used for the mailbox content. */
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    56
#ifdef EC_REDUCE_MBOXFRAMESIZE
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    57
    ec_datagram_t end_datagram; /**< Datagram used for writing the end byte to
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    58
                                  the mailbox. */
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    59
#endif
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    60
};
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    61
typedef struct ec_mailbox ec_mailbox_t; /**< \see ec_mailbox. */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    62
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    63
/*****************************************************************************/
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    64
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    65
void ec_mbox_init(ec_mailbox_t *, ec_datagram_t *);
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    66
void ec_mbox_clear(ec_mailbox_t *);
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    67
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    68
/**
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    69
   Checks the datagrams states.
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    70
*/
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    71
static inline int ec_mbox_is_datagram_state(
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    72
        ec_mailbox_t *mbox,
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    73
        ec_datagram_state_t state
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    74
        )
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    75
{
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    76
    return (mbox->datagram->state == state)
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    77
#ifdef EC_REDUCE_MBOXFRAMESIZE
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    78
         && (mbox->end_datagram.type == EC_DATAGRAM_NONE
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    79
                 || mbox->end_datagram.state == state)
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    80
#endif
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    81
         ;
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    82
}
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    83
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    84
/**
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    85
   Checks the datagrams working counter.
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    86
*/
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    87
static inline int ec_mbox_is_datagram_wc(
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    88
        ec_mailbox_t *mbox,
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    89
        size_t wc
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    90
        )
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    91
{
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    92
    return (mbox->datagram->working_counter == wc)
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    93
#ifdef EC_REDUCE_MBOXFRAMESIZE
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    94
         && (mbox->end_datagram.type == EC_DATAGRAM_NONE
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    95
                 || mbox->end_datagram.working_counter == wc)
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    96
#endif
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    97
         ;
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    98
}
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1907
diff changeset
    99
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   100
void ec_slave_mbox_queue_datagrams(const ec_slave_t *, ec_mailbox_t *);
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   101
void ec_master_mbox_queue_datagrams(ec_master_t *, ec_mailbox_t *);
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   102
uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *, ec_mailbox_t *,
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   103
                                    uint8_t, size_t);
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   104
int ec_slave_mbox_prepare_check(const ec_slave_t *, ec_mailbox_t *);
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   105
int ec_slave_mbox_check(ec_mailbox_t *);
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   106
int ec_slave_mbox_prepare_fetch(const ec_slave_t *, ec_mailbox_t *);
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   107
uint8_t *ec_slave_mbox_fetch(const ec_slave_t *, ec_mailbox_t *,
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 328
diff changeset
   108
                             uint8_t *, size_t *);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
#endif