Fixed spacing and comments.
authorFlorian Pose <fp@igh-essen.com>
Mon, 26 Jan 2009 16:23:09 +0000
changeset 1343 6628cd694cba
parent 1342 a72b9b370277
child 1344 e5756d4ed12c
Fixed spacing and comments.
master/fsm_foe.c
--- a/master/fsm_foe.c	Mon Jan 26 16:01:13 2009 +0000
+++ b/master/fsm_foe.c	Mon Jan 26 16:23:09 2009 +0000
@@ -52,37 +52,53 @@
 
 #define EC_MBOX_TYPE_FILEACCESS 0x04
 
-#define myDEBUG
-
-/*****************************************************************************/
-
-int		ec_foe_prepare_data_send( ec_fsm_foe_t * );
-int		ec_foe_prepare_wrq_send( ec_fsm_foe_t * );
-int		ec_foe_prepare_rrq_send( ec_fsm_foe_t * );
-int		ec_foe_prepare_send_ack( ec_fsm_foe_t * );
-
-void	ec_foe_set_tx_error( ec_fsm_foe_t *, uint32_t );
-void	ec_foe_set_rx_error( ec_fsm_foe_t *, uint32_t );
-
-void	ec_fsm_foe_write(ec_fsm_foe_t * );
-void	ec_fsm_foe_read(ec_fsm_foe_t * );
-void 	ec_fsm_foe_end( ec_fsm_foe_t * );
-void 	ec_fsm_foe_error( ec_fsm_foe_t * );
-
-void	ec_fsm_foe_state_wrq_sent( ec_fsm_foe_t * );
-void	ec_fsm_foe_state_rrq_sent( ec_fsm_foe_t * );
-
-void	ec_fsm_foe_state_ack_check( ec_fsm_foe_t * );
-void	ec_fsm_foe_state_ack_read( ec_fsm_foe_t * );
-
-void	ec_fsm_foe_state_data_sent( ec_fsm_foe_t * );
-
-void	ec_fsm_foe_state_data_check( ec_fsm_foe_t * );
-void	ec_fsm_foe_state_data_read ( ec_fsm_foe_t * );
-void	ec_fsm_foe_state_sent_ack( ec_fsm_foe_t * );
-
-void	ec_fsm_foe_write_start( ec_fsm_foe_t * );
-void	ec_fsm_foe_read_start(ec_fsm_foe_t * );
+#define EC_FOE_HEADER_SIZE 6
+// uint8_t  OpCode
+// uint8_t  reserved
+// uint32_t PacketNo, Password, ErrorCode
+
+//#define DEBUG_FOE
+
+/*****************************************************************************/
+
+enum {
+    EC_FOE_OPCODE_RRQ  = 1,
+    EC_FOE_OPCODE_WRQ  = 2,
+    EC_FOE_OPCODE_DATA = 3,
+    EC_FOE_OPCODE_ACK  = 4,
+    EC_FOE_OPCODE_ERR  = 5,
+    EC_FOE_OPCODE_BUSY = 6
+} ec_foe_opcode_t;
+
+/*****************************************************************************/
+
+int ec_foe_prepare_data_send(ec_fsm_foe_t *);
+int ec_foe_prepare_wrq_send(ec_fsm_foe_t *);
+int ec_foe_prepare_rrq_send(ec_fsm_foe_t *);
+int ec_foe_prepare_send_ack(ec_fsm_foe_t *);
+
+void ec_foe_set_tx_error(ec_fsm_foe_t *, uint32_t);
+void ec_foe_set_rx_error(ec_fsm_foe_t *, uint32_t);
+
+void ec_fsm_foe_write(ec_fsm_foe_t *);
+void ec_fsm_foe_read(ec_fsm_foe_t *);
+void ec_fsm_foe_end(ec_fsm_foe_t *);
+void ec_fsm_foe_error(ec_fsm_foe_t *);
+
+void ec_fsm_foe_state_wrq_sent(ec_fsm_foe_t *);
+void ec_fsm_foe_state_rrq_sent(ec_fsm_foe_t *);
+
+void ec_fsm_foe_state_ack_check(ec_fsm_foe_t *);
+void ec_fsm_foe_state_ack_read(ec_fsm_foe_t *);
+
+void ec_fsm_foe_state_data_sent(ec_fsm_foe_t *);
+
+void ec_fsm_foe_state_data_check(ec_fsm_foe_t *);
+void ec_fsm_foe_state_data_read(ec_fsm_foe_t *);
+void ec_fsm_foe_state_sent_ack(ec_fsm_foe_t *);
+
+void ec_fsm_foe_write_start(ec_fsm_foe_t *);
+void ec_fsm_foe_read_start(ec_fsm_foe_t *);
 
 /*****************************************************************************/
 
