Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
authorFlorian Pose <fp@igh-essen.com>
Fri, 29 Feb 2008 12:19:48 +0000
changeset 847 92266462d411
parent 846 19248bbf9308
child 848 ae0829882a72
Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
master/Kbuild.in
master/Makefile.am
master/canopen.c
master/canopen.h
master/fsm_coe.h
master/fsm_coe_map.c
master/fsm_master.h
master/globals.h
master/sdo.c
master/sdo.h
master/sdo_entry.c
master/sdo_entry.h
master/sdo_request.c
master/sdo_request.h
master/slave.h
--- a/master/Kbuild.in	Fri Feb 29 08:27:17 2008 +0000
+++ b/master/Kbuild.in	Fri Feb 29 12:19:48 2008 +0000
@@ -33,11 +33,32 @@
 
 obj-m := ec_master.o
 
-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_pdo_mapping.o fsm_pdo_config.o fsm_slave_scan.o fsm_slave_config.o \
-    fsm_master.o xmldev.o
+ec_master-objs := \
+    datagram.o \
+    device.o \
+    domain.o \
+    fmmu_config.o \
+    fsm_change.o \
+    fsm_coe.o \
+    fsm_coe_map.o \
+    fsm_master.o \
+    fsm_pdo_config.o \
+    fsm_pdo_mapping.o \
+    fsm_sii.o \
+    fsm_slave_config.o \
+    fsm_slave_scan.o \
+    mailbox.o \
+    master.o \
+    module.o \
+    pdo.o \
+    pdo_mapping.o \
+    sdo.o \
+    sdo_entry.o \
+    sdo_request.o \
+    slave.o \
+    slave_config.o \
+    sync.o \
+    xmldev.o
 
 ifeq (@ENABLE_EOE@,1)
 	ec_master-objs += ethernet.o
--- a/master/Makefile.am	Fri Feb 29 08:27:17 2008 +0000
+++ b/master/Makefile.am	Fri Feb 29 12:19:48 2008 +0000
@@ -33,32 +33,34 @@
 
 EXTRA_DIST = \
 	Kbuild.in \
-	canopen.c canopen.h \
 	datagram.c datagram.h \
 	debug.c	debug.h \
 	device.c device.h \
-	pdo.c pdo.h \
-	sync.c sync.h \
-	fmmu_config.c fmmu_config.h \
 	domain.c domain.h \
 	doxygen.c \
 	ethernet.c ethernet.h \
-	fsm_sii.c fsm_sii.h \
+	fmmu_config.c fmmu_config.h \
 	fsm_change.c fsm_change.h \
 	fsm_coe.c fsm_coe.h \
 	fsm_coe_map.c fsm_coe_map.h \
+	fsm_master.c fsm_master.h \
+	fsm_pdo_config.c fsm_pdo_config.h \
 	fsm_pdo_mapping.c fsm_pdo_mapping.h \
-	fsm_pdo_config.c fsm_pdo_config.h \
+	fsm_sii.c fsm_sii.h \
+	fsm_slave_config.c fsm_slave_config.h \
 	fsm_slave_scan.c fsm_slave_scan.h \
-	fsm_slave_config.c fsm_slave_config.h \
-	fsm_master.c fsm_master.h \
 	globals.h \
 	mailbox.c mailbox.h \
 	master.c master.h \
 	module.c \
+	pdo.c pdo.h \
+	pdo_mapping.c pdo_mapping.h \
+	sdo.c sdo.h \
+	sdo_entry.c sdo_entry.h \
+	sdo_request.c sdo_request.h \
 	slave.c slave.h \
 	slave_config.c slave_config.h \
-	pdo_mapping.c pdo_mapping.h \
+	sync.c sync.h \
 	xmldev.c xmldev.h
 
 modules:
