Layed out FMMU structure and methods to own files.
--- a/master/Kbuild Wed Mar 07 13:12:33 2007 +0000
+++ b/master/Kbuild Wed Mar 07 13:29:29 2007 +0000
@@ -35,9 +35,9 @@
obj-m := ec_master.o
-ec_master-objs := module.o master.o device.o device_id.o pdo.o sync.o slave.o \
- datagram.o domain.o mailbox.o canopen.o ethernet.o fsm_sii.o fsm_change.o \
- fsm_coe.o fsm_slave.o fsm_master.o xmldev.o
+ec_master-objs := module.o master.o device.o device_id.o pdo.o sync.o fmmu.o \
+ slave.o datagram.o domain.o mailbox.o canopen.o ethernet.o fsm_sii.o \
+ fsm_change.o fsm_coe.o fsm_slave.o fsm_master.o xmldev.o
ifeq ($(EC_DBG_IF),1)
ec_master-objs += debug.o
--- a/master/Makefile.am Wed Mar 07 13:12:33 2007 +0000
+++ b/master/Makefile.am Wed Mar 07 13:29:29 2007 +0000
@@ -40,6 +40,7 @@
device_id.c device_id.h \
pdo.c pdo.h \
sync.c sync.h \
+ fmmu.c fmmu.h \
domain.c domain.h \
doxygen.c \
ethernet.c ethernet.h \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/master/fmmu.c Wed Mar 07 13:29:29 2007 +0000
@@ -0,0 +1,97 @@
+/******************************************************************************
+ *
+ * $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 FMMU methods.
+*/
+
+/*****************************************************************************/
+
+#include "globals.h"
+#include "slave.h"
+#include "master.h"
+#include "fmmu.h"
+
+/*****************************************************************************/
+
+/**
+ * FMMU Constructor.
+ */
+
+void ec_fmmu_init(
+ ec_fmmu_t *fmmu, /**< EtherCAT FMMU */
+ ec_slave_t *slave, /**< EtherCAT slave */
+ unsigned int index /**< FMMU index */
+ )
+{
+ fmmu->slave = slave;
+ fmmu->index = index;
+}
+
+/*****************************************************************************/
+
+/**
+ * Initializes an FMMU configuration page.
+ * The referenced memory (\a data) must be at least EC_FMMU_SIZE bytes.
+ */
+
+void ec_fmmu_config(
+ const ec_fmmu_t *fmmu, /**< EtherCAT FMMU */
+ uint8_t *data /**> configuration memory */
+ )
+{
+ size_t sync_size;
+
+ sync_size = ec_slave_calc_sync_size(fmmu->slave, fmmu->sync);
+
+ if (fmmu->slave->master->debug_level) {
+ EC_DBG("FMMU%u: LogAddr 0x%08X, Size %3i, PhysAddr 0x%04X, Dir %s\n",
+ fmmu->index, fmmu->logical_start_address,
+ sync_size, fmmu->sync->physical_start_address,
+ ((fmmu->sync->control_register & 0x04) ? "out" : "in"));
+ }
+
+ EC_WRITE_U32(data, fmmu->logical_start_address);
+ EC_WRITE_U16(data + 4, sync_size); // size of fmmu
+ EC_WRITE_U8 (data + 6, 0x00); // logical start bit
+ EC_WRITE_U8 (data + 7, 0x07); // logical end bit
+ EC_WRITE_U16(data + 8, fmmu->sync->physical_start_address);
+ EC_WRITE_U8 (data + 10, 0x00); // physical start bit
+ EC_WRITE_U8 (data + 11, ((fmmu->sync->control_register & 0x04)
+ ? 0x02 : 0x01));
+ EC_WRITE_U16(data + 12, 0x0001); // enable
+ EC_WRITE_U16(data + 14, 0x0000); // reserved
+}
+
+/*****************************************************************************/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/master/fmmu.h Wed Mar 07 13:29:29 2007 +0000
@@ -0,0 +1,77 @@
+/******************************************************************************
+ *
+ * $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 FMMU structure.
+*/
+
+/*****************************************************************************/
+
+#ifndef _EC_FMMU_H_
+#define _EC_FMMU_H_
+
+#include "../include/ecrt.h"
+
+#include "globals.h"
+
+/*****************************************************************************/
+
+/** size of an FMMU configuration page */
+#define EC_FMMU_SIZE 16
+
+/*****************************************************************************/
+
+/**
+ * FMMU configuration.
+ */
+
+typedef struct
+{
+ const ec_slave_t *slave; /**< EtherCAT slave, the FMMU belongs to */
+ unsigned int index; /**< FMMU index */
+ const ec_domain_t *domain; /**< domain */
+ const ec_sync_t *sync; /**< sync manager */
+ uint32_t logical_start_address; /**< logical start address */
+}
+ec_fmmu_t;
+
+/*****************************************************************************/
+
+void ec_fmmu_init(ec_fmmu_t *, ec_slave_t *, unsigned int);
+
+void ec_fmmu_config(const ec_fmmu_t *, uint8_t *);
+
+/*****************************************************************************/
+
+#endif
--- a/master/fsm_slave.c Wed Mar 07 13:12:33 2007 +0000
+++ b/master/fsm_slave.c Wed Mar 07 13:29:29 2007 +0000
@@ -879,8 +879,7 @@
0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
memset(datagram->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count);
for (j = 0; j < slave->fmmu_count; j++) {
- ec_slave_fmmu_config(slave, &slave->fmmus[j],
- datagram->data + EC_FMMU_SIZE * j);
+ ec_fmmu_config(&slave->fmmus[j], datagram->data + EC_FMMU_SIZE * j);
}
ec_master_queue_datagram(master, datagram);
--- a/master/globals.h Wed Mar 07 13:12:33 2007 +0000
+++ b/master/globals.h Wed Mar 07 13:29:29 2007 +0000
@@ -78,9 +78,6 @@
/** size of an EtherCAT datagram footer */
#define EC_DATAGRAM_FOOTER_SIZE 2
-/** size of an FMMU configuration page */
-#define EC_FMMU_SIZE 16
-
/** resulting maximum data size of a single datagram in a frame */
#define EC_MAX_DATA_SIZE (ETH_DATA_LEN - EC_FRAME_HEADER_SIZE \
- EC_DATAGRAM_HEADER_SIZE - EC_DATAGRAM_FOOTER_SIZE)
--- a/master/slave.c Wed Mar 07 13:12:33 2007 +0000
+++ b/master/slave.c Wed Mar 07 13:29:29 2007 +0000
@@ -591,21 +591,22 @@
/*****************************************************************************/
/**
- Prepares an FMMU configuration.
- Configuration data for the FMMU is saved in the slave structure and is
- written to the slave in ecrt_master_activate().
- The FMMU configuration is done in a way, that the complete data range
- of the corresponding sync manager is covered. Seperate FMMUs are configured
- for each domain.
- If the FMMU configuration is already prepared, the function returns with
- success.
- \return 0 in case of success, else < 0
-*/
-
-int ec_slave_prepare_fmmu(ec_slave_t *slave, /**< EtherCAT slave */
- const ec_domain_t *domain, /**< domain */
- const ec_sync_t *sync /**< sync manager */
- )
+ * Prepares an FMMU configuration.
+ * Configuration data for the FMMU is saved in the slave structure and is
+ * written to the slave in ecrt_master_activate().
+ * The FMMU configuration is done in a way, that the complete data range
+ * of the corresponding sync manager is covered. Seperate FMMUs are configured
+ * for each domain.
+ * If the FMMU configuration is already prepared, the function returns with
+ * success.
+ * \return 0 in case of success, else < 0
+ */
+
+int ec_slave_prepare_fmmu(
+ ec_slave_t *slave, /**< EtherCAT slave */
+ const ec_domain_t *domain, /**< domain */
+ const ec_sync_t *sync /**< sync manager */
+ )
{
unsigned int i;
ec_fmmu_t *fmmu;
@@ -626,12 +627,11 @@
fmmu = &slave->fmmus[slave->fmmu_count];
- fmmu->index = slave->fmmu_count;
+ ec_fmmu_init(fmmu, slave, slave->fmmu_count++);
fmmu->domain = domain;
fmmu->sync = sync;
fmmu->logical_start_address = 0;
- slave->fmmu_count++;
slave->pdos_registered = 1;
ec_slave_request_state(slave, EC_SLAVE_STATE_OP);
@@ -1152,42 +1152,6 @@
/*****************************************************************************/
/**
- Initializes an FMMU configuration page.
- The referenced memory (\a data) must be at least EC_FMMU_SIZE bytes.
-*/
-
-void ec_slave_fmmu_config(const ec_slave_t *slave, /**< EtherCAT slave */
- const ec_fmmu_t *fmmu, /**< FMMU */
- uint8_t *data /**> configuration memory */
- )
-{
- size_t sync_size;
-
- sync_size = ec_slave_calc_sync_size(slave, fmmu->sync);
-
- if (slave->master->debug_level) {
- EC_DBG("Slave %3i, FMMU %2i:"
- " LogAddr 0x%08X, Size %3i, PhysAddr 0x%04X, Dir %s\n",
- slave->ring_position, fmmu->index, fmmu->logical_start_address,
- sync_size, fmmu->sync->physical_start_address,
- ((fmmu->sync->control_register & 0x04) ? "out" : "in"));
- }
-
- EC_WRITE_U32(data, fmmu->logical_start_address);
- EC_WRITE_U16(data + 4, sync_size); // size of fmmu
- EC_WRITE_U8 (data + 6, 0x00); // logical start bit
- EC_WRITE_U8 (data + 7, 0x07); // logical end bit
- EC_WRITE_U16(data + 8, fmmu->sync->physical_start_address);
- EC_WRITE_U8 (data + 10, 0x00); // physical start bit
- EC_WRITE_U8 (data + 11, ((fmmu->sync->control_register & 0x04)
- ? 0x02 : 0x01));
- EC_WRITE_U16(data + 12, 0x0001); // enable
- EC_WRITE_U16(data + 14, 0x0000); // reserved
-}
-
-/*****************************************************************************/
-
-/**
\return non-zero if slave is a bus coupler
*/
--- a/master/slave.h Wed Mar 07 13:12:33 2007 +0000
+++ b/master/slave.h Wed Mar 07 13:29:29 2007 +0000
@@ -50,6 +50,7 @@
#include "datagram.h"
#include "pdo.h"
#include "sync.h"
+#include "fmmu.h"
/*****************************************************************************/
@@ -109,21 +110,6 @@
/*****************************************************************************/
/**
- FMMU configuration.
-*/
-
-typedef struct
-{
- unsigned int index; /**< FMMU index */
- const ec_domain_t *domain; /**< domain */
- const ec_sync_t *sync; /**< sync manager */
- uint32_t logical_start_address; /**< logical start address */
-}
-ec_fmmu_t;
-
-/*****************************************************************************/
-
-/**
EtherCAT slave.
*/
@@ -218,7 +204,6 @@
// misc.
ec_sync_t *ec_slave_get_pdo_sync(ec_slave_t *, ec_direction_t);
-void ec_slave_fmmu_config(const ec_slave_t *, const ec_fmmu_t *, uint8_t *);
uint16_t ec_slave_calc_sync_size(const ec_slave_t *, const ec_sync_t *);
int ec_slave_is_coupler(const ec_slave_t *);