comparison chipsetsw/riviera/rvm/rvm_swe_db.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /**
2 *
3 * @file rvm_swe_db.c
4 *
5 * This file contains the functions related to the SW Entities
6 * database management.
7 *
8 * @author David Lamy-Charrier (d-lamy@ti.com)
9 * @version 0.2
10 *
11 */
12
13 /*
14 * Revision History:
15 *
16 * 01/19/2000 David Lamy-Charrier Create.
17 * 10/22/2001 David Lamy-Charrier Update for new Riviera 1.6.
18 *
19 * (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved
20 */
21
22 #include "rvf/rvf_env.h"
23
24 #include "rvm/rvm_gen.h"
25 #include "rvm/rvm_api.h"
26 #include "rvm/rvm_i.h"
27 #include "rvm/rvm_use_id_list.h"
28
29 #include <string.h>
30
31 extern T_RVM_CONST_SWE_INFO RVM_SWE_GET_INFO_ARRAY[];
32
33 extern const T_RVM_USE_ID * RVM_TYPE2_SWE_GROUPS[];
34
35
36 /* id of the main rvm memory bank */
37 T_RVF_MB_ID rvm_mem_bank=RVF_INVALID_MB_ID;
38 T_RVF_MB_ID rvm_sys_mem_bank=RVF_INVALID_MB_ID;
39 T_RVF_MB_ID rvm_timer_mem_bank=RVF_INVALID_MB_ID;
40 T_RVF_MB_ID rvm_tm_notify_mem_bank=RVF_INVALID_MB_ID;
41 T_RVF_MB_ID rvm_stack_mem_bank=RVF_INVALID_MB_ID;
42
43
44 /* database of all SW Entities, their name, their get_info function and their links */
45 T_RVM_KNOWN_SWE * rvm_swe_array;
46
47 T_RVM_GROUP_INFO * rvm_group_array;
48
49 /*
50 ** Used task id array
51 ** This array allows the RVM to allocate dynamically task ids to SWEs
52 ** The task ids are allocated during creation.
53 */
54 /*BOOLEAN rvm_allocated_task_id [MAX_RVF_TASKS]; */
55
56 /*
57 ** Number of SW Entities known on the system
58 */
59 UINT8 rvm_swe_number = 0;
60
61
62 /*******************************************************************************
63 ** Function rvm_init_swe_db
64 **
65 ** Description Internal function called once at the beginning which
66 ** initializes the SWE database from information gathered
67 ** in a const array (defined in rvm_swe.c).
68 **
69 *******************************************************************************/
70 T_RVM_RETURN rvm_init_swe_db ()
71 {
72 UINT8 swe_cpt=0, i=0, j=0, group_cpt = 0;
73 T_RVM_INFO_SWE swe_info;
74 char rvm_trace_name[RVM_NAME_MAX_LEN+20] = "SWE Name: ";
75
76 /* Initialize the allocated task id array */
77 /* for (i=0; i<MAX_RVF_TASKS; i++)
78 {
79 rvm_allocated_task_id[i] = FALSE;
80 }
81 */
82 /* None task ID allocated at startup except:
83 * - RVM_TASK_ID,
84 * - RVTEST_MENU_TASK_ID,
85 * - DUMMY_TASK_ID.
86 *
87 * Refer to rv_general.h.
88 *
89 * TO DO: Remove the last two IDs as soon as managed as SWEs. */
90 /* rvm_allocated_task_id[RVM_TASK_ID] = TRUE;
91
92 if ( RVTEST_MENU_TASK_ID < MAX_RVF_TASKS)
93 { rvm_allocated_task_id[RVTEST_MENU_TASK_ID] = TRUE;
94 }
95
96 if ( IDLE_TASK_ID < MAX_RVF_TASKS)
97 { rvm_allocated_task_id[IDLE_TASK_ID] = TRUE;
98 }
99 */
100
101 /* Get the number of known SWEs */
102 while ( ( RVM_SWE_GET_INFO_ARRAY[swe_cpt].get_info_func) != NULL)
103 {
104 swe_cpt++;
105 }
106 rvm_swe_number = swe_cpt;
107 RVM_TRACE_DEBUG_HIGH_PARAM("RVM: number of registered SWE in the system: ", rvm_swe_number);
108
109 /* Get memory for the SWEs array */
110 if ( rvf_get_buf( rvm_mem_bank, (swe_cpt+1)*sizeof(T_RVM_KNOWN_SWE), (T_RVF_BUFFER**)&rvm_swe_array ) == RVF_RED )
111 {
112 RVM_TRACE_WARNING("RVM_init_swe_db: not enough memory in the RVM main memory bank for init of array");
113 return RVM_MEMORY_ERR;
114 }
115 memset(rvm_swe_array, 0, (swe_cpt+1)*sizeof(T_RVM_KNOWN_SWE));
116
117 /* call all get_info functions to gather information about the SWEs */
118 for (i=0; i<swe_cpt; i++)
119 {
120 /* Call get info fct */
121 (RVM_SWE_GET_INFO_ARRAY[i].get_info_func)(&swe_info);
122
123 /* Init global structure */
124 rvm_swe_array[i].swe_get_info = RVM_SWE_GET_INFO_ARRAY[i].get_info_func;
125 rvm_swe_array[i].swe_use_id = RVM_SWE_GET_INFO_ARRAY[i].use_id;
126 rvm_swe_array[i].swe_addr_id = RVF_INVALID_ADDR_ID;
127 rvm_swe_array[i].group_index = RVM_OWN_GROUP;
128 rvm_swe_array[i].swe_type = swe_info.swe_type;
129
130 switch(swe_info.swe_type)
131 {
132 case(RVM_SWE_TYPE_1):
133 { strcpy (rvm_swe_array[i].swe_name, swe_info.type_info.type1.swe_name);
134 rvm_swe_array[i].swe_return_path.callback_func = swe_info.type_info.type1.return_path.callback_func;
135 rvm_swe_array[i].swe_use_id = swe_info.type_info.type1.swe_use_id;
136 rvm_swe_array[i].swe_stack_size = 0;
137 rvm_swe_array[i].swe_priority = 0;
138 break;
139 }
140
141 case(RVM_SWE_TYPE_2):
142 { strcpy (rvm_swe_array[i].swe_name, swe_info.type_info.type2.swe_name);
143 rvm_swe_array[i].swe_return_path.callback_func = swe_info.type_info.type2.return_path.callback_func;
144 rvm_swe_array[i].swe_use_id = swe_info.type_info.type2.swe_use_id;
145 rvm_swe_array[i].swe_stack_size = swe_info.type_info.type2.stack_size;
146 rvm_swe_array[i].swe_priority = swe_info.type_info.type2.priority;
147 break;
148 }
149
150 case(RVM_SWE_TYPE_3):
151 { strcpy (rvm_swe_array[i].swe_name, swe_info.type_info.type3.swe_name);
152 rvm_swe_array[i].swe_return_path.callback_func = swe_info.type_info.type3.return_path.callback_func;
153 rvm_swe_array[i].swe_use_id = swe_info.type_info.type3.swe_use_id;
154 rvm_swe_array[i].swe_stack_size = swe_info.type_info.type3.stack_size;
155 rvm_swe_array[i].swe_priority = swe_info.type_info.type3.priority;
156 break;
157 }
158
159 case(RVM_SWE_TYPE_4):
160 { strcpy (rvm_swe_array[i].swe_name, swe_info.type_info.type4.swe_name);
161 rvm_swe_array[i].swe_return_path.callback_func = swe_info.type_info.type4.return_path.callback_func;
162 rvm_swe_array[i].swe_use_id = swe_info.type_info.type4.swe_use_id;
163 rvm_swe_array[i].swe_stack_size = swe_info.type_info.type4.stack_size;
164 rvm_swe_array[i].swe_priority = swe_info.type_info.type4.priority;
165 break;
166 }
167 }
168
169
170 rvm_swe_array[i].swe_state = SWE_NOT_STARTED;
171 rvm_swe_array[i].stack_ptr = NULL;
172 rvm_swe_array[i].nb_using_appli = 0;
173
174 for (j=0; j<RVM_MAX_SWE_USING; j++)
175 {
176 rvm_swe_array[i].using_appli[j] = RVM_INVALID_SWE_INDEX;
177 }
178
179 rvm_swe_array[i].swe_return_path.addr_id = RVF_INVALID_ADDR_ID;
180
181 rvm_swe_array[i].mmi_return_path.callback_func = NULL;
182 rvm_swe_array[i].mmi_return_path.addr_id = RVF_INVALID_ADDR_ID;
183 }
184
185 RVM_TRACE_DEBUG_HIGH("RVM init: Known SWE database built");
186
187 /* display the list of known SWEs with their name, use_id and index in the array. */
188 for (i=0; i<swe_cpt; i++)
189 {
190 strcpy(rvm_trace_name + 10, rvm_swe_array[i].swe_name);
191 rvf_send_trace(rvm_trace_name , (UINT8)strlen(rvm_trace_name), NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, RVM_USE_ID );
192 RVM_TRACE_DEBUG_LOW_PARAM("SWE number:", i);
193 RVM_TRACE_DEBUG_LOW_PARAM("SWE use_id:", rvm_swe_array[i].swe_use_id);
194 }
195
196 /* initialize SWEs group array */
197
198 /* Get the number of groups
199 group_cpt = 0;
200 while ( (RVM_TYPE2_SWE_GROUPS[group_cpt]) != NULL)
201 {
202 i++;
203 }
204
205 // Get memory for the groups array
206 if ( rvf_get_buf( rvm_mem_bank, (group_cpt+1)*sizeof(T_RVM_GROUP_INFO), (T_RVF_BUFFER**)&rvm_group_array ) == RVF_RED )
207 {
208 RVM_TRACE_WARNING("RVM_build_swe_list: not enough memory in the RVM main memory bank for init of group array");
209 return RVM_MEMORY_ERR;
210 }
211 memset(rvm_group_array, 0, (group_cpt+1)*sizeof(T_RVM_GROUP_INFO));
212
213 // update the group_index of each type 2 SWE.
214 for( i = 0; i < group_cpt; i++)
215 { rvm_group_array[i].host_state = SWE_NOT_STARTED;
216 rvm_group_array[i].task_id = RVF_INVALID_TASK;
217 rvm_group_array[i].task_priority= 255;
218
219 if( RVM_TYPE2_SWE_GROUPS[i] != NULL)
220 { UINT8 index;
221 j = 0;
222 while( RVM_TYPE2_SWE_GROUPS[i][j] != RVM_INVALID_USE_ID)
223 { if( rvm_get_swe_index( &index, RVM_TYPE2_SWE_GROUPS[i][j]) == RVM_OK)
224 { // store the host group in the SWE
225 rvm_swe_array[index].group_index = i;
226
227 // computes the highest stack size
228 if( rvm_swe_array[index].swe_stack_size > rvm_group_array[i].stack_size)
229 { rvm_group_array[i].stack_size = rvm_swe_array[index].swe_stack_size;
230 }
231
232 // computes the smallest priority
233 if( rvm_swe_array[index].swe_priority < rvm_group_array[i].task_priority)
234 { rvm_group_array[i].task_priority = rvm_swe_array[index].swe_priority;
235 }
236 }
237 j++;
238 }
239 }
240 }
241 */
242 return RVM_OK;
243 }
244
245
246 /*******************************************************************************
247 ** Function rvm_get_swe_index
248 **
249 ** Description Internal function which returns the index of the swe in the
250 ** database of known SWEs.
251 ** Returns RVM_OK if it exists, else RVM_INVALID_PARAMETER.
252 *******************************************************************************/
253 T_RVM_RETURN rvm_get_swe_index( UINT8 * index, T_RVM_USE_ID swe_use_id)
254 { for ( (*index) = 0; ( (*index) < rvm_swe_number) && (swe_use_id != rvm_swe_array[*index].swe_use_id) ; (*index)++);
255 if ( *index == rvm_swe_number ) /* swe use id not found */
256 {
257 *index = RVM_INVALID_SWE_INDEX;
258 return RVM_INVALID_PARAMETER;
259 }
260 return RVM_OK;
261 }
262
263
264 /*******************************************************************************
265 ** Function rvm_check_application
266 **
267 ** Description Internal function which checks if a SWE can be started
268 ** or stopped, depending on appli_action parameter.
269 ** If it is the case, it returns the application number.
270 *******************************************************************************/
271 T_RVM_RETURN rvm_check_application (T_RVM_USE_ID swe_use_id, UINT8* num_swe, T_RVM_APPLI_ACTION appli_action)
272 {
273 /* check if the SWE use_id exists */
274 if (rvm_get_swe_index(num_swe, swe_use_id) != RVM_OK)
275 {
276 return RVM_INVALID_PARAMETER;
277 }
278
279 /* check if the get_info function is known */
280 if (rvm_swe_array[*num_swe].swe_get_info == NULL )
281 {
282 *num_swe = 0;
283 return RVM_NOT_READY;
284 }
285
286 /* check if the appli can be started or stopped */
287 /* if ((appli_action == RVM_START_APPLI) && ( rvm_swe_array[*num_swe].swe_state != SWE_NOT_STARTED))
288 {
289 *num_swe = 0;
290 return RVM_NOT_READY;
291 }
292 */
293 /* If more than 1 SWE is using the application, we cannot stop it */
294 /* if (appli_action == RVM_STOP_APPLI)
295 {
296 if ( (rvm_swe_array[*num_swe].swe_state != SWE_RUNNING) || \
297 (rvm_swe_array[*num_swe].nb_using_appli != 1) || \
298 (rvm_swe_array[rvm_swe_array[*num_swe].using_appli[0]].swe_use_id != rvm_swe_array[*num_swe].swe_use_id) )
299 {
300 *num_swe = 0;
301 return RVM_NOT_READY;
302 }
303 }*/
304
305 return RVM_OK;
306 }
307
308
309 /*******************************************************************************
310 ** Function rvm_unlock_swe
311 **
312 ** Description Internal function that sets back SWE state to NOT_STARTED
313 ** in case an error occurs or the stop process is finished
314 *******************************************************************************/
315 T_RVM_RETURN rvm_unlock_swe ( T_RVM_PROCESSING_SWE * appli)
316 {
317 T_RVM_PROCESSING_SWE * cur_elem = appli;
318
319 while (cur_elem)
320 {
321 UINT8 swe_index = cur_elem->swe_id;
322
323 if (rvm_swe_array[swe_index].swe_state != SWE_RUNNING)
324 {
325 cur_elem = cur_elem->next_swe;
326 continue;
327 }
328
329 rvm_swe_array[swe_index].swe_state = SWE_NOT_STARTED;
330
331 cur_elem = cur_elem->next_swe;
332 }
333
334 return RVM_OK;
335 }
336
337
338 /*******************************************************************************
339 **
340 ** Function rvm_build_swe_list
341 **
342 ** Description Build the list of SWEs required to launch the specified SWE.
343 **
344 ** Parameters: T_RVM_PROCESSING_SWE ** list: list of required SWE.
345 ** UINT8 swe_num: index of the SWE to start in the array of known SWEs.
346 **
347 ** Returns T_RVM_RETURN
348 **
349 *******************************************************************************/
350 T_RVM_RETURN rvm_build_swe_list(T_RVM_PROCESSING_SWE ** list, UINT8 swe_num, UINT8 mode)
351 {
352 T_RVM_PROCESSING_SWE * cur_elem = *list;
353 T_RVM_USE_ID loc_linked_swe_id[RVM_MAX_NB_LINKED_SWE];
354 UINT8* rvm_swe_to_call;
355 UINT8 rvm_current_swe_to_call = 0, rvm_last_swe_to_call = 1;
356 UINT8 swe_cpt;
357 UINT8 mb_cpt;
358 UINT8 nb_linked_swe = 0;
359 volatile T_RVM_RETURN rvm_ret_value = RVM_OK;
360 UINT8 isRunning=0;
361
362 /* allocate a matrix to store temporarily the dependencies between SWEs */
363 if (rvf_get_buf( rvm_mem_bank, rvm_swe_number*rvm_swe_number, (void**)&rvm_swe_to_call) == RVF_RED)
364 {
365 rvf_send_trace("RVM_build_swe_list: not enough memory in the RVM memory bank for build_swe_list process", 87, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
366 return RVM_MEMORY_ERR;
367 }
368
369 rvm_swe_to_call[rvm_current_swe_to_call] = swe_num;
370
371 do
372 /* While some get_info functions has to be called. */
373 {
374 T_RVM_INFO_SWE swe_info;
375 UINT8 swe_num_i = rvm_swe_to_call[rvm_current_swe_to_call];
376
377 /* Check if SWE is running or not */
378 if (rvm_swe_array[swe_num_i].swe_state == SWE_RUNNING && mode==0) {
379 rvf_send_trace("RVM_build_swe_list: SWE already running, nb: ", 45, swe_num_i, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID );
380 rvm_current_swe_to_call++;
381 continue;
382 }
383
384 if ( rvm_swe_array[swe_num_i].swe_state == SWE_STOPPING && mode==0) {
385 rvf_send_trace("RVM_build_swe_list: SWE stopped awaiting kill, nb: ", 45, swe_num_i, RV_TRACE_LEVEL_DEBUG_HIGH, RVM_USE_ID );
386 rvm_current_swe_to_call++;
387 continue;
388 }
389
390
391
392 /* Check if SWE is already queued or not. */
393 cur_elem = *list;
394 while ( (cur_elem != NULL) && ( rvm_swe_array[cur_elem->swe_id].swe_use_id != rvm_swe_array[swe_num_i].swe_use_id) )
395 {
396 cur_elem = cur_elem->next_swe;
397 }
398
399 if (cur_elem != NULL)
400 /* SWE was found => - update SWE variables and pointers
401 - go to next step of the loop. */
402 {
403 rvm_current_swe_to_call++;
404 continue;
405 }
406
407
408 /* cur_elem = NULL => SWE was not found => create its entry in the list. */
409
410 /* create it and call its get_info function */
411 if ( rvf_get_buf( rvm_mem_bank, sizeof(T_RVM_PROCESSING_SWE), (void**)&cur_elem ) == RVF_RED )
412 {
413 rvf_send_trace("RVM_build_swe_list: not enough memory in the RVM main memory bank for the SWE entry", 83, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
414 rvm_ret_value = RVM_MEMORY_ERR;
415 break;
416 }
417
418 /*
419 ** initialize the new entry
420 */
421 memset(cur_elem, 0, sizeof(T_RVM_PROCESSING_SWE) );
422
423 /*
424 ** Set the SWE id: index in known SWE array
425 */
426 cur_elem->swe_id = swe_num_i;
427
428 /* call its get_info() function */
429 if ( rvm_swe_array[swe_num_i].swe_get_info(&swe_info) != RVM_OK )
430 {
431 /* Here an error occured in its get_info function.
432 free memory allocated for this entry and return an error. */
433 rvf_free_buf( cur_elem );
434 rvf_send_trace("RVM_build_swe_list: get_info function returns an error", 54, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
435 rvm_ret_value = RVM_INTERNAL_ERR;
436 break;
437 }
438
439 cur_elem->swe_type = swe_info.swe_type;
440 cur_elem->rvm_functions.core = rvm_generic_swe_core;
441
442 switch( swe_info.swe_type)
443 {
444 case ( RVM_SWE_TYPE_1):
445 { cur_elem->rvm_functions.set_info = swe_info.type_info.type1.set_info;
446 cur_elem->rvm_functions.init = swe_info.type_info.type1.init;
447 cur_elem->rvm_functions.start = swe_info.type_info.type1.start;
448 cur_elem->rvm_functions.stop1 = swe_info.type_info.type1.stop;
449 cur_elem->rvm_functions.kill = swe_info.type_info.type1.kill;
450
451 nb_linked_swe = swe_info.type_info.type1.nb_linked_swe;
452 for( mb_cpt = 0; mb_cpt < nb_linked_swe; mb_cpt++ )
453 { loc_linked_swe_id[mb_cpt] = swe_info.type_info.type1.linked_swe_id[mb_cpt];
454 }
455
456 /* memory bank information */
457 cur_elem->nb_requested_mb = swe_info.type_info.type1.nb_mem_bank;
458
459 for( mb_cpt = 0; mb_cpt < cur_elem->nb_requested_mb; mb_cpt++ )
460 {
461 memcpy (cur_elem->swe_mem_bank[mb_cpt].mb_name, \
462 swe_info.type_info.type1.mem_bank[mb_cpt].bank_name, \
463 RVF_MAX_MB_LEN);
464 cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.size \
465 = swe_info.type_info.type1.mem_bank[mb_cpt].initial_params.size;
466 cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.watermark \
467 = swe_info.type_info.type1.mem_bank[mb_cpt].initial_params.watermark;
468 }
469
470 break;
471 }
472 case ( RVM_SWE_TYPE_2):
473 { cur_elem->rvm_functions.set_info = swe_info.type_info.type2.set_info;
474 cur_elem->rvm_functions.init = swe_info.type_info.type2.init;
475 cur_elem->rvm_functions.start = swe_info.type_info.type2.start;
476 cur_elem->rvm_functions.stop = swe_info.type_info.type2.stop;
477 cur_elem->rvm_functions.kill = swe_info.type_info.type2.kill;
478 cur_elem->rvm_functions.handle_message = swe_info.type_info.type2.handle_message;
479 cur_elem->rvm_functions.handle_timer = swe_info.type_info.type2.handle_timer;
480
481 cur_elem->priority = swe_info.type_info.type2.priority;
482 cur_elem->stack_size = swe_info.type_info.type2.stack_size;
483 nb_linked_swe = swe_info.type_info.type2.nb_linked_swe;
484 for( mb_cpt = 0; mb_cpt < nb_linked_swe; mb_cpt++ )
485 { loc_linked_swe_id[mb_cpt] = swe_info.type_info.type2.linked_swe_id[mb_cpt];
486 }
487
488 /* memory bank information */
489 cur_elem->nb_requested_mb = swe_info.type_info.type2.nb_mem_bank;
490
491 for( mb_cpt = 0; mb_cpt < cur_elem->nb_requested_mb; mb_cpt++ )
492 {
493 memcpy (cur_elem->swe_mem_bank[mb_cpt].mb_name, \
494 swe_info.type_info.type2.mem_bank[mb_cpt].bank_name, \
495 RVF_MAX_MB_LEN);
496 cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.size \
497 = swe_info.type_info.type2.mem_bank[mb_cpt].initial_params.size;
498 cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.watermark \
499 = swe_info.type_info.type2.mem_bank[mb_cpt].initial_params.watermark;
500 }
501
502 break;
503 }
504 case ( RVM_SWE_TYPE_3):
505 { cur_elem->rvm_functions.set_info = swe_info.type_info.type3.set_info;
506 cur_elem->rvm_functions.init = swe_info.type_info.type3.init;
507 cur_elem->rvm_functions.start = swe_info.type_info.type3.start;
508 cur_elem->rvm_functions.stop = swe_info.type_info.type3.stop;
509 cur_elem->rvm_functions.kill = swe_info.type_info.type3.kill;
510 cur_elem->rvm_functions.handle_message = swe_info.type_info.type3.handle_message;
511 cur_elem->rvm_functions.handle_timer = swe_info.type_info.type3.handle_timer;
512
513 cur_elem->priority = swe_info.type_info.type3.priority;
514 cur_elem->stack_size = swe_info.type_info.type3.stack_size;
515 nb_linked_swe = swe_info.type_info.type3.nb_linked_swe;
516 for( mb_cpt = 0; mb_cpt < nb_linked_swe; mb_cpt++ )
517 { loc_linked_swe_id[mb_cpt] = swe_info.type_info.type3.linked_swe_id[mb_cpt];
518 }
519
520 /* memory bank information */
521 cur_elem->nb_requested_mb = swe_info.type_info.type3.nb_mem_bank;
522
523 for( mb_cpt = 0; mb_cpt < cur_elem->nb_requested_mb; mb_cpt++ )
524 {
525 memcpy (cur_elem->swe_mem_bank[mb_cpt].mb_name, \
526 swe_info.type_info.type3.mem_bank[mb_cpt].bank_name, \
527 RVF_MAX_MB_LEN);
528 cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.size \
529 = swe_info.type_info.type3.mem_bank[mb_cpt].initial_params.size;
530 cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.watermark \
531 = swe_info.type_info.type3.mem_bank[mb_cpt].initial_params.watermark;
532 }
533
534 break;
535 }
536 case ( RVM_SWE_TYPE_4):
537 { cur_elem->rvm_functions.set_info = swe_info.type_info.type4.set_info;
538 cur_elem->rvm_functions.init = swe_info.type_info.type4.init;
539 cur_elem->rvm_functions.stop1 = swe_info.type_info.type4.stop;
540 cur_elem->rvm_functions.kill = swe_info.type_info.type4.kill;
541 cur_elem->rvm_functions.core = swe_info.type_info.type4.core;
542
543 cur_elem->priority = swe_info.type_info.type4.priority;
544 cur_elem->stack_size = swe_info.type_info.type4.stack_size;
545 nb_linked_swe = swe_info.type_info.type4.nb_linked_swe;
546 for( mb_cpt = 0; mb_cpt < nb_linked_swe; mb_cpt++ )
547 { loc_linked_swe_id[mb_cpt] = swe_info.type_info.type4.linked_swe_id[mb_cpt];
548 }
549
550 /* memory bank information */
551 cur_elem->nb_requested_mb = swe_info.type_info.type4.nb_mem_bank;
552
553 for( mb_cpt = 0; mb_cpt < cur_elem->nb_requested_mb; mb_cpt++ )
554 {
555 memcpy (cur_elem->swe_mem_bank[mb_cpt].mb_name, \
556 swe_info.type_info.type4.mem_bank[mb_cpt].bank_name, \
557 RVF_MAX_MB_LEN);
558 cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.size \
559 = swe_info.type_info.type4.mem_bank[mb_cpt].initial_params.size;
560 cur_elem->swe_mem_bank[mb_cpt].mb_initial_param.watermark \
561 = swe_info.type_info.type4.mem_bank[mb_cpt].initial_params.watermark;
562 }
563
564 break;
565 }
566 }
567
568 /* allocate a task id, if necessary. */
569 /* if ( (swe_info.swe_type == RVM_SWE_TYPE_3)
570 ||(swe_info.swe_type == RVM_SWE_TYPE_4)
571 || ( (swe_info.swe_type == RVM_SWE_TYPE_2) && ( rvm_swe_array[swe_num_i].group_index == RVM_OWN_GROUP) )
572 || ( (swe_info.swe_type == RVM_SWE_TYPE_2) && ( rvm_group_array[rvm_swe_array[swe_num_i].group_index].task_id == RVF_INVALID_TASK) ) )
573 {
574 T_RVM_TASK_ID loc_task_id;
575 if(swe_info.swe_type==RVM_SWE_TYPE_2) loc_task_id = rvm_allocate_task_id(0);
576 else loc_task_id = rvm_allocate_task_id(1);
577
578 if (loc_task_id == RVF_INVALID_TASK)
579 {
580 rvm_ret_value = RVM_INTERNAL_ERR;
581 break;
582 }
583 if ( (swe_info.swe_type == RVM_SWE_TYPE_3)
584 ||(swe_info.swe_type == RVM_SWE_TYPE_4)
585 || ( (swe_info.swe_type == RVM_SWE_TYPE_2) && ( rvm_swe_array[swe_num_i].group_index == RVM_OWN_GROUP) ) )
586 { rvm_swe_array[swe_num_i].swe_addr_id = loc_task_id;
587 }
588 else
589 { if ( (swe_info.swe_type == RVM_SWE_TYPE_2) && ( rvm_group_array[rvm_swe_array[swe_num_i].group_index].task_id == RVF_INVALID_TASK) )
590 { rvm_group_array[rvm_swe_array[swe_num_i].group_index].task_id = loc_task_id;
591 }
592 }
593
594 }
595 */
596 /* Insert the element in the head of the list. */
597 if (*list == NULL) /* the list is empty */
598 {
599 /* This element is the first of the list */
600 *list = cur_elem;
601 cur_elem->next_swe = NULL;
602 }
603 else
604 { cur_elem->next_swe = *list;
605 *list = cur_elem;
606 }
607
608 /* Get the list of linked swe num, and put it in the array */
609 if (nb_linked_swe != 0) {
610 for (swe_cpt = 0; swe_cpt < nb_linked_swe; swe_cpt++) {
611 if (rvm_get_swe_index(&(rvm_swe_to_call[rvm_last_swe_to_call + swe_cpt]), loc_linked_swe_id[swe_cpt] ) != RVM_OK) {
612 rvm_ret_value = RVM_INVALID_PARAMETER;
613 rvf_send_trace("rvm_swe_db: Task allocation error!",35, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
614 break;
615 }
616 }
617 if (rvm_ret_value != RVM_OK) break;
618
619 rvm_last_swe_to_call += nb_linked_swe;
620 }
621 /* Once everything is done for current swe, increment rvm_current_swe_to_call */
622 rvm_current_swe_to_call ++;
623
624 }
625 while (rvm_current_swe_to_call != rvm_last_swe_to_call);
626
627
628 if (rvm_ret_value != RVM_OK)
629 /* Something went wrong => undo everything */
630 {
631 rvm_delete_used_memory (*list);
632 }
633
634 rvf_free_buf (rvm_swe_to_call);
635 return (rvm_ret_value);
636 }
637
638
639 /*******************************************************************************
640 **
641 ** Function rvm_clean_env
642 **
643 ** Description This function will clean the environment.
644 ** Its main tasks are:
645 ** - Update the using_appli pointer of the SWE array
646 ** - Update states to NOT_STARTED
647 ** - Release local memory
648 **
649 ** Parameters: T_RVM_PROCESSING_SWE * appli: list of required SWEs with their parameters.
650 **
651 ** Returns T_RVM_OK if all allocation are successful,
652 ** else T_RVM_INTERNAL_ERR (then some SWE are not killed.)
653 **
654 *******************************************************************************/
655 T_RVM_RETURN rvm_clean_env( T_RVM_PROCESSING_SWE * appli)
656 {
657 T_RVM_PROCESSING_SWE * cur_swe = appli;
658 UINT8 appli_nb1, appli_nb2;
659 volatile T_RVM_RETURN rvm_ret_value = RVM_OK;
660
661 /* for each SWE in the list */
662 while (cur_swe != NULL )
663 {
664 UINT8 swe_index = cur_swe->swe_id;
665
666 /* Update using_appli array */
667 if (rvm_swe_array[swe_index].nb_using_appli > 1)
668 {
669 for (appli_nb1 = 0; appli_nb1 < (rvm_swe_array[swe_index].nb_using_appli - 1); appli_nb1++)
670 {
671 if (rvm_swe_array[swe_index].using_appli[appli_nb1] == appli->swe_id)
672 /* appli was found in the using_appli array -> remove it and shift down the others */
673 {
674 for (appli_nb2 = appli_nb1; appli_nb2 < rvm_swe_array[swe_index].nb_using_appli; appli_nb2++)
675 {
676 rvm_swe_array[swe_index].using_appli[appli_nb2] = rvm_swe_array[swe_index].using_appli[appli_nb2 + 1];
677 }
678 /* Once using_appli pointer has been eliminated, we can exit the loop */
679 break;
680 }
681
682 }
683 }
684
685 /* Decrement nb of using applications */
686 rvm_swe_array[swe_index].nb_using_appli--;
687
688 /* Force to NULL last appli pointer */
689 rvm_swe_array[swe_index].using_appli[rvm_swe_array[swe_index].nb_using_appli] = RVM_INVALID_SWE_INDEX;
690
691 /* If last appli was deleted, put state back to init */
692 if (rvm_swe_array[swe_index].nb_using_appli == 0)
693 {
694 rvm_swe_array[swe_index].swe_state = SWE_NOT_STARTED;
695 }
696
697 /* Proceed to the next SWE */
698 cur_swe = cur_swe->next_swe;
699 }
700
701 /* Once Everything is back in stand-by, release used memory */
702 rvm_delete_used_memory (appli);
703
704 return rvm_ret_value;
705 }
706
707
708 /*******************************************************************************
709 **
710 ** Function rvm_error
711 **
712 ** Description Called by a SWE in case of unrecoverable error
713 **
714 ** Parameters: T_RVM_NAME swe_name:
715 ** T_RVM_RETURN error_cause:
716 ** T_RVM_ERROR_TYPE error_type:
717 ** T_RVM_STRING error_msg:
718 **
719 ** Returns T_RVM_RETURN: RVM_OK if successful, else a negative value.
720 **
721 *******************************************************************************/
722 T_RVM_RETURN rvm_error ( T_RVM_NAME swe_name, T_RVM_RETURN error_cause,
723 T_RVM_ERROR_TYPE error_type, T_RVM_STRING error_msg)
724 {
725 char swe_name_string[40];
726 UINT8 i=0;
727
728 memcpy(swe_name_string,"RVM: coming from: ",18);
729 memcpy((void*)((char*)swe_name_string+18),swe_name,RVM_NAME_MAX_LEN);
730
731 RVM_TRACE_WARNING("RVM: unrecoverable error indication");
732 rvf_send_trace(swe_name_string, 18 + RVM_NAME_MAX_LEN, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
733 RVM_TRACE_WARNING_PARAM("RVM: Error Cause: ", error_cause);
734 RVM_TRACE_WARNING_PARAM("RVM: Error Type: ", error_type);
735 /* check the message to limit its length to RVM_ERROR_MSG_MAX_LENGTH characters. */
736 while (error_msg[i])
737 {
738 i++;
739 if (i>RVM_ERROR_MSG_MAX_LENGTH)
740 break;
741 }
742
743 rvf_send_trace(error_msg, i, NULL_PARAM, RV_TRACE_LEVEL_WARNING, RVM_USE_ID );
744
745 return RVM_OK;
746 }
747