master/fsm_sii.c
author Martin Troxler <martin.troxler@komaxgroup.com>
Mon, 23 Nov 2009 14:22:48 +0100
changeset 1582 7273aa7deb3d
parent 1507 68e89abadd19
child 1583 017fa8fd9ac1
permissions -rw-r--r--
Fixed SDO up/download kernel oops bug
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
100f51f28cf2 Layed out SII state machine.
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: 1225
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
100f51f28cf2 Layed out SII state machine.
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
   \file
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
   EtherCAT slave information interface FSM.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "globals.h"
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "mailbox.h"
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "master.h"
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "fsm_sii.h"
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
1123
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    42
/** Read/write timeout [ms].
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    43
 *
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    44
 * Used to calculate timeouts bsed on the jiffies counter.
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    45
 *
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    46
 * \attention Must be more than 10 to avoid problems on kernels that run with
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    47
 * a timer interupt frequency of 100 Hz.
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 755
diff changeset
    48
 */
1123
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    49
#define SII_TIMEOUT 20
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    50
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    51
/** Time before evaluating answer at writing [ms].
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 755
diff changeset
    52
 */
1123
17bef224061d Fixed SII reading timeout bug on 100 Hz kernels.
Florian Pose <fp@igh-essen.com>
parents: 1039
diff changeset
    53
#define SII_INHIBIT 5
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
    54
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
    55
//#define SII_DEBUG
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
    56
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    59
void ec_fsm_sii_state_start_reading(ec_fsm_sii_t *);
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    60
void ec_fsm_sii_state_read_check(ec_fsm_sii_t *);
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    61
void ec_fsm_sii_state_read_fetch(ec_fsm_sii_t *);
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    62
void ec_fsm_sii_state_start_writing(ec_fsm_sii_t *);
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    63
void ec_fsm_sii_state_write_check(ec_fsm_sii_t *);
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    64
void ec_fsm_sii_state_write_check2(ec_fsm_sii_t *);
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    65
void ec_fsm_sii_state_end(ec_fsm_sii_t *);
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    66
void ec_fsm_sii_state_error(ec_fsm_sii_t *);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
   Constructor.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
void ec_fsm_sii_init(ec_fsm_sii_t *fsm, /**< finite state machine */
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
                     ec_datagram_t *datagram /**< datagram structure to use */
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
                     )
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    fsm->state = NULL;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    fsm->datagram = datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
   Destructor.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
void ec_fsm_sii_clear(ec_fsm_sii_t *fsm /**< finite state machine */)
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
   Initializes the SII read state machine.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
