evolution

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
avnisha
Date:
Wed Feb 05 04:33:33 2014 +0000
Parent:
0:f25a61b099e5
Commit message:
ok

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Feb 01 18:55:02 2014 +0000
+++ b/main.cpp	Wed Feb 05 04:33:33 2014 +0000
@@ -2,14 +2,31 @@
 
 
 /*
-led1: flash brief one per second, EVERY second.
-led2: On at t = 2 and off at t = 5
-led3: On at t = 3 and off at t = 6
+ * Based on 
+ *
+ * http://mbed.org/users/AjK/notebook/regarding-interrupts-use-and-blocking/?c=9228
+ */
+ 
+ 
+/*
+
+Specification:
+
+    led1: flash briefly once per second, EVERY second.
+    led2: On at t = 2 and off at t = 5
+    led3: On at t = 3 and off at t = 6
 */
 
-#define ONE
+#define SIX
 
 #ifdef ONE
+/*
+ * Basic processing looping  
+ *
+ * Good     - simple to write/debug
+ * Bad      - not so simple to add led2/led3 without some state machine logic and timer polling
+ */
+ 
  
 DigitalOut led1(LED1);
  
@@ -25,6 +42,14 @@
 #endif
 
 #ifdef TWO
+
+/*
+ * Event driven logic and loop together
+ *
+ * Good     - led2 is getting serviced by callback
+ * Bad      - led1 will missing some flashes due to wait() in callback
+ *
+ */
  
 Timeout to1;
 DigitalOut led1(LED1);
@@ -50,6 +75,13 @@
 
 #endif
 #ifdef THREE
+
+/*
+ * Good     - led1/led2/led3 all getting serviced
+ * Bad      - timing off on led3 since that callback has to wait for previous callback to finish 
+ *          - timing off on led1 due to both callbacks wait()
+ */
+ 
  
 Timeout to1;
 Timeout to2;
@@ -85,6 +117,11 @@
 
 #ifdef FOUR
 
+/*
+ * Good - Use gloabls to coordinate callback/main loop - no wait() in callback
+ * Bad  - led1 uses wait() making it less effective for polling other devices
+ */
+ 
  
 Timeout to1;
 Timeout to2;
@@ -110,9 +147,7 @@
         to1.detach();            
     } 
 }
-#endif
 
-#ifdef FIVE
  
 void cb2(void) { 
     to2triggered = true;    
@@ -157,7 +192,12 @@
 
 #endif
 
-#ifdef SIX
+#ifdef FIVE
+
+/*
+ * Good - all led's are callback interrupt driven
+ * Bad  - printf() in callback (interrupt context) bad idea
+ */
 
 #include "mbed.h"
  
@@ -177,6 +217,7 @@
         to1_led = 0;
     }
     // Reschedule a new event.
+    printf("cb1 callback\n");
     to1.detach();
     to1.attach(&cb1, 3);
 }
@@ -212,15 +253,17 @@
     to2.attach(&cb2, 3);
  
     while(1) {
-        // Calculate PI here as we have so much time :)
-        // It's like riding a bike with no hands, who's
-        // steering?! :)
+        // Calculate PI here as we have so much time 
     }
 }
 
 #endif
 
-#ifdef SEVEN
+#ifdef SIX
+
+/*
+ * Final version ... event driven for LED's
+*/
  
 Ticker  tled1on;
 Timeout tled1off;
@@ -238,7 +281,6 @@
         to1_led = 0;
     }
     
-    printf("hello\n");                      // BAD IDEA !!!!
     
     // Reschedule a new event.
     to1.detach();
@@ -277,8 +319,7 @@
  
     while(1) {
         // Calculate PI here as we have so much time :)
-        // It's like riding a bike with no hands, who's
-        // steering?! :)
+        printf("main loop\n");
     }
 }