1 /*
2 * Copyright (c) 2012-2014, Texas Instruments Incorporated
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 * ======== GateMP.xs ========
34 *
35 */
37 var GateMP = null;
38 var NameServer = null;
39 var MultiProc = null;
40 var GateAll = null;
41 var GateSwi = null;
42 var GateMutexPri = null;
43 var GateNull = null;
44 var SharedRegion = null;
45 var Ipc = null;
46 var Settings = null;
48 var instCount = 0; /* use to determine if processing last instance */
50 /*!
51 * ======== module$use ========
52 */
53 function module$use()
54 {
55 GateMP = this;
56 NameServer = xdc.useModule("ti.sdo.utils.NameServer");
57 MultiProc = xdc.useModule("ti.sdo.utils.MultiProc");
58 SharedRegion = xdc.useModule("ti.sdo.ipc.SharedRegion");
59 Settings = xdc.useModule("ti.sdo.ipc.family.Settings");
61 /* For local protection */
62 GateMutexPri = xdc.useModule('ti.sysbios.gates.GateMutexPri');
63 GateSwi = xdc.useModule('ti.sysbios.gates.GateSwi');
64 GateAll = xdc.useModule('ti.sysbios.gates.GateAll');
65 GateNull = xdc.useModule('xdc.runtime.GateNull');
67 /* Asserts, errors, etc */
68 Ipc = xdc.useModule('ti.sdo.ipc.Ipc');
70 if (GateMP.RemoteSystemProxy == null) {
71 var gateDel = Settings.getHWGate();
72 GateMP.RemoteSystemProxy = xdc.module(gateDel);
73 }
75 if (GateMP.RemoteCustom1Proxy == null) {
76 GateMP.RemoteCustom1Proxy
77 = xdc.module('ti.sdo.ipc.gates.GatePeterson');
78 }
80 if (GateMP.RemoteCustom2Proxy == null) {
81 GateMP.RemoteCustom2Proxy
82 = xdc.module('ti.sdo.ipc.gates.GateMPSupportNull');
83 }
84 }
86 /*!
87 * ======== module$static$init ========
88 */
89 function module$static$init(mod, params)
90 {
91 /* Might be changed below */
92 mod.nameServer = null;
93 for (var i = 0; i < GateMP.ProxyOrder_NUM; i++) {
94 mod.proxyMap[i] = i;
95 }
97 /* See if any of the proxies are the same */
98 if (GateMP.RemoteCustom1Proxy.delegate$.$name ==
99 GateMP.RemoteSystemProxy.delegate$.$name) {
100 mod.proxyMap[GateMP.ProxyOrder_CUSTOM1] =
101 mod.proxyMap[GateMP.ProxyOrder_SYSTEM];
102 }
104 if (GateMP.RemoteCustom2Proxy.delegate$.$name ==
105 GateMP.RemoteSystemProxy.delegate$.$name) {
106 mod.proxyMap[GateMP.ProxyOrder_CUSTOM2] =
107 mod.proxyMap[GateMP.ProxyOrder_SYSTEM];
108 }
109 else if (GateMP.RemoteCustom2Proxy.delegate$.$name ==
110 GateMP.RemoteCustom1Proxy.delegate$.$name) {
111 mod.proxyMap[GateMP.ProxyOrder_CUSTOM2] =
112 mod.proxyMap[GateMP.ProxyOrder_CUSTOM1];
113 }
115 /* Setup nameserver */
116 /* initialize the NameServer param to be used now or later */
117 GateMP.nameSrvPrms.maxRuntimeEntries = params.maxRuntimeEntries;
118 GateMP.nameSrvPrms.tableSection = params.tableSection;
119 GateMP.nameSrvPrms.maxNameLen = params.maxNameLen;
121 var Program = xdc.module('xdc.cfg.Program');
122 var target = Program.build.target;
124 if (params.hostSupport) {
125 /*
126 * Need 6 words for info entry, which is larger than other entries
127 */
128 GateMP.nameSrvPrms.maxValueLen = 6 * target.stdTypes["t_Int32"].size;
129 if (params.maxNameLen < 32) {
130 GateMP.nameSrvPrms.maxNameLen = 32; /* min 32 chars for def gate */
131 }
132 mod.hostSupport = true;
133 }
134 else {
135 /*
136 * Need 2 words:
137 * 1 word for the SharedRegion Ptr.
138 * 1 word for the proc id of creator and if remote is allowed.
139 */
140 GateMP.nameSrvPrms.maxValueLen = 2 * target.stdTypes["t_Int32"].size;
141 mod.hostSupport = false;
142 }
144 /*
145 * Get the current number of created static instances of this module.
146 * Note: if user creates a static instance after this point and
147 * expects to use NameServer, this is a problem.
148 */
149 var instCount = this.$instances.length;
151 /* create NameServer here only if no static instances are created */
152 if (instCount == 0) {
153 mod.nameServer = NameServer.create("GateMP",
154 GateMP.nameSrvPrms);
155 }
157 /* Create the GateAll, GateSwi, and GateNull singletons */
158 mod.gateAll = GateAll.create();
159 mod.gateSwi = GateSwi.create();
160 mod.gateMutexPri = GateMutexPri.create();
161 mod.gateNull = GateNull.create();
163 mod.numRemoteSystem = GateMP.RemoteSystemProxy.delegate$.getNumResources();
164 mod.numRemoteCustom1 = GateMP.RemoteCustom1Proxy.delegate$.getNumResources();
165 mod.numRemoteCustom2 = GateMP.RemoteCustom2Proxy.delegate$.getNumResources();
166 mod.remoteSystemGates.length = mod.numRemoteSystem;
168 /*
169 * If the proxies are not unique, plug these pointers in GateMP_start
170 * accordingly.
171 */
172 if (mod.proxyMap[GateMP.ProxyOrder_CUSTOM1] == GateMP.ProxyOrder_CUSTOM1) {
173 mod.remoteCustom1Gates.length = mod.numRemoteCustom1;
174 }
175 else {
176 mod.remoteCustom1Gates.length = 0;
177 }
179 if (mod.proxyMap[GateMP.ProxyOrder_CUSTOM2] == GateMP.ProxyOrder_CUSTOM2) {
180 mod.remoteCustom2Gates.length = mod.numRemoteCustom2;
181 }
182 else {
183 mod.remoteCustom2Gates.length = 0;
184 }
186 mod.defaultGate = null;
187 mod.nsKey = 0;
188 mod.remoteSystemGates[0] = mod.defaultGate;
190 /* Initialize the rest of the proxy gate arrays */
191 for (var i = 1; i < mod.remoteSystemGates.length; i++) {
192 mod.remoteSystemGates[i] = null;
193 }
195 for (var i = 0; i < mod.remoteCustom1Gates.length; i++) {
196 mod.remoteCustom1Gates[i] = null;
197 }
199 for (var i = 0; i < mod.remoteCustom2Gates.length; i++) {
200 mod.remoteCustom2Gates[i] = null;
201 }
202 }
204 /*
205 * ======== queryMeta ========
206 */
207 function queryMeta(qual)
208 {
209 var rc = false;
211 return (rc);
212 }
214 /*
215 * ======== viewInitBasic ========
216 */
217 function viewInitBasic(view, obj)
218 {
219 var Program = xdc.useModule('xdc.rov.Program');
220 var NameServer = xdc.useModule('ti.sdo.utils.NameServer');
221 var SharedRegion = xdc.useModule('ti.sdo.ipc.SharedRegion');
222 var Ipc = xdc.useModule('ti.sdo.ipc.Ipc');
223 var GateMP = xdc.useModule('ti.sdo.ipc.GateMP');
225 /* view.name */
226 try {
227 if (obj.nsKey != 0x0) {
228 view.name = NameServer.getNameByKey$view(obj.nsKey);
229 }
230 }
231 catch(e) {
232 Program.displayError(view, "name",
233 "Error retrieving name from NameServer: " + e);
234 }
236 var GateSupportProxy;
238 /* view.remoteProtect & view.remoteStatus */
239 switch(obj.remoteProtect) {
240 case GateMP.RemoteProtect_NONE:
241 view.remoteProtect = "NONE";
242 GateSupportProxy = null;
243 break;
244 case GateMP.RemoteProtect_SYSTEM:
245 view.remoteProtect = "SYSTEM";
246 GateSupportProxy =
247 Program.$modules['ti.sdo.ipc.GateMP'].RemoteSystemProxy;
248 break;
249 case GateMP.RemoteProtect_CUSTOM1:
250 view.remoteProtect = "CUSTOM1";
251 GateSupportProxy =
252 Program.$modules['ti.sdo.ipc.GateMP'].RemoteCustom1Proxy;
253 break;
254 case GateMP.RemoteProtect_CUSTOM2:
255 view.remoteProtect = "CUSTOM2";
256 GateSupportProxy =
257 Program.$modules['ti.sdo.ipc.GateMP'].RemoteCustom2Proxy;
258 break;
259 default:
260 Program.displayError(view, "remoteProtect",
261 "Corrupted state: The value of 'obj->remoteProtect' is not " +
262 "one of known types");
263 }
265 if (GateSupportProxy == null) {
266 view.remoteStatus = "[none]";
267 }
268 else {
269 try {
270 var GateDelegate = xdc.useModule(GateSupportProxy.$name);
271 view.remoteStatus
272 = GateDelegate.getRemoteStatus$view(obj.gateHandle);
273 }
274 catch (e) {
275 Program.displayError(view, "remoteStatus",
276 "Error obtaining remote gate (resourceId = " +
277 obj.resourceId + ") status: " + e);
278 }
279 }
281 /* view.localProtect */
282 switch(obj.localProtect) {
283 case GateMP.LocalProtect_NONE:
284 view.localProtect = "NONE";
285 break;
286 case GateMP.LocalProtect_INTERRUPT:
287 view.localProtect = "INTERRUPT";
288 break;
289 case GateMP.LocalProtect_TASKLET:
290 view.localProtect = "TASKLET";
291 break;
292 case GateMP.LocalProtect_THREAD:
293 view.localProtect = "THREAD";
294 break;
295 case GateMP.LocalProtect_PROCESS:
296 view.localProtect = "PROCESS";
297 break;
298 default:
299 Program.displayError(view, "localProtect",
300 "Corrupted state: The value of 'obj->localProtect' is not " +
301 "one of known types");
302 }
304 /* view.numOpens */
305 view.numOpens = obj.numOpens;
307 /* view.resourceId; Ensure that it isn't equal to ((UInt)-1) */
308 if (obj.resourceId != 0xFFFFFFFF) {
309 view.resourceId = obj.resourceId;
310 }
312 /* view.creatorProcId */
313 try {
314 var attrs = Program.fetchStruct(GateMP.Attrs$fetchDesc,
315 obj.attrs.$addr, false);
317 view.creatorProcId = attrs.creatorProcId;
318 }
319 catch (e) {
320 Program.displayError(view, 'creatorProcId',
321 "Error: could not fetch shared memory structure: " + e);
322 }
324 /* view.objType */
325 try {
326 view.objType = Ipc.getObjTypeStr$view(obj.objType);
327 }
328 catch (e) {
329 Program.displayError(view, "objType", "Corrupted state: " + e);
330 }
331 }
333 /*
334 * ======== viewInitModule ========
335 */
336 function viewInitModule(view, mod)
337 {
338 var Program = xdc.useModule('xdc.rov.Program');
339 var ScalarStructs = xdc.useModule('xdc.rov.support.ScalarStructs');
341 view.numGatesSystem = mod.numRemoteSystem;
343 if (mod.defaultGate == 0) {
344 /* GateMP not started yet */
345 view.numUsedSystem = 0;
346 return;
347 }
349 try {
350 var remoteSystemInUse = Program.fetchArray(
351 mod.remoteSystemInUse$fetchDesc,
352 mod.remoteSystemInUse.$addr,
353 mod.numRemoteSystem);
354 }
355 catch (e) {
356 throw("Problem fetching remoteSystemInUse" + e); //TODO
357 }
359 view.numUsedSystem = 0;
360 for each (var isUsed in remoteSystemInUse) {
361 if (isUsed) {
362 view.numUsedSystem++;
363 }
364 }
366 if (mod.proxyMap[1] == 1) {
367 view.numGatesCustom1 = mod.numRemoteCustom1;
369 try {
370 var remoteCustom1InUse = Program.fetchArray(
371 mod.remoteCustom1InUse$fetchDesc,
372 mod.remoteCustom1InUse.$addr,
373 mod.numRemoteCustom1);
374 }
375 catch (e) {
376 throw("Problem fetching remoteCustom1InUse" + e); //TODO
377 }
380 view.numUsedCustom1 = 0;
381 for each (var isUsed in remoteCustom1InUse) {
382 if (isUsed) {
383 view.numUsedCustom1++;
384 }
385 }
386 }
388 if (mod.proxyMap[2] == 2) {
389 view.numGatesCustom2 = mod.numRemoteCustom2;
391 try {
392 var remoteCustom2InUse = Program.fetchArray(
393 mod.remoteCustom2InUse$fetchDesc,
394 mod.remoteCustom2InUse.$addr,
395 mod.numRemoteCustom2);
396 }
397 catch (e) {
398 throw("Problem fetching remoteCustom2InUse" + e); //TODO
399 }
402 view.numUsedCustom2 = 0;
403 for each (var isUsed in remoteCustom2InUse) {
404 if (isUsed) {
405 view.numUsedCustom2++;
406 }
407 }
408 }
409 }