master/fsm_pdo_mapping.c
author Florian Pose <fp@igh-essen.com>
Thu, 21 Feb 2008 09:24:56 +0000
changeset 806 ab8daaabbe48
parent 802 b947d0b09f9a
child 808 1feddbd65608
permissions -rw-r--r--
Renamed master module parameters, re-formatted code documentation.
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    34
/** \file
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    35
 * EtherCAT PDO mapping state machine.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    36
 */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "globals.h"
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "master.h"
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "mailbox.h"
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    43
#include "slave_config.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    44
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    45
#include "fsm_pdo_mapping.h"
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    46
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    47
/*****************************************************************************/
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    48
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    49
void ec_fsm_pdo_mapping_state_start(ec_fsm_pdo_mapping_t *);
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    50
void ec_fsm_pdo_mapping_state_zero_count(ec_fsm_pdo_mapping_t *);
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    51
void ec_fsm_pdo_mapping_state_add_pdo(ec_fsm_pdo_mapping_t *);
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    52
void ec_fsm_pdo_mapping_state_pdo_count(ec_fsm_pdo_mapping_t *);
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    53
void ec_fsm_pdo_mapping_state_end(ec_fsm_pdo_mapping_t *);
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    54
void ec_fsm_pdo_mapping_state_error(ec_fsm_pdo_mapping_t *);
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    55
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    56
void ec_fsm_pdo_mapping_next_sync(ec_fsm_pdo_mapping_t *);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    60
/** Constructor.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    61
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    62
void ec_fsm_pdo_mapping_init(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    63
        ec_fsm_pdo_mapping_t *fsm, /**< mapping state machine */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
        ec_fsm_coe_t *fsm_coe /**< CoE state machine to use */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    fsm->fsm_coe = fsm_coe;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    fsm->sdodata.data = (uint8_t *) &fsm->sdo_value;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    73
/** Destructor.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    74
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    75
void ec_fsm_pdo_mapping_clear(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    76
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    77
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    78
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    79
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    80
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    81
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    82
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    83
/** Start PDO mapping configuration state machine.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    84
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    85
void ec_fsm_pdo_mapping_start(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    86
        ec_fsm_pdo_mapping_t *fsm, /**< mapping state machine */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
        ec_slave_t *slave /**< slave to configure */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    fsm->slave = slave;
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
    91
    fsm->state = ec_fsm_pdo_mapping_state_start;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    96
