homework 7

Dependencies:   mbed-rtos mbed C12832_lcd LM75B

Files at this revision

API Documentation at this revision

Comitter:
gatedClock
Date:
Thu Sep 12 23:11:09 2013 +0000
Parent:
121:c9d28cd59460
Commit message:
buggy totalTime, back away from this.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Sep 12 22:51:30 2013 +0000
+++ b/main.cpp	Thu Sep 12 23:11:09 2013 +0000
@@ -23,6 +23,9 @@
     'threadButtonStateManager' has forwarded the fact that the buttons were
     pressed.  I don't expect there to be any collision of writing the variables.
     
+    giRemainingTime.cControl is mutexed.
+    giRemainingTime.cBeepEnable can't be as its used in a timer.
+    
     
     
     
@@ -151,6 +154,7 @@
     Ticker       tickerBlinkCarousel;           // caroulsel LED blinker.
     
     Mutex        mutexControl;                  // for giRemainingTime.cControl.
+    Mutex        mutexTotalTime;                // for giRemainingTime.dTotalTime
 //-------prototypes-----------------------------//------------------------------
 
     void slowClock();                           // 1Hz or thereabouts.
@@ -301,7 +305,9 @@
         {
           dTotalTime = 0;
           queueSetRemainingTime.put((int *) dTotalTime,1);
+          mutexTotalTime.lock();
           giRemainingTime.dTotalTime = dTotalTime;
+          mutexTotalTime.unlock();
         }
       
  
@@ -329,7 +335,9 @@
           if (dTotalTime <   0) dTotalTime =   0;         
           
           queueSetRemainingTime.put((int *) dTotalTime,1);
+          mutexTotalTime.lock();
           giRemainingTime.dTotalTime = dTotalTime;
+          mutexTotalTime.unlock();
         }
 
              
@@ -380,7 +388,9 @@
 
             
                                                 // set global LCD data.
+            mutexTotalTime.lock();
             giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
+            mutexTotalTime.unlock();
             giLCD.dRemainingTime = 0;           // suppress remaining time display.
 
                                                 // remaining time loaded with total time.
@@ -392,8 +402,13 @@
                                                 // to FSM_COOK if the start button was
                                                 // pressed, the door is closed, and the
                                                 // remaining time is more than zero.
+                                                
+            int dTotalTime;
+            mutexTotalTime.lock();
+            dTotalTime = giRemainingTime.dTotalTime;
+            mutexTotalTime.unlock();
             
-            if ((dButtonStart == 1) && (dDoorOpen == 0) && (giRemainingTime.dTotalTime > 0)) dFSMstate = FSM_COOK;
+            if ((dButtonStart == 1) && (dDoorOpen == 0) && (dTotalTime > 0)) dFSMstate = FSM_COOK;
             break;
           }
 //---   
@@ -418,8 +433,10 @@
             }    
             
                                                 // update global LCD data.
+            mutexTotalTime.lock();
             giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
-            giLCD.dRemainingTime = giRemainingTime.dRemainingTime;
+            mutexTotalTime.unlock();
+            giLCD.dRemainingTime = dRemainingTime;
             
             
             
@@ -452,7 +469,9 @@
             }
             
                                                 // update LCD globals.
+            mutexTotalTime.lock();
             giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
+            mutexTotalTime.unlock();
             giLCD.dRemainingTime = giRemainingTime.dRemainingTime;
             
             
@@ -466,8 +485,12 @@
                                                 // continue if user hits start button,
                                                 // and the door is closed, and there
                                                 // is some remaining time.
+            int dTotalTime;
+            mutexTotalTime.lock();
+            dTotalTime = giRemainingTime.dTotalTime;
+            mutexTotalTime.unlock();
             
-            if ((dButtonStart == 1) && (dDoorOpen == 0) && (giRemainingTime.dTotalTime > 0)) dFSMstate = FSM_CONTINUE;
+            if ((dButtonStart == 1) && (dDoorOpen == 0) && (dTotalTime > 0)) dFSMstate = FSM_CONTINUE;
             else
             
                                                 // to idle if user hits stop button.
@@ -488,7 +511,9 @@
             }
             
                                                 // update LCD globals.
+            mutexTotalTime.lock();
             giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
+            mutexTotalTime.unlock();
             giLCD.dRemainingTime = giRemainingTime.dRemainingTime;
         
             
@@ -528,7 +553,9 @@
             }
            
                                                 // update LCD globals.
+            mutexTotalTime.lock();
             giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
+            mutexTotalTime.unlock();
             giLCD.dRemainingTime = giRemainingTime.dRemainingTime;
             
             mutexControl.lock();
@@ -714,7 +741,13 @@
         }
         
         if (dTempControl == TEMP_CALC)          // calculate synthetic temperature.
-        fCelsius = ((float) (giRemainingTime.dTotalTime - giRemainingTime.dRemainingTime) / 
+        
+        int dTotalTime;
+        mutexTotalTime.lock();
+        dTotalTime = giRemainingTime.dTotalTime;
+        mutexTotalTime.unlock();
+        
+        fCelsius = ((float) (dTotalTime - giRemainingTime.dRemainingTime) / 
                             (float) 6.0) + fLastMeasuredTemperature;
             
         giLCD.fCelsius = fCelsius;              // to global scope for LCD.
@@ -805,7 +838,10 @@
                                                 // dropping the right-of-decimal result,
                                                 // that occuring at the bottom of this
                                                 // routine.
+                                                
+          mutexTotalTime.lock();                                                
           dRemainingTime = (giRemainingTime.dTotalTime * GRANULARITY) + (GRANULARITY - 1);
+          mutexTotalTime.unlock();
           break;
         }