Removed ktype for module kobject; added backup device for master; device
connection information and IDs in master info file.
This commit is contained in:
parent
046d9e7cd5
commit
b1a770729c
|
|
@ -116,6 +116,7 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */
|
|||
|
||||
master->device = NULL;
|
||||
master->main_device_id = main_id;
|
||||
master->backup_device = NULL;
|
||||
master->backup_device_id = backup_id;
|
||||
init_MUTEX(&master->device_sem);
|
||||
|
||||
|
|
@ -849,6 +850,38 @@ static int ec_master_thread(void *data)
|
|||
complete_and_exit(&master->thread_exit, 0);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
ssize_t ec_master_device_info(const ec_device_t *device,
|
||||
const ec_device_id_t *dev_id,
|
||||
char *buffer)
|
||||
{
|
||||
unsigned int frames_lost;
|
||||
off_t off = 0;
|
||||
|
||||
off += ec_device_id_print(dev_id, buffer + off);
|
||||
|
||||
if (device) {
|
||||
off += sprintf(buffer + off, " (connected).\n");
|
||||
off += sprintf(buffer + off, " Frames sent: %u\n",
|
||||
device->tx_count);
|
||||
off += sprintf(buffer + off, " Frames received: %u\n",
|
||||
device->rx_count);
|
||||
frames_lost = device->tx_count - device->rx_count;
|
||||
if (frames_lost) frames_lost--;
|
||||
off += sprintf(buffer + off, " Frames lost: %u\n", frames_lost);
|
||||
}
|
||||
else if (dev_id->type != ec_device_id_empty) {
|
||||
off += sprintf(buffer + off, " (WAITING).\n");
|
||||
}
|
||||
else {
|
||||
off += sprintf(buffer + off, ".\n");
|
||||
}
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
|
|
@ -863,9 +896,7 @@ ssize_t ec_master_info(ec_master_t *master, /**< EtherCAT master */
|
|||
off_t off = 0;
|
||||
ec_eoe_t *eoe;
|
||||
uint32_t cur, sum, min, max, pos, i;
|
||||
unsigned int frames_lost;
|
||||
|
||||
off += sprintf(buffer + off, "\nVersion: %s", ec_master_version_str);
|
||||
off += sprintf(buffer + off, "\nMode: ");
|
||||
switch (master->mode) {
|
||||
case EC_MASTER_MODE_ORPHANED:
|
||||
|
|
@ -881,14 +912,22 @@ ssize_t ec_master_info(ec_master_t *master, /**< EtherCAT master */
|
|||
|
||||
off += sprintf(buffer + off, "\nSlaves: %i\n",
|
||||
master->slave_count);
|
||||
off += sprintf(buffer + off, "\nDevice:\n");
|
||||
off += sprintf(buffer + off, " Frames sent: %u\n",
|
||||
master->device->tx_count);
|
||||
off += sprintf(buffer + off, " Frames received: %u\n",
|
||||
master->device->rx_count);
|
||||
frames_lost = master->device->tx_count - master->device->rx_count;
|
||||
if (frames_lost) frames_lost--;
|
||||
off += sprintf(buffer + off, " Frames lost: %u\n", frames_lost);
|
||||
|
||||
off += sprintf(buffer + off, "\nDevices:\n");
|
||||
|
||||
if (down_interruptible(&master->device_sem)) {
|
||||
EC_ERR("Interrupted while waiting for device!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
off += sprintf(buffer + off, " Main: ");
|
||||
off += ec_master_device_info(master->device,
|
||||
master->main_device_id, buffer + off);
|
||||
off += sprintf(buffer + off, " Backup: ");
|
||||
off += ec_master_device_info(master->backup_device,
|
||||
master->backup_device_id, buffer + off);
|
||||
|
||||
up(&master->device_sem);
|
||||
|
||||
off += sprintf(buffer + off, "\nTiming (min/avg/max) [us]:\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ struct ec_master
|
|||
|
||||
ec_device_t *device; /**< EtherCAT device */
|
||||
const ec_device_id_t *main_device_id; /**< ID of main device */
|
||||
ec_device_t *backup_device; /**< EtherCAT backup device */
|
||||
const ec_device_id_t *backup_device_id; /**< ID of backup device */
|
||||
struct semaphore device_sem; /**< device semaphore */
|
||||
|
||||
|
|
|
|||
|
|
@ -52,33 +52,6 @@
|
|||
int __init ec_init_module(void);
|
||||
void __exit ec_cleanup_module(void);
|
||||
|
||||
ssize_t ec_show_attribute(struct kobject *, struct attribute *, char *);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** \cond */
|
||||
|
||||
EC_SYSFS_READ_ATTR(info);
|
||||
|
||||
static struct attribute *ec_def_attrs[] = {
|
||||
&attr_info,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct sysfs_ops ec_sysfs_ops = {
|
||||
.show = &ec_show_attribute,
|
||||
.store = NULL
|
||||
};
|
||||
|
||||
static struct kobj_type ktype_ec_module = {
|
||||
.release = NULL, // this is ok, because the module can not be unloaded
|
||||
// if the reference count is greater zero.
|
||||
.sysfs_ops = &ec_sysfs_ops,
|
||||
.default_attrs = ec_def_attrs
|
||||
};
|
||||
|
||||
/** \endcond */
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
struct kobject ec_kobj; /**< kobject for master module */
|
||||
|
|
@ -128,8 +101,7 @@ int __init ec_init_module(void)
|
|||
|
||||
// init kobject and add it to the hierarchy
|
||||
memset(&ec_kobj, 0x00, sizeof(struct kobject));
|
||||
kobject_init(&ec_kobj);
|
||||
ec_kobj.ktype = &ktype_ec_module;
|
||||
kobject_init(&ec_kobj); // no ktype
|
||||
|
||||
if (kobject_set_name(&ec_kobj, "ethercat")) {
|
||||
EC_ERR("Failed to set module kobject name.\n");
|
||||
|
|
@ -231,42 +203,6 @@ void __exit ec_cleanup_module(void)
|
|||
EC_INFO("Master module cleaned up.\n");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
Formats module information for SysFS read access.
|
||||
\return number of bytes written
|
||||
*/
|
||||
|
||||
ssize_t ec_info(char *buffer /**< memory to store data */)
|
||||
{
|
||||
off_t off = 0;
|
||||
|
||||
off += sprintf(buffer + off, "\nVersion: %s", ec_master_version_str);
|
||||
off += sprintf(buffer + off, "\n");
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
Formats attribute data for SysFS read access.
|
||||
\return number of bytes to read
|
||||
*/
|
||||
|
||||
ssize_t ec_show_attribute(struct kobject *kobj, /**< kobject */
|
||||
struct attribute *attr, /**< attribute */
|
||||
char *buffer /**< memory to store data */
|
||||
)
|
||||
{
|
||||
if (attr == &attr_info)
|
||||
return ec_info(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
|
|
@ -403,7 +339,7 @@ int ecdev_offer(struct net_device *net_dev, /**< net_device to offer */
|
|||
)
|
||||
{
|
||||
ec_master_t *master;
|
||||
unsigned int i;
|
||||
char str[50]; // FIXME
|
||||
|
||||
list_for_each_entry(master, &masters, list) {
|
||||
if (down_interruptible(&master->device_sem)) {
|
||||
|
|
@ -414,15 +350,12 @@ int ecdev_offer(struct net_device *net_dev, /**< net_device to offer */
|
|||
if (ec_device_id_check(master->main_device_id, net_dev,
|
||||
driver_name, device_index)) {
|
||||
|
||||
EC_INFO("Accepting device %s:%u (", driver_name, device_index);
|
||||
for (i = 0; i < ETH_ALEN; i++) {
|
||||
printk("%02X", net_dev->dev_addr[i]);
|
||||
if (i < ETH_ALEN - 1) printk(":");
|
||||
}
|
||||
printk(") for master %u.\n", master->index);
|
||||
ec_device_id_print(master->main_device_id, str);
|
||||
EC_INFO("Accepting device %s for master %u.\n",
|
||||
str, master->index);
|
||||
|
||||
if (master->device) {
|
||||
EC_ERR("Master already has a device.\n");
|
||||
EC_ERR("Master %u already has a device.\n", master->index);
|
||||
goto out_up;
|
||||
}
|
||||
|
||||
|
|
@ -473,22 +406,18 @@ int ecdev_offer(struct net_device *net_dev, /**< net_device to offer */
|
|||
void ecdev_withdraw(ec_device_t *device /**< EtherCAT device */)
|
||||
{
|
||||
ec_master_t *master = device->master;
|
||||
unsigned int i;
|
||||
char str[50]; // FIXME
|
||||
|
||||
ec_device_id_print(master->main_device_id, str);
|
||||
|
||||
EC_INFO("Master %u releasing main device %s.\n", master->index, str);
|
||||
|
||||
down(&master->device_sem);
|
||||
|
||||
EC_INFO("Master %u releasing device ", master->index);
|
||||
for (i = 0; i < ETH_ALEN; i++) {
|
||||
printk("%02X", device->dev->dev_addr[i]);
|
||||
if (i < ETH_ALEN - 1) printk(":");
|
||||
}
|
||||
printk(".\n");
|
||||
|
||||
ec_device_clear(master->device);
|
||||
kfree(master->device);
|
||||
master->device = NULL;
|
||||
|
||||
up(&master->device_sem);
|
||||
|
||||
ec_device_clear(device);
|
||||
kfree(device);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
Loading…
Reference in New Issue