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.c ========
34 * Implementation of functions specified in MultiProc.xdc.
35 */
37 #include <xdc/std.h>
38 #include <string.h>
39 #include <xdc/runtime/Assert.h>
40 #include <xdc/runtime/Startup.h>
42 #include <ti/sdo/utils/_MultiProc.h>
44 #include "package/internal/MultiProc.xdc.h"
46 #ifdef __ti__
47 #pragma FUNC_EXT_CALLED(MultiProc_getBaseIdOfCluster);
48 #pragma FUNC_EXT_CALLED(MultiProc_getId);
49 #pragma FUNC_EXT_CALLED(MultiProc_getName);
50 #pragma FUNC_EXT_CALLED(MultiProc_getNumProcessors);
51 #pragma FUNC_EXT_CALLED(MultiProc_getNumProcsInCluster);
52 #pragma FUNC_EXT_CALLED(MultiProc_self);
53 #pragma FUNC_EXT_CALLED(MultiProc_setBaseIdOfCluster);
54 #pragma FUNC_EXT_CALLED(MultiProc_setLocalId);
55 #endif
57 /*
58 *************************************************************************
59 * Common Header Functions
60 *************************************************************************
61 */
63 /*
64 * ======== MultiProc_getBaseIdOfCluster ========
65 */
66 UInt16 MultiProc_getBaseIdOfCluster()
67 {
68 return (MultiProc_module->baseIdOfCluster);
69 }
71 /*
72 * ======== MultiProc_getId ========
73 */
74 UInt16 MultiProc_getId(String name)
75 {
76 Int i;
77 UInt16 id;
79 Assert_isTrue(name != NULL, ti_sdo_utils_MultiProc_A_invalidProcName);
81 id = MultiProc_INVALIDID;
82 for (i = 0; i < ti_sdo_utils_MultiProc_numProcsInCluster; i++) {
83 if ((ti_sdo_utils_MultiProc_nameList[i] != NULL) &&
84 (strcmp(name, ti_sdo_utils_MultiProc_nameList[i]) == 0)) {
85 id = i + MultiProc_module->baseIdOfCluster;
86 }
87 }
88 return (id);
89 }
91 /*
92 * ======== MultiProc_getClusterId ========
93 */
94 UInt16 ti_sdo_utils_MultiProc_getClusterId(UInt16 procId)
95 {
96 return (procId - MultiProc_module->baseIdOfCluster);
97 }
99 /*
100 * ======== MultiProc_getName ========
101 */
102 String MultiProc_getName(UInt16 id)
103 {
104 Assert_isTrue((id < ti_sdo_utils_MultiProc_numProcessors),
105 ti_sdo_utils_MultiProc_A_invalidMultiProcId);
107 return (ti_sdo_utils_MultiProc_nameList[id -
108 MultiProc_module->baseIdOfCluster]);
109 }
111 /*
112 * ======== MultiProc_getNumProcessors ========
113 */
114 UInt16 MultiProc_getNumProcessors()
115 {
116 return (ti_sdo_utils_MultiProc_numProcessors);
117 }
119 /*
120 * ======== MultiProc_getNumProcsInCluster ========
121 */
122 UInt16 MultiProc_getNumProcsInCluster()
123 {
124 return (ti_sdo_utils_MultiProc_numProcsInCluster);
125 }
127 /*
128 * ======== MultiProc_self ========
129 */
130 UInt16 MultiProc_self()
131 {
132 return (MultiProc_module->id);
133 }
135 /*
136 * ======== MultiProc_setBaseIdOfCluster ========
137 */
138 Int MultiProc_setBaseIdOfCluster(UInt16 baseId)
139 {
140 /* baseId + numProcsInCluster must be less than the number of processors */
141 Assert_isTrue(((baseId + ti_sdo_utils_MultiProc_numProcsInCluster)
142 < ti_sdo_utils_MultiProc_numProcessors),
143 ti_sdo_utils_MultiProc_A_invalidMultiProcId);
145 /*
146 * Check the following
147 * 1. Make sure the call is made before module startup
148 */
149 if (Startup_rtsDone() == FALSE) {
150 /* It is ok to set clusterBaseId */
151 MultiProc_module->baseIdOfCluster = baseId;
153 return (MultiProc_S_SUCCESS);
154 }
156 return (MultiProc_E_FAIL);
157 }
159 /*
160 * ======== MultiProc_setLocalId ========
161 */
162 Int MultiProc_setLocalId(UInt16 id)
163 {
164 /* id must be less than the number of processors */
165 Assert_isTrue((id < ti_sdo_utils_MultiProc_numProcessors),
166 ti_sdo_utils_MultiProc_A_invalidMultiProcId);
168 /*
169 * Check the following
170 * 1. Make sure the statically configured constant was invalid.
171 * To call setLocalId, the id must have been set to invalid.
172 * 2. Make sure the call is made before module startup
173 */
174 if ((MultiProc_self() == MultiProc_INVALIDID) &&
175 (Startup_rtsDone() == FALSE)) {
177 /* It is ok to set the id */
178 MultiProc_module->id = id;
179 return (MultiProc_S_SUCCESS);
180 }
182 return (MultiProc_E_FAIL);
183 }
185 /*
186 * ======== ti_sdo_utils_MultiProc_dummy ========
187 */
188 Void ti_sdo_utils_MultiProc_dummy()
189 {
190 }