This section describes the M2MB APIs to perform OS queue operations.  
More...
| #define | M2MB_OS_Q_INVALID   0 | 
|  | 
| #define | M2MB_OS_Q_INVALID_ATTR   0 | 
|  | 
| #define | M2MB_OS_Q_TX_PRIORITIZE   1 | 
|  | 
| #define | WORD32_FOR_MSG(type)   ( ( sizeof( type ) % 4 ) == 0 ? sizeof( type ) / 4 : sizeof( type ) / 4 + 1 ) | 
|  | 
| #define | BYTES_FOR_MSG(type)   ( 4 * WORD32_FOR_MSG( type ) ) | 
|  | 
| #define | m2mb_os_q_setAttrItem_(h,  args, ...)   m2mb_os_q_setAttrItem( h, CMDS_ARGS( args ) ) | 
|  | 
| enum | M2MB_OS_Q_SEL_CMD_E { M2MB_OS_Q_SEL_CMD_CREATE_ATTR,
 M2MB_OS_Q_SEL_CMD_DEL_ATTR,
 M2MB_OS_Q_SEL_CMD_NAME,
 M2MB_OS_Q_SEL_CMD_USRNAME,
 M2MB_OS_Q_SEL_CMD_MSG_SIZE,
 M2MB_OS_Q_SEL_CMD_QSTART,
 M2MB_OS_Q_SEL_CMD_QSIZE,
 M2MB_OS_Q_SEL_CMD_SUSPENDED_COUNT,
 M2MB_OS_Q_SEL_CMD_1ST_SUSP,
 M2MB_OS_Q_SEL_CMD_ENQUEUED,
 M2MB_OS_Q_SEL_CMD_QROOM,
 M2MB_OS_Q_SEL_CMD_END
 }
 | 
|  | 
| typedef struct M2MB_OS_Q_HANDLE_TAG * | M2MB_OS_Q_HANDLE | 
|  | 
| typedef struct M2MB_OS_Q_ATTR_HANDLE_TAG * | M2MB_OS_Q_ATTR_HANDLE | 
|  | 
| M2MB_OS_RESULT_E | m2mb_os_q_init (M2MB_OS_Q_HANDLE *pQHandle, M2MB_OS_Q_ATTR_HANDLE *pQAttrHandle) | 
|  | Message Queue creation.  More... 
 | 
|  | 
| M2MB_OS_RESULT_E | m2mb_os_q_deinit (M2MB_OS_Q_HANDLE qHandle) | 
|  | Message Queue Deinit or Deletion.  More... 
 | 
|  | 
| M2MB_OS_RESULT_E | m2mb_os_q_rx (M2MB_OS_Q_HANDLE qHandle, void *pDest, UINT32 timeoutTicks) | 
|  | Receive message from the queue.  More... 
 | 
|  | 
| M2MB_OS_RESULT_E | m2mb_os_q_tx (M2MB_OS_Q_HANDLE qHandle, void *pSource, UINT32 timeoutTicks, UINT8 priority) | 
|  | Send message to the queue.  More... 
 | 
|  | 
| M2MB_OS_RESULT_E | m2mb_os_q_hptf (M2MB_OS_Q_HANDLE queueHandle) | 
|  | Prioritize queue suspension list Set HPTF: Highest Priority Task First to receive the message from queue (one shot)  More... 
 | 
|  | 
| M2MB_OS_RESULT_E | m2mb_os_q_clear (M2MB_OS_Q_HANDLE qHandle) | 
|  | Clear all messages from the queue.  More... 
 | 
|  | 
| M2MB_OS_RESULT_E | m2mb_os_q_setAttrItem (M2MB_OS_Q_ATTR_HANDLE *pQAttrHandle, UINT8 nCmds,...) | 
|  | Set specific attribute for queue creation.  More... 
 | 
|  | 
| M2MB_OS_RESULT_E | m2mb_os_q_getItem (M2MB_OS_Q_HANDLE qHandle, M2MB_OS_Q_SEL_CMD_E selCmd, MEM_W *pOut, void *pIn) | 
|  | Get specific properties of the queue.  More... 
 | 
|  | 
| M2MB_OS_RESULT_E | m2mb_os_q_setItem (M2MB_OS_Q_HANDLE qHandle, M2MB_OS_Q_SEL_CMD_E selCmd, void *pIn) | 
|  | Set specific properties of the queue.  More... 
 | 
|  | 
This section describes the M2MB APIs to perform OS queue operations. 
◆ BYTES_FOR_MSG
◆ M2MB_OS_Q_INVALID
      
        
          | #define M2MB_OS_Q_INVALID   0 | 
      
 
 
◆ M2MB_OS_Q_INVALID_ATTR
      
        
          | #define M2MB_OS_Q_INVALID_ATTR   0 | 
      
 
 
