master/domain.c
changeset 84 b4ae98855cea
parent 76 9dc136e3801c
child 90 044e97bce4bd
equal deleted inserted replaced
83:e8b76a509bc9 84:b4ae98855cea
    74 {
    74 {
    75     ec_field_reg_t *field_reg;
    75     ec_field_reg_t *field_reg;
    76 
    76 
    77     if (!(field_reg = (ec_field_reg_t *) kmalloc(sizeof(ec_field_reg_t),
    77     if (!(field_reg = (ec_field_reg_t *) kmalloc(sizeof(ec_field_reg_t),
    78                                                  GFP_KERNEL))) {
    78                                                  GFP_KERNEL))) {
    79         printk(KERN_ERR "EtherCAT: Failed to allocate field registration.\n");
    79         EC_ERR("Failed to allocate field registration.\n");
    80         return -1;
    80         return -1;
    81     }
    81     }
    82 
    82 
    83     if (ec_slave_set_fmmu(slave, domain, sync)) {
    83     if (ec_slave_set_fmmu(slave, domain, sync)) {
    84         printk(KERN_ERR "EtherCAT: FMMU configuration failed.\n");
    84         EC_ERR("FMMU configuration failed.\n");
    85         kfree(field_reg);
    85         kfree(field_reg);
    86         return -1;
    86         return -1;
    87     }
    87     }
    88 
    88 
    89     field_reg->slave = slave;
    89     field_reg->slave = slave;
   110     ec_slave_t *slave;
   110     ec_slave_t *slave;
   111     ec_fmmu_t *fmmu;
   111     ec_fmmu_t *fmmu;
   112     unsigned int i, j, found, data_offset;
   112     unsigned int i, j, found, data_offset;
   113 
   113 
   114     if (domain->data) {
   114     if (domain->data) {
   115         printk(KERN_ERR "EtherCAT: Domain already allocated!\n");
   115         EC_ERR("Domain already allocated!\n");
   116         return -1;
   116         return -1;
   117     }
   117     }
   118 
   118 
   119     domain->base_address = base_address;
   119     domain->base_address = base_address;
   120 
   120 
   131             }
   131             }
   132         }
   132         }
   133     }
   133     }
   134 
   134 
   135     if (!domain->data_size) {
   135     if (!domain->data_size) {
   136         printk(KERN_WARNING "EtherCAT: Domain 0x%08X contains no data!\n",
   136         EC_WARN("Domain 0x%08X contains no data!\n", (u32) domain);
   137                (u32) domain);
       
   138     }
   137     }
   139     else {
   138     else {
   140         // Prozessdaten allozieren
   139         // Prozessdaten allozieren
   141         if (!(domain->data = kmalloc(domain->data_size, GFP_KERNEL))) {
   140         if (!(domain->data = kmalloc(domain->data_size, GFP_KERNEL))) {
   142             printk(KERN_ERR "EtherCAT: Failed to allocate domain data!\n");
   141             EC_ERR("Failed to allocate domain data!\n");
   143             return -1;
   142             return -1;
   144         }
   143         }
   145 
   144 
   146         // Prozessdaten mit Nullen vorbelegen
   145         // Prozessdaten mit Nullen vorbelegen
   147         memset(domain->data, 0x00, domain->data_size);
   146         memset(domain->data, 0x00, domain->data_size);
   159                     break;
   158                     break;
   160                 }
   159                 }
   161             }
   160             }
   162 
   161 
   163             if (!found) { // Sollte nie passieren
   162             if (!found) { // Sollte nie passieren
   164                 printk(KERN_ERR "EtherCAT: FMMU not found. Please report!\n");
   163                 EC_ERR("FMMU not found. Please report!\n");
   165                 return -1;
   164                 return -1;
   166             }
   165             }
   167         }
   166         }
   168     }
   167     }
   169 
   168 
   207     const ec_field_t *field;
   206     const ec_field_t *field;
   208     unsigned int field_idx, i, j;
   207     unsigned int field_idx, i, j;
   209     uint32_t field_offset;
   208     uint32_t field_offset;
   210 
   209 
   211     if (!field_count) {
   210     if (!field_count) {
   212         printk(KERN_ERR "EtherCAT: field_count may not be 0!\n");
   211         EC_ERR("field_count may not be 0!\n");
   213         return NULL;
   212         return NULL;
   214     }
   213     }
   215 
   214 
   216     master = domain->master;
   215     master = domain->master;
   217 
   216 
   218     // Adresse übersetzen
   217     // Adresse übersetzen
   219     if ((slave = ec_address(master, address)) == NULL) return NULL;
   218     if ((slave = ec_address(master, address)) == NULL) return NULL;
   220 
   219 
   221     if (!(type = slave->type)) {
   220     if (!(type = slave->type)) {
   222         printk(KERN_ERR "EtherCAT: Slave \"%s\" (position %i) has unknown"
   221         EC_ERR("Slave \"%s\" (position %i) has unknown type!\n", address,
   223                " type!\n", address, slave->ring_position);
   222                slave->ring_position);
   224         return NULL;
   223         return NULL;
   225     }
   224     }
   226 
   225 
   227     if (strcmp(vendor_name, type->vendor_name) ||
   226     if (strcmp(vendor_name, type->vendor_name) ||
   228         strcmp(product_name, type->product_name)) {
   227         strcmp(product_name, type->product_name)) {
   229         printk(KERN_ERR "EtherCAT: Invalid slave type at position %i -"
   228         EC_ERR("Invalid slave type at position %i - Requested: \"%s %s\","
   230                " Requested: \"%s %s\", found: \"%s %s\".\n",
   229                " found: \"%s %s\".\n", slave->ring_position, vendor_name,
   231                slave->ring_position, vendor_name, product_name,
   230                product_name, type->vendor_name, type->product_name);
   232                type->vendor_name, type->product_name);
       
   233         return NULL;
   231         return NULL;
   234     }
   232     }
   235 
   233 
   236     field_idx = 0;
   234     field_idx = 0;
   237     for (i = 0; type->sync_managers[i]; i++) {
   235     for (i = 0; type->sync_managers[i]; i++) {
   249             }
   247             }
   250             field_offset += field->size;
   248             field_offset += field->size;
   251         }
   249         }
   252     }
   250     }
   253 
   251 
   254     printk(KERN_ERR "EtherCAT: Slave %i (\"%s %s\") has less than %i field(s)"
   252     EC_ERR("Slave %i (\"%s %s\") registration mismatch: Type %i, index %i,"
   255 	   " of type %i, starting at %i (only %i)!\n", slave->ring_position,
   253            " count %i.\n", slave->ring_position, vendor_name, product_name,
   256            vendor_name, product_name, field_count, field_type, field_index,
   254            field_type, field_index, field_count);
   257 	   field_idx);
       
   258     return NULL;
   255     return NULL;
   259 }
   256 }
   260 
   257 
   261 /*****************************************************************************/
   258 /*****************************************************************************/
   262 
   259 
   290 
   287 
   291         ec_frame_init_lrw(frame, master, domain->base_address + offset, size,
   288         ec_frame_init_lrw(frame, master, domain->base_address + offset, size,
   292                           domain->data + offset);
   289                           domain->data + offset);
   293 
   290 
   294         if (unlikely(ec_frame_send(frame) < 0)) {
   291         if (unlikely(ec_frame_send(frame) < 0)) {
   295             printk(KERN_ERR "EtherCAT: Could not send process data"
   292             EC_ERR("Could not send process data command!\n");
   296                    " command!\n");
       
   297             return -1;
   293             return -1;
   298         }
   294         }
   299 
   295 
   300         // Warten
   296         // Warten
   301         do {
   297         do {
   313             ec_output_lost_frames(master);
   309             ec_output_lost_frames(master);
   314             return -1;
   310             return -1;
   315         }
   311         }
   316 
   312 
   317         if (unlikely(ec_frame_receive(frame) < 0)) {
   313         if (unlikely(ec_frame_receive(frame) < 0)) {
   318             printk(KERN_ERR "EtherCAT: Receive error!\n");
   314             EC_ERR("Receive error!\n");
   319             return -1;
   315             return -1;
   320         }
   316         }
   321 
   317 
   322         if (unlikely(frame->state != ec_frame_received)) {
   318         if (unlikely(frame->state != ec_frame_received)) {
   323             printk(KERN_WARNING "EtherCAT: Process data command not"
   319             EC_WARN("Process data command not received!\n");
   324                    " received!\n");
       
   325             return -1;
   320             return -1;
   326         }
   321         }
   327 
   322 
   328         working_counter_sum += frame->working_counter;
   323         working_counter_sum += frame->working_counter;
   329 
   324 
   333         offset += size;
   328         offset += size;
   334     }
   329     }
   335 
   330 
   336     if (working_counter_sum != domain->response_count) {
   331     if (working_counter_sum != domain->response_count) {
   337         domain->response_count = working_counter_sum;
   332         domain->response_count = working_counter_sum;
   338         printk(KERN_INFO "EtherCAT: Domain %08X state change - %i slaves"
   333         EC_INFO("Domain %08X state change - %i slaves responding.\n",
   339                " responding.\n", (unsigned int) domain, working_counter_sum);
   334                 (u32) domain, working_counter_sum);
   340     }
   335     }
   341 
   336 
   342     return 0;
   337     return 0;
   343 }
   338 }
   344 
   339