RTOS2 Code Example Message Q
diff --git a/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Message.txt b/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Message.txt
index ce9fd21..a054e92 100644
--- a/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Message.txt
+++ b/CMSIS/DoxyGen/RTOS2/src/cmsis_os2_Message.txt
@@ -23,22 +23,22 @@
Follow these steps to create and use a message queue:
-# Setup the message queue:
\code
-osMessageQDef(message_q, 5, uint32_t); // Declare a message queue
-osMessageQId (message_q_id); // Declare an ID for the message queue
+osMessageQueueId_t MsgQ_Id; // Define a message queue ID
\endcode
-# Then, create the message queue in a thread:
\code
-message_q_id = osMessageCreate(osMessageQ(message_q), NULL);
+MsgQId_Isr = osMessageQueueNew (16, sizeof(uint32_t), NULL); // Instance a message queue for 16 elements of uint32_t
\endcode
-# Fill the message queue with data:
\code
uint32_t data = 512;
-osMailPut(message_q_id, data, osWaitForever);
+osMessageQueuePut(MsgQ_Id, data, 0, 0);
\endcode
-# From the receiving thread access the data using:
\code
-osEvent event = osMessageGet(message_q_id, osWaitForever);
+uint32_t msg;
+osMessageQueueGet(MsgQ_Id, &msg, NULL, 0);
\endcode
@{
@@ -66,6 +66,84 @@
/**
\fn osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t millisec)
\details
+\b Example:
+\code
+#include "cmsis_os2.h" // CMSIS RTOS header file
+
+void *Thread_MsgQueue1 (void *argument); // thread function 1
+void *Thread_MsgQueue2 (void *argument); // thread function 2
+osThreadId_t tid_Thread_MsgQueue1; // thread id 1
+osThreadId_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;
+} MEM_BLOCK_t;
+
+typedef struct { // object data type
+ uint8_t Buf[32];
+ uint8_t Idx;
+} MSGQUEUE_OBJ_t;
+
+osMemoryPoolId_t mpid_MemPool2; // memory pool id
+osMessageQueueId_t mid_MsgQueue; // message queue id
+
+int Init_MsgQueue (void) {
+
+ mpid_MemPool2 = osMemoryPoolNew(MSGQUEUE_OBJECTS, sizeof(MSGQUEUE_OBJ_t), NULL);
+ if (!mpid_MemPool2) {
+ ; // MemPool object not created, handle failure
+ }
+
+ 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) {
+ MEM_BLOCK_t *pMsg = 0;
+
+ while (1) {
+ ; // Insert thread code here...
+ pMsg = (MEM_BLOCK_t *)osMemoryPoolAlloc (mpid_MemPool2, NULL); // get Mem Block
+ if (pMsg) { // Mem Block was available
+ pMsg->Buf[0] = 0x55; // do some work...
+ pMsg->Idx = 0;
+ osMessageQueuePut (mid_MsgQueue, &pMsg, NULL, NULL);
+ }
+
+ osThreadYield (); // suspend thread
+ }
+}
+
+void *Thread_MsgQueue2 (void *argument) {
+ osStatus_t status;
+ MEM_BLOCK_t *pMsg = 0;
+
+ while (1) {
+ ; // Insert thread code here...
+ status = osMessageQueueGet (mid_MsgQueue, &pMsg, NULL, NULL); // wait for message
+ if (status == osOK) {
+ if (pMsg) {
+ ; // process data
+ osMemoryPoolFree (mpid_MemPool2, pMsg); // free memory allocated for message
+ }
+ }
+ }
+}
+\endcode
+
+\todo Example formatting does not use syntax highlighting and links to known identifiers
*/
/*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/