New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.

This commit is contained in:
Florian Pose 2007-02-20 11:28:15 +00:00
parent 383a1f7631
commit 27f9a4af2d
4 changed files with 106 additions and 23 deletions

View File

@ -101,11 +101,12 @@ static struct kobj_type ktype_ec_master = {
*/
int ec_master_init(ec_master_t *master, /**< EtherCAT master */
unsigned int index, /**< master index */
const ec_device_id_t *main_id, /**< ID of main device */
const ec_device_id_t *backup_id, /**< ID of main device */
unsigned int eoeif_count /**< number of EoE interfaces */
)
struct kobject *module_kobj, /**< kobject of the master module */
unsigned int index, /**< master index */
const ec_device_id_t *main_id, /**< ID of main device */
const ec_device_id_t *backup_id, /**< ID of main device */
unsigned int eoeif_count /**< number of EoE interfaces */
)
{
ec_eoe_t *eoe, *next_eoe;
unsigned int i;
@ -192,13 +193,16 @@ int ec_master_init(ec_master_t *master, /**< EtherCAT master */
memset(&master->kobj, 0x00, sizeof(struct kobject));
kobject_init(&master->kobj);
master->kobj.ktype = &ktype_ec_master;
if (kobject_set_name(&master->kobj, "ethercat%i", index)) {
EC_ERR("Failed to set kobj name.\n");
master->kobj.parent = module_kobj;
if (kobject_set_name(&master->kobj, "master%i", index)) {
EC_ERR("Failed to set master kobject name.\n");
kobject_put(&master->kobj);
return -1;
}
if (kobject_add(&master->kobj)) {
EC_ERR("Failed to add master kobj.\n");
EC_ERR("Failed to add master kobject.\n");
kobject_put(&master->kobj);
return -1;
}

View File

@ -150,7 +150,7 @@ struct ec_master
/*****************************************************************************/
// master creation/deletion
int ec_master_init(ec_master_t *, unsigned int,
int ec_master_init(ec_master_t *, struct kobject *, unsigned int,
const ec_device_id_t *, const ec_device_id_t *, unsigned int);
void ec_master_destroy(ec_master_t *);

View File

@ -52,8 +52,37 @@
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 */
static char *main; /**< main devices parameter */
static char *backup; /**< backup devices parameter */
@ -97,9 +126,24 @@ int __init ec_init_module(void)
EC_INFO("Master driver %s\n", EC_MASTER_VERSION);
// 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;
if (kobject_set_name(&ec_kobj, "ethercat")) {
EC_ERR("Failed to set module kobject name.\n");
goto out_put;
}
if (kobject_add(&ec_kobj)) {
EC_ERR("Failed to add module kobject.\n");
goto out_put;
}
if (alloc_chrdev_region(&device_number, 0, 1, "EtherCAT")) {
EC_ERR("Failed to obtain device number!\n");
goto out_return;
goto out_del;
}
if (ec_device_id_process_params(main, backup, &main_ids, &backup_ids))
@ -121,7 +165,7 @@ int __init ec_init_module(void)
goto out_free_masters;
}
if (ec_master_init(master, master_index,
if (ec_master_init(master, &ec_kobj, master_index,
main_dev_id, backup_dev_id, 0))
goto out_free_masters;
@ -153,7 +197,10 @@ out_free_masters:
ec_device_id_clear_list(&backup_ids);
out_cdev:
unregister_chrdev_region(device_number, 1);
out_return:
out_del:
kobject_del(&ec_kobj);
out_put:
kobject_put(&ec_kobj);
return -1;
}
@ -178,10 +225,48 @@ void __exit ec_cleanup_module(void)
ec_device_id_clear_list(&main_ids);
ec_device_id_clear_list(&backup_ids);
unregister_chrdev_region(device_number, 1);
kobject_del(&ec_kobj);
kobject_put(&ec_kobj);
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;
}
/*****************************************************************************/
/**

View File

@ -44,28 +44,20 @@ use Getopt::Std;
my %opt;
my $master_index;
my $master_dir;
my $term_width;
#------------------------------------------------------------------------------
$term_width = &get_terminal_width;
&get_options;
&query_master;
&query;
exit 0;
#------------------------------------------------------------------------------
sub query_master
{
$master_dir = "/sys/ethercat" . $master_index;
&query_slaves;
}
#------------------------------------------------------------------------------
sub query_slaves
sub query
{
my $master_dir;
my $dirhandle;
my $entry;
my @slaves;
@ -77,6 +69,8 @@ sub query_slaves
my $fmt;
my $cols;
$master_dir = "/sys/ethercat/master" . $master_index;
unless (opendir $dirhandle, $master_dir) {
print "Failed to open directory \"$master_dir\".\n";
exit 1;