◆ m2mb_os_q_setAttrItem_
◆ M2MB_OS_Q_TX_PRIORITIZE
      
        
          | #define M2MB_OS_Q_TX_PRIORITIZE   1 | 
      
 
 
◆ WORD32_FOR_MSG
      
        
          | #define WORD32_FOR_MSG | ( |  | type | ) | ( ( sizeof( type ) % 4 ) == 0 ? sizeof( type ) / 4 : sizeof( type ) / 4 + 1 ) | 
      
 
 
◆ M2MB_OS_Q_ATTR_HANDLE
◆ M2MB_OS_Q_HANDLE
◆ M2MB_OS_Q_SEL_CMD_E
| Enumerator | 
|---|
| M2MB_OS_Q_SEL_CMD_CREATE_ATTR |  | 
| M2MB_OS_Q_SEL_CMD_DEL_ATTR |  | 
| M2MB_OS_Q_SEL_CMD_NAME |  | 
| M2MB_OS_Q_SEL_CMD_USRNAME |  | 
| M2MB_OS_Q_SEL_CMD_MSG_SIZE |  | 
| M2MB_OS_Q_SEL_CMD_QSTART |  | 
| M2MB_OS_Q_SEL_CMD_QSIZE |  | 
| M2MB_OS_Q_SEL_CMD_SUSPENDED_COUNT |  | 
| M2MB_OS_Q_SEL_CMD_1ST_SUSP |  | 
| M2MB_OS_Q_SEL_CMD_ENQUEUED |  | 
| M2MB_OS_Q_SEL_CMD_QROOM |  | 
| M2MB_OS_Q_SEL_CMD_END |  | 
Definition at line 77 of file m2mb_os_q.h.
 
 
◆ m2mb_os_q_clear()
Clear all messages from the queue. 
This service deletes all messages stored in the specified message queue identified by its handle. If the queue is full, messages of all suspended tasks are discarded. Each suspended task is then resumed with a return status that indicates the message send was successful. If the queue is empty, this service does nothing.
- Parameters
- 
  
    | [in] | qHandle | handle of queue to be clear |  
 
- Returns
- M2MB_OS_SUCCESS in case of success 
- 
M2MB_OS_SUCCESS Successful queue operation. M2MB_OS_QUEUE_ERROR Invalid counting queue handle
- Note
- Allowed From Initialization, tasks, timers, and ISRs Preemption Possible Yes
Example 
 
 
 
◆ m2mb_os_q_deinit()
Message Queue Deinit or Deletion. 
This service deletes the specified message queue. All tasks suspended waiting for a message from this queue are resumed with a return value egual to M2MB_OS_DELETED The resources will be released It is the application's responsibility to manage the memory area associated with the queue, which is available after this service completes, if qStart with M2MB_OS_Q_SEL_CMD_QSTART was specified. It is the application's responsibility to prevent use of a deleted queue.
- Parameters
- 
  
    | [in] | qHandle | handle of the queue |  
 
- Returns
- M2MB_OS_SUCCESS in case of success 
- 
M2MB_OS_QUEUE_ERROR Invalid counting queue handle M2MB_OS_INVALID_ARG invalid arguments M2MB_OS_CALLER_ERROR Invalid caller of this service.
- Note
- It is the application's responsibility to prevent use of a deleted queue. Allowed From tasks Preemption Possible Yes
Example 
 
 
 
◆ m2mb_os_q_getItem()
Get specific properties of the queue. 
This service retrieve value for specified parameter of the specified queue Selecting cmd, a parameter to be retrieved can be set To be used when queue is already created: its right use is under application responsibility
- Parameters
- 
  
    | [in] | qHandle | handle of queue |  | [in] | selCmd | Select parameter to be retrieved (see M2MB_OS_Q_SEL_CMD_E) |  | [out] | pOut | pointer Output parameter got: its meaning depend on selCmd used See examples as general pointer it is set to UINT32 |  | [in] | pIn | pointer to void general Parameter to be specified, if any, to get right output See examples If parameter is not needed, use NULL |  
 
- Returns
- M2MB_OS_SUCCESS in case of success (others in case of error : see m2mb_os_types.h) 
- 
M2MB_OS_QUEUE_ERROR Invalid counting queue handle M2MB_OS_INVALID_ARG invalid arguments
- Note
- Not all the M2MB_OS_Q_SEL_CMD_E are always available. Of course M2MB_OS_Q_SEL_CMD_CREATE_ATTR is not right for this function Allowed: M2MB_OS_Q_SEL_CMD_NAME M2MB_OS_Q_SEL_CMD_USRNAME M2MB_OS_Q_SEL_CMD_MSG_SIZE M2MB_OS_Q_SEL_CMD_QSTART M2MB_OS_Q_SEL_CMD_QSIZE M2MB_OS_Q_SEL_CMD_1ST_SUSP M2MB_OS_Q_SEL_CMD_SUSPENDED_COUNT M2MB_OS_Q_SEL_CMD_ENQUEUED M2MB_OS_Q_SEL_CMD_QROOM
Example 
 
 
 
