master/fsm_slave.c
author Florian Pose <fp@igh-essen.com>
Thu, 15 Dec 2011 13:21:32 +0100
branchredundancy
changeset 2314 fd8a6fb53d6b
parent 2304 1b0372eede04
child 2374 e898451c054a
permissions -rw-r--r--
Added e1000 driver for 2.6.32.
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
     1
/******************************************************************************
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
     2
 *
2099
e485694c6427 Minor: Fixed broken keyword strings.
Florian Pose <fp@igh-essen.com>
parents: 2083
diff changeset
     3
 *  $Id$
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
     4
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
     6
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
     8
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    12
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    16
 *  Public License for more details.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    17
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    21
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    22
 *  ---
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    23
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    27
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    28
 *****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    29
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    30
/** \file
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    31
 * EtherCAT slave (SDO) state machine.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    32
 */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    33
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    34
/*****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    35
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    36
#include "globals.h"
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    37
#include "master.h"
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    38
#include "mailbox.h"
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    39
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    40
#include "fsm_slave.h"
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    41
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    42
/*****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    43
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    44
void ec_fsm_slave_state_idle(ec_fsm_slave_t *);
1601
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
    45
void ec_fsm_slave_state_ready(ec_fsm_slave_t *);
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
    46
int ec_fsm_slave_action_process_sdo(ec_fsm_slave_t *);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    47
void ec_fsm_slave_state_sdo_request(ec_fsm_slave_t *);
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
    48
int ec_fsm_slave_action_process_foe(ec_fsm_slave_t *);
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
    49
void ec_fsm_slave_state_foe_request(ec_fsm_slave_t *);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    50
int ec_fsm_slave_action_process_soe(ec_fsm_slave_t *);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    51
void ec_fsm_slave_state_soe_request(ec_fsm_slave_t *);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    52
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    53
/*****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    54
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    55
/** Constructor.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    56
 */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    57
void ec_fsm_slave_init(
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    58
        ec_fsm_slave_t *fsm, /**< Slave state machine. */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    59
        ec_slave_t *slave, /**< EtherCAT slave. */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    60
        ec_datagram_t *datagram /**< Datagram object to use. */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    61
        )
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    62
{
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    63
    fsm->slave = slave;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    64
    fsm->datagram = datagram;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    65
    fsm->datagram->data_size = 0;
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
    66
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
    67
    EC_SLAVE_DBG(slave, 1, "Init FSM.\n");
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
    68
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
    69
    fsm->state = ec_fsm_slave_state_idle;
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    70
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    71
    // init sub-state-machines
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    72
    ec_fsm_coe_init(&fsm->fsm_coe, fsm->datagram);
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
    73
    ec_fsm_foe_init(&fsm->fsm_foe, fsm->datagram);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    74
    ec_fsm_soe_init(&fsm->fsm_soe, fsm->datagram);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    75
}
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    76
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    77
/*****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    78
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    79
/** Destructor.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    80
 */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    81
void ec_fsm_slave_clear(
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    82
        ec_fsm_slave_t *fsm /**< Master state machine. */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    83
        )
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    84
{
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    85
    // clear sub-state machines
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    86
    ec_fsm_coe_clear(&fsm->fsm_coe);
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
    87
    ec_fsm_foe_clear(&fsm->fsm_foe);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
    88
    ec_fsm_soe_clear(&fsm->fsm_soe);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    89
}
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    90
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    91
/*****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    92
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    93
/** Executes the current state of the state machine.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    94
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    95
 * If the state machine's datagram is not sent or received yet, the execution
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    96
 * of the state machine is delayed to the next cycle.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    97
 */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    98
void ec_fsm_slave_exec(
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
    99
        ec_fsm_slave_t *fsm /**< Slave state machine. */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   100
        )
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   101
{
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   102
    if (fsm->datagram->state == EC_DATAGRAM_SENT
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   103
        || fsm->datagram->state == EC_DATAGRAM_QUEUED) {
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   104
        // datagram was not sent or received yet.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   105
        return;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   106
    }
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   107
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   108
    fsm->state(fsm);
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   109
}
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   110
1601
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   111
/*****************************************************************************/
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   112
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   113
/** Sets the current state of the state machine to READY
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   114
 */
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   115
void ec_fsm_slave_ready(
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   116
        ec_fsm_slave_t *fsm /**< Slave state machine. */
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   117
        )
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   118
{
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   119
    if (fsm->state == ec_fsm_slave_state_idle) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   120
        EC_SLAVE_DBG(fsm->slave, 1, "Ready for requests.\n");
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   121
        fsm->state = ec_fsm_slave_state_ready;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   122
    }
