master/master.c
changeset 347 d201392748eb
parent 345 beb0a77d73c0
child 356 4bdc4f2e1a93
equal deleted inserted replaced
346:8f35508d90ad 347:d201392748eb
   240 
   240 
   241     master->datagram_index = 0;
   241     master->datagram_index = 0;
   242     master->debug_level = 0;
   242     master->debug_level = 0;
   243 
   243 
   244     master->stats.timeouts = 0;
   244     master->stats.timeouts = 0;
   245     master->stats.delayed = 0;
       
   246     master->stats.corrupted = 0;
   245     master->stats.corrupted = 0;
   247     master->stats.skipped = 0;
   246     master->stats.skipped = 0;
   248     master->stats.unmatched = 0;
   247     master->stats.unmatched = 0;
   249     master->stats.output_jiffies = 0;
   248     master->stats.output_jiffies = 0;
   250 
   249 
   420     size_t frame_size, data_size;
   419     size_t frame_size, data_size;
   421     uint8_t datagram_type, datagram_index;
   420     uint8_t datagram_type, datagram_index;
   422     unsigned int cmd_follows, matched;
   421     unsigned int cmd_follows, matched;
   423     const uint8_t *cur_data;
   422     const uint8_t *cur_data;
   424     ec_datagram_t *datagram;
   423     ec_datagram_t *datagram;
   425     cycles_t cycles_received, cycles_timeout;
       
   426 
       
   427     cycles_received = get_cycles();
       
   428     cycles_timeout = EC_IO_TIMEOUT * cpu_khz / 1000;
       
   429 
   424 
   430     if (unlikely(size < EC_FRAME_HEADER_SIZE)) {
   425     if (unlikely(size < EC_FRAME_HEADER_SIZE)) {
   431         master->stats.corrupted++;
   426         master->stats.corrupted++;
   432         ec_master_output_stats(master);
   427         ec_master_output_stats(master);
   433         return;
   428         return;
   490         cur_data += EC_DATAGRAM_FOOTER_SIZE;
   485         cur_data += EC_DATAGRAM_FOOTER_SIZE;
   491 
   486 
   492         // dequeue the received datagram
   487         // dequeue the received datagram
   493         datagram->state = EC_DATAGRAM_RECEIVED;
   488         datagram->state = EC_DATAGRAM_RECEIVED;
   494         list_del_init(&datagram->queue);
   489         list_del_init(&datagram->queue);
   495 
       
   496         // was the datagram reception delayed?
       
   497         if (cycles_received - datagram->cycles_sent > cycles_timeout) {
       
   498             master->stats.delayed++;
       
   499             ec_master_output_stats(master);
       
   500         }
       
   501     }
   490     }
   502 }
   491 }
   503 
   492 
   504 /*****************************************************************************/
   493 /*****************************************************************************/
   505 
   494 
   543         master->stats.output_jiffies = jiffies;
   532         master->stats.output_jiffies = jiffies;
   544 
   533 
   545         if (master->stats.timeouts) {
   534         if (master->stats.timeouts) {
   546             EC_WARN("%i datagrams TIMED OUT!\n", master->stats.timeouts);
   535             EC_WARN("%i datagrams TIMED OUT!\n", master->stats.timeouts);
   547             master->stats.timeouts = 0;
   536             master->stats.timeouts = 0;
   548         }
       
   549         if (master->stats.delayed) {
       
   550             EC_WARN("%i frame(s) DELAYED!\n", master->stats.delayed);
       
   551             master->stats.delayed = 0;
       
   552         }
   537         }
   553         if (master->stats.corrupted) {
   538         if (master->stats.corrupted) {
   554             EC_WARN("%i frame(s) CORRUPTED!\n", master->stats.corrupted);
   539             EC_WARN("%i frame(s) CORRUPTED!\n", master->stats.corrupted);
   555             master->stats.corrupted = 0;
   540             master->stats.corrupted = 0;
   556         }
   541         }