master/fsm_mapping.c
author Florian Pose <fp@igh-essen.com>
Tue, 08 Jan 2008 16:20:02 +0000
changeset 773 6c4646a03d68
parent 758 8fa6f825eb7d
child 792 3778920f61e4
permissions -rw-r--r--
Increased maximum number of EEPROM words from 512 to 1024.
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
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT PDO mapping state machine.
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
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "globals.h"
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "master.h"
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "mailbox.h"
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "fsm_mapping.h"
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
void ec_fsm_mapping_state_start(ec_fsm_mapping_t *);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
void ec_fsm_mapping_state_zero_count(ec_fsm_mapping_t *);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
void ec_fsm_mapping_state_add_pdo(ec_fsm_mapping_t *);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
void ec_fsm_mapping_state_pdo_count(ec_fsm_mapping_t *);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
void ec_fsm_mapping_state_end(ec_fsm_mapping_t *);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
void ec_fsm_mapping_state_error(ec_fsm_mapping_t *);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
void ec_fsm_mapping_next_sync(ec_fsm_mapping_t *);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
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
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
 * Constructor.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
void ec_fsm_mapping_init(ec_fsm_mapping_t *fsm, /**< mapping state machine */
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
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
 * Destructor.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
void ec_fsm_mapping_clear(ec_fsm_mapping_t *fsm /**< mapping state machine */)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
 * Start PDO mapping configuration state machine.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
void ec_fsm_mapping_start(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        ec_fsm_mapping_t *fsm, /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        ec_slave_t *slave /**< slave to configure */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    fsm->slave = slave;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    fsm->state = ec_fsm_mapping_state_start;
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
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
 * \return false, if state machine has terminated
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
int ec_fsm_mapping_running(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        const ec_fsm_mapping_t *fsm /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    return fsm->state != ec_fsm_mapping_state_end
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
        && fsm->state != ec_fsm_mapping_state_error;
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
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
 * Executes the current state of the state machine.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
 * 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
   115
 * of the state machine is delayed to the next cycle.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
 * \return false, if state machine has terminated
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
int ec_fsm_mapping_exec(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
        ec_fsm_mapping_t *fsm /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    fsm->state(fsm);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    return ec_fsm_mapping_running(fsm);
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
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
 * \return true, if the state machine terminated gracefully
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
int ec_fsm_mapping_success(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
        const ec_fsm_mapping_t *fsm /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
        )
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
    return fsm->state == ec_fsm_mapping_state_end;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
/******************************************************************************
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 660
diff changeset
   141
 * state functions
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
 *****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
/**
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 660
diff changeset
   145
 * Start mapping configuration.
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
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
void ec_fsm_mapping_state_start(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
        ec_fsm_mapping_t *fsm /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    fsm->dir = EC_DIR_OUTPUT;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
    ec_fsm_mapping_next_sync(fsm);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
}
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
/**
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 660
diff changeset
   159
 * Process mapping of next sync manager.
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
void ec_fsm_mapping_next_sync(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
        ec_fsm_mapping_t *fsm /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
{
660
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   166
    while (1) {
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
        if (fsm->dir > EC_DIR_INPUT) {
660
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   168
            // no more directions to configure mappings for
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
            fsm->state = ec_fsm_mapping_state_end;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
            return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
        }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
        if (!(fsm->sync = ec_slave_get_pdo_sync(fsm->slave, fsm->dir))) {
660
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   174
            // no sync manager found for this direction
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   175
            fsm->dir++;
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   176
            continue;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
        }
660
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   178
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
        fsm->dir++;
660
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   180
        if (fsm->sync->alt_mapping)
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   181
            break;
582a90a34303 Configure alternative PDO mapping only on slaves that have PDO sync
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   182
    }
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    if (fsm->slave->master->debug_level) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
        EC_DBG("Configuring PDO mapping for SM%u of slave %i.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
                fsm->sync->index, fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    // set mapped PDO count to zero
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
    fsm->sdodata.index = 0x1C10 + fsm->sync->index;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    fsm->sdodata.subindex = 0; // mapped PDO count
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
    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
   193
    fsm->sdodata.size = 1;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
        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
   196
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
    fsm->state = ec_fsm_mapping_state_zero_count;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    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
   199
    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
   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
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
/**
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 660
diff changeset
   205
 * Process mapping of next PDO.
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
ec_pdo_t *ec_fsm_mapping_next_pdo(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
        ec_fsm_mapping_t *fsm, /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
        struct list_head *list /**< current PDO list item */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
    ec_pdo_t *pdo;
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
    do {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
        list = list->next; 
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
        if (list == &fsm->sync->pdos)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
            return NULL; // no next PDO
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
        pdo = list_entry(list, ec_pdo_t, list);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    while (pdo->sync_index != fsm->sync->index);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
    
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
    return pdo;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
/**
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 660
diff changeset
   229
 * Set the number of mapped PDOs to zero.
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
void ec_fsm_mapping_state_zero_count(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
        ec_fsm_mapping_t *fsm /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
    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
   237
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
        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
   240
                fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
        fsm->state = ec_fsm_mapping_state_error;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
    // 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
   246
    
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
    // find first PDO
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
    if (!(fsm->pdo = ec_fsm_mapping_next_pdo(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
                    fsm, &fsm->sync->pdos))) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
        if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
            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
   252
                    fsm->sync->index, fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
        ec_fsm_mapping_next_sync(fsm);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
    // add first PDO to mapping
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
    fsm->pdo_count = 1;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
    fsm->sdodata.subindex = fsm->pdo_count;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
    EC_WRITE_U16(&fsm->sdo_value, fsm->pdo->index);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
    fsm->sdodata.size = 2;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
    if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
        EC_DBG("Mapping PDO 0x%04X at position %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
                fsm->pdo->index, fsm->sdodata.subindex);
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
    fsm->state = ec_fsm_mapping_state_add_pdo;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    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
   269
    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
   270
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
/**
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 660
diff changeset
   275
 * Add a PDO to the sync managers mapping.
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
 */
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
void ec_fsm_mapping_state_add_pdo(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
        ec_fsm_mapping_t *fsm /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
    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
   283
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
        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
   286
                fsm->pdo->index, fsm->sync->index, fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
        fsm->state = ec_fsm_mapping_state_error;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
    }
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
    // find next PDO
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
    if (!(fsm->pdo = ec_fsm_mapping_next_pdo(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
                    fsm, &fsm->pdo->list))) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
        // no more PDOs to map. write PDO count
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
        fsm->sdodata.subindex = 0;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
        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
   297
        fsm->sdodata.size = 1;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
        if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
            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
   301
                    fsm->pdo_count);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
        
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
        fsm->state = ec_fsm_mapping_state_pdo_count;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
        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
   305
        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
   306
        return;
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
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
    // add next PDO to mapping
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
    fsm->sdodata.subindex = fsm->pdo_count;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
    EC_WRITE_U16(&fsm->sdo_value, fsm->pdo->index);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
    fsm->sdodata.size = 2;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
    if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
        EC_DBG("Mapping PDO 0x%04X at position %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
                fsm->pdo->index, fsm->sdodata.subindex);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
    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
   320
    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
   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
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
/**
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 660
diff changeset
   326
 * Set the number of mapped PDOs.
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
void ec_fsm_mapping_state_pdo_count(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
        ec_fsm_mapping_t *fsm /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
        )
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_exec(fsm->fsm_coe)) return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
        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
   337
                fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
        fsm->state = ec_fsm_mapping_state_error;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
    if (fsm->slave->master->debug_level)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
        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
   344
                fsm->sync->index, fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
    // mapping configuration for this sync manager complete.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
    ec_fsm_mapping_next_sync(fsm);
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
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
 * Common state functions
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
 *****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
   State: ERROR.
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
void ec_fsm_mapping_state_error(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
        ec_fsm_mapping_t *fsm /**< mapping state machine */
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
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
   State: END.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
*/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   370
void ec_fsm_mapping_state_end(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
        ec_fsm_mapping_t *fsm /**< mapping state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   372
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
/*****************************************************************************/