first compiled version
Dependencies: mbed-rtos mbed C12832_lcd LM75B
Revision 9:f40c7c08d1c2, committed 2014-03-11
- Comitter:
- nleoni
- Date:
- Tue Mar 11 06:39:37 2014 +0000
- Parent:
- 8:4fcba095bdf0
- Commit message:
- Added 6 test cases covering regular and extreme uses of the program
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4fcba095bdf0 -r f40c7c08d1c2 main.cpp --- a/main.cpp Tue Mar 11 05:40:23 2014 +0000 +++ b/main.cpp Tue Mar 11 06:39:37 2014 +0000 @@ -1,18 +1,38 @@ //LAB 6: RTOS AND IPC //WRITTEN BY: ROBERT HARRELL AND NAPOLEON LEONI +//IPC: INTER PROGRAMMER COMMUNICATION.... +//This program tests IPC for the mbed RTOS +//It features an LCD thread that updates the Pot value, +//Temperature and the fortune cookie using IPC methods with timeout +//The POT thread reads the POT value in a polling loop every 10 seconds +//and uses the IPC queue to send the data to the LCD thread +//The TEMP thread reads the temp value in a polling loop every 60 seconds +//and uses the IPC queue to send the data to the LCD thread +//The fortune cookie thread reads a fortune from a user using getc on a polling loop +//every 100 ms and sends the fortune cookie via an IPC memory pool to the LCD thread +//The TOD thread updates the time of date once a minute, it uses a mutex to share the LCD +//with the LCD thread. -//IPC: INTER PROGRAMMER COMMUNICATION.... -//Rob I updated the LCD update and read pot thread and they are working -//One key issues was adding timeout for the put and get methods of the queue -//Maybe you can work on the TOD thread and MUTEX (you'll need to add it to the -//LCD thread and I will finish the scan thread, sounds like Plan?? :-) -//In the end I had to add the memory pool combined with the queue as otherwise -//the queues just keep pointers to data and being that the putting and getting of -//the pot values in the queue is asynchronous you need a buffer to keep the values -//and this is provided by the MemoryPool. -//I also merged your changes with mine.....temproarily commented out the pc.printf meessage for pot read. 3/4/14 +//***************************** TESTING ********************************************************// +// TEST TEST DESCRIPTION STATUS // +// 1 POT thread updates to a in less than 10 s when pot PASS // +// value is changed // +// 2 Temp thread updates to a in less than 60 s when sensor PASS // +// sensor temperature changes // +// 3 Strings entered with the terminal are faithfully displayed PASS // +// in the LCD, no missing characters regardless of typing // +// speed // +// 4 Enetering a fortune cookie in the terminal does not block PASS // +// normsl executions o the other threads // +// 5 There is no risk of overunning the fortune cookie buffer PASS // +// if the user continues to type beyond the allowable cookie // +// length the program trims the fortune cookie and reads the // +// reamining characters for the next cookie, no missing characters // +// 6 Pressing center joystick button at reset allows entering date PASS // +// from the terminal. +//**********************************************************************************************// #include "mbed.h" @@ -24,6 +44,7 @@ //#define _DEBUGMODE //Uncomment to enter debug mode which prints some diagnostic strings to the terminal #define BUFFER 17 #define COOKIEQUEUE 30 +#define TIMEOUT 200 C12832_LCD lcd; Serial pc(USBTX, USBRX); //To differentiate from LCD functions @@ -55,22 +76,22 @@ *******************************************************************/ void lcdUpdate(void const*){ while(1){ - osStatus lcdStatus = lcdMutex.lock(1200); + osStatus lcdStatus = lcdMutex.lock(TIMEOUT); if(lcdStatus == osOK){ - osEvent evtPot = potReadingQueue.get(1200); + osEvent evtPot = potReadingQueue.get(TIMEOUT); if (evtPot.status == osEventMessage) { float *queuePot = (float*)evtPot.value.p; lcd.locate(0,0); - lcd.printf("Voltage: %.2f V", *queuePot); + lcd.printf("Volt: %.2f V", *queuePot); potReadingBuffer.free(queuePot); } - osEvent evtTemp = tempReadingQueue.get(1200); + osEvent evtTemp = tempReadingQueue.get(TIMEOUT); if (evtPot.status == osEventMessage) { float *queueTemp = (float*)evtTemp.value.p; lcd.locate(0,8); lcd.printf("Temp: %.2f F", *queueTemp); } - osEvent evtCookie = cookieReadingQueue.get(1200); + osEvent evtCookie = cookieReadingQueue.get(TIMEOUT); if (evtCookie.status == osEventMessage) { char (*queueCookie)[BUFFER] = (char (*)[BUFFER])evtCookie.value.p; lcd.locate(0,16); @@ -94,7 +115,7 @@ while(1){ float *queue = potReadingBuffer.alloc(); *queue = pot1; - potReadingQueue.put(queue,1200); + potReadingQueue.put(queue,TIMEOUT); #ifdef _DEBUGMODE pc.printf("POT read"); #endif @@ -136,7 +157,10 @@ char *ptrChar; ptrChar=*ptrBuffer; while(1){ - + //Note the choice of using getc instead of scanf to read the fortune cookie, + //this is a non-blocking call and allows the rest of our threads to continue operating + //only when a new character is typed this thread executes its body otherwise + //it immediately yields to other threads. if(pc.readable()){ *ptrChar=pc.getc(); pc.putc(*ptrChar); @@ -146,14 +170,15 @@ *ptrChar++=' '; } *ptrChar='\0'; - cookieReadingQueue.put(ptrBuffer,500); + cookieReadingQueue.put(ptrBuffer,TIMEOUT); pc.printf(">Enter your fortune cookie\n>"); ptrChar=*ptrBuffer; } else { ptrChar++; } } - Thread::wait(10); + //A 100 ms wait seems like reasonable delay which allows operation of the remaining threads. + Thread::wait(100); } } @@ -172,7 +197,7 @@ dtp = &dt; while(1){ - osStatus lcdStatus = lcdMutex.lock(1200); + osStatus lcdStatus = lcdMutex.lock(TIMEOUT); if(lcdStatus == osOK){ //pc.printf("TOD updated"); t = time( NULL );