master/mailbox.c
author Florian Pose <fp@igh-essen.com>
Tue, 20 Jan 2009 08:04:50 +0000
branch1.4-foe
changeset 1710 4522459bb5a4
parent 1709 63e4bc918640
child 1711 2b017fcc1c6d
permissions -rw-r--r--
merge -c1617 branches/stable-1.4
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
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
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    22
 *  Using the EtherCAT technology and brand is permitted in compliance with
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
    23
 *  the 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
    24
 *
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    27
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    28
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    29
   Mailbox functionality.
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
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    32
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    33
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <linux/slab.h>
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include <linux/delay.h>
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "mailbox.h"
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    38
#include "datagram.h"
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "master.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
/*****************************************************************************/
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
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    44
   Prepares a mailbox-send datagram.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    45
   \return pointer to mailbox datagram data
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
    46
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
    47
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
    48
uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *slave, /**< slave */
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    49
                                    ec_datagram_t *datagram, /**< datagram */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
    50
                                    uint8_t type, /**< mailbox protocol */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
    51
                                    size_t size /**< size of the data */
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
                                    )
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
{
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
    size_t total_size;
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    55
    uint16_t mailbox_offset, mailbox_size;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    57
    if (unlikely(!slave->sii.mailbox_protocols)) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
    58
        EC_ERR("Slave %u does not support mailbox communication!\n",
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
               slave->ring_position);
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
        return NULL;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
    }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    total_size = size + 6;
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    64
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    65
    if (slave->current_state != EC_SLAVE_STATE_BOOT) {
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    66
        mailbox_offset = slave->sii.std_rx_mailbox_offset;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    67
        mailbox_size = slave->sii.std_rx_mailbox_size;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    68
    } else {
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    69
        mailbox_offset = slave->sii.boot_rx_mailbox_offset;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    70
        mailbox_size = slave->sii.boot_rx_mailbox_size;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    71
    }
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    72
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    73
    if (unlikely(total_size > mailbox_size)) {
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
        EC_ERR("Data size does not fit in mailbox!\n");
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
        return NULL;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 786
diff changeset
    78
    if (ec_datagram_fpwr(datagram, slave->station_address,
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    79
                         mailbox_offset, mailbox_size))
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    80
        return NULL;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    81
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    82
    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
    83
    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
    84
    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
    85
    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
    86
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    87
    return datagram->data + 6;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    88
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    89
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    90
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    91
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    92
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    93
   Prepares a datagram for checking the mailbox state.
786
ad618c76e9bd Updated doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 504
diff changeset
    94
   \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
    95
   \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
    96
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
    97
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
    98
int ec_slave_mbox_prepare_check(const ec_slave_t *slave, /**< slave */
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    99
                                ec_datagram_t *datagram /**< datagram */
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   100
                                )
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   101
{
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 786
diff changeset
   102
    if (ec_datagram_fprd(datagram, slave->station_address, 0x808, 8))
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        return -1;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    return 0;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
/*****************************************************************************/
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
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   111
   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
   112
   \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
   113
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   114
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   115
int ec_slave_mbox_check(const ec_datagram_t *datagram /**< datagram */)
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   116
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   117
    return EC_READ_U8(datagram->data + 5) & 8 ? 1 : 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   118
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   119
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   120
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   121
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   122
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   123
   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
   124
   \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
   125
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   126
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   127
int ec_slave_mbox_prepare_fetch(const ec_slave_t *slave, /**< slave */
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   128
                                ec_datagram_t *datagram /**< datagram */
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   129
                                )
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   130
{
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   131
    uint16_t mailbox_offset, mailbox_size;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   132
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   133
    if (slave->current_state != EC_SLAVE_STATE_BOOT) {
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   134
        mailbox_offset = slave->sii.std_tx_mailbox_offset;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   135
        mailbox_size = slave->sii.std_tx_mailbox_size;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   136
    } else {
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   137
        mailbox_offset = slave->sii.boot_tx_mailbox_offset;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   138
        mailbox_size = slave->sii.boot_tx_mailbox_size;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   139
    }
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   140
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 786
diff changeset
   141
    if (ec_datagram_fprd(datagram, slave->station_address,
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   142
                         mailbox_offset, mailbox_size))
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   143
        return -1;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   144
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    return 0;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
/**
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   151
   Mailbox error codes.
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   152
*/
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   153
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   154
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
   155
    {0x00000001, "MBXERR_SYNTAX"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   156
    {0x00000002, "MBXERR_UNSUPPORTEDPROTOCOL"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   157
    {0x00000003, "MBXERR_INVAILDCHANNEL"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   158
    {0x00000004, "MBXERR_SERVICENOTSUPPORTED"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   159
    {0x00000005, "MBXERR_INVALIDHEADER"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   160
    {0x00000006, "MBXERR_SIZETOOSHORT"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   161
    {0x00000007, "MBXERR_NOMOREMEMORY"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   162
    {0x00000008, "MBXERR_INVALIDSIZE"},
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   163
    {}
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   164
};
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   165
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   166
/*****************************************************************************/
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   167
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   168
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   169
   Processes received mailbox data.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   170
   \return pointer to the received data
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   171
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 154
diff changeset
   172
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 276
diff changeset
   173
uint8_t *ec_slave_mbox_fetch(const ec_slave_t *slave, /**< slave */
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   174
                             ec_datagram_t *datagram, /**< datagram */
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   175
                             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
   176
                             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
   177
                             )
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
{
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
    size_t data_size;
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   180
    uint16_t mailbox_offset, mailbox_size;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   181
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   182
    if (slave->current_state != EC_SLAVE_STATE_BOOT) {
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   183
        mailbox_offset = slave->sii.std_tx_mailbox_offset;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   184
        mailbox_size = slave->sii.std_tx_mailbox_size;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   185
    } else {
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   186
        mailbox_offset = slave->sii.boot_tx_mailbox_offset;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   187
        mailbox_size = slave->sii.boot_tx_mailbox_size;
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   188
    }
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
431
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   190
    data_size = EC_READ_U16(datagram->data);
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   191
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   192
    if (data_size > mailbox_size - 6) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   193
        EC_ERR("Corrupt mailbox response received from slave %u!\n",
504
63d11bdfe3df Improved error messages in mailbox.c
Florian Pose <fp@igh-essen.com>
parents: 431
diff changeset
   194
               slave->ring_position);
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   195
        ec_print_data(datagram->data, mailbox_size);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   196
        return NULL;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   197
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   198
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   199
    *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
   200
    *size = data_size;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   201
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   202
    if (*type == 0x00) {
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   203
        const ec_code_msg_t *mbox_msg;
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   204
        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
   205
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   206
        EC_ERR("Mailbox error response received from slave %u - ",
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   207
                slave->ring_position);
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   208
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   209
        for (mbox_msg = mbox_error_messages; mbox_msg->code; mbox_msg++) {
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   210
            if (mbox_msg->code != code)
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   211
                continue;
431
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   212
            printk("Code 0x%04X: \"%s\".\n",
1709
63e4bc918640 Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   213
                    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
   214
            break;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   215
        }
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   216
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   217
        if (!mbox_msg->code)
431
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   218
            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
   219
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   220
        if (slave->master->debug_level)
47e7f99005c0 Improved output at mailbox error.
Florian Pose <fp@igh-essen.com>
parents: 424
diff changeset
   221
            ec_print_data(datagram->data + 6, data_size);
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   222
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
        return NULL;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
    }
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   226
    return datagram->data + 6;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   227
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   228
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   229
/*****************************************************************************/