Sinnvolle Meldung verlorener Frames, Zustand antwortender Slaves.
This commit is contained in:
parent
3cce3f4278
commit
368936bb28
|
|
@ -27,6 +27,7 @@ void EtherCAT_domain_init(EtherCAT_domain_t *dom)
|
|||
dom->data = NULL;
|
||||
dom->data_size = 0;
|
||||
dom->logical_offset = 0;
|
||||
dom->response_count = 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ typedef struct EtherCAT_domain
|
|||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ void EtherCAT_master_init(EtherCAT_master_t *master)
|
|||
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 @@ int EtherCAT_simple_receive(EtherCAT_master_t *master,
|
|||
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 @@ int EtherCAT_simple_receive(EtherCAT_master_t *master,
|
|||
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 @@ int EtherCAT_check_slaves(EtherCAT_master_t *master,
|
|||
}
|
||||
}
|
||||
|
||||
// Calculate domain sizes
|
||||
// Calculate domain sizes and addresses
|
||||
|
||||
offset = 0;
|
||||
for (i = 0; i < master->domain_count; i++)
|
||||
{
|
||||
|
|
@ -547,7 +554,7 @@ int EtherCAT_check_slaves(EtherCAT_master_t *master,
|
|||
|
||||
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 @@ int EtherCAT_check_slaves(EtherCAT_master_t *master,
|
|||
|
||||
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 @@ int EtherCAT_check_slaves(EtherCAT_master_t *master,
|
|||
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 @@ int EtherCAT_process_data_cycle(EtherCAT_master_t *master, unsigned int domain,
|
|||
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 @@ int EtherCAT_process_data_cycle(EtherCAT_master_t *master, unsigned int domain,
|
|||
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 @@ int EtherCAT_process_data_cycle(EtherCAT_master_t *master, unsigned int domain,
|
|||
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 @@ void output_debug_data(const EtherCAT_master_t *master)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ struct EtherCAT_master
|
|||
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 @@ int EtherCAT_process_data_cycle(EtherCAT_master_t *, unsigned int,
|
|||
|
||||
// Private functions
|
||||
void output_debug_data(const EtherCAT_master_t *);
|
||||
void ecat_output_lost_frames(EtherCAT_master_t *);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -135,23 +135,22 @@ static void msr_controller_run(void)
|
|||
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 @@ static void msr_controller_run(void)
|
|||
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);
|
||||
rdtscl(t_bus_end);
|
||||
ecat_bus_time = TSC2US(t_bus_start, t_bus_end);
|
||||
|
||||
ecat_bus_time = TSC2US(t2, t3);
|
||||
if (debug_counter == 0) {
|
||||
ecat_master->debug_level = 0;
|
||||
}
|
||||
|
||||
// Daten lesen und skalieren
|
||||
#ifdef USE_MSR_LIB
|
||||
|
|
@ -198,16 +202,8 @@ static void msr_controller_run(void)
|
|||
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;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
|
|
|||
Loading…
Reference in New Issue