LWMSGQueue clarification needed

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

LWMSGQueue clarification needed

跳至解决方案
2,003 次查看
mmalagon
Contributor II

I have a confusion about the usage of lightweight message queues that should be very easy to resolve by someone with experience on MQX. I can see on the example code included in MQX that the array is declared as:

#define NUM_MESSAGES  3
#define MSG_SIZE      1

uint32_t server_queue[sizeof(LWMSGQ_STRUCT)/sizeof(uint32_t) + NUM_MESSAGES * MSG_SIZE];

 

And that is is being initialized as:

_lwmsgq_init((void *)server_queue, NUM_MESSAGES, MSG_SIZE);

 

So, my question is simple, how should I declare my queue array and initialize the queue if I have the following structure:

typedef struct my_struct
{
    uint32_t a;
    uint8_t b;
    char *c[32]
    uint32_t *d;
} my_struct_t;

 

I ask because the example uses uint32_t which is not that helpful. The fact it uses uint32_t causes confusion about what to change to adapt the example to what I need. For instance, should I declare my array as:

my_struct_t server_queue[sizeof(LWMSGQ_STRUCT)/sizeof(my_struct_t) + NUM_MESSAGES * MSG_SIZE];

 

And what about the initialization? There seems like there is nothing to change about it because it doesn't include the data type. Is it really the exact same initialization regardless of the data type used for the queue? That doesn't sound right.

Thanks!

0 项奖励
回复
1 解答
1,981 次查看
danielchen
NXP TechSupport
NXP TechSupport
#define NUM_MESSAGES  3
#define MSG_SIZE      sizeof(my_struct)/sizeof(_mqx_max_type)

uint32_t server_queue [sizeof(LWMSGQ_STRUCT) + NUM_MESSAGES * MSG_SIZE];

_lwmsgq_init((void *)server_queue, NUM_MESSAGES, MSG_SIZE);

在原帖中查看解决方案

3 回复数
1,995 次查看
danielchen
NXP TechSupport
NXP TechSupport

Hi 

Please check the _lwmsgq_init ,   Lightweight message queues are a simpler, low-overhead implementation of standard MQX RTOS messages. Tasks send messages to lightweight message queues and receive message from lightweight message queues.  A message in the message pool has a fixed size, a multiple of 32 bits.

danielchen_0-1672834039000.png

 

Regards

Daniel

 

0 项奖励
回复
1,990 次查看
mmalagon
Contributor II

@danielchen thanks for helping!

So if I understand correctly, if my structure is:

typedef struct my_struct
{
    uint16_t a;
    uint16_t b;
    uint8_t c;
} my_struct_t

 

That would be 40 bits only, therefore I would have to make my structure as:

typedef struct my_struct
{
    uint16_t a;
    uint16_t b;
    uint8_t c;
    uint8_t reserved[3];
} my_struct_t

To make it 64 bits and be able to use it, is this correct?

Then, should the array declaration and queue initialization be:

#define NUM_MESSAGES  3
#define MSG_SIZE      2 /* 2 because the struct is 64bits long, correct? */

uint32_t server_queue [sizeof(LWMSGQ_STRUCT)/sizeof(uint32_t) + NUM_MESSAGES * MSG_SIZE];

_lwmsgq_init((void *)server_queue, NUM_MESSAGES, MSG_SIZE);

 

Or, written in terms of the structure:

#define NUM_MESSAGES  3
#define MSG_SIZE      sizeof(my_struct)/sizeof(_mqx_max_type)

uint32_t server_queue [sizeof(LWMSGQ_STRUCT)/sizeof(uint32_t) + NUM_MESSAGES * MSG_SIZE];

_lwmsgq_init((void *)server_queue, NUM_MESSAGES, MSG_SIZE);

 

Is this correct?

0 项奖励
回复
1,982 次查看
danielchen
NXP TechSupport
NXP TechSupport
#define NUM_MESSAGES  3
#define MSG_SIZE      sizeof(my_struct)/sizeof(_mqx_max_type)

uint32_t server_queue [sizeof(LWMSGQ_STRUCT) + NUM_MESSAGES * MSG_SIZE];

_lwmsgq_init((void *)server_queue, NUM_MESSAGES, MSG_SIZE);