]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - packages/ti/sdo/ipc/family/f28m35x/TransportCirc.xs
Add defaultErrFxn and an err fxn to module state
[ipc/ipcdev.git] / packages / ti / sdo / ipc / family / f28m35x / TransportCirc.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  *  ======== TransportCirc.xs ========
34  */
36 var TransportCirc = null;
37 var MessageQ     = null;
38 var Notify       = null;
39 var MultiProc    = null;
40 var Swi          = null;
42 /*
43  *  ======== module$use ========
44  */
45 function module$use()
46 {
47     TransportCirc = this;
48     MessageQ     = xdc.useModule("ti.sdo.ipc.MessageQ");
49     Notify       = xdc.useModule("ti.sdo.ipc.Notify");
50     MultiProc    = xdc.useModule("ti.sdo.utils.MultiProc");
51     Swi          = xdc.useModule("ti.sysbios.knl.Swi");
52 }
54 /*
55  * ======== module$static$init ========
56  */
57 function module$static$init(mod, params)
58 {
59     var target = Program.build.target;
60     var bitsPerByte = 8;
61     var bitsPerChar = target.bitsPerChar;
63     /* calculate the msgSize */
64     TransportCirc.msgSize = TransportCirc.maxMsgSizeInBytes *
65                               (bitsPerByte / bitsPerChar);
67     /* calculate the maxIndex */
68     TransportCirc.maxIndex = TransportCirc.numMsgs - 1;
70     /* determine numMsgs is a power of 2 */
71     if (TransportCirc.numMsgs & (TransportCirc.maxIndex)) {
72         TransportCirc.$logFatal("TransportCirc.numMsgs: " +
73                 TransportCirc.numMsgs +
74                 " is not a power of 2", TransportCirc);
75     }
77     if (params.errFxn != null) {
78         mod.errFxn = params.errFxn;
79     }
80     else {
81         mod.errFxn = TransportCirc.defaultErrFxn;
82     }
83 }
85 /*
86  *  ======== module$validate ========
87  */
88 function module$validate()
89 {
90     if (Notify.numEvents <= TransportCirc.notifyEventId) {
91         TransportCirc.$logFatal("TransportCirc.notifyEventId (" +
92                 TransportCirc.notifyEventId +
93                 ") is too big: Notify.numEvents = " + Notify.numEvents,
94                 TransportCirc);
95     }
96 }
98 /*
99  *  ======== sharedMemReqMeta ========
100  */
101 function sharedMemReqMeta(params)
103     var target = Program.build.target;
104     var bitsPerByte = 8;
105     var bitsPerChar = target.bitsPerChar;
107     /* calculate the msgSize */
108     var msgSize = TransportCirc.maxMsgSizeInBytes *
109                   (bitsPerByte / bitsPerChar);
111     /*
112      *  Amount of shared memory:
113      *  1 putBuffer (msgSize * numMsgs) +
114      *  1 putWriteIndex ptr             +
115      *  1 putReadIndex ptr              +
116      */
117     var memReq = (msgSize * TransportCirc.numMsgs) +
118                  (2 *  Program.build.target.stdTypes['t_Int32'].size);
120     return (memReq);
123 /*
124  *************************************************************************
125  *                       ROV View functions
126  *************************************************************************
127  */
129 /*
130  *  ======== viewInitBasic ========
131  */
132 function viewInitBasic(view, obj)
134     var MultiProc = xdc.useModule('ti.sdo.utils.MultiProc');
135     var MultiProcCfg = Program.getModuleConfig('ti.sdo.utils.MultiProc');
137     /* view.remoteProcName */
138     try {
139         view.remoteProcName = MultiProc.getName$view(obj.remoteProcId -
140                                   MultiProcCfg.baseIdOfCluster);
141     }
142     catch(e) {
143         Program.displayError(view, 'remoteProcName',
144                              "Problem retrieving proc name: " + e);
145     }
148 /*
149  *  ======== getEventData ========
150  *  Helper function for use within viewInitData
151  */
152 function getEventData(view, obj, bufferPtr, putIndex, getIndex)
154     var TransportCirc =
155         xdc.useModule('ti.sdo.ipc.family.f28m35x.TransportCirc');
156     var modCfg =
157         Program.getModuleConfig('ti.sdo.ipc.family.f28m35x.TransportCirc');
158     var ScalarStructs   = xdc.useModule('xdc.rov.support.ScalarStructs');
160     if (bufferPtr == obj.putBuffer) {
161         var bufferName = "put";
162     }
163     else {
164         var bufferName = "get";
165     }
167     try {
168         var putBuffer = Program.fetchArray(ScalarStructs.S_Bits32$fetchDesc,
169                                            bufferPtr,
170                                            modCfg.numMsgs);
171     }
172     catch(e) {
173         throw (new Error("Error fetching putBuffer struct from shared memory"));
174     }
176     var i = getIndex;
178     while (i != putIndex) {
179         /* The event is registered */
180         var elem = Program.newViewStruct(
181                 'ti.sdo.ipc.family.f28m35x.TransportCirc',
182                 'Events');
184         elem.index = i;
185         elem.buffer = bufferName;
186         elem.message = utils.toHex(Number(bufferPtr) + (i * modCfg.msgSize));
188         /* Create a new row in the instance data view */
189         view.elements.$add(elem);
191         i++;
192         if ((i % modCfg.numMsgs) == 0) {
193             i = 0;
194         }
195     }
199 /*
200  *  ======== viewInitData ========
201  *  Instance data view.
202  */
203 function viewInitData(view, obj)
205     var Program         = xdc.useModule('xdc.rov.Program');
206     var ScalarStructs   = xdc.useModule('xdc.rov.support.ScalarStructs');
207     var MultiProc       = xdc.useModule('ti.sdo.utils.MultiProc');
209     /* Display the instance label in the tree */
210     view.label = "remoteProcId = " + obj.remoteProcId;
212     /* Fetch put/get index's */
213     try {
214         var putWriteIndex = Program.fetchStruct(ScalarStructs.S_Bits32$fetchDesc,
215                                                 obj.putWriteIndex);
216     }
217     catch(e) {
218         throw (new Error("Error fetching putWriteIndex struct from shared memory"));
219     }
221     try {
222         var putReadIndex = Program.fetchStruct(ScalarStructs.S_Bits32$fetchDesc,
223                                                obj.putReadIndex);
224     }
225     catch(e) {
226         throw (new Error("Error fetching putReadIndex struct from shared memory"));
227     }
229     try {
230         var getWriteIndex = Program.fetchStruct(ScalarStructs.S_Bits32$fetchDesc,
231                                                 obj.getWriteIndex);
232     }
233     catch(e) {
234         throw (new Error("Error fetching getWriteIndex struct from shared memory"));
235     }
237     try {
238         var getReadIndex = Program.fetchStruct(ScalarStructs.S_Bits32$fetchDesc,
239                                                obj.getReadIndex);
240     }
241     catch(e) {
242         throw (new Error("Error fetching getReadIndex struct from shared memory"));
243     }
245     /* Get event data for the put buffer */
246     getEventData(view, obj, obj.putBuffer, putWriteIndex.elem, putReadIndex.elem);
248     /* Get event data for the get buffer */
249     getEventData(view, obj, obj.getBuffer, getWriteIndex.elem, getReadIndex.elem);