FreeCalypso > hg > fc-selenite
comparison src/cs/riviera/rvm/rvm_api.c @ 0:b6a5e36de839
src/cs: initial import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Jul 2018 04:39:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b6a5e36de839 |
---|---|
1 /** | |
2 * | |
3 * @file rvm_api.c | |
4 * | |
5 * This file contains interface functions. | |
6 * | |
7 * @author Cristian Livadiotti (c-livadiotti@ti.com) | |
8 * @version 0.2 | |
9 * | |
10 */ | |
11 | |
12 /* | |
13 * Revision History: | |
14 * | |
15 * 06/04/2000 Cristian Livadiotti Create. | |
16 * 10/22/2001 David Lamy-Charrier Update for new Riviera 1.6. | |
17 * | |
18 * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved | |
19 */ | |
20 | |
21 | |
22 #ifndef _WINDOWS | |
23 #include "config/rv.cfg" | |
24 #endif | |
25 | |
26 #include "rvf/rvf_env.h" | |
27 | |
28 #include "rvm/rvm_gen.h" | |
29 #include "rvm/rvm_api.h" | |
30 #include "rvm/rvm_i.h" | |
31 #include "rvm/rvm_use_id_list.h" | |
32 | |
33 #include <string.h> | |
34 | |
35 extern T_RVM_KNOWN_SWE * rvm_swe_array; | |
36 | |
37 | |
38 /******************************************************************************* | |
39 ** Function rvm_start_environment | |
40 ** | |
41 ** Description Start the RV manager. | |
42 ** | |
43 *******************************************************************************/ | |
44 T_RVM_RETURN rvm_start_environment() | |
45 { T_RVF_BUFFER * rvm_stack; | |
46 | |
47 /* initialize the RVM */ | |
48 if ( rvm_init() == FALSE) | |
49 { return RVM_INTERNAL_ERR; | |
50 } | |
51 | |
52 /* start the RV manager task */ | |
53 | |
54 if ( rvf_get_buf( rvm_stack_mem_bank, RVM_STACK_SIZE, &rvm_stack) == RVF_RED ) | |
55 { return RVM_MEMORY_ERR; | |
56 } | |
57 | |
58 if ( rvf_create_task( rvm_task, RVM_TASK_ID, "RVM", rvm_stack, RVM_STACK_SIZE, RVM_PRIORITY, RVM_TASK, DEFAULT_TIME_SLICING, RUNNING) | |
59 != RVF_OK ) | |
60 { return RVM_INTERNAL_ERR; | |
61 } | |
62 | |
63 return RVM_OK; | |
64 } | |
65 | |
66 | |
67 /******************************************************************************* | |
68 ** | |
69 ** Function rvm_start_swe | |
70 ** | |
71 ** Description Called by an application to start the specified SWE | |
72 ** | |
73 ** Parameters: USE_ID of the SWE to start. | |
74 ** return path for asynchronous response | |
75 ** | |
76 ** Returns T_RVM_RETURN: RVM_OK if everything is ok, | |
77 ** RVM_INVALID_PARAMETER if the SWE USE_ID is unknown | |
78 ** RVM_NOT_READY if the get_info function has not been specified in the database | |
79 ** or the SWE has been already started. | |
80 ** RVM_MEMORY_ERR if there is not enough memory in the RVM memory bank. | |
81 ** RVM_INTERNAL_ERR if the RVM task has not been created. | |
82 ** | |
83 *******************************************************************************/ | |
84 T_RVM_RETURN rvm_start_swe (T_RVM_USE_ID swe_use_id, T_RV_RETURN_PATH return_path) | |
85 { | |
86 T_RVM_MSG *msg; | |
87 T_RVM_RETURN rvm_status; | |
88 UINT8 num_swe; | |
89 | |
90 /* Check Application is "startable" */ | |
91 if ((rvm_status = rvm_check_application (swe_use_id, &num_swe, RVM_START_APPLI)) != RVM_OK) | |
92 { | |
93 rvf_send_trace("RVM_task: rvm_start_swe() this appli cannot be started", 54, (UINT32)rvm_status, RV_TRACE_LEVEL_WARNING, RVM_USE_ID ); | |
94 return rvm_status; | |
95 } | |
96 | |
97 /* build a msg */ | |
98 if (rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_MSG), (void **)&msg) == RVF_RED ) | |
99 { | |
100 rvf_send_trace("RVM_task: No memory", 19, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID ); | |
101 return RVM_MEMORY_ERR; | |
102 } | |
103 | |
104 msg->header.msg_id = RVM_START_APPLI; | |
105 msg->header.src_addr_id = return_path.addr_id; | |
106 // msg->header.callback_func = return_path.callback_func; | |
107 msg->rp.callback_func = return_path.callback_func; | |
108 msg->swe_num = num_swe; | |
109 | |
110 rvf_send_trace("RVM: SWE START REQUEST", 22, rvm_swe_array[num_swe].swe_use_id, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID ); | |
111 | |
112 /* and send it to the RVM task to be treated by the RVM task */ | |
113 /* Note: task_id is used as the destination addr_id. This is only */ | |
114 /* true in the case of mailbox zero. Then task_id==addr_id */ | |
115 if ( rvf_send_msg( RVM_TASK_ID, msg) != RVF_OK) | |
116 { rvf_free_buf( msg); | |
117 return RVM_INTERNAL_ERR; | |
118 } | |
119 | |
120 return RVM_OK; | |
121 } | |
122 | |
123 /******************************************************************************* | |
124 ** | |
125 ** Function rvm_stop_swe | |
126 ** | |
127 ** Description Called by an application to stop the specified SWE. | |
128 ** | |
129 ** Parameters: USE_ID of the SWE to start. | |
130 ** return path for asynchronous response | |
131 ** | |
132 ** Returns T_RVM_RETURN: RVM_OK if everything is ok, | |
133 ** RVM_INVALID_PARAMETER if the USE_ID is unknown | |
134 ** RVM_NOT_READY if the get_info function has not been specified in the database | |
135 ** or the SWE is not running. | |
136 ** RVM_MEMORY_ERR if there is not enough memory in the RVM memory bank. | |
137 ** RVM_INTERNAL_ERR if the RVM task has not been created. | |
138 ** | |
139 ** RV2 ADDITIONAL NOTES: This now creates a RVM_STOP_MSG instead of a RVM_STOP_APPLI message. | |
140 ** both are supported in the RVM-FSM, hence the legacy concept may be reverted to easily | |
141 *******************************************************************************/ | |
142 T_RVM_RETURN rvm_stop_swe (T_RVM_USE_ID swe_use_id, T_RV_RETURN_PATH return_path) | |
143 { | |
144 T_RVM_STOP_MSG *msg; | |
145 T_RVM_RETURN rvm_status; | |
146 UINT8 num_swe; | |
147 | |
148 /* | |
149 ** Check Application is "stopable" | |
150 */ | |
151 if ((rvm_status = rvm_check_application (swe_use_id, &num_swe, RVM_STOP_APPLI)) != RVM_OK) | |
152 return rvm_status; | |
153 | |
154 /* build a msg */ | |
155 if (rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_STOP_MSG), (void **)&msg) == RVF_RED ) | |
156 { return RVM_MEMORY_ERR; | |
157 } | |
158 | |
159 msg->header.msg_id = RVM_STOP_MSG; | |
160 msg->header.src_addr_id = return_path.addr_id; | |
161 // msg->header.callback_func = return_path.callback_func; | |
162 msg->rp.callback_func = return_path.callback_func; | |
163 msg->swe_num = num_swe; | |
164 msg->status = SWE_RUNNING; | |
165 | |
166 /* and send it to the rve mailbox to be treated by the RVM task */ | |
167 if ( rvf_send_msg( RVM_TASK_ID, msg) != RVF_OK) | |
168 { rvf_free_buf( msg); | |
169 return RVM_INTERNAL_ERR; | |
170 } | |
171 | |
172 return RVM_OK; | |
173 } | |
174 | |
175 // NOTE: this may be used to enable the terminator to uncondionally | |
176 // kill the Entity. Mainly, spoofing RVM. | |
177 T_RVM_RETURN rvm_kill_immediate (T_RVM_USE_ID swe_use_id, T_RV_RETURN_PATH return_path){ | |
178 T_RVM_STOP_MSG *msg; | |
179 T_RVM_RETURN rvm_status; | |
180 UINT8 num_swe; | |
181 | |
182 /* | |
183 ** Check Application is "stopable" | |
184 */ | |
185 if ((rvm_status = rvm_check_application (swe_use_id, &num_swe, RVM_STOP_APPLI)) != RVM_OK) | |
186 return rvm_status; | |
187 | |
188 /* build a msg */ | |
189 if (rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_STOP_MSG), (void **)&msg) == RVF_RED ) | |
190 { return RVM_MEMORY_ERR; | |
191 } | |
192 | |
193 msg->header.msg_id = RVM_STOP_MSG; | |
194 msg->header.src_addr_id = return_path.addr_id; | |
195 // msg->header.callback_func = return_path.callback_func; | |
196 msg->rp.callback_func = return_path.callback_func; | |
197 msg->swe_num = num_swe; | |
198 msg->status = SWE_STOPPING; | |
199 | |
200 /* and send it to the rve mailbox to be treated by the RVM task */ | |
201 if ( rvf_send_msg( RVM_TASK_ID, msg) != RVF_OK) | |
202 { rvf_free_buf( msg); | |
203 return RVM_INTERNAL_ERR; | |
204 } | |
205 | |
206 return RVM_OK; | |
207 } | |
208 | |
209 T_RVM_RETURN rvm_swe_stopped(T_RV_HDR* p_msg) { | |
210 T_RVM_STOP_MSG *msg=(T_RVM_STOP_MSG*)p_msg; | |
211 | |
212 msg->status = SWE_STOPPING; | |
213 | |
214 if ( rvf_send_msg( RVM_TASK_ID, msg) != RVF_OK) { | |
215 rvf_free_buf( msg); | |
216 return RVM_INTERNAL_ERR; | |
217 } | |
218 return RVM_OK; | |
219 } | |
220 | |
221 /******************************************************************************* | |
222 ** | |
223 ** Function rvm_snd_msg_to_upper | |
224 ** | |
225 ** Description Called during processing to report to MMI the result of an | |
226 ** action. | |
227 ** | |
228 ** Parameters: name of the application to start. | |
229 ** return path for asynchronous response | |
230 ** | |
231 ** Returns T_RVM_RETURN: RVM_OK if everything is ok, | |
232 ** RVM_INVALID_PARAMETER if the appli name is unknown | |
233 ** RVM_NOT_READY if the get_info function has not been specified in the database | |
234 ** or the application has been already started. | |
235 ** RVM_MEMORY_ERR if there is not enough memory in the RVM memory bank. | |
236 ** RVM_INTERNAL_ERR if the RVM task has not been created. | |
237 ** | |
238 *******************************************************************************/ | |
239 T_RVM_RETURN rvm_snd_msg_to_upper (T_RVM_APPLI_ACTION action, | |
240 T_RVM_RETURN result, | |
241 UINT8 swe_num, | |
242 T_RV_RETURN_PATH return_path) | |
243 { | |
244 T_RVM_APPLI_RESULT *msg; | |
245 | |
246 | |
247 /* build a msg */ | |
248 if (rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_APPLI_RESULT), (void **)&msg) == RVF_RED ) | |
249 { return RVM_MEMORY_ERR; | |
250 } | |
251 | |
252 msg->header.msg_id = RVM_EVT_TO_APPLI; | |
253 msg->header.src_addr_id = RVM_TASK_ID; | |
254 // msg->header.callback_func = return_path.callback_func; | |
255 msg->rp.callback_func = return_path.callback_func; | |
256 msg->result = result; | |
257 msg->action = action; | |
258 msg->swe_index = swe_num; | |
259 | |
260 memcpy(msg->swe_name, rvm_swe_array[swe_num].swe_name, RVM_NAME_MAX_LEN); | |
261 | |
262 /* and send it to the rve mailbox to be treated by the RVM task */ | |
263 if (return_path.callback_func) | |
264 { | |
265 return_path.callback_func ((void*) msg); | |
266 } | |
267 else | |
268 { | |
269 if ( rvf_send_msg(return_path.addr_id, (void*)msg) != RVF_OK) | |
270 { rvf_free_buf( msg); | |
271 return RVM_INTERNAL_ERR; | |
272 } | |
273 } | |
274 | |
275 return RVM_OK; | |
276 } | |
277 | |
278 | |
279 | |
280 /******************************************************************************* | |
281 ** | |
282 ** Function rvm_get_swe_information | |
283 ** | |
284 ** Description Called by a SWE to know information about another SWE. | |
285 ** | |
286 ** Parameters In: name of the swe we want to get information about. | |
287 ** | |
288 ** Parameters Out: State of the SWE. | |
289 ** | |
290 ** Returns T_RVM_RETURN: RVM_OK if everything is ok, | |
291 ** RVM_INVALID_PARAMETER if the SWE use_id is unknown | |
292 ** RVM_NOT_READY if the | |
293 ** RVM_MEMORY_ERR if there is not enough memory in the RVM memory bank. | |
294 ** RVM_INTERNAL_ERR if the RVM task has not been created. | |
295 ** | |
296 *******************************************************************************/ | |
297 T_RVM_RETURN rvm_get_swe_information (T_RVM_USE_ID swe_id, | |
298 T_RV_RETURN_PATH * return_path) | |
299 { | |
300 UINT8 swe_index; | |
301 | |
302 if (rvm_get_swe_index(&swe_index, swe_id) != RVM_OK) | |
303 { | |
304 | |
305 RVM_TRACE_WARNING_PARAM("RVM API: Get SWE Information of an unknown SWE, use_id:", swe_id); | |
306 return RVM_INVALID_PARAMETER; | |
307 } | |
308 | |
309 if (return_path != NULL) | |
310 { | |
311 (*return_path).callback_func = rvm_swe_array[swe_index].swe_return_path.callback_func; | |
312 (*return_path).addr_id = rvm_swe_array[swe_index].swe_addr_id; | |
313 } | |
314 | |
315 return RVM_OK; | |
316 } | |
317 |