master/domain.c
changeset 332 e16093374dfd
parent 325 7833cf70c4f2
child 339 a3a4ee854bd8
equal deleted inserted replaced
331:17f58fe99511 332:e16093374dfd
   104     domain->master = master;
   104     domain->master = master;
   105     domain->index = index;
   105     domain->index = index;
   106     domain->data_size = 0;
   106     domain->data_size = 0;
   107     domain->base_address = 0;
   107     domain->base_address = 0;
   108     domain->response_count = 0xFFFFFFFF;
   108     domain->response_count = 0xFFFFFFFF;
       
   109     domain->t_last = 0;
       
   110     domain->working_counter_changes = 0;
   109 
   111 
   110     INIT_LIST_HEAD(&domain->data_regs);
   112     INIT_LIST_HEAD(&domain->data_regs);
   111     INIT_LIST_HEAD(&domain->datagrams);
   113     INIT_LIST_HEAD(&domain->datagrams);
   112 
   114 
   113     // init kobject and add it to the hierarchy
   115     // init kobject and add it to the hierarchy
   509 
   511 
   510 void ecrt_domain_process(ec_domain_t *domain /**< EtherCAT domain */)
   512 void ecrt_domain_process(ec_domain_t *domain /**< EtherCAT domain */)
   511 {
   513 {
   512     unsigned int working_counter_sum;
   514     unsigned int working_counter_sum;
   513     ec_datagram_t *datagram;
   515     ec_datagram_t *datagram;
       
   516     cycles_t t_now = get_cycles();
   514 
   517 
   515     working_counter_sum = 0;
   518     working_counter_sum = 0;
   516     list_for_each_entry(datagram, &domain->datagrams, list) {
   519     list_for_each_entry(datagram, &domain->datagrams, list) {
   517         if (datagram->state == EC_DATAGRAM_RECEIVED) {
   520         if (datagram->state == EC_DATAGRAM_RECEIVED) {
   518             working_counter_sum += datagram->working_counter;
   521             working_counter_sum += datagram->working_counter;
   519         }
   522         }
   520     }
   523     }
   521 
   524 
   522     if (working_counter_sum != domain->response_count) {
   525     if (working_counter_sum != domain->response_count) {
       
   526         domain->working_counter_changes++;
   523         domain->response_count = working_counter_sum;
   527         domain->response_count = working_counter_sum;
   524         EC_INFO("Domain %i working counter change: %i\n", domain->index,
   528     }
   525                 domain->response_count);
   529 
       
   530     if (domain->working_counter_changes &&
       
   531         (u32) (t_now - domain->t_last) / cpu_khz > 1000) {
       
   532         domain->t_last = t_now;
       
   533         if (domain->working_counter_changes == 1) {
       
   534             EC_INFO("Domain %i working counter change: %i\n", domain->index,
       
   535                     domain->response_count);
       
   536         }
       
   537         else {
       
   538             EC_INFO("Domain %i: %u WC changes. Current response count: %i\n",
       
   539                     domain->index, domain->working_counter_changes,
       
   540                     domain->response_count);
       
   541         }
       
   542         domain->working_counter_changes = 0;
   526     }
   543     }
   527 
   544 
   528     ec_domain_queue(domain);
   545     ec_domain_queue(domain);
   529 }
   546 }
   530 
   547