master/voe_handler.c
author Florian Pose <fp@igh.de>
Fri, 08 Sep 2017 14:39:38 +0200
branchstable-1.5
changeset 2685 740291442c05
parent 2522 ec403cf308eb
permissions -rw-r--r--
Added clean igb driver from kernel 3.18 (no EtherCAT yet).
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
8be462afb7f4 Added VoE handler.
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: 1315
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
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: 1315
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: 1315
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: 1315
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: 1315
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: 1315
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: 1315
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: 1315
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: 1315
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: 1315
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: 1315
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: 1315
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1348
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1348
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1348
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: 1348
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: 1348
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/** \file
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    31
 * Vendor specific over EtherCAT protocol handler functions.
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include <linux/module.h>
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "master.h"
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "slave_config.h"
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "mailbox.h"
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "voe_handler.h"
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
1216
e70c4d71cebd Changed VoE mailbox type to 0xff.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
    43
/** VoE mailbox type.
e70c4d71cebd Changed VoE mailbox type to 0xff.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
    44
 */
1224
784bb76105cd Fixed VoE mailbox type.
Florian Pose <fp@igh-essen.com>
parents: 1218
diff changeset
    45
#define EC_MBOX_TYPE_VOE 0x0f
1216
e70c4d71cebd Changed VoE mailbox type to 0xff.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
    46
1218
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
    47
/** VoE header size.
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
    48
 */
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
    49
#define EC_VOE_HEADER_SIZE 6
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
    50
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
/** VoE response timeout in [ms].
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
 */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
#define EC_VOE_RESPONSE_TIMEOUT 500
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
void ec_voe_handler_state_write_start(ec_voe_handler_t *);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
void ec_voe_handler_state_write_response(ec_voe_handler_t *);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
void ec_voe_handler_state_read_start(ec_voe_handler_t *);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
void ec_voe_handler_state_read_check(ec_voe_handler_t *);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
void ec_voe_handler_state_read_response(ec_voe_handler_t *);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    64
void ec_voe_handler_state_read_nosync_start(ec_voe_handler_t *);
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    65
void ec_voe_handler_state_read_nosync_response(ec_voe_handler_t *);
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    66
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
void ec_voe_handler_state_end(ec_voe_handler_t *);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
void ec_voe_handler_state_error(ec_voe_handler_t *);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
/** VoE handler constructor.
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    73
 *
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    74
 * \return Return value of ec_datagram_prealloc().
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
 */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
int ec_voe_handler_init(
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        ec_voe_handler_t *voe, /**< VoE handler. */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
        ec_slave_config_t *sc, /**< Parent slave configuration. */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        size_t size /**< Size of memory to reserve. */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        )
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    voe->config = sc;
1218
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
    83
    voe->vendor_id = 0x00000000;
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
    84
    voe->vendor_type = 0x0000;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    voe->data_size = 0;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    voe->dir = EC_DIR_INVALID;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    voe->request_state = EC_INT_REQUEST_INIT;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    ec_datagram_init(&voe->datagram);
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    91
    return ec_datagram_prealloc(&voe->datagram,
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    92
            size + EC_MBOX_HEADER_SIZE + EC_VOE_HEADER_SIZE);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
/** VoE handler destructor.
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
 */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
void ec_voe_handler_clear(
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        ec_voe_handler_t *voe /**< VoE handler. */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
        )
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    ec_datagram_clear(&voe->datagram);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1226
diff changeset
   106
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1226
diff changeset
   107
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1226
diff changeset
   108
