430 slave->sii_revision_number, slave->sii_serial_number); |
430 slave->sii_revision_number, slave->sii_serial_number); |
431 } |
431 } |
432 |
432 |
433 /*****************************************************************************/ |
433 /*****************************************************************************/ |
434 |
434 |
|
435 /** |
|
436 Gibt die Zählerstände der CRC-Fault-Counter aus und setzt diese zurück. |
|
437 |
|
438 \return 0 bei Erfolg, sonst < 0 |
|
439 */ |
|
440 |
|
441 int ec_slave_check_crc(ec_slave_t *slave /**< EtherCAT-Slave */) |
|
442 { |
|
443 ec_frame_t frame; |
|
444 uint8_t data[4]; |
|
445 uint16_t crc[2]; |
|
446 |
|
447 ec_frame_init_nprd(&frame, slave->master, slave->station_address, 0x0300, |
|
448 4); |
|
449 |
|
450 if (unlikely(ec_frame_send_receive(&frame))) { |
|
451 printk(KERN_WARNING "EtherCAT: Reading CRC fault counters failed" |
|
452 " on slave %i - Could not send command!\n", |
|
453 slave->ring_position); |
|
454 return -1; |
|
455 } |
|
456 |
|
457 if (unlikely(frame.working_counter != 1)) { |
|
458 printk(KERN_WARNING "EtherCAT: Reading CRC fault counters -" |
|
459 " Slave %i did not respond!\n", slave->ring_position); |
|
460 return -1; |
|
461 } |
|
462 |
|
463 crc[0] = frame.data[0] | (frame.data[1] << 8); |
|
464 crc[1] = frame.data[2] | (frame.data[3] << 8); |
|
465 |
|
466 // No CRC faults. |
|
467 if (!crc[0] && !crc[1]) return 0; |
|
468 |
|
469 printk(KERN_INFO "EtherCAT: CRC faults on slave %i. A: %i, B: %i\n", |
|
470 slave->ring_position, crc[0], crc[1]); |
|
471 |
|
472 // Reset CRC counters |
|
473 memset(data, 0x00, 4); |
|
474 ec_frame_init_npwr(&frame, slave->master, slave->station_address, 0x0300, |
|
475 4, data); |
|
476 |
|
477 if (unlikely(ec_frame_send_receive(&frame))) return -1; |
|
478 |
|
479 if (unlikely(frame.working_counter != 1)) { |
|
480 printk(KERN_ERR "EtherCAT: Resetting CRC fault counters - Slave" |
|
481 " %i did not respond!\n", slave->ring_position); |
|
482 return -1; |
|
483 } |
|
484 |
|
485 return 0; |
|
486 } |
|
487 |
|
488 /*****************************************************************************/ |
|
489 |
435 /* Emacs-Konfiguration |
490 /* Emacs-Konfiguration |
436 ;;; Local Variables: *** |
491 ;;; Local Variables: *** |
437 ;;; c-basic-offset:4 *** |
492 ;;; c-basic-offset:4 *** |
438 ;;; End: *** |
493 ;;; End: *** |
439 */ |
494 */ |