1 /*
2 * Copyright (c) 2012-2015 Texas Instruments Incorporated - http://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 /*
33 * ======== Ipc.xs ========
34 *
35 */
37 var Ipc = null;
38 var Notify = null;
39 var SharedRegion = null;
40 var MessageQ = null;
41 var MultiProc = null;
42 var NameServer = null;
43 var Settings = null;
44 var Cache = null;
45 var Hwi = null;
47 var initEntryDone = false;
49 /*
50 * ======== module$meta$init ========
51 */
52 function module$meta$init()
53 {
54 /* Only process during "cfg" phase */
55 if (xdc.om.$name != "cfg") {
56 return;
57 }
59 Ipc = this;
61 Ipc.entry.length = 0;
63 Settings = xdc.module("ti.sdo.ipc.family.Settings");
65 /* determine if slave data is needed to be generated for host */
66 Ipc.generateSlaveDataForHost = Settings.generateSlaveDataForHost();
68 /* Set Ipc.sr0MemorySetup based on device defaults */
69 var sr0MemorySetup = Settings.getIpcSR0Setup();
70 if (sr0MemorySetup) {
71 Ipc.sr0MemorySetup = true;
72 }
73 else {
74 Ipc.sr0MemorySetup = false;
75 }
76 }
78 /*
79 * ======== module$use ========
80 */
81 function module$use()
82 {
83 SharedRegion = xdc.useModule("ti.sdo.ipc.SharedRegion");
84 Cache = xdc.useModule("ti.sysbios.hal.Cache");
85 Hwi = xdc.useModule("ti.sysbios.hal.Hwi");
86 Notify = xdc.useModule("ti.sdo.ipc.Notify");
87 MessageQ = xdc.useModule("ti.sdo.ipc.MessageQ");
88 MultiProc = xdc.useModule("ti.sdo.utils.MultiProc");
89 NameServer = xdc.useModule("ti.sdo.utils.NameServer");
90 Settings = xdc.useModule("ti.sdo.ipc.family.Settings");
92 if (!(NameServer.SetupProxy.$written("delegate$"))) {
93 NameServer.SetupProxy =
94 xdc.useModule(Settings.getNameServerRemoteDelegate());
95 }
97 /* get the host processor id */
98 Ipc.hostProcId = Settings.getHostProcId();
99 }
101 /*
102 * ======== module$static$init ========
103 * Initialize module values.
104 */
105 function module$static$init(state, mod)
106 {
107 var fxn = new Ipc.UserFxn;
108 var userFxnSet = false;
110 /* set user's default attach/detach funtions */
111 if (Ipc.userFxn.attach == undefined) {
112 Ipc.userFxn.attach = null;
113 fxn.attach = null;
114 }
115 else {
116 fxn.attach = Ipc.userFxn.attach;
117 userFxnSet = true;
118 }
120 if (Ipc.userFxn.detach == undefined) {
121 Ipc.userFxn.detach = null;
122 fxn.detach = null;
123 }
124 else {
125 fxn.detach = Ipc.userFxn.detach;
126 userFxnSet = true;
127 }
129 if (userFxnSet) {
130 Ipc.$logWarning("Ipc.userFxn is deprecated. The recommended way " +
131 "to add an attach/detach function is by using " +
132 "Ipc.addUserFxn(fxn, arg).", Ipc);
133 addUserFxn(fxn, null);
134 }
136 /* init Ipc.entry */
137 initEntryArray();
139 /* initialize the procEntry[] array */
140 state.procEntry.length = MultiProc.numProcsInCluster;
142 for (var i = 0; i < state.procEntry.length; i++) {
143 state.procEntry[i].entry = Ipc.entry[i];
144 state.procEntry[i].localConfigList = null;
145 state.procEntry[i].remoteConfigList = null;
146 state.procEntry[i].attached = 0;
147 }
149 state.ipcSharedAddr = null;
150 state.gateMPSharedAddr = null;
151 Ipc.numUserFxns = Ipc.userFxns.length;
152 }
154 /*
155 * ======== addUserFxn ========
156 */
157 function addUserFxn(fxn, arg)
158 {
159 Ipc.userFxns.$add({userFxn: fxn, arg: arg});
160 }
162 /*
163 * ======== setEntryMeta ========
164 * MultiProc.numProcessors must be set before calling this function
165 */
166 function setEntryMeta(entry)
167 {
168 var MultiProc = xdc.module("ti.sdo.utils.MultiProc");
170 if (entry.remoteProcId == undefined) {
171 Ipc.$logError("Ipc.setEntryMeta: remoteProcId was not specified.\n",
172 Ipc);
173 }
175 /* Log an error if the specified remoteProcId is invalid */
176 if (entry.remoteProcId > MultiProc.numProcessors) {
177 Ipc.$logError("Ipc.setEntryMeta: Invalid remoteProcId was " +
178 "specified.\n", Ipc);
179 }
181 /* init Ipc.entry */
182 initEntryArray();
184 if (MultiProc.baseIdOfCluster == MultiProc.INVALIDID) {
185 Ipc.$logError("Cannot use Ipc.setEntryMeta when "
186 + "MultiProc.baseIdOfCluster is INVALIDID.", Ipc);
187 }
189 var clusterId = entry.remoteProcId - MultiProc.baseIdOfCluster;
191 if (entry.setupNotify != undefined) {
192 Ipc.entry[clusterId].setupNotify = entry.setupNotify;
193 }
195 if (entry.setupMessageQ != undefined) {
196 Ipc.entry[clusterId].setupMessageQ = entry.setupMessageQ;
197 }
198 }
200 /*
201 * ======== initEntryArray ========
202 * This is an internal function. This function is called from
203 * setEntryMeta and module$static$init
204 */
205 function initEntryArray()
206 {
207 var MultiProc = xdc.module("ti.sdo.utils.MultiProc");
209 /* init Ipc.entry if its not already initialized */
210 if (!(initEntryDone)) {
211 Ipc.entry.length = MultiProc.numProcsInCluster;
213 for (var i = 0; i < MultiProc.numProcsInCluster; i++) {
214 Ipc.entry[i].remoteProcId =
215 (MultiProc.baseIdOfCluster == MultiProc.INVALIDID) ?
216 MultiProc.INVALIDID : MultiProc.baseIdOfCluster + i;
217 Ipc.entry[i].setupNotify = true;
218 Ipc.entry[i].setupMessageQ = true;
219 }
221 initEntryDone = true;
222 }
223 }
225 /*
226 * ======== getObjTypeStr$view ========
227 */
228 function getObjTypeStr$view(type)
229 {
230 var typeStr;
232 switch(type) {
233 case this.ObjType_CREATESTATIC:
234 typeStr = "CREATESTATIC";
235 break;
236 case this.ObjType_CREATESTATIC_REGION:
237 typeStr = "CREATESTATIC";
238 break;
239 case this.ObjType_CREATEDYNAMIC:
240 typeStr = "CREATEDYNAMIC";
241 break;
242 case this.ObjType_CREATEDYNAMIC_REGION:
243 typeStr = "CREATEDYNAMIC_REGION";
244 break;
245 case this.ObjType_OPENDYNAMIC:
246 typeStr = "OPENDYNAMIC";
247 break;
248 case this.ObjType_LOCAL:
249 typeStr = "LOCAL";
250 break;
251 default:
252 typeStr = null;
253 }
255 return (typeStr);
256 }
258 /*
259 * ======== viewInitModule ========
260 */
261 function viewInitModule(view)
262 {
263 var Program = xdc.useModule('xdc.rov.Program');
264 var Ipc = xdc.useModule('ti.sdo.ipc.Ipc');
265 var SharedRegion = xdc.useModule('ti.sdo.ipc.SharedRegion');
266 var MultiProc = Program.getModuleConfig('ti.sdo.utils.MultiProc');
268 /* Scan the raw view in order to obtain the module state. */
269 var rawView;
270 try {
271 rawView = Program.scanRawView('ti.sdo.ipc.Ipc');
272 }
273 catch (e) {
274 var entryView = Program.newViewStruct('ti.sdo.ipc.Ipc',
275 'Module');
276 Program.displayError(entryView, 'remoteProcId',
277 "Problem retrieving raw view: " + e);
278 view.elements.$add(entryView);
279 return;
280 }
282 var mod = rawView.modState;
284 /* Retrieve the processor entry table */
285 try {
286 var entries = Program.fetchArray(Ipc.ProcEntry$fetchDesc,
287 mod.procEntry,
288 MultiProc.numProcsInCluster);
289 }
290 catch (e) {
291 var entryView = Program.newViewStruct('ti.sdo.ipc.Ipc',
292 'Module');
293 Program.displayError(entryView, 'remoteProcId',
294 "Caught exception while trying to retrieve entry table: " + e);
295 view.elements.$add(entryView);
296 return;
297 }
299 /* Display each of the remote entries */
300 for (var i = 0; i < entries.length; i++) {
301 if (i != MultiProc.id) {
302 var entry = entries[i].entry;
304 var entryView = Program.newViewStruct('ti.sdo.ipc.Ipc',
305 'Module');
307 entryView.remoteProcId = entry.remoteProcId;
308 if (entries[i].attached) {
309 entryView.attached = true;
310 }
311 else {
312 entryView.attached = false;
313 }
314 entryView.setupNotify = entry.setupNotify;
315 entryView.setupMessageQ = entry.setupMessageQ;
317 view.elements.$add(entryView);
318 }
319 }
320 }