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 * ======== MultiProc.xs ========
34 *
35 */
37 var MultiProc = null;
38 var BaseIdOfCluster = null;
39 var NumProcessors = null;
41 /*
42 * ======== module$use ========
43 */
44 function module$use()
45 {
46 MultiProc = this;
48 if (((BaseIdOfCluster != MultiProc.baseIdOfCluster) &&
49 (BaseIdOfCluster != null)) ||
50 ((NumProcessors != MultiProc.numProcessors) &&
51 (NumProcessors != null))) {
52 MultiProc.$logError("MultiProc.numProcessors and " +
53 "MultiProc.baseIdOfCluster must be " +
54 "set before MultiProc.setConfig()", this);
55 }
57 /* Make sure the name list is not too long... */
58 if (MultiProc.nameList.length > MultiProc.numProcsInCluster) {
59 MultiProc.$logError("The name list is too long. numProcessors = " +
60 MultiProc.numProcsInCluster, this);
61 }
62 else if (MultiProc.nameList.length < MultiProc.numProcsInCluster) {
63 /* If too short, fill in with nulls */
64 var len = MultiProc.nameList.length;
65 MultiProc.nameList.length = MultiProc.numProcsInCluster;
66 for (var i = len; i < MultiProc.numProcsInCluster; i++) {
67 MultiProc.nameList[i] = null;
68 }
69 }
71 /*
72 * Make sure the id is ok (e.g. not equal to or greater than numProcessors)
73 * If it is INVALID (e.g. set at runtime) do not do the check.
74 */
75 if ((MultiProc.id != MultiProc.INVALIDID) &&
76 (MultiProc.id >= MultiProc.numProcessors)) {
78 MultiProc.$logError("The processor id (" + MultiProc.id +
79 ") is larger than numProcessors (" + MultiProc.numProcessors +
80 ")", this);
81 }
82 }
84 /*
85 * ======== setConfig ========
86 */
87 function setConfig(name, nameList)
88 {
89 var Settings = xdc.module('ti.sdo.ipc.family.Settings');
90 MultiProc = this;
92 MultiProc.nameList = nameList;
93 MultiProc.id = MultiProc.INVALIDID;
95 /* set/check numProcsInCluster */
96 if (!(MultiProc.$written("numProcsInCluster"))) {
97 /*
98 * If numProcsInCluster is not set, then set it to the
99 * length of the nameList.
100 */
101 MultiProc.numProcsInCluster = nameList.length;
102 }
104 /* set/check numProcessors */
105 if (!(MultiProc.$written("baseIdOfCluster"))) {
106 if (!(MultiProc.$written("numProcessors"))) {
107 /*
108 * If baseIdOfCluster is not set and numProcessors is not set
109 * then set numProcessors to numProcsInCluster
110 */
111 MultiProc.numProcessors = MultiProc.numProcsInCluster;
112 }
113 }
114 else {
115 if (!(MultiProc.$written("numProcessors"))) {
116 /*
117 * If baseIdOfCluster is set and numProcessors is not set
118 * then throw error because numProcessors needs to be set
119 */
120 MultiProc.$logError("MultiProc.numProcessors needs to be set" +
121 " before calling MultiProc.setConfig()", this);
122 }
123 }
125 /* BaseIdOfCluster and NumProcessors must not change after this point */
126 NumProcessors = MultiProc.numProcessors;
127 BaseIdOfCluster = MultiProc.baseIdOfCluster;
129 /* create the list of processor ids */
130 MultiProc.procIdList.length = MultiProc.numProcsInCluster;
131 for (var i = 0; i < MultiProc.numProcsInCluster; i++) {
132 MultiProc.procIdList[i] = i + MultiProc.baseIdOfCluster;
133 }
135 if (nameList.length == 0) {
136 /* Empty name array supplied */
137 MultiProc.$logError("'nameList' cannot be empty", this);
138 }
139 else {
140 /* Check for duplicate names in nameList */
141 var temp = [];
142 for each (procName in nameList) {
143 if (temp[procName] != null) {
144 MultiProc.$logError("nameList has a duplicate name: " +
145 procName, this);
146 }
147 temp[procName] = 1;
148 }
149 }
151 /*
152 * Check for valid nameList names. I.e. if building on DM6446, the only
153 * possible names in nameList are "HOST" and "DSP".
154 */
155 if (MultiProc.numProcsInCluster > 1) {
156 for each (var tempName in MultiProc.nameList) {
157 if (tempName != null && !Settings.procInDevice(tempName)) {
158 MultiProc.$logError("The MultiProc name (" + tempName +
159 ") does not match any of the following possible names on the"
160 + " device (" + Program.cpu.deviceName + "): " +
161 Settings.getDeviceProcNames().join(", "),
162 this);
163 }
164 }
165 }
167 /* If name is not null, set the id here otherwise set it at runtime */
168 if (name != null) {
169 /* Set MultiProc.id from the name */
170 var id = this.getIdMeta(name);
172 if (id == MultiProc.INVALIDID) {
173 MultiProc.$logError("The processor name (" + name +
174 ") is not contained within the nameList", this);
175 }
177 /* only get here if id is valid */
178 MultiProc.id = id + MultiProc.baseIdOfCluster;
179 }
180 else if (MultiProc.numProcsInCluster == 1) {
181 /* There is only 1 processor so set id to the base of cluster */
182 MultiProc.id = MultiProc.baseIdOfCluster;
183 }
184 }
186 /*
187 * ======== getDeviceProcNames ========
188 */
189 function getDeviceProcNames()
190 {
191 var Settings = xdc.module('ti.sdo.ipc.family.Settings');
193 return (Settings.getDeviceProcNames());
194 }
196 /*
197 * ======== getIdMeta ========
198 */
199 function getIdMeta(name)
200 {
201 MultiProc = this;
203 var id = MultiProc.INVALIDID;
205 if (name != null) {
206 for (var i in MultiProc.nameList) {
207 if (MultiProc.nameList[i] == name) {
208 id = Number(i);
209 }
210 }
211 }
212 else {
213 /* Get our 'own' MultiProc id */
214 id = MultiProc.id;
215 }
217 return (id);
218 }
220 /*
221 * ======== module$static$init ========
222 */
223 function module$static$init(mod, params)
224 {
225 mod.id = params.id;
226 mod.baseIdOfCluster = params.baseIdOfCluster;
227 }
229 /*
230 * ======== getName$view ========
231 * ROV helper function that returns a processor name given its id
232 */
233 function getName$view(id)
234 {
235 var name;
237 /*
238 * Scan in the MultiProc view so we have the mapping from processor id
239 * to processor name.
240 */
241 try {
242 var multiProcView = Program.scanModuleView('ti.sdo.utils.MultiProc',
243 'Module');
244 }
245 catch (e) {
246 /*
247 * If there was a problem scanning the MultiProc view, throw an error
248 */
249 throw("Error scanning MultiProc module view: " + String(e));
250 }
252 /* Check whether id is valid; throw an error if not */
253 if (id > multiProcView.numProcessors) {
254 throw("Invalid MultiProc id: " + id);
255 }
257 /* Since nameList is ordered by id, we can directly index the array */
258 name = multiProcView.nameList[id];
260 return (name);
261 }
263 /*
264 * ======== self$view ========
265 * ROV helper function that returns the local MultiProc id
266 */
267 function self$view()
268 {
269 /* Retrieve the module state. */
270 var rawView = Program.scanRawView('ti.sdo.utils.MultiProc');
271 var mod = rawView.modState;
273 return (mod.id);
274 }
276 /*
277 * ======== viewInitModule ========
278 * Display the module properties in ROV
279 */
280 function viewInitModule(view, mod)
281 {
282 var MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
283 var Program = xdc.useModule('xdc.rov.Program');
284 var multiprocModConfig = Program.getModuleConfig(MultiProc.$name);
286 view.id = mod.id;
287 view.numProcessors = multiprocModConfig.numProcsInCluster;
289 /* Drop-down of the names */
290 view.nameList.length = multiprocModConfig.nameList.length
291 for (var i =0; i < multiprocModConfig.nameList.length; i++) {
292 if (multiprocModConfig.nameList[i] != null) {
293 view.nameList[i] = multiprocModConfig.nameList[i];
294 }
295 else {
296 view.nameList[i] = "[unnamed]";
297 }
298 }
299 }