--- a/master/canopen.c	Fri Feb 29 08:27:17 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,509 +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
-   Canopen-over-EtherCAT functions.
-*/
-
-/*****************************************************************************/
-
-#include <linux/module.h>
-
-#include "canopen.h"
-#include "master.h"
-
-/*****************************************************************************/
-
-ssize_t ec_show_sdo_attribute(struct kobject *, struct attribute *, char *);
-ssize_t ec_show_sdo_entry_attribute(struct kobject *, struct attribute *,
-                                    char *);
-void ec_sdo_clear(struct kobject *);
-void ec_sdo_entry_clear(struct kobject *);
-
-/*****************************************************************************/
-
-/** \cond */
-
-EC_SYSFS_READ_ATTR(info);
-EC_SYSFS_READ_ATTR(value);
-
-static struct attribute *sdo_def_attrs[] = {
-    &attr_info,
-    NULL,
-};
-
-static struct sysfs_ops sdo_sysfs_ops = {
-    .show = &ec_show_sdo_attribute,
-    .store = NULL
-};
-
-static struct kobj_type ktype_ec_sdo = {
-    .release = ec_sdo_clear,
-    .sysfs_ops = &sdo_sysfs_ops,
-    .default_attrs = sdo_def_attrs
-};
-
-static struct attribute *sdo_entry_def_attrs[] = {
-    &attr_info,
-    &attr_value,
-    NULL,
-};
-
-static struct sysfs_ops sdo_entry_sysfs_ops = {
-    .show = &ec_show_sdo_entry_attribute,
-    .store = NULL
-};
-
-static struct kobj_type ktype_ec_sdo_entry = {
-    .release = ec_sdo_entry_clear,
-    .sysfs_ops = &sdo_entry_sysfs_ops,
-    .default_attrs = sdo_entry_def_attrs
-};
-
-/** \endcond */
-
-/*****************************************************************************/
-
-/**
-   Sdo constructor.
-*/
-
-int ec_sdo_init(ec_sdo_t *sdo, /**< Sdo */
-                uint16_t index, /**< Sdo index */
-                ec_slave_t *slave /**< parent slave */
-                )
-{
-    sdo->slave = slave;
-    sdo->index = index;
-    sdo->object_code = 0x00;
-    sdo->name = NULL;
-    sdo->subindices = 0;
-    INIT_LIST_HEAD(&sdo->entries);
-
-    // init kobject and add it to the hierarchy
-    memset(&sdo->kobj, 0x00, sizeof(struct kobject));
-    kobject_init(&sdo->kobj);
-    sdo->kobj.ktype = &ktype_ec_sdo;
-    sdo->kobj.parent = &slave->sdo_kobj;
-    if (kobject_set_name(&sdo->kobj, "%4X", sdo->index)) {
-        EC_ERR("Failed to set kobj name.\n");
-        kobject_put(&sdo->kobj);
-        return -1;
-    }
-    if (kobject_add(&sdo->kobj)) {
-        EC_ERR("Failed to add Sdo kobject.\n");
-        kobject_put(&sdo->kobj);
-        return -1;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************/
-
-/**
-   Sdo destructor.
-   Clears and frees an Sdo object.
-*/
-
-void ec_sdo_destroy(ec_sdo_t *sdo /**< Sdo */)
-{
-    ec_sdo_entry_t *entry, *next;
-
-    // free all entries
-    list_for_each_entry_safe(entry, next, &sdo->entries, list) {
-        list_del(&entry->list);
-        ec_sdo_entry_destroy(entry);
-    }
-
-    // destroy self
-    kobject_del(&sdo->kobj);
-    kobject_put(&sdo->kobj);
-}
-
-/*****************************************************************************/
-
-/**
-   Clear and free Sdo.
-   This method is called by the kobject,
-   once there are no more references to it.
-*/
-
-void ec_sdo_clear(struct kobject *kobj /**< Sdo's kobject */)
-{
-    ec_sdo_t *sdo = container_of(kobj, ec_sdo_t, kobj);
-
-    if (sdo->name) kfree(sdo->name);
-
-    kfree(sdo);
-}
-
-/*****************************************************************************/
-
-/**
- * Get and Sdo entry from an Sdo via its subindex.
- * \return pointer to Sdo entry, or NULL.
- */
-
-ec_sdo_entry_t *ec_sdo_get_entry(
-        ec_sdo_t *sdo, /**< Sdo */
-        uint8_t subindex /**< entry subindex */
-        )
-{
-    ec_sdo_entry_t *entry;
-
-    list_for_each_entry(entry, &sdo->entries, list) {
-        if (entry->subindex != subindex) continue;
-        return entry;
-    }
-
-    return NULL;
-}
-
-/*****************************************************************************/
-
-/**
- * Print Sdo information to a buffer.
- * /return size of bytes written to buffer.
- */ 
-
-ssize_t ec_sdo_info(ec_sdo_t *sdo, /**< Sdo */
-                    char *buffer /**< target buffer */
-                    )
-{
-    off_t off = 0;
-
-    off += sprintf(buffer + off, "Index: 0x%04X\n", sdo->index);
-    off += sprintf(buffer + off, "Name: %s\n", sdo->name ? sdo->name : "");
-    off += sprintf(buffer + off, "Subindices: %i\n", sdo->subindices);
-
-    return off;
-}
-
-/*****************************************************************************/
-
-/**
- * Show an Sdo as Sysfs attribute.
- * /return size of bytes written to buffer.
- */ 
-
-ssize_t ec_show_sdo_attribute(struct kobject *kobj, /**< kobject */
-                              struct attribute *attr,
-                              char *buffer
-                              )
-{
-    ec_sdo_t *sdo = container_of(kobj, ec_sdo_t, kobj);
-
-    if (attr == &attr_info) {
-        return ec_sdo_info(sdo, buffer);
-    }
-
-    return 0;
-}
-
-/*****************************************************************************/
-
-/**
-   Sdo entry constructor.
-*/
-
-int ec_sdo_entry_init(ec_sdo_entry_t *entry, /**< Sdo entry */
-                      uint8_t subindex, /**< Sdo entry subindex */
-                      ec_sdo_t *sdo /**< parent Sdo */
-                      )
-{
-    entry->sdo = sdo;
-    entry->subindex = subindex;
-    entry->data_type = 0x0000;
-    entry->bit_length = 0;
-    entry->description = NULL;
-
-    // init kobject and add it to the hierarchy
-    memset(&entry->kobj, 0x00, sizeof(struct kobject));
-    kobject_init(&entry->kobj);
-    entry->kobj.ktype = &ktype_ec_sdo_entry;
-    entry->kobj.parent = &sdo->kobj;
-    if (kobject_set_name(&entry->kobj, "%i", entry->subindex)) {
-        EC_ERR("Failed to set kobj name.\n");
-        kobject_put(&entry->kobj);
-        return -1;
-    }
-    if (kobject_add(&entry->kobj)) {
-        EC_ERR("Failed to add entry kobject.\n");
-        kobject_put(&entry->kobj);
-        return -1;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************/
-
-/**
-   Sdo entry destructor.
-   Clears and frees an Sdo entry object.
-*/
-
-void ec_sdo_entry_destroy(ec_sdo_entry_t *entry /**< Sdo entry */)
-{
-    // destroy self
-    kobject_del(&entry->kobj);
-    kobject_put(&entry->kobj);
-}
-
-/*****************************************************************************/
-
-/**
-   Clear and free Sdo entry.
-   This method is called by the kobject,
-   once there are no more references to it.
-*/
-
-void ec_sdo_entry_clear(struct kobject *kobj /**< Sdo entry's kobject */)
-{
-    ec_sdo_entry_t *entry = container_of(kobj, ec_sdo_entry_t, kobj);
-
-    if (entry->description) kfree(entry->description);
-
-    kfree(entry);
-}
-
-/*****************************************************************************/
- 
-/**
- * Print Sdo entry information to a buffer.
- * \return number of bytes written.
- */
-
-ssize_t ec_sdo_entry_info(ec_sdo_entry_t *entry, /**< Sdo entry */
-                          char *buffer /**< target buffer */
-                          )
-{
-    off_t off = 0;
-
-    off += sprintf(buffer + off, "Subindex: 0x%02X\n", entry->subindex);
-    off += sprintf(buffer + off, "Description: %s\n",
-                   entry->description ? entry->description : "");
-    off += sprintf(buffer + off, "Data type: 0x%04X\n", entry->data_type);
-    off += sprintf(buffer + off, "Bit length: %i\n", entry->bit_length);
-
-    return off;
-}
-
-/*****************************************************************************/
-
-/**
- * Format entry data based on the CANopen data type and print it to a buffer.
- * \return number of bytes written.
- */
-
-ssize_t ec_sdo_entry_format_data(ec_sdo_entry_t *entry, /**< Sdo entry */
-                                 ec_sdo_request_t *request, /**< Sdo request */
-                                 char *buffer /**< target buffer */
-                                 )
-{
-    off_t off = 0;
-    unsigned int i;
-
-    if (entry->data_type == 0x0002) { // int8
-        int8_t value;
-        if (entry->bit_length != 8)
-            goto not_fit;
-        value = EC_READ_S8(request->data);
-        off += sprintf(buffer + off, "%i (0x%02X)\n", value, value);
-    }
-    else if (entry->data_type == 0x0003) { // int16
-        int16_t value;
-        if (entry->bit_length != 16)
-            goto not_fit;
-        value = EC_READ_S16(request->data);
-        off += sprintf(buffer + off, "%i (0x%04X)\n", value, value);
-    }
-    else if (entry->data_type == 0x0004) { // int32
-        int32_t value;
-        if (entry->bit_length != 32)
-            goto not_fit;
-        value = EC_READ_S16(request->data);
-        off += sprintf(buffer + off, "%i (0x%08X)\n", value, value);
-    }
-    else if (entry->data_type == 0x0005) { // uint8
-        uint8_t value;
-        if (entry->bit_length != 8)
-            goto not_fit;
-        value = EC_READ_U8(request->data);
-        off += sprintf(buffer + off, "%u (0x%02X)\n", value, value);
-    }
-    else if (entry->data_type == 0x0006) { // uint16
-        uint16_t value;
-        if (entry->bit_length != 16)
-            goto not_fit;
-        value = EC_READ_U16(request->data); 
-        off += sprintf(buffer + off, "%u (0x%04X)\n", value, value);
-    }
-    else if (entry->data_type == 0x0007) { // uint32
-        uint32_t value;
-        if (entry->bit_length != 32)
-            goto not_fit;
-        value = EC_READ_U32(request->data);
-        off += sprintf(buffer + off, "%i (0x%08X)\n", value, value);
-    }
-    else if (entry->data_type == 0x0009) { // string
-        off += sprintf(buffer + off, "%s\n", request->data);
-    }
-    else {
-        off += sprintf(buffer + off, "Unknown data type %04X. Data:\n",
-                entry->data_type);
-        goto raw_data;
-    }
-    return off;
-
-not_fit:
-    off += sprintf(buffer + off,
-            "Invalid bit length %u for data type 0x%04X. Data:\n",
-            entry->bit_length, entry->data_type);
-raw_data:
-    for (i = 0; i < request->size; i++)
-        off += sprintf(buffer + off, "%02X (%c)\n",
-                request->data[i], request->data[i]);
-    return off;
-}
-
-/*****************************************************************************/
-
-/**
- * Start Sdo entry reading.
- * This function blocks, until reading is finished, and is interruptible as
- * long as the master state machine has not begun with reading.
- * \return number of bytes written to buffer, or error code.
- */
-
-ssize_t ec_sdo_entry_read_value(ec_sdo_entry_t *entry, /**< Sdo entry */
-                                char *buffer /**< target buffer */
-                                )
-{
-    ec_master_t *master = entry->sdo->slave->master;
-    off_t off = 0;
-    ec_sdo_request_t request;
-
-    ec_sdo_request_init_read(&request, entry->sdo->slave,
-            entry->sdo->index, entry->subindex);
-
-    // schedule request.
-    down(&master->sdo_sem);
-    list_add_tail(&request.list, &master->sdo_requests);
-    up(&master->sdo_sem);
-
-    // wait for processing through FSM
-    if (wait_event_interruptible(master->sdo_queue,
-                request.state != EC_REQUEST_QUEUED)) {
-        // interrupted by signal
-        down(&master->sdo_sem);
-        if (request.state == EC_REQUEST_QUEUED) {
-            list_del(&request.list);
-            up(&master->sdo_sem);
-            return -EINTR;
-        }
-        // request already processing: interrupt not possible.
-        up(&master->sdo_sem);
-    }
-
-    // wait until master FSM has finished processing
-    wait_event(master->sdo_queue, request.state != EC_REQUEST_IN_PROGRESS);
-
-    if (request.state != EC_REQUEST_COMPLETE)
-        return -EIO;
-
-    off += ec_sdo_entry_format_data(entry, &request, buffer);
-
-    ec_sdo_request_clear(&request);
-    return off;
-}
-
-/*****************************************************************************/
-
-/**
- * Show an Sdo entry as Sysfs attribute.
- * /return size of bytes written to buffer.
- */ 
-
-ssize_t ec_show_sdo_entry_attribute(struct kobject *kobj, /**< kobject */
-                                    struct attribute *attr,
-                                    char *buffer
-                                    )
-{
-    ec_sdo_entry_t *entry = container_of(kobj, ec_sdo_entry_t, kobj);
-
-    if (attr == &attr_info) {
-        return ec_sdo_entry_info(entry, buffer);
-    }
-    else if (attr == &attr_value) {
-        return ec_sdo_entry_read_value(entry, buffer);
-    }
-
-    return 0;
-}
-
-/*****************************************************************************/
-
-/**
-   Sdo request constructor.
-*/
-
-void ec_sdo_request_init_read(
-        ec_sdo_request_t *req, /**< Sdo request */
-        ec_slave_t *slave, /**< Slave owning the Sdo. */
-        uint16_t index, /**< Sdo index. */
-        uint8_t subindex /**< Sdo subindex. */
-        )
-{
-    req->slave = slave;
-    req->index = index;
-    req->subindex = subindex;
-    req->data = NULL;
-    req->size = 0;
-    req->state = EC_REQUEST_QUEUED;
-}
-
-/*****************************************************************************/
-
-/**
-   Sdo request destructor.
-*/
-
-void ec_sdo_request_clear(ec_sdo_request_t *req /**< Sdo request */)
-{
-    if (req->data) kfree(req->data);
-}
-
-/*****************************************************************************/
--- a/master/canopen.h	Fri Feb 29 08:27:17 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +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 CANopen structures.
-*/
-
-/*****************************************************************************/
-
-#ifndef _EC_CANOPEN_H_
-#define _EC_CANOPEN_H_
-
-#include <linux/list.h>
-#include <linux/kobject.h>
-
-#include "globals.h"
-#include "slave.h"
-
-/*****************************************************************************/
-
-/** CANopen Sdo.
- */
-struct ec_sdo {
-    struct kobject kobj; /**< kobject */
-    struct list_head list; /**< list item */
-    ec_slave_t *slave; /**< parent slave */
-    uint16_t index; /**< Sdo index */
-    uint8_t object_code; /**< object code */
-    char *name; /**< Sdo name */
-    uint8_t subindices; /**< subindices */
-    struct list_head entries; /**< entry list */
-};
-
-/*****************************************************************************/
-
-/** CANopen Sdo entry.
- */
-typedef struct {
-    struct kobject kobj; /**< kobject */
-    struct list_head list; /**< list item */
-    ec_sdo_t *sdo; /**< parent Sdo */
-    uint8_t subindex; /**< entry subindex */
-    uint16_t data_type; /**< entry data type */
-    uint16_t bit_length; /**< entry length in bit */
-    char *description; /**< entry description */
-} ec_sdo_entry_t;
-
-/*****************************************************************************/
-
-/** CANopen Sdo configuration data.
- */
-typedef struct {
-    struct list_head list; /**< list item */
-    uint16_t index; /**< Sdo index */
-    uint8_t subindex; /**< Sdo subindex */
-    uint8_t *data; /**< pointer to Sdo data */
-    size_t size; /**< size of Sdo data */
-}
-ec_sdo_data_t;
-
-/*****************************************************************************/
-
-/**
-   CANopen Sdo request.
-*/
-
-typedef struct {
-    struct list_head list; /**< list item */
-    ec_slave_t *slave; /**< Slave owning the Sdo. */
-    uint16_t index; /**< Sdo index. */
-    uint8_t subindex; /**< Sdo subindex. */
-    uint8_t *data; /**< pointer to Sdo data */
-    size_t size; /**< size of Sdo data */
-    ec_request_state_t state; /**< Sdo request state */
-} ec_sdo_request_t;
-
-/*****************************************************************************/
-
-int ec_sdo_init(ec_sdo_t *, uint16_t, ec_slave_t *);
-void ec_sdo_destroy(ec_sdo_t *);
-ec_sdo_entry_t *ec_sdo_get_entry(ec_sdo_t *, uint8_t);
-
-int ec_sdo_entry_init(ec_sdo_entry_t *, uint8_t, ec_sdo_t *);
-void ec_sdo_entry_destroy(ec_sdo_entry_t *);
-
-void ec_sdo_request_init_read(ec_sdo_request_t *, ec_slave_t *, uint16_t,
-        uint8_t);
-void ec_sdo_request_clear(ec_sdo_request_t *);
-
-/*****************************************************************************/
-
-#endif
--- a/master/fsm_coe.h	Fri Feb 29 08:27:17 2008 +0000
+++ b/master/fsm_coe.h	Fri Feb 29 12:19:48 2008 +0000
@@ -45,7 +45,8 @@
 #include "../include/ecrt.h"
 #include "datagram.h"
 #include "slave.h"
-#include "canopen.h"
+#include "sdo.h"
+#include "sdo_request.h"
 
 /*****************************************************************************/
 
--- a/master/fsm_coe_map.c	Fri Feb 29 08:27:17 2008 +0000
+++ b/master/fsm_coe_map.c	Fri Feb 29 12:19:48 2008 +0000
@@ -41,7 +41,7 @@
 #include "globals.h"
 #include "master.h"
 #include "mailbox.h"
-#include "canopen.h"
+#include "sdo_request.h"
 #include "fsm_coe_map.h"
 
 /*****************************************************************************/
@@ -179,7 +179,7 @@
 
         ec_pdo_mapping_clear_pdos(&fsm->mapping);
 
-        ec_sdo_request_init_read(&fsm->request, slave, fsm->sync_sdo_index, 0);
+        ec_sdo_request_init(&fsm->request, slave, fsm->sync_sdo_index, 0);
         fsm->state = ec_fsm_coe_map_state_pdo_count;
         ec_fsm_coe_upload(fsm->fsm_coe, fsm->slave, &fsm->request);
         ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
@@ -233,7 +233,7 @@
         )
 {
     if (fsm->sync_subindex <= fsm->sync_subindices) {
-        ec_sdo_request_init_read(&fsm->request, fsm->slave,
+        ec_sdo_request_init(&fsm->request, fsm->slave,
                 fsm->sync_sdo_index, fsm->sync_subindex);
         fsm->state = ec_fsm_coe_map_state_pdo;
         ec_fsm_coe_upload(fsm->fsm_coe, fsm->slave, &fsm->request);
@@ -290,7 +290,7 @@
 
     list_add_tail(&fsm->pdo->list, &fsm->mapping.pdos);
 
-    ec_sdo_request_init_read(&fsm->request, fsm->slave, fsm->pdo->index, 0);
+    ec_sdo_request_init(&fsm->request, fsm->slave, fsm->pdo->index, 0);
     fsm->state = ec_fsm_coe_map_state_pdo_entry_count;
     ec_fsm_coe_upload(fsm->fsm_coe, fsm->slave, &fsm->request);
     ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
@@ -336,7 +336,7 @@
         )
 {
     if (fsm->pdo_subindex <= fsm->pdo_subindices) {
-        ec_sdo_request_init_read(&fsm->request, fsm->slave,
+        ec_sdo_request_init(&fsm->request, fsm->slave,
                 fsm->pdo->index, fsm->pdo_subindex);
         fsm->state = ec_fsm_coe_map_state_pdo_entry;
         ec_fsm_coe_upload(fsm->fsm_coe, fsm->slave, &fsm->request);
--- a/master/fsm_master.h	Fri Feb 29 08:27:17 2008 +0000
+++ b/master/fsm_master.h	Fri Feb 29 12:19:48 2008 +0000
@@ -45,7 +45,7 @@
 
 #include "globals.h"
 #include "datagram.h"
-#include "canopen.h"
+#include "sdo_request.h"
 #include "fsm_slave_config.h"
 #include "fsm_slave_scan.h"
 #include "fsm_coe_map.h"
--- a/master/globals.h	Fri Feb 29 08:27:17 2008 +0000
+++ b/master/globals.h	Fri Feb 29 12:19:48 2008 +0000
@@ -198,8 +198,7 @@
     EC_REQUEST_IN_PROGRESS,
     EC_REQUEST_COMPLETE,
     EC_REQUEST_FAILURE
-}
-ec_request_state_t;
+} ec_request_state_t;
 
 /*****************************************************************************/
 
@@ -213,7 +212,6 @@
 /*****************************************************************************/
 
 typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */
-typedef struct ec_sdo ec_sdo_t; /**< \see ec_sdo */
 
 /*****************************************************************************/
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/sdo.c	Fri Feb 29 12:19:48 2008 +0000
@@ -0,0 +1,218 @@
+/******************************************************************************
+ *
+ *  $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
+   CANopen Sdo functions.
+*/
+
+/*****************************************************************************/
+
+#include <linux/module.h>
+
+#include "master.h"
+
+#include "sdo.h"
+
+/*****************************************************************************/
+
+ssize_t ec_show_sdo_attribute(struct kobject *, struct attribute *, char *);
+void ec_sdo_clear(struct kobject *);
+
+/*****************************************************************************/
+
+/** \cond */
+
+EC_SYSFS_READ_ATTR(info);
+
+static struct attribute *sdo_def_attrs[] = {
+    &attr_info,
+    NULL,
+};
+
+static struct sysfs_ops sdo_sysfs_ops = {
+    .show = &ec_show_sdo_attribute,
+    .store = NULL
+};
+
+static struct kobj_type ktype_ec_sdo = {
+    .release = ec_sdo_clear,
+    .sysfs_ops = &sdo_sysfs_ops,
+    .default_attrs = sdo_def_attrs
+};
+
+/** \endcond */
+
+/*****************************************************************************/
+
+/** Sdo constructor.
+ *
+ * \todo Turn parameters.
+ */
+int ec_sdo_init(
+        ec_sdo_t *sdo, /**< Sdo. */
+        uint16_t index, /**< Sdo index. */
+        ec_slave_t *slave /**< Parent slave. */
+        )
+{
+    sdo->slave = slave;
+    sdo->index = index;
+    sdo->object_code = 0x00;
+    sdo->name = NULL;
+    sdo->subindices = 0;
+    INIT_LIST_HEAD(&sdo->entries);
+
+    // Init kobject and add it to the hierarchy
+    memset(&sdo->kobj, 0x00, sizeof(struct kobject));
+    kobject_init(&sdo->kobj);
+    sdo->kobj.ktype = &ktype_ec_sdo;
+    sdo->kobj.parent = &slave->sdo_kobj;
+    if (kobject_set_name(&sdo->kobj, "%4X", sdo->index)) {
+        EC_ERR("Failed to set kobj name.\n");
+        kobject_put(&sdo->kobj);
+        return -1;
+    }
+    if (kobject_add(&sdo->kobj)) {
+        EC_ERR("Failed to add Sdo kobject.\n");
+        kobject_put(&sdo->kobj);
+        return -1;
+    }
+
+    return 0;
+}
+
+/*****************************************************************************/
+
+/** Sdo destructor.
+ *
+ * Clears and frees an Sdo object.
+ */
+void ec_sdo_destroy(
+        ec_sdo_t *sdo /**< Sdo. */
+        )
+{
+    ec_sdo_entry_t *entry, *next;
+
+    // free all entries
+    list_for_each_entry_safe(entry, next, &sdo->entries, list) {
+        list_del(&entry->list);
+        ec_sdo_entry_destroy(entry);
+    }
+
+    // destroy self
+    kobject_del(&sdo->kobj);
+    kobject_put(&sdo->kobj);
+}
+
+/*****************************************************************************/
+
+/** Clear and free Sdo.
+ *
+ * This method is called by the kobject,
+ * once there are no more references to it.
+ */
+void ec_sdo_clear(
+        struct kobject *kobj /**< Sdo's kobject. */
+        )
+{
+    ec_sdo_t *sdo = container_of(kobj, ec_sdo_t, kobj);
+
+    if (sdo->name) kfree(sdo->name);
+
+    kfree(sdo);
+}
+
+/*****************************************************************************/
+
+/** Get and Sdo entry from an Sdo via its subindex.
+ * 
+ * \retval >0 Pointer to the requested Sdo entry.
+ * \retval NULL Sdo entry not found.
+ */
+ec_sdo_entry_t *ec_sdo_get_entry(
+        ec_sdo_t *sdo, /**< Sdo. */
+        uint8_t subindex /**< Entry subindex. */
+        )
+{
+    ec_sdo_entry_t *entry;
+
+    list_for_each_entry(entry, &sdo->entries, list) {
+        if (entry->subindex != subindex) continue;
+        return entry;
+    }
+
+    return NULL;
+}
+
+/*****************************************************************************/
+
+/** Print Sdo information to a buffer.
+ * 
+ * /return size of bytes written to buffer.
+ */ 
+ssize_t ec_sdo_info(
+        ec_sdo_t *sdo, /**< Sdo. */
+        char *buffer /**< Target buffer. */
+        )
+{
+    off_t off = 0;
+
+    off += sprintf(buffer + off, "Index: 0x%04X\n", sdo->index);
+    off += sprintf(buffer + off, "Name: %s\n", sdo->name ? sdo->name : "");
+    off += sprintf(buffer + off, "Subindices: %i\n", sdo->subindices);
+
+    return off;
+}
+
+/*****************************************************************************/
+
+/** Show a Sysfs attribute of an Sdo.
+ * 
+ * /return Number of bytes written to buffer.
+ */ 
+ssize_t ec_show_sdo_attribute(
+        struct kobject *kobj, /**< kobject */
+        struct attribute *attr, /**< Requested attribute. */
+        char *buffer /**< Buffer to write the data in. */
+        )
+{
+    ec_sdo_t *sdo = container_of(kobj, ec_sdo_t, kobj);
+
+    if (attr == &attr_info) {
+        return ec_sdo_info(sdo, buffer);
+    }
+
+    return 0;
+}
+
+/*****************************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/sdo.h	Fri Feb 29 12:19:48 2008 +0000
@@ -0,0 +1,88 @@
+/******************************************************************************
+ *
+ *  $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 CANopen Sdo structure.
+*/
+
+/*****************************************************************************/
+
+#ifndef __EC_SDO_H__
+#define __EC_SDO_H__
+
+#include <linux/list.h>
+#include <linux/kobject.h>
+
+#include "globals.h"
+#include "sdo_entry.h"
+
+/*****************************************************************************/
+
+/** CANopen Sdo.
+ */
+struct ec_sdo {
+    struct kobject kobj; /**< kobject */
+    struct list_head list; /**< list item */
+    ec_slave_t *slave; /**< parent slave */
+    uint16_t index; /**< Sdo index */
+    uint8_t object_code; /**< object code */
+    char *name; /**< Sdo name */
+    uint8_t subindices; /**< subindices */
+    struct list_head entries; /**< entry list */
+};
+
+/*****************************************************************************/
+
+/** CANopen Sdo configuration data.
+ * \todo remove
+ */
+typedef struct {
+    struct list_head list; /**< list item */
+    uint16_t index; /**< Sdo index */
+    uint8_t subindex; /**< Sdo subindex */
+    uint8_t *data; /**< pointer to Sdo data */
+    size_t size; /**< size of Sdo data */
+}
+ec_sdo_data_t;
+
+/*****************************************************************************/
+
+int ec_sdo_init(ec_sdo_t *, uint16_t, ec_slave_t *);
+void ec_sdo_destroy(ec_sdo_t *);
+
+ec_sdo_entry_t *ec_sdo_get_entry(ec_sdo_t *, uint8_t);
+
+/*****************************************************************************/
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/sdo_entry.c	Fri Feb 29 12:19:48 2008 +0000
@@ -0,0 +1,327 @@
+/******************************************************************************
+ *
+ *  $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
+   CANopen-over-EtherCAT Sdo entry functions.
+*/
+
+/*****************************************************************************/
+
+#include <linux/module.h>
+
+#include "sdo.h"
+#include "sdo_request.h"
+#include "master.h"
+
+#include "sdo_entry.h"
+
+/*****************************************************************************/
+
+ssize_t ec_show_sdo_entry_attribute(struct kobject *, struct attribute *,
+                                    char *);
+void ec_sdo_entry_clear(struct kobject *);
+
+/*****************************************************************************/
+
+/** \cond */
+
+EC_SYSFS_READ_ATTR(info);
+EC_SYSFS_READ_ATTR(value);
+
+static struct attribute *sdo_entry_def_attrs[] = {
+    &attr_info,
+    &attr_value,
+    NULL,
+};
+
+static struct sysfs_ops sdo_entry_sysfs_ops = {
+    .show = &ec_show_sdo_entry_attribute,
+    .store = NULL
+};
+
+static struct kobj_type ktype_ec_sdo_entry = {
+    .release = ec_sdo_entry_clear,
+    .sysfs_ops = &sdo_entry_sysfs_ops,
+    .default_attrs = sdo_entry_def_attrs
+};
+
+/** \endcond */
+
+/*****************************************************************************/
+
+/** Sdo entry constructor.
+ *
+ * \todo Turn parameters.
+ */
+int ec_sdo_entry_init(
+        ec_sdo_entry_t *entry, /**< Sdo entry. */
+        uint8_t subindex, /**< Subindex. */
+        ec_sdo_t *sdo /**< Parent Sdo. */
+        )
+{
+    entry->sdo = sdo;
+    entry->subindex = subindex;
+    entry->data_type = 0x0000;
+    entry->bit_length = 0;
+    entry->description = NULL;
+
+    // Init kobject and add it to the hierarchy
+    memset(&entry->kobj, 0x00, sizeof(struct kobject));
+    kobject_init(&entry->kobj);
+    entry->kobj.ktype = &ktype_ec_sdo_entry;
+    entry->kobj.parent = &sdo->kobj;
+    if (kobject_set_name(&entry->kobj, "%i", entry->subindex)) {
+        EC_ERR("Failed to set kobj name.\n");
+        kobject_put(&entry->kobj);
+        return -1;
+    }
+    if (kobject_add(&entry->kobj)) {
+        EC_ERR("Failed to add entry kobject.\n");
+        kobject_put(&entry->kobj);
+        return -1;
+    }
+
+    return 0;
+}
+
+/*****************************************************************************/
+
+/** Sdo entry destructor.
+ *
+ * Clears and frees an Sdo entry object.
+ */
+void ec_sdo_entry_destroy(
+        ec_sdo_entry_t *entry /**< Sdo entry. */
+        )
+{
+    // destroy self
+    kobject_del(&entry->kobj);
+    kobject_put(&entry->kobj);
+}
+
+/*****************************************************************************/
+
+/** Clear and free the Sdo entry.
+ *
+ * This method is called by the kobject,
+ * once there are no more references to it.
+ */
+void ec_sdo_entry_clear(
+        struct kobject *kobj /**< Sdo entry's kobject. */
+        )
+{
+    ec_sdo_entry_t *entry = container_of(kobj, ec_sdo_entry_t, kobj);
+
+    if (entry->description) kfree(entry->description);
+
+    kfree(entry);
+}
+
+/*****************************************************************************/
+ 
+/** Print Sdo entry information to a buffer.
+ * 
+ * \return Number of bytes written.
+ */
+ssize_t ec_sdo_entry_info(
+        ec_sdo_entry_t *entry, /**< Sdo entry. */
+        char *buffer /**< Target buffer. */
+        )
+{
+    off_t off = 0;
+
+    off += sprintf(buffer + off, "Subindex: 0x%02X\n", entry->subindex);
+    off += sprintf(buffer + off, "Description: %s\n",
+                   entry->description ? entry->description : "");
+    off += sprintf(buffer + off, "Data type: 0x%04X\n", entry->data_type);
+    off += sprintf(buffer + off, "Bit length: %i\n", entry->bit_length);
+
+    return off;
+}
+
+/*****************************************************************************/
+
+/** Format entry data based on the CANopen data type and print it to a buffer.
+ *
+ * \return number of bytes written.
+ */
+ssize_t ec_sdo_entry_format_data(
+        ec_sdo_entry_t *entry, /**< Sdo entry. */
+        ec_sdo_request_t *request, /**< Sdo request. */
+        char *buffer /**< Target buffer. */
+        )
+{
+    off_t off = 0;
+    unsigned int i;
+
+    if (entry->data_type == 0x0002) { // int8
+        int8_t value;
+        if (entry->bit_length != 8)
+            goto not_fit;
+        value = EC_READ_S8(request->data);
+        off += sprintf(buffer + off, "%i (0x%02X)\n", value, value);
+    }
+    else if (entry->data_type == 0x0003) { // int16
+        int16_t value;
+        if (entry->bit_length != 16)
+            goto not_fit;
+        value = EC_READ_S16(request->data);
+        off += sprintf(buffer + off, "%i (0x%04X)\n", value, value);
+    }
+    else if (entry->data_type == 0x0004) { // int32
+        int32_t value;
+        if (entry->bit_length != 32)
+            goto not_fit;
+        value = EC_READ_S16(request->data);
+        off += sprintf(buffer + off, "%i (0x%08X)\n", value, value);
+    }
+    else if (entry->data_type == 0x0005) { // uint8
+        uint8_t value;
+        if (entry->bit_length != 8)
+            goto not_fit;
+        value = EC_READ_U8(request->data);
+        off += sprintf(buffer + off, "%u (0x%02X)\n", value, value);
+    }
+    else if (entry->data_type == 0x0006) { // uint16
+        uint16_t value;
+        if (entry->bit_length != 16)
+            goto not_fit;
+        value = EC_READ_U16(request->data); 
+        off += sprintf(buffer + off, "%u (0x%04X)\n", value, value);
+    }
+    else if (entry->data_type == 0x0007) { // uint32
+        uint32_t value;
+        if (entry->bit_length != 32)
+            goto not_fit;
+        value = EC_READ_U32(request->data);
+        off += sprintf(buffer + off, "%i (0x%08X)\n", value, value);
+    }
+    else if (entry->data_type == 0x0009) { // string
+        off += sprintf(buffer + off, "%s\n", request->data);
+    }
+    else {
+        off += sprintf(buffer + off, "Unknown data type %04X. Data:\n",
+                entry->data_type);
+        goto raw_data;
+    }
+    return off;
+
+not_fit:
+    off += sprintf(buffer + off,
+            "Invalid bit length %u for data type 0x%04X. Data:\n",
+            entry->bit_length, entry->data_type);
+raw_data:
+    for (i = 0; i < request->size; i++)
+        off += sprintf(buffer + off, "%02X (%c)\n",
+                request->data[i], request->data[i]);
+    return off;
+}
+
+/*****************************************************************************/
+
+/** Start blocking Sdo entry reading.
+ *
+ * This function blocks, until reading is finished, and is interruptible as
+ * long as the master state machine has not begun with reading.
+ *
+ * \return number of bytes written to buffer, or error code.
+ */
+ssize_t ec_sdo_entry_read_value(
+        ec_sdo_entry_t *entry, /**< Sdo entry. */
+        char *buffer /**< Target buffer. */
+        )
+{
+    ec_master_t *master = entry->sdo->slave->master;
+    off_t off = 0;
+    ec_sdo_request_t request;
+
+    ec_sdo_request_init(&request, entry->sdo->slave,
+            entry->sdo->index, entry->subindex);
+
+    // schedule request.
+    down(&master->sdo_sem);
+    list_add_tail(&request.list, &master->sdo_requests);
+    up(&master->sdo_sem);
+
+    // wait for processing through FSM
+    if (wait_event_interruptible(master->sdo_queue,
+                request.state != EC_REQUEST_QUEUED)) {
+        // interrupted by signal
+        down(&master->sdo_sem);
+        if (request.state == EC_REQUEST_QUEUED) {
+            list_del(&request.list);
+            up(&master->sdo_sem);
+            return -EINTR;
+        }
+        // request already processing: interrupt not possible.
+        up(&master->sdo_sem);
+    }
+
+    // wait until master FSM has finished processing
+    wait_event(master->sdo_queue, request.state != EC_REQUEST_IN_PROGRESS);
+
+    if (request.state != EC_REQUEST_COMPLETE)
+        return -EIO;
+
+    off += ec_sdo_entry_format_data(entry, &request, buffer);
+
+    ec_sdo_request_clear(&request);
+    return off;
+}
+
+/*****************************************************************************/
+
+/** Show the Sysfs attribute of an Sdo entry.
+ *
+ * /return Number of bytes written to buffer.
+ */ 
+ssize_t ec_show_sdo_entry_attribute(
+        struct kobject *kobj, /**< kobject. */
+        struct attribute *attr, /**< Sysfs attribute. */
+        char *buffer /**< Target buffer. */
+        )
+{
+    ec_sdo_entry_t *entry = container_of(kobj, ec_sdo_entry_t, kobj);
+
+    if (attr == &attr_info) {
+        return ec_sdo_entry_info(entry, buffer);
+    }
+    else if (attr == &attr_value) {
+        return ec_sdo_entry_read_value(entry, buffer);
+    }
+
+    return 0;
+}
+
+/*****************************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/sdo_entry.h	Fri Feb 29 12:19:48 2008 +0000
@@ -0,0 +1,75 @@
+/******************************************************************************
+ *
+ *  $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 CANopen Sdo entry structure.
+*/
+
+/*****************************************************************************/
+
+#ifndef __EC_SDO_ENTRY_H__
+#define __EC_SDO_ENTRY_H__
+
+#include <linux/list.h>
+#include <linux/kobject.h>
+
+#include "globals.h"
+
+/*****************************************************************************/
+
+struct ec_sdo;
+typedef struct ec_sdo ec_sdo_t;
+
+/*****************************************************************************/
+
+/** CANopen Sdo entry.
+ */
+typedef struct {
+    struct kobject kobj; /**< kobject */
+    struct list_head list; /**< List item. */
+    ec_sdo_t *sdo; /**< Parent Sdo. */
+    uint8_t subindex; /**< Subindex. */
+    uint16_t data_type; /**< Data type. */
+    uint16_t bit_length; /**< Data size in bit. */
+    char *description; /**< Description. */
+} ec_sdo_entry_t;
+
+/*****************************************************************************/
+
+int ec_sdo_entry_init(ec_sdo_entry_t *, uint8_t, ec_sdo_t *);
+void ec_sdo_entry_destroy(ec_sdo_entry_t *);
+
+/*****************************************************************************/
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/sdo_request.c	Fri Feb 29 12:19:48 2008 +0000
@@ -0,0 +1,76 @@
+/******************************************************************************
+ *
+ *  $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
+   Canopen-over-EtherCAT Sdo request functions.
+*/
+
+/*****************************************************************************/
+
+#include <linux/module.h>
+
+#include "sdo_request.h"
+
+/*****************************************************************************/
+
+/** Sdo request constructor.
+ */
+void ec_sdo_request_init(
+        ec_sdo_request_t *req, /**< Sdo request. */
+        ec_slave_t *slave, /**< Slave owning the Sdo. */
+        uint16_t index, /**< Sdo index. */
+        uint8_t subindex /**< Sdo subindex. */
+        )
+{
+    req->slave = slave;
+    req->index = index;
+    req->subindex = subindex;
+    req->data = NULL;
+    req->size = 0;
+    req->state = EC_REQUEST_QUEUED;
+}
+
+/*****************************************************************************/
+
+/** Sdo request destructor.
+ */
+void ec_sdo_request_clear(
+        ec_sdo_request_t *req /**< Sdo request. */
+        )
+{
+    if (req->data)
+        kfree(req->data);
+}
+
+/*****************************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/master/sdo_request.h	Fri Feb 29 12:19:48 2008 +0000
@@ -0,0 +1,69 @@
+/******************************************************************************
+ *
+ *  $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 CANopen Sdo request structure.
+*/
+
+/*****************************************************************************/
+
+#ifndef __EC_SDO_REQUEST_H__
+#define __EC_SDO_REQUEST_H__
+
+#include <linux/list.h>
+
+#include "globals.h"
+
+/*****************************************************************************/
+
+/** CANopen Sdo request.
+ */
+typedef struct {
+    struct list_head list; /**< List item. */
+    ec_slave_t *slave; /**< Slave. */
+    uint16_t index; /**< Sdo index. */
+    uint8_t subindex; /**< Sdo subindex. */
+    uint8_t *data; /**< Pointer to Sdo data. */
+    size_t size; /**< Size of Sdo data. */
+    ec_request_state_t state; /**< Sdo request state. */
+} ec_sdo_request_t;
+
+/*****************************************************************************/
+
+void ec_sdo_request_init(ec_sdo_request_t *, ec_slave_t *, uint16_t, uint8_t);
+void ec_sdo_request_clear(ec_sdo_request_t *);
+
+/*****************************************************************************/
+
+#endif
--- a/master/slave.h	Fri Feb 29 08:27:17 2008 +0000
+++ b/master/slave.h	Fri Feb 29 12:19:48 2008 +0000
@@ -50,6 +50,7 @@
 #include "datagram.h"
 #include "pdo.h"
 #include "sync.h"
+#include "sdo.h"
 
 /*****************************************************************************/