Trying to get a handle on the 'new' CMSIS Keil RTX5 RTOS2 and am currently working with MessageQueue. Specifically, I am creating my own osMessageQueueAttr_t so I have the ability to use my own static memory for messaging rather than using the MemoryPool option. However, the documentation is a bit lacking on the declaration of the elements within the Attr structure. So, stepped through rtx_msgsqueue.c function os_svcMessageQueueNew() and think I have a proper grasp on these elements but would like a confirmation that I am not uses too much memory in my declarations. Note the gaps are due to the code pasted from different areas of the same file. Thanks...
// Task MessageQueue sizes #define TASK1_MSGQSIZE 10 #define TASK2_MSGQSIZE 10 // NOTE: os_message_t/os_message_queue_t structs are found in rtx_os.h // from rtx_msgqueue.c: 0s_MemoryAlloc(os_Info.mem.common, sizeof(os_message_queue_t), 1U); #define TASK1CB_MEMSIZE sizeof(os_message_queue_t) uint32_t Task1CBMemBlock[TASK1CB_MEMSIZE]; // from rtx_msgqueue.c: (msg_count * (msg_size + sizeof(os_message_t))) = 160 (0xA0) #define TASK1MQ_MEMSIZE (TASK1_MSGQSIZE*(sizeof(uint32_t)+sizeof(os_message_t))) uint32_t Task1MQMemBlock[TASK1MQ_MEMSIZE]; Trying to get a handle on the 'new' CMSIS RTOS2 osMessageQueueAttr_t Task1MsgAttr = { .name = "T1MsgQ", // .attr_bits = 0, // NOT a CLUE what these are.... .cb_mem = &Task1CBMemBlock[0], // .cb_size = TASK1CB_MEMSIZE, .mq_mem = &Task1MQMemBlock[0], // data memory (rtx_msgqueue.c line 307) .mq_size = TASK1MQ_MEMSIZE }; if ((Task1MsgQId = osMessageQueueNew(TASK1_MSGQSIZE, sizeof(uint32_t), NULL)) == NULL) while(1);
The memory usage as per .map file:
Task1CBMemBlock 0x20001ee0 Data 208 rtx2main.o(.bss) Task1MQMemBlock 0x20001fb0 Data 640 rtx2main.o(.bss) Task2CBMemBlock 0x20002230 Data 208 rtx2main.o(.bss) Task2MQMemBlock 0x20002300 Data 640 rtx2main.o(.bss) and the declaration was in error in the first post: if ((Task1MsgQId = osMessageQueueNew(TASK1_MSGQSIZE, sizeof(uint32_t), &Task1MsgAttr)) == NULL) while(1);
RTX already provides definitions is order to make specifying own memory easier.
You can use control block definitions and macros for calculating data memory sizes.
Your examples would look like:
#include "cmsis_os2.h" #include "rtx_os.h" #define TASK1_MSGQSIZE 10 osRtxMessageQueue_t Task1CBMemBlock; uint32_t Task1MQMemBlock[osRtxMessageQueueMemSize(TASK1_MSGQSIZE, 4)/sizeof(uint32_t)]; osMessageQueueAttr_t Task1MsgAttr = { .name = "T1MsgQ", .attr_bits = 0, // Reserved (must be zero) .cb_mem = &Task1CBMemBlock, .cb_size = sizeof(Task1CBMemBlock), .mq_mem = &Task1MQMemBlock[0], .mq_size = sizeof(Task1MQMemBlock) };