comparison src/cs/services/Audio/audio_melody_E2.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 Name: audio_melody_E2.c */
4 /* */
5 /* Purpose: This file contains all the functions used to manage the */
6 /* melody_E2. */
7 /* */
8 /* Version .1 */
9 /* */
10 /* Date Modification */
11 /* ------------------------------------ */
12 /* 10 dicember 2001 Create */
13 /* */
14 /* Author */
15 /* Stephanie Gerthoux */
16 /* */
17 /* (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved*/
18 /****************************************************************************/
19
20 #include "rv/rv_defined_swe.h"
21
22 #ifdef RVM_AUDIO_MAIN_SWE
23 #ifndef _WINDOWS
24 #include "config/swconfig.cfg"
25 #include "config/sys.cfg"
26 #include "config/chipset.cfg"
27 #endif
28
29 /* include the usefull L1 header */
30 #include "l1_confg.h"
31
32 #if (MELODY_E2)
33 #include "rv/rv_general.h"
34 #include "rvm/rvm_gen.h"
35 #include "audio/audio_features_i.h"
36 #include "audio/audio_ffs_i.h"
37 #include "audio/audio_api.h"
38 #include "audio/audio_structs_i.h"
39 #include "audio/audio_var_i.h"
40 #include "audio/audio_messages_i.h"
41 #include "rvf/rvf_target.h"
42 #include "audio/audio_const_i.h"
43 #include "audio/audio_error_hdlr_i.h"
44
45 /* include the usefull L1 header */
46 #define BOOL_FLAG
47 #include "l1_types.h"
48 #include "l1audio_cust.h"
49 #include "l1audio_defty.h"
50 #include "l1audio_msgty.h"
51 #include "l1audio_signa.h"
52
53 #ifndef _WINDOWS
54 #if TESTMODE
55 #include "l1tm_defty.h"
56 #endif
57 #if (L1_GTT == 1)
58 #include "l1gtt_const.h"
59 #include "l1gtt_defty.h"
60 #endif
61
62 #include "l1audio_const.h"
63 #include "l1audio_varex.h"
64 #include "l1_const.h"
65 #include "l1_defty.h"
66 #include "l1_varex.h"
67 #endif
68
69 #include <string.h>
70
71 /* external prototype */
72 extern UWORD16 Cust_audio_melody_E2_load_instrument (UWORD8 customer_instrument_id,
73 volatile UWORD16 *API_address,
74 UWORD16 allowed_size);
75
76 /********************************************************************************/
77 /* */
78 /* Function Name: audio_melody_E2_send_status */
79 /* */
80 /* Purpose: This function sends the melody_E2 status to the entity. */
81 /* */
82 /* Input Parameters: */
83 /* status, */
84 /* return path */
85 /* */
86 /* Output Parameters: */
87 /* None. */
88 /* */
89 /* Note: */
90 /* None. */
91 /* */
92 /* Revision History: */
93 /* None. */
94 /* */
95 /********************************************************************************/
96 void audio_melody_E2_send_status (T_AUDIO_RET status, T_RV_RETURN return_path)
97 {
98 void *p_send_message;
99 T_RVF_MB_STATUS mb_status;
100
101 /* allocate the message buffer */
102 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
103 sizeof (T_AUDIO_MELODY_E2_STATUS),
104 (T_RVF_BUFFER **) (&p_send_message));
105
106 /* If insufficient resources, then report a memory error and abort. */
107 if (mb_status == RVF_RED)
108 {
109 audio_melody_E2_error_trace(AUDIO_ENTITY_NO_MEMORY);
110 }
111
112 /*fill the header of the message */
113 ((T_AUDIO_MELODY_E2_STATUS *)(p_send_message))->os_hdr.msg_id = AUDIO_MELODY_E2_STATUS_MSG;
114
115 /* fill the status parameters */
116 ((T_AUDIO_MELODY_E2_STATUS *)(p_send_message))->status = status;
117
118 if (return_path.callback_func == NULL)
119 {
120 /* send the message to the entity */
121 rvf_send_msg (return_path.addr_id,
122 p_send_message);
123 }
124 else
125 {
126 /* call the callback function */
127 (*return_path.callback_func)((void *)(p_send_message));
128 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
129 }
130 }
131
132 /********************************************************************************/
133 /* */
134 /* Function Name: audio_melody_E2_message_switch */
135 /* */
136 /* Purpose: Manage the message supply between the melody manager 1 and */
137 /* manager 0 */
138 /* */
139 /* Input Parameters: */
140 /* start or stop message from the melody E2 features */
141 /* */
142 /* Output Parameters: */
143 /* index of the manager */
144 /* */
145 /* Note: */
146 /* None. */
147 /* */
148 /* Revision History: */
149 /* None. */
150 /* */
151 /********************************************************************************/
152 UINT8 audio_melody_E2_message_switch (T_RV_HDR *p_message)
153 {
154 switch (p_message->msg_id)
155 {
156 case AUDIO_MELODY_E2_START_REQ:
157 {
158 /* Check if the melody E2 number 0 isn't started */
159 if (p_audio_gbl_var->melody_E2_0.state == AUDIO_MELODY_E2_IDLE)
160 {
161 /* Save the mode of the melody */
162 p_audio_gbl_var->melody_E2_mode =
163 ((T_AUDIO_MELODY_E2_START *)p_message)->melody_E2_parameter.melody_E2_mode;
164 return(AUDIO_MELODY_E2_0);
165 }
166 /* Check if the melody E2 number 1 isn't started and if the current mode is game mode */
167 if ( (p_audio_gbl_var->melody_E2_1.state == AUDIO_MELODY_E2_IDLE) &&
168 (p_audio_gbl_var->melody_E2_mode == AUDIO_MELODY_GAME_MODE) )
169 {
170 return(AUDIO_MELODY_E2_1);
171 }
172
173 /* This start command is an error */
174 /* error due to a wrong melody mode */
175 if ( (p_audio_gbl_var->melody_E2_1.state == AUDIO_MELODY_E2_IDLE) &&
176 (p_audio_gbl_var->melody_E2_mode == AUDIO_MELODY_NORMAL_MODE) )
177 {
178 /* Close the FFS file previously open by the audio start API*/
179 #ifndef _WINDOWS
180 if ( ffs_close(((T_AUDIO_MELODY_E2_START *)(p_message))->audio_E2_ffs_fd) != EFFS_OK )
181 {
182 audio_melody_E2_error_trace(AUDIO_ENTITY_FILE_NO_CLOSE);
183 }
184 #endif
185 audio_melody_E2_send_status (AUDIO_MODE_ERROR, ((T_AUDIO_MELODY_E2_START *)(p_message))->return_path);
186 audio_melody_E2_error_trace(AUDIO_ERROR_MODE);
187 p_audio_gbl_var->message_processed = TRUE;
188 return(AUDIO_MELODY_E2_NONE);
189 }
190
191 /* error due to a wrong start */
192 /* Close the FFS file previously open by the audio start API*/
193 #ifndef _WINDOWS
194 if ( ffs_close(((T_AUDIO_MELODY_E2_START *)(p_message))->audio_E2_ffs_fd) != EFFS_OK )
195 {
196 audio_melody_E2_error_trace(AUDIO_ENTITY_FILE_NO_CLOSE);
197 }
198 #endif
199 audio_melody_E2_send_status (AUDIO_ERROR, ((T_AUDIO_MELODY_E2_START *)(p_message))->return_path);
200 audio_melody_E2_error_trace(AUDIO_ERROR_START_EVENT);
201 p_audio_gbl_var->message_processed = TRUE;
202 return(AUDIO_MELODY_E2_NONE);
203 }
204
205 case AUDIO_MELODY_E2_STOP_REQ:
206 {
207 /* Check if the melody E2 number 0 is running and if the stop command and */
208 /* the manager 0 talk about the same melody name */
209 if ( (p_audio_gbl_var->melody_E2_0.state != AUDIO_MELODY_E2_IDLE) &&
210 (strcmp(p_audio_gbl_var->melody_E2_0.melody_name,
211 ((T_AUDIO_MELODY_E2_STOP*)p_message)->melody_E2_name) == 0) )
212 {
213 return(AUDIO_MELODY_E2_0);
214 }
215 /* Check if the melody E2 number 1 is running and if the stop command and */
216 /* the manager 1 talk about the same melody name */
217 if ( (p_audio_gbl_var->melody_E2_1.state != AUDIO_MELODY_E2_IDLE) &&
218 (strcmp(p_audio_gbl_var->melody_E2_1.melody_name,
219 ((T_AUDIO_MELODY_E2_STOP*)p_message)->melody_E2_name) == 0) )
220 {
221 return(AUDIO_MELODY_E2_1);
222 }
223
224 /* the stop command isn't apply to a melody E2, it's an error */
225 /* event error - send an error message*/
226 audio_melody_E2_send_status (AUDIO_ERROR, ((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
227 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
228 p_audio_gbl_var->message_processed = TRUE;
229 return(AUDIO_MELODY_E2_NONE);
230 }
231
232 case AUDIO_FFS_INIT_DONE:
233 {
234 /* The FFS message is from the melody E2 manager 0 */
235 if ( ((T_AUDIO_FFS_INIT *)p_message)->session_id == AUDIO_FFS_SESSION_MELODY_E2_0 )
236 {
237 return(AUDIO_MELODY_E2_0);
238 }
239 /* The FFS message is from the melody E2 manager 1 */
240 if ( ((T_AUDIO_FFS_INIT *)p_message)->session_id == AUDIO_FFS_SESSION_MELODY_E2_1 )
241 {
242 return(AUDIO_MELODY_E2_1);
243 }
244 return(AUDIO_MELODY_E2_NONE);
245 }
246
247 case AUDIO_FFS_STOP_CON:
248 {
249 /* The FFS message is from the melody E2 manager 0 */
250 if ( ((T_AUDIO_FFS_STOP_REQ *)p_message)->session_id == AUDIO_FFS_SESSION_MELODY_E2_0 )
251 {
252 return(AUDIO_MELODY_E2_0);
253 }
254 /* The FFS message is from the melody E2 manager 1 */
255 if ( ((T_AUDIO_FFS_STOP_REQ *)p_message)->session_id == AUDIO_FFS_SESSION_MELODY_E2_1 )
256 {
257 return(AUDIO_MELODY_E2_1);
258 }
259 return(AUDIO_MELODY_E2_NONE);
260 }
261
262 case MMI_MELODY0_E2_START_CON:
263 case MMI_MELODY0_E2_STOP_CON:
264 {
265 return(AUDIO_MELODY_E2_0);
266 }
267
268 case MMI_MELODY1_E2_START_CON:
269 case MMI_MELODY1_E2_STOP_CON:
270 {
271 return(AUDIO_MELODY_E2_1);
272 }
273
274 default:
275 {
276 return(AUDIO_MELODY_E2_NONE);
277 break;
278 }
279
280 } /* switch */
281 }
282
283 /********************************************************************************/
284 /* */
285 /* Function Name: audio_melody_e2_convert_parameter */
286 /* */
287 /* Purpose: Convert the melody parameters from the entity to the l1 */
288 /* parameters */
289 /* */
290 /* Input Parameters: */
291 /* session_id of the melody */
292 /* id of the melody */
293 /* */
294 /* Output Parameters: */
295 /* layer 1 melody message */
296 /* */
297 /* Note: */
298 /* None. */
299 /* */
300 /* Revision History: */
301 /* None. */
302 /* */
303 /********************************************************************************/
304 void audio_melody_e2_convert_parameter(UINT8 channel_id, T_MMI_MELODY_E2_REQ *l1_parameter, UINT8 melody_id)
305 {
306 if (melody_id == 0)
307 {
308 /* loopback mode */
309 l1_parameter->loopback =
310 p_audio_gbl_var->melody_E2_0.loopback;
311 }
312 else
313 {
314 /* loopback mode */
315 l1_parameter->loopback =
316 p_audio_gbl_var->melody_E2_1.loopback;
317 }
318 l1_parameter->session_id = channel_id;
319 }
320
321 /********************************************************************************/
322 /* */
323 /* Function Name: audio_melody_E2_manager_0 */
324 /* */
325 /* Purpose: This function is called to manage a melody E2 format number 0. */
326 /* */
327 /* Input Parameters: */
328 /* Message to the audio entity */
329 /* */
330 /* Output Parameters: */
331 /* None. */
332 /* */
333 /* Note: */
334 /* None. */
335 /* */
336 /* Revision History: */
337 /* None. */
338 /* */
339 /********************************************************************************/
340 void audio_melody_E2_manager_0 (T_RV_HDR *p_message)
341 {
342 /* Declare local variables */
343 void *p_send_message;
344 T_RVF_MB_STATUS mb_status;
345
346 /**************** audio_melody_e2_manager function begins *********************/
347
348 switch(p_audio_gbl_var->melody_E2_0.state)
349 {
350 case AUDIO_MELODY_E2_IDLE:
351 {
352 switch(p_message->msg_id)
353 {
354 case AUDIO_MELODY_E2_START_REQ:
355 {
356 /* save the task id of the entity */
357 p_audio_gbl_var->melody_E2_0.task_id = p_message->src_addr_id;
358
359 /* save the return path */
360 p_audio_gbl_var->melody_E2_0.return_path.callback_func =
361 ((T_AUDIO_MELODY_E2_START*)(p_message))->return_path.callback_func;
362 p_audio_gbl_var->melody_E2_0.return_path.addr_id =
363 ((T_AUDIO_MELODY_E2_START*)(p_message))->return_path.addr_id;
364
365 /* Before to start any melody, check if the instrument file is download*/
366 if (p_audio_gbl_var->melody_E2_load_file_instruments.file_downloaded == FALSE)
367 {
368 /* The instrument file is not downloaded*/
369 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_START *)(p_message))->return_path);
370 audio_melody_E2_error_trace(AUDIO_ERROR_NOT_DOWNLOAD);
371 break;
372 }
373
374 strcpy( p_audio_gbl_var->melody_E2_0.melody_name,
375 ((T_AUDIO_MELODY_E2_START*)(p_message))->melody_E2_parameter.melody_E2_name);
376
377 p_audio_gbl_var->melody_E2_0.loopback =
378 ((T_AUDIO_MELODY_E2_START*)(p_message))->melody_E2_parameter.E2_loopback;
379
380 /* Send the Start message to the FFS */
381 /* allocate the message buffer */
382 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
383 sizeof (T_AUDIO_FFS_FLASH_2_RAM_START),
384 (T_RVF_BUFFER **) (&p_send_message));
385
386 /* If insufficient resources, then report a memory error and abort. */
387 if (mb_status == RVF_RED)
388 {
389 audio_melody_E2_error_trace(AUDIO_ENTITY_NO_MEMORY);
390 }
391
392 /* fill the header of the message */
393 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_FLASH_2_RAM_START_REQ;
394
395 /* fill the parameters */
396 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->audio_ffs_fd =
397 ((T_AUDIO_MELODY_E2_START*)(p_message))->audio_E2_ffs_fd;
398 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->initial_size = AUDIO_MELODY_E2_SIZE;
399 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->loop =
400 ((T_AUDIO_MELODY_E2_START*)(p_message))->melody_E2_parameter.E2_loopback;
401
402 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->session_id = AUDIO_FFS_SESSION_MELODY_E2_0;
403
404 /* send the message to the entity */
405 rvf_send_msg (p_audio_gbl_var->audio_ffs_addrId,
406 p_send_message);
407
408 /* change to the state AUDIO_MELODY_E2_WAIT_INIT_FFS */
409 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_INIT_FFS;
410 break;
411 } /* case AUDIO_MELODY_E2_START_REQ */
412 } /* switch(p_message->msg_id) */
413 break;
414 } /* case AUDIO_MELODY_E2_IDLE */
415
416 case AUDIO_MELODY_E2_WAIT_INIT_FFS:
417 {
418 switch(p_message->msg_id)
419 {
420 case AUDIO_FFS_INIT_DONE:
421 {
422 /* send the start melody message to the L1 */
423 /* allocate the buffer for the message to the L1 */
424 p_send_message = audio_allocate_l1_message(sizeof(T_MMI_MELODY_E2_REQ));
425
426 if ( p_send_message != NULL)
427 {
428 /* Convert the entity parameters to the audio L1 parameters */
429 audio_melody_e2_convert_parameter(((T_AUDIO_FFS_INIT *)(p_message))->channel_id,
430 ((T_MMI_MELODY_E2_REQ *)(p_send_message)),
431 AUDIO_MELODY_E2_0);
432
433 /* send the start command to the audio L1 */
434 audio_send_l1_message(MMI_MELODY0_E2_START_REQ, p_send_message);
435 }
436
437 /* change to the state AUDIO_MELODY_E2_WAIT_START_CONFIRMATION */
438 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_START_CON;
439 break;
440 } /* case AUDIO_FFS_INIT_DONE */
441
442 case AUDIO_MELODY_E2_STOP_REQ:
443 {
444 /*.Before stopping this task, control that */
445 /* stop task id caller =Melody task id */
446 if ( p_audio_gbl_var->melody_E2_0.task_id == p_message->src_addr_id)
447 {
448 /* change to the state AUDIO_MELODY_E2_WAIT_INIT_DONE */
449 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_INIT_DONE;
450 }
451 else
452 {
453 /* A stop request from an other task is sent during a start connection */
454 /* event error - send an error message */
455 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
456 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
457 }
458 break;
459 } /* case AUDIO_MELODY_E2_STOP_REQ */
460 } /* switch(p_message->msg_id) */
461 break;
462 } /* case AUDIO_MELODY_E2_WAIT_INIT_FFS */
463
464 case AUDIO_MELODY_E2_WAIT_INIT_DONE:
465 {
466 switch(p_message->msg_id)
467 {
468 case AUDIO_FFS_INIT_DONE:
469 {
470 /* Send FFS stop command */
471 /* allocate the message buffer */
472 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
473 sizeof (T_AUDIO_FFS_STOP_REQ),
474 (T_RVF_BUFFER **) (&p_send_message));
475
476 /* If insufficient resources, then report a memory error and abort. */
477 if (mb_status == RVF_RED)
478 {
479 audio_melody_E2_error_trace(AUDIO_ENTITY_NO_MEMORY);
480 }
481
482 /* fill the header of the message */
483 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_STOP_REQ;
484
485 /* fill the parameter */
486 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->session_id = AUDIO_FFS_SESSION_MELODY_E2_0;
487
488 /* send the message to the entity */
489 rvf_send_msg (p_audio_gbl_var->audio_ffs_addrId,
490 p_send_message);
491
492 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_FFS */
493 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_STOP_FFS;
494 break;
495 } /* case AUDIO_FFS_INIT_DONE */
496
497 case AUDIO_MELODY_E2_STOP_REQ:
498 {
499 /* stop event error - send an error message */
500 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
501 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
502 break;
503 } /* case AUDIO_MELODY_E2_STOP_REQ */
504 } /* switch(p_message->msg_id) */
505 break;
506 } /* case AUDIO_MELODY_E2_WAIT_INIT_DONE*/
507
508 case AUDIO_MELODY_E2_WAIT_START_CON:
509 {
510 switch(p_message->msg_id)
511 {
512 case MMI_MELODY0_E2_START_CON:
513 {
514 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_COMMAND */
515 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_STOP_COMMAND;
516 audio_melody_E2_send_status (AUDIO_OK, p_audio_gbl_var->melody_E2_0.return_path);
517 break;
518 } /* case MMI_MELODY0_E2_START_CON */
519
520 case AUDIO_MELODY_E2_STOP_REQ:
521 {
522 /*.Before stopping this task, control that */
523 /* stop task id caller =Melody task id */
524 if ( p_audio_gbl_var->melody_E2_0.task_id == p_message->src_addr_id)
525 {
526 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_CONFIRMATION */
527 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_START_CON_TO_STOP;
528 }
529 else
530 {
531 /* A stop request from an other task is sent during a start connection */
532 /* event error - send an error message */
533 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
534 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
535 }
536 break;
537 } /* case AUDIO_MELODY_E2_STOP_REQ */
538 } /* switch(p_message->msg_id) */
539 break;
540 } /* case AUDIO_MELODY_E2_PLAY_WAIT_START_CON */
541
542 case AUDIO_MELODY_E2_WAIT_START_CON_TO_STOP:
543 {
544 switch(p_message->msg_id)
545 {
546 case MMI_MELODY0_E2_START_CON:
547 {
548 /* send the stop command to the audio L1 */
549 /* allocate the buffer for the message to the L1 */
550 p_send_message = audio_allocate_l1_message(0);
551 if ( p_send_message != NULL)
552 {
553 /* send the stop command to the audio L1 */
554 audio_send_l1_message(MMI_MELODY0_E2_STOP_REQ, p_send_message);
555 }
556
557 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_CON */
558 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_STOP_CON;
559 break;
560 }
561
562 case AUDIO_MELODY_E2_STOP_REQ:
563 {
564 /* stop event error - send an error message */
565 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
566 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
567 break;
568 } /* case AUDIO_MELODY_E2_STOP_REQ */
569 } /* switch(p_message->msg_id) */
570 break;
571 } /* case AUDIO_MELODY_E2_WAIT_START_CON_TO_STOP */
572
573 case AUDIO_MELODY_E2_WAIT_STOP_COMMAND:
574 {
575 switch(p_message->msg_id)
576 {
577 case MMI_MELODY0_E2_STOP_CON:
578 {
579 /* Send FFS stop command */
580 /* allocate the message buffer */
581 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
582 sizeof (T_AUDIO_FFS_STOP_REQ),
583 (T_RVF_BUFFER **) (&p_send_message));
584
585 /* If insufficient resources, then report a memory error and abort. */
586 if (mb_status == RVF_RED)
587 {
588 audio_melody_E2_error_trace(AUDIO_ENTITY_NO_MEMORY);
589 }
590
591 /* fill the header of the message */
592 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_STOP_REQ;
593
594 /* fill the parameter */
595 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->session_id = AUDIO_FFS_SESSION_MELODY_E2_0;
596
597 /* send the message to the entity */
598 rvf_send_msg (p_audio_gbl_var->audio_ffs_addrId,
599 p_send_message);
600
601 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_FFS */
602 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_STOP_FFS;
603 break;
604 } /* case MMI_MELODY1_E2_STOP_CON */
605
606 case AUDIO_MELODY_E2_STOP_REQ:
607 {
608 /*.Before stopping this task, control that */
609 /* stop task id caller = Melody task id */
610 if ( p_audio_gbl_var->melody_E2_0.task_id == p_message->src_addr_id)
611 {
612
613 /* save the return path */
614 p_audio_gbl_var->melody_E2_0.return_path.callback_func =
615 ((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path.callback_func;
616 p_audio_gbl_var->melody_E2_0.return_path.addr_id =
617 ((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path.addr_id;
618
619 /* send the stop command to the audio L1 */
620 /* allocate the buffer for the message to the L1 */
621 p_send_message = audio_allocate_l1_message(0);
622 if (p_send_message != NULL)
623 {
624 /* send the start command to the audio L1 */
625 audio_send_l1_message(MMI_MELODY0_E2_STOP_REQ, p_send_message);
626 }
627
628 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_CONFIRMATION */
629 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_STOP_CON;
630 }
631 else
632 {
633 /* A stop request from an other task is sent during a start connection */
634 /* event error - send an error message */
635 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
636 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
637 }
638 break;
639 } /* case AUDIO_MELODY_E2_STOP_REQ */
640 } /* switch(p_message->msg_id) */
641 break;
642 } /* case AUDIO_MELODY_E2_WAIT_STOP_COMMAND */
643
644 case AUDIO_MELODY_E2_WAIT_STOP_CON:
645 {
646 switch(p_message->msg_id)
647 {
648 case MMI_MELODY0_E2_STOP_CON:
649 {
650 /* Send FFS stop command */
651 /* allocate the message buffer */
652 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
653 sizeof (T_AUDIO_FFS_STOP_REQ),
654 (T_RVF_BUFFER **) (&p_send_message));
655
656 /* If insufficient resources, then report a memory error and abort. */
657 if (mb_status == RVF_RED)
658 {
659 audio_melody_E2_error_trace(AUDIO_ENTITY_NO_MEMORY);
660 }
661
662 /* fill the header of the message */
663 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_STOP_REQ;
664
665 /* fill the parameter */
666 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->session_id = AUDIO_FFS_SESSION_MELODY_E2_0;
667
668 /* send the message to the entity */
669 rvf_send_msg (p_audio_gbl_var->audio_ffs_addrId,
670 p_send_message);
671
672 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_FFS */
673 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_WAIT_STOP_FFS;
674 break;
675 }
676
677 case AUDIO_MELODY_E2_STOP_REQ:
678 {
679 /* stop event error - send an error message */
680 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
681 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
682 break;
683 } /* case AUDIO_MELODY_E2_STOP_REQ */
684 } /* switch(p_message->msg_id) */
685 break;
686 } /* case AUDIO_MELODY_E2_WAIT_STOP_CON */
687
688 case AUDIO_MELODY_E2_WAIT_STOP_FFS:
689 {
690 switch(p_message->msg_id)
691 {
692 case AUDIO_FFS_STOP_CON:
693 {
694 /* change to the state AUDIO_MELODY_E2_IDLE */
695 p_audio_gbl_var->melody_E2_0.state = AUDIO_MELODY_E2_IDLE;
696
697 audio_melody_E2_send_status (AUDIO_OK, p_audio_gbl_var->melody_E2_0.return_path);
698
699 break;
700 }
701
702 case AUDIO_MELODY_E2_STOP_REQ:
703 {
704 /* stop event error - send an error message */
705 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
706 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
707 break;
708 } /* case AUDIO_MELODY_E2_STOP_REQ */
709 } /* switch(p_message->msg_id) */
710 break;
711 } /* case AUDIO_MELODY_E2_WAIT_STOP_CON */
712
713 } /* switch(p_audio_gbl_var->melody_E2_0.state) */
714
715 } /*********************** End of audio_melody_E2_manager_0 function ************/
716
717 /********************************************************************************/
718 /* */
719 /* Function Name: audio_melody_E2_manager_1 */
720 /* */
721 /* Purpose: This function is called to manage a melody E2 format number 1. */
722 /* */
723 /* Input Parameters: */
724 /* Message to the audio entity */
725 /* */
726 /* Output Parameters: */
727 /* None. */
728 /* */
729 /* Note: */
730 /* None. */
731 /* */
732 /* Revision History: */
733 /* None. */
734 /* */
735 /********************************************************************************/
736 void audio_melody_E2_manager_1 (T_RV_HDR *p_message)
737 {
738 /* Declare local variables */
739 void *p_send_message;
740 T_RVF_MB_STATUS mb_status;
741
742 /**************** audio_melody_e2_manager function begins *********************/
743
744 switch(p_audio_gbl_var->melody_E2_1.state)
745 {
746 case AUDIO_MELODY_E2_IDLE:
747 {
748 switch(p_message->msg_id)
749 {
750 case AUDIO_MELODY_E2_START_REQ:
751 {
752 /* save the task id of the entity */
753 p_audio_gbl_var->melody_E2_1.task_id = p_message->src_addr_id;
754
755 /* save the return path */
756 p_audio_gbl_var->melody_E2_1.return_path.callback_func =
757 ((T_AUDIO_MELODY_E2_START*)(p_message))->return_path.callback_func;
758 p_audio_gbl_var->melody_E2_1.return_path.addr_id =
759 ((T_AUDIO_MELODY_E2_START*)(p_message))->return_path.addr_id;
760
761 /* Before to start any melody, check if the instrument file is download*/
762 if (p_audio_gbl_var->melody_E2_load_file_instruments.file_downloaded == FALSE)
763 {
764 /* The instrument file is not downloaded*/
765 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_START *)(p_message))->return_path);
766 audio_melody_E2_error_trace(AUDIO_ERROR_NOT_DOWNLOAD);
767 break;
768 }
769
770 strcpy( p_audio_gbl_var->melody_E2_1.melody_name,
771 ((T_AUDIO_MELODY_E2_START*)(p_message))->melody_E2_parameter.melody_E2_name);
772
773 p_audio_gbl_var->melody_E2_1.loopback =
774 ((T_AUDIO_MELODY_E2_START*)(p_message))->melody_E2_parameter.E2_loopback;
775
776 /* Send the Start message to the FFS */
777 /* allocate the message buffer */
778 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
779 sizeof (T_AUDIO_FFS_FLASH_2_RAM_START),
780 (T_RVF_BUFFER **) (&p_send_message));
781
782 /* If insufficient resources, then report a memory error and abort. */
783 if (mb_status == RVF_RED)
784 {
785 audio_melody_E2_error_trace(AUDIO_ENTITY_NO_MEMORY);
786 }
787
788 /* fill the header of the message */
789 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_FLASH_2_RAM_START_REQ;
790
791 /* fill the parameters */
792 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->audio_ffs_fd =
793 ((T_AUDIO_MELODY_E2_START*)(p_message))->audio_E2_ffs_fd;
794 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->initial_size = AUDIO_MELODY_E2_SIZE;
795 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->loop =
796 ((T_AUDIO_MELODY_E2_START*)(p_message))->melody_E2_parameter.E2_loopback;
797
798 ((T_AUDIO_FFS_FLASH_2_RAM_START *)(p_send_message))->session_id = AUDIO_FFS_SESSION_MELODY_E2_1;
799
800 /* send the message to the entity */
801 rvf_send_msg (p_audio_gbl_var->audio_ffs_addrId,
802 p_send_message);
803
804 /* change to the state AUDIO_MELODY_E2_WAIT_INIT_FFS */
805 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_INIT_FFS;
806 break;
807 } /* case AUDIO_MELODY_E2_START_REQ */
808 } /* switch(p_message->msg_id) */
809 break;
810 } /* case AUDIO_MELODY_E2_IDLE */
811
812 case AUDIO_MELODY_E2_WAIT_INIT_FFS:
813 {
814 switch(p_message->msg_id)
815 {
816 case AUDIO_FFS_INIT_DONE:
817 {
818 /* send the start melody message to the L1 */
819 /* allocate the buffer for the message to the L1 */
820 p_send_message = audio_allocate_l1_message(sizeof(T_MMI_MELODY_E2_REQ));
821
822 if ( p_send_message != NULL)
823 {
824 /* Convert the entity parameters to the audio L1 parameters */
825 audio_melody_e2_convert_parameter(((T_AUDIO_FFS_INIT *)(p_message))->channel_id,
826 ((T_MMI_MELODY_E2_REQ *)(p_send_message)),
827 AUDIO_MELODY_E2_1);
828
829 /* send the start command to the audio L1 */
830 audio_send_l1_message(MMI_MELODY1_E2_START_REQ, p_send_message);
831 }
832
833 /* change to the state AUDIO_MELODY_E2_WAIT_START_CONFIRMATION */
834 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_START_CON;
835 break;
836 } /* case AUDIO_FFS_INIT_DONE */
837
838 case AUDIO_MELODY_E2_STOP_REQ:
839 {
840 /*.Before stopping this task, control that */
841 /* stop task id caller =Melody task id */
842 if ( p_audio_gbl_var->melody_E2_1.task_id == p_message->src_addr_id)
843 {
844 /* change to the state AUDIO_MELODY_E2_WAIT_INIT_DONE */
845 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_INIT_DONE;
846 }
847 else
848 {
849 /* A stop request from an other task is sent during a start connection */
850 /* event error - send an error message */
851 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
852 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
853 }
854 break;
855 } /* case AUDIO_MELODY_E2_STOP_REQ */
856 } /* switch(p_message->msg_id) */
857 break;
858 } /* case AUDIO_MELODY_E2_WAIT_INIT_FFS */
859
860 case AUDIO_MELODY_E2_WAIT_INIT_DONE:
861 {
862 switch(p_message->msg_id)
863 {
864 case AUDIO_FFS_INIT_DONE:
865 {
866 /* Send FFS stop command */
867 /* allocate the message buffer */
868 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
869 sizeof (T_AUDIO_FFS_STOP_REQ),
870 (T_RVF_BUFFER **) (&p_send_message));
871
872 /* If insufficient resources, then report a memory error and abort. */
873 if (mb_status == RVF_RED)
874 {
875 audio_melody_E2_error_trace(AUDIO_ENTITY_NO_MEMORY);
876 }
877
878 /* fill the header of the message */
879 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_STOP_REQ;
880
881 /* fill the parameter */
882 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->session_id = AUDIO_FFS_SESSION_MELODY_E2_1;
883
884 /* send the message to the entity */
885 rvf_send_msg (p_audio_gbl_var->audio_ffs_addrId,
886 p_send_message);
887
888 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_FFS */
889 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_STOP_FFS;
890 break;
891 } /* case AUDIO_FFS_INIT_DONE */
892
893 case AUDIO_MELODY_E2_STOP_REQ:
894 {
895 /* stop event error - send an error message */
896 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
897 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
898 break;
899 } /* case AUDIO_MELODY_E2_STOP_REQ */
900 } /* switch(p_message->msg_id) */
901 break;
902 } /* case AUDIO_MELODY_E2_WAIT_INIT_DONE*/
903
904 case AUDIO_MELODY_E2_WAIT_START_CON:
905 {
906 switch(p_message->msg_id)
907 {
908 case MMI_MELODY1_E2_START_CON:
909 {
910 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_COMMAND */
911 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_STOP_COMMAND;
912 audio_melody_E2_send_status (AUDIO_OK, p_audio_gbl_var->melody_E2_1.return_path);
913 break;
914 } /* case MMI_MELODY1_E2_START_CON */
915
916 case AUDIO_MELODY_E2_STOP_REQ:
917 {
918 /*.Before stopping this task, control that */
919 /* stop task id caller =Melody task id */
920 if ( p_audio_gbl_var->melody_E2_1.task_id == p_message->src_addr_id)
921 {
922 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_CONFIRMATION */
923 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_START_CON_TO_STOP;
924 }
925 else
926 {
927 /* A stop request from an other task is sent during a start connection */
928 /* event error - send an error message */
929 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
930 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
931 }
932 break;
933 } /* case AUDIO_MELODY_E2_STOP_REQ */
934 } /* switch(p_message->msg_id) */
935 break;
936 } /* case AUDIO_MELODY_E2_PLAY_WAIT_START_CON */
937
938 case AUDIO_MELODY_E2_WAIT_START_CON_TO_STOP:
939 {
940 switch(p_message->msg_id)
941 {
942 case MMI_MELODY1_E2_START_CON:
943 {
944 /* send the stop command to the audio L1 */
945 /* allocate the buffer for the message to the L1 */
946 p_send_message = audio_allocate_l1_message(0);
947 if ( p_send_message != NULL)
948 {
949 /* send the stop command to the audio L1 */
950 audio_send_l1_message(MMI_MELODY1_E2_STOP_REQ, p_send_message);
951 }
952
953 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_CON */
954 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_STOP_CON;
955 break;
956 }
957
958 case AUDIO_MELODY_E2_STOP_REQ:
959 {
960 /* stop event error - send an error message */
961 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
962 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
963 break;
964 } /* case AUDIO_MELODY_E2_STOP_REQ */
965 } /* switch(p_message->msg_id) */
966 break;
967 } /* case AUDIO_MELODY_E2_WAIT_START_CON_TO_STOP */
968
969 case AUDIO_MELODY_E2_WAIT_STOP_COMMAND:
970 {
971 switch(p_message->msg_id)
972 {
973 case MMI_MELODY1_E2_STOP_CON:
974 {
975 /* Send FFS stop command */
976 /* allocate the message buffer */
977 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
978 sizeof (T_AUDIO_FFS_STOP_REQ),
979 (T_RVF_BUFFER **) (&p_send_message));
980
981 /* If insufficient resources, then report a memory error and abort. */
982 if (mb_status == RVF_RED)
983 {
984 audio_melody_E2_error_trace(AUDIO_ENTITY_NO_MEMORY);
985 }
986
987 /* fill the header of the message */
988 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_STOP_REQ;
989
990 /* fill the parameter */
991 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->session_id = AUDIO_FFS_SESSION_MELODY_E2_1;
992
993 /* send the message to the entity */
994 rvf_send_msg (p_audio_gbl_var->audio_ffs_addrId,
995 p_send_message);
996
997 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_FFS */
998 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_STOP_FFS;
999 break;
1000 } /* case MMI_MELODY1_E2_STOP_CON */
1001
1002 case AUDIO_MELODY_E2_STOP_REQ:
1003 {
1004 /*.Before stopping this task, control that */
1005 /* stop task id caller = Melody task id */
1006 if ( p_audio_gbl_var->melody_E2_1.task_id == p_message->src_addr_id)
1007 {
1008 /* save the return path */
1009 p_audio_gbl_var->melody_E2_1.return_path.callback_func =
1010 ((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path.callback_func;
1011 p_audio_gbl_var->melody_E2_1.return_path.addr_id =
1012 ((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path.addr_id;
1013
1014 /* send the stop command to the audio L1 */
1015 /* allocate the buffer for the message to the L1 */
1016 p_send_message = audio_allocate_l1_message(0);
1017 if (p_send_message != NULL)
1018 {
1019 /* send the start command to the audio L1 */
1020 audio_send_l1_message(MMI_MELODY1_E2_STOP_REQ, p_send_message);
1021 }
1022
1023 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_CONFIRMATION */
1024 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_STOP_CON;
1025 }
1026 else
1027 {
1028 /* A stop request from an other task is sent during a start connection */
1029 /* event error - send an error message */
1030 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
1031 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
1032 }
1033 break;
1034 } /* case AUDIO_MELODY_E2_STOP_REQ */
1035 } /* switch(p_message->msg_id) */
1036 break;
1037 } /* case AUDIO_MELODY_E2_WAIT_STOP_COMMAND */
1038
1039 case AUDIO_MELODY_E2_WAIT_STOP_CON:
1040 {
1041 switch(p_message->msg_id)
1042 {
1043 case MMI_MELODY1_E2_STOP_CON:
1044 {
1045 /* Send FFS stop command */
1046 /* allocate the message buffer */
1047 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
1048 sizeof (T_AUDIO_FFS_STOP_REQ),
1049 (T_RVF_BUFFER **) (&p_send_message));
1050
1051 /* If insufficient resources, then report a memory error and abort. */
1052 if (mb_status == RVF_RED)
1053 {
1054 audio_melody_E2_error_trace(AUDIO_ENTITY_NO_MEMORY);
1055 }
1056
1057 /* fill the header of the message */
1058 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_STOP_REQ;
1059
1060 /* fill the parameter */
1061 ((T_AUDIO_FFS_STOP_REQ *)(p_send_message))->session_id = AUDIO_FFS_SESSION_MELODY_E2_1;
1062
1063 /* send the message to the entity */
1064 rvf_send_msg (p_audio_gbl_var->audio_ffs_addrId,
1065 p_send_message);
1066
1067 /* change to the state AUDIO_MELODY_E2_WAIT_STOP_FFS */
1068 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_WAIT_STOP_FFS;
1069 break;
1070 }
1071
1072 case AUDIO_MELODY_E2_STOP_REQ:
1073 {
1074 /* stop event error - send an error message */
1075 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
1076 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
1077 break;
1078 } /* case AUDIO_MELODY_E2_STOP_REQ */
1079 } /* switch(p_message->msg_id) */
1080 break;
1081 } /* case AUDIO_MELODY_E2_WAIT_STOP_CON */
1082
1083 case AUDIO_MELODY_E2_WAIT_STOP_FFS:
1084 {
1085 switch(p_message->msg_id)
1086 {
1087 case AUDIO_FFS_STOP_CON:
1088 {
1089 /* change to the state AUDIO_MELODY_E2_IDLE */
1090 p_audio_gbl_var->melody_E2_1.state = AUDIO_MELODY_E2_IDLE;
1091
1092 audio_melody_E2_send_status (AUDIO_OK, p_audio_gbl_var->melody_E2_1.return_path);
1093
1094 break;
1095 }
1096
1097 case AUDIO_MELODY_E2_STOP_REQ:
1098 {
1099 /* stop event error - send an error message */
1100 audio_melody_E2_send_status (AUDIO_ERROR,((T_AUDIO_MELODY_E2_STOP *)(p_message))->return_path);
1101 audio_melody_E2_error_trace(AUDIO_ERROR_STOP_EVENT);
1102 break;
1103 } /* case AUDIO_MELODY_E2_STOP_REQ */
1104 } /* switch(p_message->msg_id) */
1105 break;
1106 } /* case AUDIO_MELODY_E2_WAIT_STOP_CON */
1107
1108 } /* switch(p_audio_gbl_var->melody_E2_1.state) */
1109
1110 } /*********************** End of audio_melody_E2_manager_1 function ************/
1111
1112 #ifndef _WINDOWS
1113 /*---------------------------------------------------------*/
1114 /* audio_background_melody_e2_download_instrument_manager()*/
1115 /*---------------------------------------------------------*/
1116 /* */
1117 /* Description: */
1118 /* ------------ */
1119 /* This function is used to load/unload the instrument of */
1120 /* the melodies E2. */
1121 /* */
1122 /* Starting messages: */
1123 /* L1_BACK_MELODY_E2_LOAD_INSTRUMENT_REQ */
1124 /* L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_REQ */
1125 /* */
1126 /* Result messages (input): none */
1127 /* */
1128 /* Result messages (output): */
1129 /* L1_BACK_MELODY_E2_LOAD_INSTRUMENT_CON */
1130 /* L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON */
1131 /* */
1132 /* Reset messages (input): none */
1133 /* */
1134 /* Stop message (input): none. */
1135 /* */
1136 /* Stop message (output): */
1137 /* L1_BACK_MELODY_E2_LOAD_INSTRUMENT_CON */
1138 /* L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON */
1139 /* */
1140 /* Rem: to stop immediatly the instrument download flags */
1141 /* ---- is created: */
1142 /* l1a_l1s_com.melody0_e2_task.parameters.emergency_stop */
1143 /* l1a_l1s_com.melody1_e2_task.parameters.emergency_stop */
1144 /* */
1145 /*---------------------------------------------------------*/
1146 void audio_background_melody_e2_download_instrument_manager(T_RV_HDR *p_message)
1147 {
1148 void *p_confirm_message;
1149 UINT8 instrument_number, max_number_of_instrument, instrument_id, id;
1150 UINT16 size;
1151 UINT32 address;
1152 void *p_send_message;
1153
1154 if (p_message->msg_id == L1_BACK_MELODY_E2_LOAD_INSTRUMENT_REQ)
1155 {
1156 // Load the instrument
1157
1158 // Init the first address
1159 address = ( ((UINT32)(l1s_dsp_com.dsp_ndb_ptr->a_melody_e2_instrument_wave))
1160 - SC_AUDIO_MCU_API_BEGIN_ADDRESS );
1161 l1s_dsp_com.dsp_ndb_ptr->a_melody_e2_instrument_ptr[0] =
1162 (API)( (address>>1) + SC_AUDIO_DSP_API_BEGIN_ADDRESS );
1163
1164 // Download the instrument
1165 max_number_of_instrument = ((T_L1_BACK_MELODY_E2_LOAD_INSTRUMENT_REQ *)(p_message))->number_of_instrument;
1166 for(instrument_number=0; instrument_number < max_number_of_instrument ; instrument_number++)
1167 {
1168 // No instrument was previously download
1169 if (audioback_melody_e2.number_of_user[instrument_number] == 0)
1170 {
1171 // load the insturment ID
1172 instrument_id =
1173 ((T_L1_BACK_MELODY_E2_LOAD_INSTRUMENT_REQ *)(p_message))->waves_table_id[instrument_number];
1174
1175 // Find if this instrument was already downloaded
1176 id = 0;
1177 while ( (id < SC_AUDIO_MELODY_E2_MAX_NUMBER_OF_INSTRUMENT) &&
1178 ((instrument_id != audioback_melody_e2.instrument_id[id]) ||
1179 (audioback_melody_e2.number_of_user[id] == 0)) )
1180 {
1181 id++;
1182 }
1183
1184 if (id < SC_AUDIO_MELODY_E2_MAX_NUMBER_OF_INSTRUMENT)
1185 {
1186 // This insturment was already downloaded
1187 // copy the address of this instrument
1188 l1s_dsp_com.dsp_ndb_ptr->a_melody_e2_instrument_ptr[instrument_number] =
1189 l1s_dsp_com.dsp_ndb_ptr->a_melody_e2_instrument_ptr[id];
1190
1191 // The size of this instrument is 0
1192 audioback_melody_e2.instrument_size[instrument_number] = 0;
1193 }
1194 else
1195 {
1196 // Load the customer instrument
1197 size = Cust_audio_melody_E2_load_instrument (
1198 ((T_L1_BACK_MELODY_E2_LOAD_INSTRUMENT_REQ *)(p_message))->waves_table_id[instrument_number],
1199 audioback_melody_e2.API_address,
1200 audioback_melody_e2.allowed_size);
1201
1202 // Added to stop the L1 in case of download error
1203 if (size == 0)
1204 {
1205 // Send a message to stop the L1
1206 /* send the stop command to the audio L1 */
1207 /* allocate the buffer for the message to the L1 */
1208 p_send_message = audio_allocate_l1_message(0);
1209 if ( p_send_message != NULL)
1210 {
1211 /* send the stop command to the audio L1 */
1212 if ( ((T_L1_BACK_MELODY_E2_LOAD_INSTRUMENT_REQ *)(p_message))->melody_id == 0)
1213 {
1214 audio_send_l1_message(MMI_MELODY0_E2_STOP_REQ, p_send_message);
1215 }
1216 else
1217 {
1218 audio_send_l1_message(MMI_MELODY1_E2_STOP_REQ, p_send_message);
1219 }
1220 }
1221 }
1222
1223 // Save the size of this instrument
1224 audioback_melody_e2.instrument_size[instrument_number]= size;
1225 }
1226
1227 // Update the Cust_audio_melody_E2_load_instrument argument
1228 audioback_melody_e2.API_address += audioback_melody_e2.instrument_size[instrument_number];
1229 audioback_melody_e2.allowed_size -= audioback_melody_e2.instrument_size[instrument_number];
1230
1231 // Put the DSP address to the NDB API for the next instrument
1232 if (instrument_number < SC_AUDIO_MELODY_E2_MAX_NUMBER_OF_INSTRUMENT-1)
1233 {
1234 address = ( ((UWORD32)(audioback_melody_e2.API_address))
1235 - SC_AUDIO_MCU_API_BEGIN_ADDRESS );
1236
1237 l1s_dsp_com.dsp_ndb_ptr->a_melody_e2_instrument_ptr[instrument_number + 1] =
1238 (API)( (address>>1) + SC_AUDIO_DSP_API_BEGIN_ADDRESS );
1239 }
1240
1241 // Save the instrument ID
1242 audioback_melody_e2.instrument_id[instrument_number] = instrument_id;
1243 }
1244
1245 // Increase the number of user of this instrument number
1246 audioback_melody_e2.number_of_user[instrument_number]++;
1247 }
1248
1249 // Send the load confirmation message
1250 p_confirm_message = audio_allocate_l1_message(sizeof(T_L1_BACK_MELODY_E2_LOAD_INSTRUMENT_CON));
1251 if (p_confirm_message != NULL)
1252 {
1253 // Fill the parameter
1254 ((T_L1_BACK_MELODY_E2_LOAD_INSTRUMENT_CON *)(p_confirm_message))->melody_id =
1255 ((T_L1_BACK_MELODY_E2_LOAD_INSTRUMENT_REQ *)(p_message))->melody_id;
1256
1257 /* send the start command to the audio L1 */
1258 audio_send_l1_message(L1_BACK_MELODY_E2_LOAD_INSTRUMENT_CON,
1259 p_confirm_message);
1260 }
1261 }
1262 else
1263 if (p_message->msg_id == L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_REQ)
1264 {
1265 // Unload the instrument
1266 max_number_of_instrument = ((T_L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_REQ *)(p_message))->number_of_instrument;
1267 for(instrument_number=max_number_of_instrument; instrument_number > 0; instrument_number--)
1268 {
1269 // Decrease the number of user of this instrument number
1270 audioback_melody_e2.number_of_user[instrument_number-1]--;
1271
1272 // Check if the instrument must be removed
1273 if (audioback_melody_e2.number_of_user[instrument_number-1] == 0)
1274 {
1275 // Increase the size and decrease the pointer to the API with the size
1276 // of the removed instrument
1277 // Update the Cust_audio_melody_E2_load_instrument argument
1278 audioback_melody_e2.API_address -= audioback_melody_e2.instrument_size[instrument_number-1];
1279 audioback_melody_e2.allowed_size += audioback_melody_e2.instrument_size[instrument_number-1];
1280 }
1281 }
1282
1283 // Send the unload confirmation message
1284 p_confirm_message = audio_allocate_l1_message(sizeof(T_L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON));
1285 if (p_confirm_message != NULL)
1286 {
1287 // Fill the parameter
1288 ((T_L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON *)(p_confirm_message))->melody_id =
1289 ((T_L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_REQ *)(p_message))->melody_id;
1290
1291 /* send the start command to the audio L1 */
1292 audio_send_l1_message(L1_BACK_MELODY_E2_UNLOAD_INSTRUMENT_CON,
1293 p_confirm_message);
1294 }
1295 }
1296 }
1297 #endif /* _WINDOWS */
1298 #endif /* MELODY_E2 */
1299 #endif /* RVM_AUDIO_MAIN_SWE */