comparison services/etm/etm_audio.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /********************************************************************************
2 * Enhanced TestMode (ETM)
3 * @file etm_audio.c (Support for AUDIO commands)
4 *
5 * @author Kim T. Peteren (ktp@ti.com)
6 * @version 0.8
7 *
8
9 *
10 * History:
11 *
12 * Date Modification
13 * ------------------------------------
14 * 16/06/2003 Creation
15 * 30/06/2003 Small cleanup in func. etm_audio_write, etm_audio_saveload and
16 * etm_aud_wait_for_aud_event is updated and renamed
17 * 12/08/2003 The func. etm_audio_write has been updated regarding the AEC struct.
18 * 14/08/2003 The func. etm_audio_read has been updated regarding the AEC struct.
19 * 17/03/2004 Modified the event handling, events revceived from the Audio SWE.
20 * Integrated event callback function, etm_audio_callback().
21 *
22 * (C) Copyright 2003 by Texas Instruments Incorporated, All Rights Reserved
23 *********************************************************************************/
24
25
26 #include "etm/etm.h"
27 #include "etm/etm_api.h"
28 #include "etm/etm_trace.h"
29 #include "etm/etm_env.h" // Need because use of T_ETM_ENV_CTRL_BLK
30 #include "etm/etm_audio_err.h" // Privat Audio error codes for PC and Target
31
32 #include "etm/etm_trace.h"
33 #include "audio/audio_api.h"
34
35 #include "rv/rv_general.h"
36 #include "spi/spi_drv.h" // used for codec read/write
37
38 #include "memif/mem.h"
39 #include <string.h>
40
41
42 /******************************************************************************
43 * Globals
44 *****************************************************************************/
45
46 // Version of the ETM AUDIO module
47 //const uint16 etm_audio_revision = (1<<12) | (0x1);
48
49 extern T_ETM_ENV_CTRL_BLK *etm_env_ctrl_blk;
50
51 static int etm_audio_event_status = 0;
52
53
54 /******************************************************************************
55 * Internal prototypes
56 *****************************************************************************/
57
58 int etm_audio(uint8 *indata, int insize);
59 T_RV_HDR *etm_audio_wait_for_event(UINT16 msg_id_expected);
60 T_ETM_PKT *etm_audio_setup(uint8 fid, uint8 cfg_data);
61 void etm_audio_callback(void *event_from_audio);
62
63
64 /******************************************************************************
65 * Register the Audio Module to the ETM database
66 *****************************************************************************/
67
68 int etm_audio_init(void)
69 {
70 int result;
71
72 result = etm_register("AUDIO", ETM_AUDIO, 0, 0, etm_audio);
73 return result;
74 }
75
76
77 /******************************************************************************
78 * Audio Full Access Read Function
79 *****************************************************************************/
80
81 int etm_audio_read(T_ETM_PKT *pkt, uint8 *buf)
82 {
83 int result, size = 0, size_tmp, i;
84 uint8 param;
85 T_AUDIO_FULL_ACCESS_READ audio;
86 T_AUDIO_AEC_CFG *aec_parameter = NULL;
87 void *parameter = NULL;
88
89 param = *buf;
90 if ((result = etm_pkt_put8(pkt, param)) < 0)
91 return result;
92
93 tr_etm(TgTrAudio, "ETM AUDIO: _audio_read: param(%d)", param);
94
95 audio.variable_indentifier = param;
96 audio.data = (T_AUDIO_FULL_ACCESS_READ *) &pkt->data[2]; //data[0] = fid
97 //data[1] = parameter/identifier
98
99 if ((result = audio_full_access_read(&audio)) != AUDIO_OK){
100 tr_etm(TgTrAudio, "ETM AUDIO: _audio_read: ERROR(%d)", result);
101 if (result == AUDIO_ERROR)
102 return ETM_INVAL; // Invalid audio parameter
103 else
104 return ETM_AUDIO_FATAL;
105 }
106
107 switch (param) {
108 case AUDIO_PATH_USED:
109 size = sizeof(T_AUDIO_VOICE_PATH_SETTING);
110 break;
111 case AUDIO_MICROPHONE_MODE:
112 case AUDIO_MICROPHONE_GAIN:
113 case AUDIO_MICROPHONE_EXTRA_GAIN:
114 case AUDIO_MICROPHONE_OUTPUT_BIAS:
115 case AUDIO_MICROPHONE_SPEAKER_LOOP_SIDETONE:
116 size = sizeof(INT8);
117 break;
118 case AUDIO_MICROPHONE_SPEAKER_LOOP_AEC:
119 size = sizeof(T_AUDIO_AEC_CFG);
120
121 aec_parameter = (T_AUDIO_AEC_CFG *) &pkt->data[2];
122
123 etm_pkt_put16(pkt, aec_parameter->aec_enable); // 1
124 #if (L1_NEW_AEC)
125 etm_pkt_put16(pkt, aec_parameter->continuous_filtering); // 2
126 etm_pkt_put16(pkt, aec_parameter->granularity_attenuation); // 3
127 etm_pkt_put16(pkt, aec_parameter->smoothing_coefficient); // 4
128 etm_pkt_put16(pkt, aec_parameter->max_echo_suppression_level); // 5
129 etm_pkt_put16(pkt, aec_parameter->vad_factor); // 6
130 etm_pkt_put16(pkt, aec_parameter->absolute_threshold); // 7
131 etm_pkt_put16(pkt, aec_parameter->factor_asd_filtering); // 8
132 etm_pkt_put16(pkt, aec_parameter->factor_asd_muting); // 9
133 etm_pkt_put16(pkt, aec_parameter->aec_visibility); //10
134 #else
135 etm_pkt_put16(pkt, aec_parameter->aec_mode); // 2
136 etm_pkt_put16(pkt, aec_parameter->echo_suppression_level); // 3
137 #endif // end of (L1_NEW_AEC)
138 etm_pkt_put16(pkt, aec_parameter->noise_suppression_enable); // 4 or 11
139 etm_pkt_put16(pkt, aec_parameter->noise_suppression_level); // 5 or 12
140 break;
141 case AUDIO_MICROPHONE_FIR:
142 case AUDIO_SPEAKER_FIR:
143 size = sizeof(T_AUDIO_FIR_COEF);
144 break;
145 case AUDIO_SPEAKER_MODE:
146 case AUDIO_SPEAKER_GAIN:
147 case AUDIO_SPEAKER_FILTER:
148 case AUDIO_SPEAKER_BUZZER_STATE:
149 size = sizeof(INT8);
150 break;
151 case AUDIO_SPEAKER_VOLUME_LEVEL:
152 size = sizeof(T_AUDIO_SPEAKER_LEVEL);
153 break;
154 default:
155 size = ETM_INVAL;
156 }
157
158 pkt->size += size;
159 return ETM_OK;
160 }
161
162
163 /******************************************************************************
164 * Audio Full Access Write Function
165 *****************************************************************************/
166
167 int etm_audio_write(T_ETM_PKT *pkt, uint8 *buf)
168 {
169 T_RV_HDR *msg = NULL;
170 T_RV_RETURN return_path;
171 T_AUDIO_FULL_ACCESS_WRITE audio;
172 T_AUDIO_AEC_CFG *aec_parameter = NULL;
173 void *parameter = NULL;
174 int result = ETM_OK, i;
175 uint8 param;
176
177 param = *buf++;
178 if ((result = etm_pkt_put8(pkt, param)) < ETM_OK) {
179 return result;
180 }
181
182 tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: param(%d)", param);
183
184 return_path.addr_id = NULL; //etm_env_ctrl_blk->addr_id;
185 return_path.callback_func = etm_audio_callback;
186
187 audio.variable_indentifier = param;
188 audio.data = buf;
189
190 switch (param) {
191 case AUDIO_MICROPHONE_SPEAKER_LOOP_AEC:
192 tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: AUDIO_MICROPHONE_SPEAKER_LOOP_AEC"); // RemoveMe
193 aec_parameter = etm_malloc (sizeof(T_AUDIO_AEC_CFG));
194
195 aec_parameter->aec_enable = etm_get16(buf); buf += 2;// 1
196 #if (L1_NEW_AEC)
197 if (etm_get16(buf)) // 2
198 aec_parameter->continuous_filtering = TRUE;
199 else
200 aec_parameter->continuous_filtering = FALSE;
201 buf += 2;
202 aec_parameter->granularity_attenuation = etm_get16(buf); buf += 2;// 3
203 aec_parameter->smoothing_coefficient = etm_get16(buf); buf += 2;// 4
204 aec_parameter->max_echo_suppression_level = etm_get16(buf); buf += 2;// 5
205 aec_parameter->vad_factor = etm_get16(buf); buf += 2;// 6
206 aec_parameter->absolute_threshold = etm_get16(buf); buf += 2;// 7
207 aec_parameter->factor_asd_filtering = etm_get16(buf); buf += 2;// 8
208 aec_parameter->factor_asd_muting = etm_get16(buf); buf += 2;// 9
209 aec_parameter->aec_visibility = etm_get16(buf); buf += 2;// 10
210 #else
211 aec_parameter->aec_mode = etm_get16(buf); buf += 2;// 2
212 aec_parameter->echo_suppression_level = etm_get16(buf); buf += 2;// 3
213 #endif // end of (L1_NEW_AEC)
214 #if (L1_ANR == 0)
215 aec_parameter->noise_suppression_enable = etm_get16(buf); buf += 2;// 4 or 11
216 aec_parameter->noise_suppression_level = etm_get16(buf); // 5 or 12
217 #endif // end of (L1_ANR)
218 audio.data = aec_parameter;
219 break;
220 case AUDIO_MICROPHONE_FIR:
221 case AUDIO_SPEAKER_FIR:
222 tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: AUDIO_MICROPHONE/SPEAKER_FIR [%d]",
223 sizeof(T_AUDIO_FIR_COEF)/2); // RemoveMe
224
225 parameter = etm_malloc (sizeof(T_AUDIO_FIR_COEF));
226 // Write coeffient values
227 for (i=0; i <= (sizeof(T_AUDIO_FIR_COEF)/2); i++) {
228 ((T_AUDIO_FIR_COEF *) parameter)->coefficient[i] = etm_get16(buf); buf += 2;
229 }
230 audio.data = parameter;
231 break;
232 }
233
234 if ((result = audio_full_access_write(&audio, return_path)) != AUDIO_OK) {
235 tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: ERROR(%d)", result);
236 if (result == AUDIO_ERROR)
237 result = ETM_INVAL; // Invalid audio parameter
238 else
239 result = ETM_AUDIO_FATAL;
240 }
241
242 // Wait for recv. of event: AUDIO_FULL_ACCESS_WRITE_DONE
243 rvf_wait(0xffff, 100); // Timeout 100 ticks
244 tr_etm(TgTrAudio, "ETM AUDIO: _audio_write: STATUS(%d)", etm_audio_event_status);
245
246 if (parameter != NULL) {
247 etm_free(parameter);
248 parameter = NULL;
249 }
250
251 if (aec_parameter != NULL) {
252 etm_free(aec_parameter);
253 aec_parameter = NULL;
254 }
255
256 if (etm_audio_event_status != 0) {
257 etm_audio_event_status = 0;
258 result = ETM_AUDIO_FATAL;
259 }
260
261 return result;
262 }
263
264 /******************************************************************************
265 * Audio Save and Load cfg file Function
266 *****************************************************************************/
267
268 int etm_audio_saveload(T_ETM_PKT *pkt, uint8 saveload, void *buf, int size)
269 {
270 T_RV_HDR *msg;
271 T_AUDIO_MODE_SAVE audio_s;
272 T_AUDIO_MODE_LOAD audio_l;
273 T_RV_RETURN return_path;
274 int result = ETM_OK;
275 int error, event;
276
277 return_path.addr_id = etm_env_ctrl_blk->addr_id;
278 return_path.callback_func = NULL;
279
280 switch(saveload) {
281 case 'S':
282 memcpy(audio_s.audio_mode_filename, buf, size);
283 result = audio_mode_save(&audio_s, return_path);
284 break;
285 case 'L':
286 memcpy(audio_l.audio_mode_filename, buf, size);
287 result = audio_mode_load(&audio_l, return_path);
288 break;
289 default:
290 tr_etm(TgTrAudio, "ETM AUDIO: _audio_saveload: FAILED");
291 break;
292 }
293
294 rvf_wait(0xffff, 100); // Timeout 100 ticks
295 tr_etm(TgTrAudio, "ETM AUDIO: _audio_saveload: STATUS(%d)", etm_audio_event_status);
296
297 if (etm_audio_event_status != 0) {
298 etm_audio_event_status = 0;
299 return ETM_AUDIO_FATAL;
300 }
301
302 if (result != AUDIO_OK)
303 return ETM_AUDIO_FATAL;
304
305 return result;
306 }
307
308
309 /******************************************************************************
310 * ETM AUDIO callback functio
311 *****************************************************************************/
312
313 void etm_audio_callback(void *event_from_audio)
314 {
315 tr_etm(TgTrEtmLow,"ETM: AUDIO: _audio_callback: recv. event (0x%x)",
316 ((T_RV_HDR *) event_from_audio)->msg_id);
317
318 switch (((T_RV_HDR *) event_from_audio)->msg_id)
319 {
320 case AUDIO_FULL_ACCESS_WRITE_DONE:
321 tr_etm(TgTrAudio, "ETM AUDIO: _audio_callback: recv. event AUDIO_FULL_ACCESS_WRITE_DONE");
322 etm_audio_event_status = ((T_AUDIO_FULL_ACCESS_WRITE_DONE *) event_from_audio)->status;
323 break;
324 case AUDIO_MODE_SAVE_DONE:
325 tr_etm(TgTrAudio, "ETM AUDIO: _audio_callback: recv. event AUDIO_MODE_SAVE_DONE");
326 etm_audio_event_status = ((T_AUDIO_SAVE_DONE *) event_from_audio)->status;
327 break;
328 case AUDIO_MODE_LOAD_DONE:
329 tr_etm(TgTrAudio, "ETM AUDIO: _audio_callback: recv. event AUDIO_MODE_LOAD_DONE");
330 etm_audio_event_status = ((T_AUDIO_LOAD_DONE *) event_from_audio)->status;
331 break;
332 }
333
334 if (event_from_audio != NULL) {
335 // etm_free(event_from_audio);
336 event_from_audio = NULL;
337 }
338 }
339
340
341 /******************************************************************************
342 * ETM AUDIO Moudle - Main Task
343 *****************************************************************************/
344
345 // AUDIO packet structure for audio read/write and codec read/write:
346 // |fid(8)|param(8)|--data(W)--| and for audio save/load |fid|--data(W)--|
347
348 int etm_audio(uint8 *indata, int insize)
349 {
350 int error = ETM_OK;
351 uint8 fid;
352 T_ETM_PKT *pkt = NULL;
353
354 fid = *indata++;
355
356 tr_etm(TgTrAudio, "ETM AUDIO: _audio: fid(%c) param(%d) recv. size(%d)",
357 fid, *indata, insize);
358
359 /* Create TestMode return Packet */
360 if ((pkt = (T_ETM_PKT *) etm_malloc(sizeof(T_ETM_PKT))) == NULL) {
361 return ETM_NOMEM;
362 }
363
364 // Init. of return packet
365 pkt->mid = ETM_AUDIO;
366 pkt->status = ETM_OK;
367 pkt->size = 0;
368 pkt->index = 0;
369 etm_pkt_put8(pkt, fid);
370
371 if (error == ETM_OK) {
372 switch (fid) {
373 case 'R':
374 error = etm_audio_read(pkt, indata);
375 break;
376 case 'W':
377 error = etm_audio_write(pkt, indata);
378 break;
379 case 'S':
380 case 'L':
381 error = etm_audio_saveload(pkt, fid, indata, insize);
382 break;
383 default:
384 tr_etm(TgTrAudio, "ETM AUDIO: _audio: fid(%c) - ERROR ", fid);
385 error = ETM_NOSYS;
386 break;
387 }
388 }
389
390 if (error < 0) {
391 tr_etm(TgTrAudio,"ETM AUDIO: _audio: ERROR(%d)", error);
392 pkt->status = -error;
393
394 }
395
396 etm_pkt_send(pkt);
397 etm_free(pkt);
398
399 return ETM_OK;
400 }
401