homework 7
Dependencies: mbed-rtos mbed C12832_lcd LM75B
Revision 71:4a5f256ecf7c, committed 2013-09-11
- Comitter:
- gatedClock
- Date:
- Wed Sep 11 23:00:14 2013 +0000
- Parent:
- 70:7c0743c28b11
- Child:
- 72:b4d0c0aa3c26
- Commit message:
- rewrite tickCookRemainingTime.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Sep 11 21:16:58 2013 +0000 +++ b/main.cpp Wed Sep 11 23:00:14 2013 +0000 @@ -6,6 +6,7 @@ ----description---------------------------------//------------------------------ gotchyas 1. using pc.printf inside a ticker routine will freeze the routine. + 2. using queues (get, put) will not work within a ticker routine. -----includes-----------------------------------//----------------------------*/ #include "mbed.h" // mbed class. #include "rtos.h" // rtos class. @@ -43,6 +44,11 @@ #define FSM_PAUSE 0x02 // cook-state state-machine. #define FSM_DONE 0x04 // cook-state state-machine. + #define RT_PRELOAD 0x01 // remaining-time preload. + #define RT_DECREMENT 0x02 // remaining-time decrement. + #define RT_PAUSE 0x03 // remaining-time don't change. + #define RT_CLEAR 0x04 // remaining-time set to zero. + #define DEBUG1 // debug preprocessor control. //--global_definitions--------------------------//------------------------------ struct tButtons // button ISR updates. @@ -55,10 +61,17 @@ char cDoorOpen; // door open. }; + struct tRemainingTime // remaining time related. + { + char cControl; // countdown control. + int dTotalTime; // initialize to this. + int dRemainingTime; // the countdown value. + }; + Queue<int, 1> queueModTotalTime; // message to modify total time. Queue<int, 1> queueUpdateFSM; // message to inform FSM. Queue<int, 1> queueUpdateRemainingTime; // message to update remaining time. - Queue<int, 16> queueSetRemainingTime; // tell countdown it's start time. + Queue<int, 1> queueSetRemainingTime; // tell countdown it's start time. Queue<int, 1> queueFSMnewState; // latest FSM state. //--global_variables----------------------------//------------------------------ char gcSignalWaitEnable; // 1 to wait on a signal. @@ -70,6 +83,8 @@ int gdCookTimeRemainingSec; // feed into LCD. tButtons gtButtons; // ISR button updates. + tRemainingTime giRemainingTime; // structure instance. + int gdDiagTotalTime; //--global_instances----------------------------//------------------------------ Serial pc(USBTX, USBRX); // PuTTY terminal communication. @@ -115,7 +130,7 @@ void threadButtonStateManager(void const *args); void threadTotalTimeControl(void const *args); void threadCookStateFSM(void const *args); - void cookRemainingTime(); // remaining time countdown. + void tickCookRemainingTime(); // remaining time countdown. void temperatureThread(void const *args); // temperature measurement. void LCDthread (void const *args); // LCD display thread. @@ -156,7 +171,7 @@ // count-down by one second. pc.printf("\n\r starting cookRemainingTime"); - tickerCookCountdown.attach(&cookRemainingTime,1); + tickerCookCountdown.attach(&tickCookRemainingTime,1); Thread thread_1(temperatureThread ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); @@ -562,49 +577,62 @@ } // thread loop. } // LCDthread. /*----------------------------------------------//----------------------------*/ - void cookRemainingTime(void) // cook-cycle countdown. + +/* + struct tRemainingTime // remaining time related. { - static int dFSMstate = FSM_IDLE; // mirror FSM state. - static int dTotalTime = 0; // local copy, total time. - static int dRemainingTime = 0; // remaining time. - osEvent queueEvent; // queue event. - osEvent queueEvent1; // queue event. - - // count-down while FSM is in cook mode. - if (dFSMstate == FSM_COOK) dRemainingTime--; + char cControl; // countdown control. + int dTotalTime; // initialize to this. + int dRemainingTime; // the countdown value. + } + +giRemainingTime. - // if done, including if stop button - // was presed. - if (dFSMstate == FSM_DONE) dRemainingTime = 0; - - // saturate remaining time. - if (dRemainingTime < 0) dRemainingTime = 0; - - gdCookTimeRemainingSec = dRemainingTime; // update global. + #define RT_PRELOAD 0x01 // remaining-time preload. + #define RT_DECREMENT 0x02 // remaining-time decrement. + #define RT_PAUSE 0x03 // remaining-time don't change. + #define RT_CLEAR 0x04 // remaining-time set to zero. + +*/ + + + + + + + void tickCookRemainingTime(void) // cook-cycle countdown. + { + static int dRemainingTime = 0; // remaining time in seconds. - // send to FSM. - queueUpdateRemainingTime.put((int *) dRemainingTime,1); - - queueEvent1 = queueSetRemainingTime.get(1); - if (queueEvent1.status == osEventMessage) // update state variable. - { - led0 = !led0; - dTotalTime = (int) queueEvent1.value.p; // interpret as integer, not pointer. - gdDiagTotalTime = dTotalTime; - } - - queueEvent = queueFSMnewState.get(1); // get latest FSM state. - if (queueEvent.status == osEventMessage) // if there is an FSM change. - { - led1 = !led1; - dFSMstate = (int) queueEvent.value.p; // mirror the FSM state. - - if (dFSMstate == FSM_COOK) // if FSM just entered cook mode. + switch (giRemainingTime.cControl) + { + case RT_PRELOAD : + { + + break; + } + case RT_DECREMENT : + { + + break; + } + + case RT_PAUSE : { - dRemainingTime = dTotalTime; // rewind countdown. - } // if FSM just entered cook mode. + + break; + } + + case RT_CLEAR : + { + + break; + } - } // get latest FSM state. + default : break; + } + + } // cookRemainingTime. /*----------------------------------------------//----------------------------*/