Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
authorFlorian Pose <fp@igh-essen.com>
Tue, 19 Feb 2008 16:18:01 +0000
changeset 802 b947d0b09f9a
parent 801 6b1e2b0ed8bc
child 803 c9e147567924
Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
master/Kbuild.in
master/Makefile.am
master/fsm_mapping.c
master/fsm_mapping.h
master/fsm_pdo_mapping.c
master/fsm_pdo_mapping.h
master/fsm_slave.c
master/fsm_slave.h
--- a/master/Kbuild.in	Tue Feb 19 16:09:58 2008 +0000
+++ b/master/Kbuild.in	Tue Feb 19 16:18:01 2008 +0000
@@ -35,8 +35,8 @@
 
 ec_master-objs := module.o master.o device.o pdo.o sync.o fmmu_config.o \
     slave.o slave_config.o pdo_mapping.o datagram.o domain.o mailbox.o \
-    canopen.o fsm_sii.o fsm_change.o fsm_coe.o fsm_coe_map.o fsm_mapping.o \
-    fsm_pdo_config.o fsm_slave.o fsm_master.o xmldev.o
+    canopen.o fsm_sii.o fsm_change.o fsm_coe.o fsm_coe_map.o \
+    fsm_pdo_mapping.o fsm_pdo_config.o fsm_slave.o fsm_master.o xmldev.o
 
 ifeq (@ENABLE_EOE@,1)
 	ec_master-objs += ethernet.o
--- a/master/Makefile.am	Tue Feb 19 16:09:58 2008 +0000
+++ b/master/Makefile.am	Tue Feb 19 16:18:01 2008 +0000
@@ -47,7 +47,7 @@
 	fsm_change.c fsm_change.h \
 	fsm_coe.c fsm_coe.h \
 	fsm_coe_map.c fsm_coe_map.h \
-	fsm_mapping.c fsm_mapping.h \
+	fsm_pdo_mapping.c fsm_pdo_mapping.h \
 	fsm_pdo_config.c fsm_pdo_config.h \
 	fsm_slave.c fsm_slave.h \
 	fsm_master.c fsm_master.h \
