1. 程式人生 > >CMSIS-RTOS2 文件翻譯 之 參考(CMSIS-RTOS2 API 之 訊息佇列)

CMSIS-RTOS2 文件翻譯 之 參考(CMSIS-RTOS2 API 之 訊息佇列)

// CMSIS RTOS header file/*---------------------------------------------------------------------------- * Message Queue creation & usage *---------------------------------------------------------------------------*/void Thread_MsgQueue1 (void *argument); // thread function 1
void Thread_MsgQueue2 (void *argument); // thread function 2osThreadId_t tid_Thread_MsgQueue1; // thread id 1osThreadId_t tid_Thread_MsgQueue2; // thread id 2#define MSGQUEUE_OBJECTS 16 // number of Message Queue Objects
typedef struct { // object data type uint8_t Buf[32]; uint8_t Idx;} MSGQUEUE_OBJ_t;osMessageQueueId_t mid_MsgQueue; // message queue idint Init_MsgQueue (void) { mid_MsgQueue = osMessageQueueNew(MSGQUEUE_OBJECTS, sizeof
(MSGQUEUE_OBJ_t), NULL); if (!mid_MsgQueue) { ; // Message Queue object not created, handle failure } tid_Thread_MsgQueue1 = osThreadNew (Thread_MsgQueue1, NULL, NULL); if (!tid_Thread_MsgQueue1) return(-1); tid_Thread_MsgQueue2 = osThreadNew (Thread_MsgQueue2, NULL, NULL); if (!tid_Thread_MsgQueue2) return(-1); return(0);}void Thread_MsgQueue1 (void *argument) { MSGQUEUE_OBJ_t msg; while (1) { ; // Insert thread code here... msg.Buf[0] = 0x55; // do some work... msg.Idx = 0; osMessageQueuePut (mid_MsgQueue, &msg, 0, NULL); }}void Thread_MsgQueue2 (void *argument) { MSGQUEUE_OBJ_t msg; osStatus_t status; while (1) { ; // Insert thread code here... status = osMessageQueueGet (mid_MsgQueue, &msg, NULL, NULL); // wait for message if (status == osOK) { ; // process data } }}