homework 7
Dependencies: mbed-rtos mbed C12832_lcd LM75B
Diff: main.cpp
- Revision:
- 124:55c83dbeba2c
- Parent:
- 123:c8ea8f59455b
- Child:
- 125:6b3a86e3c883
--- a/main.cpp Thu Sep 12 23:28:18 2013 +0000 +++ b/main.cpp Thu Sep 12 23:52:30 2013 +0000 @@ -87,6 +87,18 @@ upon commands from the FSM. * LCD thread + magnetron timing + * LED2 is used for magnetron control (non-blinking). + - front-end control is used to turn it off: + - it is turned off in the 'stop' button ISR for safety. + - it is turned OFF in the door-toggle ISR for safety. + - this ensures immediate magnetron off. + + other timing + * the FSM thread has (if I counted right) six message get/puts worst + case in one loop, all with 1mS timeout, and the loop has a 1mS wait, + so it would be running on the order of once each 10mS. + this is the highest priority thread. -----includes-----------------------------------//----------------------------*/ @@ -190,10 +202,10 @@ Serial pc(USBTX, USBRX); // PuTTY terminal communication. LM75B temperature(p28,p27); // on-board thermometer. C12832_LCD lcd; // LCD object. - DigitalOut led0(LED4); // magnetron. - DigitalOut led1(LED3); - DigitalOut led2(LED2); - DigitalOut led3(LED1); + DigitalOut led0(LED4); // magnetron enunciator (not magnatron control) + DigitalOut led1(LED3); // carousel enunciator (not carousel control) + DigitalOut led2(LED2); // magnetron CONTROL. + DigitalOut led3(LED1); // carousel CONTROL. DigitalOut speaker(p26); // speaker device. InterruptIn iJoyStickUp (p15); // joystick up rising edge. @@ -274,11 +286,11 @@ tickerBlinkCarousel.attach_us(&tickerCarousel,250000); // kick-off threads. - Thread thread_1(temperatureThread ,NULL,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); + Thread thread_1(temperatureThread ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); Thread thread_2(LCDthread ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); - Thread thread_3(threadTotalTimeControl ,NULL,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); + Thread thread_3(threadTotalTimeControl ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); Thread thread_4(threadButtonStateManager,NULL,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); - Thread thread_5(threadCookStateFSM ,NULL,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); + Thread thread_5(threadCookStateFSM ,NULL,osPriorityHigh,DEFAULT_STACK_SIZE,NULL); while(1) Thread::wait(10000); // execute microwave controller. @@ -425,8 +437,10 @@ //--- case FSM_IDLE : // IDLE. { - giMagnetron.cMagnetron = 0; // highest priority. - giMagnetron.cCarousel = 0; // turn on carousel. + led2 = 0; // magnetron OFF. + led3 = 0; // carousel OFF. + giMagnetron.cMagnetron = 0; // ennunciator. + giMagnetron.cCarousel = 0; // ennunciator. if (dFSMstate != dFSMstateLast) // if just entered state. { @@ -461,8 +475,10 @@ //--- case FSM_COOK : // COOK. { - giMagnetron.cMagnetron = 1; // highest priority. - giMagnetron.cCarousel = 1; // turn on carousel. + led2 = 1; // magnetron ON. + led3 = 1; // carousel ON. + giMagnetron.cMagnetron = 1; // ennunciator. + giMagnetron.cCarousel = 1; // ennunciator. if (dFSMstate != dFSMstateLast) // if just entered state. { @@ -504,8 +520,10 @@ //--- case FSM_PAUSE : // PAUSE. { - giMagnetron.cMagnetron = 0; // highest priority. - giMagnetron.cCarousel = 0; // turn on carousel. + led2 = 0; // magnetron OFF. + led3 = 0; // carousel OFF. + giMagnetron.cMagnetron = 0; // ennunciator. + giMagnetron.cCarousel = 0; // ennunciator. if (dFSMstate != dFSMstateLast) // if just entered state. { @@ -540,8 +558,10 @@ //--- case FSM_CONTINUE : // CONTINUE. { - giMagnetron.cMagnetron = 1; // highest priority. - giMagnetron.cCarousel = 1; // turn on carousel. + led2 = 1; // magnetron ON. + led3 = 1; // carousel ON. + giMagnetron.cMagnetron = 1; // ennunciator. + giMagnetron.cCarousel = 1; // ennunciator. if (dFSMstate != dFSMstateLast) // if just entered state. { @@ -578,8 +598,10 @@ //--- case FSM_DONE : // DONE. { - giMagnetron.cMagnetron = 0; // highest priority. - giMagnetron.cCarousel = 0; // turn on carousel. + led2 = 0; // magnetron OFF. + led3 = 0; // carousel OFF. + giMagnetron.cMagnetron = 0; // ennunciator. + giMagnetron.cCarousel = 0; // ennunciator. if (dFSMstate != dFSMstateLast) // if just entered state. { @@ -657,7 +679,10 @@ /*----------------------------------------------//----------------------------*/ void initialization(void) // program initializations. { + led0 = 0; led1 = 0; + led2 = 0; + led3 = 0; giButtons.cDoorOpen = 0; // initialize with door closed. giRemainingTime.cBeepEnable =0; giMagnetron.cMagnetron = 0; @@ -711,7 +736,7 @@ { if (debounceTimer.read_ms() > DEBOUNCEmS) { - led0 = 0; // magnetron off. + led2 = 0; // magnetron off. giButtons.cBottomButton = 1; // detect bottom button. } debounceTimer.reset(); // begin debounce period. @@ -736,7 +761,7 @@ giButtons.cDoorOpen = MSG_OPEN; // magnetron off. - if (giButtons.cDoorOpen == MSG_OPEN) led0 = 0; + if (giButtons.cDoorOpen == MSG_OPEN) led2 = 0; giButtons.cCenterButton = 1; } @@ -913,6 +938,7 @@ } } /*----------------------------------------------//----------------------------*/ + // this is not magnetron control. void tickerMagnetron(void) // magnetron enunciator. { if (giMagnetron.cMagnetron) led0 = !led0; @@ -920,6 +946,7 @@ } /*----------------------------------------------//----------------------------*/ + // this is not carousel control. void tickerCarousel(void) // carousel enunciator. { if (giMagnetron.cCarousel) led1 = !led1;