--- a/master/fsm_mapping.c	Tue Feb 19 16:09:58 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,370 +0,0 @@
-/******************************************************************************
- *
- *  $Id$
- *
- *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
- *
- *  This file is part of the IgH EtherCAT Master.
- *
- *  The IgH EtherCAT Master is free software; you can redistribute it
- *  and/or modify it under the terms of the GNU General Public License
- *  as published by the Free Software Foundation; either version 2 of the
- *  License, or (at your option) any later version.
- *
- *  The IgH EtherCAT Master is distributed in the hope that it will be
- *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with the IgH EtherCAT Master; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- *  The right to use EtherCAT Technology is granted and comes free of
- *  charge under condition of compatibility of product made by
- *  Licensee. People intending to distribute/sell products based on the
- *  code, have to sign an agreement to guarantee that products using
- *  software based on IgH EtherCAT master stay compatible with the actual
- *  EtherCAT specification (which are released themselves as an open
- *  standard) as the (only) precondition to have the right to use EtherCAT
- *  Technology, IP and trade marks.
- *
- *****************************************************************************/
-
-/** \file
- * EtherCAT PDO mapping state machine.
- */
-
-/*****************************************************************************/
-
-#include "globals.h"
-#include "master.h"
-#include "mailbox.h"
-#include "slave_config.h"
-
-#include "fsm_mapping.h"
-
-/*****************************************************************************/
-
-void ec_fsm_mapping_state_start(ec_fsm_mapping_t *);
-void ec_fsm_mapping_state_zero_count(ec_fsm_mapping_t *);
-void ec_fsm_mapping_state_add_pdo(ec_fsm_mapping_t *);
-void ec_fsm_mapping_state_pdo_count(ec_fsm_mapping_t *);
-void ec_fsm_mapping_state_end(ec_fsm_mapping_t *);
-void ec_fsm_mapping_state_error(ec_fsm_mapping_t *);
-
-void ec_fsm_mapping_next_sync(ec_fsm_mapping_t *);
-
-/*****************************************************************************/
-
-/** Constructor.
- */
-void ec_fsm_mapping_init(
-        ec_fsm_mapping_t *fsm, /**< mapping state machine */
-        ec_fsm_coe_t *fsm_coe /**< CoE state machine to use */
-        )
-{
-    fsm->fsm_coe = fsm_coe;
-    fsm->sdodata.data = (uint8_t *) &fsm->sdo_value;
-}
-
-/*****************************************************************************/
-
-/** Destructor.
- */
-void ec_fsm_mapping_clear(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-}
-
-/*****************************************************************************/
-
-/** Start PDO mapping configuration state machine.
- */
-void ec_fsm_mapping_start(
-        ec_fsm_mapping_t *fsm, /**< mapping state machine */
-        ec_slave_t *slave /**< slave to configure */
-        )
-{
-    fsm->slave = slave;
-    fsm->state = ec_fsm_mapping_state_start;
-}
-
-/*****************************************************************************/
-
-/** Get running state.
- *
- * \return false, if state machine has terminated
- */
-int ec_fsm_mapping_running(
-        const ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-    return fsm->state != ec_fsm_mapping_state_end
-        && fsm->state != ec_fsm_mapping_state_error;
-}
-
-/*****************************************************************************/
-
-/** Executes the current state of the state machine.
- *
- * If the state machine's datagram is not sent or received yet, the execution
- * of the state machine is delayed to the next cycle.
- *
- * \return false, if state machine has terminated
- */
-int ec_fsm_mapping_exec(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-    fsm->state(fsm);
-    return ec_fsm_mapping_running(fsm);
-}
-
-/*****************************************************************************/
-
-/** Get execution result.
- *
- * \return true, if the state machine terminated gracefully
- */
-int ec_fsm_mapping_success(
-        const ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-    return fsm->state == ec_fsm_mapping_state_end;
-}
-
-/******************************************************************************
- * State functions.
- *****************************************************************************/
-
-/** Start mapping configuration.
- */
-void ec_fsm_mapping_state_start(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-    if (!fsm->slave->config) {
-        fsm->state = ec_fsm_mapping_state_end;
-        return;
-    }
-
-    fsm->sync = NULL;
-    ec_fsm_mapping_next_sync(fsm);
-}
-
-/*****************************************************************************/
-
-/** Process mapping of next sync manager.
- */
-void ec_fsm_mapping_next_sync(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-    ec_direction_t dir;
-    const ec_sync_t *sync;
-    const ec_pdo_mapping_t *map;
-
-    for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
-        if (!(sync = ec_slave_get_pdo_sync(fsm->slave, dir))) {
-            EC_WARN("No sync manager for direction %u!\n", dir);
-            continue;
-        }
-
-        if (fsm->sync) { // there is a last SM
-            if (sync == fsm->sync) // this is the last SM
-                fsm->sync = NULL; // take the next one
-        } else {
-            map = &fsm->slave->config->mapping[dir];
-            if (ec_pdo_mapping_equal(&sync->mapping, map))
-                continue;
-
-            fsm->sync = sync;
-            fsm->mapping = map;
-            break;
-        }
-    }
-
-    if (!sync) {
-        if (fsm->slave->master->debug_level)
-            EC_DBG("Pdo mapping finished for slave %u.\n",
-                    fsm->slave->ring_position);
-        fsm->state = ec_fsm_mapping_state_end;
-        return;
-    }
-
-    if (fsm->slave->master->debug_level) {
-        EC_DBG("Configuring PDO mapping for SM%u of slave %u.\n",
-                fsm->sync->index, fsm->slave->ring_position);
-    }
-
-    // set mapped PDO count to zero
-    fsm->sdodata.index = 0x1C10 + fsm->sync->index;
-    fsm->sdodata.subindex = 0; // mapped PDO count
-    EC_WRITE_U8(&fsm->sdo_value, 0); // zero PDOs mapped
-    fsm->sdodata.size = 1;
-    if (fsm->slave->master->debug_level)
-        EC_DBG("Setting PDO count to zero for SM%u.\n", fsm->sync->index);
-
-    fsm->state = ec_fsm_mapping_state_zero_count;
-    ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
-    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
-}
-
-/*****************************************************************************/
-
-/** Process mapping of next PDO.
- */
-ec_pdo_t *ec_fsm_mapping_next_pdo(
-        const ec_fsm_mapping_t *fsm, /**< mapping state machine */
-        const struct list_head *list /**< current PDO list item */
-        )
-{
-    list = list->next; 
-    if (list == &fsm->mapping->pdos)
-        return NULL; // no next PDO
-    return list_entry(list, ec_pdo_t, list);
-}
-
-/*****************************************************************************/
-
-/** Add a Pdo to the mapping.
- */
-void ec_fsm_mapping_add_pdo(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-    fsm->sdodata.subindex = fsm->pdo_count;
-    EC_WRITE_U16(&fsm->sdo_value, fsm->pdo->index);
-    fsm->sdodata.size = 2;
-
-    if (fsm->slave->master->debug_level)
-        EC_DBG("Mapping PDO 0x%04X at position %u.\n",
-                fsm->pdo->index, fsm->sdodata.subindex);
-    
-    fsm->state = ec_fsm_mapping_state_add_pdo;
-    ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
-    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
-}
-
-/*****************************************************************************/
-
-/** Set the number of mapped PDOs to zero.
- */
-void ec_fsm_mapping_state_zero_count(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
-
-    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
-        EC_ERR("Failed to clear PDO mapping for slave %u.\n",
-                fsm->slave->ring_position);
-        fsm->state = ec_fsm_mapping_state_error;
-        return;
-    }
-
-    // map all PDOs belonging to the current sync manager
-    
-    // find first PDO
-    if (!(fsm->pdo = ec_fsm_mapping_next_pdo(fsm, &fsm->mapping->pdos))) {
-        if (fsm->slave->master->debug_level)
-            EC_DBG("No PDOs to map for SM%u of slave %u.\n",
-                    fsm->sync->index, fsm->slave->ring_position);
-        ec_fsm_mapping_next_sync(fsm);
-        return;
-    }
-
-    // add first PDO to mapping
-    fsm->pdo_count = 1;
-    ec_fsm_mapping_add_pdo(fsm);
-}
-
-/*****************************************************************************/
-
-/** Add a PDO to the sync managers mapping.
- */
-void ec_fsm_mapping_state_add_pdo(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
-
-    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
-        EC_ERR("Failed to map PDO 0x%04X for SM%u of slave %u.\n",
-                fsm->pdo->index, fsm->sync->index, fsm->slave->ring_position);
-        fsm->state = ec_fsm_mapping_state_error;
-        return;
-    }
-
-    // find next PDO
-    if (!(fsm->pdo = ec_fsm_mapping_next_pdo(fsm, &fsm->pdo->list))) {
-        // no more PDOs to map. write PDO count
-        fsm->sdodata.subindex = 0;
-        EC_WRITE_U8(&fsm->sdo_value, fsm->pdo_count);
-        fsm->sdodata.size = 1;
-
-        if (fsm->slave->master->debug_level)
-            EC_DBG("Setting number of mapped PDOs to %u.\n",
-                    fsm->pdo_count);
-        
-        fsm->state = ec_fsm_mapping_state_pdo_count;
-        ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
-        ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
-        return;
-    }
-
-    // add next PDO to mapping
-    fsm->pdo_count++;
-    ec_fsm_mapping_add_pdo(fsm);
-}
-
-/*****************************************************************************/
-
-/** Set the number of mapped PDOs.
- */
-void ec_fsm_mapping_state_pdo_count(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
-
-    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
-        EC_ERR("Failed to set number of mapped PDOs for slave %u.\n",
-                fsm->slave->ring_position);
-        fsm->state = ec_fsm_mapping_state_error;
-        return;
-    }
-
-    if (fsm->slave->master->debug_level)
-        EC_DBG("Successfully set PDO mapping for SM%u of slave %u.\n",
-                fsm->sync->index, fsm->slave->ring_position);
-
-    // mapping configuration for this sync manager complete.
-    ec_fsm_mapping_next_sync(fsm);
-}
-
-/******************************************************************************
- * Common state functions
- *****************************************************************************/
-
-/** State: ERROR.
- */
-void ec_fsm_mapping_state_error(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-}
-
-/*****************************************************************************/
-
-/** State: END.
- */
-void ec_fsm_mapping_state_end(
-        ec_fsm_mapping_t *fsm /**< mapping state machine */
-        )
-{
-}
-
-/*****************************************************************************/
--- a/master/fsm_mapping.h	Tue Feb 19 16:09:58 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-/******************************************************************************
- *
- *  $Id$
- *
- *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
- *
- *  This file is part of the IgH EtherCAT Master.
- *
- *  The IgH EtherCAT Master is free software; you can redistribute it
- *  and/or modify it under the terms of the GNU General Public License
- *  as published by the Free Software Foundation; either version 2 of the
- *  License, or (at your option) any later version.
- *
- *  The IgH EtherCAT Master is distributed in the hope that it will be
- *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with the IgH EtherCAT Master; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- *  The right to use EtherCAT Technology is granted and comes free of
- *  charge under condition of compatibility of product made by
- *  Licensee. People intending to distribute/sell products based on the
- *  code, have to sign an agreement to guarantee that products using
- *  software based on IgH EtherCAT master stay compatible with the actual
- *  EtherCAT specification (which are released themselves as an open
- *  standard) as the (only) precondition to have the right to use EtherCAT
- *  Technology, IP and trade marks.
- *
- *****************************************************************************/
-
-/**
-   \file
-   EtherCAT PDO mapping state machine structures.
-*/
-
-/*****************************************************************************/
-
-#ifndef __EC_FSM_MAPPING__
-#define __EC_FSM_MAPPING__
-
-#include "globals.h"
-#include "../include/ecrt.h"
-#include "datagram.h"
-#include "fsm_coe.h"
-
-/*****************************************************************************/
-
-typedef struct ec_fsm_mapping ec_fsm_mapping_t; /**< \see ec_fsm_mapping */
-
-/** Pdo mapping state machine.
- */
-struct ec_fsm_mapping
-{
-    void (*state)(ec_fsm_mapping_t *); /**< State function. */
-    ec_fsm_coe_t *fsm_coe; /**< CoE state machine to use. */
-    ec_slave_t *slave; /**< Slave the FSM runs on. */
-
-    const ec_sync_t *sync; /**< Current sync manager. */
-    const ec_pdo_mapping_t *mapping; /**< Target Pdo mapping. */
-    const ec_pdo_t *pdo; /**< Current Pdo. */
-
-    ec_sdo_data_t sdodata; /**< SDO configuration data. */
-    uint16_t sdo_value; /**< SDO value. */
-    unsigned int pdo_count; /**< Number of mapped Pdos. */
-};
-
-/*****************************************************************************/
-
-void ec_fsm_mapping_init(ec_fsm_mapping_t *, ec_fsm_coe_t *);
-void ec_fsm_mapping_clear(ec_fsm_mapping_t *);
-
-void ec_fsm_mapping_start(ec_fsm_mapping_t *, ec_slave_t *);
-int ec_fsm_mapping_exec(ec_fsm_mapping_t *);
-int ec_fsm_mapping_success(const ec_fsm_mapping_t *);
-
-/*****************************************************************************/
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/fsm_pdo_mapping.c	Tue Feb 19 16:18:01 2008 +0000
@@ -0,0 +1,370 @@
+/******************************************************************************
+ *
+ *  $Id$
+ *
+ *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it
+ *  and/or modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  The IgH EtherCAT Master is distributed in the hope that it will be
+ *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  The right to use EtherCAT Technology is granted and comes free of
+ *  charge under condition of compatibility of product made by
+ *  Licensee. People intending to distribute/sell products based on the
+ *  code, have to sign an agreement to guarantee that products using
+ *  software based on IgH EtherCAT master stay compatible with the actual
+ *  EtherCAT specification (which are released themselves as an open
+ *  standard) as the (only) precondition to have the right to use EtherCAT
+ *  Technology, IP and trade marks.
+ *
+ *****************************************************************************/
+
+/** \file
+ * EtherCAT PDO mapping state machine.
+ */
+
+/*****************************************************************************/
+
+#include "globals.h"
+#include "master.h"
+#include "mailbox.h"
+#include "slave_config.h"
+
+#include "fsm_pdo_mapping.h"
+
+/*****************************************************************************/
+
+void ec_fsm_pdo_mapping_state_start(ec_fsm_pdo_mapping_t *);
+void ec_fsm_pdo_mapping_state_zero_count(ec_fsm_pdo_mapping_t *);
+void ec_fsm_pdo_mapping_state_add_pdo(ec_fsm_pdo_mapping_t *);
+void ec_fsm_pdo_mapping_state_pdo_count(ec_fsm_pdo_mapping_t *);
+void ec_fsm_pdo_mapping_state_end(ec_fsm_pdo_mapping_t *);
+void ec_fsm_pdo_mapping_state_error(ec_fsm_pdo_mapping_t *);
+
+void ec_fsm_pdo_mapping_next_sync(ec_fsm_pdo_mapping_t *);
+
+/*****************************************************************************/
+
+/** Constructor.
+ */
+void ec_fsm_pdo_mapping_init(
+        ec_fsm_pdo_mapping_t *fsm, /**< mapping state machine */
+        ec_fsm_coe_t *fsm_coe /**< CoE state machine to use */
+        )
+{
+    fsm->fsm_coe = fsm_coe;
+    fsm->sdodata.data = (uint8_t *) &fsm->sdo_value;
+}
+
+/*****************************************************************************/
+
+/** Destructor.
+ */
+void ec_fsm_pdo_mapping_clear(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+}
+
+/*****************************************************************************/
+
+/** Start PDO mapping configuration state machine.
+ */
+void ec_fsm_pdo_mapping_start(
+        ec_fsm_pdo_mapping_t *fsm, /**< mapping state machine */
+        ec_slave_t *slave /**< slave to configure */
+        )
+{
+    fsm->slave = slave;
+    fsm->state = ec_fsm_pdo_mapping_state_start;
+}
+
+/*****************************************************************************/
+
+/** Get running state.
+ *
+ * \return false, if state machine has terminated
+ */
+int ec_fsm_pdo_mapping_running(
+        const ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+    return fsm->state != ec_fsm_pdo_mapping_state_end
+        && fsm->state != ec_fsm_pdo_mapping_state_error;
+}
+
+/*****************************************************************************/
+
+/** Executes the current state of the state machine.
+ *
+ * If the state machine's datagram is not sent or received yet, the execution
+ * of the state machine is delayed to the next cycle.
+ *
+ * \return false, if state machine has terminated
+ */
+int ec_fsm_pdo_mapping_exec(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+    fsm->state(fsm);
+    return ec_fsm_pdo_mapping_running(fsm);
+}
+
+/*****************************************************************************/
+
+/** Get execution result.
+ *
+ * \return true, if the state machine terminated gracefully
+ */
+int ec_fsm_pdo_mapping_success(
+        const ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+    return fsm->state == ec_fsm_pdo_mapping_state_end;
+}
+
+/******************************************************************************
+ * State functions.
+ *****************************************************************************/
+
+/** Start mapping configuration.
+ */
+void ec_fsm_pdo_mapping_state_start(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+    if (!fsm->slave->config) {
+        fsm->state = ec_fsm_pdo_mapping_state_end;
+        return;
+    }
+
+    fsm->sync = NULL;
+    ec_fsm_pdo_mapping_next_sync(fsm);
+}
+
+/*****************************************************************************/
+
+/** Process mapping of next sync manager.
+ */
+void ec_fsm_pdo_mapping_next_sync(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+    ec_direction_t dir;
+    const ec_sync_t *sync;
+    const ec_pdo_mapping_t *map;
+
+    for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
+        if (!(sync = ec_slave_get_pdo_sync(fsm->slave, dir))) {
+            EC_WARN("No sync manager for direction %u!\n", dir);
+            continue;
+        }
+
+        if (fsm->sync) { // there is a last SM
+            if (sync == fsm->sync) // this is the last SM
+                fsm->sync = NULL; // take the next one
+        } else {
+            map = &fsm->slave->config->mapping[dir];
+            if (ec_pdo_mapping_equal(&sync->mapping, map))
+                continue;
+
+            fsm->sync = sync;
+            fsm->mapping = map;
+            break;
+        }
+    }
+
+    if (!sync) {
+        if (fsm->slave->master->debug_level)
+            EC_DBG("Pdo mapping finished for slave %u.\n",
+                    fsm->slave->ring_position);
+        fsm->state = ec_fsm_pdo_mapping_state_end;
+        return;
+    }
+
+    if (fsm->slave->master->debug_level) {
+        EC_DBG("Configuring PDO mapping for SM%u of slave %u.\n",
+                fsm->sync->index, fsm->slave->ring_position);
+    }
+
+    // set mapped PDO count to zero
+    fsm->sdodata.index = 0x1C10 + fsm->sync->index;
+    fsm->sdodata.subindex = 0; // mapped PDO count
+    EC_WRITE_U8(&fsm->sdo_value, 0); // zero PDOs mapped
+    fsm->sdodata.size = 1;
+    if (fsm->slave->master->debug_level)
+        EC_DBG("Setting PDO count to zero for SM%u.\n", fsm->sync->index);
+
+    fsm->state = ec_fsm_pdo_mapping_state_zero_count;
+    ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
+    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
+}
+
+/*****************************************************************************/
+
+/** Process mapping of next PDO.
+ */
+ec_pdo_t *ec_fsm_pdo_mapping_next_pdo(
+        const ec_fsm_pdo_mapping_t *fsm, /**< mapping state machine */
+        const struct list_head *list /**< current PDO list item */
+        )
+{
+    list = list->next; 
+    if (list == &fsm->mapping->pdos)
+        return NULL; // no next PDO
+    return list_entry(list, ec_pdo_t, list);
+}
+
+/*****************************************************************************/
+
+/** Add a Pdo to the mapping.
+ */
+void ec_fsm_pdo_mapping_add_pdo(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+    fsm->sdodata.subindex = fsm->pdo_count;
+    EC_WRITE_U16(&fsm->sdo_value, fsm->pdo->index);
+    fsm->sdodata.size = 2;
+
+    if (fsm->slave->master->debug_level)
+        EC_DBG("Mapping PDO 0x%04X at position %u.\n",
+                fsm->pdo->index, fsm->sdodata.subindex);
+    
+    fsm->state = ec_fsm_pdo_mapping_state_add_pdo;
+    ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
+    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
+}
+
+/*****************************************************************************/
+
+/** Set the number of mapped PDOs to zero.
+ */
+void ec_fsm_pdo_mapping_state_zero_count(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
+
+    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
+        EC_ERR("Failed to clear PDO mapping for slave %u.\n",
+                fsm->slave->ring_position);
+        fsm->state = ec_fsm_pdo_mapping_state_error;
+        return;
+    }
+
+    // map all PDOs belonging to the current sync manager
+    
+    // find first PDO
+    if (!(fsm->pdo = ec_fsm_pdo_mapping_next_pdo(fsm, &fsm->mapping->pdos))) {
+        if (fsm->slave->master->debug_level)
+            EC_DBG("No PDOs to map for SM%u of slave %u.\n",
+                    fsm->sync->index, fsm->slave->ring_position);
+        ec_fsm_pdo_mapping_next_sync(fsm);
+        return;
+    }
+
+    // add first PDO to mapping
+    fsm->pdo_count = 1;
+    ec_fsm_pdo_mapping_add_pdo(fsm);
+}
+
+/*****************************************************************************/
+
+/** Add a PDO to the sync managers mapping.
+ */
+void ec_fsm_pdo_mapping_state_add_pdo(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
+
+    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
+        EC_ERR("Failed to map PDO 0x%04X for SM%u of slave %u.\n",
+                fsm->pdo->index, fsm->sync->index, fsm->slave->ring_position);
+        fsm->state = ec_fsm_pdo_mapping_state_error;
+        return;
+    }
+
+    // find next PDO
+    if (!(fsm->pdo = ec_fsm_pdo_mapping_next_pdo(fsm, &fsm->pdo->list))) {
+        // no more PDOs to map. write PDO count
+        fsm->sdodata.subindex = 0;
+        EC_WRITE_U8(&fsm->sdo_value, fsm->pdo_count);
+        fsm->sdodata.size = 1;
+
+        if (fsm->slave->master->debug_level)
+            EC_DBG("Setting number of mapped PDOs to %u.\n",
+                    fsm->pdo_count);
+        
+        fsm->state = ec_fsm_pdo_mapping_state_pdo_count;
+        ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata);
+        ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
+        return;
+    }
+
+    // add next PDO to mapping
+    fsm->pdo_count++;
+    ec_fsm_pdo_mapping_add_pdo(fsm);
+}
+
+/*****************************************************************************/
+
+/** Set the number of mapped PDOs.
+ */
+void ec_fsm_pdo_mapping_state_pdo_count(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
+
+    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
+        EC_ERR("Failed to set number of mapped PDOs for slave %u.\n",
+                fsm->slave->ring_position);
+        fsm->state = ec_fsm_pdo_mapping_state_error;
+        return;
+    }
+
+    if (fsm->slave->master->debug_level)
+        EC_DBG("Successfully set PDO mapping for SM%u of slave %u.\n",
+                fsm->sync->index, fsm->slave->ring_position);
+
+    // mapping configuration for this sync manager complete.
+    ec_fsm_pdo_mapping_next_sync(fsm);
+}
+
+/******************************************************************************
+ * Common state functions
+ *****************************************************************************/
+
+/** State: ERROR.
+ */
+void ec_fsm_pdo_mapping_state_error(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+}
+
+/*****************************************************************************/
+
+/** State: END.
+ */
+void ec_fsm_pdo_mapping_state_end(
+        ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */
+        )
+{
+}
+
+/*****************************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/fsm_pdo_mapping.h	Tue Feb 19 16:18:01 2008 +0000
@@ -0,0 +1,85 @@
+/******************************************************************************
+ *
+ *  $Id$
+ *
+ *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ *  This file is part of the IgH EtherCAT Master.
+ *
+ *  The IgH EtherCAT Master is free software; you can redistribute it
+ *  and/or modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2 of the
+ *  License, or (at your option) any later version.
+ *
+ *  The IgH EtherCAT Master is distributed in the hope that it will be
+ *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with the IgH EtherCAT Master; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *  The right to use EtherCAT Technology is granted and comes free of
+ *  charge under condition of compatibility of product made by
+ *  Licensee. People intending to distribute/sell products based on the
+ *  code, have to sign an agreement to guarantee that products using
+ *  software based on IgH EtherCAT master stay compatible with the actual
+ *  EtherCAT specification (which are released themselves as an open
+ *  standard) as the (only) precondition to have the right to use EtherCAT
+ *  Technology, IP and trade marks.
+ *
+ *****************************************************************************/
+
+/**
+   \file
+   EtherCAT PDO mapping state machine structures.
+*/
+
+/*****************************************************************************/
+
+#ifndef __EC_FSM_PDO_MAPPING__
+#define __EC_FSM_PDO_MAPPING__
+
+#include "../include/ecrt.h"
+
+#include "globals.h"
+#include "datagram.h"
+#include "fsm_coe.h"
+
+/*****************************************************************************/
+
+/**
+ * \see ec_fsm_pdo_mapping
+ */
+typedef struct ec_fsm_pdo_mapping ec_fsm_pdo_mapping_t;
+
+/** Pdo mapping state machine.
+ */
+struct ec_fsm_pdo_mapping
+{
+    void (*state)(ec_fsm_pdo_mapping_t *); /**< State function. */
+    ec_fsm_coe_t *fsm_coe; /**< CoE state machine to use. */
+    ec_slave_t *slave; /**< Slave the FSM runs on. */
+
+    const ec_sync_t *sync; /**< Current sync manager. */
+    const ec_pdo_mapping_t *mapping; /**< Target Pdo mapping. */
+    const ec_pdo_t *pdo; /**< Current Pdo. */
+
+    ec_sdo_data_t sdodata; /**< SDO configuration data. */
+    uint16_t sdo_value; /**< SDO value. */
+    unsigned int pdo_count; /**< Number of mapped Pdos. */
+};
+
+/*****************************************************************************/
+
+void ec_fsm_pdo_mapping_init(ec_fsm_pdo_mapping_t *, ec_fsm_coe_t *);
+void ec_fsm_pdo_mapping_clear(ec_fsm_pdo_mapping_t *);
+
+void ec_fsm_pdo_mapping_start(ec_fsm_pdo_mapping_t *, ec_slave_t *);
+int ec_fsm_pdo_mapping_exec(ec_fsm_pdo_mapping_t *);
+int ec_fsm_pdo_mapping_success(const ec_fsm_pdo_mapping_t *);
+
+/*****************************************************************************/
+
+#endif
--- a/master/fsm_slave.c	Tue Feb 19 16:09:58 2008 +0000
+++ b/master/fsm_slave.c	Tue Feb 19 16:18:01 2008 +0000
@@ -92,8 +92,8 @@
     ec_fsm_sii_init(&fsm->fsm_sii, fsm->datagram);
     ec_fsm_change_init(&fsm->fsm_change, fsm->datagram);
     ec_fsm_coe_init(&fsm->fsm_coe, fsm->datagram);
