# HG changeset patch # User Florian Pose # Date 1136563266 0 # Node ID 7e75772ea28c663cc07a01812ce4ec11c19d7b27 # Parent ad5f969f263bf52d3fc8939f8be44179bddf8b1b Sinnvolle Meldung verlorener Frames, Zustand antwortender Slaves. diff -r ad5f969f263b -r 7e75772ea28c drivers/ec_domain.c --- a/drivers/ec_domain.c Fri Jan 06 13:20:29 2006 +0000 +++ b/drivers/ec_domain.c Fri Jan 06 16:01:06 2006 +0000 @@ -27,6 +27,7 @@ dom->data = NULL; dom->data_size = 0; dom->logical_offset = 0; + dom->response_count = 0; } /*****************************************************************************/ diff -r ad5f969f263b -r 7e75772ea28c drivers/ec_domain.h --- a/drivers/ec_domain.h Fri Jan 06 13:20:29 2006 +0000 +++ b/drivers/ec_domain.h Fri Jan 06 16:01:06 2006 +0000 @@ -32,6 +32,7 @@ unsigned char *data; /**< Zeiger auf Speicher mit Prozessdaten */ unsigned int data_size; /**< Größe des Prozessdatenspeichers */ unsigned int logical_offset; /**< Logische Basisaddresse */ + unsigned int response_count; /**< Anzahl antwortender Slaves */ } EtherCAT_domain_t; diff -r ad5f969f263b -r 7e75772ea28c drivers/ec_master.c --- a/drivers/ec_master.c Fri Jan 06 13:20:29 2006 +0000 +++ b/drivers/ec_master.c Fri Jan 06 16:01:06 2006 +0000 @@ -34,6 +34,8 @@ master->domain_count = 0; master->debug_level = 0; master->bus_time = 0; + master->frames_lost = 0; + master->t_lost_output = 0; } /*****************************************************************************/ @@ -289,8 +291,8 @@ master->rx_data_length = (unsigned int) ret; if (unlikely(master->rx_data_length < 2)) { - printk(KERN_ERR "EtherCAT: Received frame with incomplete" - " EtherCAT header!\n"); + printk(KERN_ERR "EtherCAT: Received frame with incomplete EtherCAT" + " header!\n"); output_debug_data(master); return -1; } @@ -332,6 +334,10 @@ cmd->working_counter = ((master->rx_data[length + 2 + 10] & 0xFF) | ((master->rx_data[length + 2 + 11] & 0xFF) << 8)); + + if (unlikely(master->debug_level > 1)) { + output_debug_data(master); + } } else { @@ -539,7 +545,8 @@ } } - // Calculate domain sizes + // Calculate domain sizes and addresses + offset = 0; for (i = 0; i < master->domain_count; i++) { @@ -547,7 +554,7 @@ dom->logical_offset = offset; - // For every slave in the list + // Calculate size of the domain size = 0; for (j = 0; j < slave_count; j++) { if (slaves[j].domain == dom->number) { @@ -563,16 +570,16 @@ if (!(dom->data = (unsigned char *) kmalloc(sizeof(unsigned char) * size, GFP_KERNEL))) { - printk(KERN_ERR "EtherCAT: Could not allocate" - " %i bytes of domain data.\n", size); + printk(KERN_ERR "EtherCAT: Could not allocate %i bytes of domain" + " data.\n", size); return -1; } dom->data_size = size; memset(dom->data, 0x00, size); - printk(KERN_INFO "EtherCAT: Domain %i: %i Bytes of process data.\n", - dom->number, size); + printk(KERN_INFO "EtherCAT: Domain %i: Offset 0x%04X, %i Bytes of" + " process data.\n", dom->number, dom->logical_offset, size); // Set logical addresses and data pointers of domain slaves size = 0; @@ -581,6 +588,10 @@ slaves[j].process_data = dom->data + size; slaves[j].logical_address = dom->logical_offset + size; size += slaves[j].desc->process_data_size; + + printk(KERN_INFO "EtherCAT: Slave %i: Logical Address 0x%04X, %i" + " bytes of process data.\n", j, slaves[j].logical_address, + slaves[j].desc->process_data_size); } } @@ -1004,6 +1015,9 @@ EtherCAT_domain_t *dom; unsigned long start_ticks, end_ticks, timeout_ticks; + ecat_output_lost_frames(master); // Evtl. verlorene Frames ausgeben + + // Domäne bestimmen dom = NULL; for (i = 0; i < master->domain_count; i++) { if (master->domains[i].number == domain) { @@ -1041,7 +1055,9 @@ master->bus_time = (end_ticks - start_ticks) * 1000 / cpu_khz; if (unlikely(end_ticks - start_ticks >= timeout_ticks)) { - printk(KERN_ERR "EtherCAT: Timeout while receiving process data!\n"); + master->dev->state = ECAT_DS_READY; + master->frames_lost++; + ecat_output_lost_frames(master); return -1; } @@ -1055,6 +1071,12 @@ return -1; } + if (dom->command.working_counter != dom->response_count) { + dom->response_count = dom->command.working_counter; + printk(KERN_INFO "EtherCAT: Domain %i State change - %i slaves" + " responding.\n", dom->number, dom->response_count); + } + // Daten vom Kommando in den Prozessdatenspeicher kopieren memcpy(dom->data, dom->command.data, dom->data_size); @@ -1098,6 +1120,28 @@ /*****************************************************************************/ +/** + Gibt von Zeit zu Zeit die Anzahl verlorener Frames aus. + + @param master EtherCAT-Master +*/ + +void ecat_output_lost_frames(EtherCAT_master_t *master) +{ + unsigned long int t; + + if (master->frames_lost) { + rdtscl(t); + if ((t - master->t_lost_output) / cpu_khz > 1000) { + printk(KERN_ERR "EtherCAT: %u frame(s) LOST!\n", master->frames_lost); + master->frames_lost = 0; + master->t_lost_output = t; + } + } +} + +/*****************************************************************************/ + EXPORT_SYMBOL(EtherCAT_master_init); EXPORT_SYMBOL(EtherCAT_master_clear); EXPORT_SYMBOL(EtherCAT_master_open); diff -r ad5f969f263b -r 7e75772ea28c drivers/ec_master.h --- a/drivers/ec_master.h Fri Jan 06 13:20:29 2006 +0000 +++ b/drivers/ec_master.h Fri Jan 06 16:01:06 2006 +0000 @@ -40,6 +40,9 @@ unsigned int domain_count; int debug_level; /**< Debug-Level im Master-Code */ unsigned int bus_time; /**< Letzte Bus-Zeit in Mikrosekunden */ + unsigned int frames_lost; /**< Anzahl verlorene Frames */ + unsigned long t_lost_output; /*<< Timer-Ticks bei der letzten Ausgabe von + verlorenen Frames */ }; /*****************************************************************************/ @@ -73,6 +76,7 @@ // Private functions void output_debug_data(const EtherCAT_master_t *); +void ecat_output_lost_frames(EtherCAT_master_t *); /*****************************************************************************/ diff -r ad5f969f263b -r 7e75772ea28c rt/msr_module.c --- a/rt/msr_module.c Fri Jan 06 13:20:29 2006 +0000 +++ b/rt/msr_module.c Fri Jan 06 16:01:06 2006 +0000 @@ -135,23 +135,22 @@ static int ms = 0; static int cnt = 0; static int firstrun = 1; + static unsigned int debug_counter = 0; static int klemme = 0; static int kanal = 0; static int up_down = 0; int wrap = 0; - static unsigned int debug_counter = 0; - unsigned long t1, t2, t3; - unsigned int bustime1, bustime2; - static unsigned long lt = 0; - - rdtscl(t1); + unsigned long t_bus_start, t_bus_end; // Prozessdaten lesen msr_jitter_run(MSR_ABTASTFREQUENZ); - if (firstrun) klemme = next2004(&wrap); + if (firstrun) { + klemme = next2004(&wrap); + firstrun = 0; + } ms++; ms %= 1000; @@ -176,21 +175,26 @@ EtherCAT_write_value(&ecat_slaves[klemme], kanal, up_down); } + if (debug_counter == 0) { + ecat_master->debug_level = 0; + } + // Prozessdaten schreiben - rdtscl(t2); + rdtscl(t_bus_start); if (EtherCAT_process_data_cycle(ecat_master, 0, 40) < 0) ecat_timeouts++; - bustime1 = ecat_master->bus_time; if (EtherCAT_process_data_cycle(ecat_master, 1, 40) < 0) ecat_timeouts++; - bustime2 = ecat_master->bus_time; - - rdtscl(t3); - - ecat_bus_time = TSC2US(t2, t3); + + rdtscl(t_bus_end); + ecat_bus_time = TSC2US(t_bus_start, t_bus_end); + + if (debug_counter == 0) { + ecat_master->debug_level = 0; + } // Daten lesen und skalieren #ifdef USE_MSR_LIB @@ -198,16 +202,8 @@ dig1 = EtherCAT_read_value(&ecat_slaves[2], 0); #endif - if (debug_counter == MSR_ABTASTFREQUENZ) { - printk(KERN_DEBUG "%lu: %luŽµs + %uŽµs + %uŽµs = %luŽµs\n", TSC2US(lt, t1), - TSC2US(t1, t2), bustime1, bustime2, TSC2US(t1, t3)); - debug_counter = 0; - } - - lt = t1; - - firstrun = 0; debug_counter++; + if (debug_counter >= MSR_ABTASTFREQUENZ * 5) debug_counter = 0; } /******************************************************************************