Included datagram queuing in critical section in idle task; added some
authorFlorian Pose <fp@igh-essen.com>
Thu, 09 Aug 2007 14:47:37 +0000
changeset 691 77b79a29e0e7
parent 690 5e231f6a3d2e
child 692 fe7cf37c33f1
Included datagram queuing in critical section in idle task; added some
debugging and comments.
master/master.c
--- a/master/master.c	Thu Aug 09 14:40:29 2007 +0000
+++ b/master/master.c	Thu Aug 09 14:47:37 2007 +0000
@@ -798,21 +798,21 @@
     while (!signal_pending(current)) {
         cycles_start = get_cycles();
 
-        if (ec_fsm_master_running(&master->fsm)) {
+        if (ec_fsm_master_running(&master->fsm)) { // datagram on the way
             // receive
             spin_lock_bh(&master->internal_lock);
             ecrt_master_receive(master);
             spin_unlock_bh(&master->internal_lock);
-        }
-
-        if (master->fsm_datagram.state == EC_DATAGRAM_SENT)
-            goto schedule;
+
+            if (master->fsm_datagram.state == EC_DATAGRAM_SENT)
+                goto schedule;
+        }
 
         // execute master state machine
-        if (ec_fsm_master_exec(&master->fsm)) {
+        if (ec_fsm_master_exec(&master->fsm)) { // datagram ready for sending
             // queue and send
+            spin_lock_bh(&master->internal_lock);
             ec_master_queue_datagram(master, &master->fsm_datagram);
-            spin_lock_bh(&master->internal_lock);
             ecrt_master_send(master);
             spin_unlock_bh(&master->internal_lock);
         }
@@ -1514,8 +1514,8 @@
             ec_master_output_stats(master);
 
             if (unlikely(master->debug_level > 0)) {
-                EC_DBG("TIMED OUT datagram index %02X waited %u us.\n",
-                        datagram->index,
+                EC_DBG("TIMED OUT datagram %08x, index %02X waited %u us.\n",
+                        (unsigned int) datagram, datagram->index,
                         (unsigned int) (master->main_device.cycles_poll
                             - datagram->cycles_sent) * 1000 / cpu_khz);
             }