-    ec_fsm_mapping_init(&fsm->fsm_map, &fsm->fsm_coe);
-    ec_fsm_pdo_config_init(&fsm->fsm_pdo, &fsm->fsm_coe);
+    ec_fsm_pdo_mapping_init(&fsm->fsm_pdo_map, &fsm->fsm_coe);
+    ec_fsm_pdo_config_init(&fsm->fsm_pdo_conf, &fsm->fsm_coe);
 }
 
 /*****************************************************************************/
@@ -106,8 +106,8 @@
     ec_fsm_sii_clear(&fsm->fsm_sii);
     ec_fsm_change_clear(&fsm->fsm_change);
     ec_fsm_coe_clear(&fsm->fsm_coe);
-    ec_fsm_mapping_clear(&fsm->fsm_map);
-    ec_fsm_pdo_config_clear(&fsm->fsm_pdo);
+    ec_fsm_pdo_mapping_clear(&fsm->fsm_pdo_map);
+    ec_fsm_pdo_config_clear(&fsm->fsm_pdo_conf);
 }
 
 /*****************************************************************************/
@@ -941,8 +941,8 @@
 {
     // start configuring PDO mapping
     fsm->state = ec_fsm_slave_conf_state_mapping;
-    ec_fsm_mapping_start(&fsm->fsm_map, fsm->slave);
-    ec_fsm_mapping_exec(&fsm->fsm_map); // execute immediately
+    ec_fsm_pdo_mapping_start(&fsm->fsm_pdo_map, fsm->slave);
+    ec_fsm_pdo_mapping_exec(&fsm->fsm_pdo_map); // execute immediately
 }
 
 /*****************************************************************************/
