homework 7
Dependencies: mbed-rtos mbed C12832_lcd LM75B
Diff: main.cpp
- Revision:
- 121:c9d28cd59460
- Parent:
- 120:64a969984af2
- Child:
- 122:69e32460b543
- Child:
- 123:c8ea8f59455b
--- a/main.cpp Thu Sep 12 22:42:56 2013 +0000 +++ b/main.cpp Thu Sep 12 22:51:30 2013 +0000 @@ -49,7 +49,7 @@ #define THREAD_2_WAITmS 40 // LCD thread wait. #define THREAD_3_WAITmS 80 // thread 3 wait in mS. #define THREAD_4_WAITmS 1 // thread 4 wait in mS. - #define THREAD_5_WAITmS 100 // FSM thread wait. + #define THREAD_5_WAITmS 1 // FSM thread wait. #define HB_MODULO 1024 // heartbeat modulo divisor. #define MSG_INC_TIME 0x01 @@ -149,6 +149,8 @@ Ticker tickerBeep; // beeper ticker. Ticker tickerBlinkMagnetron; // magnetron LED blinker. Ticker tickerBlinkCarousel; // caroulsel LED blinker. + + Mutex mutexControl; // for giRemainingTime.cControl. //-------prototypes-----------------------------//------------------------------ void slowClock(); // 1Hz or thereabouts. @@ -382,7 +384,9 @@ giLCD.dRemainingTime = 0; // suppress remaining time display. // remaining time loaded with total time. - giRemainingTime.cControl = RT_PRELOAD; + mutexControl.lock(); + giRemainingTime.cControl = RT_PRELOAD; + mutexControl.unlock(); dFSMstateLast = dFSMstate; // determine next state. // to FSM_COOK if the start button was @@ -406,7 +410,9 @@ // temperature synthesizer is now // calculating the temperature, // user can no longer adjust total time. + mutexControl.lock(); giRemainingTime.cControl = RT_DECREMENT; + mutexControl.unlock(); queueTemperatureControl.put((int *) TEMP_CALC,1); queueSuppressTimeAdjust.put((int*) 1,1); } @@ -450,8 +456,9 @@ giLCD.dRemainingTime = giRemainingTime.dRemainingTime; - + mutexControl.lock(); giRemainingTime.cControl = RT_PAUSE;// pause remaining time countdown. + mutexControl.unlock(); dFSMstateLast = dFSMstate; // determine next state. @@ -486,7 +493,9 @@ // continue decrementing time. + mutexControl.lock(); giRemainingTime.cControl = RT_DECREMENT; + mutexControl.unlock(); dFSMstateLast = dFSMstate; // determine next state. @@ -521,7 +530,10 @@ // update LCD globals. giLCD.dTotalCookTime = giRemainingTime.dTotalTime; giLCD.dRemainingTime = giRemainingTime.dRemainingTime; + + mutexControl.lock(); giRemainingTime.cControl = RT_CLEAR;// clear remaining time. (needed?) + mutexControl.unlock(); dFSMstateLast = dFSMstate; // determine next state. @@ -775,10 +787,15 @@ { static int dRemainingTime = 0; // remaining time in seconds. int dMaximum; // MAXSECONDS * GRANULARITY. + char cControl; // local copy. dMaximum = MAXSECONDS * GRANULARITY; // precalculate. - switch (giRemainingTime.cControl) // control processing. + mutexControl.lock(); + cControl = giRemainingTime.cControl; + mutexControl.unlock(); + + switch (cControl) // control processing. { case RT_PRELOAD : // preload with total time.