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 * ======== NameServerRemoteNotify.xs ========
34 */
36 var NameServerRemoteNotify;
37 var NameServer;
38 var MultiProc;
39 var Notify;
40 var Ipc;
41 var GateMP;
42 var SharedRegion;
43 var Semaphore;
44 var Swi;
45 var Clock = null;
46 var Cache;
48 /*
49 * ======== module$use ========
50 */
51 function module$use()
52 {
53 NameServerRemoteNotify = this;
54 NameServer = xdc.useModule("ti.sdo.utils.NameServer");
55 MultiProc = xdc.useModule("ti.sdo.utils.MultiProc");
56 Notify = xdc.useModule("ti.sdo.ipc.Notify");
57 Ipc = xdc.useModule("ti.sdo.ipc.Ipc");
58 GateMP = xdc.useModule("ti.sdo.ipc.GateMP");
59 SharedRegion = xdc.useModule("ti.sdo.ipc.SharedRegion");
60 Semaphore = xdc.useModule("ti.sysbios.knl.Semaphore");
61 Swi = xdc.useModule("ti.sysbios.knl.Swi");
62 Clock = xdc.useModule("ti.sysbios.knl.Clock");
63 Cache = xdc.useModule("ti.sysbios.hal.Cache");
64 }
66 /*
67 * ======== module$static$init ========
68 * Initialize module values.
69 */
70 function module$static$init(mod, params)
71 {
72 /* calculate the timeout value */
73 if (NameServerRemoteNotify.timeoutInMicroSecs != ~(0)) {
74 NameServerRemoteNotify.timeout =
75 NameServerRemoteNotify.timeoutInMicroSecs / Clock.tickPeriod;
76 }
77 else {
78 NameServerRemoteNotify.timeout =
79 NameServerRemoteNotify.timeoutInMicroSecs;
80 }
81 }
83 /*
84 * ======== module$validate ========
85 */
86 function module$validate()
87 {
88 if (Notify.numEvents <= NameServerRemoteNotify.notifyEventId) {
89 NameServerRemoteNotify.$logFatal(
90 "NameServerRemoteNotify.notifyEventId (" +
91 NameServerRemoteNotify.notifyEventId +
92 ") is too big: Notify.numEvents = " + Notify.numEvents,
93 NameServerRemoteNotify);
94 }
95 }
97 /*
98 *************************************************************************
99 * ROV View functions
100 *************************************************************************
101 */
103 /*
104 * ======== fetchString ========
105 * Returns a string contained in one of the Bits32 array fields in 'msg'
106 */
107 function fetchString(msg, field)
108 {
109 var NSRN = xdc.useModule('ti.sdo.ipc.nsremote.NameServerRemoteNotify');
111 var ptrToString = $addr(Number(msg) + NSRN.Message.$offsetof(field));
113 return (Program.fetchString(ptrToString));
114 }
116 /*
117 * ======== viewInitBasic ========
118 */
119 function viewInitBasic(view, obj)
120 {
121 var MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
122 var NSRN = xdc.useModule('ti.sdo.ipc.nsremote.NameServerRemoteNotify');
124 /* view.remoteProcId */
125 view.remoteProcId = obj.remoteProcId;
127 /* view.remoteProcName */
128 try {
129 view.remoteProcName = MultiProc.getName$view(obj.remoteProcId);
130 }
131 catch(e) {
132 Program.displayError(view, 'remoteProcName',
133 "Problem retrieving proc name: " + e);
134 }
136 if (MultiProc.self$view() > obj.remoteProcId) {
137 var offset = 1;
138 }
139 else {
140 var offset = 0;
141 }
142 var localId = offset;
143 var remoteId = 1 - offset;
145 try {
146 var localMsg = Program.fetchStruct(
147 NSRN.Message$fetchDesc,
148 $addr(obj.msg[localId])); /* msg[0] belongs to local core */
149 }
150 catch(e) {
151 Program.displayError(view, "localRequestStatus", "Problem " +
152 "retrieving local request status ");
153 return;
154 }
156 if (localMsg.request == 1 || localMsg.response == 1) {
157 if (localMsg.request == 1) {
158 /* Request */
159 view.localRequestStatus = "Receiving a request";
160 }
161 else {
162 /* Response */
163 view.localRequestStatus = "Sending a response ";
164 if (localMsg.requestStatus == 1) {
165 view.localRequestStatus += "(found)";
166 if (localMsg.valueLen <= 4) {
167 view.localValue = "0x" +
168 Number(localMsg.value).toString(16);
169 }
170 else {
171 view.localValue = "Value at 0x" +
172 Number(Number(obj.msg[localId]) +
173 NSRN.Message.$offsetof("valueBuf")).toString(16);
174 }
175 }
176 else {
177 view.localRequestStatus += "(not found)";
178 }
179 }
181 view.localInstanceName = fetchString(obj.msg[localId], "instanceName");
182 view.localName = fetchString(obj.msg[localId], "name");
183 }
184 else {
185 view.localRequestStatus = "Idle";
186 }
188 try {
189 var remoteMsg = Program.fetchStruct(
190 NSRN.Message$fetchDesc,
191 $addr(obj.msg[remoteId]));
192 }
193 catch(e) {
194 Program.displayError(view, "localRequestStatus", "Problem " +
195 "retrieving remote request status ");
196 return;
197 }
199 if (remoteMsg.request == 1 || remoteMsg.response == 1) {
200 if (remoteMsg.request == 1) {
201 /* Request */
202 view.remoteRequestStatus = "Receiving a request";
203 }
204 else {
205 /* Response */
206 view.remoteRequestStatus = "Sending a response ";
207 if (remoteMsg.requestStatus == 1) {
208 view.remoteRequestStatus += "(found)";
210 if (remoteMsg.valueLen <= 4) {
211 view.remoteValue = "0x" +
212 Number(remoteMsg.value).toString(16);
213 }
214 else {
215 view.remoteValue = "Value at 0x" +
216 Number(Number(obj.msg[remoteId]) +
217 NSRN.Message.$offsetof("valueBuf")).toString(16);
218 }
219 }
220 else {
221 view.remoteRequestStatus += "(not found)";
222 }
223 }
225 view.remoteInstanceName = fetchString(obj.msg[remoteId], "instanceName");
226 view.remoteName = fetchString(obj.msg[remoteId], "name");
227 }
228 else {
229 view.remoteRequestStatus = "Idle";
230 }
231 }