LWMSGQueue clarification needed

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LWMSGQueue clarification needed

ソリューションへジャンプ
1,225件の閲覧回数
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,203件の閲覧回数
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,217件の閲覧回数
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,212件の閲覧回数
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,204件の閲覧回数
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);