master/domain.c
changeset 97 e6264685dd7b
parent 96 080b46eb6e2d
child 98 f564d0929292
equal deleted inserted replaced
96:080b46eb6e2d 97:e6264685dd7b
   176         kfree(field_reg);
   176         kfree(field_reg);
   177     }
   177     }
   178     INIT_LIST_HEAD(&domain->field_regs); // wichtig!
   178     INIT_LIST_HEAD(&domain->field_regs); // wichtig!
   179 
   179 
   180     return 0;
   180     return 0;
       
   181 }
       
   182 
       
   183 /*****************************************************************************/
       
   184 
       
   185 /**
       
   186    Gibt die Anzahl der antwortenden Slaves aus.
       
   187 */
       
   188 
       
   189 void ec_domain_response_count(ec_domain_t *domain, /**< Domäne */
       
   190                               unsigned int count /**< Neue Anzahl */
       
   191                               )
       
   192 {
       
   193     if (count != domain->response_count) {
       
   194         domain->response_count = count;
       
   195         EC_INFO("Domain %08X state change - %i slaves responding.\n",
       
   196                 (u32) domain, count);
       
   197     }
   181 }
   198 }
   182 
   199 
   183 /******************************************************************************
   200 /******************************************************************************
   184  *
   201  *
   185  * Echtzeitschnittstelle
   202  * Echtzeitschnittstelle
   279     frame = &domain->frame;
   296     frame = &domain->frame;
   280     working_counter_sum = 0;
   297     working_counter_sum = 0;
   281 
   298 
   282     ec_cyclic_output(master);
   299     ec_cyclic_output(master);
   283 
   300 
       
   301     if (unlikely(!master->device.link_state)) {
       
   302         ec_domain_response_count(domain, working_counter_sum);
       
   303         ec_device_call_isr(&master->device);
       
   304         return -1;
       
   305     }
       
   306 
   284     rdtscl(start_ticks); // Sendezeit nehmen
   307     rdtscl(start_ticks); // Sendezeit nehmen
   285     timeout_ticks = domain->timeout_us * cpu_khz / 1000;
   308     timeout_ticks = domain->timeout_us * cpu_khz / 1000;
   286 
   309 
   287     offset = 0;
   310     offset = 0;
   288     while (offset < domain->data_size)
   311     while (offset < domain->data_size)
   295 
   318 
   296         if (unlikely(ec_frame_send(frame) < 0)) {
   319         if (unlikely(ec_frame_send(frame) < 0)) {
   297             master->device.state = EC_DEVICE_STATE_READY;
   320             master->device.state = EC_DEVICE_STATE_READY;
   298             master->frames_lost++;
   321             master->frames_lost++;
   299             ec_cyclic_output(master);
   322             ec_cyclic_output(master);
   300 
   323             ec_domain_response_count(domain, working_counter_sum);
   301             // Falls Link down...
       
   302             ec_device_call_isr(&master->device);
       
   303 
       
   304             return -1;
   324             return -1;
   305         }
   325         }
   306 
   326 
   307         // Warten
   327         // Warten
   308         do {
   328         do {
   321             }
   341             }
   322             else {
   342             else {
   323                 master->device.state = EC_DEVICE_STATE_READY;
   343                 master->device.state = EC_DEVICE_STATE_READY;
   324                 master->frames_lost++;
   344                 master->frames_lost++;
   325                 ec_cyclic_output(master);
   345                 ec_cyclic_output(master);
       
   346                 ec_domain_response_count(domain, working_counter_sum);
   326                 return -1;
   347                 return -1;
   327             }
   348             }
   328         }
   349         }
   329 
   350 
   330         if (unlikely(ec_frame_receive(frame) < 0)) {
   351         if (unlikely(ec_frame_receive(frame) < 0)) {
   331             EC_ERR("Receiving process data failed!\n");
   352             ec_domain_response_count(domain, working_counter_sum);
   332             return -1;
   353             return -1;
   333         }
   354         }
   334 
   355 
   335         working_counter_sum += frame->working_counter;
   356         working_counter_sum += frame->working_counter;
   336 
   357 
   338         memcpy(domain->data + offset, frame->data, size);
   359         memcpy(domain->data + offset, frame->data, size);
   339 
   360 
   340         offset += size;
   361         offset += size;
   341     }
   362     }
   342 
   363 
   343     if (working_counter_sum != domain->response_count) {
   364     ec_domain_response_count(domain, working_counter_sum);
   344         domain->response_count = working_counter_sum;
       
   345         EC_INFO("Domain %08X state change - %i slaves responding.\n",
       
   346                 (u32) domain, working_counter_sum);
       
   347     }
       
   348 
   365 
   349     return 0;
   366     return 0;
   350 }
   367 }
   351 
   368 
   352 /*****************************************************************************/
   369 /*****************************************************************************/