]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - src/ti/sdo/ipc/gates/GateHWSem.xs
Rename: Renamed packages to src to allow application of ipc-j tree commits.
[ipc/ipcdev.git] / src / ti / sdo / ipc / gates / GateHWSem.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  *  ======== GateHWSem.xs ========
34  *
35  */
37 var GateHWSem   = null;
38 var GateMP      = null;
39 var Ipc         = null;
41 /*
42  *  ======== module$meta$init ========
43  */
44 function module$meta$init()
45 {
46     /* Only process during "cfg" phase */
47     if (xdc.om.$name != "cfg") {
48         return;
49     }
51     GateHWSem = this
53     try {
54         var Settings = xdc.module("ti.sdo.ipc.family.Settings");
55         var devCfg = Settings.getGateHWSemSettings();
56         GateHWSem.baseAddr      = devCfg.baseAddr;
57         GateHWSem.queryAddr     = devCfg.queryAddr;
58         GateHWSem.numSems       = devCfg.numSems;
60         GateHWSem.reservedMaskArr.length =
61                 Math.ceil(GateHWSem.numSems / 32);
62         for (var i = 0; i < GateHWSem.reservedMaskArr.length; i++) {
63             GateHWSem.reservedMaskArr[i] = 0;
64         }
65     }
66     catch(e) {
67     }
68 }
70 /*
71  *  ======== queryMeta ========
72  */
73 function queryMeta(qual)
74 {
75     var rc = false;
76     var IGateProvider = xdc.module('xdc.runtime.IGateProvider');
78     switch (qual) {
79         case IGateProvider.Q_BLOCKING:
80             rc = true;
81             break;
82         case IGateProvider.Q_PREEMPTING:
83             rc = true;
84             break;
85         default:
86            GateHWSem.$logWarning("Invalid quality.", this, qual);
87            break;
88     }
90     return (rc);
91 }
93 /*
94  *  ======== getNumResources ========
95  */
96 function getNumResources()
97 {
98     return (GateHWSem.numSems);
99 }
101 /*
102  *  ======== setReserved ========
103  */
104 function setReserved(semNum)
106     var GateHWSem = this;
108     if (semNum >= GateHWSem.numSems) {
109         GateHWSem.$logError("Invalid semaphore number: " + GateHWSem.numSems +
110                 ". There are only " + GateHWSem.numSems + " on this device.",
111                 this);
112     }
114     GateHWSem.reservedMaskArr[semNum >> 5] |= (1 << (semNum % 32));
117 /*
118  *************************************************************************
119  *                       ROV View functions
120  *************************************************************************
121  */
123 /*
124  *  ======== getRemoteStatus$view ========
125  */
126 function getRemoteStatus$view(handle)
128     var Program         = xdc.useModule('xdc.rov.Program');
130     try {
131         var view = Program.scanHandleView('ti.sdo.ipc.gates.GateHWSem',
132                                           $addr(handle), 'Basic');
133         return ("Entered by " + view.enteredBy);
134     }
135     catch(e) {
136         throw("ERROR: Couldn't scan GateHWSem handle view: " + e);
137     }
139     return (status);
142 /*
143  *  ======== viewInitBasic ========
144  */
145 function viewInitBasic(view, obj)
147     var GateHWSem       = xdc.useModule('ti.sdo.ipc.gates.GateHWSem');
148     var ScalarStructs   = xdc.useModule('xdc.rov.support.ScalarStructs');
150     /* view.semNum */
151     view.semNum = obj.semNum;
153     /* view.nested */
154     view.nested = obj.nested;
156     /* view.enteredBy */
157     try {
158         var modCfg = Program.getModuleConfig('ti.sdo.ipc.gates.GateHWSem');
159         var semQueryAddr = $addr(Number(modCfg.queryAddr) + obj.semNum * 4);
161         var sstruct_status = Program.fetchStruct(
162                                 ScalarStructs.S_Bits32$fetchDesc,
163                                 semQueryAddr, false);
164         var status = sstruct_status.elem;
165         if (status & 0x1) {
166             view.enteredBy = "[free]";
167         }
168         else {
169             var coreId = (status & 0x0000ff00) >> 8;
170             view.enteredBy = "CORE" + coreId;
171         }
172     }
173     catch(e) {
174         view.$status["enteredBy"] =
175             "Error: could not fetch query data: " + e;
176     }