1601
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   123
}
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   124
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   125
/******************************************************************************
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   126
 * Slave state machine
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   127
 *****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   128
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   129
/** Slave state: IDLE.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   130
 */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   131
void ec_fsm_slave_state_idle(
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   132
        ec_fsm_slave_t *fsm /**< Slave state machine. */
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   133
        )
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   134
{
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   135
    // do nothing
1601
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   136
}
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   137
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   138
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   139
/*****************************************************************************/
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   140
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   141
/** Slave state: READY.
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   142
 */
a784812c787f master FSM enables slave FSM
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1598
diff changeset
   143
void ec_fsm_slave_state_ready(
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   144
        ec_fsm_slave_t *fsm /**< Slave state machine. */
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   145
        )
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   146
{
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   147
    // Check for pending external SDO requests
2304
1b0372eede04 Minor: Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   148
    if (ec_fsm_slave_action_process_sdo(fsm)) {
1b0372eede04 Minor: Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   149
        return;
1b0372eede04 Minor: Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   150
    }
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   151
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   152
    // Check for pending FoE requests
2304
1b0372eede04 Minor: Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   153
    if (ec_fsm_slave_action_process_foe(fsm)) {
1b0372eede04 Minor: Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   154
        return;
1b0372eede04 Minor: Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   155
    }
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   156
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   157
    // Check for pending SoE requests
2304
1b0372eede04 Minor: Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   158
    if (ec_fsm_slave_action_process_soe(fsm)) {
1b0372eede04 Minor: Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   159
        return;
1b0372eede04 Minor: Fixed spacing.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
   160
    }
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   161
}
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   162
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   163
/*****************************************************************************/
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   164
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   165
/** Check for pending SDO requests and process one.
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   166
 *
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   167
 * \return non-zero, if an SDO request is processed.
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   168
 */
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   169
int ec_fsm_slave_action_process_sdo(
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   170
        ec_fsm_slave_t *fsm /**< Slave state machine. */
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   171
        )
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   172
{
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   173
    ec_slave_t *slave = fsm->slave;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   174
    ec_master_sdo_request_t *request, *next;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   175
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   176
    // search the first external request to be processed
1596
ea8d2b4ee742 Moved sdo request queue to slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
   177
    list_for_each_entry_safe(request, next, &slave->slave_sdo_requests, list) {
1598
5ad4eb4963a6 Postpone SDO request when slave is in INIT
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
   178
1604
699bd70f7bfe undone changes of revision 1547: Abort SDO/FOE requests when slave is in INIT
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1601
diff changeset
   179
        list_del_init(&request->list); // dequeue
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   180
        if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   181
            EC_SLAVE_WARN(slave, "Aborting SDO request,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   182
                    " slave has error flag set.\n");
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   183
            request->req.state = EC_INT_REQUEST_FAILURE;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   184
            wake_up(&slave->sdo_queue);
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   185
            fsm->sdo_request = NULL;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   186
            fsm->state = ec_fsm_slave_state_idle;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   187
            return 0;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   188
        }
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   189
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   190
        if (slave->current_state == EC_SLAVE_STATE_INIT) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   191
            EC_SLAVE_WARN(slave, "Aborting SDO request, slave is in INIT.\n");
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   192
            request->req.state = EC_INT_REQUEST_FAILURE;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   193
            wake_up(&slave->sdo_queue);
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   194
            fsm->sdo_request = NULL;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   195
            fsm->state = ec_fsm_slave_state_idle;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   196
            return 0;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   197
        }
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   198
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   199
        request->req.state = EC_INT_REQUEST_BUSY;
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   200
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   201
        // Found pending SDO request. Execute it!
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   202
        EC_SLAVE_DBG(slave, 1, "Processing SDO request...\n");
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   203
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   204
        // Start SDO transfer
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   205
        fsm->sdo_request = &request->req;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   206
        fsm->state = ec_fsm_slave_state_sdo_request;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   207
        ec_fsm_coe_transfer(&fsm->fsm_coe, slave, &request->req);
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   208
        ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   209
        ec_master_queue_external_datagram(fsm->slave->master, fsm->datagram,
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   210
                EC_DEVICE_MAIN);
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   211
        return 1;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   212
    }
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   213
    return 0;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   214
}
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   215
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   216
/*****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   217
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   218
/** Slave state: SDO_REQUEST.
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   219
 */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   220
