--- a/master/sdo.c Wed Jun 11 15:37:38 2008 +0000
+++ b/master/sdo.c Thu Jun 12 07:15:54 2008 +0000
@@ -38,7 +38,7 @@
/*****************************************************************************/
-#include <linux/module.h>
+#include <linux/slab.h>
#include "master.h"
@@ -46,43 +46,12 @@
/*****************************************************************************/
-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.
+/** Constructor.
*/
-int ec_sdo_init(
+void ec_sdo_init(
ec_sdo_t *sdo, /**< Sdo. */
- uint16_t index, /**< Sdo index. */
- ec_slave_t *slave /**< Parent slave. */
+ ec_slave_t *slave, /**< Parent slave. */
+ uint16_t index /**< Sdo index. */
)
{
sdo->slave = slave;
@@ -91,24 +60,6 @@
sdo->name = NULL;
sdo->max_subindex = 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;
}
/*****************************************************************************/
@@ -117,7 +68,7 @@
*
* Clears and frees an Sdo object.
*/
-void ec_sdo_destroy(
+void ec_sdo_clear(
ec_sdo_t *sdo /**< Sdo. */
)
{
@@ -130,27 +81,8 @@
kfree(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);
+ if (sdo->name)
+ kfree(sdo->name);
}
/*****************************************************************************/
@@ -202,44 +134,3 @@
}
/*****************************************************************************/
-
-/** 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, "Max subindex: %u\n", sdo->max_subindex);
-
- 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;
-}
-
-/*****************************************************************************/
--- a/master/slave.c Wed Jun 11 15:37:38 2008 +0000
+++ b/master/slave.c Thu Jun 12 07:15:54 2008 +0000
@@ -54,50 +54,21 @@
/*****************************************************************************/
-void ec_slave_clear(struct kobject *);
-void ec_slave_sdos_clear(struct kobject *);
-ssize_t ec_show_slave_attribute(struct kobject *, struct attribute *, char *);
char *ec_slave_sii_string(ec_slave_t *, unsigned int);
/*****************************************************************************/
-/** \cond */
-
-EC_SYSFS_READ_ATTR(info);
-
-static struct attribute *def_attrs[] = {
- &attr_info,
- NULL,
-};
-
-static struct sysfs_ops sysfs_ops = {
- .show = ec_show_slave_attribute,
-};
-
-static struct kobj_type ktype_ec_slave = {
- .release = ec_slave_clear,
- .sysfs_ops = &sysfs_ops,
- .default_attrs = def_attrs
-};
-
-static struct kobj_type ktype_ec_slave_sdos = {
- .release = ec_slave_sdos_clear
-};
-
-/** \endcond */
-
-/*****************************************************************************/
-
/**
Slave constructor.
\return 0 in case of success, else < 0
*/
-int ec_slave_init(ec_slave_t *slave, /**< EtherCAT slave */
- ec_master_t *master, /**< EtherCAT master */
- uint16_t ring_position, /**< ring position */
- uint16_t station_address /**< station address to configure */
- )
+void ec_slave_init(
+ ec_slave_t *slave, /**< EtherCAT slave */
+ ec_master_t *master, /**< EtherCAT master */
+ uint16_t ring_position, /**< ring position */
+ uint16_t station_address /**< station address to configure */
+ )
{
unsigned int i;
@@ -159,43 +130,6 @@
slave->dl_signal[i] = 0;
slave->sii.physical_layer[i] = 0xFF;
}
-
- // init kobject and add it to the hierarchy
- memset(&slave->kobj, 0x00, sizeof(struct kobject));
- kobject_init(&slave->kobj);
- slave->kobj.ktype = &ktype_ec_slave;
- slave->kobj.parent = &master->kobj;
- if (kobject_set_name(&slave->kobj, "slave%03i", slave->ring_position)) {
- EC_ERR("Failed to set kobject name.\n");
- goto out_slave_put;
- }
- if (kobject_add(&slave->kobj)) {
- EC_ERR("Failed to add slave's kobject.\n");
- goto out_slave_put;
- }
-
- // init Sdo kobject and add it to the hierarchy
- memset(&slave->sdo_kobj, 0x00, sizeof(struct kobject));
- kobject_init(&slave->sdo_kobj);
- slave->sdo_kobj.ktype = &ktype_ec_slave_sdos;
- slave->sdo_kobj.parent = &slave->kobj;
- if (kobject_set_name(&slave->sdo_kobj, "sdos")) {
- EC_ERR("Failed to set kobject name.\n");
- goto out_sdo_put;
- }
- if (kobject_add(&slave->sdo_kobj)) {
- EC_ERR("Failed to add Sdos kobject.\n");
- goto out_sdo_put;
- }
-
- return 0;
-
- out_sdo_put:
- kobject_put(&slave->sdo_kobj);
- kobject_del(&slave->kobj);
- out_slave_put:
- kobject_put(&slave->kobj);
- return -1;
}
/*****************************************************************************/
@@ -205,9 +139,11 @@
Clears and frees a slave object.
*/
-void ec_slave_destroy(ec_slave_t *slave /**< EtherCAT slave */)
+void ec_slave_clear(ec_slave_t *slave /**< EtherCAT slave */)
{
ec_sdo_t *sdo, *next_sdo;
+ unsigned int i;
+ ec_pdo_t *pdo, *next_pdo;
if (slave->config)
ec_slave_config_detach(slave->config);
@@ -215,33 +151,9 @@
// free all Sdos
list_for_each_entry_safe(sdo, next_sdo, &slave->sdo_dictionary, list) {
list_del(&sdo->list);
- ec_sdo_destroy(sdo);
- }
-
- // free Sdo kobject
- kobject_del(&slave->sdo_kobj);
- kobject_put(&slave->sdo_kobj);
-
- // destroy self
- kobject_del(&slave->kobj);
- kobject_put(&slave->kobj);
-}
-
-/*****************************************************************************/
-
-/**
- Clear and free slave.
- This method is called by the kobject,
- once there are no more references to it.
-*/
-
-void ec_slave_clear(struct kobject *kobj /**< kobject of the slave */)
-{
- ec_slave_t *slave;
- ec_pdo_t *pdo, *next_pdo;
- unsigned int i;
-
- slave = container_of(kobj, ec_slave_t, kobj);
+ ec_sdo_clear(sdo);
+ kfree(sdo);
+ }
// free all strings
if (slave->sii.strings) {
@@ -262,18 +174,6 @@
if (slave->sii_words)
kfree(slave->sii_words);
-
- kfree(slave);
-}
-
-/*****************************************************************************/
-
-/**
- * Sdo kobject clear method.
- */
-
-void ec_slave_sdos_clear(struct kobject *kobj /**< kobject for Sdos */)
-{
}
/*****************************************************************************/
@@ -607,239 +507,6 @@
/*****************************************************************************/
-/** Outputs all information about a certain slave.
- */
-ssize_t ec_slave_info(const ec_slave_t *slave, /**< EtherCAT slave */
- char *buffer /**< Output buffer */
- )
-{
- const ec_sync_t *sync;
- const ec_pdo_t *pdo;
- const ec_pdo_entry_t *pdo_entry;
- int first, i;
- char *large_buffer, *buf;
- unsigned int size;
-
- if (!(large_buffer = (char *) kmalloc(PAGE_SIZE * 2, GFP_KERNEL))) {
- return -ENOMEM;
- }
-
- buf = large_buffer;
-
- buf += sprintf(buf, "Ring position: %u\n",
- slave->ring_position);
- buf += sprintf(buf, "State: ");
- buf += ec_state_string(slave->current_state, buf);
- buf += sprintf(buf, " (");
- buf += ec_state_string(slave->requested_state, buf);
- buf += sprintf(buf, ")\n");
- buf += sprintf(buf, "Flags: %s\n\n", slave->error_flag ? "ERROR" : "ok");
-
- buf += sprintf(buf, "Data link status:\n");
- for (i = 0; i < 4; i++) {
- buf += sprintf(buf, " Port %u: Phy %u (",
- i, slave->sii.physical_layer[i]);
- switch (slave->sii.physical_layer[i]) {
- case 0x00:
- buf += sprintf(buf, "EBUS");
- break;
- case 0x01:
- buf += sprintf(buf, "100BASE-TX");
- break;
- case 0x02:
- buf += sprintf(buf, "100BASE-FX");
- break;
- default:
- buf += sprintf(buf, "unknown");
- }
- buf += sprintf(buf, "), Link %s, Loop %s, %s\n",
- slave->dl_link[i] ? "up" : "down",
- slave->dl_loop[i] ? "closed" : "open",
- slave->dl_signal[i] ? "Signal detected" : "No signal");
- }
- buf += sprintf(buf, "\n");
-
- if (slave->sii.alias)
- buf += sprintf(buf, "Configured station alias:"
- " 0x%04X (%u)\n\n", slave->sii.alias, slave->sii.alias);
-
- buf += sprintf(buf, "Identity:\n");
- buf += sprintf(buf, " Vendor ID: 0x%08X (%u)\n",
- slave->sii.vendor_id, slave->sii.vendor_id);
- buf += sprintf(buf, " Product code: 0x%08X (%u)\n",
- slave->sii.product_code, slave->sii.product_code);
- buf += sprintf(buf, " Revision number: 0x%08X (%u)\n",
- slave->sii.revision_number, slave->sii.revision_number);
- buf += sprintf(buf, " Serial number: 0x%08X (%u)\n\n",
- slave->sii.serial_number, slave->sii.serial_number);
-
- if (slave->sii.mailbox_protocols) {
- buf += sprintf(buf, "Mailboxes:\n");
- buf += sprintf(buf, " RX: 0x%04X/%u, TX: 0x%04X/%u\n",
- slave->sii.rx_mailbox_offset, slave->sii.rx_mailbox_size,
- slave->sii.tx_mailbox_offset, slave->sii.tx_mailbox_size);
- buf += sprintf(buf, " Supported protocols: ");
-
- first = 1;
- if (slave->sii.mailbox_protocols & EC_MBOX_AOE) {
- buf += sprintf(buf, "AoE");
- first = 0;
- }
- if (slave->sii.mailbox_protocols & EC_MBOX_EOE) {
- if (!first) buf += sprintf(buf, ", ");
- buf += sprintf(buf, "EoE");
- first = 0;
- }
- if (slave->sii.mailbox_protocols & EC_MBOX_COE) {
- if (!first) buf += sprintf(buf, ", ");
- buf += sprintf(buf, "CoE");
- first = 0;
- }
- if (slave->sii.mailbox_protocols & EC_MBOX_FOE) {
- if (!first) buf += sprintf(buf, ", ");
- buf += sprintf(buf, "FoE");
- first = 0;
- }
- if (slave->sii.mailbox_protocols & EC_MBOX_SOE) {
- if (!first) buf += sprintf(buf, ", ");
- buf += sprintf(buf, "SoE");
- first = 0;
- }
- if (slave->sii.mailbox_protocols & EC_MBOX_VOE) {
- if (!first) buf += sprintf(buf, ", ");
- buf += sprintf(buf, "VoE");
- }
- buf += sprintf(buf, "\n\n");
- }
-
- if (slave->sii.has_general) {
- buf += sprintf(buf, "General:\n");
-
- if (slave->sii.group)
- buf += sprintf(buf, " Group: %s\n", slave->sii.group);
- if (slave->sii.image)
- buf += sprintf(buf, " Image: %s\n", slave->sii.image);
- if (slave->sii.order)
- buf += sprintf(buf, " Order number: %s\n",
- slave->sii.order);
- if (slave->sii.name)
- buf += sprintf(buf, " Name: %s\n", slave->sii.name);
- if (slave->sii.mailbox_protocols & EC_MBOX_COE) {
- buf += sprintf(buf, " CoE details:\n");
- buf += sprintf(buf, " Enable Sdo: %s\n",
- slave->sii.coe_details.enable_sdo ? "yes" : "no");
- buf += sprintf(buf, " Enable Sdo Info: %s\n",
- slave->sii.coe_details.enable_sdo_info ? "yes" : "no");
- buf += sprintf(buf, " Enable Pdo Assign: %s\n",
- slave->sii.coe_details.enable_pdo_assign ? "yes" : "no");
- buf += sprintf(buf, " Enable Pdo Configuration: %s\n",
- slave->sii.coe_details.enable_pdo_configuration ?
- "yes" : "no");
- buf += sprintf(buf, " Enable Upload at startup: %s\n",
- slave->sii.coe_details.enable_upload_at_startup ?
- "yes" : "no");
- buf += sprintf(buf, " Enable Sdo complete access: %s\n",
- slave->sii.coe_details.enable_sdo_complete_access
- ? "yes" : "no");
- }
-
- buf += sprintf(buf, " Flags:\n");
- buf += sprintf(buf, " Enable SafeOp: %s\n",
- slave->sii.general_flags.enable_safeop ? "yes" : "no");
- buf += sprintf(buf, " Enable notLRW: %s\n",
- slave->sii.general_flags.enable_not_lrw ? "yes" : "no");
- buf += sprintf(buf, " Current consumption: %i mA\n\n",
- slave->sii.current_on_ebus);
- }
-
- if (slave->sii.sync_count) {
- buf += sprintf(buf, "Sync managers / assigned Pdos:\n");
-
- for (i = 0; i < slave->sii.sync_count; i++) {
- sync = &slave->sii.syncs[i];
- buf += sprintf(buf,
- " SM%u: addr 0x%04X, size %u, control 0x%02X, %s\n",
- sync->index, sync->physical_start_address,
- sync->length, sync->control_register,
- sync->enable ? "enable" : "disable");
-
- if (list_empty(&sync->pdos.list)) {
- buf += sprintf(buf, " No Pdos assigned.\n");
- } else if (sync->assign_source != EC_ASSIGN_NONE) {
- buf += sprintf(buf, " Pdo assignment from ");
- switch (sync->assign_source) {
- case EC_ASSIGN_SII:
- buf += sprintf(buf, "SII");
- break;
- case EC_ASSIGN_COE:
- buf += sprintf(buf, "CoE");
- break;
- case EC_ASSIGN_CUSTOM:
- buf += sprintf(buf, "application");
- break;
- default:
- buf += sprintf(buf, "?");
- break;
- }
- buf += sprintf(buf, ".\n");
- }
-
- list_for_each_entry(pdo, &sync->pdos.list, list) {
- buf += sprintf(buf, " %s 0x%04X \"%s\"\n",
- pdo->dir == EC_DIR_OUTPUT ? "RxPdo" : "TxPdo",
- pdo->index, pdo->name ? pdo->name : "???");
-
- list_for_each_entry(pdo_entry, &pdo->entries, list) {
- buf += sprintf(buf,
- " 0x%04X:%02X, %u bit, \"%s\"\n",
- pdo_entry->index, pdo_entry->subindex,
- pdo_entry->bit_length,
- pdo_entry->name ? pdo_entry->name : "???");
- }
- }
- }
- buf += sprintf(buf, "\n");
- }
-
- // type-cast to avoid warnings on some compilers
- if (!list_empty((struct list_head *) &slave->sii.pdos)) {
- buf += sprintf(buf, "Available Pdos from SII:\n");
-
- list_for_each_entry(pdo, &slave->sii.pdos, list) {
- buf += sprintf(buf, " %s 0x%04X \"%s\"",
- pdo->dir == EC_DIR_OUTPUT ? "RxPdo" : "TxPdo",
- pdo->index, pdo->name ? pdo->name : "???");
- if (pdo->sync_index >= 0)
- buf += sprintf(buf, ", default assignment: SM%u.\n",
- pdo->sync_index);
- else
- buf += sprintf(buf, ", no default assignment.\n");
-
- list_for_each_entry(pdo_entry, &pdo->entries, list) {
- buf += sprintf(buf, " 0x%04X:%02X, %u bit, \"%s\"\n",
- pdo_entry->index, pdo_entry->subindex,
- pdo_entry->bit_length,
- pdo_entry->name ? pdo_entry->name : "???");
- }
- }
- buf += sprintf(buf, "\n");
- }
-
- size = buf - large_buffer;
- if (size >= PAGE_SIZE) {
- const char trunc[] = "\n---TRUNCATED---\n";
- unsigned int len = strlen(trunc);
- memcpy(large_buffer + PAGE_SIZE - len, trunc, len);
- }
-
- size = min(size, (unsigned int) PAGE_SIZE);
- memcpy(buffer, large_buffer, size);
- kfree(large_buffer);
- return size;
-}
-
-/*****************************************************************************/
-
/**
* Writes SII contents to a slave.
* \return Zero on success, otherwise error code.
@@ -898,27 +565,6 @@
/*****************************************************************************/
-/**
- Formats attribute data for SysFS read access.
- \return number of bytes to read
-*/
-
-ssize_t ec_show_slave_attribute(struct kobject *kobj, /**< slave's kobject */
- struct attribute *attr, /**< attribute */
- char *buffer /**< memory to store data */
- )
-{
- ec_slave_t *slave = container_of(kobj, ec_slave_t, kobj);
-
- if (attr == &attr_info) {
- return ec_slave_info(slave, buffer);
- }
-
- return 0;
-}
-
-/*****************************************************************************/
-
/** Get the sync manager for either Rx- or Tx-Pdos.
*
* \todo This seems not to be correct in every case...