Lightweight message size

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lightweight message size

438 Views
davidsherman
Senior Contributor I

I'm trying to understand the message sizing in lightweight messages.  I understand that it is in multiples of 32 bits.  Let's say I'm trying to pass a structure as a message:

typedef struct

{

     unsigned char byte1;

     unsigned char *ptr1;

     unsigned char byte2;

     unsigned char *ptr2;

}messageStruct;

The sizeof() for this structure returns 16 bytes.  So, if i create a message queue like this:

uint32_t msgQ[sizeof(LWMSGQ_STRUCT)/sizeof(uint32_t) + sizeof(messageStruct)/sizeof(uint32_t)]

I end up with an array of 20 uint32_t, or 80 bytes, which is what I would expect.

I then initialize the queue with:

_lwmsq_init(msgQ, 1, 4);

However, when I send this structure, with the LWMSGQ_SEND_BLOCK_ON_FULL, it doesn't block because apparently it's not full.  As an experiment, I tried send a single uint32_t integer, but left the message size the same.  Again, it did not block.  Once I changed the message size to 1, it blocked.  Although it only allows 1 message, apparently it's not "full" unless the size of the message is exact.  How does one send a structure like this and have it block on full?

On a somewhat related note, if I send a message with the LWMSQ_SEND_BLOCK_ON_SEND flag, it does indeed block, but what unblocks the task?  I was able to block one task, receive the structure message by the receiving task, but I could not send a structure back and unblock the requesting task.

1 Reply

211 Views
danielchen
NXP TechSupport
NXP TechSupport

Please refer to the macro in lwmsgq.h ,  task will be block when LWMSGQ_IS_FULL

/* Return whether the queue is full */

#define LWMSGQ_IS_FULL(q) \

   (((LWMSGQ_STRUCT_PTR)(q))->CURRENT_SIZE >= ((LWMSGQ_STRUCT_PTR)(q))->MAX_SIZE)

Message queue is full if current_size >= max_size.    max_size is the number of messages when you use _lwmsgq_init.   Current_size will increase by 1 when enqueue and will decrease by 1 when dequeue.

0 Kudos