]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - packages/ti/sdo/ipc/heaps/HeapMultiBufMP.xs
ipc-bios.bld: Add "-cr" lnkOpt in for C66 target for remoteproc loaded images.
[ipc/ipcdev.git] / packages / ti / sdo / ipc / heaps / HeapMultiBufMP.xs
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  *  ======== HeapMultiBufMP.xs ========
34  *
35  */
37 var HeapMultiBufMP  = null;
38 var SharedRegion    = null;
39 var NameServer      = null;
40 var Ipc             = null;
41 var Cache           = null;
42 var GateMP          = null;
44 var instCount = 0;  /* use to determine if processing last instance */
46 /*
47  *  ======== module$use ========
48  */
49 function module$use()
50 {
51     HeapMultiBufMP  = this;
52     Memory          = xdc.useModule('xdc.runtime.Memory');
53     NameServer      = xdc.useModule('ti.sdo.utils.NameServer');
54     SharedRegion    = xdc.useModule('ti.sdo.ipc.SharedRegion');
55     Ipc             = xdc.useModule('ti.sdo.ipc.Ipc');
56     GateMP          = xdc.useModule('ti.sdo.ipc.GateMP');
57     Cache           = xdc.useModule('ti.sysbios.hal.Cache');
58 }
60 /*
61  *  ======== module$static$init ========
62  */
63 function module$static$init(mod, params)
64 {
65     mod.nameServer  = null;
67     /* Setup nameserver */
68     /* initialize the NameServer param to be used now or later */
69     HeapMultiBufMP.nameSrvPrms.maxRuntimeEntries
70             = params.maxRuntimeEntries;
71     HeapMultiBufMP.nameSrvPrms.tableSection = params.tableSection;
72     HeapMultiBufMP.nameSrvPrms.maxNameLen   = params.maxNameLen;
74     /*
75      *  Get the current number of created static instances of this module.
76      *  Note: if user creates a static instance after this point and
77      *        expects to use NameServer, this is a problem.
78      */
79     var instCount = this.$instances.length;
81     /* create NameServer here only if no static instances are created */
82     if (instCount == 0) {
83         mod.nameServer = NameServer.create("HeapMultiBufMP",
84                                             HeapMultiBufMP.nameSrvPrms);
85     }
86 }
88 /*
89  *  ======== viewInitBasic ========
90  */
91 function viewInitBasic(view, obj)
92 {
93     var NameServer      = xdc.useModule('ti.sdo.utils.NameServer');
94     var HeapMultiBufMP  = xdc.useModule('ti.sdo.ipc.heaps.HeapMultiBufMP');
95     var Ipc             = xdc.useModule('ti.sdo.ipc.Ipc');
96     var SharedRegion    = xdc.useModule('ti.sdo.ipc.SharedRegion');
98     /* view.name */
99     view.name = NameServer.getName$view("HeapMultiBufMP",
100         SharedRegion.getSRPtrMeta$view(obj.attrs));
102     /* view.objType */
103     view.objType = Ipc.getObjTypeStr$view(obj.objType);
105     /* view.gate */
106     view.gate = obj.gate;
108     try {
109         var attrs = Program.fetchStruct(HeapMultiBufMP.Attrs$fetchDesc,
110                                         obj.attrs.$addr);
111         var totalSize = 0;
112         for (var i = 0; i < attrs.numBuckets; i++) {
113             totalSize += attrs.buckets[i].blockSize *
114                          attrs.buckets[i].numBlocks;
115         }
117         /* view.totalSize */
118         view.totalSize = "0x" + Number(totalSize).toString(16);
120         /* view.exact */
121         view.exact = attrs.exact == 1 ? true : false;
123         /* view.buf */
124         view.buf = $addr(obj.buf);
125     }
126     catch (e) {
127         throw("Error: could not access shared memory: " + e);
128     }
132 /*
133  *  ======== viewInitData ========
134  */
135 function viewInitData(view, obj)
137     var HeapMultiBufMP = xdc.useModule('ti.sdo.ipc.heaps.HeapMultiBufMP');
138     var SharedRegion   = xdc.useModule('ti.sdo.ipc.SharedRegion');
139     var NameServer     = xdc.useModule('ti.sdo.utils.NameServer');
141     /* Display the instance label in the tree */
142     view.label = NameServer.getName$view("HeapMultiBufMP",
143         SharedRegion.getSRPtrMeta$view(obj.attrs.$addr));
144     if (view.label == null) {
145         view.label = "0x" + Number(obj.attrs.$addr).toString(16);
146     }
148     /* Fetch attrs struct */
149     try {
150         var attrs = Program.fetchStruct(HeapMultiBufMP.Attrs$fetchDesc,
151                                         obj.attrs.$addr);
153         for (i = 0; i < Number(attrs.numBuckets); i++) {
154             var elem = Program.newViewStruct('ti.sdo.ipc.heaps.HeapMultiBufMP',
155                                              'Buffer Information');
156             elem.baseAddr       = "0x" + Number(SharedRegion.getPtrMeta$view(
157                 attrs.buckets[i].baseAddr)).toString(16);
158             elem.blockSize      = attrs.buckets[i].blockSize;
159             elem.align          = attrs.buckets[i].align;
160             elem.numBlocks      = attrs.buckets[i].numBlocks;
161             elem.numFreeBlocks  = attrs.buckets[i].numFreeBlocks;
163             elem.minFreeBlocks  = attrs.buckets[i].minFreeBlocks == 0xffffffff
164                                   ? -1 : attrs.buckets[i].minFreeBlocks;
166             /* Add the element to the list. */
167             view.elements.$add(elem);
168         }
169     }
170     catch (e) {
171         throw("Error: could not access shared memory: " + e);
172     }