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

CMSIS Example - osMessageQ osMessagePut osMessageGet

时间:2014-07-19 15:06:21      阅读:1230      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   art   io   

 1 #include "cmsis_os.h"
 2 
 3 void Thread0( void * arg);
 4 void Thread1( void * arg);
 5 
 6 osThreadDef( Thread0, Thread0, osPriorityNormal, 512 );
 7 osThreadDef( Thread1, Thread1, osPriorityAboveNormal, 512 );
 8 
 9 osMessageQDef(_thread0_MsgQ, 100 );
10 osMessageQId thread0_MsgQ;
11 
12 osMessageQDef(_thread1_MsgQ, 100 );
13 osMessageQId thread1_MsgQ;
14 
15 void Thread0( void * arg)
16 {
17   osEvent event;
18   while(1)
19   {
20     event = osMessageGet(thread0_MsgQ, osWaitForever );
21     if ( event.status == osOK)
22       osMessagePut( thread1_MsgQ, event.value.v+1, osWaitForever );
23 
24     osDelay( 100 );
25   }
26 }
27 
28 void Thread1( void * arg)
29 {
30   osEvent event;
31   osMessagePut( thread0_MsgQ, 0, 1000 );
32 
33   while(1)
34   {
35     event = osMessageGet(thread1_MsgQ, osWaitForever );
36     if ( event.status == osOK)
37       osMessagePut( thread0_MsgQ, event.value.v+1, osWaitForever );
38 
39     osDelay( 50 );
40   }
41 }
42 
43 int main( void )
44 {
45   osKernelInitialize();
46 
47   thread0_MsgQ = osMessageCreate( osMessageQ(_thread0_MsgQ), 0 );
48   thread1_MsgQ = osMessageCreate( osMessageQ(_thread1_MsgQ), 0 );
49 
50   osThreadCreate( osThread(Thread0), (void *)100 );
51   osThreadCreate( osThread(Thread1), (void *)200 );
52 
53   osKernelStart();
54 
55   return 0;
56 }

CMSIS Example - osMessageQ osMessagePut osMessageGet,布布扣,bubuko.com

CMSIS Example - osMessageQ osMessagePut osMessageGet

标签:style   blog   color   os   art   io   

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

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