首页 > 代码库 > CMSIS Example - osMessageQ osMessagePut osMessageGet
CMSIS Example - osMessageQ osMessagePut osMessageGet
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 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。