void ec_fsm_sii_read(ec_fsm_sii_t *fsm, /**< finite state machine */
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
                     ec_slave_t *slave, /**< slave to read from */
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   100
                     uint16_t word_offset, /**< offset to read from */
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
                     ec_fsm_sii_addressing_t mode /**< addressing scheme */
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
                     )
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
{
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   104
    fsm->state = ec_fsm_sii_state_start_reading;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    fsm->slave = slave;
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   106
    fsm->word_offset = word_offset;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    fsm->mode = mode;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
   Initializes the SII write state machine.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
void ec_fsm_sii_write(ec_fsm_sii_t *fsm, /**< finite state machine */
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
                      ec_slave_t *slave, /**< slave to read from */
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   118
                      uint16_t word_offset, /**< offset to read from */
979
405cc2d033e0 Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   119
                      const uint16_t *value, /**< pointer to 2 bytes of data */
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
                      ec_fsm_sii_addressing_t mode /**< addressing scheme */
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
                      )
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
{
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   123
    fsm->state = ec_fsm_sii_state_start_writing;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    fsm->slave = slave;
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   125
    fsm->word_offset = word_offset;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    fsm->mode = mode;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    memcpy(fsm->value, value, 2);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
   Executes the SII state machine.
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   134
   \return false, if the state machine has terminated
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   135
*/
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   136
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   137
int ec_fsm_sii_exec(ec_fsm_sii_t *fsm /**< finite state machine */)
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    fsm->state(fsm);
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   140
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   141
    return fsm->state != ec_fsm_sii_state_end
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   142
        && fsm->state != ec_fsm_sii_state_error;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
   Returns, if the master startup state machine terminated with success.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
   \return non-zero if successful.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
int ec_fsm_sii_success(ec_fsm_sii_t *fsm /**< Finite state machine */)
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
{
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   154
    return fsm->state == ec_fsm_sii_state_end;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
/******************************************************************************
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   158
 * state functions
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
 *****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
   SII state: START READING.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
   Starts reading the slave information interface.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   166
void ec_fsm_sii_state_start_reading(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   167
        ec_fsm_sii_t *fsm /**< finite state machine */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   168
        )
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
    // initiate read operation
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    switch (fsm->mode) {
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   174
        case EC_FSM_SII_USE_INCREMENT_ADDRESS:
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
            ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x502, 4);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
            break;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   177
        case EC_FSM_SII_USE_CONFIGURED_ADDRESS:
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   178
            ec_datagram_fpwr(datagram, fsm->slave->station_address, 0x502, 4);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
            break;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   182
    EC_WRITE_U8 (datagram->data,     0x80); // two address octets
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    EC_WRITE_U8 (datagram->data + 1, 0x01); // request read operation
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   184
    EC_WRITE_U16(datagram->data + 2, fsm->word_offset);
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   185
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   186
#ifdef SII_DEBUG
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   187
    EC_DBG("reading SII data:\n");
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   188
    ec_print_data(datagram->data, 4);
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   189
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   190
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   191
    fsm->retries = EC_FSM_RETRIES;
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   192
    fsm->state = ec_fsm_sii_state_read_check;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
   SII state: READ CHECK.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
   Checks, if the SII-read-datagram has been sent and issues a fetch datagram.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   202
void ec_fsm_sii_state_read_check(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   203
        ec_fsm_sii_t *fsm /**< finite state machine */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   204
        )
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   208
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   209
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   210
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   211
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   212
        fsm->state = ec_fsm_sii_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   213
        EC_ERR("Failed to receive SII read datagram from slave %u"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   214
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   215
               fsm->slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   216
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   217
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   218
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   219
    if (datagram->working_counter != 1) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   220
        fsm->state = ec_fsm_sii_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   221
        EC_ERR("Reception of SII read datagram failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   222
                fsm->slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   223
        ec_datagram_print_wc_error(datagram);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
1039
2881a83d084f Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   227
    fsm->jiffies_start = datagram->jiffies_sent;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
    fsm->check_once_more = 1;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
    // issue check/fetch datagram
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
    switch (fsm->mode) {
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   232
        case EC_FSM_SII_USE_INCREMENT_ADDRESS:
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
            ec_datagram_aprd(datagram, fsm->slave->ring_position, 0x502, 10);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
            break;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   235
        case EC_FSM_SII_USE_CONFIGURED_ADDRESS:
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   236
            ec_datagram_fprd(datagram, fsm->slave->station_address, 0x502, 10);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
            break;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
    }
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   239
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1123
diff changeset
   240
    ec_datagram_zero(datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   241
    fsm->retries = EC_FSM_RETRIES;
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   242
    fsm->state = ec_fsm_sii_state_read_fetch;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
   SII state: READ FETCH.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
   Fetches the result of an SII-read datagram.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   252
void ec_fsm_sii_state_read_fetch(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   253
        ec_fsm_sii_t *fsm /**< finite state machine */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   254
        )
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   258
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   259
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   260
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   261
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   262
        fsm->state = ec_fsm_sii_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   263
        EC_ERR("Failed to receive SII check/fetch datagram from slave %u"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   264
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   265
               fsm->slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   266
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   267
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   268
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   269
    if (datagram->working_counter != 1) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   270
        fsm->state = ec_fsm_sii_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   271
        EC_ERR("Reception of SII check/fetch datagram failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   272
                fsm->slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   273
        ec_datagram_print_wc_error(datagram);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   277
#ifdef SII_DEBUG
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   278
    EC_DBG("checking SII read state:\n");
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   279
    ec_print_data(datagram->data, 10);
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   280
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   281
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   282
    if (EC_READ_U8(datagram->data + 1) & 0x20) {
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   283
        EC_ERR("SII: Error on last SII command!\n");
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   284
        fsm->state = ec_fsm_sii_state_error;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   285
        return;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   286
    }
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   287
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
    // check "busy bit"
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   289
    if (EC_READ_U8(datagram->data + 1) & 0x81) { /* busy bit or
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   290
                                                    read operation busy */
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
        // still busy... timeout?
1039
2881a83d084f Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   292
        unsigned long diff_ms =
2881a83d084f Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   293
            (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
2881a83d084f Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   294
        if (diff_ms >= SII_TIMEOUT) {
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   295
            if (fsm->check_once_more) {
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   296
                fsm->check_once_more = 0;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   297
            } else {
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
                EC_ERR("SII: Read timeout.\n");
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   299
                fsm->state = ec_fsm_sii_state_error;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
                return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
            }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
        }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
        // issue check/fetch datagram again
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   305
        fsm->retries = EC_FSM_RETRIES;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
    // SII value received.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
    memcpy(fsm->value, datagram->data + 6, 4);
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   311
    fsm->state = ec_fsm_sii_state_end;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
   SII state: START WRITING.
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   318
   Starts writing a word through the slave information interface.
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   321
void ec_fsm_sii_state_start_writing(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   322
        ec_fsm_sii_t *fsm /**< finite state machine */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   323
        )
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
    // initiate write operation
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   328
    ec_datagram_fpwr(datagram, fsm->slave->station_address, 0x502, 8);
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   329
    EC_WRITE_U8 (datagram->data,     0x81); /* two address octets
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   330
                                               + enable write access */
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
    EC_WRITE_U8 (datagram->data + 1, 0x02); // request write operation
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   332
    EC_WRITE_U16(datagram->data + 2, fsm->word_offset);
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   333
    memset(datagram->data + 4, 0x00, 2);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
    memcpy(datagram->data + 6, fsm->value, 2);
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   335
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   336
#ifdef SII_DEBUG
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   337
    EC_DBG("writing SII data:\n");
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   338
    ec_print_data(datagram->data, 8);
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   339
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   340
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   341
    fsm->retries = EC_FSM_RETRIES;
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   342
    fsm->state = ec_fsm_sii_state_write_check;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
   SII state: WRITE CHECK.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   351
void ec_fsm_sii_state_write_check(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   352
        ec_fsm_sii_t *fsm /**< finite state machine */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   353
        )
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   357
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   358
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   359
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   360
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   361
        fsm->state = ec_fsm_sii_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   362
        EC_ERR("Failed to receive SII write datagram for slave %u"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   363
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   364
               fsm->slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   365
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   366
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   367
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   368
    if (datagram->working_counter != 1) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   369
        fsm->state = ec_fsm_sii_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   370
        EC_ERR("Reception of SII write datagram failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   371
                fsm->slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   372
        ec_datagram_print_wc_error(datagram);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
1039
2881a83d084f Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   376
    fsm->jiffies_start = datagram->jiffies_sent;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
    fsm->check_once_more = 1;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   379
    // issue check datagram
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   380
    ec_datagram_fprd(datagram, fsm->slave->station_address, 0x502, 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1123
diff changeset
   381
    ec_datagram_zero(datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   382
    fsm->retries = EC_FSM_RETRIES;
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   383
    fsm->state = ec_fsm_sii_state_write_check2;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   386
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   388
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   389
   SII state: WRITE CHECK 2.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   392
void ec_fsm_sii_state_write_check2(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   393
        ec_fsm_sii_t *fsm /**< finite state machine */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   394
        )
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   396
    ec_datagram_t *datagram = fsm->datagram;
1039
2881a83d084f Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   397
    unsigned long diff_ms;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   398
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   399
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   400
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   401
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   402
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   403
        fsm->state = ec_fsm_sii_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   404
        EC_ERR("Failed to receive SII write check datagram from slave %u"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   405
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   406
               fsm->slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   407
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   408
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   409
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   410
    if (datagram->working_counter != 1) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   411
        fsm->state = ec_fsm_sii_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   412
        EC_ERR("Reception of SII write check datagram failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   413
                fsm->slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   414
        ec_datagram_print_wc_error(datagram);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   416
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   418
#ifdef SII_DEBUG
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   419
    EC_DBG("checking SII write state:\n");
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   420
    ec_print_data(datagram->data, 2);
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   421
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   422
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   423
    if (EC_READ_U8(datagram->data + 1) & 0x20) {
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   424
        EC_ERR("SII: Error on last SII command!\n");
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   425
        fsm->state = ec_fsm_sii_state_error;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   426
        return;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   427
    }
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   428
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   429
    /* FIXME: some slaves never answer with the busy flag set...
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   430
     * wait a few ms for the write operation to complete. */
1039
2881a83d084f Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   431
    diff_ms = (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
2881a83d084f Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   432
    if (diff_ms < SII_INHIBIT) {
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   433
#ifdef SII_DEBUG
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   434
        EC_DBG("too early.\n");
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   435
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   436
        // issue check datagram again
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   437
        fsm->retries = EC_FSM_RETRIES;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   438
        return;
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   439
    }
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   440
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   441
    if (EC_READ_U8(datagram->data + 1) & 0x82) { /* busy bit or
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   442
                                                    write operation busy bit */
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   443
        // still busy... timeout?
1039
2881a83d084f Use jiffies instead of cycles in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   444
        if (diff_ms >= SII_TIMEOUT) {
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   445
            if (fsm->check_once_more) {
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   446
                fsm->check_once_more = 0;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   447
            } else {
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
                EC_ERR("SII: Write timeout.\n");
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   449
                fsm->state = ec_fsm_sii_state_error;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
                return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
            }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
        }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   454
        // issue check datagram again
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   455
        fsm->retries = EC_FSM_RETRIES;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   457
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   459
    if (EC_READ_U8(datagram->data + 1) & 0x40) {
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
        EC_ERR("SII: Write operation failed!\n");
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   461
        fsm->state = ec_fsm_sii_state_error;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   464
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   465
    // success
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   466
    fsm->state = ec_fsm_sii_state_end;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   467
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   470
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   471
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   472
   State: ERROR.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   473
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   474
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   475
void ec_fsm_sii_state_error(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   476
        ec_fsm_sii_t *fsm /**< finite state machine */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   477
        )
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   478
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   479
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   480
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   481
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   482
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   483
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   484
   State: END.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   485
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   486
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   487
void ec_fsm_sii_state_end(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   488
        ec_fsm_sii_t *fsm /**< finite state machine */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   489
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   490
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   491
}
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   492
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   493
/*****************************************************************************/