send_task send the mail of people struct to the recieve task

Dependencies:   mbed-rtos mbed

Fork of rtos_queue by mbed official

main.cpp

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

File content as of revision 5:de4eb34fcc3d:

/**************************************************
*file:mail_box test
*Creator:JacobShi
*Time:2014/10/24
* Description: send_task send the mail of 
* people struct to the recieve task
 **************************************************/

#include "mbed.h"
#include "rtos.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
typedef struct {
    char school[5];
    int num;
    char career[10];
}my_inform;

Mail<my_inform,32>taskmail;
void send_task(void const*args)
{
   
    while(1)
    {
        my_inform*my=taskmail.alloc();
        strcpy(my->school,"ECNU");
        my->num=0x06;
        strcpy(my->career,"Student");
        led1=!led1;
        taskmail.put(my);
        Thread::wait(500);
    }

}

void recieve_task(void const *args)
{
        osEvent eve;
        my_inform*my;
     while(1)
        {
                led2=!led2;
                eve=taskmail.get();
                if(eve.status==osEventMail)
                  {
                    my=(my_inform*)eve.value.p;
                    printf("school is:%s\r\n", my->school);
                    printf("number is :%d\r\n",my->num );
                    printf("career is :%s\r\n",my->career);
                    taskmail.free(my);
                }  
            Thread::wait(200);
        }

}

int main(void)
{
    Thread task1(send_task);
    Thread task2(recieve_task);
  
    while(1)
    {
       

    }

    return 0;
}