/** Get usable memory size.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   109
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
   110
 * \return Memory size.
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1226
diff changeset
   111
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1226
diff changeset
   112
size_t ec_voe_handler_mem_size(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   113
        const ec_voe_handler_t *voe /**< VoE handler. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   114
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   115
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   116
    if (voe->datagram.mem_size >= EC_MBOX_HEADER_SIZE + EC_VOE_HEADER_SIZE)
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   117
        return voe->datagram.mem_size -
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   118
            (EC_MBOX_HEADER_SIZE + EC_VOE_HEADER_SIZE);
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   119
    else
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   120
        return 0;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1226
diff changeset
   121
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1226
diff changeset
   122
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
/*****************************************************************************
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
 * Application interface.
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
 ****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
1226
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   127
void ecrt_voe_handler_send_header(ec_voe_handler_t *voe, uint32_t vendor_id,
1218
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   128
        uint16_t vendor_type)
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   129
{
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   130
    voe->vendor_id = vendor_id;
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   131
    voe->vendor_type = vendor_type;
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   132
}
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   133
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   134
/*****************************************************************************/
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   135
1226
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   136
void ecrt_voe_handler_received_header(const ec_voe_handler_t *voe,
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   137
        uint32_t *vendor_id, uint16_t *vendor_type)
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   138
{
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   139
    uint8_t *header = voe->datagram.data + EC_MBOX_HEADER_SIZE;
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   140
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   141
    if (vendor_id)
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   142
        *vendor_id = EC_READ_U32(header);
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   143
    if (vendor_type)
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   144
        *vendor_type = EC_READ_U16(header + 4);
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   145
}
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   146
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   147
/*****************************************************************************/
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   148
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
uint8_t *ecrt_voe_handler_data(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
{
1218
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   151
    return voe->datagram.data + EC_MBOX_HEADER_SIZE + EC_VOE_HEADER_SIZE;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
size_t ecrt_voe_handler_data_size(const ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    return voe->data_size;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
void ecrt_voe_handler_read(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    voe->dir = EC_DIR_INPUT;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    voe->state = ec_voe_handler_state_read_start;
1348
8db0f72ace11 Fixed usage of internal request states.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   167
    voe->request_state = EC_INT_REQUEST_BUSY;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   172
void ecrt_voe_handler_read_nosync(ec_voe_handler_t *voe)
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   173
{
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   174
    voe->dir = EC_DIR_INPUT;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   175
    voe->state = ec_voe_handler_state_read_nosync_start;
1348
8db0f72ace11 Fixed usage of internal request states.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   176
    voe->request_state = EC_INT_REQUEST_BUSY;
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   177
}
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   178
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   179
/*****************************************************************************/
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   180
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
void ecrt_voe_handler_write(ec_voe_handler_t *voe, size_t size)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    voe->dir = EC_DIR_OUTPUT;
1218
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   184
    voe->data_size = size;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
    voe->state = ec_voe_handler_state_write_start;
1348
8db0f72ace11 Fixed usage of internal request states.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   186
    voe->request_state = EC_INT_REQUEST_BUSY;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
ec_request_state_t ecrt_voe_handler_execute(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
{
1348
8db0f72ace11 Fixed usage of internal request states.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   193
    if (voe->config->slave) { // FIXME locking?
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
        voe->state(voe);
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   195
        if (voe->request_state == EC_INT_REQUEST_BUSY) {
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   196
            ec_master_queue_datagram(voe->config->master, &voe->datagram);
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   197
        }
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    } else {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
        voe->request_state = EC_INT_REQUEST_FAILURE;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
    return ec_request_state_translation_table[voe->request_state];
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
/******************************************************************************
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
 * State functions.
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
 *****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   210
/** Start writing VoE data.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   211
 */
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
void ec_voe_handler_state_write_start(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
    ec_slave_t *slave = voe->config->slave;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
    uint8_t *data;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
    if (slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   218
        EC_SLAVE_DBG(slave, 0, "Writing %zu bytes of VoE data.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   219
               voe->data_size);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
        ec_print_data(ecrt_voe_handler_data(voe), voe->data_size);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
    if (!(slave->sii.mailbox_protocols & EC_MBOX_VOE)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   224
        EC_SLAVE_ERR(slave, "Slave does not support VoE!\n");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
        voe->request_state = EC_INT_REQUEST_FAILURE;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
    }
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   229
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   230
    data = ec_slave_mbox_prepare_send(slave, &voe->datagram,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   231
            EC_MBOX_TYPE_VOE, EC_VOE_HEADER_SIZE + voe->data_size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   232
    if (IS_ERR(data)) {
1218
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   233
        voe->state = ec_voe_handler_state_error;
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   234
        voe->request_state = EC_INT_REQUEST_FAILURE;
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   235
        return;
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   236
    }
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   237
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   238
    EC_WRITE_U32(data,     voe->vendor_id);
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   239
    EC_WRITE_U16(data + 4, voe->vendor_type);
1550
81a16ba13ae6 Avoid zeroing mailbox datagram because of VoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   240
    /* data already in datagram */
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
    voe->retries = EC_FSM_RETRIES;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
    voe->jiffies_start = jiffies;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
    voe->state = ec_voe_handler_state_write_response;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   249
/** Wait for the mailbox response.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   250
 */
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
void ec_voe_handler_state_write_response(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
    ec_datagram_t *datagram = &voe->datagram;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
    ec_slave_t *slave = voe->config->slave;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && voe->retries--)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   262
        EC_SLAVE_ERR(slave, "Failed to receive VoE write request datagram: ");
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1551
diff changeset
   263
        ec_datagram_print_state(datagram);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
    if (datagram->working_counter != 1) {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
        if (!datagram->working_counter) {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
            unsigned long diff_ms =
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
                (jiffies - voe->jiffies_start) * 1000 / HZ;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
            if (diff_ms < EC_VOE_RESPONSE_TIMEOUT) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   272
                EC_SLAVE_DBG(slave, 1, "Slave did not respond to"
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   273
                        " VoE write request. Retrying after %lu ms...\n",
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   274
                        diff_ms);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
                // no response; send request datagram again
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
                return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
            }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
        }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   281
        EC_SLAVE_ERR(slave, "Reception of VoE write request failed: ");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
        ec_datagram_print_wc_error(datagram);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   286
    EC_CONFIG_DBG(voe->config, 1, "VoE write request successful.\n");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
    voe->request_state = EC_INT_REQUEST_SUCCESS;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
    voe->state = ec_voe_handler_state_end;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   294
/** Start reading VoE data.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   295
 */
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
void ec_voe_handler_state_read_start(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
    ec_datagram_t *datagram = &voe->datagram;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
    ec_slave_t *slave = voe->config->slave;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   301
    EC_SLAVE_DBG(slave, 1, "Reading VoE data.\n");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
    if (!(slave->sii.mailbox_protocols & EC_MBOX_VOE)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   304
        EC_SLAVE_ERR(slave, "Slave does not support VoE!\n");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
        voe->request_state = EC_INT_REQUEST_FAILURE;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
    }
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   309
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
    voe->jiffies_start = jiffies;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
    voe->retries = EC_FSM_RETRIES;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
    voe->state = ec_voe_handler_state_read_check;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   319
/** Check for new data in the mailbox.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   320
 */
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
void ec_voe_handler_state_read_check(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
    ec_datagram_t *datagram = &voe->datagram;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
    ec_slave_t *slave = voe->config->slave;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && voe->retries--)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   332
        EC_SLAVE_ERR(slave, "Failed to receive VoE mailbox check datagram: ");
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1551
diff changeset
   333
        ec_datagram_print_state(datagram);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
    if (datagram->working_counter != 1) {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   340
        EC_SLAVE_ERR(slave, "Reception of VoE mailbox check"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   341
                " datagram failed: ");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
        ec_datagram_print_wc_error(datagram);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
    if (!ec_slave_mbox_check(datagram)) {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
        unsigned long diff_ms =
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
            (datagram->jiffies_received - voe->jiffies_start) * 1000 / HZ;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
        if (diff_ms >= EC_VOE_RESPONSE_TIMEOUT) {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
            voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
            voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   352
            EC_SLAVE_ERR(slave, "Timeout while waiting for VoE data.\n");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
            return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
        }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
        voe->retries = EC_FSM_RETRIES;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   360
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
    // Fetch response
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
    voe->retries = EC_FSM_RETRIES;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
    voe->state = ec_voe_handler_state_read_response;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   369
/** Read the pending mailbox data.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   370
 */
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
void ec_voe_handler_state_read_response(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   372
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
    ec_datagram_t *datagram = &voe->datagram;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
    ec_slave_t *slave = voe->config->slave;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
    ec_master_t *master = voe->config->master;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
    uint8_t *data, mbox_prot;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
    size_t rec_size;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && voe->retries--)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   382
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   383
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   385
        EC_SLAVE_ERR(slave, "Failed to receive VoE read datagram: ");
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1551
diff changeset
   386
        ec_datagram_print_state(datagram);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   388
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   389
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
    if (datagram->working_counter != 1) {
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   392
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   393
        EC_SLAVE_ERR(slave, "Reception of VoE read response failed: ");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
        ec_datagram_print_wc_error(datagram);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   396
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   397
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   398
    data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   399
    if (IS_ERR(data)) {
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   400
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
        voe->request_state = EC_INT_REQUEST_FAILURE;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   403
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
1216
e70c4d71cebd Changed VoE mailbox type to 0xff.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   405
    if (mbox_prot != EC_MBOX_TYPE_VOE) {
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
        voe->state = ec_voe_handler_state_error;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   407
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   408
        EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   409
                " as response.\n", mbox_prot);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   410
        ec_print_data(data, rec_size);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   411
        return;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   412
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   413
1218
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   414
    if (rec_size < EC_VOE_HEADER_SIZE) {
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   415
        voe->state = ec_voe_handler_state_error;
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   416
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   417
        EC_SLAVE_ERR(slave, "Received VoE header is"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   418
                " incomplete (%zu bytes)!\n", rec_size);
1218
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   419
        return;
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   420
    }
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   421
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
    if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   423
        EC_CONFIG_DBG(voe->config, 0, "VoE data:\n");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
        ec_print_data(data, rec_size);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
    }
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
1218
6f3a973fc29e Introduced VoE header.
Florian Pose <fp@igh-essen.com>
parents: 1216
diff changeset
   427
    voe->data_size = rec_size - EC_VOE_HEADER_SIZE;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   428
    voe->request_state = EC_INT_REQUEST_SUCCESS;
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   429
    voe->state = ec_voe_handler_state_end; // success
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   430
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   434
/** Start reading VoE data without sending a sync message before.
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   435
 */
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   436
void ec_voe_handler_state_read_nosync_start(ec_voe_handler_t *voe)
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   437
{
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   438
    ec_datagram_t *datagram = &voe->datagram;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   439
    ec_slave_t *slave = voe->config->slave;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   440
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   441
    EC_SLAVE_DBG(slave, 1, "Reading VoE data.\n");
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   442
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   443
    if (!(slave->sii.mailbox_protocols & EC_MBOX_VOE)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   444
        EC_SLAVE_ERR(slave, "Slave does not support VoE!\n");
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   445
        voe->state = ec_voe_handler_state_error;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   446
        voe->request_state = EC_INT_REQUEST_FAILURE;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   447
        return;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   448
    }
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   449
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   450
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   451
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   452
    voe->jiffies_start = jiffies;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   453
    voe->retries = EC_FSM_RETRIES;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   454
    voe->state = ec_voe_handler_state_read_nosync_response;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   455
}
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   456
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   457
/*****************************************************************************/
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   458
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   459
/** Read the pending mailbox data without sending a sync message before. This
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   460
 *  might lead to an empty reponse from the client.
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   461
 */
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   462
void ec_voe_handler_state_read_nosync_response(ec_voe_handler_t *voe)
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   463
{
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   464
    ec_datagram_t *datagram = &voe->datagram;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   465
    ec_slave_t *slave = voe->config->slave;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   466
    ec_master_t *master = voe->config->master;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   467
    uint8_t *data, mbox_prot;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   468
    size_t rec_size;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   469
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   470
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && voe->retries--)
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   471
        return;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   472
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   473
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   474
        voe->state = ec_voe_handler_state_error;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   475
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   476
        EC_SLAVE_ERR(slave, "Failed to receive VoE read datagram: ");
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1551
diff changeset
   477
        ec_datagram_print_state(datagram);
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   478
        return;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   479
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   480
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   481
    if (datagram->working_counter == 0) {
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   482
        voe->state = ec_voe_handler_state_error;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   483
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   484
        EC_SLAVE_DBG(slave, 1, "Slave did not send VoE data.\n");
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   485
        return;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   486
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   487
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   488
    if (datagram->working_counter != 1) {
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   489
        voe->state = ec_voe_handler_state_error;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   490
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   491
        EC_SLAVE_WARN(slave, "Reception of VoE read response failed: ");
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   492
        ec_datagram_print_wc_error(datagram);
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   493
        return;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   494
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   495
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   496
    if (!(data = ec_slave_mbox_fetch(slave, datagram,
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   497
                    &mbox_prot, &rec_size))) {
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   498
        voe->state = ec_voe_handler_state_error;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   499
        voe->request_state = EC_INT_REQUEST_FAILURE;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   500
        return;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   501
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   502
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   503
    if (mbox_prot != EC_MBOX_TYPE_VOE) {
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   504
        voe->state = ec_voe_handler_state_error;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   505
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   506
        EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   507
                " as response.\n", mbox_prot);
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   508
        ec_print_data(data, rec_size);
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   509
        return;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   510
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   511
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   512
    if (rec_size < EC_VOE_HEADER_SIZE) {
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   513
        voe->state = ec_voe_handler_state_error;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   514
        voe->request_state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   515
        EC_SLAVE_ERR(slave, "Received VoE header is"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   516
                " incomplete (%zu bytes)!\n", rec_size);
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   517
        return;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   518
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   519
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   520
    if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   521
        EC_CONFIG_DBG(voe->config, 1, "VoE data:\n");
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   522
        ec_print_data(data, rec_size);
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   523
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   524
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   525
    voe->data_size = rec_size - EC_VOE_HEADER_SIZE;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   526
    voe->request_state = EC_INT_REQUEST_SUCCESS;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   527
    voe->state = ec_voe_handler_state_end; // success
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   528
}
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   529
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   530
/*****************************************************************************/
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
   531
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   532
/** Successful termination state function.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   533
 */
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   534
void ec_voe_handler_state_end(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   535
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   536
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   537
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   538
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   539
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   540
/** Failure termination state function.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   541
 */
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   542
void ec_voe_handler_state_error(ec_voe_handler_t *voe)
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   543
{
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   544
}
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   545
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   546
/*****************************************************************************/
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   547
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   548
/** \cond */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   549
1226
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   550
EXPORT_SYMBOL(ecrt_voe_handler_send_header);
afb189516fcf Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents: 1224
diff changeset
   551
EXPORT_SYMBOL(ecrt_voe_handler_received_header);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   552
EXPORT_SYMBOL(ecrt_voe_handler_data);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   553
EXPORT_SYMBOL(ecrt_voe_handler_data_size);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   554
EXPORT_SYMBOL(ecrt_voe_handler_read);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   555
EXPORT_SYMBOL(ecrt_voe_handler_write);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   556
EXPORT_SYMBOL(ecrt_voe_handler_execute);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   557
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   558
/** \endcond */
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   559
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   560
/*****************************************************************************/