This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MessageQ and variable length messages

CCS v5.4

TI-RTOS 1.10.00.23

F28M35H52C1 Experimenter Kit

 

I’m just starting to use TI-RTOS for the first time on a Concerto F28M35H52C1 Experimenter Kit.  I’m designing an application for the ARM core and I would like to use the MessageQ IPC to send data between threads within that same core.  From what I’ve read, the MessageQ is supposed to support sending and receiving of variable length messages, but I'm confused as how to implement this after looking for examples.  I’ve seen example code where a structure for a message is defined something like this:

   typedef struct MyMsg {

       MessageQ_MsgHeader header;

       int MyData[10];

   } MyMsg;

After the message is sent from one thread, Another thread  receives the message with something like this:

   MyMsg msg;  

   status = MessageQ_get(message, &msg, MessageQ_FOREVER);

From this code, it appears the MessageQ_get expects a fixed sized message based on the size of the MyMsg structure.

If I have a second structure defined as follows

   typedef struct MyMsg2

      MessageQ_MsgHeader header;

      float MyData[100];

   } MyMsg2;

 

how could I send either MyMsg or MyMsg2 through the same MessageQ, if the MessageQ_get call needs to specify a buffer defined as a fixed size structure to hold the message?  Would this require a separate message queue for each message of a different length?

Thanks in advance for any help.

  • Hi Greg,

    MessageQ passes pointers. It is not copy based. So you can pass messages of different length. Of course your application needs to know what type of message (e.g. MyMsg or MyMsg2) it received. You can use the msgId in the message to denote what type of message it is. For example, if you send a myMsg, set msgId to 1. If you send a MyMsg2, set msgId to 2. Then the receiver get the msgId and know how to cast accordingly.

    Todd

  • Thanks Todd!  It appears I have this working with multiple messages through the same message queue by receiving to a MessageQ_Msg in my MessageQ_get call and then casting appropriately based on a message ID that I set.