yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2012 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * |
| 38 | * Filename: |
| 39 | * --------- |
| 40 | * tone.c |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * MTK6208 |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * Tone Interface |
| 49 | * |
| 50 | * Author: |
| 51 | * ------- |
| 52 | * ------- |
| 53 | * |
| 54 | *============================================================================== |
| 55 | * HISTORY |
| 56 | * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 57 | *------------------------------------------------------------------------------ |
| 58 | * removed! |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * |
| 62 | * removed! |
| 63 | * removed! |
| 64 | * removed! |
| 65 | * |
| 66 | * removed! |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * removed! |
| 70 | * removed! |
| 71 | * removed! |
| 72 | * |
| 73 | * removed! |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * |
| 77 | * removed! |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * |
| 81 | * removed! |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * |
| 85 | * removed! |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * |
| 89 | * removed! |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * |
| 93 | * removed! |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * |
| 97 | * removed! |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * |
| 101 | * removed! |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * |
| 105 | * removed! |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * |
| 109 | * removed! |
| 110 | * removed! |
| 111 | * |
| 112 | * removed! |
| 113 | * removed! |
| 114 | * removed! |
| 115 | * |
| 116 | * removed! |
| 117 | * removed! |
| 118 | * removed! |
| 119 | * removed! |
| 120 | * removed! |
| 121 | * removed! |
| 122 | * removed! |
| 123 | * removed! |
| 124 | * removed! |
| 125 | * removed! |
| 126 | * removed! |
| 127 | * removed! |
| 128 | * removed! |
| 129 | * removed! |
| 130 | * removed! |
| 131 | * removed! |
| 132 | * removed! |
| 133 | * removed! |
| 134 | * removed! |
| 135 | * removed! |
| 136 | * removed! |
| 137 | * removed! |
| 138 | * removed! |
| 139 | * removed! |
| 140 | * removed! |
| 141 | * removed! |
| 142 | * removed! |
| 143 | * removed! |
| 144 | * removed! |
| 145 | * removed! |
| 146 | * removed! |
| 147 | * removed! |
| 148 | * removed! |
| 149 | * removed! |
| 150 | * removed! |
| 151 | * removed! |
| 152 | * removed! |
| 153 | * removed! |
| 154 | * removed! |
| 155 | * removed! |
| 156 | * removed! |
| 157 | * removed! |
| 158 | * removed! |
| 159 | * |
| 160 | * removed! |
| 161 | * removed! |
| 162 | * removed! |
| 163 | * |
| 164 | * removed! |
| 165 | * removed! |
| 166 | * removed! |
| 167 | * |
| 168 | * removed! |
| 169 | * removed! |
| 170 | * removed! |
| 171 | * |
| 172 | *------------------------------------------------------------------------------ |
| 173 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 174 | *============================================================================== |
| 175 | *******************************************************************************/ |
| 176 | |
| 177 | #include "kal_public_api.h" |
| 178 | #include "kal_general_types.h" |
| 179 | #include "dcl.h" |
| 180 | #include "reg_base.h" |
| 181 | #include "sync_data.h" |
| 182 | |
| 183 | #include "l1aud_common_def.h" |
| 184 | #include "l1audio.h" |
| 185 | #include "media.h" |
| 186 | #include "afe.h" |
| 187 | #include "am.h" |
| 188 | #include "speech_def.h" |
| 189 | // #include "audio_def.h" |
| 190 | #include "afe_def.h" |
| 191 | |
| 192 | |
| 193 | |
| 194 | #define KT_INIT_AMP 0x3FFF |
| 195 | #define TONE_INIT_AMP 0x1FFF |
| 196 | |
| 197 | static struct |
| 198 | { |
| 199 | const L1SP_Tones *tonelist; |
| 200 | const L1SP_QTMF *curr_qtmf; |
| 201 | void (*handler)(void); |
| 202 | uint32 gpt; |
| 203 | uint16 aud_id; |
| 204 | uint16 amp; |
| 205 | bool bQTMF; |
| 206 | bool isRun; |
| 207 | } tone; |
| 208 | |
| 209 | static struct |
| 210 | { |
| 211 | uint32 gpt; |
| 212 | uint16 aud_id; |
| 213 | int8 lock; |
| 214 | uint8 volume1; |
| 215 | int8 digital_gain_index; |
| 216 | bool isRun; |
| 217 | } keytone; |
| 218 | |
| 219 | |
| 220 | #define DSP_QTMF_FREQ(f1,f2,f3,f4) { DSP_TONE_F2A = (f1); \ |
| 221 | DSP_TONE_F2B = (f2); \ |
| 222 | DSP_TONE_F1A = (tone.bQTMF)?(f3):0; \ |
| 223 | DSP_TONE_F1B = (tone.bQTMF)?(f4):0; \ |
| 224 | Data_Sync_Barrier(); } |
| 225 | |
| 226 | #define DSP_KT_FREQ(f1,f2) { DSP_TONE_F2A = (f1); \ |
| 227 | DSP_TONE_F2B = (f2); \ |
| 228 | Data_Sync_Barrier(); } |
| 229 | |
| 230 | /* When Audio Ramp Down Enable, MCU waits until Audio RampDown of DSP. If the time of DSP's RampDown exceeds this value, the beginning part of Tone maybe be cut */ |
| 231 | #define SW_WAIT_AUDIO_RAMPDOWN (6) |
| 232 | |
| 233 | /* ------------------------------------------------------------------------------ */ |
| 234 | /* Functions for Playing Comfort Tones */ |
| 235 | /* ------------------------------------------------------------------------------ */ |
| 236 | static void tonePlayOff( void *data ); |
| 237 | |
| 238 | void toneStop_FlushQueue( void *data ) |
| 239 | { |
| 240 | if(AM_IsToneOn()) |
| 241 | { |
| 242 | SGPT_CTRL_START_T start; |
| 243 | start.u2Tick = 1; |
| 244 | start.pfCallback = toneStop_FlushQueue; |
| 245 | start.vPara = data; |
| 246 | DclSGPT_Control( tone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 247 | } else { |
| 248 | L1Audio_ClearFlag( tone.aud_id ); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | static void toneStop( void *data ) |
| 253 | { |
| 254 | uint16 tone_ctrl; |
| 255 | SGPT_CTRL_START_T start; |
| 256 | |
| 257 | if( !L1Audio_CheckFlag( tone.aud_id ) ) |
| 258 | return; |
| 259 | tone_ctrl = (DSP_TONE_CTRL2 << 8) + DSP_TONE_CTRL1; |
| 260 | switch( tone_ctrl ) { |
| 261 | case 0: |
| 262 | if (tone.isRun) { |
| 263 | tone.isRun = false; |
| 264 | tone.bQTMF = false; |
| 265 | AM_ToneOff(); |
| 266 | DP_KT_ATT = 0; |
| 267 | Data_Sync_Barrier(); |
| 268 | L1Audio_SetEvent( tone.aud_id, 0 ); |
| 269 | |
| 270 | // unapply hardware mute during tone playback |
| 271 | *AFE_AMCU_CON1 &= ~0x30; |
| 272 | Data_Sync_Barrier(); |
| 273 | |
| 274 | #if defined(__BT_SUPPORT__) |
| 275 | if( L1SP_GetSpeechMode() == SPH_MODE_LINEIN_VIA_BT_CORDLESS ) |
| 276 | { |
| 277 | *DP_AUDIO_PAR = (*DP_AUDIO_PAR & 0xFF) | 0x1000; // set back to cordless mode |
| 278 | Data_Sync_Barrier(); |
| 279 | } |
| 280 | #endif |
| 281 | } |
| 282 | start.u2Tick = 1; |
| 283 | start.pfCallback = toneStop_FlushQueue; |
| 284 | start.vPara = data; |
| 285 | DclSGPT_Control( tone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 286 | break; |
| 287 | case 0x202: |
| 288 | DSP_TONE_CTRL1 = 4; |
| 289 | DSP_TONE_CTRL2 = 4; |
| 290 | Data_Sync_Barrier(); |
| 291 | default: |
| 292 | start.u2Tick = 1; |
| 293 | start.pfCallback = toneStop; |
| 294 | start.vPara = data; |
| 295 | DclSGPT_Control( tone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | static void tonePlayOn( void *data ) |
| 301 | { |
| 302 | uint16 dura; |
| 303 | |
| 304 | if( tone.bQTMF ) |
| 305 | tone.curr_qtmf = (L1SP_QTMF *)tone.tonelist + (uint32)data; |
| 306 | else |
| 307 | tone.curr_qtmf = (L1SP_QTMF *)(tone.tonelist + (uint32)data); |
| 308 | |
| 309 | // apply hardware mute during tone playback |
| 310 | *AFE_AMCU_CON1 |= 0x0C; |
| 311 | Data_Sync_Barrier(); |
| 312 | DSP_QTMF_FREQ( tone.curr_qtmf->freq1, tone.curr_qtmf->freq2, |
| 313 | tone.curr_qtmf->freq3, tone.curr_qtmf->freq4 ); |
| 314 | DSP_TONE_CTRL1 = 1; |
| 315 | DSP_TONE_CTRL2 = 1; |
| 316 | Data_Sync_Barrier(); |
| 317 | |
| 318 | if( ( dura = tone.curr_qtmf->on_duration / 10 ) > 0 ) { |
| 319 | SGPT_CTRL_START_T start; |
| 320 | start.u2Tick = dura; |
| 321 | start.pfCallback = tonePlayOff; |
| 322 | start.vPara = 0; |
| 323 | DclSGPT_Control( tone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | static void toneMute( void *data ) |
| 328 | { |
| 329 | int32 dura = (int32)data; |
| 330 | uint16 tone_ctrl; |
| 331 | SGPT_CTRL_START_T start; |
| 332 | |
| 333 | tone_ctrl = (DSP_TONE_CTRL2 << 8) + DSP_TONE_CTRL1; |
| 334 | switch( tone_ctrl ) { |
| 335 | case 0: |
| 336 | start.u2Tick = dura+1; |
| 337 | start.pfCallback = tonePlayOn; |
| 338 | start.vPara = (void *)(kal_uint32)tone.curr_qtmf->next_tone; |
| 339 | DclSGPT_Control( tone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 340 | break; |
| 341 | case 0x202: |
| 342 | DSP_TONE_CTRL1 = 4; |
| 343 | DSP_TONE_CTRL2 = 4; |
| 344 | Data_Sync_Barrier(); |
| 345 | default: |
| 346 | start.u2Tick = 1; |
| 347 | start.pfCallback = toneMute; |
| 348 | start.vPara = (void*)((dura>0)?dura-1:0); |
| 349 | DclSGPT_Control( tone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 350 | break; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | static void tonePlayOff( void *data ) |
| 355 | { |
| 356 | uint16 dura = tone.curr_qtmf->off_duration / 10; |
| 357 | if( dura == 0 ) |
| 358 | toneStop( 0 ); |
| 359 | else |
| 360 | toneMute( (void*)(kal_uint32)dura ); |
| 361 | } |
| 362 | |
| 363 | static void toneHandler( void *data ) /* This function works in L1Audio Task */ |
| 364 | { |
| 365 | (void)data; |
| 366 | if( tone.handler != 0 ) |
| 367 | tone.handler(); |
| 368 | } |
| 369 | |
| 370 | void toneInit( uint16 aud_id ) |
| 371 | { |
| 372 | tone.aud_id = aud_id; |
| 373 | tone.handler = 0; |
| 374 | L1Audio_SetEventHandler( aud_id, toneHandler ); |
| 375 | tone.gpt = DclSGPT_Open( DCL_GPT_CB ,0 ); |
| 376 | DSP_TONE_CTRL1 = 0; |
| 377 | |
| 378 | tone.amp = TONE_INIT_AMP; |
| 379 | tone.bQTMF = false; |
| 380 | |
| 381 | DP_KT_ATT = 0; |
| 382 | Data_Sync_Barrier(); |
| 383 | #ifdef ANALOG_AFE_PATH_EXIST |
| 384 | AFE_TurnOnFIR( L1SP_TONE ); |
| 385 | #endif // ANALOG_AFE_PATH_EXIST |
| 386 | } |
| 387 | |
| 388 | /* ------------------------------------------------------------------------------ */ |
| 389 | /* Tone Interface */ |
| 390 | /* ------------------------------------------------------------------------------ */ |
| 391 | void TONE_SetOutputDevice( uint8 device ) |
| 392 | { |
| 393 | #if 0 // def ANALOG_AFE_PATH_EXIST |
| 394 | /* under construction !*/ |
| 395 | #endif |
| 396 | } |
| 397 | |
| 398 | void TONE_SetOutputVolume( uint8 volume1, int8 digital_gain_index ) |
| 399 | { |
| 400 | #if 0 // def ANALOG_AFE_PATH_EXIST |
| 401 | /* under construction !*/ |
| 402 | #endif |
| 403 | } |
| 404 | |
| 405 | /***************************************************************************** |
| 406 | * FUNCTION |
| 407 | * TONE_PlayQTMF |
| 408 | * DESCRIPTION |
| 409 | * This function is used to play comfort tones. |
| 410 | * Totally 4 frequencies can be generated |
| 411 | * |
| 412 | * PARAMETERS |
| 413 | * tonelist - QTMF list |
| 414 | * RETURNS |
| 415 | * None. |
| 416 | * GLOBALS AFFECTED |
| 417 | * None |
| 418 | *****************************************************************************/ |
| 419 | void TONE_PlayQTMF( const L1SP_QTMF *tonelist ) |
| 420 | { |
| 421 | if( L1Audio_CheckFlag( tone.aud_id ) ) |
| 422 | return; |
| 423 | tone.bQTMF = true; |
| 424 | TONE_Play((const L1SP_Tones *)tonelist); |
| 425 | } |
| 426 | |
| 427 | /***************************************************************************** |
| 428 | * FUNCTION |
| 429 | * TONE_Play |
| 430 | * DESCRIPTION |
| 431 | * This function is used to play comfort tones. |
| 432 | * |
| 433 | * PARAMETERS |
| 434 | * tonelist - Tone list |
| 435 | * RETURNS |
| 436 | * None. |
| 437 | * GLOBALS AFFECTED |
| 438 | * None |
| 439 | *****************************************************************************/ |
| 440 | void TONE_Play( const L1SP_Tones *tonelist ) |
| 441 | { |
| 442 | // FIXME: |
| 443 | return; |
| 444 | |
| 445 | if(AM_IsSpeechOn()){/* Prevent Speech from being muted, becuase Tone/KT with volume = 0 results in DigitalGain = 0 */ |
| 446 | /* |
| 447 | uint8 volume; |
| 448 | |
| 449 | #ifdef ANALOG_AFE_PATH_EXIST |
| 450 | int8 digital_gain_index; |
| 451 | AFE_GetOutputVolume(L1SP_TONE, &volume, &digital_gain_index); |
| 452 | #else |
| 453 | AFE_DigitalOnly_GetOutputVolume(L1SP_TONE, &volume); |
| 454 | #endif // ANALOG_AFE_PATH_EXIST |
| 455 | if(0 == volume) |
| 456 | return; |
| 457 | */ |
| 458 | |
| 459 | } |
| 460 | |
| 461 | if( L1Audio_CheckFlag( tone.aud_id ) ) |
| 462 | return; |
| 463 | if( L1Audio_CheckFlag( keytone.aud_id ) ) { |
| 464 | KT_Stop(); |
| 465 | while( L1Audio_CheckFlag( keytone.aud_id ) ) |
| 466 | kal_sleep_task( AUD_1TICK(1) ); |
| 467 | } |
| 468 | |
| 469 | if( AM_IsSpeechOn() ) |
| 470 | { |
| 471 | DP_KT_ATT = 0x4000; |
| 472 | Data_Sync_Barrier(); |
| 473 | } |
| 474 | |
| 475 | #if defined(__BT_SUPPORT__) |
| 476 | if( L1SP_IsBluetoothOn() ){ |
| 477 | if( L1SP_GetSpeechMode() == SPH_MODE_LINEIN_VIA_BT_CORDLESS ) |
| 478 | *DP_AUDIO_PAR = (*DP_AUDIO_PAR & 0xFF) | 0x2000; // set to earphone mode |
| 479 | DSP_TONE_AMP1 = (TONE_INIT_AMP >> 2); /* degrade bluetooth tone volume by 12dB */ |
| 480 | DSP_TONE_AMP2 = (TONE_INIT_AMP >> 2); /* degrade bluetooth tone volume by 12dB */ |
| 481 | }else |
| 482 | #endif |
| 483 | { |
| 484 | DSP_TONE_AMP1 = tone.amp; |
| 485 | DSP_TONE_AMP2 = tone.amp; |
| 486 | } |
| 487 | Data_Sync_Barrier(); |
| 488 | L1Audio_SetFlag( tone.aud_id ); |
| 489 | tone.tonelist = tonelist; |
| 490 | AM_ToneOn(); |
| 491 | tonePlayOn( 0 ); |
| 492 | tone.isRun = true; |
| 493 | } |
| 494 | |
| 495 | /***************************************************************************** |
| 496 | * FUNCTION |
| 497 | * TONE_Stop |
| 498 | * DESCRIPTION |
| 499 | * This function is used to stop playing comfort tones. |
| 500 | * |
| 501 | * PARAMETERS |
| 502 | * None |
| 503 | * RETURNS |
| 504 | * None |
| 505 | * GLOBALS AFFECTED |
| 506 | * None |
| 507 | *****************************************************************************/ |
| 508 | void TONE_Stop( void ) |
| 509 | { |
| 510 | DclSGPT_Control(tone.gpt ,SGPT_CMD_STOP, 0); |
| 511 | toneStop( 0 ); |
| 512 | } |
| 513 | |
| 514 | void TONE_StopAndWait( void ) |
| 515 | { |
| 516 | int I; |
| 517 | |
| 518 | AM_FlushQFunction(); |
| 519 | TONE_Stop(); |
| 520 | |
| 521 | for( I = 0; ; I++ ) { |
| 522 | if ( !AM_IsToneOn() ) |
| 523 | break; |
| 524 | |
| 525 | ASSERT_REBOOT(I < 20); |
| 526 | kal_sleep_task( AUD_1TICK(2) ); |
| 527 | } |
| 528 | kal_sleep_task( AUD_1TICK(2) );//wait AFE also updated |
| 529 | } |
| 530 | |
| 531 | void TONE_SetAmplitude( int16 amp ) |
| 532 | { |
| 533 | tone.amp = (uint16)amp; |
| 534 | } |
| 535 | |
| 536 | void TONE_SetFIR( bool enable ) |
| 537 | { |
| 538 | if( enable ) { |
| 539 | #if 0 // def ANALOG_AFE_PATH_EXIST |
| 540 | /* under construction !*/ |
| 541 | #endif // ANALOG_AFE_PATH_EXIST |
| 542 | }else{ |
| 543 | #if 0 // def ANALOG_AFE_PATH_EXIST |
| 544 | /* under construction !*/ |
| 545 | #endif |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | void TONE_SetHandler( void (*handler)(void) ) |
| 550 | { |
| 551 | tone.handler = handler; |
| 552 | } |
| 553 | |
| 554 | /* ------------------------------------------------------------------------------ */ |
| 555 | /* Keytone Interface */ |
| 556 | /* ------------------------------------------------------------------------------ */ |
| 557 | void ktStop_FlushQueue( void *data ) |
| 558 | { |
| 559 | if(AM_IsKeyToneOn()) |
| 560 | { |
| 561 | SGPT_CTRL_START_T start; |
| 562 | start.u2Tick = 1; |
| 563 | start.pfCallback = ktStop_FlushQueue; |
| 564 | start.vPara = data; |
| 565 | DclSGPT_Control( keytone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 566 | } else { |
| 567 | L1Audio_ClearFlag( keytone.aud_id ); |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | static void ktStop( void *data ) |
| 572 | { |
| 573 | SGPT_CTRL_START_T start; |
| 574 | if( !L1Audio_CheckFlag( keytone.aud_id ) ) |
| 575 | return; |
| 576 | switch( DSP_TONE_CTRL2 ) { |
| 577 | case 0: |
| 578 | if (keytone.isRun) { |
| 579 | keytone.isRun = false; |
| 580 | AM_KeyToneOff(); |
| 581 | } |
| 582 | start.u2Tick = 1; |
| 583 | start.pfCallback = ktStop_FlushQueue; |
| 584 | start.vPara = data; |
| 585 | DclSGPT_Control( keytone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 586 | //L1Audio_ClearFlag( keytone.aud_id ); |
| 587 | break; |
| 588 | case 2: |
| 589 | DSP_TONE_CTRL2 = 4; |
| 590 | Data_Sync_Barrier(); |
| 591 | default: |
| 592 | start.u2Tick = 1; |
| 593 | start.pfCallback = ktStop; |
| 594 | start.vPara = data; |
| 595 | DclSGPT_Control( keytone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 596 | break; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | void ktInit( uint16 aud_id ) |
| 601 | { |
| 602 | keytone.aud_id = aud_id; |
| 603 | keytone.lock = 0; |
| 604 | keytone.volume1 = 160; |
| 605 | keytone.digital_gain_index = 0; |
| 606 | keytone.gpt = DclSGPT_Open(DCL_GPT_CB,0); |
| 607 | DSP_TONE_CTRL2 = 0; |
| 608 | DSP_TONE_AMP2 = KT_INIT_AMP; |
| 609 | Data_Sync_Barrier(); |
| 610 | #if 0 // def ANALOG_AFE_PATH_EXIST |
| 611 | /* under construction !*/ |
| 612 | #endif |
| 613 | } |
| 614 | |
| 615 | void ktLock( void ) |
| 616 | { |
| 617 | |
| 618 | ASSERT( keytone.lock < 8 ); |
| 619 | |
| 620 | keytone.lock++; |
| 621 | |
| 622 | } |
| 623 | |
| 624 | void ktUnlock( void ) |
| 625 | { |
| 626 | |
| 627 | ASSERT( keytone.lock > 0 ); |
| 628 | |
| 629 | keytone.lock--; |
| 630 | |
| 631 | } |
| 632 | |
| 633 | void KT_SetOutputDevice( uint8 device ) |
| 634 | { |
| 635 | if( L1Audio_CheckFlag( keytone.aud_id ) ) { |
| 636 | KT_Stop(); |
| 637 | while( L1Audio_CheckFlag( keytone.aud_id ) ) |
| 638 | kal_sleep_task( AUD_1TICK(1) ); |
| 639 | } |
| 640 | #if 0 // def ANALOG_AFE_PATH_EXIST |
| 641 | /* under construction !*/ |
| 642 | #endif |
| 643 | } |
| 644 | |
| 645 | void KT_SetOutputVolume( uint8 volume1, int8 digital_gain_index ) |
| 646 | { |
| 647 | keytone.volume1 = volume1; |
| 648 | keytone.digital_gain_index = digital_gain_index; |
| 649 | } |
| 650 | |
| 651 | /***************************************************************************** |
| 652 | * FUNCTION |
| 653 | * KT_Play |
| 654 | * DESCRIPTION |
| 655 | * This function is used to play keytone. |
| 656 | * |
| 657 | * PARAMETERS |
| 658 | * freq1 - The first frequency |
| 659 | * freq2 - The second frequency |
| 660 | * duration - Duration of the tone |
| 661 | * RETURNS |
| 662 | * None. |
| 663 | * GLOBALS AFFECTED |
| 664 | * None |
| 665 | *****************************************************************************/ |
| 666 | |
| 667 | void KT_Play( uint16 freq1, uint16 freq2, uint16 duration ) |
| 668 | { |
| 669 | // FIXME: |
| 670 | return; |
| 671 | // endif |
| 672 | |
| 673 | if( keytone.lock > 0 || keytone.volume1 == 0 ) |
| 674 | return; |
| 675 | |
| 676 | if( L1Audio_CheckFlag( keytone.aud_id ) ) |
| 677 | return; |
| 678 | |
| 679 | #if !defined(__DISABLE_SKIP_KEYTONE_DURING_TONE_PLAY__) |
| 680 | if( L1Audio_CheckFlag( tone.aud_id ) ) |
| 681 | return; |
| 682 | #endif |
| 683 | |
| 684 | if( L1Audio_CheckFlag( tone.aud_id ) ) { |
| 685 | TONE_Stop(); |
| 686 | while( L1Audio_CheckFlag( tone.aud_id ) ) |
| 687 | kal_sleep_task( AUD_1TICK(1) ); |
| 688 | } |
| 689 | |
| 690 | /* When Tone/KT with volume = 0 lets AFE set DigitalGain = 0, it causes the side effect. At the same time, Speech is muted, becuase digital gain is 0 */ |
| 691 | if(AM_IsSpeechOn()){ |
| 692 | /* |
| 693 | uint8 volume; |
| 694 | #ifdef ANALOG_AFE_PATH_EXIST |
| 695 | int8 digital_gain_index; |
| 696 | AFE_GetOutputVolume(L1SP_TONE, &volume, &digital_gain_index); |
| 697 | #else |
| 698 | AFE_DigitalOnly_GetOutputVolume(L1SP_TONE, &volume); |
| 699 | #endif // ANALOG_AFE_PATH_EXIST |
| 700 | if(0 == volume) |
| 701 | return; |
| 702 | */ |
| 703 | } |
| 704 | |
| 705 | L1Audio_SetFlag( keytone.aud_id ); |
| 706 | |
| 707 | /* keytone in speech mode, need special care */ |
| 708 | #if defined(__BT_SUPPORT__) |
| 709 | if( L1SP_IsBluetoothOn() ) { |
| 710 | DSP_TONE_AMP2 = KT_INIT_AMP >> 2; /* degrade bluetooth keytone volume by 12dB */ |
| 711 | Data_Sync_Barrier(); |
| 712 | #if 0 |
| 713 | /* under construction !*/ |
| 714 | /* under construction !*/ |
| 715 | #else //#if 0 |
| 716 | // FIXME: take care here! still no implement |
| 717 | ASSERT(0); |
| 718 | #endif //#if 0 |
| 719 | } |
| 720 | else |
| 721 | #endif |
| 722 | if( AM_IsSpeechOn() ) { // && AFE_GetOutputDevice(L1SP_KEYTONE)==AFE_GetOutputDevice(L1SP_SPEECH) ) { |
| 723 | #if 0 // def ANALOG_AFE_PATH_EXIST |
| 724 | /* under construction !*/ |
| 725 | /* under construction !*/ |
| 726 | /* under construction !*/ |
| 727 | /* under construction !*/ |
| 728 | /* under construction !*/ |
| 729 | /* under construction !*/ |
| 730 | /* under construction !*/ |
| 731 | /* under construction !*/ |
| 732 | /* under construction !*/ |
| 733 | /* under construction !*/ |
| 734 | /* under construction !*/ |
| 735 | /* under construction !*/ |
| 736 | /* under construction !*/ |
| 737 | /* under construction !*/ |
| 738 | /* under construction !*/ |
| 739 | /* under construction !*/ |
| 740 | /* under construction !*/ |
| 741 | /* under construction !*/ |
| 742 | /* under construction !*/ |
| 743 | /* under construction !*/ |
| 744 | /* under construction !*/ |
| 745 | /* under construction !*/ |
| 746 | /* under construction !*/ |
| 747 | /* under construction !*/ |
| 748 | /* under construction !*/ |
| 749 | /* under construction !*/ |
| 750 | #else |
| 751 | DSP_TONE_AMP2 = KT_INIT_AMP; |
| 752 | #endif // ANALOG_AFE_PATH_EXIST |
| 753 | Data_Sync_Barrier(); |
| 754 | } |
| 755 | else { |
| 756 | DSP_TONE_AMP2 = KT_INIT_AMP; |
| 757 | Data_Sync_Barrier(); |
| 758 | #if 0 |
| 759 | /* under construction !*/ |
| 760 | /* under construction !*/ |
| 761 | #else //#if 0 |
| 762 | // FIXME: take care here! still no implement |
| 763 | ASSERT(0); |
| 764 | #endif //#if 0 |
| 765 | } |
| 766 | |
| 767 | DSP_KT_FREQ( freq1, freq2 ); |
| 768 | DSP_TONE_CTRL2 = 1; |
| 769 | Data_Sync_Barrier(); |
| 770 | keytone.isRun = true; |
| 771 | |
| 772 | AM_KeyToneOn(); |
| 773 | if( (duration = duration / 10) > 0 ) { |
| 774 | SGPT_CTRL_START_T start; |
| 775 | start.u2Tick = duration; |
| 776 | start.pfCallback = ktStop; |
| 777 | start.vPara = 0; |
| 778 | DclSGPT_Control( keytone.gpt, SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | /***************************************************************************** |
| 783 | * FUNCTION |
| 784 | * KT_Stop |
| 785 | * DESCRIPTION |
| 786 | * This function is used to stop key tone playing. |
| 787 | *****************************************************************************/ |
| 788 | void KT_Stop( void ) |
| 789 | { |
| 790 | DclSGPT_Control( keytone.gpt, SGPT_CMD_STOP, 0); |
| 791 | ktStop( 0 ); |
| 792 | } |
| 793 | |
| 794 | void KT_StopAndWait(void) |
| 795 | { |
| 796 | int I; |
| 797 | |
| 798 | AM_FlushQFunction(); |
| 799 | KT_Stop(); |
| 800 | |
| 801 | for( I = 0; ; I++ ) { |
| 802 | if ( !AM_IsKeyToneOn() ) |
| 803 | break; |
| 804 | |
| 805 | ASSERT_REBOOT(I < 20); |
| 806 | kal_sleep_task( AUD_1TICK(2) ); |
| 807 | } |
| 808 | kal_sleep_task( AUD_1TICK(2) );//wait AFE also updated |
| 809 | } |
| 810 | |
| 811 | void KT_SetAmplitude( int16 amp ) |
| 812 | { |
| 813 | DSP_TONE_AMP2 = amp; |
| 814 | Data_Sync_Barrier(); |
| 815 | } |
| 816 | |
| 817 | void KT_SetFIR( bool enable ) |
| 818 | { |
| 819 | if( enable ){ |
| 820 | #if 0 |
| 821 | /* under construction !*/ |
| 822 | /* under construction !*/ |
| 823 | #endif //#if 0 |
| 824 | } else { |
| 825 | #if 0 |
| 826 | /* under construction !*/ |
| 827 | /* under construction !*/ |
| 828 | #endif //#if 0 |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | /* To indicate if the keytone can be play */ |
| 833 | kal_bool KT_IsPlayable(void) |
| 834 | { |
| 835 | if( keytone.lock > 0 || keytone.volume1 == 0 ) |
| 836 | return KAL_FALSE; |
| 837 | if( L1Audio_CheckFlag( keytone.aud_id ) || L1Audio_CheckFlag( tone.aud_id ) ) |
| 838 | return KAL_FALSE; |
| 839 | return KAL_TRUE; |
| 840 | } |