Faulty threads with IPC messages
Dependencies: C12832_lcd LM75B mbed-rtos mbed
Revision 0:337ae54a3bdb, committed 2014-03-12
- Comitter:
- Michael_embed1
- Date:
- Wed Mar 12 03:49:02 2014 +0000
- Commit message:
- rev1_mhey_HW6_1
Changed in this revision
diff -r 000000000000 -r 337ae54a3bdb C12832_lcd.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Wed Mar 12 03:49:02 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/dreschpe/code/C12832_lcd/#468cdccff7af
diff -r 000000000000 -r 337ae54a3bdb HW6_1_IPC.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HW6_1_IPC.cpp Wed Mar 12 03:49:02 2014 +0000 @@ -0,0 +1,115 @@ +#include "mbed.h" +#include "LM75B.h" +#include "C12832_lcd.h" +#include "rtos.h" + +// instantiate hardware peripherals +LM75B tmpSns(p28,p27); +C12832_LCD lcd; +Serial pc(USBTX, USBRX); // tx, rx; used only if errors encountered + +// mutex to make the lcd lib thread safe +Mutex lcd_mutex; + +AnalogIn Pot1(p19); + +typedef unsigned short potVal_t; +typedef float tempVal_t; + +//Potentiometer values memory pool +MemoryPool<potVal_t, 16> potVal_mpool; +Queue<potVal_t, 16> potVal_queue; + +//Temperature sensor values memory pool +MemoryPool<tempVal_t, 16> tempVal_mpool; +Queue<tempVal_t, 16> tempVal_queue; + + +// Thread potVal_send_thread() +// Pot1 sends value to LCD thread via IPC Queue +void potVal_send_thread(void const *args) +{ + potVal_t *potValMessage; + + while(true) + { +// potVal_t *potValMessage = potVal_mpool.alloc(); + potValMessage = potVal_mpool.alloc(); + *potValMessage = Pot1.read_u16(); // get Pot1 value + potVal_queue.put(potValMessage); // put it in the queue + Thread::wait(1000); // wait 1.0s + } +} + +// Thread tempVal_send_thread() +// Temperature sensor sends value to LCD thread via IPC Queue +void tempVal_send_thread(void const *args) +{ + float *tempValMessage; + while(true) + { +// float *tempValMessage = tempVal_mpool.alloc(); + tempValMessage = tempVal_mpool.alloc(); + *tempValMessage = ((tmpSns.read()*9/5)+32);// get Temp update + tempVal_queue.put(tempValMessage); // put value in the queue + Thread::wait(1000); // wait 0.5s + pc.printf("\ntempVal_send_thread executing"); + } +} + +void lcd_thread(void const *args) +{ + osEvent evt1; + osEvent evt2; + + float *tempVal; + potVal_t *pot1Val; + + + while (true) + { + // osEvent evt1 = potVal_queue.get(); + evt1 = potVal_queue.get(); + if (evt1.status == osEventMessage) + { + potVal_t *pot1Val = (potVal_t*)evt1.value.p; + pot1Val = (potVal_t*)evt1.value.p; + lcd_mutex.lock(); // exclude other thread access to lcd + lcd.locate(0,0); + lcd.printf("\nPot1=%d", *pot1Val); + lcd_mutex.unlock(); + potVal_mpool.free(pot1Val); + } + + // osEvent evt2 = tempVal_queue.get(); + evt2 = tempVal_queue.get(); + if (evt2.status == osEventMessage) +// pc.printf("\nevt2.status == osEventMessage"); + { +// float *tempVal = (float*)evt2.value.p; + tempVal = (float*)evt2.value.p; + lcd_mutex.lock(); // exclude other thread access to lcd + lcd.locate(0,20); + lcd.printf("\nTemp=%3.1f", *tempVal); + lcd_mutex.unlock(); + tempVal_mpool.free(tempVal); + } + + } +} + +int main() { + pc.printf("\nmain started..."); + lcd.cls(); + Thread thread1(potVal_send_thread); + pc.printf("\nthree threads started..."); + Thread thread2(lcd_thread); + Thread thread3(tempVal_send_thread); + pc.printf("\nthree threads started..."); + + while(true) + { + Thread::wait(1000); + } +} +
diff -r 000000000000 -r 337ae54a3bdb LM75B.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.lib Wed Mar 12 03:49:02 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/chris/code/LM75B/#6a70c9303bbe
diff -r 000000000000 -r 337ae54a3bdb mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed Mar 12 03:49:02 2014 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed-rtos/#869ef732a8a2
diff -r 000000000000 -r 337ae54a3bdb mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 12 03:49:02 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1 \ No newline at end of file