he send thread uses the queueto send the code to the receive thread and print the code on the screen.
Fork of rtos_queue by
Revision 5:a1609b233d6d, committed 2014-10-27
- Comitter:
- shiyilei
- Date:
- Mon Oct 27 04:39:50 2014 +0000
- Parent:
- 4:c980920b5e22
- Commit message:
- he send thread uses the queueto send the code; to the receive thread and print the code on the screen.
Changed in this revision
diff -r c980920b5e22 -r a1609b233d6d main.cpp --- a/main.cpp Tue Jun 04 16:03:43 2013 +0100 +++ b/main.cpp Mon Oct 27 04:39:50 2014 +0000 @@ -1,41 +1,56 @@ +/************************************************************** +*file name :queue test +*Creator :JacobShi +*Time :2014/10/27 +* Description : The send thread uses the queueto send the code +* to the receive thread and print the code on the screen. + **************************************************************/ #include "mbed.h" #include "rtos.h" - -typedef struct { - float voltage; /* AD result of measured voltage */ - float current; /* AD result of measured current */ - uint32_t counter; /* A counter value */ -} message_t; - -MemoryPool<message_t, 16> mpool; -Queue<message_t, 16> queue; +#include <string.h> +#include <stdio.h> +DigitalOut led1(LED1); +DigitalOut led2(LED2); +Queue<char ,32> taskqueue; +void send_message(void const *args) +{ -/* Send Thread */ -void send_thread (void const *args) { - uint32_t i = 0; - while (true) { - i++; // fake data update - message_t *message = mpool.alloc(); - message->voltage = (i * 0.1) * 33; - message->current = (i * 0.1) * 11; - message->counter = i; - queue.put(message); + char data[16]; + while(1) + { + strcpy(data,(const char *)args); + taskqueue.put(data); + led1=!led1; Thread::wait(1000); } } -int main (void) { - Thread thread(send_thread); - - while (true) { - osEvent evt = queue.get(); - if (evt.status == osEventMessage) { - message_t *message = (message_t*)evt.value.p; - printf("\nVoltage: %.2f V\n\r" , message->voltage); - printf("Current: %.2f A\n\r" , message->current); - printf("Number of cycles: %u\n\r", message->counter); - - mpool.free(message); - } +void receive_message(void const *args) +{ + osEvent myevent; + while(1) + { + + led2=!led2; + myevent=taskqueue.get(); + if(myevent.status==osEventMessage) + { + char *data=(char *)myevent.value.p; + printf("%s\n",data); + } + Thread::wait(500); } } + + +int main(void) +{ + Thread send_task(send_message,(void*)"send task"); + Thread receive_task(receive_message); + + while(1) + { + + } + return 0; +}
diff -r c980920b5e22 -r a1609b233d6d mbed-rtos.lib --- a/mbed-rtos.lib Tue Jun 04 16:03:43 2013 +0100 +++ b/mbed-rtos.lib Mon Oct 27 04:39:50 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/ \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed-rtos/#e2da1b20a6d5
diff -r c980920b5e22 -r a1609b233d6d mbed.bld --- a/mbed.bld Tue Jun 04 16:03:43 2013 +0100 +++ b/mbed.bld Mon Oct 27 04:39:50 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file