Introduced FORCE_OUTPUT_CORRUPTED. stable-1.5
authorFlorian Pose <fp@igh-essen.com>
Tue, 21 May 2013 13:18:24 +0200
branchstable-1.5
changeset 2530 f8b779c9794e
parent 2529 c7e1f2616a9d
child 2531 193443bcd7dc
Introduced FORCE_OUTPUT_CORRUPTED.
master/device.c
master/master.c
master/master.h
--- a/master/device.c	Mon May 13 20:21:19 2013 +0200
+++ b/master/device.c	Tue May 21 13:18:24 2013 +0200
@@ -663,7 +663,7 @@
     ec_device_debug_ring_append(device, RX, ec_data, ec_size);
 #endif
 
-    ec_master_receive_datagrams(device->master, ec_data, ec_size);
+    ec_master_receive_datagrams(device->master, device, ec_data, ec_size);
 }
 
 /*****************************************************************************/
--- a/master/master.c	Mon May 13 20:21:19 2013 +0200
+++ b/master/master.c	Tue May 21 13:18:24 2013 +0200
@@ -60,6 +60,10 @@
  */
 #define DEBUG_INJECT 0
 
+/** Always output corrupted frames.
+ */
+#define FORCE_OUTPUT_CORRUPTED 0
+
 #ifdef EC_HAVE_CYCLES
 
 /** Frame timeout in cycles.
@@ -1107,10 +1111,12 @@
  *
  * \return 0 in case of success, else < 0
  */
-void ec_master_receive_datagrams(ec_master_t *master, /**< EtherCAT master */
-                                 const uint8_t *frame_data, /**< frame data */
-                                 size_t size /**< size of the received data */
-                                 )
+void ec_master_receive_datagrams(
+        ec_master_t *master, /**< EtherCAT master */
+        ec_device_t *device, /**< EtherCAT device */
+        const uint8_t *frame_data, /**< frame data */
+        size_t size /**< size of the received data */
+        )
 {
     size_t frame_size, data_size;
     uint8_t datagram_type, datagram_index;
@@ -1119,10 +1125,10 @@
     ec_datagram_t *datagram;
 
     if (unlikely(size < EC_FRAME_HEADER_SIZE)) {
-        if (master->debug_level) {
+        if (master->debug_level || FORCE_OUTPUT_CORRUPTED) {
             EC_MASTER_DBG(master, 0, "Corrupted frame received"
-                    " (size %zu < %u byte):\n",
-                    size, EC_FRAME_HEADER_SIZE);
+                    " on %s (size %zu < %u byte):\n",
+                    device->dev->name, size, EC_FRAME_HEADER_SIZE);
             ec_print_data(frame_data, size);
         }
         master->stats.corrupted++;
@@ -1137,10 +1143,11 @@
     cur_data += EC_FRAME_HEADER_SIZE;
 
     if (unlikely(frame_size > size)) {
-        if (master->debug_level) {
+        if (master->debug_level || FORCE_OUTPUT_CORRUPTED) {
             EC_MASTER_DBG(master, 0, "Corrupted frame received"
-                    " (invalid frame size %zu for "
-                    "received size %zu):\n", frame_size, size);
+                    " on %s (invalid frame size %zu for "
+                    "received size %zu):\n", device->dev->name,
+                    frame_size, size);
             ec_print_data(frame_data, size);
         }
         master->stats.corrupted++;
@@ -1159,9 +1166,10 @@
 
         if (unlikely(cur_data - frame_data
                      + data_size + EC_DATAGRAM_FOOTER_SIZE > size)) {
-            if (master->debug_level) {
+            if (master->debug_level || FORCE_OUTPUT_CORRUPTED) {
                 EC_MASTER_DBG(master, 0, "Corrupted frame received"
-                        " (invalid data size %zu):\n", data_size);
+                        " on %s (invalid data size %zu):\n",
+                        device->dev->name, data_size);
                 ec_print_data(frame_data, size);
             }
             master->stats.corrupted++;
--- a/master/master.h	Mon May 13 20:21:19 2013 +0200
+++ b/master/master.h	Tue May 21 13:18:24 2013 +0200
@@ -343,7 +343,8 @@
 #endif
 
 // datagram IO
-void ec_master_receive_datagrams(ec_master_t *, const uint8_t *, size_t);
+void ec_master_receive_datagrams(ec_master_t *, ec_device_t *,
+        const uint8_t *, size_t);
 void ec_master_queue_datagram(ec_master_t *, ec_datagram_t *);
 void ec_master_queue_datagram_ext(ec_master_t *, ec_datagram_t *);