1) lcd must wait 2) assign high priority to lcd 3) check malloc return code 4) printf clean

Dependencies:   C12832_lcd LM75B mbed-rtos mbed

Fork of MHey_HW6_1 by M Hey

Revision:
1:52291f3a1895
Parent:
0:337ae54a3bdb
--- a/HW6_1_IPC.cpp	Wed Mar 12 03:49:02 2014 +0000
+++ b/HW6_1_IPC.cpp	Wed Mar 12 20:51:16 2014 +0000
@@ -35,9 +35,17 @@
     {
 //        potVal_t *potValMessage = potVal_mpool.alloc();
         potValMessage = potVal_mpool.alloc();
+        if (potValMessage == NULL) {
+                pc.printf("****\n\r");
+                continue;
+        }
         *potValMessage = Pot1.read_u16(); // get Pot1 value
-        potVal_queue.put(potValMessage);  // put it in the queue
-        Thread::wait(1000);    // wait 1.0s
+        potVal_queue.put(potValMessage, 1000);  // put it in the queue
+        Thread::wait(2000);    
+        pc.printf("potVal_send_thread executing\n\r");
+        
+        
+        
     }
 }
 
@@ -50,10 +58,14 @@
     {
 //        float *tempValMessage = tempVal_mpool.alloc();
         tempValMessage = tempVal_mpool.alloc();
+        if (tempValMessage == NULL){
+                pc.printf("***\n\r");
+                continue;
+        }
         *tempValMessage = ((tmpSns.read()*9/5)+32);// get Temp update
-        tempVal_queue.put(tempValMessage);  // put value in the queue
-        Thread::wait(1000);  // wait 0.5s
-        pc.printf("\ntempVal_send_thread executing");
+        tempVal_queue.put(tempValMessage, 1000);  // put value in the queue
+        Thread::wait(2000); 
+        pc.printf("tempVal_send_thread executing\n\r");
     }
 }
 
@@ -69,47 +81,60 @@
     while (true) 
     {
      //   osEvent evt1 = potVal_queue.get();
-        evt1 = potVal_queue.get();
+        evt1 = potVal_queue.get(1000);                      // note timeout
         if (evt1.status == osEventMessage) 
         {
             potVal_t *pot1Val = (potVal_t*)evt1.value.p;
             pot1Val = (potVal_t*)evt1.value.p;
             lcd_mutex.lock(); // exclude other thread access to lcd 
             lcd.locate(0,0);
-            lcd.printf("\nPot1=%d", *pot1Val);
+            lcd.printf("Pot1=%d\n\r", *pot1Val);
             lcd_mutex.unlock();
             potVal_mpool.free(pot1Val);
         }
         
+        pc.printf("evt1 %d\n\r", evt1.status);
+        
       //  osEvent evt2 = tempVal_queue.get();
-        evt2 = tempVal_queue.get();
+        evt2 = tempVal_queue.get(1000);                 /// note timeout
         if (evt2.status == osEventMessage) 
-//        pc.printf("\nevt2.status == osEventMessage");
         {
-//            float *tempVal = (float*)evt2.value.p;
+//          float *tempVal = (float*)evt2.value.p;
             tempVal = (float*)evt2.value.p;
             lcd_mutex.lock(); // exclude other thread access to lcd 
-            lcd.locate(0,20);
-            lcd.printf("\nTemp=%3.1f", *tempVal);
+            lcd.locate(0,2);
+            lcd.printf("Temp=%3.1f\n\r", *tempVal);
             lcd_mutex.unlock();
             tempVal_mpool.free(tempVal);
         }
+        pc.printf("evt2 %d\n\r", evt2.status);
+        
+        Thread::wait(500);  
+        pc.printf("LCD  executing\n\r");                                   // note wait()
         
     }
 }
 
 int main() {
-    pc.printf("\nmain started...");
+    
+    osPriority pri;
+
+    
+    
+    pc.printf("main started...\n\r");
     lcd.cls();
     Thread thread1(potVal_send_thread);
     pc.printf("\nthree threads started...");
     Thread thread2(lcd_thread);
     Thread thread3(tempVal_send_thread);
-    pc.printf("\nthree threads started...");
+    pri = osPriorityHigh;
+    thread2.set_priority(pri);                           // make sure lcd thread is receiving data and flushing IPC 
+    pc.printf("three threads started...\n\r");
 
     while(true)
     {
         Thread::wait(1000);
+        pc.printf("main thread executing\n\r");
     }
 }