send_task send the mail of people struct to the recieve task
Fork of rtos_queue by
main.cpp@5:de4eb34fcc3d, 2014-10-27 (annotated)
- Committer:
- shiyilei
- Date:
- Mon Oct 27 04:42:31 2014 +0000
- Revision:
- 5:de4eb34fcc3d
- Parent:
- 3:c490e2d69dd8
send_task send the mail of ; people struct to the recieve task
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shiyilei | 5:de4eb34fcc3d | 1 | /************************************************** |
shiyilei | 5:de4eb34fcc3d | 2 | *file:mail_box test |
shiyilei | 5:de4eb34fcc3d | 3 | *Creator:JacobShi |
shiyilei | 5:de4eb34fcc3d | 4 | *Time:2014/10/24 |
shiyilei | 5:de4eb34fcc3d | 5 | * Description: send_task send the mail of |
shiyilei | 5:de4eb34fcc3d | 6 | * people struct to the recieve task |
shiyilei | 5:de4eb34fcc3d | 7 | **************************************************/ |
shiyilei | 5:de4eb34fcc3d | 8 | |
emilmont | 1:d2ba5afbf91f | 9 | #include "mbed.h" |
emilmont | 1:d2ba5afbf91f | 10 | #include "rtos.h" |
shiyilei | 5:de4eb34fcc3d | 11 | DigitalOut led1(LED1); |
shiyilei | 5:de4eb34fcc3d | 12 | DigitalOut led2(LED2); |
emilmont | 1:d2ba5afbf91f | 13 | typedef struct { |
shiyilei | 5:de4eb34fcc3d | 14 | char school[5]; |
shiyilei | 5:de4eb34fcc3d | 15 | int num; |
shiyilei | 5:de4eb34fcc3d | 16 | char career[10]; |
shiyilei | 5:de4eb34fcc3d | 17 | }my_inform; |
emilmont | 1:d2ba5afbf91f | 18 | |
shiyilei | 5:de4eb34fcc3d | 19 | Mail<my_inform,32>taskmail; |
shiyilei | 5:de4eb34fcc3d | 20 | void send_task(void const*args) |
shiyilei | 5:de4eb34fcc3d | 21 | { |
shiyilei | 5:de4eb34fcc3d | 22 | |
shiyilei | 5:de4eb34fcc3d | 23 | while(1) |
shiyilei | 5:de4eb34fcc3d | 24 | { |
shiyilei | 5:de4eb34fcc3d | 25 | my_inform*my=taskmail.alloc(); |
shiyilei | 5:de4eb34fcc3d | 26 | strcpy(my->school,"ECNU"); |
shiyilei | 5:de4eb34fcc3d | 27 | my->num=0x06; |
shiyilei | 5:de4eb34fcc3d | 28 | strcpy(my->career,"Student"); |
shiyilei | 5:de4eb34fcc3d | 29 | led1=!led1; |
shiyilei | 5:de4eb34fcc3d | 30 | taskmail.put(my); |
shiyilei | 5:de4eb34fcc3d | 31 | Thread::wait(500); |
emilmont | 1:d2ba5afbf91f | 32 | } |
shiyilei | 5:de4eb34fcc3d | 33 | |
emilmont | 1:d2ba5afbf91f | 34 | } |
emilmont | 1:d2ba5afbf91f | 35 | |
shiyilei | 5:de4eb34fcc3d | 36 | void recieve_task(void const *args) |
shiyilei | 5:de4eb34fcc3d | 37 | { |
shiyilei | 5:de4eb34fcc3d | 38 | osEvent eve; |
shiyilei | 5:de4eb34fcc3d | 39 | my_inform*my; |
shiyilei | 5:de4eb34fcc3d | 40 | while(1) |
shiyilei | 5:de4eb34fcc3d | 41 | { |
shiyilei | 5:de4eb34fcc3d | 42 | led2=!led2; |
shiyilei | 5:de4eb34fcc3d | 43 | eve=taskmail.get(); |
shiyilei | 5:de4eb34fcc3d | 44 | if(eve.status==osEventMail) |
shiyilei | 5:de4eb34fcc3d | 45 | { |
shiyilei | 5:de4eb34fcc3d | 46 | my=(my_inform*)eve.value.p; |
shiyilei | 5:de4eb34fcc3d | 47 | printf("school is:%s\r\n", my->school); |
shiyilei | 5:de4eb34fcc3d | 48 | printf("number is :%d\r\n",my->num ); |
shiyilei | 5:de4eb34fcc3d | 49 | printf("career is :%s\r\n",my->career); |
shiyilei | 5:de4eb34fcc3d | 50 | taskmail.free(my); |
shiyilei | 5:de4eb34fcc3d | 51 | } |
shiyilei | 5:de4eb34fcc3d | 52 | Thread::wait(200); |
emilmont | 1:d2ba5afbf91f | 53 | } |
shiyilei | 5:de4eb34fcc3d | 54 | |
shiyilei | 5:de4eb34fcc3d | 55 | } |
shiyilei | 5:de4eb34fcc3d | 56 | |
shiyilei | 5:de4eb34fcc3d | 57 | int main(void) |
shiyilei | 5:de4eb34fcc3d | 58 | { |
shiyilei | 5:de4eb34fcc3d | 59 | Thread task1(send_task); |
shiyilei | 5:de4eb34fcc3d | 60 | Thread task2(recieve_task); |
shiyilei | 5:de4eb34fcc3d | 61 | |
shiyilei | 5:de4eb34fcc3d | 62 | while(1) |
shiyilei | 5:de4eb34fcc3d | 63 | { |
shiyilei | 5:de4eb34fcc3d | 64 | |
shiyilei | 5:de4eb34fcc3d | 65 | |
emilmont | 1:d2ba5afbf91f | 66 | } |
shiyilei | 5:de4eb34fcc3d | 67 | |
shiyilei | 5:de4eb34fcc3d | 68 | return 0; |
shiyilei | 5:de4eb34fcc3d | 69 | } |