master/fsm_sii.c
author Florian Pose <fp@igh-essen.com>
Mon, 24 Sep 2007 10:35:00 +0000
changeset 757 6210c4260899
parent 755 178353fc47e5
child 758 8fa6f825eb7d
permissions -rw-r--r--
Added Doxyfile to configuration files.
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
 *
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
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
 *
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  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
    22
 *
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
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
   \file
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT slave information interface FSM.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "globals.h"
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "mailbox.h"
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "master.h"
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "fsm_sii.h"
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
    46
#define EEPROM_TIMEOUT 10 // read/write timeout [ms]
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
    47
#define EEPROM_INHIBIT  5 // time before evaluating answer at writing [ms]
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
    48
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
    49
//#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
    50
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    53
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
    54
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
    55
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
    56
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
    57
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
    58
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
    59
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
    60
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
    61
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
   Constructor.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
*/
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
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
    69
                     ec_datagram_t *datagram /**< datagram structure to use */
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
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    fsm->state = NULL;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    fsm->datagram = datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
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
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
   Destructor.
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
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
    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
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
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
   Initializes the SII read state machine.
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
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
    93
                     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
    94
                     uint16_t word_offset, /**< offset to read from */
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
                     ec_fsm_sii_addressing_t mode /**< addressing scheme */
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
{
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    98
    fsm->state = ec_fsm_sii_state_start_reading;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    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
   100
    fsm->word_offset = word_offset;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    fsm->mode = mode;
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
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
   Initializes the SII write state machine.
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
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
   111
                      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
   112
                      uint16_t word_offset, /**< offset to read from */
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   113
                      const uint8_t *value, /**< pointer to 2 bytes of data */
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
                      ec_fsm_sii_addressing_t mode /**< addressing scheme */
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
{
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   117
    fsm->state = ec_fsm_sii_state_start_writing;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    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
   119
    fsm->word_offset = word_offset;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    fsm->mode = mode;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    memcpy(fsm->value, value, 2);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
   Executes the SII state machine.
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   128
   \return false, if the state machine has terminated
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   129
*/
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   130
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   131
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
   132
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    fsm->state(fsm);
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   134
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   135
    return fsm->state != ec_fsm_sii_state_end
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   136
		&& fsm->state != ec_fsm_sii_state_error;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
}
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
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
   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
   143
   \return non-zero if successful.
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
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
   147
{
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   148
    return fsm->state == ec_fsm_sii_state_end;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
}
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
/******************************************************************************
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   152
 * state functions
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
 *****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
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
   SII state: START READING.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
   Starts reading the slave information interface.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   160
void ec_fsm_sii_state_start_reading(
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   161
		ec_fsm_sii_t *fsm /**< finite state machine */
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   162
		)
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    // initiate read operation
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    switch (fsm->mode) {
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
        case EC_FSM_SII_POSITION:
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
            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
   170
            break;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
        case EC_FSM_SII_NODE:
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
            ec_datagram_npwr(datagram, fsm->slave->station_address, 0x502, 4);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
            break;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   176
    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
   177
    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
   178
    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
   179
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   180
#ifdef SII_DEBUG
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   181
	EC_DBG("reading SII data:\n");
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   182
	ec_print_data(datagram->data, 4);
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   183
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   184
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   185
    fsm->retries = EC_FSM_RETRIES;
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   186
    fsm->state = ec_fsm_sii_state_read_check;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
   SII state: READ CHECK.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
   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
   194
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   196
void ec_fsm_sii_state_read_check(
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   197
		ec_fsm_sii_t *fsm /**< finite state machine */
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   198
		)
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   202
    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
   203
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   204
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   205
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   206
        fsm->state = ec_fsm_sii_state_error;
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   207
        EC_ERR("Failed to receive SII read datagram from slave %i"
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   208
                " (datagram state %i).\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   209
               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
   210
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   211
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   212
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   213
    if (datagram->working_counter != 1) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   214
        fsm->state = ec_fsm_sii_state_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   215
        EC_ERR("Reception of SII read datagram failed on slave %i: ",
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   216
                fsm->slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   217
        ec_datagram_print_wc_error(datagram);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    fsm->cycles_start = datagram->cycles_sent;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
    fsm->check_once_more = 1;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
    // issue check/fetch datagram
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
    switch (fsm->mode) {
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
        case EC_FSM_SII_POSITION:
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
            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
   228
            break;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
        case EC_FSM_SII_NODE:
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
            ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 10);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
            break;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
    }
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   233
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   234
    fsm->retries = EC_FSM_RETRIES;
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   235
    fsm->state = ec_fsm_sii_state_read_fetch;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
   SII state: READ FETCH.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
   Fetches the result of an SII-read datagram.
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
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   245
void ec_fsm_sii_state_read_fetch(
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   246
		ec_fsm_sii_t *fsm /**< finite state machine */
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   247
		)
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
{
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   251
    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
   252
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   253
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   254
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   255
        fsm->state = ec_fsm_sii_state_error;
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   256
        EC_ERR("Failed to receive SII check/fetch datagram from slave %i"
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   257
                " (datagram state %i).\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   258
               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
   259
        return;
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
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   262
    if (datagram->working_counter != 1) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   263
        fsm->state = ec_fsm_sii_state_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   264
        EC_ERR("Reception of SII check/fetch datagram failed on slave %i: ",
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   265
                fsm->slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   266
        ec_datagram_print_wc_error(datagram);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   270
#ifdef SII_DEBUG
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   271
	EC_DBG("checking SII read state:\n");
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   272
	ec_print_data(datagram->data, 10);
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   273
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   274
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   275
    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
   276
        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
   277
        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
   278
        return;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   279
    }
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   280
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
    // check "busy bit"
755
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) & 0x81) { // busy bit or
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   283
												 // read operation busy
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
        // still busy... timeout?
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
        if (datagram->cycles_received
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   286
            - fsm->cycles_start >= (cycles_t) EEPROM_TIMEOUT * cpu_khz) {
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   287
            if (fsm->check_once_more) {
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   288
				fsm->check_once_more = 0;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   289
			} else {
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
                EC_ERR("SII: Read timeout.\n");
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   291
                fsm->state = ec_fsm_sii_state_error;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
                return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
            }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
        }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
        // issue check/fetch datagram again
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   297
        fsm->retries = EC_FSM_RETRIES;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
    // SII value received.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
    memcpy(fsm->value, datagram->data + 6, 4);
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   303
    fsm->state = ec_fsm_sii_state_end;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
/*****************************************************************************/
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 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
   310
   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
   311
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   313
void ec_fsm_sii_state_start_writing(
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   314
		ec_fsm_sii_t *fsm /**< finite state machine */
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   315
		)
433
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
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
    // initiate write operation
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
    ec_datagram_npwr(datagram, fsm->slave->station_address, 0x502, 8);
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   321
    EC_WRITE_U8 (datagram->data,     0x81); // two address octets
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   322
											// + enable write access
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
    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
   324
    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
   325
	memset(datagram->data + 4, 0x00, 2);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
    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
   327
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   328
#ifdef SII_DEBUG
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   329
	EC_DBG("writing SII data:\n");
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   330
	ec_print_data(datagram->data, 8);
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   331
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   332
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   333
    fsm->retries = EC_FSM_RETRIES;
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   334
    fsm->state = ec_fsm_sii_state_write_check;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
   SII state: WRITE CHECK.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   343
void ec_fsm_sii_state_write_check(
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   344
		ec_fsm_sii_t *fsm /**< finite state machine */
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   345
		)
433
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
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   349
    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
   350
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   351
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   352
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   353
        fsm->state = ec_fsm_sii_state_error;
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   354
        EC_ERR("Failed to receive SII write datagram for slave %i"
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   355
                " (datagram state %i).\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   356
               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
   357
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   358
    }
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->working_counter != 1) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   361
        fsm->state = ec_fsm_sii_state_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   362
        EC_ERR("Reception of SII write datagram failed on slave %i: ",
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   363
                fsm->slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   364
        ec_datagram_print_wc_error(datagram);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
    fsm->cycles_start = datagram->cycles_sent;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
    fsm->check_once_more = 1;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   370
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   371
    // issue check datagram
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   372
    ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 2);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   373
    fsm->retries = EC_FSM_RETRIES;
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   374
    fsm->state = ec_fsm_sii_state_write_check2;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
}
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
   SII state: WRITE CHECK 2.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   382
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   383
void ec_fsm_sii_state_write_check2(
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   384
		ec_fsm_sii_t *fsm /**< finite state machine */
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   385
		)
433
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
    ec_datagram_t *datagram = fsm->datagram;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   388
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 600
diff changeset
   389
    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
   390
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   391
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   392
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   393
        fsm->state = ec_fsm_sii_state_error;
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   394
        EC_ERR("Failed to receive SII write check datagram from slave %i"
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   395
                " (datagram state %i).\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   396
               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
   397
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   398
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   399
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   400
    if (datagram->working_counter != 1) {
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   401
        fsm->state = ec_fsm_sii_state_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   402
        EC_ERR("Reception of SII write check datagram failed on slave %i: ",
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   403
                fsm->slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   404
        ec_datagram_print_wc_error(datagram);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   407
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   408
#ifdef SII_DEBUG
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   409
	EC_DBG("checking SII write state:\n");
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   410
	ec_print_data(datagram->data, 2);
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   411
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   412
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   413
    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
   414
        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
   415
        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
   416
        return;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   417
    }
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   418
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   419
	/* FIXME: some slaves never answer with the busy flag set...
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   420
	 * wait a few ms for the write operation to complete. */
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   421
	if (datagram->cycles_received - fsm->cycles_start
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   422
			< (cycles_t) EEPROM_INHIBIT * cpu_khz) {
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   423
#ifdef SII_DEBUG
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   424
		EC_DBG("too early.\n");
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   425
#endif
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   426
        // 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
   427
        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
   428
        return;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   429
	}
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   430
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   431
    if (EC_READ_U8(datagram->data + 1) & 0x82) { // busy bit or
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   432
												 // write operation busy bit
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
        // still busy... timeout?
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
        if (datagram->cycles_received
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   435
            - fsm->cycles_start >= (cycles_t) EEPROM_TIMEOUT * cpu_khz) {
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   436
            if (fsm->check_once_more) {
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   437
				fsm->check_once_more = 0;
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   438
			} else {
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   439
                EC_ERR("SII: Write timeout.\n");
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   440
                fsm->state = ec_fsm_sii_state_error;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   441
                return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   442
            }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   443
        }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   444
755
178353fc47e5 SII writing workaround for some slaves, that don't respond correctly;
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   445
        // issue check datagram again
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   446
        fsm->retries = EC_FSM_RETRIES;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   447
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   449
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
    if (EC_READ_U8(datagram->data + 1) & 0x40) {
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
        EC_ERR("SII: Write operation failed!\n");
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   452
        fsm->state = ec_fsm_sii_state_error;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
        return;
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
    }
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
    // success
753
7ba5f9cd8f7e Renamed sii state functions.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   457
    fsm->state = ec_fsm_sii_state_end;
433
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
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
/*****************************************************************************/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
   State: ERROR.
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
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   466
void ec_fsm_sii_state_error(
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   467
		ec_fsm_sii_t *fsm /**< finite state machine */
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   468
		)
433
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
/*****************************************************************************/
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
/**
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   475
   State: END.
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   476
*/
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   477
754
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   478
void ec_fsm_sii_state_end(
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   479
		ec_fsm_sii_t *fsm /**< finite state machine */
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   480
		)
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   481
{
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   482
}
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   483
0b47b49c5976 Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents: 753
diff changeset
   484
/*****************************************************************************/