1 /*
2 * Copyright (c) 2012-2013, 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 * ======== Notify.xs ========
34 */
36 var Notify = null;
37 var MultiProc = null;
38 var Memory = null;
39 var Ipc = null;
40 var List = null;
41 var Settings = null;
43 /*
44 * ======== module$use ========
45 */
46 function module$use()
47 {
48 Notify = this;
49 Memory = xdc.useModule('xdc.runtime.Memory');
50 MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
51 List = xdc.useModule('ti.sdo.utils.List');
52 Settings = xdc.useModule('ti.sdo.ipc.family.Settings');
54 /* Check for valid numEvents */
55 if (Notify.numEvents > Notify.MAXEVENTS) {
56 Notify.$logFatal("Notify.numEvents may not be set to a value greater" +
57 " than " + Notify.MAXEVENTS, Notify);
58 }
60 /*
61 * Plug the module gate which will be used for protecting Notify APIs from
62 * each other. Use GateSwi
63 */
64 if (Notify.common$.gate === undefined) {
65 var GateSwi = xdc.useModule('ti.sysbios.gates.GateSwi');
66 Notify.common$.gate = GateSwi.create();
67 }
69 /* Plug the NotifySetup proxy */
70 if (Notify.SetupProxy == null) {
71 if (MultiProc.numProcessors == 1) {
72 /*
73 * On a uniprocessor system (or Notify is disabled). We will never
74 * need to setup remote notify driver instances, so plug in
75 * NotifySetupNull.
76 */
77 Notify.SetupProxy
78 = xdc.useModule('ti.sdo.ipc.notifyDrivers.NotifySetupNull');
79 }
80 else {
81 /*
82 * On a multiprocessor system. Query the Settings module for the
83 * device-specific NotifySetup delegate.
84 */
85 try {
86 delegateName = Settings.getNotifySetupDelegate();
87 Notify.SetupProxy = xdc.useModule(delegateName);
88 }
89 catch (e) {
90 Notify.$logFatal(String(e), Notify);
91 }
92 }
93 }
95 }
97 /*
98 * ======== module$static$init ========
99 */
100 function module$static$init(mod, params)
101 {
102 var handles = Notify.$object.notifyHandles;
104 handles.length = MultiProc.numProcsInCluster;
106 /* Initialize every handle to null */
107 for (var i = 0; i < handles.length; i++) {
108 handles[i].length = params.numLines;
110 for (var j = 0; j < handles[i].length; j++) {
111 handles[i][j] = null;
112 }
113 }
115 mod.localEnableMask = ~0; /* all enabled by default */
116 }
119 /*
120 *************************************************************************
121 * ROV View functions
122 *************************************************************************
123 */
125 /*
126 * ======== viewInitBasic ========
127 */
128 function viewInitBasic(view, obj)
129 {
130 var MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
132 /* view.remoteProcId */
133 view.remoteProcId = obj.remoteProcId;
135 /* view.remoteProcName */
136 try {
137 view.remoteProcName = MultiProc.getName$view(obj.remoteProcId);
138 }
139 catch(e) {
140 Program.displayError(view, 'remoteProcName',
141 "Problem retrieving proc name: " + e);
142 }
144 /* view.lineId */
145 view.lineId = obj.lineId;
147 /* view.disabled */
148 view.disabled = obj.nesting;
149 }
151 /*
152 * ======== viewInitData ========
153 * Instance data view.
154 */
155 function viewInitData(view, obj)
156 {
157 var Notify = xdc.useModule('ti.sdo.ipc.Notify');
158 var List = xdc.useModule('ti.sdo.utils.List');
159 var modCfg = Program.getModuleConfig('ti.sdo.ipc.Notify');
161 /* Display the instance label in the tree */
162 view.label = "procId = " + obj.remoteProcId + " lineId = " + obj.lineId;
164 /* Fetch the callback array */
165 try {
166 var callbacks = Program.fetchArray(obj.callbacks$fetchDesc,
167 obj.callbacks,
168 modCfg.numEvents);
169 }
170 catch(e) {
171 Program.displayError(view, "eventId", "Problem retrieving callback " +
172 " array from instance state.");
173 return;
174 }
176 /* Fetch the eventList */
177 try {
178 var eventList = Program.fetchArray(obj.eventList$fetchDesc,
179 obj.eventList,
180 modCfg.numEvents);
181 }
182 catch(e) {
183 Program.displayError(view, "eventId", "Problem retrieving eventList " +
184 " from instance state.");
185 return;
186 }
188 /* For each element of the buffer... */
189 for (var eventId = 0; eventId < modCfg.numEvents; eventId++) {
190 var fnNotifyCbck = callbacks[eventId].fnNotifyCbck;
191 if (Number(fnNotifyCbck) == 0) {
192 /* Event is unplugged */
193 continue;
194 }
196 var fxnName = Program.lookupFuncName(Number(fnNotifyCbck))[0];
197 if (fxnName == "ti_sdo_ipc_Notify_execMany__I") {
198 /* Multiple callbacks registered. View all of them */
199 try {
200 listView = Program.scanObjectView('ti.sdo.utils.List',
201 eventList[eventId],
202 'Basic');
203 }
204 catch (e) {
205 Program.displayError(view, "eventId", "Problem scanning ROV " +
206 " for embedded event list object");
207 return;
208 }
209 for each (var listElemPtr in listView.elems) {
210 try {
211 var eventListener = Program.fetchStruct(
212 Notify.EventListener$fetchDesc,
213 $addr(listElemPtr));
214 }
215 catch(e) {
216 Program.displayError(view, "eventId", "Problem " +
217 "retrieving event listener ");
218 return;
219 }
221 var elem = Program.newViewStruct('ti.sdo.ipc.Notify',
222 'EventListeners');
223 elem.eventId = eventId;
224 elem.fnNotifyCbck = Program.lookupFuncName(
225 Number(eventListener.callback.fnNotifyCbck))[0];
226 elem.cbckArg = "0x" +
227 Number(eventListener.callback.cbckArg).toString(16);
229 /* Create a new row in the instance data view */
230 view.elements.$add(elem);
231 }
232 }
233 else {
234 /* Single callback function registered. Just view one. */
235 var elem = Program.newViewStruct('ti.sdo.ipc.Notify',
236 'EventListeners');
237 elem.fnNotifyCbck = fxnName;
238 elem.eventId = eventId;
239 elem.cbckArg = "0x" +
240 Number(callbacks[eventId].cbckArg).toString(16);
242 /* Create a new row in the instance data view */
243 view.elements.$add(elem);
244 }
245 }
246 }