◆ m2mb_os_q_hptf()
Prioritize queue suspension list Set HPTF: Highest Priority Task First to receive the message from queue (one shot) 
This service set the task waiting for this queue which has currently highest priority, on the top of FIFO suspension list
- Parameters
- 
  
    | [in] | queueHandle | handle of queue |  
 
- Returns
- M2MB_OS_SUCCESS in case of success 
- 
M2MB_OS_SUCCESS Successful queue operation. M2MB_OS_QUEUE_ERROR Invalid counting queue handle M2MB_OS_INVALID_ARG invalid oneShot parameter
- Note
- Allowed From Initialization, tasks, timers, and ISRs Preemption Possible No
Example: Set highest priority task waiting on the queue, at the top of FIFO suspension list 
 
 
 
◆ m2mb_os_q_init()
Message Queue creation. 
This service creates a message queue that is typically used for inter- task communication. The total number of messages is calculated from the specified message size and the total number of bytes in the queue. Specifies the size of each message in the queue. Message sizes range from 1 32-bit word to 16 32-bit words. Valid message size options are numerical values from 1 through 16, inclusive.
- Parameters
- 
  
    | [out] | pQHandle | pointer to queue handle |  | [in] | pQAttrHandle | pointer to queue attribute handle |  
 
- Returns
- M2MB_OS_SUCCESS in case of success 
- 
M2MB_OS_QUEUE_ERROR Invalid counting queue handle M2MB_OS_INVALID_ARG invalid arguments M2MB_OS_SIZE_ERROR Size of message queue is invalid: for example no space for at least 1 msg M2MB_OS_CALLER_ERROR Invalid caller of this service.
- Note
- If the total number of bytes specified in the queue’s memory area is not evenly divisible by the specified message size, the remaining bytes in the memory area are not used. After successful queue creation, queue attribute will be deleted, their resources free and pQAttr set to M2MB_OS_Q_INVALID_ATTR Pay attention if start of queue is provided: since message size is multiple of word32 ( 32 bit word ) better to specify q area as UINT32 array, whose size has to be multiple of message size in word32. In case start of q area is not aligned on word32, a space for 1 message can be lost due to internal alignement
Allowed From Initialization and tasks Preemption Possible No
Example 
 #define N_MSG          100
 
 
 
 
 
 
 
 static UINT32  QueueArea[ (N_MSG * 5*4) / 
sizeof( 
UINT32) + 1];  
                                                                 
 or just simply
 static UINT32 QueueArea[ (N_MSG * 5) ]; 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 static UINT32 QueueArea[N_MSG * 5 ];  
                                        
 
     exit(error_creating attribute queueHandle);
                                "Myqueue", msgSize, &QueueArea, sizeof(QueueArea)
                              );
     exit(error_creating attribute queueHandle);
                                "Myqueue", msgSize, &QueueArea, sizeof(QueueArea)
                              );
 
 
 
 
 
 
 
 
 
 
    exit(...)
 
 
 
 
 
 
◆ m2mb_os_q_rx()
Receive message from the queue. 
This service retrieves a message from the specified message queue identified by its handle. The retrieved message is copied from the queue into the memory area specified by the destination pointer. That message is then removed from the queue.
- Parameters
- 
  
    | [in] | qHandle | handle of queue |  | [in] | pDest | pointer to destination where to copy the received message |  | [in] | timeoutTicks | If timeout is specified and messages are not available on queue, task will be suspended for a maximum time of timeout ticks |  
 
- Returns
- M2MB_OS_SUCCESS in case of success (others in case of error : see m2mb_os_types.h) 
- 
M2MB_OS_SUCCESS Successful retrieval of a queue instance. M2MB_OS_DELETED queue was deleted while task was suspended. M2MB_OS_WAIT_ABORTED Suspension was aborted by another task, timer, or ISR. M2MB_OS_QUEUE_ERROR Invalid counting queue handle. M2MB_OS_WAIT_ERROR A wait option other than M2MB_OS_NO_WAIT was specified on a call from a non-task. M2MB_OS_CALLER_ERROR Invalid caller of this service.
- Note
- The specified destination memory area must be large enough to hold the message; i.e., the message destination pointed to by pDest must be at least as large as the message size for this queue. Otherwise, if the destination is not large enough, memory corruption occurs in the following memory area. Allowed From Initialization, tasks, timers and ISRs Preemption Possible Yes
Example 
 
 
 