void ec_fsm_slave_state_sdo_request(
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   221
        ec_fsm_slave_t *fsm /**< Slave state machine. */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   222
        )
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   223
{
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   224
    ec_slave_t *slave = fsm->slave;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   225
    ec_sdo_request_t *request = fsm->sdo_request;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   226
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   227
    if (ec_fsm_coe_exec(&fsm->fsm_coe)) {
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   228
        ec_master_queue_external_datagram(fsm->slave->master, fsm->datagram,
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   229
                EC_DEVICE_MAIN);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   230
        return;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   231
    }
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   232
    if (!ec_fsm_coe_success(&fsm->fsm_coe)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   233
        EC_SLAVE_ERR(slave, "Failed to process SDO request.\n");
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   234
        request->state = EC_INT_REQUEST_FAILURE;
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   235
        wake_up(&slave->sdo_queue);
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   236
        fsm->sdo_request = NULL;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   237
        fsm->state = ec_fsm_slave_state_idle;
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   238
        return;
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   239
    }
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   240
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   241
    EC_SLAVE_DBG(slave, 1, "Finished SDO request.\n");
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   242
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   243
    // SDO request finished
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   244
    request->state = EC_INT_REQUEST_SUCCESS;
1596
ea8d2b4ee742 Moved sdo request queue to slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
   245
    wake_up(&slave->sdo_queue);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
diff changeset
   246
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   247
    fsm->sdo_request = NULL;
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   248
    fsm->state = ec_fsm_slave_state_ready;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   249
}
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   250
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   251
/*****************************************************************************/
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   252
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   253
/** Check for pending FOE requests and process one.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   254
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   255
 * \return non-zero, if an FOE request is processed.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   256
 */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   257
int ec_fsm_slave_action_process_foe(
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   258
        ec_fsm_slave_t *fsm /**< Slave state machine. */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   259
        )
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   260
{
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   261
    ec_slave_t *slave = fsm->slave;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   262
    ec_master_foe_request_t *request, *next;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   263
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   264
    // search the first request to be processed
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   265
    list_for_each_entry_safe(request, next, &slave->foe_requests, list) {
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   266
        if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   267
            EC_SLAVE_WARN(slave, "Aborting FOE request,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   268
                    " slave has error flag set.\n");
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   269
            request->req.state = EC_INT_REQUEST_FAILURE;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   270
            wake_up(&slave->sdo_queue);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   271
            fsm->sdo_request = NULL;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   272
            fsm->state = ec_fsm_slave_state_idle;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   273
            return 0;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   274
        }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   275
        list_del_init(&request->list); // dequeue
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   276
        request->req.state = EC_INT_REQUEST_BUSY;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   277
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   278
        EC_SLAVE_DBG(slave, 1, "Processing FoE request.\n");
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   279
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   280
        fsm->foe_request = &request->req;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   281
        fsm->state = ec_fsm_slave_state_foe_request;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   282
        ec_fsm_foe_transfer(&fsm->fsm_foe, slave, &request->req);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   283
        ec_fsm_foe_exec(&fsm->fsm_foe);
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   284
        ec_master_queue_external_datagram(fsm->slave->master, fsm->datagram,
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   285
                EC_DEVICE_MAIN);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   286
        return 1;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   287
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   288
    return 0;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   289
}
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   290
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   291
/*****************************************************************************/
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   292
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   293
/** Slave state: FOE REQUEST.
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   294
 */
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   295
void ec_fsm_slave_state_foe_request(
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   296
        ec_fsm_slave_t *fsm /**< Slave state machine. */
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   297
        )
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   298
{
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   299
    ec_slave_t *slave = fsm->slave;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   300
    ec_foe_request_t *request = fsm->foe_request;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   301
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   302
    if (ec_fsm_foe_exec(&fsm->fsm_foe)) {
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   303
        ec_master_queue_external_datagram(fsm->slave->master, fsm->datagram,
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   304
                EC_DEVICE_MAIN);
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   305
        return;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   306
    }
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   307
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   308
    if (!ec_fsm_foe_success(&fsm->fsm_foe)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   309
        EC_SLAVE_ERR(slave, "Failed to handle FoE request.\n");
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   310
        request->state = EC_INT_REQUEST_FAILURE;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   311
        wake_up(&slave->foe_queue);
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   312
        fsm->foe_request = NULL;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   313
        fsm->state = ec_fsm_slave_state_idle;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   314
        return;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   315
    }
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   316
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   317
    // finished transferring FoE
1930
59a50053ccc6 Made send_interval variable an unsigned int; fixed format specifiers for
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   318
    EC_SLAVE_DBG(slave, 1, "Successfully transferred %zu bytes of FoE"
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   319
            " data.\n", request->data_size);
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   320
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   321
    request->state = EC_INT_REQUEST_SUCCESS;
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   322
    wake_up(&slave->foe_queue);
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   323
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   324
    fsm->foe_request = NULL;
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   325
    fsm->state = ec_fsm_slave_state_ready;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   326
}
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   327
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1608
diff changeset
   328