@@ -162,8 +178,8 @@
 
 void ec_fsm_foe_error(ec_fsm_foe_t *fsm /**< finite state machine */)
 {
-#ifdef	myDEBUG
-	printk("ec_fsm_foe_error()\n");
+#ifdef DEBUG_FOE
+    printk("ec_fsm_foe_error()\n");
 #endif
 }
 
@@ -175,35 +191,12 @@
 
 void ec_fsm_foe_end(ec_fsm_foe_t *fsm /**< finite state machine */)
 {
-#ifdef	myDEBUG
+#ifdef DEBUG_FOE
     printk("ec_fsm_foe_end\n");
 #endif
 }
 
 /*****************************************************************************/
-
-#define	EC_MBOX_HEADER_SIZE		6
-// uint16_t	Length
-// uint16_t	Address
-// uint8_t	reserved
-// uint8_t	Type:4
-// uint8_t	Counter:4
-
-#define	EC_FOE_HEADER_SIZE		6
-// uint8_t	OpCode
-// uint8_t	reserved
-// uint32_t	PacketNo, Password, ErrorCode
-
-enum {
-	EC_FOE_OPCODE_RRQ  = 1,
-	EC_FOE_OPCODE_WRQ  = 2,
-	EC_FOE_OPCODE_DATA = 3,
-	EC_FOE_OPCODE_ACK  = 4,
-	EC_FOE_OPCODE_ERR  = 5,
-	EC_FOE_OPCODE_BUSY = 6
-} ec_foe_opcode_t;
-
-/*****************************************************************************/
 /**
    Sends a file or the next fragment.
 */
@@ -224,14 +217,15 @@
     }
 
     if (!(data = ec_slave_mbox_prepare_send(fsm->slave, fsm->datagram,
-    		EC_MBOX_TYPE_FILEACCESS, current_size + EC_FOE_HEADER_SIZE)))
+                    EC_MBOX_TYPE_FILEACCESS,
+                    current_size + EC_FOE_HEADER_SIZE)))
         return -1;
 
-    EC_WRITE_U8 ( data, EC_FOE_OPCODE_DATA ); 		// OpCode = DataBlock req.
-    EC_WRITE_U32( data + 2, fsm->tx_packet_no );	// PacketNo, Password
-
-    memcpy(data + EC_FOE_HEADER_SIZE, fsm->tx_buffer + fsm->tx_buffer_offset, current_size);
-
+    EC_WRITE_U8 ( data, EC_FOE_OPCODE_DATA );    // OpCode = DataBlock req.
+    EC_WRITE_U32( data + 2, fsm->tx_packet_no ); // PacketNo, Password
+
+    memcpy(data + EC_FOE_HEADER_SIZE,
+            fsm->tx_buffer + fsm->tx_buffer_offset, current_size);
     fsm->tx_current_size = current_size;
 
     return 0;
@@ -249,12 +243,12 @@
     fsm->tx_buffer_offset = 0;
     fsm->tx_current_size = 0;
     fsm->tx_packet_no = 0;
-	fsm->tx_last_packet = 0;
+    fsm->tx_last_packet = 0;
 
     current_size = fsm->tx_filename_len;
 
     if (!(data = ec_slave_mbox_prepare_send(fsm->slave, fsm->datagram,
-    		EC_MBOX_TYPE_FILEACCESS, current_size + EC_FOE_HEADER_SIZE)))
+                    EC_MBOX_TYPE_FILEACCESS, current_size + EC_FOE_HEADER_SIZE)))
         return -1;
 
     EC_WRITE_U16( data, EC_FOE_OPCODE_WRQ); // fsm write request