◆ m2mb_os_q_setAttrItem()
Set specific attribute for queue creation. 
This service set the attribute (or create it) to be used for queue creation Selecting cmd, a parameter to be set can be selected
- Parameters
- 
  
    | [in] | pQAttrHandle | pointer to event attribute of event |  | [in] | nCmds | number of commands to be issued at once |  | [in] | ... | variable inputs, N cmds (see M2MB_OS_Q_SEL_CMD_E) followed by N arguments for their respective issued commands. CMDS(...) and CMDS_ARGS(...) macro can be used to better insert cmd and parameters and to better control right insertion |  
 
- Returns
- M2MB_OS_SUCCESS in case of success 
- 
M2MB_OS_SUCCESS Successful queue operation. M2MB_OS_QUEUE_ERROR Invalid counting queue handle M2MB_OS_INVALID_ARG invalid pQAttr or pIn
- Note
- The attribute set are useful for queue creation. Once created, use instead m2mb_os_q_setItem() to set only available queue properties After m2mb_os_q_init, resources of M2MB_OS_Q_ATTR_HANDLE will be released and handle set to M2MB_OS_Q_INVALID_ATTR It is under application responsibility the right use of m2mb_os_q_setAttrItem. For instance, multi creation of attrHandle withouth free of previous resources ( M2MB_OS_Q_SEL_CMD_CREATE_ATTR without M2MB_OS_Q_SEL_CMD_DEL_ATTR in case no m2mb_os_q_init is used in the between ) will waste memory.
Example 
 static UINT32          QueueArea[100 * 5 ];  
                                               
     exit(error_creating attribute queueHandle);
                                Myqueue", &QueueArea, msgSize, sizeof(QueueArea)
                              )
 // or using CMDS_ARGS(...) macro
 // m2mb_os_q_setAttrItem( &qAttrHandle,
 //                        CMDS_ARGS
 //                        (
 //                          M2MB_OS_Q_SEL_CMD_NAME, "Myqueue",
 //                          M2MB_OS_Q_SEL_CMD_QSTART, &QueueArea,
 //                          M2MB_OS_Q_SEL_CMD_MSG_SIZE, msgSize,
 //                          M2MB_OS_Q_SEL_CMD_QSIZE, sizeof(QueueArea)
 //                        )
 //                       );
if ( osRes != M2MB_OS_SUCCESS )
    exit(...)
 m2mb_os_q_init( &queueHandle, &qAttrHandle );
 
 
◆ m2mb_os_q_setItem()
Set specific properties of the queue. 
This service set value for specified parameter of the specified queue if available Selecting cmd, a parameter to be set can be selected To be used when queue is already created: its right use is under application responsibility
- Parameters
- 
  
    | [in] | qHandle | handle of queue |  | [in] | selCmd | Select parameter to be set (see M2MB_OS_Q_SEL_CMD_E) |  | [in] | pIn | pointer to value to be set. If a simple value, can be easily casted to (void*) e.g. int value -3 has to be passed, use (void*)-3 NULL if no value is needed |  
 
- Returns
- M2MB_OS_SUCCESS in case of success 
- 
M2MB_OS_QUEUE_ERROR Invalid counting queue handle M2MB_OS_INVALID_ARG invalid arguments
- Note
- Not all the M2MB_OS_Q_SEL_CMD_E are always available. Of course M2MB_OS_Q_SEL_CMD_CREATE_ATTR is not right for this function Only M2MB_OS_Q_SEL_CMD_USRNAME is allowed
Example 
 
 
 
◆ m2mb_os_q_tx()
Send message to the queue. 
This service sends a message to the specified message queue identified by its handler. The sent message is copied to the queue from the memory area specified by the pSource pointer. If priority M2MB_OS_Q_TX_PRIORITIZE or a value higher then 0 is selected, the message is placed at the top of the queue, therefore first to be received
- Parameters
- 
  
    | [in] | qHandle | handle of queue |  | [in] | pSource | pointer of Source message to be sent in queue |  | [in] | timeoutTicks | If timeout is specified and there is not room available on queue, task will be suspended for a maximum numbers of timeout ticks |  | [in] | priority | with priority > 0 or M2MB_OS_Q_TX_PRIORITIZE the message is copied to the front of the queue from the memory area specified by the pSource pointer |  
 
- Returns
- M2MB_OS_SUCCESS in case of success 
- 
M2MB_OS_SUCCESS Successful queue put. M2MB_OS_QUEUE_ERROR Invalid queue handle M2MB_OS_CALLER_ERROR Invalid caller of this service. M2MB_OS_QUEUE_FULL Service was unable to send message because the queue was full for the duration of the specified time to wait. M2MB_OS_WAIT_ERROR A wait option other than M2MB_OS_NO_WAIT was specified on a call from a non-task. M2MB_OS_WAIT_ABORTED Suspension was aborted by another task, timer, or ISR.
- Note
- Allowed From Initialization, tasks timers and ISRs Preemption Possible Yes
Example