homework 7

Dependencies:   mbed-rtos mbed C12832_lcd LM75B

Revision:
120:64a969984af2
Parent:
119:e14b0f6e97cb
Child:
121:c9d28cd59460
--- a/main.cpp	Thu Sep 12 22:13:51 2013 +0000
+++ b/main.cpp	Thu Sep 12 22:42:56 2013 +0000
@@ -13,6 +13,19 @@
     countdown timer needs to be sync'd to start button press.
     this could not be done, use granularity setting instead.
     
+    global variables considerations (mutex)
+    the global variables associated with joystick button presses are 
+    in the structure 'tButtons' (instance 'giButtons').  ISRs store that a
+    button has been pressed in this struct, and since mutex can not be called
+    within an interrupt, no mutex is used on these buttons.
+    only the ISRs are 'authorized' to set those variables, and the bottom-half
+    of the ISRs, 'threadButtonStateManager', is authorized to clear them once
+    'threadButtonStateManager' has forwarded the fact that the buttons were
+    pressed.  I don't expect there to be any collision of writing the variables.
+    
+    
+    
+    
     
 -----includes-----------------------------------//----------------------------*/
     #include "mbed.h"                           // mbed class.
@@ -82,10 +95,14 @@
     {
       char cControl;                            // countdown control.
       char cBeepEnable;                         // beep control.
+      int  dTotalTime;                          // initialize to this.
+      int  dRemainingTime;                      // the countdown value.
+    };
+    
+    struct tMagnetron                           // magnetron control.
+    {
       char cMagnetron;                          // magnetron blink control.
       char cCarousel;                           // carousel  blink control.
-      int  dTotalTime;                          // initialize to this.
-      int  dRemainingTime;                      // the countdown value.
     };
     
     struct tLCD                                 // LCD related.
@@ -105,6 +122,7 @@
 //--global_variables----------------------------//------------------------------ 
     tButtons       giButtons;                   // ISR button updates.
     tRemainingTime giRemainingTime;             // structure instance.
+    tMagnetron     giMagnetron;                 // structure instance.
     tLCD           giLCD;                       // structure instance.
 //--global_instances----------------------------//------------------------------ 
     Serial      pc(USBTX, USBRX);               // PuTTY terminal communication.
@@ -223,14 +241,14 @@
       if (giButtons.cLeftButton)                // total time increment button.
       {
         dMessage = MSG_INC_TIME;                // set message.
-        queueModTotalTime.put((int *) dMessage,1);// pretend it's a pointer.
+        queueModTotalTime.put((int *) dMessage,1);
         giButtons.cLeftButton = 0;              // clear the button state.
       }
 
       if (giButtons.cRightButton)               // total time decrement button.
       {
         dMessage = MSG_DEC_TIME;                // set message.
-        queueModTotalTime.put((int *) dMessage,1);// pretend it's a pointer.
+        queueModTotalTime.put((int *) dMessage,1);
         giButtons.cRightButton = 0;             // clear the button state.
       }
    
@@ -239,21 +257,21 @@
       if (giButtons.cTopButton)                 // start-cook button.             
       {
         dMessage = MSG_START;                   // set message.
-        queueUpdateFSM.put((int *) dMessage,1);   // pretend it's a pointer.
+        queueUpdateFSM.put((int *) dMessage,1);
         giButtons.cTopButton = 0;               // clear the button state.
       }
      
       if (giButtons.cBottomButton)              // stop-cook button.
       {
         dMessage = MSG_STOP;                    // set message.
-        queueUpdateFSM.put((int *) dMessage,1);   // pretend it's a pointer.
+        queueUpdateFSM.put((int *) dMessage,1); 
         giButtons.cBottomButton = 0;            // clear the button state.
       }
   
       if (giButtons.cCenterButton)              // door-state-toggle.
       {
         dMessage = giButtons.cDoorOpen;         // determined in ISR.
-        queueUpdateFSM.put((int *) dMessage,1);   // pretend it's a pointer.
+        queueUpdateFSM.put((int *) dMessage,1); 
         giButtons.cCenterButton = 0;            // clear the button state.      
       }
 //---     
