2 /*
3 Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
4 All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
36 #ifndef _ASP_MSG_MASTER_H_
37 #define _ASP_MSG_MASTER_H_
39 #include <xdc/std.h>
40 #include <ti/sysbios/heaps/HeapBuf.h>
41 #include <ti/sysbios/knl/Event.h>
42 #include <ti/sysbios/syncs/SyncEvent.h>
43 #include <ti/ipc/MessageQ.h>
45 // Error return codes
46 #define ASP_MSG_MASTER_SOK ( 0 )
47 #define ASP_MSG_MASTER_MSGPOOL_MALLOC_FAIL ( -1 )
48 #define ASP_MSG_MASTER_MSGPOOL_HEAPBUF_CREATE_FAIL ( -2 )
49 #define ASP_MSG_MASTER_MSGQ_REGHEAP_FAIL ( -3 )
50 #define ASP_MSG_MASTER_MASTER_MSGQ_CREATE_FAIL ( -4 )
51 #define ASP_MSG_MASTER_SLAVE_MSGQ_OPEN_FAIL ( -5 )
52 #define ASP_MSG_MASTER_SAVEMSGID_MALLOC_FAIL ( -6 )
54 // Error return codes for function AspMsgSend & AspMsgRcvAck
55 #define ASP_MSG_NO_ERR ( 0 )
56 #define ASP_MSG_ERR_QUEUE_ALLOC ( -1 )
57 #define ASP_MSG_ERR_QUEUE_PUT ( -2 )
58 #define ASP_MSG_ERR_QUEUE_GET ( -3 )
59 #define ASP_MSG_ERR_QUEUE_TIMEOUT ( -4 )
60 #define ASP_MSG_ERR_QUEUE_FREE ( -5 )
61 #define ASP_MSG_ERR_ACKNOWLEDGE ( -6 )
62 #define ASP_MSG_ERR_SEND_OVR ( -7 )
63 #define ASP_MSG_ERR_RECEIVE_UND ( -8 )
65 #define ASP_MSG_MASTER_DEF_NUMMSGS ( 4 )
67 // save message info
68 typedef struct AspMsgMaster_SaveMsgInfo
69 {
70 UInt32 sndCmd; // command sent from master to slave
71 UInt32 msgId; // Id contained in LS 31 bits, MS bit is 0
72 } AspMsgMaster_SaveMsgInfo;
74 // module structure
75 typedef struct AspMsgMaster_Module
76 {
77 UInt16 masterProcId; // master processor id
78 UInt16 slaveProcId; // slave processor id
79 MessageQ_Handle masterQue; // created locally
80 MessageQ_QueueId slaveQueId; // created remotely, opened locally
81 UInt16 heapId; // MessageQ heapId
82 UInt16 numMsgs; // maximum number of messages
83 HeapBuf_Handle heap; // message heap
84 Int msgSize; // aligned size of message
85 Int poolSize; // size of message pool
86 Ptr store; // memory store for message pool
87 UInt32 messageId; // Next send message Id. Format: Id contained in LS 31 bits, MS bit is 0.
88 AspMsgMaster_SaveMsgInfo *saveMsgInfo; // Send message info array
89 UInt8 saveMsgWrtIdx; // index of next location in saveMsgInfo[] for write (message send)
90 UInt8 saveMsgRdIdx; // index of next location in saveMsgInfo[] for read (message receive)
91 Int8 numSaveMsgInfo; // number of saved message info
92 SyncEvent_Handle syncEventHandle; // sync event handle
93 Event_Handle eventHandle; // event handle
94 UInt eventId; // event Id
95 } AspMsgMaster_Module;
97 // module handle
98 typedef AspMsgMaster_Module * AspMsgMaster_Handle;
100 // Initialize ASP master messaging
101 Int // returned status
102 AspMsgMaster_init(
103 AspMsgMaster_Handle hAspMsgMaster, // message master handle
104 UInt16 remoteProcId, // remote processor Id
105 UInt16 heapId, // heap Id for message pool
106 UInt16 numMsgs, // number of messages in message pool
107 SyncEvent_Handle syncEventHandle, // sync event handle
108 Event_Handle eventHandle, // event handle
109 UInt eventId // event Id
110 );
112 /*
113 * ASP message send function
114 *
115 * Description:
116 * This function sends a message from the master to the slave processor.
117 */
118 Int // returned status
119 AspMsgSnd(
120 AspMsgMaster_Handle hAspMsgMaster, // message master handle
121 UInt32 sndCmd, // command sent from master to slave
122 char *sndMsgBuf // message buffer for message sent from master to slave
123 );
125 /*
126 * ASP message receive acknowledge function
127 *
128 * Description:
129 * This function receives an acknowledgment message from the slave to the master processor.
130 * The expected acknowledgement is an input to the function.
131 */
132 Int // returned status
133 AspMsgRcvAck(
134 AspMsgMaster_Handle hAspMsgMaster, // message master handle
135 UInt32 ackCmd, // expected acknowledgment sent from slave to master
136 char *ackMsgBuf, // message buffer for acknowledgment message sent from slave to master
137 Bool pendOnEvent // whether to pend on Event synchronizer
138 );
140 /*
141 * ASP message get number of outstanding messages function
142 *
143 * Description:
144 * This function returns the number of messages sent to the slave which haven't yet been acknowledged.
145 */
146 Int // returned status
147 AspMsgGetNumSndMsgUnack(
148 AspMsgMaster_Handle hAspMsgMaster, // message master handle
149 UInt16 *pNumSndMsgUnack // number of unacknowledged messages sent to the slave
150 );
152 /*
153 * ASP message receive acknowledge function
154 *
155 * Description:
156 * This function receives an acknowledgment message from the slave to the master processor.
157 * The receive acknowledgement is output by the function.
158 */
159 Int // returned status
160 AspMsgRcvAckUnk(
161 AspMsgMaster_Handle hAspMsgMaster, // message master handle
162 UInt32 *pAckCmd, // acknowledgment sent from slave to master
163 char *ackMsgBuf, // message buffer for acknowledgment message sent from slave to master
164 Bool pendOnEvent // whether to pend on Event synchronizer
165 );
168 #endif /* _ASP_MSG_MASTER_H_ */