he send thread uses the queueto send the code to the receive thread and print the code on the screen.

Dependencies:   mbed-rtos mbed

Fork of rtos_queue by mbed official

Committer:
shiyilei
Date:
Mon Oct 27 04:39:50 2014 +0000
Revision:
5:a1609b233d6d
Parent:
3:c490e2d69dd8
he send thread uses the queueto send the code; to the receive thread and print the code on the screen.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shiyilei 5:a1609b233d6d 1 /**************************************************************
shiyilei 5:a1609b233d6d 2 *file name :queue test
shiyilei 5:a1609b233d6d 3 *Creator :JacobShi
shiyilei 5:a1609b233d6d 4 *Time :2014/10/27
shiyilei 5:a1609b233d6d 5 * Description : The send thread uses the queueto send the code
shiyilei 5:a1609b233d6d 6 * to the receive thread and print the code on the screen.
shiyilei 5:a1609b233d6d 7 **************************************************************/
emilmont 1:d2ba5afbf91f 8 #include "mbed.h"
emilmont 1:d2ba5afbf91f 9 #include "rtos.h"
shiyilei 5:a1609b233d6d 10 #include <string.h>
shiyilei 5:a1609b233d6d 11 #include <stdio.h>
shiyilei 5:a1609b233d6d 12 DigitalOut led1(LED1);
shiyilei 5:a1609b233d6d 13 DigitalOut led2(LED2);
shiyilei 5:a1609b233d6d 14 Queue<char ,32> taskqueue;
shiyilei 5:a1609b233d6d 15 void send_message(void const *args)
shiyilei 5:a1609b233d6d 16 {
emilmont 1:d2ba5afbf91f 17
shiyilei 5:a1609b233d6d 18 char data[16];
shiyilei 5:a1609b233d6d 19 while(1)
shiyilei 5:a1609b233d6d 20 {
shiyilei 5:a1609b233d6d 21 strcpy(data,(const char *)args);
shiyilei 5:a1609b233d6d 22 taskqueue.put(data);
shiyilei 5:a1609b233d6d 23 led1=!led1;
emilmont 1:d2ba5afbf91f 24 Thread::wait(1000);
emilmont 1:d2ba5afbf91f 25 }
emilmont 1:d2ba5afbf91f 26 }
emilmont 1:d2ba5afbf91f 27
shiyilei 5:a1609b233d6d 28 void receive_message(void const *args)
shiyilei 5:a1609b233d6d 29 {
shiyilei 5:a1609b233d6d 30 osEvent myevent;
shiyilei 5:a1609b233d6d 31 while(1)
shiyilei 5:a1609b233d6d 32 {
shiyilei 5:a1609b233d6d 33
shiyilei 5:a1609b233d6d 34 led2=!led2;
shiyilei 5:a1609b233d6d 35 myevent=taskqueue.get();
shiyilei 5:a1609b233d6d 36 if(myevent.status==osEventMessage)
shiyilei 5:a1609b233d6d 37 {
shiyilei 5:a1609b233d6d 38 char *data=(char *)myevent.value.p;
shiyilei 5:a1609b233d6d 39 printf("%s\n",data);
shiyilei 5:a1609b233d6d 40 }
shiyilei 5:a1609b233d6d 41 Thread::wait(500);
emilmont 1:d2ba5afbf91f 42 }
emilmont 1:d2ba5afbf91f 43 }
shiyilei 5:a1609b233d6d 44
shiyilei 5:a1609b233d6d 45
shiyilei 5:a1609b233d6d 46 int main(void)
shiyilei 5:a1609b233d6d 47 {
shiyilei 5:a1609b233d6d 48 Thread send_task(send_message,(void*)"send task");
shiyilei 5:a1609b233d6d 49 Thread receive_task(receive_message);
shiyilei 5:a1609b233d6d 50
shiyilei 5:a1609b233d6d 51 while(1)
shiyilei 5:a1609b233d6d 52 {
shiyilei 5:a1609b233d6d 53
shiyilei 5:a1609b233d6d 54 }
shiyilei 5:a1609b233d6d 55 return 0;
shiyilei 5:a1609b233d6d 56 }