@@ -955,9 +955,9 @@
         ec_fsm_slave_t *fsm /**< slave state machine */
         )
 {
-    if (ec_fsm_mapping_exec(&fsm->fsm_map)) return;
-
-    if (!ec_fsm_mapping_success(&fsm->fsm_map)) {
+    if (ec_fsm_pdo_mapping_exec(&fsm->fsm_pdo_map)) return;
+
+    if (!ec_fsm_pdo_mapping_success(&fsm->fsm_pdo_map)) {
         EC_ERR("PDO mapping configuration failed for slave %u.\n",
                 fsm->slave->ring_position);
         fsm->slave->error_flag = 1;
@@ -967,8 +967,8 @@
 
     // Start Pdo configuration
     fsm->state = ec_fsm_slave_conf_state_pdo_conf;
-    ec_fsm_pdo_config_start(&fsm->fsm_pdo, fsm->slave);
-    ec_fsm_pdo_config_exec(&fsm->fsm_pdo); // execute immediately
+    ec_fsm_pdo_config_start(&fsm->fsm_pdo_conf, fsm->slave);
+    ec_fsm_pdo_config_exec(&fsm->fsm_pdo_conf); // execute immediately
 }
 
 /*****************************************************************************/
@@ -981,9 +981,9 @@
         ec_fsm_slave_t *fsm /**< slave state machine */
         )
 {
-    if (ec_fsm_pdo_config_exec(&fsm->fsm_pdo)) return;
-
-    if (!ec_fsm_pdo_config_success(&fsm->fsm_pdo)) {
+    if (ec_fsm_pdo_config_exec(&fsm->fsm_pdo_conf)) return;
+
+    if (!ec_fsm_pdo_config_success(&fsm->fsm_pdo_conf)) {
         EC_ERR("Pdo configuration failed for slave %u.\n",
                 fsm->slave->ring_position);
         fsm->slave->error_flag = 1;
--- a/master/fsm_slave.h	Tue Feb 19 16:09:58 2008 +0000
+++ b/master/fsm_slave.h	Tue Feb 19 16:18:01 2008 +0000
@@ -48,7 +48,7 @@
 #include "fsm_sii.h"
 #include "fsm_change.h"
 #include "fsm_coe.h"
-#include "fsm_mapping.h"
+#include "fsm_pdo_mapping.h"
 #include "fsm_pdo_config.h"
 
 /*****************************************************************************/
@@ -70,8 +70,8 @@
     ec_fsm_sii_t fsm_sii; /**< SII state machine. */
     ec_fsm_change_t fsm_change; /**< State change state machine. */
     ec_fsm_coe_t fsm_coe; /**< CoE state machine. */
-    ec_fsm_mapping_t fsm_map; /**< PDO mapping state machine. */
-    ec_fsm_pdo_config_t fsm_pdo; /**< PDO configuration state machine. */
+    ec_fsm_pdo_mapping_t fsm_pdo_map; /**< Pdo mapping state machine. */
+    ec_fsm_pdo_config_t fsm_pdo_conf; /**< Pdo configuration state machine. */
 };
 
 /*****************************************************************************/