@@ -267,28 +261,16 @@
 
 /*****************************************************************************/
 
-char		tx_buffer[0x1000];
 void ec_fsm_foe_write(ec_fsm_foe_t *fsm /**< finite state machine */)
 {
     fsm->tx_buffer = fsm->request->buffer;
     fsm->tx_buffer_size = fsm->request->data_size;
     fsm->tx_buffer_offset = 0;
 
-	fsm->tx_filename = fsm->request->file_name;
-	fsm->tx_filename_len = strlen(fsm->tx_filename);
-
-	fsm->state = ec_fsm_foe_write_start;
-
-#ifdef use_ext_buffer
-	{
-		int i;
-		fsm->tx_data = tx_buffer;
-		for (i=0 ; i<sizeof(tx_buffer) ; i++) {
-			tx_buffer[i] = (uint8_t)(i);
-		}
-		fsm->tx_data_len = sizeof(tx_buffer);
-	}
-#endif
+    fsm->tx_filename = fsm->request->file_name;
+    fsm->tx_filename_len = strlen(fsm->tx_filename);
+
+    fsm->state = ec_fsm_foe_write_start;
 }
 
 /*****************************************************************************/
@@ -303,9 +285,9 @@
     fsm->tx_buffer_offset = 0;
     fsm->tx_current_size = 0;
     fsm->tx_packet_no = 0;
-	fsm->tx_last_packet = 0;
-
-#ifdef	myDEBUG
+    fsm->tx_last_packet = 0;
+
+#ifdef DEBUG_FOE
     printk("ec_fsm_foe_write_start()\n");
 #endif
 
@@ -329,11 +311,12 @@
     ec_datagram_t *datagram = fsm->datagram;
     ec_slave_t *slave = fsm->slave;
 
-#ifdef	myDEBUG
-//	printk("ec_fsm_foe_ack_check()\n");
-#endif
+#ifdef DEBUG_FOE
+    printk("ec_fsm_foe_ack_check()\n");
+#endif
+
     if (datagram->state != EC_DATAGRAM_RECEIVED) {
-    	ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
+        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
         EC_ERR("Failed to receive FoE mailbox check datagram for slave %u"
                 " (datagram state %u).\n",
                slave->ring_position, datagram->state);
@@ -341,24 +324,24 @@
     }
 
     if (datagram->working_counter != 1) {
-    	// slave hat noch nichts in die Mailbox getan
+        // slave did not put anything in the mailbox yet
         ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
         EC_ERR("Reception of FoE mailbox check datagram failed on slave %u: ",
                slave->ring_position);
         ec_datagram_print_wc_error(datagram);
-	    return;
-	}
+        return;
+    }
 
     if (!ec_slave_mbox_check(datagram)) {
         unsigned long diff_ms =
             (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
         if (diff_ms >= EC_FSM_FOE_TIMEOUT) {
-        	ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
+            ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
             EC_ERR("Timeout while waiting for ack response "
                     "on slave %u.\n", slave->ring_position);
             return;
         }
-//        EC_ERR("WAIT!!!!!!!!!!!!!\n");
+
         ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
         fsm->retries = EC_FSM_RETRIES;
         return;
@@ -381,11 +364,12 @@
     uint8_t opCode;
     size_t rec_size;
 
-#ifdef	myDEBUG
-	printk("ec_fsm_foe_ack_read()\n");
-#endif
+#ifdef DEBUG_FOE
+    printk("ec_fsm_foe_ack_read()\n");
+#endif
+
     if (datagram->state != EC_DATAGRAM_RECEIVED) {
-    	ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
+        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
         EC_ERR("Failed to receive FoE ack response datagram for"
                " slave %u (datagram state %u).\n",
                slave->ring_position, datagram->state);
@@ -400,13 +384,14 @@
         return;
     }
 
-	if (!(data = ec_slave_mbox_fetch(fsm->slave, datagram, &mbox_prot, &rec_size))) {
-    	ec_foe_set_tx_error(fsm, FOE_PROT_ERROR);
+    if (!(data = ec_slave_mbox_fetch(fsm->slave, datagram,
+                    &mbox_prot, &rec_size))) {
+        ec_foe_set_tx_error(fsm, FOE_PROT_ERROR);
         return;
     }
 
     if (mbox_prot != EC_MBOX_TYPE_FILEACCESS) { // FoE
-    	ec_foe_set_tx_error(fsm, FOE_MBOX_PROT_ERROR);
+        ec_foe_set_tx_error(fsm, FOE_MBOX_PROT_ERROR);
         EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
         return;
     }
@@ -414,11 +399,11 @@
     opCode = EC_READ_U8(data);
 
     if (opCode == EC_FOE_OPCODE_BUSY) {
-    	// slave ist noch nicht bereit
+        // slave not ready
         if (ec_foe_prepare_data_send(fsm)) {
-        	ec_foe_set_tx_error(fsm, FOE_PROT_ERROR);
+            ec_foe_set_tx_error(fsm, FOE_PROT_ERROR);
             EC_ERR("Slave is busy.\n");
-        	return;
+            return;
         }
         fsm->state = ec_fsm_foe_state_data_sent;
         return;
@@ -429,18 +414,18 @@
         fsm->tx_buffer_offset += fsm->tx_current_size;
 
         if (fsm->tx_last_packet) {
-        	fsm->state = ec_fsm_foe_end;
-        	return;
+            fsm->state = ec_fsm_foe_end;
+            return;
         }
 
         if (ec_foe_prepare_data_send(fsm)) {
-        	ec_foe_set_tx_error(fsm, FOE_PROT_ERROR);
-	    	return;
-	    }
+            ec_foe_set_tx_error(fsm, FOE_PROT_ERROR);
+            return;
+        }
         fsm->state = ec_fsm_foe_state_data_sent;
-    	return;
-    }
-	ec_foe_set_tx_error(fsm, FOE_ACK_ERROR);
+        return;
+    }
+    ec_foe_set_tx_error(fsm, FOE_ACK_ERROR);
 }
 
 /*****************************************************************************/
