master/fsm_pdo_mapping.c
author Florian Pose <fp@igh-essen.com>
Mon, 07 Apr 2008 10:19:59 +0000
changeset 885 eaa10a277d52
parent 879 9b395c5646ab
child 890 1115793a76ed
permissions -rw-r--r--
Removed unused domain state.
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/** \file
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    35
 * EtherCAT Pdo mapping state machine.
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
 */
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "globals.h"
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "master.h"
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "mailbox.h"
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "slave_config.h"
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    45
#include "fsm_pdo_mapping.h"
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    46
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    47
/*****************************************************************************/
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    48
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    49
void ec_fsm_pdo_mapping_state_start(ec_fsm_pdo_mapping_t *);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    50
void ec_fsm_pdo_mapping_state_zero_count(ec_fsm_pdo_mapping_t *);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    51
void ec_fsm_pdo_mapping_state_add_entry(ec_fsm_pdo_mapping_t *);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    52
void ec_fsm_pdo_mapping_state_entry_count(ec_fsm_pdo_mapping_t *);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    53
void ec_fsm_pdo_mapping_state_end(ec_fsm_pdo_mapping_t *);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    54
void ec_fsm_pdo_mapping_state_error(ec_fsm_pdo_mapping_t *);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    55
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    56
void ec_fsm_pdo_mapping_next_pdo(ec_fsm_pdo_mapping_t *);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
/** Constructor.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    62
void ec_fsm_pdo_mapping_init(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    63
        ec_fsm_pdo_mapping_t *fsm, /**< Pdo mapping state machine. */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    64
        ec_fsm_coe_t *fsm_coe /**< CoE state machine to use. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    fsm->fsm_coe = fsm_coe;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
    68
    ec_sdo_request_init(&fsm->request);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
/** Destructor.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    75
void ec_fsm_pdo_mapping_clear(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    76
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
{
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
    79
    ec_sdo_request_clear(&fsm->request);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    84
/** Start Pdo mapping state machine.
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    85
 */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    86
