Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
This commit is contained in:
parent
88017c1555
commit
f621cf2619
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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_pdo_mapping.c fsm_pdo_mapping.h \
|
||||
fsm_pdo_config.c fsm_pdo_config.h \
|
||||
fsm_slave_scan.c fsm_slave_scan.h \
|
||||
fsm_slave_config.c fsm_slave_config.h \
|
||||
fsm_master.c fsm_master.h \
|
||||
fsm_pdo_config.c fsm_pdo_config.h \
|
||||
fsm_pdo_mapping.c fsm_pdo_mapping.h \
|
||||
fsm_sii.c fsm_sii.h \
|
||||
fsm_slave_config.c fsm_slave_config.h \
|
||||
fsm_slave_scan.c fsm_slave_scan.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:
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@
|
|||
#include "../include/ecrt.h"
|
||||
#include "datagram.h"
|
||||
#include "slave.h"
|
||||
#include "canopen.h"
|
||||
#include "sdo.h"
|
||||
#include "sdo_request.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@ void ec_fsm_coe_map_action_next_dir(
|
|||
|
||||
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 @@ void ec_fsm_coe_map_action_next_pdo(
|
|||
)
|
||||
{
|
||||
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 @@ void ec_fsm_coe_map_state_pdo(
|
|||
|
||||
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 @@ void ec_fsm_coe_map_action_next_pdo_entry(
|
|||
)
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -198,8 +198,7 @@ typedef enum {
|
|||
EC_REQUEST_IN_PROGRESS,
|
||||
EC_REQUEST_COMPLETE,
|
||||
EC_REQUEST_FAILURE
|
||||
}
|
||||
ec_request_state_t;
|
||||
} ec_request_state_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -213,7 +212,6 @@ typedef enum {
|
|||
/*****************************************************************************/
|
||||
|
||||
typedef struct ec_slave ec_slave_t; /**< \see ec_slave. */
|
||||
typedef struct ec_sdo ec_sdo_t; /**< \see ec_sdo */
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -33,19 +33,19 @@
|
|||
|
||||
/**
|
||||
\file
|
||||
EtherCAT CANopen structures.
|
||||
EtherCAT CANopen Sdo structure.
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef _EC_CANOPEN_H_
|
||||
#define _EC_CANOPEN_H_
|
||||
#ifndef __EC_SDO_H__
|
||||
#define __EC_SDO_H__
|
||||
|
||||
#include <linux/list.h>
|
||||
#include <linux/kobject.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "slave.h"
|
||||
#include "sdo_entry.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -64,21 +64,8 @@ struct ec_sdo {
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** 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.
|
||||
* \todo remove
|
||||
*/
|
||||
typedef struct {
|
||||
struct list_head list; /**< list item */
|
||||
|
|
@ -91,33 +78,11 @@ 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
|
||||
|
|
@ -33,22 +33,23 @@
|
|||
|
||||
/**
|
||||
\file
|
||||
Canopen-over-EtherCAT functions.
|
||||
CANopen-over-EtherCAT Sdo entry functions.
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <linux/module.h>
|
||||
|
||||
#include "canopen.h"
|
||||
#include "sdo.h"
|
||||
#include "sdo_request.h"
|
||||
#include "master.h"
|
||||
|
||||
#include "sdo_entry.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 *);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -58,22 +59,6 @@ void ec_sdo_entry_clear(struct kobject *);
|
|||
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,
|
||||
|
|
@ -95,153 +80,15 @@ static struct kobj_type ktype_ec_sdo_entry = {
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
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.
|
||||
/** Sdo entry constructor.
|
||||
*
|
||||
* \todo Turn parameters.
|
||||
*/
|
||||
|
||||
ec_sdo_entry_t *ec_sdo_get_entry(
|
||||
ec_sdo_t *sdo, /**< Sdo */
|
||||
uint8_t subindex /**< entry subindex */
|
||||
int ec_sdo_entry_init(
|
||||
ec_sdo_entry_t *entry, /**< Sdo entry. */
|
||||
uint8_t subindex, /**< Subindex. */
|
||||
ec_sdo_t *sdo /**< Parent Sdo. */
|
||||
)
|
||||
{
|
||||
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;
|
||||
|
|
@ -249,7 +96,7 @@ int ec_sdo_entry_init(ec_sdo_entry_t *entry, /**< Sdo entry */
|
|||
entry->bit_length = 0;
|
||||
entry->description = NULL;
|
||||
|
||||
// init kobject and add it to the hierarchy
|
||||
// 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;
|
||||
|
|
@ -270,12 +117,13 @@ int ec_sdo_entry_init(ec_sdo_entry_t *entry, /**< Sdo entry */
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
Sdo entry destructor.
|
||||
Clears and frees an Sdo entry object.
|
||||
*/
|
||||
|
||||
void ec_sdo_entry_destroy(ec_sdo_entry_t *entry /**< Sdo entry */)
|
||||
/** 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);
|
||||
|
|
@ -284,13 +132,14 @@ void ec_sdo_entry_destroy(ec_sdo_entry_t *entry /**< Sdo entry */)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
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 */)
|
||||
/** 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);
|
||||
|
||||
|
|
@ -301,14 +150,14 @@ void ec_sdo_entry_clear(struct kobject *kobj /**< Sdo entry's kobject */)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Print Sdo entry information to a buffer.
|
||||
* \return number of bytes written.
|
||||
/** 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 */
|
||||
)
|
||||
ssize_t ec_sdo_entry_info(
|
||||
ec_sdo_entry_t *entry, /**< Sdo entry. */
|
||||
char *buffer /**< Target buffer. */
|
||||
)
|
||||
{
|
||||
off_t off = 0;
|
||||
|
||||
|
|
@ -323,15 +172,15 @@ ssize_t ec_sdo_entry_info(ec_sdo_entry_t *entry, /**< Sdo entry */
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Format entry data based on the CANopen data type and print it to a buffer.
|
||||
/** 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 */
|
||||
)
|
||||
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;
|
||||
|
|
@ -401,22 +250,23 @@ raw_data:
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Start Sdo entry reading.
|
||||
/** 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 */
|
||||
)
|
||||
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,
|
||||
ec_sdo_request_init(&request, entry->sdo->slave,
|
||||
entry->sdo->index, entry->subindex);
|
||||
|
||||
// schedule request.
|
||||
|
|
@ -452,15 +302,15 @@ ssize_t ec_sdo_entry_read_value(ec_sdo_entry_t *entry, /**< Sdo entry */
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Show an Sdo entry as Sysfs attribute.
|
||||
* /return size of bytes written to buffer.
|
||||
/** 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,
|
||||
char *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);
|
||||
|
||||
|
|
@ -475,35 +325,3 @@ ssize_t ec_show_sdo_entry_attribute(struct kobject *kobj, /**< kobject */
|
|||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -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
|
||||
|
|
@ -50,6 +50,7 @@
|
|||
#include "datagram.h"
|
||||
#include "pdo.h"
|
||||
#include "sync.h"
|
||||
#include "sdo.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue