master/fsm_slave_scan.h
author Florian Pose <fp@igh-essen.com>
Mon, 17 Mar 2008 09:05:13 +0000
changeset 870 fbd5924690ee
parent 831 ded9519c8d6e
child 879 9b395c5646ab
permissions -rw-r--r--
Allow multiple sync manager categories.
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT slave scanning state machine.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#ifndef __EC_FSM_SLAVE_SCAN__
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#define __EC_FSM_SLAVE_SCAN__
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "../include/ecrt.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
#include "globals.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
#include "datagram.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
#include "slave.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
#include "fsm_sii.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#include "fsm_change.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
#include "fsm_coe.h"
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    52
#include "fsm_coe_map.h"
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
#include "fsm_pdo_mapping.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
#include "fsm_pdo_config.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
/** \see ec_fsm_slave_scan */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
typedef struct ec_fsm_slave_scan ec_fsm_slave_scan_t;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
/** Finite state machine for scanning an EtherCAT slave.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
 */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
struct ec_fsm_slave_scan
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    ec_slave_t *slave; /**< Slave the FSM runs on. */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    ec_datagram_t *datagram; /**< Datagram used in the state machine. */
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    67
    ec_fsm_slave_config_t *fsm_slave_config; /**< Slave configuration state
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    68
                                               machine to use. */
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    69
    ec_fsm_coe_map_t *fsm_coe_map; /**< Pdo mapping state machine to use. */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    unsigned int retries; /**< Retries on datagram timeout. */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    void (*state)(ec_fsm_slave_scan_t *); /**< State function. */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    uint16_t sii_offset; /**< SII offset in words. */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    ec_fsm_sii_t fsm_sii; /**< SII state machine. */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
};
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    80
void ec_fsm_slave_scan_init(ec_fsm_slave_scan_t *, ec_datagram_t *,
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    81
        ec_fsm_slave_config_t *, ec_fsm_coe_map_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
void ec_fsm_slave_scan_clear(ec_fsm_slave_scan_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
void ec_fsm_slave_scan_start(ec_fsm_slave_scan_t *, ec_slave_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
int ec_fsm_slave_scan_exec(ec_fsm_slave_scan_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
int ec_fsm_slave_scan_success(const ec_fsm_slave_scan_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
#endif