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 * ======== ListMP.xs ========
34 *
35 */
37 var Cache = null;
38 var Ipc = null;
39 var GateMP = null;
40 var ListMP = null;
41 var SharedRegion = null;
42 var MultiProc = null;
43 var NameServer = null;
44 var instCount = 0; /* use to determine if processing last instance */
46 /*
47 * ======== module$use ========
48 */
49 function module$use()
50 {
51 ListMP = this;
52 Ipc = xdc.useModule('ti.sdo.ipc.Ipc');
53 GateMP = xdc.useModule('ti.sdo.ipc.GateMP');
54 SharedRegion = xdc.useModule("ti.sdo.ipc.SharedRegion");
55 MultiProc = xdc.useModule("ti.sdo.utils.MultiProc");
56 NameServer = xdc.useModule("ti.sdo.utils.NameServer");
57 Cache = xdc.useModule("ti.sysbios.hal.Cache");
59 ListMP.common$.fxntab = false;
60 }
62 /*
63 * ======== module$static$init ========
64 */
65 function module$static$init(mod, params)
66 {
67 mod.nameServer = null;
68 ListMP.nameSrvPrms.maxRuntimeEntries = params.maxRuntimeEntries;
69 ListMP.nameSrvPrms.maxNameLen = params.maxNameLen;
70 ListMP.nameSrvPrms.tableSection = params.tableSection;
72 /*
73 * Get the current number of created static instances of this module.
74 * Note: if user creates a static instance after this point and
75 * expects to use NameServer, this is a problem.
76 */
77 var instCount = this.$instances.length;
79 /* create NameServer here only if no static instances are created */
80 if (instCount == 0) {
81 mod.nameServer = NameServer.create("ListMP", ListMP.nameSrvPrms);
82 }
83 }
85 /*
86 * ======== viewInitBasic ========
87 * Processes the 'Basic' view for a ListMP instance.
88 */
89 function viewInitBasic(view, obj)
90 {
91 var NameServer = xdc.useModule('ti.sdo.utils.NameServer');
92 var Ipc = xdc.useModule('ti.sdo.ipc.Ipc');
93 var GateMP = xdc.useModule('ti.sdo.ipc.GateMP');
95 /* Determine if the instance was given a name in the nameserver. */
96 if (obj.nsKey != 0x0) {
97 view.label = NameServer.getNameByKey$view(obj.nsKey);
98 }
99 /* Otherwise, leave the label empty. */
100 else {
101 view.label = "";
102 }
104 /* Get the instance's type (created, opened, etc.) */
105 view.type = Ipc.getObjTypeStr$view(obj.objType);
107 /* Display the handle to the instance's gate. */
108 view.gate = String(obj.gate);
109 }
111 /*
112 * ======== viewInitLists ========
113 * Processes the 'Lists' view for a ListMP instance.
114 *
115 * The 'Lists' view is a tree-type view (Instance Data) which displays the
116 * elements on the list. For each element, it displays an index and both the
117 * local and shared region address of the element.
118 */
119 function viewInitLists(view, obj)
120 {
121 var Program = xdc.useModule('xdc.rov.Program');
122 var SharedRegion = xdc.useModule('ti.sdo.ipc.SharedRegion');
123 var ListMP = xdc.useModule('ti.sdo.ipc.ListMP');
125 /* Label the list by its address. */
126 view.label = String(obj.$addr);
128 /* Retrieve the ListMP's Attrs struct. */
129 var attrs;
130 try {
131 attrs = Program.fetchStruct(obj.attrs$fetchDesc, obj.attrs);
132 }
133 /* If there was a problem fetching the attrs struct, report it. */
134 catch (e) {
135 /* Create an element view to display the problem. */
136 var elemView = Program.newViewStruct('ti.sdo.ipc.ListMP', 'Lists');
137 Program.displayError(elemView, 'index',
138 "Problem retrieving the instance's Attrs " +
139 "struct: " + e);
140 view.elements.$add(elemView);
141 return;
142 }
144 /* Compute the address of the 'head' element within the attrs struct. */
145 var hdrOffset = $om['ti.sdo.ipc.ListMP.Attrs'].$offsetof('head');
146 var hdrAddr = Number(obj.attrs) + hdrOffset;
148 /* Get the shared region address of the header. */
149 try {
150 var srHdrAddr = SharedRegion.getSRPtrMeta$view(hdrAddr);
151 }
152 /* If there was a problem, report it. */
153 catch (e) {
154 /* Create an element view to display the problem. */
155 var elemView = Program.newViewStruct('ti.sdo.ipc.ListMP', 'Lists');
156 Program.displayError(elemView, 'index',
157 "Problem retrieving SharedRegion address for " +
158 "the list's head: " + e);
159 view.elements.$add(elemView);
160 return;
161 }
163 /*
164 * To check for loops, store each address as a key in a map,
165 * then with each new address check first if it is already in
166 * the map.
167 */
168 var srAddrs = {};
170 /* Start at the head element. */
171 var e = attrs.head;
173 /* Loop through all of the elements until we're back at the head. */
174 while (e.next != srHdrAddr) {
176 /* Before fetching the next element, verify we're not in a loop. */
177 if (e.next in srAddrs) {
178 var lastElem = view.elements[view.elements.length - 1];
179 Program.displayError(lastElem, 'addr', "List contains loop. " +
180 "This element points to SharedRegion " +
181 "address 0x" + Number(e.next).toString(16));
182 break;
183 }
185 /* Create a view structure to represent the next element. */
186 var elemView = Program.newViewStruct('ti.sdo.ipc.ListMP', 'Lists');
188 /* Display the shared region address of the next element. */
189 elemView.srPtr = "0x" + Number(e.next).toString(16);
191 /*
192 * Get the local address of the next element using the SharedRegion
193 * module.
194 */
195 try {
196 var nextAddr = SharedRegion.getPtrMeta$view(Number(e.next));
197 }
198 catch (e) {
199 Program.displayError(elemView, 'addr', "Problem calculating " +
200 "local address: " + addressString(e));
201 }
203 /* Display the local address of the next element. */
204 elemView.addr = "0x" + Number(nextAddr).toString(16);
206 /* Add the element to the view. */
207 view.elements.$add(elemView);
209 /*
210 * Add the address to a map so we can check for loops.
211 * The value 'true' is just a placeholder to make sure the address
212 * is in the map.
213 */
214 srAddrs[e.next] = true;
216 /* Fetch the next element (using its local address) */
217 e = Program.fetchStruct(ListMP.Elem$fetchDesc, nextAddr);
218 }
219 }