master/domain.c
changeset 178 b84f69db8566
parent 166 29b19a90ff3f
child 179 fb4c9dd11ca0
equal deleted inserted replaced
177:482200a0659f 178:b84f69db8566
    10 
    10 
    11 #include "globals.h"
    11 #include "globals.h"
    12 #include "domain.h"
    12 #include "domain.h"
    13 #include "master.h"
    13 #include "master.h"
    14 
    14 
       
    15 /*****************************************************************************/
       
    16 
    15 void ec_domain_clear_field_regs(ec_domain_t *);
    17 void ec_domain_clear_field_regs(ec_domain_t *);
    16 
    18 
    17 /*****************************************************************************/
    19 /*****************************************************************************/
    18 
    20 
       
    21 static struct attribute attr_data_size = {
       
    22     .name = "data_size",
       
    23     .owner = THIS_MODULE,
       
    24     .mode = S_IRUGO
       
    25 };
       
    26 
       
    27 static struct attribute *def_attrs[] = {
       
    28     &attr_data_size,
       
    29     NULL,
       
    30 };
       
    31 
       
    32 static struct sysfs_ops sysfs_ops = {
       
    33     .show = &ec_show_domain_attribute,
       
    34     .store = NULL
       
    35 };
       
    36 
       
    37 static struct kobj_type ktype_ec_domain = {
       
    38     .release = ec_domain_clear,
       
    39     .sysfs_ops = &sysfs_ops,
       
    40     .default_attrs = def_attrs
       
    41 };
       
    42 
       
    43 /*****************************************************************************/
       
    44 
    19 /**
    45 /**
    20    Konstruktor einer EtherCAT-Domäne.
    46    Konstruktor einer EtherCAT-Domäne.
    21 */
    47 */
    22 
    48 
    23 void ec_domain_init(ec_domain_t *domain, /**< Domäne */
    49 int ec_domain_init(ec_domain_t *domain, /**< Domäne */
    24                     ec_master_t *master /**< Zugehöriger Master */
    50                    ec_master_t *master, /**< Zugehöriger Master */
    25                     )
    51                    unsigned int index /**< Domänen-Index */
       
    52                    )
    26 {
    53 {
    27     domain->master = master;
    54     domain->master = master;
       
    55     domain->index = index;
    28     domain->data_size = 0;
    56     domain->data_size = 0;
    29     domain->base_address = 0;
    57     domain->base_address = 0;
    30     domain->response_count = 0xFFFFFFFF;
    58     domain->response_count = 0xFFFFFFFF;
    31 
    59 
    32     INIT_LIST_HEAD(&domain->field_regs);
    60     INIT_LIST_HEAD(&domain->field_regs);
    33     INIT_LIST_HEAD(&domain->commands);
    61     INIT_LIST_HEAD(&domain->commands);
       
    62 
       
    63     // Init kobject and add it to the hierarchy
       
    64     memset(&domain->kobj, 0x00, sizeof(struct kobject));
       
    65     kobject_init(&domain->kobj);
       
    66     domain->kobj.ktype = &ktype_ec_domain;
       
    67     domain->kobj.parent = &master->kobj;
       
    68     if (kobject_set_name(&domain->kobj, "domain%i", index)) {
       
    69         EC_ERR("Failed to set kobj name.\n");
       
    70         return -1;
       
    71     }
       
    72 
       
    73     return 0;
    34 }
    74 }
    35 
    75 
    36 /*****************************************************************************/
    76 /*****************************************************************************/
    37 
    77 
    38 /**
    78 /**
    39    Destruktor einer EtherCAT-Domäne.
    79    Destruktor einer EtherCAT-Domäne.
    40 */
    80 */
    41 
    81 
    42 void ec_domain_clear(ec_domain_t *domain /**< Domäne */)
    82 void ec_domain_clear(struct kobject *kobj /**< Kobject der Domäne */)
    43 {
    83 {
    44     ec_command_t *command, *next;
    84     ec_command_t *command, *next;
       
    85     ec_domain_t *domain;
       
    86 
       
    87     domain = container_of(kobj, ec_domain_t, kobj);
       
    88 
       
    89     EC_INFO("Clearing domain %i.\n", domain->index);
    45 
    90 
    46     list_for_each_entry_safe(command, next, &domain->commands, list) {
    91     list_for_each_entry_safe(command, next, &domain->commands, list) {
    47         ec_command_clear(command);
    92         ec_command_clear(command);
    48         kfree(command);
    93         kfree(command);
    49     }
    94     }
    50 
    95 
    51     ec_domain_clear_field_regs(domain);
    96     ec_domain_clear_field_regs(domain);
       
    97 
       
    98     kfree(domain);
    52 }
    99 }
    53 
   100 
    54 /*****************************************************************************/
   101 /*****************************************************************************/
    55 
   102 
    56 /**
   103 /**
   190             return -1;
   237             return -1;
   191         cmd_count++;
   238         cmd_count++;
   192     }
   239     }
   193 
   240 
   194     if (!cmd_count) {
   241     if (!cmd_count) {
   195         EC_WARN("Domain 0x%08X contains no data!\n", (u32) domain);
   242         EC_WARN("Domain %i contains no data!\n", domain->index);
   196         ec_domain_clear_field_regs(domain);
   243         ec_domain_clear_field_regs(domain);
   197         return 0;
   244         return 0;
   198     }
   245     }
   199 
   246 
   200     // Alle Prozessdatenzeiger setzen
   247     // Alle Prozessdatenzeiger setzen
   219                 break;
   266                 break;
   220             }
   267             }
   221         }
   268         }
   222     }
   269     }
   223 
   270 
   224     EC_INFO("Domain %X - Allocated %i bytes in %i command(s)\n",
   271     EC_INFO("Domain %i - Allocated %i bytes in %i command%s\n",
   225             (u32) domain, domain->data_size, cmd_count);
   272             domain->index, domain->data_size, cmd_count,
       
   273             cmd_count == 1 ? "" : "s");
   226 
   274 
   227     ec_domain_clear_field_regs(domain);
   275     ec_domain_clear_field_regs(domain);
   228 
   276 
   229     return 0;
   277     return 0;
   230 }
   278 }
   239                               unsigned int count /**< Neue Anzahl */
   287                               unsigned int count /**< Neue Anzahl */
   240                               )
   288                               )
   241 {
   289 {
   242     if (count != domain->response_count) {
   290     if (count != domain->response_count) {
   243         domain->response_count = count;
   291         domain->response_count = count;
   244         EC_INFO("Domain 0x%08X working counter change: %i\n",
   292         EC_INFO("Domain %i working counter change: %i\n", domain->index, count);
   245                 (u32) domain, count);
   293     }
   246     }
   294 }
       
   295 
       
   296 /*****************************************************************************/
       
   297 
       
   298 /**
       
   299    Formatiert Attribut-Daten für lesenden Zugriff im SysFS
       
   300 
       
   301    \return Anzahl Bytes im Speicher
       
   302 */
       
   303 
       
   304 ssize_t ec_show_domain_attribute(struct kobject *kobj, /**< KObject */
       
   305                                  struct attribute *attr, /**< Attribut */
       
   306                                  char *buffer /**< Speicher für die Daten */
       
   307                                  )
       
   308 {
       
   309     ec_domain_t *domain = container_of(kobj, ec_domain_t, kobj);
       
   310 
       
   311     if (attr == &attr_data_size) {
       
   312         return sprintf(buffer, "%i\n", domain->data_size);
       
   313     }
       
   314 
       
   315     return 0;
   247 }
   316 }
   248 
   317 
   249 /******************************************************************************
   318 /******************************************************************************
   250  *
   319  *
   251  * Echtzeitschnittstelle
   320  * Echtzeitschnittstelle