/** Get running state.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    97
 *
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
 * \return false, if state machine has terminated
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   100
int ec_fsm_pdo_mapping_running(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   101
        const ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   102
        )
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   103
{
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   104
    return fsm->state != ec_fsm_pdo_mapping_state_end
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   105
        && fsm->state != ec_fsm_pdo_mapping_state_error;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   110
/** Executes the current state of the state machine.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   111
 *
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
 * If the state machine's datagram is not sent or received yet, the execution
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
 * of the state machine is delayed to the next cycle.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   114
 *
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
 * \return false, if state machine has terminated
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   117
int ec_fsm_pdo_mapping_exec(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   118
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    fsm->state(fsm);
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   122
    return ec_fsm_pdo_mapping_running(fsm);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   127
/** Get execution result.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   128
 *
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
 * \return true, if the state machine terminated gracefully
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   131
int ec_fsm_pdo_mapping_success(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   132
        const ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   133
        )
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   134
{
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   135
    return fsm->state == ec_fsm_pdo_mapping_state_end;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
/******************************************************************************
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   139
 * State functions.
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
 *****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   142
/** Start mapping configuration.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   143
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   144
void ec_fsm_pdo_mapping_state_start(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   145
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   148
    if (!fsm->slave->config) {
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   149
        fsm->state = ec_fsm_pdo_mapping_state_end;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   150
        return;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   151
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   152
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   153
    fsm->sync = NULL;
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   154
    ec_fsm_pdo_mapping_next_sync(fsm);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   159
/** Process mapping of next sync manager.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   160
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   161
void ec_fsm_pdo_mapping_next_sync(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   162
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
{
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   165
    ec_direction_t dir;
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   166
    const ec_sync_t *sync;
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   167
    const ec_pdo_mapping_t *map;
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   168
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   169
    for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   170
        if (!(sync = ec_slave_get_pdo_sync(fsm->slave, dir))) {
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   171
            EC_WARN("No sync manager for direction %u!\n", dir);
660
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   172
            continue;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
        }
660
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   174
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   175
        if (fsm->sync) { // there is a last SM
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   176
            if (sync == fsm->sync) // this is the last SM
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   177
                fsm->sync = NULL; // take the next one
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   178
        } else {
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   179
            map = &fsm->slave->config->mapping[dir];
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   180
            if (ec_pdo_mapping_equal(&sync->mapping, map))
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   181
                continue;
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   182
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   183
            fsm->sync = sync;
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   184
            fsm->mapping = map;
660
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   185
            break;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   186
        }
660
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   187
    }
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   189
    if (!sync) {
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   190
        if (fsm->slave->master->debug_level)
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   191
            EC_DBG("Pdo mapping finished for slave %u.\n",
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   192
                    fsm->slave->ring_position);
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   193
        fsm->state = ec_fsm_pdo_mapping_state_end;
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   194
        return;
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   195
    }
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   196
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
    if (fsm->slave->master->debug_level) {
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   198
        EC_DBG("Configuring PDO mapping for SM%u of slave %u.\n",
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
                fsm->sync->index, fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
    // set mapped PDO count to zero
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
    fsm->sdodata.index = 0x1C10 + fsm->sync->index;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
    fsm->sdodata.subindex = 0; // mapped PDO count
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
    EC_WRITE_U8(&fsm->sdo_value, 0); // zero PDOs mapped
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
    fsm->sdodata.size = 1;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
    if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
        EC_DBG("Setting PDO count to zero for SM%u.\n", fsm->sync->index);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   210
    fsm->state = ec_fsm_pdo_mapping_state_zero_count;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
    ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   217
/** Process mapping of next PDO.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   218
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   219
ec_pdo_t *ec_fsm_pdo_mapping_next_pdo(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   220
        const ec_fsm_pdo_mapping_t *fsm, /**< mapping state machine */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   221
        const struct list_head *list /**< current PDO list item */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   222
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   223
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   224
    list = list->next; 
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   225
    if (list == &fsm->mapping->pdos)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   226
        return NULL; // no next PDO
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   227
    return list_entry(list, ec_pdo_t, list);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   228
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   229
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   230
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   231
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   232
/** Add a Pdo to the mapping.
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   233
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   234
void ec_fsm_pdo_mapping_add_pdo(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   235
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   236
        )
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   237
{
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   238
    fsm->sdodata.subindex = fsm->pdo_count;
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   239
    EC_WRITE_U16(&fsm->sdo_value, fsm->pdo->index);
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   240
    fsm->sdodata.size = 2;
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   241
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   242
    if (fsm->slave->master->debug_level)
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   243
        EC_DBG("Mapping PDO 0x%04X at position %u.\n",
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   244
                fsm->pdo->index, fsm->sdodata.subindex);
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   245
    
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   246
    fsm->state = ec_fsm_pdo_mapping_state_add_pdo;
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   247
    ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   248
    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   249
}
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   250
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   251
/*****************************************************************************/
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   252
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   253
/** Set the number of mapped PDOs to zero.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   254
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   255
void ec_fsm_pdo_mapping_state_zero_count(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   256
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
        EC_ERR("Failed to clear PDO mapping for slave %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
                fsm->slave->ring_position);
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   264
        fsm->state = ec_fsm_pdo_mapping_state_error;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    // map all PDOs belonging to the current sync manager
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
    
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
    // find first PDO
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   271
    if (!(fsm->pdo = ec_fsm_pdo_mapping_next_pdo(fsm, &fsm->mapping->pdos))) {
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
        if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
            EC_DBG("No PDOs to map for SM%u of slave %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
                    fsm->sync->index, fsm->slave->ring_position);
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   275
        ec_fsm_pdo_mapping_next_sync(fsm);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
    // add first PDO to mapping
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
    fsm->pdo_count = 1;
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   281
    ec_fsm_pdo_mapping_add_pdo(fsm);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   286
/** Add a PDO to the sync managers mapping.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   287
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   288
void ec_fsm_pdo_mapping_state_add_pdo(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   289
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
        EC_ERR("Failed to map PDO 0x%04X for SM%u of slave %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
                fsm->pdo->index, fsm->sync->index, fsm->slave->ring_position);
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   297
        fsm->state = ec_fsm_pdo_mapping_state_error;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
    // find next PDO
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   302
    if (!(fsm->pdo = ec_fsm_pdo_mapping_next_pdo(fsm, &fsm->pdo->list))) {
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
        // no more PDOs to map. write PDO count
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
        fsm->sdodata.subindex = 0;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
        EC_WRITE_U8(&fsm->sdo_value, fsm->pdo_count);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
        fsm->sdodata.size = 1;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
        if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
            EC_DBG("Setting number of mapped PDOs to %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
                    fsm->pdo_count);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
        
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   312
        fsm->state = ec_fsm_pdo_mapping_state_pdo_count;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
        ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
        ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
    // add next PDO to mapping
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
    fsm->pdo_count++;
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   320
    ec_fsm_pdo_mapping_add_pdo(fsm);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   325
/** Set the number of mapped PDOs.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   326
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   327
void ec_fsm_pdo_mapping_state_pdo_count(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   328
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
        EC_ERR("Failed to set number of mapped PDOs for slave %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
                fsm->slave->ring_position);
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   336
        fsm->state = ec_fsm_pdo_mapping_state_error;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
    if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
        EC_DBG("Successfully set PDO mapping for SM%u of slave %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
                fsm->sync->index, fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
    // mapping configuration for this sync manager complete.
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   345
    ec_fsm_pdo_mapping_next_sync(fsm);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
/******************************************************************************
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
 * Common state functions
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
 *****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   352
/** State: ERROR.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   353
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   354
void ec_fsm_pdo_mapping_state_error(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   355
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   360
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   362
/** State: END.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   363
 */
802
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   364
void ec_fsm_pdo_mapping_state_end(
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   365
        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   366
        )
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   367
{
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   368
}
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   369
b947d0b09f9a Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   370
/*****************************************************************************/