comparison chipsetsw/services/Audio/audio_mode_save.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /****************************************************************************/
2 /* */
3 /* File Name: audio_mode_save.c */
4 /* */
5 /* Purpose: This file contains all the functions used for audio mode */
6 /* save 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 #ifdef _WINDOWS
69 #include "audio/tests/audio_test.h"
70 #endif
71
72 /* external functions */
73 /* read */
74 extern T_AUDIO_RET audio_mode_voice_path_read (T_AUDIO_VOICE_PATH_SETTING *data);
75 extern T_AUDIO_RET audio_mode_microphone_mode_read (INT8 *data);
76 extern T_AUDIO_RET audio_mode_microphone_gain_read (INT8 *data);
77 extern T_AUDIO_RET audio_mode_microphone_extra_gain_read (INT8 *data);
78 extern T_AUDIO_RET audio_mode_microphone_output_bias_read (INT8 *data);
79 extern T_AUDIO_RET audio_mode_microphone_fir_read (T_AUDIO_FIR_COEF *data);
80 extern T_AUDIO_RET audio_mode_speaker_mode_read (INT8 *data);
81 extern T_AUDIO_RET audio_mode_speaker_gain_read (INT8 *data);
82 extern T_AUDIO_RET audio_mode_speaker_filter_read (INT8 *data);
83 extern T_AUDIO_RET audio_mode_speaker_fir_read (T_AUDIO_FIR_COEF *data);
84 extern T_AUDIO_RET audio_mode_speaker_buzzer_read (INT8 *data);
85 extern T_AUDIO_RET audio_mode_sidetone_gain_read (INT8 *data);
86 extern T_AUDIO_RET audio_mode_aec_read (T_AUDIO_AEC_CFG *data);
87 extern T_AUDIO_RET audio_mode_speaker_volume_read (T_AUDIO_SPEAKER_LEVEL *data);
88
89 /* Define a macro to simplify the code */
90 #define CHECK_STATUS(function, param) if ( (function(&(param))) == AUDIO_ERROR ) \
91 { \
92 return(AUDIO_ERROR); \
93 } \
94
95 /********************************************************************************/
96 /* */
97 /* Function Name: audio_mode_save_send_status */
98 /* */
99 /* Purpose: This function sends the audio mdoe save status to the entity. */
100 /* */
101 /* Input Parameters: */
102 /* status, */
103 /* return path */
104 /* */
105 /* Output Parameters: */
106 /* None. */
107 /* */
108 /* Note: */
109 /* None. */
110 /* */
111 /* Revision History: */
112 /* None. */
113 /* */
114 /********************************************************************************/
115 void audio_mode_save_send_status (T_AUDIO_RET status, T_RV_RETURN return_path)
116 {
117 void *p_send_message = NULL;
118 T_RVF_MB_STATUS mb_status = RVF_RED;
119
120 while (mb_status == RVF_RED)
121 {
122 /* allocate the message buffer */
123 mb_status = rvf_get_buf (p_audio_gbl_var->mb_external,
124 sizeof(T_AUDIO_SAVE_DONE),
125 (T_RVF_BUFFER **) (&p_send_message));
126
127 /* If insufficient resources, then report a memory error and abort. */
128 /* and wait until more ressource is given */
129 if (mb_status == RVF_RED)
130 {
131 audio_mode_error_trace(AUDIO_ENTITY_NO_MEMORY);
132 rvf_delay(RVF_MS_TO_TICKS(1000));
133 }
134 }
135 /*fill the header of the message */
136 ((T_AUDIO_SAVE_DONE *)(p_send_message))->os_hdr.msg_id =
137 AUDIO_MODE_SAVE_DONE;
138
139 /* fill the status parameters */
140 ((T_AUDIO_SAVE_DONE *)(p_send_message))->status = status;
141
142 if (return_path.callback_func == NULL)
143 {
144 /* send the message to the entity */
145 rvf_send_msg (return_path.addr_id,
146 p_send_message);
147 }
148 else
149 {
150 /* call the callback function */
151 (*return_path.callback_func)((void *)(p_send_message));
152 rvf_free_buf((T_RVF_BUFFER *)p_send_message);
153 }
154 }
155
156 /********************************************************************************/
157 /* */
158 /* Function Name: audio_mode_get */
159 /* */
160 /* Purpose: This function fill the audio mode structure. */
161 /* */
162 /* Input Parameters: */
163 /* Audio mode structure. */
164 /* */
165 /* Output Parameters: */
166 /* Status. */
167 /* */
168 /* Note: */
169 /* None. */
170 /* */
171 /* Revision History: */
172 /* None. */
173 /* */
174 /********************************************************************************/
175 T_AUDIO_RET audio_mode_get(T_AUDIO_MODE *p_audio_mode)
176 {
177 /* Audio voice path */
178 CHECK_STATUS(audio_mode_voice_path_read, p_audio_mode->audio_path_setting)
179
180 /* Audio microphone mode */
181 CHECK_STATUS(audio_mode_microphone_mode_read, p_audio_mode->audio_microphone_setting.mode)
182
183 /* Audio microphone setting */
184 switch (p_audio_mode->audio_microphone_setting.mode)
185 {
186 case AUDIO_MICROPHONE_HANDHELD:
187 {
188 CHECK_STATUS(audio_mode_microphone_gain_read, p_audio_mode->audio_microphone_setting.setting.handheld.gain)
189 CHECK_STATUS(audio_mode_microphone_fir_read, p_audio_mode->audio_microphone_setting.setting.handheld.fir)
190 CHECK_STATUS(audio_mode_microphone_output_bias_read, p_audio_mode->audio_microphone_setting.setting.handheld.output_bias)
191 break;
192 }
193 case AUDIO_MICROPHONE_HANDFREE:
194 {
195 CHECK_STATUS(audio_mode_microphone_extra_gain_read, p_audio_mode->audio_microphone_setting.setting.handfree.extra_gain)
196 CHECK_STATUS(audio_mode_microphone_fir_read, p_audio_mode->audio_microphone_setting.setting.handfree.fir)
197 CHECK_STATUS(audio_mode_microphone_gain_read, p_audio_mode->audio_microphone_setting.setting.handfree.gain)
198 CHECK_STATUS(audio_mode_microphone_output_bias_read, p_audio_mode->audio_microphone_setting.setting.handfree.output_bias)
199 break;
200 }
201 case AUDIO_MICROPHONE_HEADSET:
202 {
203 CHECK_STATUS(audio_mode_microphone_gain_read, p_audio_mode->audio_microphone_setting.setting.headset.gain)
204 CHECK_STATUS(audio_mode_microphone_fir_read, p_audio_mode->audio_microphone_setting.setting.headset.fir)
205 CHECK_STATUS(audio_mode_microphone_output_bias_read, p_audio_mode->audio_microphone_setting.setting.headset.output_bias)
206 }
207 }
208
209 /* Audio speaker mode */
210 CHECK_STATUS(audio_mode_speaker_mode_read, p_audio_mode->audio_speaker_setting.mode)
211
212 /* Audio speaker setting */
213 switch(p_audio_mode->audio_speaker_setting.mode)
214 {
215 case AUDIO_SPEAKER_HANDHELD:
216 {
217 CHECK_STATUS(audio_mode_speaker_filter_read, p_audio_mode->audio_speaker_setting.setting.handheld.audio_filter)
218 CHECK_STATUS(audio_mode_speaker_fir_read, p_audio_mode->audio_speaker_setting.setting.handheld.fir)
219 CHECK_STATUS(audio_mode_speaker_gain_read, p_audio_mode->audio_speaker_setting.setting.handheld.gain)
220 break;
221 }
222 case AUDIO_SPEAKER_HANDFREE:
223 {
224 CHECK_STATUS(audio_mode_speaker_filter_read, p_audio_mode->audio_speaker_setting.setting.handfree.audio_filter)
225 CHECK_STATUS(audio_mode_speaker_fir_read, p_audio_mode->audio_speaker_setting.setting.handfree.fir)
226 CHECK_STATUS(audio_mode_speaker_gain_read, p_audio_mode->audio_speaker_setting.setting.handfree.gain)
227 break;
228 }
229 case AUDIO_SPEAKER_HEADSET:
230 {
231 CHECK_STATUS(audio_mode_speaker_filter_read, p_audio_mode->audio_speaker_setting.setting.headset.audio_filter)
232 CHECK_STATUS(audio_mode_speaker_fir_read, p_audio_mode->audio_speaker_setting.setting.headset.fir)
233 CHECK_STATUS(audio_mode_speaker_gain_read, p_audio_mode->audio_speaker_setting.setting.headset.gain)
234 break;
235 }
236 case AUDIO_SPEAKER_BUZZER:
237 {
238 CHECK_STATUS(audio_mode_speaker_buzzer_read, p_audio_mode->audio_speaker_setting.setting.buzzer.activate)
239 break;
240 }
241 case AUDIO_SPEAKER_HANDHELD_HANDFREE:
242 {
243 CHECK_STATUS(audio_mode_speaker_filter_read, p_audio_mode->audio_speaker_setting.setting.handheld_handfree.audio_filter)
244 CHECK_STATUS(audio_mode_speaker_fir_read, p_audio_mode->audio_speaker_setting.setting.handheld_handfree.fir)
245 CHECK_STATUS(audio_mode_speaker_gain_read, p_audio_mode->audio_speaker_setting.setting.handheld_handfree.gain)
246 break;
247 }
248 }
249
250 /* Audio spkear microphone loop setting */
251 CHECK_STATUS(audio_mode_aec_read, p_audio_mode->audio_microphone_speaker_loop_setting.aec)
252 CHECK_STATUS(audio_mode_sidetone_gain_read, p_audio_mode->audio_microphone_speaker_loop_setting.sidetone_gain)
253
254 return(AUDIO_OK);
255 }
256
257 /********************************************************************************/
258 /* */
259 /* Function Name: audio_volume_get */
260 /* */
261 /* Purpose: This function fill the audio volume structure. */
262 /* */
263 /* Input Parameters: */
264 /* Audio volume structure. */
265 /* */
266 /* Output Parameters: */
267 /* Status. */
268 /* */
269 /* Note: */
270 /* None. */
271 /* */
272 /* Revision History: */
273 /* None. */
274 /* */
275 /********************************************************************************/
276 T_AUDIO_RET audio_volume_get(T_AUDIO_SPEAKER_LEVEL *p_audio_volume)
277 {
278 CHECK_STATUS(audio_mode_speaker_volume_read, *p_audio_volume)
279
280 return(AUDIO_OK);
281 }
282
283 /********************************************************************************/
284 /* */
285 /* Function Name: audio_mode_save_manager */
286 /* */
287 /* Purpose: This function manage the audio mode save services. */
288 /* */
289 /* Input Parameters: */
290 /* Audio message. */
291 /* */
292 /* Output Parameters: */
293 /* None. */
294 /* */
295 /* Note: */
296 /* None. */
297 /* */
298 /* Revision History: */
299 /* None. */
300 /* */
301 /********************************************************************************/
302 void audio_mode_save_manager (T_RV_HDR *p_message)
303 {
304 T_AUDIO_MODE *p_audio_mode;
305 T_AUDIO_SPEAKER_LEVEL audio_volume;
306 T_RVF_MB_STATUS mb_status;
307
308 #ifdef _WINDOWS
309 INT8 *p_read, *p_write;
310 UINT8 i;
311 #endif
312 /* allocate the buffer for the current Audio mode */
313 mb_status = rvf_get_buf (p_audio_gbl_var->mb_internal,
314 sizeof (T_AUDIO_MODE),
315 (T_RVF_BUFFER **) (&p_audio_mode));
316 /* If insufficient resources, then report a memory error and abort. */
317 if (mb_status == RVF_RED)
318 {
319 AUDIO_SEND_TRACE("AUDIO MODE SAVE: not enough memory to allocate the audio mode buffer", RV_TRACE_LEVEL_ERROR);
320 audio_mode_save_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_SAVE_REQ *)p_message)->return_path);
321 return;
322 }
323
324 /* Fill the audio mode structure */
325 if ( (audio_mode_get(p_audio_mode)) == AUDIO_ERROR)
326 {
327 AUDIO_SEND_TRACE("AUDIO MODE SAVE: error in the the audio mode get function", RV_TRACE_LEVEL_ERROR);
328 /* free the audio mode buffer */
329 rvf_free_buf((T_RVF_BUFFER *)p_audio_mode);
330
331 #ifndef _WINDOWS
332 /* Close the files */
333 ffs_close(((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_ffs_fd);
334 ffs_close(((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_volume_ffs_fd);
335 #endif
336
337 /* send the status message */
338 audio_mode_save_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_SAVE_REQ *)p_message)->return_path);
339 return;
340 }
341
342 #ifndef _WINDOWS
343 /* Save the audio mode structure to the FFS */
344 if ( (ffs_write (((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_ffs_fd,
345 p_audio_mode,
346 sizeof(T_AUDIO_MODE))) < EFFS_OK )
347 {
348 AUDIO_SEND_TRACE("AUDIO MODE SAVE: impossible to save the current audio mode", RV_TRACE_LEVEL_ERROR);
349
350 /* free the audio mode buffer */
351 rvf_free_buf((T_RVF_BUFFER *)p_audio_mode);
352
353 /* Close the files */
354 ffs_close(((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_ffs_fd);
355 ffs_close(((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_volume_ffs_fd);
356
357 /* send the status message */
358 audio_mode_save_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_SAVE_REQ *)p_message)->return_path);
359 return;
360 }
361
362 /* Close the file */
363 ffs_close(((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_ffs_fd);
364 #else
365 #if ((AUDIO_REGR == SW_COMPILED) || (AUDIO_MISC == SW_COMPILED))
366 p_read = (INT8 *)(p_audio_mode);
367 p_write = (INT8 *)(&(p_audio_test->audio_mode_2));
368
369 for (i=0; i<sizeof(T_AUDIO_MODE); i++)
370 {
371 *p_write++ = *p_read++;
372 }
373 #endif
374 #endif
375
376 /* free the audio mode buffer */
377 rvf_free_buf((T_RVF_BUFFER *)p_audio_mode);
378
379 /* Fill the audio volume structure */
380 if ( (audio_volume_get(&audio_volume)) == AUDIO_ERROR)
381 {
382 AUDIO_SEND_TRACE("AUDIO MODE SAVE: error in the the audio speaker volume get function", RV_TRACE_LEVEL_ERROR);
383 #ifndef _WINDOWS
384 /* Close the file */
385 ffs_close(((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_volume_ffs_fd);
386 #endif
387
388 /* send the status message */
389 audio_mode_save_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_SAVE_REQ *)p_message)->return_path);
390 return;
391 }
392
393 #ifndef _WINDOWS
394 /* Save the audio speaker volume structure to the FFS */
395 if ( (ffs_write (((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_volume_ffs_fd,
396 &audio_volume,
397 sizeof(T_AUDIO_SPEAKER_LEVEL))) < EFFS_OK )
398 {
399 AUDIO_SEND_TRACE("AUDIO MODE SAVE: impossible to save the current speaker volume", RV_TRACE_LEVEL_ERROR);
400
401 /* Close the files */
402 ffs_close(((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_volume_ffs_fd);
403
404 /* send the status message */
405 audio_mode_save_send_status (AUDIO_ERROR, ((T_AUDIO_MODE_SAVE_REQ *)p_message)->return_path);
406 return;
407 }
408
409 /* Close the file */
410 ffs_close(((T_AUDIO_MODE_SAVE_REQ *)p_message)->audio_volume_ffs_fd);
411 #else
412 #if ((AUDIO_REGR == SW_COMPILED) || (AUDIO_MISC == SW_COMPILED))
413 p_audio_test->speaker_volume_2.audio_speaker_level = audio_volume.audio_speaker_level;
414 #endif
415 #endif
416
417 /* send the status message */
418 audio_mode_save_send_status (AUDIO_OK, ((T_AUDIO_MODE_SAVE_REQ *)p_message)->return_path);
419 }
420 #endif /* RVM_AUDIO_MAIN_SWE */