IPC API  3.40.00.06
MessageQ.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2015 Texas Instruments Incorporated - https://www.ti.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
133 #ifndef ti_ipc_MessageQ__include
134 #define ti_ipc_MessageQ__include
135 
136 #include <ti/ipc/MultiProc.h>
137 
138 #if defined (__cplusplus)
139 extern "C" {
140 #endif
141 
142 /* =============================================================================
143  * All success and failure codes for the module
144  * =============================================================================
145  */
146 
150 #define MessageQ_S_BUSY (2)
151 
155 #define MessageQ_S_ALREADYSETUP (1)
156 
160 #define MessageQ_S_SUCCESS (0)
161 
165 #define MessageQ_E_FAIL (-1)
166 
170 #define MessageQ_E_INVALIDARG (-2)
171 
175 #define MessageQ_E_MEMORY (-3)
176 
180 #define MessageQ_E_ALREADYEXISTS (-4)
181 
185 #define MessageQ_E_NOTFOUND (-5)
186 
190 #define MessageQ_E_TIMEOUT (-6)
191 
195 #define MessageQ_E_INVALIDSTATE (-7)
196 
200 #define MessageQ_E_OSFAILURE (-8)
201 
205 #define MessageQ_E_RESOURCE (-9)
206 
210 #define MessageQ_E_RESTART (-10)
211 
215 #define MessageQ_E_INVALIDMSG (-11)
216 
220 #define MessageQ_E_NOTOWNER (-12)
221 
225 #define MessageQ_E_REMOTEACTIVE (-13)
226 
230 #define MessageQ_E_INVALIDHEAPID (-14)
231 
235 #define MessageQ_E_INVALIDPROCID (-15)
236 
240 #define MessageQ_E_MAXREACHED (-16)
241 
245 #define MessageQ_E_UNREGISTEREDHEAPID (-17)
246 
250 #define MessageQ_E_CANNOTFREESTATICMSG (-18)
251 
255 #define MessageQ_E_UNBLOCKED (-19)
256 
260 #define MessageQ_E_SHUTDOWN (-20)
261 
262 /* =============================================================================
263  * Macros
264  * =============================================================================
265  */
266 
270 #define MessageQ_FOREVER (~(0))
271 
275 #define MessageQ_INVALIDMSGID (0xffff)
276 
280 #define MessageQ_INVALIDMESSAGEQ (0xffff)
281 
285 #define MessageQ_PRIORITYMASK (0x3)
286 
297 #define MessageQ_PORTOFFSET (0x80)
298 
324 #define MessageQ_getDstQueue(msg) \
325  (((MessageQ_Msg)(msg))->dstId == \
326  (MessageQ_QueueIndex)MessageQ_INVALIDMESSAGEQ) ? \
327  (MessageQ_QueueId)MessageQ_INVALIDMESSAGEQ : \
328  (((MessageQ_QueueId)((MessageQ_Msg)(msg))->dstProc << 16u) \
329  | (((MessageQ_Msg)(msg))->dstId))
330 
331 
346 #define MessageQ_getMsgId(msg) (((MessageQ_Msg) (msg))->msgId)
347 
356 #define MessageQ_getMsgSize(msg) (((MessageQ_Msg) (msg))->msgSize)
357 
365 #define MessageQ_getMsgPri(msg) \
366  ((((MessageQ_Msg) (msg))->flags & MessageQ_PRIORITYMASK))
367 
378 #define MessageQ_getProcId(queueId) \
379  ((UInt16)((queueId) >> 16))
380 
410 #define MessageQ_getQueueIndex(queueId) \
411  (((MessageQ_QueueIndex)((MessageQ_QueueId)0xFFFF & (queueId))) \
412  - MessageQ_PORTOFFSET)
413 
431 #define MessageQ_getReplyQueue(msg) \
432  (MessageQ_QueueId)((((MessageQ_Msg) (msg))->replyProc << 16u) \
433  | ((MessageQ_Msg)(msg))->replyId)
434 
443 #define MessageQ_getTransportId(msg) \
444  ((((MessageQ_Msg)(msg))->flags & (0x7 << 2)) >> 2)
445 
458 #define MessageQ_setMsgId(msg, id) ((MessageQ_Msg) (msg))->msgId = (id)
459 
466 #define MessageQ_setMsgPri(msg, priority) \
467  ((MessageQ_Msg)(msg))->flags = \
468  (((MessageQ_Msg)(msg))->flags & ~(MessageQ_PRIORITYMASK)) \
469  | ((priority) & MessageQ_PRIORITYMASK)
470 
484 #define MessageQ_setTransportId(msg, tid) \
485  ((MessageQ_Msg)(msg))->flags = \
486  ((((MessageQ_Msg)(msg))->flags & ~(0x7 << 2)) | ((tid) << 2))
487 
488 /* =============================================================================
489  * Structures & Enums
490  * =============================================================================
491  */
492 
496 typedef UInt32 MessageQ_QueueId;
497 
501 typedef UInt16 MessageQ_QueueIndex;
502 
506 typedef struct MessageQ_Object *MessageQ_Handle;
507 
511 typedef struct {
513  Int __version;
514  /* Used internally for tracking implementation evolution.
515  * For internal use only.
516  */
528  MessageQ_QueueIndex queueIndex;
544 
546 /* Date: 02 Dec 2014
547  *
548  * Initial implementation of params structure which contains
549  * a version field. This allows for binary compatibility as
550  * the params structure is modified in the future.
551  */
552 #define MessageQ_Params_VERSION_2 2
553 
559 #define MessageQ_Params_VERSION MessageQ_Params_VERSION_2
560 
571 typedef struct {
581  MessageQ_QueueIndex queueIndex;
597 
601 typedef struct {
602  Bits32 reserved0;
603  Bits32 reserved1;
604  Bits32 msgSize;
605  Bits16 flags;
606  Bits16 msgId;
607  Bits16 dstId;
608  Bits16 dstProc;
609  Bits16 replyId;
610  Bits16 replyProc;
611  Bits16 srcProc;
612  Bits16 heapId;
613  Bits16 seqNum;
614  Bits16 reserved;
616 
621 
625 typedef enum {
631 
638 #define MessageQ_ANY (Bits16)~(0)
639 
646 typedef Void (*MessageQ_FreeHookFxn)(Bits16 heapId, Bits16 msgId);
647 
658 typedef Void (*MessageQ_PutHookFxn)(MessageQ_QueueId queueId, MessageQ_Msg msg);
659 
660 #ifdef STD_H
661 #include <ti/ipc/interfaces/ITransport.h>
662 #include <ti/ipc/interfaces/IMessageQTransport.h>
663 #else
664 #include <ti/sdo/ipc/interfaces/ITransport.h>
665 #include <ti/sdo/ipc/interfaces/IMessageQTransport.h>
666 #endif
667 
668 Bool MessageQ_registerTransport(IMessageQTransport_Handle handle,
669  UInt16 rprocId, UInt priority);
670 Void MessageQ_unregisterTransport(UInt16 rprocId, UInt priority);
671 
672 
673 /* =============================================================================
674  * MessageQ Module-wide Functions
675  * =============================================================================
676  */
677 
679 /* Returns the local handle associated with queueId. */
680 MessageQ_Handle MessageQ_getLocalHandle(MessageQ_QueueId queueId);
685 Void MessageQ_Params_init__S(MessageQ_Params *params, Int version);
695 #ifndef MessageQ_internal
696 static inline Void MessageQ_Params_init(MessageQ_Params *params)
697 {
698  if (params != NULL) {
699  MessageQ_Params_init__S(params, MessageQ_Params_VERSION);
700  }
701 }
702 #endif
703 
715 
732 MessageQ_Handle MessageQ_create(String name, const MessageQ_Params *params);
733 
753 MessageQ_Handle MessageQ_create2(String name, const MessageQ_Params2 *params);
754 
768 Int MessageQ_delete(MessageQ_Handle *handlePtr);
769 
787 Int MessageQ_open(String name, MessageQ_QueueId *queueId);
788 
828 MessageQ_QueueId MessageQ_openQueueId(UInt16 queueIndex, UInt16 procId);
829 
841 Int MessageQ_close(MessageQ_QueueId *queueId);
842 
865 MessageQ_Msg MessageQ_alloc(UInt16 heapId, UInt32 size);
866 
878 Int MessageQ_free(MessageQ_Msg msg);
879 
907 Int MessageQ_registerHeap(Ptr heap, UInt16 heapId);
908 
929 Bool MessageQ_registerTransportId(UInt tid, ITransport_Handle inst);
930 
944 Int MessageQ_unregisterHeap(UInt16 heapId);
945 
955 Void MessageQ_unregisterTransportId(UInt tid);
956 
967 Void MessageQ_setMsgTrace(MessageQ_Msg msg, Bool traceFlag);
968 
993 Void MessageQ_staticMsgInit(MessageQ_Msg msg, UInt32 size);
994 
1014 
1028 
1029 /* =============================================================================
1030  * MessageQ Per-instance Functions
1031  * =============================================================================
1032  */
1033 
1066 Int MessageQ_get(MessageQ_Handle handle, MessageQ_Msg *msg, UInt timeout);
1067 
1096 Int MessageQ_put(MessageQ_QueueId queueId, MessageQ_Msg msg);
1097 
1107 Int MessageQ_count(MessageQ_Handle handle);
1108 
1121 UInt32 MessageQ_getQueueId(MessageQ_Handle handle);
1122 
1140 Void MessageQ_setReplyQueue(MessageQ_Handle handle, MessageQ_Msg msg);
1141 
1169 Void MessageQ_unblock(MessageQ_Handle handle);
1170 
1203 Void MessageQ_shutdown(MessageQ_Handle handle);
1204 
1205 #if defined (__cplusplus)
1206 }
1207 #endif /* defined (__cplusplus) */
1208 #endif /* ti_ipc_MessageQ__include */
Int MessageQ_free(MessageQ_Msg msg)
Frees a message back to the heap.
Bits16 replyProc
Definition: MessageQ.h:610
Bits16 reserved
Definition: MessageQ.h:614
Int MessageQ_get(MessageQ_Handle handle, MessageQ_Msg *msg, UInt timeout)
Gets a message from the message queue.
Void MessageQ_setFreeHookFxn(MessageQ_FreeHookFxn freeHookFxn)
Sets MessageQ's free hook function.
MessageQ_Priority
Message priority.
Definition: MessageQ.h:625
Structure defining parameters for MessageQ_create().
Definition: MessageQ.h:511
Bits16 dstId
Definition: MessageQ.h:607
Int MessageQ_delete(MessageQ_Handle *handlePtr)
Delete a created MessageQ instance.
MessageQ_Handle MessageQ_create2(String name, const MessageQ_Params2 *params)
Create a MessageQ instance using the type MessageQ_Params2.
Int MessageQ_open(String name, MessageQ_QueueId *queueId)
Open a message queue.
Void MessageQ_unregisterTransport(UInt16 rprocId, UInt priority)
Definition: MessageQ.h:629
Int MessageQ_registerHeap(Ptr heap, UInt16 heapId)
Register a heap with MessageQ.
Bits32 msgSize
Definition: MessageQ.h:604
Definition: MessageQ.h:627
Void * synchronizer
Definition: MessageQ.h:519
Void(* MessageQ_PutHookFxn)(MessageQ_QueueId queueId, MessageQ_Msg msg)
Put hook function definition.
Definition: MessageQ.h:658
UInt32 MessageQ_getQueueId(MessageQ_Handle handle)
Returns the QueueId associated with the handle.
UInt16 MessageQ_QueueIndex
Local queue index.
Definition: MessageQ.h:501
Void(* MessageQ_FreeHookFxn)(Bits16 heapId, Bits16 msgId)
Free hook prototype.
Definition: MessageQ.h:646
MessageQ_MsgHeader * MessageQ_Msg
Typedef for ease of use.
Definition: MessageQ.h:620
Definition: MessageQ.h:626
Bool MessageQ_registerTransportId(UInt tid, ITransport_Handle inst)
Register a transport instance for the given ID.
Bits16 seqNum
Definition: MessageQ.h:613
struct MessageQ_Object * MessageQ_Handle
MessageQ_Handle type.
Definition: MessageQ.h:506
Bits16 flags
Definition: MessageQ.h:605
MessageQ_Msg MessageQ_alloc(UInt16 heapId, UInt32 size)
Allocates a message from the heap.
Int MessageQ_count(MessageQ_Handle handle)
Returns the number of messages in a message queue.
Void * synchronizer
Definition: MessageQ.h:572
Processor ID Manager.
Void MessageQ_setPutHookFxn(MessageQ_PutHookFxn putHookFxn)
Set the function hook for the MessageQ_put() method.
Void MessageQ_Params2_init(MessageQ_Params2 *params)
Initialize MessageQ_Params2.
Void MessageQ_unblock(MessageQ_Handle handle)
Unblocks a MessageQ.
UInt32 MessageQ_QueueId
A 32-bit value that uniquely identifies a message queue.
Definition: MessageQ.h:496
Int MessageQ_put(MessageQ_QueueId queueId, MessageQ_Msg msg)
Place a message onto a message queue.
Required first field in every message.
Definition: MessageQ.h:601
Bits16 heapId
Definition: MessageQ.h:612
MessageQ_QueueIndex queueIndex
Definition: MessageQ.h:581
Void MessageQ_shutdown(MessageQ_Handle handle)
Shuts down a MessageQ.
Structure defining parameters for MessageQ_create2().
Definition: MessageQ.h:571
Void MessageQ_unregisterTransportId(UInt tid)
Unregister the transport instance for the given ID.
Int MessageQ_unregisterHeap(UInt16 heapId)
Unregister a heap with MessageQ.
MessageQ_QueueIndex queueIndex
Definition: MessageQ.h:528
Definition: MessageQ.h:628
Int MessageQ_close(MessageQ_QueueId *queueId)
Close the opened handle.
Bits32 reserved1
Definition: MessageQ.h:603
MessageQ_QueueId MessageQ_openQueueId(UInt16 queueIndex, UInt16 procId)
Open a MessageQ given the queue index and processor ID.
Bits16 msgId
Definition: MessageQ.h:606
Void MessageQ_setReplyQueue(MessageQ_Handle handle, MessageQ_Msg msg)
Embeds a source message queue into a message.
Bits16 replyId
Definition: MessageQ.h:609
MessageQ_Handle MessageQ_create(String name, const MessageQ_Params *params)
Create a MessageQ instance.
Bits16 dstProc
Definition: MessageQ.h:608
Bits32 reserved0
Definition: MessageQ.h:602
Bits16 srcProc
Definition: MessageQ.h:611
Void MessageQ_staticMsgInit(MessageQ_Msg msg, UInt32 size)
Initializes a message not obtained from MessageQ_alloc()
Bool MessageQ_registerTransport(IMessageQTransport_Handle handle, UInt16 rprocId, UInt priority)
Void MessageQ_setMsgTrace(MessageQ_Msg msg, Bool traceFlag)
Sets the message tracing flag on a given message.
Copyright 2015, Texas Instruments Incorporated