@@ -343,8 +361,8 @@
 //---        
           case  FSM_IDLE :                      // IDLE.
           {
-            giRemainingTime.cMagnetron = 0;     // highest priority.
-            giRemainingTime.cCarousel  = 0;     // turn on carousel.
+            giMagnetron.cMagnetron = 0;     // highest priority.
+            giMagnetron.cCarousel  = 0;     // turn on carousel.
           
             if (dFSMstate != dFSMstateLast)     // if just entered state.
             {     
@@ -377,8 +395,8 @@
 //---   
            case  FSM_COOK :                     // COOK.
           {
-            giRemainingTime.cMagnetron = 1;     // highest priority.
-            giRemainingTime.cCarousel  = 1;     // turn on carousel.
+            giMagnetron.cMagnetron = 1;     // highest priority.
+            giMagnetron.cCarousel  = 1;     // turn on carousel.
             
             if (dFSMstate != dFSMstateLast)     // if just entered state.
             { 
@@ -418,8 +436,8 @@
 //---   
           case  FSM_PAUSE :                     // PAUSE.
           {
-            giRemainingTime.cMagnetron = 0;     // highest priority.
-            giRemainingTime.cCarousel  = 0;     // turn on carousel.
+            giMagnetron.cMagnetron = 0;     // highest priority.
+            giMagnetron.cCarousel  = 0;     // turn on carousel.
               
             if (dFSMstate != dFSMstateLast)     // if just entered state.
             { 
@@ -453,8 +471,8 @@
 //---             
           case  FSM_CONTINUE :                  // CONTINUE.
           {
-            giRemainingTime.cMagnetron = 1;     // highest priority.
-            giRemainingTime.cCarousel  = 1;     // turn on carousel.
+            giMagnetron.cMagnetron = 1;     // highest priority.
+            giMagnetron.cCarousel  = 1;     // turn on carousel.
               
             if (dFSMstate != dFSMstateLast)     // if just entered state.
             { 
@@ -489,8 +507,8 @@
 //---             
           case  FSM_DONE :                      // DONE.
           {
-            giRemainingTime.cMagnetron = 0;     // highest priority.
-            giRemainingTime.cCarousel  = 0;     // turn on carousel.          
+            giMagnetron.cMagnetron = 0;     // highest priority.
+            giMagnetron.cCarousel  = 0;     // turn on carousel.          
           
             if (dFSMstate != dFSMstateLast)     // if just entered state.
             { 
@@ -568,8 +586,8 @@
       led1 = 0;
       giButtons.cDoorOpen = 0;                  // initialize with door closed.
       giRemainingTime.cBeepEnable =0;
-      giRemainingTime.cMagnetron = 0;
-      giRemainingTime.cCarousel = 0;
+      giMagnetron.cMagnetron = 0;
+      giMagnetron.cCarousel = 0;
     }
 /*----------------------------------------------//----------------------------*/
     void ISRleftButtonRising(void)              // cooktime plus 60s.
@@ -818,14 +836,14 @@
 /*----------------------------------------------//----------------------------*/
     void tickerMagnetron(void)                  // magnetron enunciator.
     {
-      if (giRemainingTime.cMagnetron) led0 = !led0;
+      if (giMagnetron.cMagnetron) led0 = !led0;
       else led0 = 0;
     }
 
 /*----------------------------------------------//----------------------------*/
     void tickerCarousel(void)                   // carousel enunciator.
     {
-      if (giRemainingTime.cCarousel) led1 = !led1;
+      if (giMagnetron.cCarousel) led1 = !led1;
       else led1 = 0;
     }
 /*----------------------------------------------//----------------------------*/