comparison src/cs/services/Audio/audio_mode_load.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 /* File Name: audio_mode_load.c */
4 /* */
5 /* Purpose: This file contains all the functions used for audio mode */
6 /* load services. */
7 /* */
8 /* Version 0.1 */
9 /* */
10 /* Date Modification */
11 /* ------------------------------------------------------------------------*/
12 /* 14 Jan 2002 Create */
13 /* */
14 /* Author Francois Mazard */
15 /* */
16 /* (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved*/
17 /****************************************************************************/
18
19 #include "rv/rv_defined_swe.h"
20
21 #ifdef RVM_AUDIO_MAIN_SWE
22 #ifndef _WINDOWS
23 #include "config/swconfig.cfg"
24 #include "config/sys.cfg"
25 #include "config/chipset.cfg"
26 #endif
27
28 #include "l1_confg.h"
29 #include "rv/rv_general.h"
30 #include "rvm/rvm_gen.h"
31 #include "audio/audio_ffs_i.h"
32 #include "audio/audio_api.h"
33 #include "audio/audio_structs_i.h"
34 #include "audio/audio_error_hdlr_i.h"
35 #include "audio/audio_var_i.h"
36 #include "audio/audio_messages_i.h"
37 #include "audio/audio_macro_i.h"
38 #include "rvf/rvf_target.h"
39 #include "audio/audio_const_i.h"
40
41 /* include the usefull L1 header */
42 #ifdef _WINDOWS
43 #define BOOL_FLAG
44 //#define CHAR_FLAG
45 #endif
46 #include "l1_types.h"
47 #include "l1audio_const.h"
48 #include "l1audio_cust.h"
49 #include "l1audio_defty.h"
50 #include "l1audio_msgty.h"
51 #include "l1audio_signa.h"
52 #if TESTMODE
53 #include "l1tm_defty.h"
54 #endif
55 #if (L1_GTT == 1)
56 #include "l1gtt_const.h"
57 #include "l1gtt_defty.h"
58 #endif
59 #include "l1_const.h"
60 #include "l1_defty.h"
61 #include "l1_msgty.h"
62 #include "l1_signa.h"
63 #ifdef _WINDOWS
64 #define L1_ASYNC_C
65 #endif
66 #include "l1_varex.h"
67
68 #include "ffs/ffs_api.h"
69
70 #ifdef _WINDOWS
71 #include "audio/tests/audio_test.h"
72 #endif
73
74 #include <string.h>
75
76 /* external functions */
77 /* write */
78 extern T_AUDIO_RET audio_mode_voice_path_write (T_AUDIO_VOICE_PATH_SETTING *data,
79 UINT8 *message_to_confirm);
80 extern T_AUDIO_RET audio_mode_microphone_mode_write (INT8 *data);
81 extern T_AUDIO_RET audio_mode_microphone_gain_write (INT8 *data);
82 extern T_AUDIO_RET audio_mode_microphone_extra_gain_write (INT8 *data);
83 extern T_AUDIO_RET audio_mode_microphone_output_bias_write (INT8 *data);
84 extern T_AUDIO_RET audio_mode_speaker_mode_write (INT8 *data);
85 extern T_AUDIO_RET audio_mode_speaker_gain_write (INT8 *data);
86 extern T_AUDIO_RET audio_mode_speaker_filter_write (INT8 *data);
87 extern T_AUDIO_RET audio_mode_speaker_buzzer_write (INT8 *data);
88 extern T_AUDIO_RET audio_mode_sidetone_gain_write (INT8 *data);
89 extern T_AUDIO_RET audio_mode_aec_write (T_AUDIO_AEC_CFG *data);
90 extern T_AUDIO_RET audio_mode_speaker_volume_write (T_AUDIO_SPEAKER_LEVEL *data);
91 extern T_AUDIO_RET audio_mode_speaker_microphone_fir_write (T_AUDIO_FIR_COEF *data_speaker,
92 T_AUDIO_FIR_COEF *data_microphone);
93
94
95 /* Define a macro to simplify the code */
96 #define CHECK_STATUS(function, param) if ( (function(&(param))) == AUDIO_ERROR ) \
97 { \
98 return(AUDIO_ERROR); \
99 } \
100
101 /********************************************************************************/
102 /* */
103 /* Function Name: audio_mode_load_send_status */
104 /* */
105 /* Purpose: This function sends the audio mdoe load status to the entity. */
106 /* */
107 /* Input Parameters: */
108 /* status, */
109 /* return path */
110 /* */
111 /* Output Parameters: */
112 /* None. */
113 /* */
114 /* Note: */
115 /* None. */
116 /* */
117 /* Revision History: */
118 /* None. */
119 /* */
120 /********************************************************************************/
121 void audio_mode_load_send_status (T_AUDIO_RET status, T_RV_RETURN return_path)
122 {
123 void *p_send_message = NULL;
124 T_RVF_MB_STATUS mb_status = RVF_RED;
125
126 while (mb_status == RVF_RED)
127 {
128 /* allocate the message buffer */
129 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
130 sizeof (T_AUDIO_LOAD_DONE),
131 (T_RVF_BUFFER **) (&p_send_message));
132
133 /* If insufficient resources, then report a memory error and abort. */
134 /* and wait until more ressource is given */
135 if (mb_status == RVF_RED)
136 {
137 audio_mode_error_trace(AUDIO_ENTITY_NO_MEMORY);
138 rvf_delay(RVF_MS_TO_TICKS(1000));
139 }
140 }
141 /*fill the header of the message */
142 ((T_AUDIO_LOAD_DONE *)(p_send_message))->os_hdr.msg_id =
143 AUDIO_MODE_LOAD_DONE;
144
145 /* fill the status parameters */
146 ((T_AUDIO_LOAD_DONE *)(p_send_message))->status = status;
147
148 if (return_path.callback_func == NULL)
149 {
150 /* send the message to the entity */
151 rvf_send_msg (return_path.addr_id,
152 p_send_message);
153 }
154 else
155 {
156 /* call the callback function */
157 (*return_path.callback_func)((void *)(p_send_message));
158 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
159 }
160 }
161 /********************************************************************************/
162 /* */
163 /* Function Name: audio_mode_set */
164 /* */
165 /* Purpose: This function set the audio mode structure to the mobile. */
166 /* */
167 /* Input Parameters: */
168 /* Audio mode structure. */
169 /* */
170 /* Output Parameters: */
171 /* Status. */
172 /* */
173 /* Note: */
174 /* None. */
175 /* */
176 /* Revision History: */
177 /* None. */
178 /* */
179 /********************************************************************************/
180 T_AUDIO_RET audio_mode_set(T_AUDIO_MODE *p_audio_mode, UINT8 *message_to_confirm)
181 {
182 T_AUDIO_FIR_COEF *data_speaker = NULL, *data_microphone = NULL;
183
184 *message_to_confirm = 0;
185
186
187 /* Audio voice path */
188 if (audio_mode_voice_path_write (&p_audio_mode->audio_path_setting, message_to_confirm) == AUDIO_ERROR)
189 {
190 return(AUDIO_ERROR);
191 }
192
193 /* CR33671 : wrong sequence of message for disabling AQI in TTY calls */
194 /* Audio speaker microphone loop setting */
195 CHECK_STATUS(audio_mode_aec_write, p_audio_mode->audio_microphone_speaker_loop_setting.aec)
196 /* confirm the AEC message */
197 *message_to_confirm += 1;
198
199
200 /* Audio microphone mode */
201 CHECK_STATUS(audio_mode_microphone_mode_write, p_audio_mode->audio_microphone_setting.mode)
202
203 /* Audio micropohne setting */
204 switch (p_audio_mode->audio_microphone_setting.mode)
205 {
206 case AUDIO_MICROPHONE_HANDHELD:
207 {
208 CHECK_STATUS(audio_mode_microphone_gain_write, p_audio_mode->audio_microphone_setting.setting.handheld.gain)
209 data_microphone = &(p_audio_mode->audio_microphone_setting.setting.handheld.fir);
210 CHECK_STATUS(audio_mode_microphone_output_bias_write, p_audio_mode->audio_microphone_setting.setting.handheld.output_bias)
211 break;
212 }
213 case AUDIO_MICROPHONE_HANDFREE:
214 {
215 CHECK_STATUS(audio_mode_microphone_extra_gain_write, p_audio_mode->audio_microphone_setting.setting.handfree.extra_gain)
216 data_microphone = &(p_audio_mode->audio_microphone_setting.setting.handfree.fir);
217 CHECK_STATUS(audio_mode_microphone_gain_write, p_audio_mode->audio_microphone_setting.setting.handfree.gain)
218 CHECK_STATUS(audio_mode_microphone_output_bias_write, p_audio_mode->audio_microphone_setting.setting.handfree.output_bias)
219 break;
220 }
221 case AUDIO_MICROPHONE_HEADSET:
222 {
223 CHECK_STATUS(audio_mode_microphone_gain_write, p_audio_mode->audio_microphone_setting.setting.headset.gain)
224 data_microphone = &(p_audio_mode->audio_microphone_setting.setting.headset.fir);
225 CHECK_STATUS(audio_mode_microphone_output_bias_write, p_audio_mode->audio_microphone_setting.setting.headset.output_bias)
226 }
227 }
228
229 /* Audio speaker mode */
230 CHECK_STATUS(audio_mode_speaker_mode_write, p_audio_mode->audio_speaker_setting.mode)
231
232 /* Audio speaker setting */
233 switch(p_audio_mode->audio_speaker_setting.mode)
234 {
235 case AUDIO_SPEAKER_HANDHELD:
236 {
237 CHECK_STATUS(audio_mode_speaker_filter_write, p_audio_mode->audio_speaker_setting.setting.handheld.audio_filter)
238 data_speaker = &(p_audio_mode->audio_speaker_setting.setting.handheld.fir);
239 CHECK_STATUS(audio_mode_speaker_gain_write, p_audio_mode->audio_speaker_setting.setting.handheld.gain)
240 break;
241 }
242 case AUDIO_SPEAKER_HANDFREE:
243 {
244 CHECK_STATUS(audio_mode_speaker_filter_write, p_audio_mode->audio_speaker_setting.setting.handfree.audio_filter)
245 data_speaker = &(p_audio_mode->audio_speaker_setting.setting.handfree.fir);
246 CHECK_STATUS(audio_mode_speaker_gain_write, p_audio_mode->audio_speaker_setting.setting.handfree.gain)
247 break;
248 }
249 case AUDIO_SPEAKER_HEADSET:
250 {
251 CHECK_STATUS(audio_mode_speaker_filter_write, p_audio_mode->audio_speaker_setting.setting.headset.audio_filter)
252 data_speaker = &(p_audio_mode->audio_speaker_setting.setting.headset.fir);
253 CHECK_STATUS(audio_mode_speaker_gain_write, p_audio_mode->audio_speaker_setting.setting.headset.gain)
254 break;
255 }
256 case AUDIO_SPEAKER_BUZZER:
257 {
258 CHECK_STATUS(audio_mode_speaker_buzzer_write, p_audio_mode->audio_speaker_setting.setting.buzzer.activate)
259 break;
260 }
261 case AUDIO_SPEAKER_HANDHELD_HANDFREE:
262 {
263 CHECK_STATUS(audio_mode_speaker_filter_write, p_audio_mode->audio_speaker_setting.setting.handheld_handfree.audio_filter)
264 data_speaker = &(p_audio_mode->audio_speaker_setting.setting.handheld_handfree.fir);
265 CHECK_STATUS(audio_mode_speaker_gain_write, p_audio_mode->audio_speaker_setting.setting.handheld_handfree.gain)
266 break;
267 }
268 }
269
270 /* Set the speaker and microphone FIR */
271 if ( (audio_mode_speaker_microphone_fir_write(data_speaker, data_microphone))
272 == AUDIO_ERROR )
273 {
274 return(AUDIO_ERROR);
275 }
276 /* confirm the FIR message */
277 *message_to_confirm += 1;
278
279 CHECK_STATUS(audio_mode_sidetone_gain_write, p_audio_mode->audio_microphone_speaker_loop_setting.sidetone_gain)
280
281
282 return(AUDIO_OK);
283 }
284
285 /********************************************************************************/
286 /* */
287 /* Function Name: audio_volume_set */
288 /* */
289 /* Purpose: This function sets the audio volume. */
290 /* */
291 /* Input Parameters: */
292 /* Audio volume structure. */
293 /* */
294 /* Output Parameters: */
295 /* Status. */
296 /* */
297 /* Note: */
298 /* None. */
299 /* */
300 /* Revision History: */
301 /* None. */
302 /* */
303 /********************************************************************************/
304 T_AUDIO_RET audio_volume_set(T_AUDIO_SPEAKER_LEVEL *p_audio_volume)
305 {
306 CHECK_STATUS(audio_mode_speaker_volume_write, *p_audio_volume)
307
308 return(AUDIO_OK);
309 }
310
311 /********************************************************************************/
312 /* */
313 /* Function Name: audio_mode_load_manager */
314 /* */
315 /* Purpose: This function manages the audio mode load services. */
316 /* */
317 /* Input Parameters: */
318 /* Audio message. */
319 /* */
320 /* Output Parameters: */
321 /* None. */
322 /* */
323 /* Note: */
324 /* None. */
325 /* */
326 /* Revision History: */
327 /* None. */
328 /* */
329 /********************************************************************************/
330 void audio_mode_load_manager (T_RV_HDR *p_message)
331 {
332 T_AUDIO_SPEAKER_LEVEL audio_volume;
333 T_RVF_MB_STATUS mb_status;
334 UINT8 message_to_confirm;
335 #ifdef _WINDOWS
336 INT8 *p_read, *p_write;
337 UINT8 i;
338 #endif
339
340 switch (p_audio_gbl_var->audio_mode_var.audio_mode_load_var.state)
341 {
342 case AUDIO_MODE_LOAD_IDLE:
343 {
344 /* allocate the buffer for the current Audio mode */
345 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
346 sizeof (T_AUDIO_MODE),
347 (T_RVF_BUFFER **) (&(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode)));
348 /* If insufficient resources, then report a memory error and abort. */
349 if (mb_status == RVF_RED)
350 {
351 AUDIO_SEND_TRACE("AUDIO MODE LOAD: not enough memory to allocate the audio mode buffer", RV_TRACE_LEVEL_ERROR);
352 audio_mode_load_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path);
353 return;
354 }
355
356 #ifdef _WINDOWS
357 #if ((AUDIO_REGR == SW_COMPILED) || (AUDIO_MISC == SW_COMPILED))
358 p_read = (INT8 *)(&(p_audio_test->audio_mode_1));
359 p_write = (INT8 *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode);
360
361 for (i=0; i<sizeof(T_AUDIO_MODE); i++)
362 {
363 *p_write++ = *p_read++;
364 }
365 #endif
366 #else
367 /* Load the audio mode structure from the FFS */
368
369 if ( ffs_read (((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd,
370 (void *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode),
371 sizeof(T_AUDIO_MODE)) < EFFS_OK )
372 {
373 AUDIO_SEND_TRACE("AUDIO MODE LOAD: impossible to load the current audio mode", RV_TRACE_LEVEL_ERROR);
374
375 /* Close the files */
376 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd);
377 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_volume_ffs_fd);
378
379 /* free the audio mode buffer */
380 rvf_free_buf((T_RVF_BUFFER *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode));
381
382 /* send the status message */
383 audio_mode_load_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path);
384 return;
385 }
386 #endif
387
388 /* Set the audio mode structure */
389 if ( (audio_mode_set((p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode),
390 &message_to_confirm)) == AUDIO_ERROR)
391 {
392 AUDIO_SEND_TRACE("AUDIO MODE LOAD: error in the the audio mode set function", RV_TRACE_LEVEL_ERROR);
393 /* free the audio mode buffer */
394 rvf_free_buf((T_RVF_BUFFER *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode));
395
396 #ifndef _WINDOWS
397 /* Close the files */
398 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd);
399 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_volume_ffs_fd);
400 #endif
401
402 /* send the status message */
403 audio_mode_load_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path);
404 return;
405 }
406
407 /* Calculate the number of confirmation message to receive */
408 p_audio_gbl_var->audio_mode_var.audio_mode_load_var.number_of_message = message_to_confirm;
409
410 #ifndef _WINDOWS
411 /* Close the file */
412 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_ffs_fd);
413 #endif
414
415 #ifndef _WINDOWS
416 /* Load the audio speaker volume structure from the FFS */
417 if ( (ffs_read (((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_volume_ffs_fd,
418 (void *)(&audio_volume),
419 sizeof(T_AUDIO_SPEAKER_LEVEL))) < EFFS_OK )
420 {
421 AUDIO_SEND_TRACE("AUDIO MODE LOAD: impossible to load the current speaker volume", RV_TRACE_LEVEL_ERROR);
422
423 /* Close the file */
424 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_volume_ffs_fd);
425
426 /* send the status message */
427 audio_mode_load_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path);
428 return;
429 }
430 #else
431 #if ((AUDIO_REGR == SW_COMPILED) || (AUDIO_MISC == SW_COMPILED))
432 audio_volume.audio_speaker_level = p_audio_test->speaker_volume_1.audio_speaker_level;
433 #endif
434 #endif
435
436 /* Fill the audio volume structure */
437 if ( (audio_volume_set(&audio_volume)) == AUDIO_ERROR)
438 {
439 AUDIO_SEND_TRACE("AUDIO MODE LOAD: error in the the audio speaker volume set function", RV_TRACE_LEVEL_ERROR);
440 #ifndef _WINDOWS
441 /* Close the file */
442 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_volume_ffs_fd);
443 #endif
444
445 /* send the status message */
446 audio_mode_load_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path);
447 return;
448 }
449 #ifndef _WINDOWS
450 /* Close the file */
451 ffs_close(((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_volume_ffs_fd);
452 #endif
453
454 /* Save the return path */
455 p_audio_gbl_var->audio_mode_var.audio_mode_load_var.return_path.callback_func =
456 ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path.callback_func;
457 p_audio_gbl_var->audio_mode_var.audio_mode_load_var.return_path.addr_id =
458 ((T_AUDIO_MODE_LOAD_REQ *)p_message)->return_path.addr_id;
459
460 /* Save the name of the volume path name */
461 strcpy(p_audio_gbl_var->audio_mode_var.audio_volume_var.audio_volume_path_name,
462 ((T_AUDIO_MODE_LOAD_REQ *)p_message)->audio_volume_path_name);
463
464 /* change the state */
465 p_audio_gbl_var->audio_mode_var.audio_mode_load_var.state =
466 AUDIO_MODE_LOAD_WAIT_MESSAGE_CONF;
467 break;
468 }
469 case AUDIO_MODE_LOAD_WAIT_MESSAGE_CONF:
470 {
471 p_audio_gbl_var->audio_mode_var.audio_mode_load_var.number_of_message--;
472
473 if (p_audio_gbl_var->audio_mode_var.audio_mode_load_var.number_of_message == 0)
474 {
475 /* free the audio mode buffer */
476 rvf_free_buf((T_RVF_BUFFER *)(p_audio_gbl_var->audio_mode_var.audio_mode_load_var.p_audio_mode));
477
478 /* send the status message */
479 audio_mode_load_send_status (AUDIO_OK,
480 p_audio_gbl_var->audio_mode_var.audio_mode_load_var.return_path);
481
482 /* change the state */
483 p_audio_gbl_var->audio_mode_var.audio_mode_load_var.state =
484 AUDIO_MODE_LOAD_IDLE;
485 }
486 break;
487 }
488 }
489 }
490 #endif /* RVM_AUDIO_MAIN_SWE */