/*****************************************************************************/
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   329
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   330
/** Check for pending SoE requests and process one.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   331
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   332
 * \return non-zero, if a request is processed.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   333
 */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   334
int ec_fsm_slave_action_process_soe(
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   335
        ec_fsm_slave_t *fsm /**< Slave state machine. */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   336
        )
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   337
{
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   338
    ec_slave_t *slave = fsm->slave;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   339
    ec_master_soe_request_t *req, *next;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   340
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   341
    // search the first request to be processed
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   342
    list_for_each_entry_safe(req, next, &slave->soe_requests, list) {
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   343
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   344
        list_del_init(&req->list); // dequeue
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   345
        if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   346
            EC_SLAVE_WARN(slave, "Aborting SoE request,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   347
                    " slave has error flag set.\n");
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   348
            req->req.state = EC_INT_REQUEST_FAILURE;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   349
            wake_up(&slave->soe_queue);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   350
            fsm->state = ec_fsm_slave_state_idle;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   351
            return 0;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   352
        }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   353
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   354
        if (slave->current_state == EC_SLAVE_STATE_INIT) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   355
            EC_SLAVE_WARN(slave, "Aborting SoE request, slave is in INIT.\n");
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   356
            req->req.state = EC_INT_REQUEST_FAILURE;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   357
            wake_up(&slave->soe_queue);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   358
            fsm->state = ec_fsm_slave_state_idle;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   359
            return 0;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   360
        }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   361
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   362
        req->req.state = EC_INT_REQUEST_BUSY;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   363
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   364
        // Found pending request. Execute it!
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   365
        EC_SLAVE_DBG(slave, 1, "Processing SoE request...\n");
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   366
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   367
        // Start SoE transfer
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   368
        fsm->soe_request = &req->req;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   369
        fsm->state = ec_fsm_slave_state_soe_request;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   370
        ec_fsm_soe_transfer(&fsm->fsm_soe, slave, &req->req);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   371
        ec_fsm_soe_exec(&fsm->fsm_soe); // execute immediately
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   372
        ec_master_queue_external_datagram(fsm->slave->master, fsm->datagram,
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   373
                EC_DEVICE_MAIN);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   374
        return 1;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   375
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   376
    return 0;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   377
}
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   378
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   379
/*****************************************************************************/
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   380
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   381
/** Slave state: SOE_REQUEST.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   382
 */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   383
void ec_fsm_slave_state_soe_request(
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   384
        ec_fsm_slave_t *fsm /**< Slave state machine. */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   385
        )
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   386
{
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   387
    ec_slave_t *slave = fsm->slave;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   388
    ec_soe_request_t *request = fsm->soe_request;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   389
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   390
    if (ec_fsm_soe_exec(&fsm->fsm_soe)) {
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   391
        ec_master_queue_external_datagram(fsm->slave->master, fsm->datagram,
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2099
diff changeset
   392
                EC_DEVICE_MAIN);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   393
        return;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   394
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   395
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   396
    if (!ec_fsm_soe_success(&fsm->fsm_soe)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   397
        EC_SLAVE_ERR(slave, "Failed to process SoE request.\n");
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   398
        request->state = EC_INT_REQUEST_FAILURE;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   399
        wake_up(&slave->soe_queue);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   400
        fsm->soe_request = NULL;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   401
        fsm->state = ec_fsm_slave_state_idle;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   402
        return;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   403
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   404
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1878
diff changeset
   405
    EC_SLAVE_DBG(slave, 1, "Finished SoE request.\n");
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   406
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   407
    // SoE request finished
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   408
    request->state = EC_INT_REQUEST_SUCCESS;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   409
    wake_up(&slave->soe_queue);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   410
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   411
    fsm->soe_request = NULL;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   412
    fsm->state = ec_fsm_slave_state_ready;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   413
}
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   414
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   415
/*****************************************************************************/