@@ -454,11 +439,12 @@
     ec_datagram_t *datagram = fsm->datagram;
     ec_slave_t *slave = fsm->slave;
 
-#ifdef	myDEBUG
-	printk("ec_foe_state_sent_wrq()\n");
-#endif
+#ifdef DEBUG_FOE
+    printk("ec_foe_state_sent_wrq()\n");
+#endif
+
     if (datagram->state != EC_DATAGRAM_RECEIVED) {
-    	ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
+        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
         EC_ERR("Failed to send FoE WRQ for slave %u"
                 " (datagram state %u).\n",
                 slave->ring_position, datagram->state);
@@ -466,12 +452,12 @@
     }
 
     if (datagram->working_counter != 1) {
-    	// slave hat noch nichts in die Mailbox getan
+        // slave did not put anything in the mailbox yet
         ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
         EC_ERR("Reception of FoE WRQ failed on slave %u: ",
                 slave->ring_position);
         ec_datagram_print_wc_error(datagram);
-    	return;
+        return;
     }
 
     fsm->jiffies_start = datagram->jiffies_sent;
@@ -493,11 +479,12 @@
     ec_datagram_t *datagram = fsm->datagram;
     ec_slave_t *slave = fsm->slave;
 
-#ifdef	myDEBUG
-	printk("ec_fsm_foe_state_data_sent()\n");
-#endif
+#ifdef DEBUG_FOE
+    printk("ec_fsm_foe_state_data_sent()\n");
+#endif
+
     if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
-    	ec_foe_set_tx_error(fsm, FOE_RECEIVE_ERROR);
+        ec_foe_set_tx_error(fsm, FOE_RECEIVE_ERROR);
         EC_ERR("Failed to receive FoE ack response datagram for"
                " slave %u (datagram state %u).\n",
                slave->ring_position, datagram->state);
@@ -505,7 +492,7 @@
     }
 
     if (fsm->datagram->working_counter != 1) {
-	    ec_foe_set_tx_error(fsm, FOE_WC_ERROR);
+        ec_foe_set_tx_error(fsm, FOE_WC_ERROR);
         EC_ERR("Reception of FoE data send failed on slave %u: ",
                 slave->ring_position);
         ec_datagram_print_wc_error(datagram);
@@ -530,7 +517,7 @@
     current_size = fsm->rx_filename_len;
 
     if (!(data = ec_slave_mbox_prepare_send(fsm->slave, fsm->datagram,
-    		EC_MBOX_TYPE_FILEACCESS, current_size + EC_FOE_HEADER_SIZE)))
+                    EC_MBOX_TYPE_FILEACCESS, current_size + EC_FOE_HEADER_SIZE)))
         return -1;
 
     EC_WRITE_U16(data, EC_FOE_OPCODE_RRQ); // fsm read request
