IPC API  3.35.01.07
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
257 /* =============================================================================
258  * Macros
259  * =============================================================================
260  */
261 
265 #define MessageQ_FOREVER (~(0))
266 
270 #define MessageQ_INVALIDMSGID (0xffff)
271 
275 #define MessageQ_INVALIDMESSAGEQ (0xffff)
276 
280 #define MessageQ_PRIORITYMASK (0x3)
281 
292 #define MessageQ_PORTOFFSET (0x80)
293 
319 #define MessageQ_getDstQueue(msg) \
320  (((MessageQ_Msg)(msg))->dstId == \
321  (MessageQ_QueueIndex)MessageQ_INVALIDMESSAGEQ) ? \
322  (MessageQ_QueueId)MessageQ_INVALIDMESSAGEQ : \
323  (((MessageQ_QueueId)((MessageQ_Msg)(msg))->dstProc << 16u) \
324  | (((MessageQ_Msg)(msg))->dstId))
325 
326 
341 #define MessageQ_getMsgId(msg) (((MessageQ_Msg) (msg))->msgId)
342 
351 #define MessageQ_getMsgSize(msg) (((MessageQ_Msg) (msg))->msgSize)
352 
360 #define MessageQ_getMsgPri(msg) \
361  ((((MessageQ_Msg) (msg))->flags & MessageQ_PRIORITYMASK))
362 
373 #define MessageQ_getProcId(queueId) \
374  ((UInt16)((queueId) >> 16))
375 
405 #define MessageQ_getQueueIndex(queueId) \
406  (((MessageQ_QueueIndex)((MessageQ_QueueId)0xFFFF & (queueId))) \
407  - MessageQ_PORTOFFSET)
408 
426 #define MessageQ_getReplyQueue(msg) \
427  (MessageQ_QueueId)((((MessageQ_Msg) (msg))->replyProc << 16u) \
428  | ((MessageQ_Msg)(msg))->replyId)
429 
438 #define MessageQ_getTransportId(msg) \
439  ((((MessageQ_Msg)(msg))->flags & (0x7 << 2)) >> 2)
440 
453 #define MessageQ_setMsgId(msg, id) ((MessageQ_Msg) (msg))->msgId = (id)
454 
461 #define MessageQ_setMsgPri(msg, priority) \
462  ((MessageQ_Msg)(msg))->flags = \
463  (((MessageQ_Msg)(msg))->flags & ~(MessageQ_PRIORITYMASK)) \
464  | ((priority) & MessageQ_PRIORITYMASK)
465 
479 #define MessageQ_setTransportId(msg, tid) \
480  ((MessageQ_Msg)(msg))->flags = \
481  ((((MessageQ_Msg)(msg))->flags & ~(0x7 << 2)) | ((tid) << 2))
482 
483 /* =============================================================================
484  * Structures & Enums
485  * =============================================================================
486  */
487 
491 typedef UInt32 MessageQ_QueueId;
492 
496 typedef UInt16 MessageQ_QueueIndex;
497 
501 typedef struct MessageQ_Object *MessageQ_Handle;
502 
506 typedef struct {
508  Int __version;
509  /* Used internally for tracking implementation evolution.
510  * For internal use only.
511  */
523  MessageQ_QueueIndex queueIndex;
539 
541 /* Date: 02 Dec 2014
542  *
543  * Initial implementation of params structure which contains
544  * a version field. This allows for binary compatibility as
545  * the params structure is modified in the future.
546  */
547 #define MessageQ_Params_VERSION_2 2
548 
554 #define MessageQ_Params_VERSION MessageQ_Params_VERSION_2
555 
566 typedef struct {
576  MessageQ_QueueIndex queueIndex;
592 
596 typedef struct {
597  Bits32 reserved0;
598  Bits32 reserved1;
599  Bits32 msgSize;
600  Bits16 flags;
601  Bits16 msgId;
602  Bits16 dstId;
603  Bits16 dstProc;
604  Bits16 replyId;
605  Bits16 replyProc;
606  Bits16 srcProc;
607  Bits16 heapId;
608  Bits16 seqNum;
609  Bits16 reserved;
611 
616 
620 typedef enum {
626 
633 #define MessageQ_ANY (Bits16)~(0)
634 
641 typedef Void (*MessageQ_FreeHookFxn)(Bits16 heapId, Bits16 msgId);
642 
653 typedef Void (*MessageQ_PutHookFxn)(MessageQ_QueueId queueId, MessageQ_Msg msg);
654 
655 #ifdef STD_H
656 #include <ti/ipc/interfaces/ITransport.h>
657 #include <ti/ipc/interfaces/IMessageQTransport.h>
658 #else
659 #include <ti/sdo/ipc/interfaces/ITransport.h>
660 #include <ti/sdo/ipc/interfaces/IMessageQTransport.h>
661 #endif
662 
663 Bool MessageQ_registerTransport(IMessageQTransport_Handle handle,
664  UInt16 rprocId, UInt priority);
665 Void MessageQ_unregisterTransport(UInt16 rprocId, UInt priority);
666 
667 
668 /* =============================================================================
669  * MessageQ Module-wide Functions
670  * =============================================================================
671  */
672 
674 Void MessageQ_Params_init__S(MessageQ_Params *params, Int version);
684 #ifndef MessageQ_internal
685 static inline Void MessageQ_Params_init(MessageQ_Params *params)
686 {
687  if (params != NULL) {
688  MessageQ_Params_init__S(params, MessageQ_Params_VERSION);
689  }
690 }
691 #endif
692 
704 
721 MessageQ_Handle MessageQ_create(String name, const MessageQ_Params *params);
722 
742 MessageQ_Handle MessageQ_create2(String name, const MessageQ_Params2 *params);
743 
757 Int MessageQ_delete(MessageQ_Handle *handlePtr);
758 
776 Int MessageQ_open(String name, MessageQ_QueueId *queueId);
777 
816 MessageQ_QueueId MessageQ_openQueueId(UInt16 queueIndex, UInt16 procId);
817 
829 Int MessageQ_close(MessageQ_QueueId *queueId);
830 
853 MessageQ_Msg MessageQ_alloc(UInt16 heapId, UInt32 size);
854 
866 Int MessageQ_free(MessageQ_Msg msg);
867 
895 Int MessageQ_registerHeap(Ptr heap, UInt16 heapId);
896 
917 Bool MessageQ_registerTransportId(UInt tid, ITransport_Handle inst);
918 
932 Int MessageQ_unregisterHeap(UInt16 heapId);
933 
943 Void MessageQ_unregisterTransportId(UInt tid);
944 
955 Void MessageQ_setMsgTrace(MessageQ_Msg msg, Bool traceFlag);
956 
981 Void MessageQ_staticMsgInit(MessageQ_Msg msg, UInt32 size);
982 
1002 
1016 
1017 /* =============================================================================
1018  * MessageQ Per-instance Functions
1019  * =============================================================================
1020  */
1021 
1051 Int MessageQ_get(MessageQ_Handle handle, MessageQ_Msg *msg, UInt timeout);
1052 
1081 Int MessageQ_put(MessageQ_QueueId queueId, MessageQ_Msg msg);
1082 
1092 Int MessageQ_count(MessageQ_Handle handle);
1093 
1106 UInt32 MessageQ_getQueueId(MessageQ_Handle handle);
1107 
1125 Void MessageQ_setReplyQueue(MessageQ_Handle handle, MessageQ_Msg msg);
1126 
1153 Void MessageQ_unblock(MessageQ_Handle handle);
1154 
1155 #if defined (__cplusplus)
1156 }
1157 #endif /* defined (__cplusplus) */
1158 #endif /* ti_ipc_MessageQ__include */
Int MessageQ_free(MessageQ_Msg msg)
Frees a message back to the heap.
Bits16 replyProc
Definition: MessageQ.h:605
Void(* MessageQ_PutHookFxn)(MessageQ_QueueId queueId, MessageQ_Msg msg)
Put hook function definition.
Definition: MessageQ.h:653
Bits16 reserved
Definition: MessageQ.h:609
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&#39;s free hook function.
MessageQ_Priority
Message priority.
Definition: MessageQ.h:620
Structure defining parameters for MessageQ_create().
Definition: MessageQ.h:506
Bits16 dstId
Definition: MessageQ.h:602
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:624
Int MessageQ_registerHeap(Ptr heap, UInt16 heapId)
Register a heap with MessageQ.
Bits32 msgSize
Definition: MessageQ.h:599
Definition: MessageQ.h:622
Void * synchronizer
Definition: MessageQ.h:514
UInt32 MessageQ_getQueueId(MessageQ_Handle handle)
Returns the QueueId associated with the handle.
UInt16 MessageQ_QueueIndex
Local queue index.
Definition: MessageQ.h:496
MessageQ_MsgHeader * MessageQ_Msg
Typedef for ease of use.
Definition: MessageQ.h:615
Definition: MessageQ.h:621
Bool MessageQ_registerTransportId(UInt tid, ITransport_Handle inst)
Register a transport instance for the given ID.
Bits16 seqNum
Definition: MessageQ.h:608
Void(* MessageQ_FreeHookFxn)(Bits16 heapId, Bits16 msgId)
Free hook prototype.
Definition: MessageQ.h:641
struct MessageQ_Object * MessageQ_Handle
MessageQ_Handle type.
Definition: MessageQ.h:501
Bits16 flags
Definition: MessageQ.h:600
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:567
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:491
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:596
Bits16 heapId
Definition: MessageQ.h:607
MessageQ_QueueIndex queueIndex
Definition: MessageQ.h:576
Structure defining parameters for MessageQ_create2().
Definition: MessageQ.h:566
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:523
Definition: MessageQ.h:623
Int MessageQ_close(MessageQ_QueueId *queueId)
Close the opened handle.
Bits32 reserved1
Definition: MessageQ.h:598
MessageQ_QueueId MessageQ_openQueueId(UInt16 queueIndex, UInt16 procId)
Opens a MessageQ given the queue index and remote processor ID.
Bits16 msgId
Definition: MessageQ.h:601
Void MessageQ_setReplyQueue(MessageQ_Handle handle, MessageQ_Msg msg)
Embeds a source message queue into a message.
Bits16 replyId
Definition: MessageQ.h:604
MessageQ_Handle MessageQ_create(String name, const MessageQ_Params *params)
Create a MessageQ instance.
Bits16 dstProc
Definition: MessageQ.h:603
Bits32 reserved0
Definition: MessageQ.h:597
Bits16 srcProc
Definition: MessageQ.h:606
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