void ec_fsm_pdo_mapping_start(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    87
        ec_fsm_pdo_mapping_t *fsm, /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        ec_slave_t *slave /**< slave to configure */
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    fsm->slave = slave;
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
    92
    fsm->state = ec_fsm_pdo_mapping_state_start;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
/** Get running state.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
 * \return false, if state machine has terminated
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   101
int ec_fsm_pdo_mapping_running(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   102
        const ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   103
        )
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   104
{
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   105
    return fsm->state != ec_fsm_pdo_mapping_state_end
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   106
        && fsm->state != ec_fsm_pdo_mapping_state_error;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
/** Executes the current state.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
 * \return false, if state machine has terminated
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   115
int ec_fsm_pdo_mapping_exec(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   116
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    fsm->state(fsm);
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   120
    return ec_fsm_pdo_mapping_running(fsm);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
/** Get execution result.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
 *
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
 * \return true, if the state machine terminated gracefully
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   129
int ec_fsm_pdo_mapping_success(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   130
        const ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   131
        )
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   132
{
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   133
    return fsm->state == ec_fsm_pdo_mapping_state_end;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
/******************************************************************************
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
 * State functions.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
 *****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   140
/** Start Pdo mapping.
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   141
 */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   142
void ec_fsm_pdo_mapping_state_start(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   143
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    if (!fsm->slave->config) {
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   147
        fsm->state = ec_fsm_pdo_mapping_state_end;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
        return;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    fsm->pdo = NULL;
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   152
    ec_fsm_pdo_mapping_next_pdo(fsm);
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   153
}
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   154
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   155
/*****************************************************************************/
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   156
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   157
/** Process mapping of next Pdo.
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   158
 */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   159
void ec_fsm_pdo_mapping_next_pdo(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   160
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
    ec_direction_t dir;
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   164
    const ec_pdo_list_t *pdos;
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   165
    const ec_pdo_t *pdo, *assigned_pdo;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   168
        pdos = &fsm->slave->config->pdos[dir];
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   169
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   170
        list_for_each_entry(pdo, &pdos->list, list) {
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   171
            if (fsm->pdo) { // there was a Pdo mapping changed in the last run
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 800
diff changeset
   172
                if (pdo == fsm->pdo) // this is the last Pdo
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 800
diff changeset
   173
                    fsm->pdo = NULL; // take the next one
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
            } else {
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   175
                if ((assigned_pdo = ec_slave_find_pdo(fsm->slave, pdo->index)))
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   176
                    if (ec_pdo_equal_entries(pdo, assigned_pdo))
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   177
                        continue; // Pdo entries mapped correctly
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
                fsm->pdo = pdo;
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 800
diff changeset
   180
                break;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
            }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
        }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 800
diff changeset
   185
    if (!fsm->pdo) {
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 800
diff changeset
   186
        if (fsm->slave->master->debug_level)
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   187
            EC_DBG("Pdo mapping finished for slave %u.\n",
801
6b1e2b0ed8bc Cleaned up Pdo mapping and configuration state machines.
Florian Pose <fp@igh-essen.com>
parents: 800
diff changeset
   188
                    fsm->slave->ring_position);
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   189
        fsm->state = ec_fsm_pdo_mapping_state_end;
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   190
        return;
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   191
    }
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   192
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   193
    // Pdo mapping has to be changed. Does the slave support this?
877
d2915690047f Fixed minor bug.
Florian Pose <fp@igh-essen.com>
parents: 875
diff changeset
   194
    if (!(fsm->slave->sii.mailbox_protocols & EC_MBOX_COE)
835
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   195
            || (fsm->slave->sii.has_general
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   196
                && !fsm->slave->sii.coe_details.enable_pdo_configuration)) {
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   197
        EC_ERR("Slave %u does not support changing the Pdo mapping!\n",
835
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   198
                fsm->slave->ring_position);
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   199
        fsm->state = ec_fsm_pdo_mapping_state_error;
835
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   200
        return;
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   201
    }
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   202
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
    if (fsm->slave->master->debug_level) {
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   204
        EC_DBG("Changing mapping of Pdo 0x%04X of slave %u.\n",
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
                fsm->pdo->index, fsm->slave->ring_position);
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   208
    if (ec_sdo_request_alloc(&fsm->request, 4)) {
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   209
        fsm->state = ec_fsm_pdo_mapping_state_error;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   210
        return;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   211
    }
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   212
814
a51f857b1b2d Renamed [PS]DO to [PS]do.
Florian Pose <fp@igh-essen.com>
parents: 801
diff changeset
   213
    // set mapped Pdo count to zero
875
c5df898a3618 Fixed access to data pointers in Pdo config and Pdo mapping FSM's.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
   214
    EC_WRITE_U8(fsm->request.data, 0);
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   215
    fsm->request.data_size = 1;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   216
    ec_sdo_request_address(&fsm->request, fsm->pdo->index, 0);
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   217
    ecrt_sdo_request_write(&fsm->request);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
    if (fsm->slave->master->debug_level)
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
        EC_DBG("Setting entry count to zero for Pdo 0x%04X.\n",
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
                fsm->pdo->index);
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   222
    fsm->state = ec_fsm_pdo_mapping_state_zero_count;
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   223
    ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
/** Process next Pdo entry.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   231
ec_pdo_entry_t *ec_fsm_pdo_mapping_next_entry(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   232
        const ec_fsm_pdo_mapping_t *fsm, /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
        const struct list_head *list /**< current entry list item */
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
    list = list->next; 
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
    if (list == &fsm->pdo->entries)
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
        return NULL; // no next entry
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
    return list_entry(list, ec_pdo_entry_t, list);
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
/** Starts to add a Pdo entry.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   246
void ec_fsm_pdo_mapping_add_entry(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   247
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    uint32_t value;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
    value = fsm->entry->index << 16
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
        | fsm->entry->subindex << 8 | fsm->entry->bit_length;
875
c5df898a3618 Fixed access to data pointers in Pdo config and Pdo mapping FSM's.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
   254
    EC_WRITE_U32(fsm->request.data, value);
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   255
    fsm->request.data_size = 4;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   256
    ec_sdo_request_address(&fsm->request, fsm->pdo->index, fsm->entry_count);
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   257
    ecrt_sdo_request_write(&fsm->request);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
    if (fsm->slave->master->debug_level)
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
        EC_DBG("Configuring Pdo entry %08X at position %u.\n",
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
                value, fsm->entry_count);
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
    
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   262
    fsm->state = ec_fsm_pdo_mapping_state_add_entry;
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   263
    ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   269
/** Set the number of mapped entries to zero.
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   270
 */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   271
void ec_fsm_pdo_mapping_state_zero_count(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   272
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   278
        EC_ERR("Failed to clear Pdo mapping for slave %u.\n",
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
                fsm->slave->ring_position);
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   280
        fsm->state = ec_fsm_pdo_mapping_state_error;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
        return;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
    // find first entry
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
    if (!(fsm->entry =
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   286
                ec_fsm_pdo_mapping_next_entry(fsm, &fsm->pdo->entries))) {
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
        if (fsm->slave->master->debug_level)
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   288
            EC_DBG("No entries to map for Pdo 0x%04X of slave %u.\n",
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
                    fsm->pdo->index, fsm->slave->ring_position);
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   290
        ec_fsm_pdo_mapping_next_pdo(fsm);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
        return;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
    // add first entry
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
    fsm->entry_count = 1;
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   296
    ec_fsm_pdo_mapping_add_entry(fsm);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
/** Add a Pdo entry.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   303
void ec_fsm_pdo_mapping_state_add_entry(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   304
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
        EC_ERR("Failed to add entry 0x%04X:%u for slave %u.\n",
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
                fsm->entry->index, fsm->entry->subindex,
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
                fsm->slave->ring_position);
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   313
        fsm->state = ec_fsm_pdo_mapping_state_error;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
        return;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
    // find next entry
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   318
    if (!(fsm->entry = ec_fsm_pdo_mapping_next_entry(fsm, &fsm->entry->list))) {
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
        // No more entries to add. Write entry count.
875
c5df898a3618 Fixed access to data pointers in Pdo config and Pdo mapping FSM's.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
   320
        EC_WRITE_U8(fsm->request.data, fsm->entry_count);
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   321
        fsm->request.data_size = 1;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   322
        ec_sdo_request_address(&fsm->request, fsm->pdo->index, 0);
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   323
        ecrt_sdo_request_write(&fsm->request);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
        if (fsm->slave->master->debug_level)
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
            EC_DBG("Setting number of Pdo entries to %u.\n",
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
                    fsm->entry_count);
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
        
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   328
        fsm->state = ec_fsm_pdo_mapping_state_entry_count;
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   329
        ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
        ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
        return;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
    // add next entry
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
    fsm->entry_count++;
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   336
    ec_fsm_pdo_mapping_add_entry(fsm);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
/** Set the number of entries.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   343
void ec_fsm_pdo_mapping_state_entry_count(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   344
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
        EC_ERR("Failed to set number of entries for slave %u.\n",
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
                fsm->slave->ring_position);
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   352
        fsm->state = ec_fsm_pdo_mapping_state_error;
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
        return;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
    if (fsm->slave->master->debug_level)
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   357
        EC_DBG("Successfully configured mapping for Pdo 0x%04X on slave %u.\n",
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
                fsm->pdo->index, fsm->slave->ring_position);
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   360
    ec_fsm_pdo_mapping_next_pdo(fsm);
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
/******************************************************************************
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
 * Common state functions
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
 *****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
/** State: ERROR.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   369
void ec_fsm_pdo_mapping_state_error(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   370
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   372
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
/*****************************************************************************/
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
/** State: END.
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
 */
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   379
void ec_fsm_pdo_mapping_state_end(
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   380
        ec_fsm_pdo_mapping_t *fsm /**< Pdo mapping state machine. */
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   381
        )
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   382
{
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   383
}
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   384
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 877
diff changeset
   385
/*****************************************************************************/