@@ -552,7 +539,7 @@
     uint8_t *data;
 
     if (!(data = ec_slave_mbox_prepare_send(foe->slave, foe->datagram,
-    		EC_MBOX_TYPE_FILEACCESS, EC_FOE_HEADER_SIZE)))
+                    EC_MBOX_TYPE_FILEACCESS, EC_FOE_HEADER_SIZE)))
         return -1;
 
     EC_WRITE_U16( data, EC_FOE_OPCODE_ACK);
@@ -572,11 +559,12 @@
     ec_datagram_t *datagram = fsm->datagram;
     ec_slave_t *slave = fsm->slave;
 
-#ifdef	myDEBUG
-	printk("ec_foe_state_rrq_sent()\n");
-#endif
+#ifdef DEBUG_FOE
+    printk("ec_foe_state_rrq_sent()\n");
+#endif
+
     if (datagram->state != EC_DATAGRAM_RECEIVED) {
-    	ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
+        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
         EC_ERR("Failed to send FoE RRQ for slave %u"
                 " (datagram state %u).\n",
                 slave->ring_position, datagram->state);
@@ -584,12 +572,12 @@
     }
 
     if (datagram->working_counter != 1) {
-    	// slave hat noch nichts in die Mailbox getan
+        // slave did not put anything in the mailbox yet
         ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
         EC_ERR("Reception of FoE RRQ failed on slave %u: ",
                 slave->ring_position);
         ec_datagram_print_wc_error(datagram);
-    	return;
+        return;
     }
 
     fsm->jiffies_start = datagram->jiffies_sent;
@@ -602,30 +590,21 @@
 
 /*****************************************************************************/
 
