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

main.cpp

Committer:
shiyilei
Date:
2014-10-27
Revision:
5:a1609b233d6d
Parent:
3:c490e2d69dd8

File content as of revision 5:a1609b233d6d:

/**************************************************************
*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"
#include <string.h>
#include <stdio.h>
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Queue<char ,32> taskqueue;
void send_message(void const *args)
{

    char data[16];
    while(1)
    {
        strcpy(data,(const char *)args);
        taskqueue.put(data);
                led1=!led1;
        Thread::wait(1000);
    }
}

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;
}