master/mailbox.c
author Martin Troxler <ch1010277@ch10lt194>
Mon, 14 Mar 2011 16:57:47 +0100
changeset 2046 4cf0161c445a
parent 2045 ff2a13a4603c
child 2094 83e9160319ec
permissions -rw-r--r--
merged
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: 1313
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: 1313
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: 1313
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: 1313
diff changeset
    11
 *  published by the Free Software Foundation.
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: 1313
diff changeset
    12
 *
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: 1313
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: 1313
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: 1313
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: 1313
diff changeset
    16
 *  Public License for more details.
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: 1313
diff changeset
    17
 *
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: 1313
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: 1313
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: 1338
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1338
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: 1338
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: 1338
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
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <linux/slab.h>
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include <linux/delay.h>
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: 1921
diff changeset
    40
#include "slave.h"
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "mailbox.h"
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    42
#include "datagram.h"
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "master.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    45
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    46
/*****************************************************************************/
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    47
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    48
/**
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    49
   Mailbox constructor.
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    50
*/
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    51
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    52
void ec_mbox_init(ec_mailbox_t* mbox, /** mailbox */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    53
                        ec_datagram_t* datagram  /**< Datagram used for the mailbox content. */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    54
                        )
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    55
{
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    56
    mbox->datagram = datagram;
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    57
#ifdef EC_REDUCE_MBOXFRAMESIZE
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    58
    ec_datagram_init(&mbox->end_datagram);
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
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: 1921
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: 1921
diff changeset
    61
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
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: 1921
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: 1921
diff changeset
    64
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    65
/**
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    66
   Clears mailbox datagrams.
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    67
*/
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
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: 1921
diff changeset
    69
void ec_mbox_clear(ec_mailbox_t* mbox /** mailbox */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    70
                         )
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    71
{
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    72
#ifdef EC_REDUCE_MBOXFRAMESIZE
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    73
    ec_datagram_clear(&mbox->end_datagram);
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    74
#endif
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    75
}
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    76
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    77
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    78
/*****************************************************************************/
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    79
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    80
/**
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    81
   Queues the slave datagrams.
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
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: 1921
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: 1921
diff changeset
    84
void  ec_slave_mbox_queue_datagrams(const ec_slave_t* slave, /** slave */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    85
                                    ec_mailbox_t* mbox /** mailbox */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    86
                                    )
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    87
{
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    88
    ec_master_queue_request_fsm_datagram(slave->master, mbox->datagram);
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    89
#ifdef EC_REDUCE_MBOXFRAMESIZE
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    90
    if (mbox->end_datagram.type != EC_DATAGRAM_NONE)
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    91
    {
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    92
        ec_master_queue_request_fsm_datagram(slave->master, &mbox->end_datagram);
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    93
    }
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    94
#endif
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    95
}
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
    96
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
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: 1921
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: 1921
diff changeset
    99
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   100
/**
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   101
   Queues the datagrams.
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   102
*/
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   103
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   104
void  ec_master_mbox_queue_datagrams(ec_master_t* master, /** master */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   105
                                    ec_mailbox_t* mbox /** mailbox */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   106
                                    )
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   107
{
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   108
    ec_master_queue_fsm_datagram(master, mbox->datagram);
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   109
#ifdef EC_REDUCE_MBOXFRAMESIZE
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   110
    if (mbox->end_datagram.type != EC_DATAGRAM_NONE)
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   111
    {
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   112
        ec_master_queue_fsm_datagram(master, &mbox->end_datagram);
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   113
    }
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   114
#endif
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   115
}
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   116
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   117
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   121
   Prepares a mailbox-send datagram.
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   122
   \return Pointer to mailbox datagram data, or ERR_PTR() code.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   123
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   124
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   125
uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t* slave, /** slave */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   126
                                    ec_mailbox_t* mbox, /** mailbox */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   127
                                    uint8_t type, /**< mailbox protocol */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   128
                                    size_t size /**< size of the data */
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
                                    )
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
{
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   131
    ec_datagram_t* datagram = mbox->datagram;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    size_t total_size;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   133
    int ret;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   135
    if (unlikely(!slave->sii.mailbox_protocols)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
   136
        EC_SLAVE_ERR(slave, "Slave does not support mailbox"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
   137
                " communication!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   138
        return ERR_PTR(-EPROTONOSUPPORT);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
1217
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   141
    total_size = EC_MBOX_HEADER_SIZE + size;
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   142
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   143
    if (unlikely(total_size > slave->configured_rx_mailbox_size)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
   144
        EC_SLAVE_ERR(slave, "Data size (%zu) does not fit in mailbox (%u)!\n",
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   145
                total_size, slave->configured_rx_mailbox_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   146
        return ERR_PTR(-EOVERFLOW);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   147
    }
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   148
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   149
    ret = ec_datagram_fpwr(datagram, slave->station_address,
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   150
                           slave->configured_rx_mailbox_offset,
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   151
#ifdef EC_REDUCE_MBOXFRAMESIZE
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   152
                           total_size
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   153
#else
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   154
                           slave->configured_rx_mailbox_size
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   155
#endif
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   156
                           );
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   157
    if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   158
        return ERR_PTR(ret);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   159
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   160
    EC_WRITE_U16(datagram->data,     size); // mailbox service data length
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   161
    EC_WRITE_U16(datagram->data + 2, slave->station_address); // station addr.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   162
    EC_WRITE_U8 (datagram->data + 4, 0x00); // channel & priority
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   163
    EC_WRITE_U8 (datagram->data + 5, type); // underlying protocol type
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   164
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   165
#ifdef EC_REDUCE_MBOXFRAMESIZE
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   166
    /* in order to fulfil the ESC's mailbox protocol,
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   167
       at least the last byte of the mailbox must be written */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   168
    if (total_size < slave->configured_rx_mailbox_size) {
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   169
        ret = ec_datagram_fpwr(&mbox->end_datagram, slave->station_address,
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   170
            slave->configured_rx_mailbox_offset+slave->configured_rx_mailbox_size-1,
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   171
            1);
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   172
        if (ret)
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   173
            return ERR_PTR(ret);
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   174
    }
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   175
#endif
1217
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   176
    return datagram->data + EC_MBOX_HEADER_SIZE;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   177
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   178
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   179
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   180
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   181
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   182
   Prepares a datagram for checking the mailbox state.
786
ad618c76e9bd Updated doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 504
diff changeset
   183
   \todo Determine sync manager used for receive mailbox
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   184
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   185
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   186
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   187
int ec_slave_mbox_prepare_check(const ec_slave_t* slave, /** slave */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   188
                                ec_mailbox_t* mbox /** mailbox */
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   189
                                )
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   190
{
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   191
    ec_datagram_t* datagram = mbox->datagram;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   192
    int ret = ec_datagram_fprd(datagram, slave->station_address, 0x808, 8);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   193
    if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   194
        return ret;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1217
diff changeset
   196
    ec_datagram_zero(datagram);
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   197
#ifdef EC_REDUCE_MBOXFRAMESIZE
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   198
    mbox->end_datagram.type = EC_DATAGRAM_NONE;
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   199
#endif
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
    return 0;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   206
   Processes a mailbox state checking datagram.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   207
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   208
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   209
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   210
int ec_slave_mbox_check(ec_mailbox_t* mbox /** mailbox */)
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   211
{
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   212
    return EC_READ_U8(mbox->datagram->data + 5) & 8 ? 1 : 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   213
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   214
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   215
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   216
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   217
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   218
   Prepares a datagram to fetch mailbox data.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   219
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   220
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   221
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   222
int ec_slave_mbox_prepare_fetch(const ec_slave_t* slave, /** slave */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   223
                                ec_mailbox_t* mbox /** mailbox */
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   224
                                )
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   225
{
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   226
    ec_datagram_t* datagram = mbox->datagram;
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   227
    int ret = ec_datagram_fprd(datagram, slave->station_address,
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   228
            slave->configured_tx_mailbox_offset,
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   229
            slave->configured_tx_mailbox_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   230
    if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   231
        return ret;
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1217
diff changeset
   232
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1217
diff changeset
   233
    ec_datagram_zero(datagram);
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   234
#ifdef EC_REDUCE_MBOXFRAMESIZE
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   235
    mbox->end_datagram.type = EC_DATAGRAM_NONE;
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   236
#endif
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
    return 0;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
/**
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   243
   Mailbox error codes.
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   244
*/
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   245
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   246
const ec_code_msg_t mbox_error_messages[] = {
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   247
    {0x00000001, "MBXERR_SYNTAX"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   248
    {0x00000002, "MBXERR_UNSUPPORTEDPROTOCOL"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   249
    {0x00000003, "MBXERR_INVAILDCHANNEL"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   250
    {0x00000004, "MBXERR_SERVICENOTSUPPORTED"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   251
    {0x00000005, "MBXERR_INVALIDHEADER"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   252
    {0x00000006, "MBXERR_SIZETOOSHORT"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   253
    {0x00000007, "MBXERR_NOMOREMEMORY"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   254
    {0x00000008, "MBXERR_INVALIDSIZE"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   255
    {}
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   256
};
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   257
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   258
/*****************************************************************************/
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   259
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   260
/** Processes received mailbox data.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   261
 *
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   262
 * \return Pointer to the received data, or ERR_PTR() code.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   263
 */
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   264
uint8_t *ec_slave_mbox_fetch(const ec_slave_t* slave, /** slave */
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   265
                             ec_mailbox_t* mbox, /** mailbox */
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   266
                             uint8_t *type, /**< expected mailbox protocol */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   267
                             size_t *size /**< size of the received data */
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
                             )
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
{
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 1921
diff changeset
   270
    ec_datagram_t* datagram = mbox->datagram;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    size_t data_size;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
431
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   273
    data_size = EC_READ_U16(datagram->data);
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   274
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   275
    if (data_size + EC_MBOX_HEADER_SIZE > slave->configured_tx_mailbox_size) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
   276
        EC_SLAVE_ERR(slave, "Corrupt mailbox response received!\n");
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   277
        ec_print_data(datagram->data, slave->configured_tx_mailbox_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   278
        return ERR_PTR(-EPROTO);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   279
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   280
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   281
    *type = EC_READ_U8(datagram->data + 5) & 0x0F;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   282
    *size = data_size;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   283
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   284
    if (*type == 0x00) {
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   285
        const ec_code_msg_t *mbox_msg;
1217
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   286
        uint16_t code = EC_READ_U16(datagram->data + 8);
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   287
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
   288
        EC_SLAVE_ERR(slave, "Mailbox error response received - ");
1217
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   289
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   290
        for (mbox_msg = mbox_error_messages; mbox_msg->code; mbox_msg++) {
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   291
            if (mbox_msg->code != code)
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   292
                continue;
431
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   293
            printk("Code 0x%04X: \"%s\".\n",
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   294
                    mbox_msg->code, mbox_msg->message);
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   295
            break;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   296
        }
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   297
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   298
        if (!mbox_msg->code)
431
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   299
            printk("Unknown error reply code 0x%04X.\n", code);
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   300
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   301
        if (slave->master->debug_level)
1217
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   302
            ec_print_data(datagram->data + EC_MBOX_HEADER_SIZE, data_size);
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   303
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   304
        return ERR_PTR(-EPROTO);
1217
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   305
    }
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   306
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   307
    return datagram->data + EC_MBOX_HEADER_SIZE;
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   308
}
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   309
e8a9785e63c3 Introduced EC_MBOX_HEADER_SIZE.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   310
/*****************************************************************************/