-#ifdef myDEBUG
-char		rx_buffer[0x8000];
-#endif
-
 void ec_fsm_foe_read(ec_fsm_foe_t *fsm /**< finite state machine */)
 {
-	fsm->state = ec_fsm_foe_read_start;
-	fsm->rx_filename = fsm->request->file_name;
-	fsm->rx_filename_len = strlen(fsm->rx_filename);
-
-	fsm->rx_buffer = fsm->request->buffer;
-	fsm->rx_buffer_size = fsm->request->buffer_size;
-
-#ifdef use_ext_buffer
-	fsm->rx_buffer = rx_buffer;
-	fsm->rx_buffer_size = sizeof(rx_buffer);
-#endif
+    fsm->state = ec_fsm_foe_read_start;
+    fsm->rx_filename = fsm->request->file_name;
+    fsm->rx_filename_len = strlen(fsm->rx_filename);
+
+    fsm->rx_buffer = fsm->request->buffer;
+    fsm->rx_buffer_size = fsm->request->buffer_size;
 }
 
 /*****************************************************************************/
 
 void ec_fsm_foe_read_start(ec_fsm_foe_t *fsm /**< finite state machine */)
 {
-	size_t current_size;
+    size_t current_size;
     ec_slave_t *slave = fsm->slave;
 
     fsm->rx_buffer_offset = 0;
@@ -636,11 +615,12 @@
 
     current_size = fsm->rx_filename_len;
 
-#ifdef	myDEBUG
-	printk("ec_fsm_foe_read_start()\n");
-#endif
+#ifdef DEBUG_FOE
+    printk("ec_fsm_foe_read_start()\n");
+#endif
+
     if (!(slave->sii.mailbox_protocols & EC_MBOX_FOE)) {
-    	ec_foe_set_tx_error(fsm, FOE_MBOX_PROT_ERROR);
+        ec_foe_set_tx_error(fsm, FOE_MBOX_PROT_ERROR);
         EC_ERR("Slave %u does not support FoE!\n", slave->ring_position);
         return;
     }
@@ -659,10 +639,11 @@
     ec_datagram_t *datagram = fsm->datagram;
     ec_slave_t *slave = fsm->slave;
 
-#ifdef	myDEBUG
-	printk("ec_fsm_foe_state_data_check()\n");
-#endif
-	if (datagram->state != EC_DATAGRAM_RECEIVED) {
+#ifdef DEBUG_FOE
+    printk("ec_fsm_foe_state_data_check()\n");
+#endif
+
+    if (datagram->state != EC_DATAGRAM_RECEIVED) {
         ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
         EC_ERR("Failed to send FoE DATA READ for slave %u"
                 " (datagram state %u).\n",
@@ -682,7 +663,7 @@
         unsigned long diff_ms =
             (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
         if (diff_ms >= EC_FSM_FOE_TIMEOUT) {
-        	ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
+            ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
             EC_ERR("Timeout while waiting for ack response "
                     "on slave %u.\n", slave->ring_position);
             return;
@@ -703,19 +684,20 @@
 
 /*****************************************************************************/
 
-void ec_fsm_foe_state_data_read ( ec_fsm_foe_t *fsm ) {
-    size_t 	rec_size;
+void ec_fsm_foe_state_data_read(ec_fsm_foe_t *fsm)
+{
+    size_t rec_size;
     uint8_t *data, opCode, packet_no, mbox_prot;
 
     ec_datagram_t *datagram = fsm->datagram;
     ec_slave_t *slave = fsm->slave;
 
-#ifdef	myDEBUG
-	printk("ec_fsm_foe_state_data_read()\n");
+#ifdef DEBUG_FOE
+    printk("ec_fsm_foe_state_data_read()\n");
 #endif
 
     if (datagram->state != EC_DATAGRAM_RECEIVED) {
-    	ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
+        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
         EC_ERR("Failed to receive FoE DATA READ datagram for"
                " slave %u (datagram state %u).\n",
                slave->ring_position, datagram->state);
@@ -730,12 +712,12 @@
         return;
     }
 
-	if (!(data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size))) {
-    	ec_foe_set_rx_error(fsm, FOE_MBOX_FETCH_ERROR);
-        return;
-    }
-
-	if (mbox_prot != EC_MBOX_TYPE_FILEACCESS) { // FoE
+    if (!(data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size))) {
+        ec_foe_set_rx_error(fsm, FOE_MBOX_FETCH_ERROR);
+        return;
+    }
+
+    if (mbox_prot != EC_MBOX_TYPE_FILEACCESS) { // FoE
         EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
         ec_foe_set_rx_error(fsm, FOE_PROT_ERROR);
         return;
@@ -752,7 +734,7 @@
 
     if (opCode == EC_FOE_OPCODE_ERR) {
         fsm->request->error_code = EC_READ_U32(data + 2);
-        EC_ERR("Received FoE Error Request (code %08x) on slave %u.\n",
+        EC_ERR("Received FoE Error Request (code 0x%08x) on slave %u.\n",
                 fsm->request->error_code, slave->ring_position);
         if (rec_size > 6) {
             uint8_t text[1024];
@@ -793,29 +775,31 @@
 
     if (fsm->rx_last_packet ||
             (slave->configured_rx_mailbox_size - EC_MBOX_HEADER_SIZE
-             - EC_FOE_HEADER_SIZE + fsm->rx_buffer_offset) <= fsm->rx_buffer_size) {
-        // either it was the last packet or a new packet will fit into the delivered buffer
-#ifdef	myDEBUG
-    	printk ("last_packet=true\n");
-#endif
-	    if (ec_foe_prepare_send_ack(fsm)) {
-	    	ec_foe_set_rx_error(fsm, FOE_RX_DATA_ACK_ERROR);
-	    	return;
-	    }
-
-	    fsm->state = ec_fsm_foe_state_sent_ack;
+             - EC_FOE_HEADER_SIZE + fsm->rx_buffer_offset)
+            <= fsm->rx_buffer_size) {
+        // either it was the last packet or a new packet will fit into the
+        // delivered buffer
+#ifdef DEBUG_FOE
+        printk ("last_packet=true\n");
+#endif
+        if (ec_foe_prepare_send_ack(fsm)) {
+            ec_foe_set_rx_error(fsm, FOE_RX_DATA_ACK_ERROR);
+            return;
+        }
+
+        fsm->state = ec_fsm_foe_state_sent_ack;
     }
     else {
-    	// no more data fits into the delivered buffer
-    	// ... wait for new read request
-    	printk ("ERROR: data doesn't fit in receive buffer\n");
-    	printk ("       rx_buffer_size  = %d\n", fsm->rx_buffer_size);
-    	printk ("       rx_buffer_offset= %d\n", fsm->rx_buffer_offset);
-    	printk ("       rec_size        = %d\n", rec_size);
-    	printk ("       rx_mailbox_size = %d\n", slave->configured_rx_mailbox_size);
-    	printk ("       rx_last_packet  = %d\n", fsm->rx_last_packet);
-//    	fsm->state = ec_fsm_state_wait_next_read;
-    	fsm->request->result = FOE_READY;
+        // no more data fits into the delivered buffer
+        // ... wait for new read request
+        printk ("ERROR: data doesn't fit in receive buffer\n");
+        printk ("       rx_buffer_size  = %d\n", fsm->rx_buffer_size);
+        printk ("       rx_buffer_offset= %d\n", fsm->rx_buffer_offset);
+        printk ("       rec_size        = %d\n", rec_size);
+        printk ("       rx_mailbox_size = %d\n",
+                slave->configured_rx_mailbox_size);
+        printk ("       rx_last_packet  = %d\n", fsm->rx_last_packet);
+        fsm->request->result = FOE_READY;
     }
 }
 
@@ -826,9 +810,10 @@
     ec_datagram_t *datagram = fsm->datagram;
     ec_slave_t *slave = fsm->slave;
 
-#ifdef	myDEBUG
-	printk("ec_foe_state_sent_ack()\n");
-#endif
+#ifdef DEBUG_FOE
+    printk("ec_foe_state_sent_ack()\n");
+#endif
+
     if (datagram->state != EC_DATAGRAM_RECEIVED) {
         ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
         EC_ERR("Failed to send FoE ACK for slave %u"
@@ -838,12 +823,12 @@
     }
 
     if (datagram->working_counter != 1) {
-    	// slave hat noch nichts in die Mailbox getan
+        // slave did not put anything into the mailbox yet
         ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
         EC_ERR("Reception of FoE ACK failed on slave %u: ",
                 slave->ring_position);
         ec_datagram_print_wc_error(datagram);
-    	return;
+        return;
     }
 
     fsm->jiffies_start = datagram->jiffies_sent;
@@ -851,12 +836,12 @@
     ec_slave_mbox_prepare_check(fsm->slave, datagram); // can not fail.
 
     if (fsm->rx_last_packet) {
-    	fsm->rx_expected_packet_no = 0;
-    	fsm->request->data_size = fsm->rx_buffer_offset;
-    	fsm->state = ec_fsm_foe_end;
+        fsm->rx_expected_packet_no = 0;
+        fsm->request->data_size = fsm->rx_buffer_offset;
+        fsm->state = ec_fsm_foe_end;
     }
     else {
-    	fsm->rx_expected_packet_no++;
+        fsm->rx_expected_packet_no++;
         fsm->retries = EC_FSM_RETRIES;
         fsm->state = ec_fsm_foe_state_data_check;
     }
@@ -866,18 +851,18 @@
 
 void ec_foe_set_tx_error(ec_fsm_foe_t *fsm, uint32_t errorcode)
 {
-	fsm->tx_errors++;
-	fsm->request->result = errorcode;
-	fsm->state = ec_fsm_foe_error;
+    fsm->tx_errors++;
+    fsm->request->result = errorcode;
+    fsm->state = ec_fsm_foe_error;
 }
 
 /*****************************************************************************/
 
 void ec_foe_set_rx_error(ec_fsm_foe_t *fsm, uint32_t errorcode)
 {
-	fsm->rx_errors++;
-	fsm->request->result = errorcode;
-	fsm->state = ec_fsm_foe_error;
-}
-
-/*****************************************************************************/
+    fsm->rx_errors++;
+    fsm->request->result = errorcode;
+    fsm->state = ec_fsm_foe_error;
+}
+
+/*****************************************************************************/