Back to Blog

VxWorks Inter-Process Communication 1 - Message Queues

#buffer#Task

VxWorks Inter-Process Communication 1 - Message Queues

I. Concepts:

  1. Message queues are used for passing information between tasks.

  2. Multiple tasks can send or receive messages to/from the same message queue.

  3. ISRs (Interrupt Service Routines) can send messages using the NO_WAIT option.

II. Control Functions:

1. msgQCreate

[c-sharp] view plain copy

  1. MSG_Q_ID msgQCreate  

  2. (  

  3.     int maxMsgs, /* Message queue length (maximum number of messages) */  

  4.     int maxMsgLength, /* Maximum length of messages in the message queue*/  

  5.     int options /* FIFO/PRIORITY task queuing method*/  

  6. )  

2. msgQSend

[c-sharp] view plain copy

  1. STATUS msgQSend  

  2. (  

  3.     MSG_Q_ID msgQId, /* Message queue ID */  

  4.     char *buffer, /* Pointer to the message to send*/  

  5.     UINT nBytes, /* Message length*/  

  6.     int timeout, /* Timeout period (ticks) / no-wait / forever */  

  7.     int priority /* MSG_PRI_NORMAL or MSG_PRI_URGENT */  

  8. )  

3. msgQReceive

[c-sharp] view plain copy

  1. int msgQReceive  

  2. (  

  3.     MSG_Q_ID msgQId, /* Message queue ID */  

  4.     char *buffer, /* Pointer to the receive buffer for the message*/  

  5.     UINT maxNBytes, /* Number of bytes in the receive buffer*/  

  6.     int timeout /* Timeout period (ticks) / no-wait / forever */  

  7. )  

4. msgQDelete

[c-sharp] view plain copy

  1. STATUS msgQDelete  
  2. (  
  3.     MSG_Q_ID msgQId /* ID of the message queue to delete */  
  4. )  

Once the msgQDelete() operation is completed, tasks blocked on this message queue, including those blocked on the send queue and receive queue, will be unpended, and the message queue ID will no longer be valid.

III. Recommendations:

  1. Create a dedicated message queue for each task.

  2. All messages intended for a task should be sent to its unique message queue.

  3. Due to the Copy & MaxLength characteristics of message queues, we can store only pointers in the message queue.