码迷,mamicode.com
首页 > 其他好文 > 详细

CMSIS Example - osMailQ osMailPut osMailGet

时间:2014-07-19 09:03:28      阅读:1090      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   art   io   

 1 struct Thread0_Mail
 2 {
 3   int a;
 4   int b;
 5 };
 6 
 7 osMailQId thread0_mail;
 8 osMailQDef( thread0_mail, 10, struct Thread0_Mail );
 9 
10 struct Thread1_Mail
11 {
12   int x;
13   int y;
14 };
15 
16 osMailQId thread1_mail;
17 osMailQDef( thread1_mail, 10, struct Thread1_Mail );
18 
19 
20 void Thread0( void * arg );
21 void Thread1( void * arg );
22 
23 osThreadDef( Thread0, Thread0, osPriorityNormal, 512 );
24 osThreadDef( Thread1, Thread1, osPriorityAboveNormal, 512 );
25 
26 
27 void Thread0( void * arg )
28 {
29   osEvent event;
30   struct Thread0_Mail * Thread0_mail;
31 
32   while ( 1 )
33   {
34     event = osMailGet( thread0_mail, osWaitForever );
35 
36     if ( event.status == osEventMail )
37     {
38       Thread0_mail = osMailAlloc( thread0_mail, osWaitForever );
39 
40       if ( Thread0_mail )
41       {
42         Thread0_mail->a = 100;
43         Thread0_mail->b = 1000;
44         osMailPut( thread1_mail, Thread0_mail );
45         osMailFree( thread0_mail, Thread0_mail );
46       }
47     }
48 
49     osDelay( 10 );
50   }
51 }
52 
53 
54 void Thread1( void * arg )
55 {
56   osEvent event;
57   struct Thread1_Mail * Thread1_mail;
58 
59   while ( 1 )
60   {
61     Thread1_mail = osMailAlloc( thread1_mail, osWaitForever );
62 
63     if ( Thread1_mail )
64     {
65       Thread1_mail->x = 100;
66       Thread1_mail->y = 1000;
67       osMailPut( thread0_mail, Thread1_mail );
68       event = osMailGet( thread1_mail, osWaitForever );
69 
70       if ( event.status == osEventMail )
71       {
72         osMailFree( thread1_mail, Thread1_mail );
73       }
74     }
75 
76     osDelay( 10 );
77   }
78 }
79 
80 int main( void )
81 {
82   osKernelInitialize();
83   osThreadCreate( osThread( Thread0 ), ( void * )100 );
84   osThreadCreate( osThread( Thread1 ), ( void * )200 );
85   thread0_mail = osMailCreate( osMailQ( thread0_mail ), 0 );
86   thread1_mail = osMailCreate( osMailQ( thread1_mail ), 0 );
87   osKernelStart();
88   return 0;
89 }

CMSIS Example - osMailQ osMailPut osMailGet,布布扣,bubuko.com

CMSIS Example - osMailQ osMailPut osMailGet

标签:style   blog   color   os   art   io   

原文地址:http://www.cnblogs.com/shangdawei/p/3854329.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!