Removed kobject from slave_config.
This commit is contained in:
parent
fbdb093ec0
commit
3197ca4a23
1
TODO
1
TODO
|
|
@ -27,6 +27,7 @@ Version 1.4.0:
|
|||
* Remove EC_IOCTL_DOMAIN_COUNT.
|
||||
* Remove ATOMIC allocations.
|
||||
* Clear FMMU configs.
|
||||
* Rename master MODE to STATE.
|
||||
|
||||
Future issues:
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
void ec_master_destroy_slave_configs(ec_master_t *);
|
||||
void ec_master_clear_slave_configs(ec_master_t *);
|
||||
void ec_master_clear_domains(ec_master_t *);
|
||||
static int ec_master_idle_thread(ec_master_t *);
|
||||
static int ec_master_operation_thread(ec_master_t *);
|
||||
|
|
@ -226,17 +226,17 @@ void ec_master_clear(
|
|||
ec_master_t *master /**< EtherCAT master */
|
||||
)
|
||||
{
|
||||
ec_cdev_clear(&master->cdev);
|
||||
#ifdef EC_EOE
|
||||
ec_master_clear_eoe_handlers(master);
|
||||
#endif
|
||||
ec_master_clear_domains(master);
|
||||
ec_master_destroy_slave_configs(master);
|
||||
ec_master_clear_slave_configs(master);
|
||||
ec_master_clear_slaves(master);
|
||||
ec_fsm_master_clear(&master->fsm);
|
||||
ec_datagram_clear(&master->fsm_datagram);
|
||||
ec_device_clear(&master->backup_device);
|
||||
ec_device_clear(&master->main_device);
|
||||
ec_cdev_clear(&master->cdev);
|
||||
|
||||
// destroy self
|
||||
kobject_del(&master->kobj);
|
||||
|
|
@ -264,15 +264,16 @@ void ec_master_clear_eoe_handlers(
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Destroy all slave configurations.
|
||||
/** Clear all slave configurations.
|
||||
*/
|
||||
void ec_master_destroy_slave_configs(ec_master_t *master)
|
||||
void ec_master_clear_slave_configs(ec_master_t *master)
|
||||
{
|
||||
ec_slave_config_t *sc, *next;
|
||||
|
||||
list_for_each_entry_safe(sc, next, &master->configs, list) {
|
||||
list_del(&sc->list);
|
||||
ec_slave_config_destroy(sc);
|
||||
ec_slave_config_clear(sc);
|
||||
kfree(sc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -517,8 +518,8 @@ void ec_master_leave_operation_mode(ec_master_t *master
|
|||
master->release_cb = ec_master_release_cb;
|
||||
master->cb_data = master;
|
||||
|
||||
ec_master_destroy_slave_configs(master);
|
||||
ec_master_clear_domains(master);
|
||||
ec_master_clear_slave_configs(master);
|
||||
|
||||
// set states for all slaves
|
||||
list_for_each_entry(slave, &master->slaves, list) {
|
||||
|
|
@ -1367,11 +1368,8 @@ ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (ec_slave_config_init(sc, master, alias, position, vendor_id,
|
||||
product_code)) {
|
||||
EC_ERR("Failed to init slave configuration.\n");
|
||||
return NULL;
|
||||
}
|
||||
ec_slave_config_init(sc, master,
|
||||
alias, position, vendor_id, product_code);
|
||||
|
||||
// try to find the addressed slave
|
||||
ec_slave_config_attach(sc);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "master.h"
|
||||
|
|
@ -47,44 +47,13 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
void ec_slave_config_clear(struct kobject *);
|
||||
ssize_t ec_show_slave_config_attribute(struct kobject *, struct attribute *,
|
||||
char *);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** \cond */
|
||||
|
||||
EC_SYSFS_READ_ATTR(info);
|
||||
|
||||
static struct attribute *def_attrs[] = {
|
||||
&attr_info,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct sysfs_ops sysfs_ops = {
|
||||
.show = ec_show_slave_config_attribute
|
||||
};
|
||||
|
||||
static struct kobj_type ktype_ec_slave_config = {
|
||||
.release = ec_slave_config_clear,
|
||||
.sysfs_ops = &sysfs_ops,
|
||||
.default_attrs = def_attrs
|
||||
};
|
||||
|
||||
/** \endcond */
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Slave configuration constructor.
|
||||
*
|
||||
* See ecrt_master_slave_config() for the usage of the \a alias and \a
|
||||
* position parameters.
|
||||
*
|
||||
* \retval 0 Success.
|
||||
* \retval <0 Failure.
|
||||
*/
|
||||
int ec_slave_config_init(ec_slave_config_t *sc, /**< Slave configuration. */
|
||||
void ec_slave_config_init(
|
||||
ec_slave_config_t *sc, /**< Slave configuration. */
|
||||
ec_master_t *master, /**< EtherCAT master. */
|
||||
uint16_t alias, /**< Slave alias. */
|
||||
uint16_t position, /**< Slave position. */
|
||||
|
|
@ -108,28 +77,6 @@ int ec_slave_config_init(ec_slave_config_t *sc, /**< Slave configuration. */
|
|||
INIT_LIST_HEAD(&sc->sdo_requests);
|
||||
|
||||
sc->used_fmmus = 0;
|
||||
|
||||
// init kobject and add it to the hierarchy
|
||||
memset(&sc->kobj, 0x00, sizeof(struct kobject));
|
||||
kobject_init(&sc->kobj);
|
||||
sc->kobj.ktype = &ktype_ec_slave_config;
|
||||
sc->kobj.parent = &master->kobj;
|
||||
if (kobject_set_name(&sc->kobj, "config-%u-%u", sc->alias, sc->position)) {
|
||||
EC_ERR("Failed to set kobject name for slave config %u:%u.\n",
|
||||
sc->alias, sc->position);
|
||||
goto out_put;
|
||||
}
|
||||
if (kobject_add(&sc->kobj)) {
|
||||
EC_ERR("Failed to add kobject for slave config %u:%u.\n",
|
||||
sc->alias, sc->position);
|
||||
goto out_put;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
out_put:
|
||||
kobject_put(&sc->kobj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -138,31 +85,14 @@ int ec_slave_config_init(ec_slave_config_t *sc, /**< Slave configuration. */
|
|||
*
|
||||
* Clears and frees a slave configuration object.
|
||||
*/
|
||||
void ec_slave_config_destroy(
|
||||
void ec_slave_config_clear(
|
||||
ec_slave_config_t *sc /**< Slave configuration. */
|
||||
)
|
||||
{
|
||||
ec_slave_config_detach(sc);
|
||||
|
||||
// destroy self
|
||||
kobject_del(&sc->kobj);
|
||||
kobject_put(&sc->kobj);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Clear and free the slave configuration.
|
||||
*
|
||||
* This method is called by the kobject, once there are no more references to
|
||||
* it.
|
||||
*/
|
||||
void ec_slave_config_clear(struct kobject *kobj /**< kobject of the config. */)
|
||||
{
|
||||
ec_slave_config_t *sc;
|
||||
ec_direction_t dir;
|
||||
ec_sdo_request_t *req, *next_req;
|
||||
|
||||
sc = container_of(kobj, ec_slave_config_t, kobj);
|
||||
ec_slave_config_detach(sc);
|
||||
|
||||
// Free Pdo mappings
|
||||
for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++)
|
||||
|
|
@ -181,8 +111,6 @@ void ec_slave_config_clear(struct kobject *kobj /**< kobject of the config. */)
|
|||
ec_sdo_request_clear(req);
|
||||
kfree(req);
|
||||
}
|
||||
|
||||
kfree(sc);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -228,99 +156,6 @@ int ec_slave_config_prepare_fmmu(
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Outputs all information about a certain slave configuration.
|
||||
*/
|
||||
ssize_t ec_slave_config_info(
|
||||
const ec_slave_config_t *sc, /**< Slave configuration. */
|
||||
char *buffer /**< Output buffer */
|
||||
)
|
||||
{
|
||||
char *buf = buffer;
|
||||
ec_direction_t dir;
|
||||
const ec_pdo_list_t *pdos;
|
||||
const ec_pdo_t *pdo;
|
||||
const ec_pdo_entry_t *entry;
|
||||
char str[20];
|
||||
const ec_sdo_request_t *req;
|
||||
|
||||
buf += sprintf(buf, "Alias: 0x%04X (%u)\n", sc->alias, sc->alias);
|
||||
buf += sprintf(buf, "Position: %u\n", sc->position);
|
||||
|
||||
for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
|
||||
pdos = &sc->pdos[dir];
|
||||
|
||||
if (!list_empty(&pdos->list)) {
|
||||
buf += sprintf(buf, "%s Pdo assignment / mapping:\n",
|
||||
dir == EC_DIR_OUTPUT ? "Output" : "Input");
|
||||
|
||||
list_for_each_entry(pdo, &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(entry, &pdo->entries, list) {
|
||||
buf += sprintf(buf, " 0x%04X:%02X \"%s\", %u bit\n",
|
||||
entry->index, entry->subindex,
|
||||
entry->name ? entry->name : "???",
|
||||
entry->bit_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// type-cast to avoid warnings on some compilers
|
||||
if (!list_empty((struct list_head *) &sc->sdo_configs)) {
|
||||
buf += sprintf(buf, "\nSdo configurations:\n");
|
||||
|
||||
list_for_each_entry(req, &sc->sdo_configs, list) {
|
||||
switch (req->data_size) {
|
||||
case 1: sprintf(str, "%u", EC_READ_U8(req->data)); break;
|
||||
case 2: sprintf(str, "%u", EC_READ_U16(req->data)); break;
|
||||
case 4: sprintf(str, "%u", EC_READ_U32(req->data)); break;
|
||||
default: sprintf(str, "(invalid size)"); break;
|
||||
}
|
||||
buf += sprintf(buf, " 0x%04X:%02X -> %s\n",
|
||||
req->index, req->subindex, str);
|
||||
}
|
||||
buf += sprintf(buf, "\n");
|
||||
}
|
||||
|
||||
// type-cast to avoid warnings on some compilers
|
||||
if (!list_empty((struct list_head *) &sc->sdo_requests)) {
|
||||
buf += sprintf(buf, "\nSdo requests:\n");
|
||||
|
||||
list_for_each_entry(req, &sc->sdo_requests, list) {
|
||||
buf += sprintf(buf, " 0x%04X:%02X\n", req->index, req->subindex);
|
||||
}
|
||||
buf += sprintf(buf, "\n");
|
||||
}
|
||||
|
||||
return buf - buffer;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Formats attribute data for SysFS read access.
|
||||
*
|
||||
* \return number of bytes to read
|
||||
*/
|
||||
ssize_t ec_show_slave_config_attribute(
|
||||
struct kobject *kobj, /**< Slave configuration's kobject */
|
||||
struct attribute *attr, /**< Requested attribute. */
|
||||
char *buffer /**< Memory to store data. */
|
||||
)
|
||||
{
|
||||
ec_slave_config_t *sc = container_of(kobj, ec_slave_config_t, kobj);
|
||||
|
||||
if (attr == &attr_info) {
|
||||
return ec_slave_config_info(sc, buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Attaches the configuration to the addressed slave object.
|
||||
*
|
||||
* \retval 0 Success.
|
||||
|
|
@ -464,8 +299,6 @@ void ec_slave_config_load_default_mapping(
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
*/
|
||||
unsigned int ec_slave_config_sdo_count(
|
||||
const ec_slave_config_t *sc /**< Slave configuration. */
|
||||
)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@
|
|||
#define __EC_SLAVE_CONFIG_H__
|
||||
|
||||
#include <linux/list.h>
|
||||
#include <linux/kobject.h>
|
||||
|
||||
#include "../include/ecrt.h"
|
||||
|
||||
|
|
@ -57,7 +56,6 @@
|
|||
*/
|
||||
struct ec_slave_config {
|
||||
struct list_head list; /**< List item. */
|
||||
struct kobject kobj; /**< kobject. */
|
||||
ec_master_t *master; /**< Master owning the slave configuration. */
|
||||
|
||||
uint16_t alias; /**< Slave alias. */
|
||||
|
|
@ -80,9 +78,9 @@ struct ec_slave_config {
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
int ec_slave_config_init(ec_slave_config_t *, ec_master_t *, uint16_t,
|
||||
void ec_slave_config_init(ec_slave_config_t *, ec_master_t *, uint16_t,
|
||||
uint16_t, uint32_t, uint32_t);
|
||||
void ec_slave_config_destroy(ec_slave_config_t *);
|
||||
void ec_slave_config_clear(ec_slave_config_t *);
|
||||
|
||||
int ec_slave_config_attach(ec_slave_config_t *);
|
||||
void ec_slave_config_detach(ec_slave_config_t *);
|
||||
|
|
|
|||
Loading…
Reference in New Issue