comparison src/cs/services/Audio/audio_ffs.c @ 0:945cf7f506b2

src/cs: chipsetsw import from tcs211-fcmodem binary blobs and LCD demo files have been excluded, all line endings are LF only
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 25 Sep 2016 22:50:11 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:945cf7f506b2
1 /****************************************************************************/
2 /* */
3 /* Name audio_ffs.c */
4 /* */
5 /* Function this file contains the AUDIO ffs function: */
6 /* */
7 /* */
8 /* Version 0.1 */
9 /* */
10 /* Date Modification */
11 /* ------------------------------------ */
12 /* 18 May 2001 Create */
13 /* */
14 /* Author Francois Mazard - Stephanie Gerthoux */
15 /* */
16 /* (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved*/
17 /****************************************************************************/
18
19 #include "rv/rv_defined_swe.h"
20 #ifdef RVM_AUDIO_MAIN_SWE
21 #ifndef _WINDOWS
22 #include "config/swconfig.cfg"
23 #include "config/sys.cfg"
24 #include "config/chipset.cfg"
25 #endif
26
27 #include "l1_confg.h"
28 #if (MELODY_E1) || (MELODY_E2) || (VOICE_MEMO)
29 #include "rvf/rvf_api.h"
30 #include "rv/rv_general.h"
31 #include "rvm/rvm_gen.h"
32 #include "audio/audio_api.h"
33 #include "audio/audio_env_i.h"
34 #include "audio/audio_ffs_i.h"
35 #include "audio/audio_structs_i.h"
36 #include "audio/audio_macro_i.h"
37 #include "rvf/rvf_target.h"
38 #include "audio/audio_const_i.h"
39 #include "audio/audio_var_i.h"
40 #include "audio/audio_error_hdlr_i.h"
41 #include "audio/audio_messages_i.h"
42
43 /* include the usefull L1 header */
44 #define BOOL_FLAG
45 #define CHAR_FLAG
46 #include "l1_types.h"
47 #include "l1audio_cust.h"
48 #include "l1audio_const.h"
49 #include "l1audio_msgty.h"
50 #include "l1audio_signa.h"
51
52 #include "ffs/ffs_api.h"
53
54
55 /********************************************************************************/
56 /* */
57 /* Function Name: audio_ffs_manager */
58 /* */
59 /* Purpose: This function is called to manage the FFS request from the */
60 /* audio entity */
61 /* */
62 /* Input Parameters: */
63 /* message from the audio entity */
64 /* */
65 /* Output Parameters: */
66 /* None. */
67 /* */
68 /* Note: */
69 /* None. */
70 /* */
71 /* Revision History: */
72 /* None. */
73 /* */
74 /********************************************************************************/
75 void audio_ffs_manager (T_RV_HDR *p_message)
76 {
77 UINT8 j, active_task, index_ffs, index_l1, *p_buffer, channel_id;
78 T_AUDIO_FFS_SESSION *p_session;
79 T_RV_HDR *p_send_message;
80 T_RVF_MB_STATUS mb_status;
81 BOOLEAN loop_mode;
82 #ifndef _WINDOWS
83 UINT16 voice_memo_size, *p_scan;
84 #else
85 UINT16 i;
86 UINT8 *p_mem;
87 #endif
88 UINT16 buffer_size;
89 T_FFS_SIZE size;
90 T_RV_RET status;
91
92 switch (p_message->msg_id)
93 {
94 case AUDIO_FFS_FLASH_2_RAM_START_REQ:
95 {
96 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: flash to RAM session_id",
97 ((T_AUDIO_FFS_FLASH_2_RAM_START *)p_message)->session_id, RV_TRACE_LEVEL_DEBUG_LOW);
98
99 /* Find a free channel */
100 channel_id = 0;
101 while ( (p_audio_gbl_var->audio_ffs_session[channel_id].session_req.valid_channel) &&
102 (channel_id < AUDIO_FFS_MAX_CHANNEL) )
103 channel_id++;
104
105 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: open channel",
106 channel_id, RV_TRACE_LEVEL_DEBUG_LOW);
107
108 p_session =
109 &(p_audio_gbl_var->audio_ffs_session[channel_id]);
110
111 /* fill the request structure corresponding to the session id */
112 p_session->session_req.audio_ffs_fd =
113 ((T_AUDIO_FFS_FLASH_2_RAM_START *)p_message)->audio_ffs_fd;
114 p_session->session_req.size =
115 ((T_AUDIO_FFS_FLASH_2_RAM_START *)p_message)->initial_size;
116 p_session->session_req.loop_mode =
117 ((T_AUDIO_FFS_FLASH_2_RAM_START *)p_message)->loop;
118 p_session->session_req.session_id =
119 ((T_AUDIO_FFS_FLASH_2_RAM_START *)p_message)->session_id;
120
121 /************************************************************/
122 /* the FFS must download the 2 first buffers to the RAM */
123 /************************************************************/
124 for (j=0; j<2; j++)
125 {
126 /* allocate the first buffer */
127 p_session->session_info.buffer[j].size =
128 p_session->session_req.size;
129
130 mb_status = rvf_get_buf (p_audio_gbl_var->mb_audio_ffs,
131 p_session->session_info.buffer[j].size,
132 (T_RVF_BUFFER **) (&p_session->session_info.buffer[j].p_start_pointer));
133
134 /* If insufficient resources, then report a memory error and abort. */
135 if (mb_status == RVF_RED)
136 {
137 audio_ffs_error_trace(AUDIO_ENTITY_NO_MEMORY);
138 }
139
140 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: allocate buffer",
141 j, RV_TRACE_LEVEL_DEBUG_LOW);
142
143 /* intialize the stop pointer */
144 p_session->session_info.buffer[j].p_stop_pointer =
145 p_session->session_info.buffer[j].p_start_pointer +
146 (p_session->session_info.buffer[j].size);
147
148 /* Fill the buffer j while it isn't full in case of the loop back mode activated */
149 loop_mode = TRUE;
150 buffer_size = p_session->session_info.buffer[j].size;
151 p_buffer = (UINT8 *)p_session->session_info.buffer[j].p_start_pointer;
152 while ( (p_buffer < p_session->session_info.buffer[j].p_stop_pointer) &&
153 (loop_mode) )
154 {
155 loop_mode = p_session->session_req.loop_mode;
156
157 #ifndef _WINDOWS
158 size = ffs_read(p_session->session_req.audio_ffs_fd,
159 p_buffer,
160 buffer_size);
161 #else
162 size = buffer_size;
163 p_mem = p_buffer;
164 for (i=0; i<size; i++)
165 {
166 *p_mem = (UINT8)i;
167 p_mem++;
168 }
169 #endif
170
171 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: ffs_read size",
172 size, RV_TRACE_LEVEL_DEBUG_LOW);
173
174 buffer_size -= size;
175 p_buffer += size;
176
177 if (buffer_size != 0)
178 {
179 #ifndef _WINDOWS
180 /* reset the FFS pointer */
181 ffs_seek(p_session->session_req.audio_ffs_fd,
182 0,
183 FFS_SEEK_SET);
184 #endif
185 }
186 } /* while */
187 } /* for (j=0; j<2; j++) */
188
189 /* initialize the cust_get_pointer state machine */
190 p_session->session_info.cust_get_pointer_state = AUDIO_CUST_GET_POINTER_INIT;
191
192 /* inform the L1 to use the buffer 0 */
193 p_session->session_info.index_l1 = 0;
194
195 /* inform the FFS downloader to fill the buffer 0 when the L1 doesn't used */
196 p_session->session_info.index_ffs = 0;
197
198 p_session->session_req.session_mode =
199 AUDIO_FFS_FLASH_2_RAM_SESSION;
200
201 /* a new session is valid now */
202 p_session->session_req.valid_channel = TRUE;
203
204 /* Active the downloader if it is not already activated */
205 active_task = 0;
206 for (j=0; j<AUDIO_FFS_MAX_CHANNEL; j++)
207 {
208 if ( p_audio_gbl_var->audio_ffs_session[j].session_req.valid_channel )
209 {
210 active_task++;
211 }
212 }
213 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: active session",
214 active_task, RV_TRACE_LEVEL_DEBUG_LOW);
215 if (active_task == 1)
216 {
217 AUDIO_SEND_TRACE("AUDIO FFS MANAGER: start FFS DOWNLOADER", RV_TRACE_LEVEL_DEBUG_LOW);
218
219 /* Active asap the FFS downloader */
220 rvf_start_timer(AUDIO_FFS_TIMER, AUDIO_FFS_ACTIVE_NOW, AUDIO_FFS_ONE_SHOT_TIMER);
221 }
222
223 /* Send the message to confirm that the first buffer is downloaded */
224 /* allocate the message buffer */
225 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
226 sizeof (T_AUDIO_FFS_INIT),
227 (T_RVF_BUFFER **) (&p_send_message));
228
229 /* If insufficient resources, then report a memory error and abort. */
230 if (mb_status == RVF_RED)
231 {
232 audio_ffs_error_trace(AUDIO_ENTITY_NO_MEMORY);
233 }
234
235 /* fill the header of the message */
236 ((T_AUDIO_FFS_INIT*)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_INIT_DONE;
237
238 /* fill the status parameters */
239 ((T_AUDIO_FFS_INIT *)(p_send_message))->session_id =
240 ((T_AUDIO_FFS_FLASH_2_RAM_START *)p_message)->session_id;
241 ((T_AUDIO_FFS_INIT *)(p_send_message))->channel_id =
242 channel_id;
243
244
245 /* send the message to the AUDIO entity */
246 rvf_send_msg (p_audio_gbl_var->addrId,
247 p_send_message);
248 break;
249 }
250 case AUDIO_FFS_RAM_2_FLASH_START_REQ:
251 {
252 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: RAM to flash session_id",
253 ((T_AUDIO_FFS_RAM_2_FLASH_START *)p_message)->session_id, RV_TRACE_LEVEL_DEBUG_LOW);
254
255 /* Find a free channel */
256 channel_id = 0;
257 while ( (p_audio_gbl_var->audio_ffs_session[channel_id].session_req.valid_channel) &&
258 (channel_id < AUDIO_FFS_MAX_CHANNEL) )
259 channel_id++;
260
261 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: open channel",
262 channel_id, RV_TRACE_LEVEL_DEBUG_LOW);
263
264 p_session =
265 &(p_audio_gbl_var->audio_ffs_session[channel_id]);
266
267 /* fill the request structure corresponding to the session id */
268 p_session->session_req.size =
269 ((T_AUDIO_FFS_RAM_2_FLASH_START *)p_message)->initial_size;
270 p_session->session_req.loop_mode = FALSE;
271 p_session->session_req.audio_ffs_fd =
272 ((T_AUDIO_FFS_RAM_2_FLASH_START *)p_message)->audio_ffs_fd;
273 p_session->session_req.session_mode =
274 AUDIO_FFS_RAM_2_FLASH_SESSION;
275 p_session->session_req.session_id =
276 ((T_AUDIO_FFS_RAM_2_FLASH_START *)p_message)->session_id;
277
278 /********************* TO BE COMPLETED **********************/
279 /* the FFS must allocate the first buffer to the RAM */
280 /************************************************************/
281 for (j=0; j<2; j++)
282 {
283 mb_status = rvf_get_buf (p_audio_gbl_var->mb_audio_ffs,
284 p_session->session_req.size,
285 (T_RVF_BUFFER **) (&p_session->session_info.buffer[j].p_start_pointer));
286
287 /* If insufficient resources, then report a memory error and abort. */
288 if (mb_status == RVF_RED)
289 {
290 audio_ffs_error_trace(AUDIO_ENTITY_NO_MEMORY);
291 }
292
293 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: allocate buffer",
294 j, RV_TRACE_LEVEL_DEBUG_LOW);
295
296 /* Copy the initial size */
297 p_session->session_info.buffer[j].size = p_session->session_req.size;
298 }
299
300 /* initialize the cust_get_pointer state machine */
301 p_session->session_info.cust_get_pointer_state = AUDIO_CUST_GET_POINTER_INIT;
302
303 /* inform the L1 to use the buffer 0 */
304 p_session->session_info.index_l1 = 0;
305
306 /* inform the FFS downloader to read the buffer 0 when the L1 doesn't used */
307 p_session->session_info.index_ffs = 0;
308
309 /* a new session is valid now */
310 p_session->session_req.valid_channel = TRUE;
311
312 /* Active the downloader if it is not already activated */
313 active_task = 0;
314 for (j=0; j<AUDIO_FFS_MAX_CHANNEL; j++)
315 {
316 if ( p_audio_gbl_var->audio_ffs_session[j].session_req.valid_channel)
317 {
318 active_task++;
319 }
320 }
321 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: active session",
322 active_task, RV_TRACE_LEVEL_DEBUG_LOW);
323
324 if (active_task == 1)
325 {
326 AUDIO_SEND_TRACE("AUDIO FFS MANAGER: start FFS DOWNLOADER", RV_TRACE_LEVEL_DEBUG_LOW);
327
328 /* Active asap the FFS downloader */
329 rvf_start_timer(AUDIO_FFS_TIMER, AUDIO_FFS_ACTIVE_NOW, AUDIO_FFS_ONE_SHOT_TIMER);
330 }
331 /* Send the message to confirm that the first buffer is allocated */
332 /* allocate the message buffer */
333 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
334 sizeof (T_AUDIO_FFS_INIT),
335 (T_RVF_BUFFER **) (&p_send_message));
336
337 /* If insufficient resources, then report a memory error and abort. */
338 if (mb_status == RVF_RED)
339 {
340 audio_ffs_error_trace(AUDIO_ENTITY_NO_MEMORY);
341 }
342
343 /* fill the header of the message */
344 ((T_AUDIO_FFS_INIT*)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_INIT_DONE;
345
346 /* fill the status parameters */
347 ((T_AUDIO_FFS_INIT *)(p_send_message))->session_id =
348 ((T_AUDIO_FFS_RAM_2_FLASH_START *)p_message)->session_id;
349 ((T_AUDIO_FFS_INIT *)(p_send_message))->channel_id =
350 channel_id;
351
352 /* send the message to the AUDIO entity */
353 rvf_send_msg (p_audio_gbl_var->addrId,
354 p_send_message);
355
356 break;
357 }
358
359 case AUDIO_FFS_STOP_REQ:
360 {
361 /* Find a channel corresponding to this session */
362 channel_id = 0;
363 while ( (p_audio_gbl_var->audio_ffs_session[channel_id].session_req.session_id
364 != ((T_AUDIO_FFS_STOP_REQ *)p_message)->session_id) &&
365 (channel_id < AUDIO_FFS_MAX_CHANNEL) )
366 channel_id++;
367
368 p_session = &(p_audio_gbl_var->audio_ffs_session[channel_id]);
369
370 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: stop session_id",
371 ((T_AUDIO_FFS_STOP_REQ *)p_message)->session_id, RV_TRACE_LEVEL_DEBUG_LOW);
372 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: close channel",
373 channel_id, RV_TRACE_LEVEL_DEBUG_LOW);
374
375 /* the task is stopped */
376 p_session->session_req.valid_channel = FALSE;
377
378 /* the stop process depends on the session_mode and sometimes the session_id */
379 #if (VOICE_MEMO)
380 if ( (p_session->session_req.session_mode == AUDIO_FFS_RAM_2_FLASH_SESSION) &&
381 (((T_AUDIO_FFS_STOP_REQ *)p_message)->session_id == AUDIO_FFS_SESSION_VM_RECORD) )
382 {
383 index_l1 = p_session->session_info.index_l1;
384 index_ffs = p_session->session_info.index_ffs;
385
386 if (index_ffs != index_l1)
387 /* There's two buffers to save: one full (index_ffs) and one not full (index_l1) */
388 {
389 AUDIO_SEND_TRACE("AUDIO FFS MANAGER: end of VM record session with index_l1<>index_ffs", RV_TRACE_LEVEL_DEBUG_LOW);
390
391 #ifndef _WINDOWS
392 /* save the full buffer */
393 if ((ffs_write (p_session->session_req.audio_ffs_fd,
394 p_session->session_info.buffer[index_ffs].p_start_pointer,
395 p_session->session_req.size)) < EFFS_OK)
396 {
397 audio_ffs_error_trace(AUDIO_ENTITY_FILE_NO_SAVED);
398 }
399
400 /* save a part of the buffer pointed by the L1 */
401 voice_memo_size = 2;
402 p_scan = (UINT16 *)(p_session->session_info.buffer[index_l1].p_start_pointer);
403 while ( (*p_scan++) != SC_VM_END_MASK )
404 {
405 voice_memo_size += 2;
406 }
407
408 if ((ffs_write (p_session->session_req.audio_ffs_fd,
409 p_session->session_info.buffer[index_l1].p_start_pointer,
410 voice_memo_size)) < EFFS_OK)
411 {
412 audio_ffs_error_trace(AUDIO_ENTITY_FILE_NO_SAVED);
413 }
414 #endif
415 }
416 else
417 /* 1 buffer (not full) needs to be saved */
418 {
419 AUDIO_SEND_TRACE("AUDIO FFS MANAGER: end of VM record session with index_l1==index_ffs", RV_TRACE_LEVEL_DEBUG_LOW);
420 #ifndef _WINDOWS
421 voice_memo_size = 2;
422 p_scan = (UINT16*)(p_session->session_info.buffer[index_l1].p_start_pointer);
423 while ( (*p_scan++) != SC_VM_END_MASK )
424 {
425 voice_memo_size += 2;
426 }
427
428 if ((ffs_write (p_session->session_req.audio_ffs_fd,
429 p_session->session_info.buffer[index_l1].p_start_pointer,
430 voice_memo_size)) < EFFS_OK)
431 {
432 audio_ffs_error_trace(AUDIO_ENTITY_FILE_NO_SAVED);
433 }
434 #endif
435 } /* index_ffs != index_l1 */
436 }
437 #endif /* VOICE_MEMO */
438 /* deallocate the buffers */
439 for (j=0; j<AUDIO_MAX_FFS_BUFFER_PER_SESSION; j++)
440 {
441 status = rvf_free_buf ( (T_RVF_BUFFER *)(p_session->session_info.buffer[j].p_start_pointer) );
442 if (status != RVF_GREEN)
443 {
444 AUDIO_SEND_TRACE(" wrong buffer deallocated ",
445 RV_TRACE_LEVEL_ERROR);
446 }
447 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: deallocate buffer",
448 j, RV_TRACE_LEVEL_DEBUG_LOW);
449 }
450
451 /* Close the FFS file */
452 #ifndef _WINDOWS
453 if ( ffs_close(p_session->session_req.audio_ffs_fd) != EFFS_OK )
454 {
455 audio_ffs_error_trace(AUDIO_ENTITY_FILE_NO_CLOSE);
456 }
457 #endif
458
459 /* Send the message to confirm that the session is stopped */
460 /* allocate the message buffer */
461 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
462 sizeof (T_AUDIO_FFS_STOP_CON),
463 (T_RVF_BUFFER **)(&p_send_message));
464
465 /* If insufficient resources, then report a memory error and abort. */
466 if (mb_status == RVF_RED)
467 {
468 audio_ffs_error_trace(AUDIO_ENTITY_NO_MEMORY);
469 }
470
471 /* fill the header of the message */
472 ((T_AUDIO_FFS_STOP_CON*)(p_send_message))->os_hdr.msg_id = AUDIO_FFS_STOP_CON;
473
474 /* fill the status parameters */
475 ((T_AUDIO_FFS_STOP_CON*)(p_send_message))->session_id =
476 ((T_AUDIO_FFS_STOP_REQ *)p_message)->session_id;
477
478 /* send the message to the AUDIO entity */
479 rvf_send_msg (p_audio_gbl_var->addrId,
480 p_send_message);
481 break;
482 }
483 } /* switch (p_message) */
484 }
485
486 /********************************************************************************/
487 /* */
488 /* Function Name: audio_ffs_downloader */
489 /* */
490 /* Purpose: This function is called to download the melody, voice memo data */
491 /* between the RAM and the FLASH. */
492 /* */
493 /* Input Parameters: */
494 /* None. */
495 /* */
496 /* Output Parameters: */
497 /* None. */
498 /* */
499 /* Note: */
500 /* None. */
501 /* */
502 /* Revision History: */
503 /* None. */
504 /* */
505 /********************************************************************************/
506 void audio_ffs_downloader(void)
507 {
508 UINT8 i, index_ffs, index_l1, *p_buffer;
509 T_AUDIO_FFS_SESSION *p_session;
510 UINT16 buffer_size;
511 T_FFS_SIZE size = 0;
512 BOOLEAN loop_mode, active_session;
513
514 /* Scan all session in order to know which is valid */
515 active_session = FALSE;
516 for (i=0; i<AUDIO_FFS_MAX_CHANNEL; i++)
517 {
518 p_session = &(p_audio_gbl_var->audio_ffs_session[i]);
519 if (p_session->session_req.valid_channel)
520 {
521 /* a session is valid */
522 active_session = TRUE;
523
524 index_l1 = p_session->session_info.index_l1;
525 index_ffs = p_session->session_info.index_ffs;
526
527 if (index_l1 != index_ffs)
528 /* It's time to download a new buffer for the L1 */
529 {
530 AUDIO_SEND_TRACE_PARAM("AUDIO FFS DOWNLOADER: index_l1",
531 index_l1, RV_TRACE_LEVEL_DEBUG_LOW);
532 AUDIO_SEND_TRACE_PARAM("AUDIO FFS DOWNLOADER: index_ffs",
533 index_ffs, RV_TRACE_LEVEL_DEBUG_LOW);
534
535 switch (p_session->session_req.session_mode)
536 {
537 case AUDIO_FFS_FLASH_2_RAM_SESSION:
538 {
539 AUDIO_SEND_TRACE("AUDIO FFS DOWNLOADER: FLASH to RAM", RV_TRACE_LEVEL_DEBUG_LOW);
540
541 /* Fill the buffer 0 while it isn't full in case of the loop back mode activated */
542 loop_mode = TRUE;
543 buffer_size = p_session->session_info.buffer[index_ffs].size;
544 p_buffer = (UINT8 *)p_session->session_info.buffer[index_ffs].p_start_pointer;
545 while ( (p_buffer < p_session->session_info.buffer[index_ffs].p_stop_pointer) &&
546 (loop_mode) )
547 {
548 loop_mode = p_session->session_req.loop_mode;
549
550 #ifndef _WINDOWS
551 size = ffs_read(p_session->session_req.audio_ffs_fd,
552 p_buffer,
553 buffer_size);
554 #endif
555
556 AUDIO_SEND_TRACE_PARAM("AUDIO FFS MANAGER: ffs_read size",
557 size, RV_TRACE_LEVEL_DEBUG_LOW);
558
559 buffer_size -= size;
560 p_buffer += size;
561
562 if (buffer_size != 0)
563 {
564 #ifndef _WINDOWS
565 /* reset the FFS pointer */
566 ffs_seek(p_session->session_req.audio_ffs_fd,
567 0,
568 FFS_SEEK_SET);
569 #endif
570 }
571 } /* while */
572 break;
573 }
574
575 case AUDIO_FFS_RAM_2_FLASH_SESSION:
576 {
577 AUDIO_SEND_TRACE("AUDIO FFS DOWNLOADER: RAM to FLASH", RV_TRACE_LEVEL_DEBUG_LOW);
578
579 /* save the full buffer */
580 #ifndef _WINDOWS
581 if ((ffs_write (p_session->session_req.audio_ffs_fd,
582 p_session->session_info.buffer[index_ffs].p_start_pointer,
583 p_session->session_req.size)) < EFFS_OK)
584 {
585 audio_ffs_error_trace(AUDIO_ENTITY_FILE_NO_SAVED);
586 }
587 #endif
588 break;
589 }
590 } /* switch (p_session->session_req.session_mode) */
591
592 /* update the ffs buffer index */
593 p_session->session_info.index_ffs++;
594 if (p_session->session_info.index_ffs == AUDIO_MAX_FFS_BUFFER_PER_SESSION)
595 {
596 p_session->session_info.index_ffs = 0;
597 }
598 } /* (p_session->session_info.index_l1 != p_session->session_info.index_l1) */
599 } /* valid session */
600 } /* for (i=0; i<AUDIO_FFS_MAX_CHANNEL; i++) */
601
602 /* Activate or not the Timer the next time */
603 if (active_session)
604 {
605 rvf_start_timer(AUDIO_FFS_TIMER, AUDIO_FFS_TIME_OUT, AUDIO_FFS_ONE_SHOT_TIMER);
606 }
607 else
608 {
609 AUDIO_SEND_TRACE("AUDIO FFS DOWNLOADER: stop", RV_TRACE_LEVEL_DEBUG_LOW);
610 /* Stop asap the FFS downloader */
611 rvf_stop_timer(AUDIO_FFS_TIMER);
612 }
613 }
614 #endif /* MELODY_E1 || MELODY_E2 || VOICE_MEMO */
615
616 #if (L1_VOICE_MEMO_AMR)
617 T_AUDIO_RET audio_convert_to_mms(UINT8 *p_buffer, UINT16 *buffer_size, UINT8 *previous_type, UINT8 *size_left)
618 {
619 UINT8 rxtx_type, frame_header, data_size;
620 UINT8 frame_type, quality;
621 UINT8 *ptr_final, *ptr_mms;
622
623 ptr_mms = p_buffer;
624 ptr_final = ptr_mms + *buffer_size;
625
626 /* sample is shared among the 2 buffers */
627 if (*size_left > 0)
628 {
629 UINT8 i;
630
631 switch (*previous_type)
632 {
633 case AUDIO_VM_AMR_RXTX_SID_FIRST:
634 /* set data bits to 0 */
635 for (i = 0; i < *size_left; i++)
636 *(ptr_mms + i) = 0;
637 /* set Mode Indication */
638 *(ptr_mms + *size_left - 1) = AUDIO_MMS_MODE_INDICATION;
639 break;
640 case AUDIO_VM_AMR_RXTX_SID_UPDATE:
641 //case AUDIO_VM_AMR_RXTX_SID_BAD:
642 *(ptr_mms + *size_left - 1) |= AUDIO_MMS_STI_BIT | AUDIO_MMS_MODE_INDICATION;
643 break;
644 }
645 ptr_mms += *size_left;
646 }
647 *size_left = 0;
648
649 while (ptr_mms < ptr_final)
650 {
651 /* read header */
652 frame_header = *ptr_mms;
653
654 /* if end_mask, stop */
655 if (frame_header == SC_VM_AMR_END_MASK)
656 {
657 *buffer_size = (ptr_mms - p_buffer);
658 return AUDIO_OK;
659 }
660
661 /* reset header */
662 *ptr_mms = 0;
663
664 rxtx_type = (frame_header & SC_RX_TX_TYPE_MASK);
665 *previous_type = rxtx_type;
666 switch (rxtx_type)
667 {
668 case AUDIO_VM_AMR_RXTX_SPEECH_GOOD:
669 //case AUDIO_VM_AMR_RXTX_SPEECH_BAD:
670 {
671 /* FT + data_size */
672 frame_type = frame_header & SC_CHAN_TYPE_MASK;
673 switch (frame_type)
674 {
675 case AUDIO_VM_AMR_SPEECH_475:
676 data_size = AUDIO_VM_AMR_SPEECH_475_DATA_SIZE;
677 break;
678 case AUDIO_VM_AMR_SPEECH_515:
679 data_size = AUDIO_VM_AMR_SPEECH_515_DATA_SIZE;
680 break;
681 case AUDIO_VM_AMR_SPEECH_59:
682 data_size = AUDIO_VM_AMR_SPEECH_590_DATA_SIZE;
683 break;
684 case AUDIO_VM_AMR_SPEECH_67:
685 data_size = AUDIO_VM_AMR_SPEECH_670_DATA_SIZE;
686 break;
687 case AUDIO_VM_AMR_SPEECH_74:
688 data_size = AUDIO_VM_AMR_SPEECH_740_DATA_SIZE;
689 break;
690 case AUDIO_VM_AMR_SPEECH_795:
691 data_size = AUDIO_VM_AMR_SPEECH_795_DATA_SIZE;
692 break;
693 case AUDIO_VM_AMR_SPEECH_102:
694 data_size = AUDIO_VM_AMR_SPEECH_102_DATA_SIZE;
695 break;
696 case AUDIO_VM_AMR_SPEECH_122:
697 data_size = AUDIO_VM_AMR_SPEECH_122_DATA_SIZE;
698 break;
699 }
700 /* Q */
701 //if (rxtx_type == AUDIO_VM_AMR_RXTX_SPEECH_GOOD)
702 quality = AUDIO_MMS_GOOD_QUALITY;
703 //else
704 // quality = AUDIO_MMS_BAD_QUALITY;
705 }
706 break;
707 case AUDIO_VM_AMR_RXTX_SID_FIRST:
708 case AUDIO_VM_AMR_RXTX_SID_UPDATE:
709 //case AUDIO_VM_AMR_RXTX_SID_BAD:
710 {
711 /* FT, data_size, Q */
712 frame_type = AUDIO_MMS_SID_FRAME_TYPE;
713 data_size = AUDIO_VM_AMR_SID_DATA_SIZE;
714 //if ((rxtx_type == AUDIO_VM_AMR_RXTX_SID_FIRST)||
715 // (rxtx_type == AUDIO_VM_AMR_RXTX_SID_UPDATE))
716 //{
717 quality = AUDIO_MMS_GOOD_QUALITY;
718 //}
719 //else
720 // quality = AUDIO_MMS_BAD_QUALITY;
721
722 /* data, STI, Mode indication */
723 if (rxtx_type == AUDIO_VM_AMR_RXTX_SID_FIRST)
724 {
725 UINT8 data, i;
726
727 /* number of bytes to set to 0 */
728 data = ((ptr_final - ptr_mms) >= (data_size + 1)) ? (data_size) : (ptr_final - ptr_mms - 1);
729
730 /* set data bits to 0 */
731 for (i = 0; i < data; i++)
732 *(ptr_mms + 1 + i) = 0;
733
734 /* set Mode indication */
735 if ((ptr_final - ptr_mms) >= (data_size + 1))
736 *(ptr_mms + data_size) = AUDIO_MMS_MODE_INDICATION;
737
738 }
739 /* SID_UPDATE */
740 else
741 {
742 /* set STI bit to 1 + Mode indication */
743 if ((ptr_final - ptr_mms) >= (data_size + 1))
744 *(ptr_mms + data_size) |= AUDIO_MMS_STI_BIT | AUDIO_MMS_MODE_INDICATION;
745 }
746 }
747 break;
748 case AUDIO_VM_AMR_RXTX_NO_DATA:
749 frame_type = AUDIO_MMS_NO_DATA_FRAME_TYPE;
750 data_size = AUDIO_VM_AMR_NO_DATA_DATA_SIZE;
751 quality = AUDIO_MMS_GOOD_QUALITY;
752 break;
753 default:
754 {
755 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY MANAGER: convert to MMS, header not recognized", frame_header, RV_TRACE_LEVEL_DEBUG_LOW);
756 return AUDIO_ERROR;
757 }
758 }
759 /* write header */
760 *(ptr_mms)++ |= (frame_type << AUDIO_MMS_FRAME_TYPE_SHIFT) | (quality << AUDIO_MMS_QUALITY_SHIFT);
761
762 /* write data, check we are not at the end of the buffer */
763 if ((ptr_final - ptr_mms) < data_size)
764 {
765 *size_left = data_size - (ptr_final - ptr_mms);
766 data_size = ptr_final - ptr_mms;
767 }
768 ptr_mms += data_size;
769 }
770 *buffer_size = (ptr_final - p_buffer);
771 return AUDIO_OK;
772 }
773
774 T_AUDIO_RET audio_convert_from_mms(UINT8 *p_buffer, UINT16 buffer_size, UINT8 *previous_type, UINT8 *size_left)
775 {
776 UINT8 frame_header, data_size;
777 UINT8 frame_type, quality;
778 UINT8 *ptr_final, *ptr_mms;
779
780 ptr_mms = p_buffer;
781 ptr_final = ptr_mms + buffer_size;
782
783 /* a sample is split between 2 RAM buffers */
784 if (*size_left > 0)
785 {
786 /* if SID sample, remove STI and mode indication */
787 if (*previous_type == AUDIO_MMS_SID_FRAME_TYPE)
788 {
789 *(ptr_mms + *size_left - 1) &= (~(AUDIO_MMS_STI_BIT | AUDIO_MMS_MODE_INDICATION));
790 }
791 ptr_mms += *size_left;
792 *size_left = 0;
793 }
794
795 while (ptr_mms < ptr_final)
796 {
797 /* read header */
798 frame_header = *ptr_mms;
799
800 /* reset header */
801 *ptr_mms = 0;
802
803 /* FT and Q */
804 frame_type = (frame_header & AUDIO_MMS_FRAME_TYPE_MASK) >> AUDIO_MMS_FRAME_TYPE_SHIFT;
805 quality = (frame_header & AUDIO_MMS_QUALITY_MASK) >> AUDIO_MMS_QUALITY_SHIFT;
806 *previous_type = frame_type;
807
808 /* Identify sample */
809 if (frame_type < AUDIO_MMS_SID_FRAME_TYPE)
810 {
811 /* speech good or bad */
812 *ptr_mms |= frame_type;
813 if (quality == AUDIO_MMS_GOOD_QUALITY)
814 *ptr_mms |= AUDIO_VM_AMR_RXTX_SPEECH_GOOD;
815 else
816 *ptr_mms |= AUDIO_VM_AMR_RXTX_SPEECH_BAD;
817
818 switch (frame_type)
819 {
820 case AUDIO_VM_AMR_SPEECH_475:
821 data_size = AUDIO_VM_AMR_SPEECH_475_DATA_SIZE;
822 break;
823 case AUDIO_VM_AMR_SPEECH_515:
824 data_size = AUDIO_VM_AMR_SPEECH_515_DATA_SIZE;
825 break;
826 case AUDIO_VM_AMR_SPEECH_59:
827 data_size = AUDIO_VM_AMR_SPEECH_590_DATA_SIZE;
828 break;
829 case AUDIO_VM_AMR_SPEECH_67:
830 data_size = AUDIO_VM_AMR_SPEECH_670_DATA_SIZE;
831 break;
832 case AUDIO_VM_AMR_SPEECH_74:
833 data_size = AUDIO_VM_AMR_SPEECH_740_DATA_SIZE;
834 break;
835 case AUDIO_VM_AMR_SPEECH_795:
836 data_size = AUDIO_VM_AMR_SPEECH_795_DATA_SIZE;
837 break;
838 case AUDIO_VM_AMR_SPEECH_102:
839 data_size = AUDIO_VM_AMR_SPEECH_102_DATA_SIZE;
840 break;
841 case AUDIO_VM_AMR_SPEECH_122:
842 data_size = AUDIO_VM_AMR_SPEECH_122_DATA_SIZE;
843 break;
844 }
845 }
846 else if (frame_type == AUDIO_MMS_SID_FRAME_TYPE)
847 {
848 data_size = AUDIO_VM_AMR_SID_DATA_SIZE;
849 /* SID_BAD */
850 if (quality == AUDIO_MMS_BAD_QUALITY)
851 *ptr_mms |= AUDIO_VM_AMR_RXTX_SID_BAD;
852 /* SID_FIRST or SID_UPDATE */
853 else
854 {
855 if (*previous_type == AUDIO_MMS_NO_DATA_FRAME_TYPE)
856 *ptr_mms |= AUDIO_VM_AMR_RXTX_SID_UPDATE;
857 else
858 *ptr_mms |= AUDIO_VM_AMR_RXTX_SID_FIRST;
859 /* try to remove STI + mode indication if sample not split between 2 buffers */
860 if ((ptr_final - ptr_mms) >= (data_size + 1))
861 *(ptr_mms + data_size) &= (~(AUDIO_MMS_STI_BIT | AUDIO_MMS_MODE_INDICATION));
862 }
863 }
864 else if (frame_type == AUDIO_MMS_NO_DATA_FRAME_TYPE)
865 {
866 data_size = AUDIO_VM_AMR_NO_DATA_DATA_SIZE;
867 *ptr_mms |= AUDIO_VM_AMR_RXTX_NO_DATA;
868 }
869 else
870 {
871 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY MANAGER: convert from MMS, header not recognized", frame_header, RV_TRACE_LEVEL_DEBUG_LOW);
872 return AUDIO_ERROR;
873 }
874
875 /* pass header */
876 ptr_mms++;
877
878 /* write data, check we are not at the end of the buffer */
879 if ((ptr_final - ptr_mms) < data_size)
880 {
881 *size_left = data_size - (ptr_final - ptr_mms);
882 data_size = ptr_final - ptr_mms;
883 }
884 ptr_mms += data_size;
885 }
886 return AUDIO_OK;
887 }
888 #endif
889
890 #if (AUDIO_RAM_MANAGER)
891 /* try to copy "size" bytes from audio_ram_fd to dest_buffer, returns bytes copied (0 to size) */
892 INT16 ram_read(T_AUDIO_MEM_SESSION *p_session, UINT8 *dest_buffer, UINT16 size)
893 {
894 UINT16 i;
895
896 /* check how many bytes there are in audio_ram_fd */
897 if (size > p_session->session_req.audio_ram_size)
898 size = p_session->session_req.audio_ram_size;
899 /* copy byte by byte */
900 for (i = 0; i < size; i++)
901 *dest_buffer++ = *(p_session->session_req.audio_ram_fd)++;
902 /* update audio_ram_fd size */
903 p_session->session_req.audio_ram_size -= size;
904 return size;
905 }
906
907 /* copy "size" bytes from src_buffer to audio_ram_fd, does not check size */
908 INT16 ram_write(T_AUDIO_MEM_SESSION *p_session, UINT8 *src_buffer, UINT16 size)
909 {
910 UINT16 i;
911
912 /* copy byte by byte */
913 for (i = 0; i < size; i++)
914 *(p_session->session_req.audio_ram_fd)++ = *src_buffer++;
915 return size;
916 }
917 #endif
918
919 #if (AUDIO_MEM_MANAGER)
920 void audio_mem_send_status(T_AUDIO_RET status, UINT8 channel_id, UINT8 status_type,
921 T_RV_RETURN return_path)
922 {
923 /* status_type START or STOP, status AUDIO_OK or AUDIO_ERROR */
924 T_AUDIO_MEM_STATUS *p_send_message;
925 T_RVF_MB_STATUS mb_status = RVF_RED;
926
927 while (mb_status == RVF_RED)
928 {
929 /* allocate the message buffer */
930 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
931 sizeof (T_AUDIO_MEM_STATUS),
932 (T_RVF_BUFFER **) (&p_send_message));
933
934 /* If insufficient resources, then report a memory error and abort. */
935 /* and wait until more ressource is given */
936 if (mb_status == RVF_RED)
937 {
938 audio_mem_error_trace(AUDIO_ENTITY_NO_MEMORY);
939 rvf_delay(RVF_MS_TO_TICKS(1000));
940 }
941 }
942
943 /*fill the header of the message */
944 p_send_message->os_hdr.msg_id = AUDIO_MEM_STATUS_MSG;
945
946 /* fill the status parameters */
947 p_send_message->status = status;
948 p_send_message->channel_id = channel_id;
949 p_send_message->status_type = status_type;
950
951 /* send message or call callback */
952 if (return_path.callback_func == NULL)
953 rvf_send_msg (return_path.addr_id, p_send_message);
954 else
955 {
956 (*return_path.callback_func)((void *)(p_send_message));
957 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
958 }
959 }
960
961 void audio_mem_send_record_status(UINT8 channel_id, UINT32 recorded_size, T_RV_RETURN return_path)
962 {
963 /* status_type START or STOP, status AUDIO_OK or AUDIO_ERROR */
964 T_AUDIO_MEM_STATUS *p_send_message;
965 T_RVF_MB_STATUS mb_status = RVF_RED;
966
967 while (mb_status == RVF_RED)
968 {
969 /* allocate the message buffer */
970 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
971 sizeof (T_AUDIO_MEM_STATUS),
972 (T_RVF_BUFFER **) (&p_send_message));
973
974 /* If insufficient resources, then report a memory error and abort. */
975 /* and wait until more ressource is given */
976 if (mb_status == RVF_RED)
977 {
978 audio_mem_error_trace(AUDIO_ENTITY_NO_MEMORY);
979 rvf_delay(RVF_MS_TO_TICKS(1000));
980 }
981 }
982
983 /*fill the header of the message */
984 p_send_message->os_hdr.msg_id = AUDIO_MEM_STATUS_MSG;
985
986 /* fill the status parameters */
987 p_send_message->status = AUDIO_OK;
988 p_send_message->channel_id = channel_id;
989 p_send_message->status_type = AUDIO_STOP_STATUS;
990 p_send_message->recorded_size = recorded_size;
991
992 /* send message or call callback */
993 if (return_path.callback_func == NULL)
994 rvf_send_msg (return_path.addr_id, p_send_message);
995 else
996 {
997 (*return_path.callback_func)((void *)(p_send_message));
998 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
999 }
1000 }
1001
1002 void audio_mem_manager (T_RV_HDR *p_message)
1003 {
1004 UINT8 channel_id, session_id, state;
1005 UINT8 mem_channel_id;
1006 T_RV_RETURN return_path;
1007 T_AUDIO_MEM_SESSION *p_session;
1008
1009 /* get channel_id from messages */
1010 switch (p_message->msg_id)
1011 {
1012 case AUDIO_MEM_START_REQ:
1013 channel_id = ((T_AUDIO_MEM_START *)p_message)->channel_id;
1014 session_id = ((T_AUDIO_MEM_START *)p_message)->session_id;
1015 break;
1016 case AUDIO_MEM_STOP_REQ:
1017 channel_id = ((T_AUDIO_MEM_STOP *)p_message)->channel_id;
1018 break;
1019 case AUDIO_DRIVER_NOTIFICATION_MSG:
1020 channel_id = ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->channel_id;
1021 break;
1022 case AUDIO_DRIVER_LAST_NOTIFICATION_MSG:
1023 channel_id = ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->channel_id;
1024 break;
1025 case AUDIO_DRIVER_STATUS_MSG:
1026 channel_id = ((T_AUDIO_DRIVER_STATUS *)p_message)->channel_id;
1027 break;
1028 }
1029
1030 /* Init mem_channel_id to browse all mem channels and find channel_id */
1031 /* state will stay IDLE if no mem channel is found */
1032 mem_channel_id = 0;
1033 state = AUDIO_MEM_IDLE;
1034
1035 /* look for an ACTIVE session, which channel_id matches the one from the message */
1036 while ( (mem_channel_id < AUDIO_MEM_MAX_CHANNEL)&&
1037 ((p_audio_gbl_var->audio_mem_session[mem_channel_id].session_info.state == AUDIO_MEM_IDLE)||
1038 (p_audio_gbl_var->audio_mem_session[mem_channel_id].session_req.channel_id != channel_id)) )
1039 {
1040 mem_channel_id++;
1041 }
1042
1043 /* if mem_channel_id < MAX_CHANNEL, we found an active channel so we can derive state */
1044 if (mem_channel_id < AUDIO_MEM_MAX_CHANNEL)
1045 {
1046 p_session = &(p_audio_gbl_var->audio_mem_session[mem_channel_id]);
1047 state = p_session->session_info.state;
1048 }
1049
1050 switch (state)
1051 {
1052 case AUDIO_MEM_IDLE:
1053 {
1054 /* requester return_path (currently is Riviera Audio) */
1055 return_path.callback_func = NULL;
1056 return_path.addr_id = p_audio_gbl_var->addrId;
1057
1058 switch (p_message->msg_id)
1059 {
1060 case AUDIO_MEM_START_REQ:
1061 {
1062 /* find free MEM channel i.e. state = AUDIO_MEM_IDLE */
1063 mem_channel_id = 0;
1064 while ( (p_audio_gbl_var->audio_mem_session[mem_channel_id].session_info.state != AUDIO_MEM_IDLE) &&
1065 (mem_channel_id < AUDIO_MEM_MAX_CHANNEL) )
1066 mem_channel_id++;
1067
1068 if (mem_channel_id == AUDIO_MEM_MAX_CHANNEL)
1069 {
1070 AUDIO_SEND_TRACE("AUDIO MEMORY MANAGER: no memory channel available", RV_TRACE_LEVEL_DEBUG_LOW);
1071 audio_mem_send_status(AUDIO_ERROR, channel_id, AUDIO_START_STATUS, return_path);
1072 return;
1073 }
1074
1075 /* get MEM session */
1076 p_session = &(p_audio_gbl_var->audio_mem_session[mem_channel_id]);
1077
1078 /* fill parameters */
1079 p_session->session_req.channel_id = channel_id;
1080 p_session->session_req.session_id = session_id;
1081 #if (AUDIO_NEW_FFS_MANAGER)
1082 p_session->session_req.audio_ffs_fd =
1083 ((T_AUDIO_MEM_START *)p_message)->audio_ffs_fd;
1084 #endif
1085 #if (AUDIO_RAM_MANAGER)
1086 p_session->session_req.audio_ram_fd =
1087 ((T_AUDIO_MEM_START *)p_message)->audio_ram_fd;
1088 p_session->session_req.audio_ram_size =
1089 ((T_AUDIO_MEM_START *)p_message)->audio_ram_size;
1090 #endif
1091 p_session->session_req.size =
1092 ((T_AUDIO_MEM_START *)p_message)->size;// temporary RAM buffer size
1093
1094 /* parameters for notification handling */
1095 p_session->session_info.size_left = 0;
1096 p_session->session_info.previous_type = AUDIO_VM_AMR_RXTX_SPEECH_GOOD;
1097 p_session->session_info.stop_req_allowed = TRUE;
1098
1099 /* initialization phase for play sessions */
1100 switch (session_id)
1101 {
1102 case AUDIO_VM_AMR_PLAY_SESSION_ID:
1103 {
1104 UINT8 *play_buffer;// temporary RAM buffer to fill
1105 INT16 size_read;
1106
1107 /* fill all buffers in advance */
1108 while (audio_driver_get_play_buffer(channel_id, &play_buffer) == AUDIO_OK)
1109 {
1110 #if (AUDIO_NEW_FFS_MANAGER)
1111 /* write from FLASH to RAM buffer */
1112 if (p_session->session_req.audio_ffs_fd != NULL)
1113 {
1114 /* copy from Flash "size" bytes into play_buffer */
1115 size_read = ffs_read(p_session->session_req.audio_ffs_fd,
1116 play_buffer,
1117 p_session->session_req.size);
1118
1119 /* wrong read */
1120 if (size_read < EFFS_OK)
1121 {
1122 if ( ffs_close(p_session->session_req.audio_ffs_fd) != EFFS_OK )
1123 audio_mem_error_trace(AUDIO_ENTITY_FILE_NO_CLOSE);
1124 AUDIO_SEND_TRACE("AUDIO MEMORY MANAGER INIT: FFS PLAY READ failed", RV_TRACE_LEVEL_DEBUG_LOW);
1125 audio_mem_send_status(AUDIO_ERROR, channel_id, AUDIO_START_STATUS, return_path);
1126 return;
1127 }
1128 }
1129 #endif
1130 #if (AUDIO_RAM_MANAGER)
1131 /* write from RAM to RAM buffer */
1132 if (p_session->session_req.audio_ram_fd != NULL)
1133 {
1134 /* copy from RAM "size" bytes into play_buffer */
1135 size_read = ram_read(p_session, play_buffer, p_session->session_req.size);
1136 }
1137 #endif
1138
1139 /* convert to MMS */
1140 if (audio_convert_from_mms(play_buffer, size_read,
1141 &(p_session->session_info.previous_type),
1142 &(p_session->session_info.size_left)) != AUDIO_OK)
1143 {
1144 AUDIO_SEND_TRACE("AUDIO MEMORY MANAGER INIT: wrong MMS format", RV_TRACE_LEVEL_DEBUG_LOW);
1145 size_read = 0;// will fill buffer with END_MASK and stop task
1146 }
1147
1148 /* last buffer already, put END_MASK */
1149 if ( ((UINT16)size_read) < p_session->session_req.size )
1150 {
1151 UINT16 i;
1152
1153 if (p_session->session_info.size_left != 0)
1154 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY DOWNLOADER: MMS PLAY file incomplete",
1155 p_session->session_info.size_left, RV_TRACE_LEVEL_DEBUG_LOW);
1156 for (i = size_read; i < p_session->session_req.size; i++)
1157 *(play_buffer + i) = SC_VM_AMR_END_MASK;
1158 }
1159
1160 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY DOWNLOADER: size read", size_read, RV_TRACE_LEVEL_DEBUG_LOW);
1161
1162 audio_driver_play_buffer(channel_id, play_buffer);
1163 }
1164
1165 }// case AUDIO_VM_AMR_PLAY_SESSION_ID
1166 break;
1167 }// switch (session_id)
1168
1169 audio_driver_start_session(channel_id, return_path);
1170
1171 p_session->session_info.state = AUDIO_MEM_WAIT_NOTIFICATION_OR_STOP;
1172 }
1173 break; //case AUDIO_MEM_START_REQ:
1174 case AUDIO_MEM_STOP_REQ:
1175 audio_mem_error_trace(AUDIO_ERROR_STOP_EVENT);
1176 break;
1177 }
1178 } // case AUDIO_MEM_IDLE:
1179 break;
1180 case AUDIO_MEM_WAIT_NOTIFICATION_OR_STOP:
1181 {
1182 /* requester return_path (currently is Riviera Audio) */
1183 return_path.callback_func = NULL;
1184 return_path.addr_id = p_audio_gbl_var->addrId;
1185
1186 switch (p_message->msg_id)
1187 {
1188 case AUDIO_DRIVER_NOTIFICATION_MSG:
1189 {
1190 switch (p_session->session_req.session_id)
1191 {
1192 case AUDIO_VM_AMR_RECORD_SESSION_ID:
1193 {
1194 UINT16 record_buffer_size;
1195
1196 /* default is session_req.size but can be less if we find END_MASK */
1197 record_buffer_size = p_session->session_req.size;
1198
1199 /* convert to MMS, update record_buffer_size if END_MASK is found */
1200 audio_convert_to_mms((UINT8 *)((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer,
1201 &record_buffer_size,
1202 &(p_session->session_info.previous_type),
1203 &(p_session->session_info.size_left));
1204
1205 #if (AUDIO_NEW_FFS_MANAGER)
1206 if (p_session->session_req.audio_ffs_fd != NULL)
1207 {
1208 if ((ffs_write (p_session->session_req.audio_ffs_fd,
1209 (UINT8 *)((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer,
1210 record_buffer_size)) < EFFS_OK)
1211 {
1212 AUDIO_SEND_TRACE("AUDIO MEMORY MANAGER: FFS RECORD WRITE FAILED", RV_TRACE_LEVEL_DEBUG_LOW);
1213 }
1214 }
1215 #endif
1216 #if (AUDIO_RAM_MANAGER)
1217 if (p_session->session_req.audio_ram_fd != NULL)
1218 {
1219 ram_write (p_session,
1220 (UINT8 *)((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer,
1221 record_buffer_size);
1222 }
1223 #endif
1224
1225 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY MANAGER: RAM to MEMORY", record_buffer_size, RV_TRACE_LEVEL_DEBUG_LOW);//DEBUG
1226 }
1227 break;
1228 case AUDIO_VM_AMR_PLAY_SESSION_ID:
1229 {
1230 UINT8 *play_buffer;
1231 INT16 size_read;
1232
1233 /* try to get a buffer */
1234 if (audio_driver_get_play_buffer(channel_id, &play_buffer) == AUDIO_OK)
1235 {
1236 #if (AUDIO_NEW_FFS_MANAGER)
1237 if (p_session->session_req.audio_ffs_fd != NULL)
1238 {
1239 size_read = ffs_read(p_session->session_req.audio_ffs_fd,
1240 play_buffer,
1241 p_session->session_req.size);
1242 /* wrong read */
1243 if (size_read < EFFS_OK)
1244 {
1245 AUDIO_SEND_TRACE("AUDIO MEMORY MANAGER: FFS PLAY READ FAILED", RV_TRACE_LEVEL_DEBUG_LOW);
1246 size_read = 0;// will put END_MASK in whole buffer so stops play
1247 }
1248 }
1249 #endif
1250 #if (AUDIO_RAM_MANAGER)
1251 if (p_session->session_req.audio_ram_fd != NULL)
1252 {
1253 size_read = ram_read(p_session, play_buffer, p_session->session_req.size);
1254 }
1255 #endif
1256
1257 if (audio_convert_from_mms(play_buffer, size_read,
1258 &(p_session->session_info.previous_type),
1259 &(p_session->session_info.size_left)) != AUDIO_OK)
1260 {
1261 AUDIO_SEND_TRACE("AUDIO MEMORY DOWNLOADER: wrong MMS format", RV_TRACE_LEVEL_DEBUG_LOW);
1262 size_read = 0;// will fill buffer with END_MASK
1263 }
1264
1265 /* last buffer, put END_MASK */
1266 if ( ((UINT16)size_read) < p_session->session_req.size )
1267 {
1268 UINT16 i;
1269
1270 if (p_session->session_info.size_left != 0)
1271 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY MANAGER: MMS PLAY file incomplete",
1272 p_session->session_info.size_left, RV_TRACE_LEVEL_DEBUG_LOW);
1273 for (i = size_read; i < p_session->session_req.size; i++)
1274 *(play_buffer + i) = SC_VM_AMR_END_MASK;
1275 }
1276
1277 audio_driver_play_buffer(channel_id, play_buffer);
1278
1279 if (size_read > 0)
1280 {
1281 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY MANAGER: MEMORY to RAM", size_read, RV_TRACE_LEVEL_DEBUG_LOW);//DEBUG
1282 }
1283 else
1284 {
1285 AUDIO_SEND_TRACE("AUDIO MEMORY MANAGER: buffer not used", RV_TRACE_LEVEL_DEBUG_LOW);//DEBUG
1286 }
1287 } // if (audio_driver_get_play_buffer(channel_id, &p_buffer) == AUDIO_OK)
1288 else
1289 AUDIO_SEND_TRACE("AUDIO MEMORY MANAGER: no buffer available", RV_TRACE_LEVEL_DEBUG_LOW);//DEBUG
1290 }
1291 break;
1292 }
1293 }
1294 break;
1295 case AUDIO_DRIVER_LAST_NOTIFICATION_MSG:
1296 {
1297 UINT16 record_buffer_size;
1298
1299 record_buffer_size = p_session->session_req.size;
1300
1301 audio_convert_to_mms((UINT8 *)((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer,
1302 &record_buffer_size,
1303 &(p_session->session_info.previous_type),
1304 &(p_session->session_info.size_left));
1305
1306 #if (AUDIO_NEW_FFS_MANAGER)
1307 if (p_session->session_req.audio_ffs_fd != NULL)
1308 {
1309 if ((ffs_write (p_session->session_req.audio_ffs_fd,
1310 (UINT8 *)((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer,
1311 record_buffer_size)) < EFFS_OK)
1312 {
1313 AUDIO_SEND_TRACE("AUDIO MEMORY MANAGER: FFS RECORD WRITE FAILED", RV_TRACE_LEVEL_DEBUG_LOW);
1314 }
1315 }
1316 #endif
1317 #if (AUDIO_RAM_MANAGER)
1318 if (p_session->session_req.audio_ram_fd != NULL)
1319 {
1320 if ((ram_write (p_session,
1321 (UINT8 *)((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->p_buffer,
1322 record_buffer_size)) < 0)
1323 {
1324 AUDIO_SEND_TRACE("AUDIO MEMORY MANAGER: RAM RECORD WRITE FAILED", RV_TRACE_LEVEL_DEBUG_LOW);
1325 }
1326 }
1327 #endif
1328
1329 /* recorded_size */
1330 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY MANAGER: last RAM to MEMORY", record_buffer_size, RV_TRACE_LEVEL_DEBUG_LOW);
1331 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY MANAGER: size recorded",
1332 ((T_AUDIO_DRIVER_LAST_NOTIFICATION *)p_message)->recorded_size, RV_TRACE_LEVEL_DEBUG_LOW);
1333 p_session->session_info.recorded_size = ((T_AUDIO_DRIVER_LAST_NOTIFICATION *)p_message)->recorded_size;
1334
1335 /* stop must no longer be accepted as it is an automatic stop */
1336 p_session->session_info.stop_req_allowed = FALSE;
1337
1338 /* MEM return_path */
1339 return_path.callback_func = NULL;
1340 return_path.addr_id = p_audio_gbl_var->addrId;
1341
1342 audio_driver_free_session(channel_id, return_path);
1343 }
1344 break;
1345 case AUDIO_DRIVER_STATUS_MSG:
1346 {
1347 /* STOP OK for play */
1348 /* FREE OK for record */
1349 if ( ( (((T_AUDIO_DRIVER_STATUS *)p_message)->status_type == AUDIO_STOP_STATUS) &&
1350 (((T_AUDIO_DRIVER_STATUS *)p_message)->status == AUDIO_OK)) ||
1351 ( (((T_AUDIO_DRIVER_STATUS *)p_message)->status_type == AUDIO_FREE_STATUS) &&
1352 (((T_AUDIO_DRIVER_STATUS *)p_message)->status == AUDIO_OK)) )
1353 {
1354 #if (AUDIO_NEW_FFS_MANAGER)
1355 if (p_session->session_req.audio_ffs_fd != NULL)
1356 {
1357 if ( ffs_close(p_session->session_req.audio_ffs_fd) != EFFS_OK )
1358 {
1359 audio_ffs_error_trace(AUDIO_ENTITY_FILE_NO_CLOSE);
1360 }
1361 AUDIO_SEND_TRACE_PARAM("AUDIO MEMORY MANAGER: close FFS file for mem channel:", mem_channel_id, RV_TRACE_LEVEL_DEBUG_LOW);
1362 }
1363 #endif
1364
1365 if (((T_AUDIO_DRIVER_STATUS *)p_message)->status_type == AUDIO_FREE_STATUS)
1366 audio_mem_send_record_status(channel_id, p_session->session_info.recorded_size, return_path);
1367 else
1368 audio_mem_send_status(AUDIO_OK, channel_id, AUDIO_STOP_STATUS, return_path);
1369
1370 p_session->session_info.state = AUDIO_MEM_IDLE;
1371 }
1372 } //case AUDIO_DRIVER_STATUS_MSG:
1373 break;
1374 case AUDIO_MEM_STOP_REQ:
1375 {
1376 /* check stop req is allowed i.e. no previous stop req, nor automatic stop */
1377 if (p_session->session_info.stop_req_allowed == TRUE)
1378 {
1379 p_session->session_info.stop_req_allowed = FALSE;
1380
1381 audio_driver_stop_session(channel_id);
1382 }
1383 else
1384 {
1385 audio_mem_error_trace(AUDIO_ERROR_STOP_EVENT);
1386 //audio_mem_send_status(AUDIO_ERROR, channel_id, AUDIO_STOP_STATUS, return_path);
1387 }
1388 }
1389 break;
1390 case AUDIO_MEM_START_REQ:
1391 audio_mem_error_trace(AUDIO_ERROR_START_EVENT);
1392 //audio_mem_send_status(AUDIO_ERROR, channel_id, AUDIO_START_STATUS, return_path);
1393 break;
1394 }//switch (p_message->msg_id)
1395 } //case AUDIO_MEM_WAIT_NOTIFICATION_OR_STOP:
1396 break;
1397 } // switch(state)
1398 }
1399
1400 UINT8 audio_mem_message_switch(T_RV_HDR *p_message)
1401 {
1402 UINT8 channel_id;
1403 UINT8 mem_channel_id = 0;
1404
1405 /* MEM START and STOP */
1406 if ((p_message->msg_id == AUDIO_MEM_START_REQ)||
1407 (p_message->msg_id == AUDIO_MEM_STOP_REQ))
1408 return 1;
1409
1410 /* For other messages, we must check channel_id is really handled by MEM
1411 and not by other managers such as streaming or UART */
1412 if (p_message->msg_id == AUDIO_DRIVER_STATUS_MSG)
1413 channel_id = ((T_AUDIO_DRIVER_STATUS *)p_message)->channel_id;
1414
1415 if (p_message->msg_id == AUDIO_DRIVER_NOTIFICATION_MSG)
1416 channel_id = ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->channel_id;
1417
1418 if (p_message->msg_id == AUDIO_DRIVER_LAST_NOTIFICATION_MSG)
1419 channel_id = ((T_AUDIO_DRIVER_NOTIFICATION *)p_message)->channel_id;
1420
1421 /* find active MEM session handling channel_id */
1422 while ( (mem_channel_id < AUDIO_MEM_MAX_CHANNEL) &&
1423 ((p_audio_gbl_var->audio_mem_session[mem_channel_id].session_info.state == AUDIO_MEM_IDLE)||
1424 (p_audio_gbl_var->audio_mem_session[mem_channel_id].session_req.channel_id != channel_id)))
1425 {
1426 mem_channel_id++;
1427 }
1428
1429 if (mem_channel_id == AUDIO_MEM_MAX_CHANNEL)
1430 return 0;
1431 else
1432 return 1;
1433 }
1434 #endif // AUDIO_MEM_MANAGER
1435
1436 #endif /* RVM_AUDIO_MAIN_SWE */
1437