首页 > 代码库 > 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 }