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 | * pcm4way.c |
| 41 | * |
| 42 | * Project: |
| 43 | * -------- |
| 44 | * MAUI |
| 45 | * |
| 46 | * Description: |
| 47 | * ------------ |
| 48 | * PCM4WAY/PCM2WAY 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 | * removed! |
| 66 | * |
| 67 | * removed! |
| 68 | * removed! |
| 69 | * removed! |
| 70 | * removed! |
| 71 | * |
| 72 | * removed! |
| 73 | * removed! |
| 74 | * removed! |
| 75 | * removed! |
| 76 | * |
| 77 | * removed! |
| 78 | * removed! |
| 79 | * removed! |
| 80 | * removed! |
| 81 | * |
| 82 | * removed! |
| 83 | * removed! |
| 84 | * removed! |
| 85 | * |
| 86 | * removed! |
| 87 | * removed! |
| 88 | * removed! |
| 89 | * |
| 90 | * removed! |
| 91 | * removed! |
| 92 | * removed! |
| 93 | * |
| 94 | * removed! |
| 95 | * removed! |
| 96 | * removed! |
| 97 | * |
| 98 | * removed! |
| 99 | * removed! |
| 100 | * removed! |
| 101 | * |
| 102 | * removed! |
| 103 | * removed! |
| 104 | * removed! |
| 105 | * |
| 106 | * removed! |
| 107 | * removed! |
| 108 | * removed! |
| 109 | * removed! |
| 110 | * |
| 111 | * removed! |
| 112 | * removed! |
| 113 | * removed! |
| 114 | * |
| 115 | * removed! |
| 116 | * removed! |
| 117 | * |
| 118 | * removed! |
| 119 | * removed! |
| 120 | * removed! |
| 121 | * |
| 122 | *------------------------------------------------------------------------------ |
| 123 | * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| 124 | *============================================================================== |
| 125 | *******************************************************************************/ |
| 126 | |
| 127 | #include "kal_public_api.h" |
| 128 | #include "kal_trace.h" |
| 129 | #include "sync_data.h" |
| 130 | #include "l1sp_trc.h" |
| 131 | #include "l1audio_voc_utmd.h" |
| 132 | #include "l1audio.h" |
| 133 | #include "am.h" |
| 134 | |
| 135 | // #include "afe_def.h" |
| 136 | #include "media.h" |
| 137 | #include "pcm4way.h" |
| 138 | #include "sal_def.h" |
| 139 | #include "sal_exp.h" |
| 140 | |
| 141 | #include "sp_drv.h" |
| 142 | #include "sp_enhance.h" |
| 143 | |
| 144 | #include "vm.h" |
| 145 | |
| 146 | #define PCMEX_INTERNAL_BUF_MAX_SIZE 960 // 48 * 20 samples |
| 147 | |
| 148 | #define PCMEX_CO_BUFFER_WHEN_RW 1 |
| 149 | |
| 150 | _PCMEX_T pcmEx; |
| 151 | |
| 152 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 153 | static uint16 pcmEx_ul1_tempBufDataSize; |
| 154 | static uint16 pcmEx_ul2_tempBufDataSize; |
| 155 | static uint16 pcmEx_ul3_tempBufDataSize; |
| 156 | static uint16 pcmEx_ul4_tempBufDataSize; |
| 157 | |
| 158 | static uint16 pcmEx_dl_tempBufDataSize; |
| 159 | |
| 160 | static uint16 pcmEx_ul1_tempBuf[PCMEX_INTERNAL_BUF_MAX_SIZE]; |
| 161 | static uint16 pcmEx_ul2_tempBuf[PCMEX_INTERNAL_BUF_MAX_SIZE]; |
| 162 | static uint16 pcmEx_ul3_tempBuf[PCMEX_INTERNAL_BUF_MAX_SIZE]; |
| 163 | static uint16 pcmEx_ul4_tempBuf[PCMEX_INTERNAL_BUF_MAX_SIZE]; |
| 164 | |
| 165 | static uint16 pcmEx_dl_tempBuf[PCMEX_INTERNAL_BUF_MAX_SIZE]; |
| 166 | #endif |
| 167 | |
| 168 | static bool idlePnwVm; |
| 169 | |
| 170 | bool pcmEx_isRunInIdleMode(void) |
| 171 | { |
| 172 | return (pcmEx.am_type==AM_PCMEX_TYPE_IDLE); |
| 173 | } |
| 174 | |
| 175 | void pcmEx_Init() |
| 176 | { |
| 177 | pcmEx.PCMEXspinLockID = kal_create_spinlock("PCMEX_LOCK"); |
| 178 | |
| 179 | } |
| 180 | |
| 181 | uint16 pcmEx_getDataFromDsp(uint16 *toBuf, Sal_PcmEx_BufId_t bufName, kal_bool isUl) |
| 182 | { |
| 183 | uint32 I; |
| 184 | uint16 bufLen = SAL_PcmEx_GetBufLen(bufName); |
| 185 | |
| 186 | // Use address mode to prevent idma being interrupted by other ISR, ie. L1D. |
| 187 | volatile uint16* ptr = SAL_PcmEx_GetBuf(bufName); |
| 188 | MD_TRC_P4W_GETDATAFROMDSP(bufName, ptr, bufLen); |
| 189 | if( SP_IsMicMute() && (KAL_TRUE == isUl) ){ |
| 190 | for( I = bufLen; I > 0; I-- ) |
| 191 | *toBuf++ = 0; |
| 192 | } else { |
| 193 | for( I = bufLen; I > 0; I-- ) |
| 194 | *toBuf++ = *ptr++; |
| 195 | } |
| 196 | |
| 197 | return bufLen; |
| 198 | } |
| 199 | |
| 200 | uint16 pcmEx_writeDataToDsp(const uint16 *fromBuf, Sal_PcmEx_BufId_t bufName) |
| 201 | { |
| 202 | uint32 I; |
| 203 | uint16 bufLen = SAL_PcmEx_GetBufLen(bufName); |
| 204 | |
| 205 | volatile uint16* ptr = SAL_PcmEx_GetBuf(bufName); |
| 206 | MD_TRC_P4W_WRITEDATATODSP(bufName, ptr, bufLen); |
| 207 | for( I = bufLen; I > 0; I-- ) |
| 208 | *ptr++ = *fromBuf++; |
| 209 | Data_Sync_Barrier(); |
| 210 | |
| 211 | return bufLen; |
| 212 | } |
| 213 | |
| 214 | uint16 pcmEx_writePatternToDsp(uint16 pattern, Sal_PcmEx_BufId_t bufName) |
| 215 | { |
| 216 | uint32 I; |
| 217 | uint16 bufLen = SAL_PcmEx_GetBufLen(bufName); |
| 218 | |
| 219 | volatile uint16* ptr = SAL_PcmEx_GetBuf(bufName); |
| 220 | for( I = bufLen; I > 0; I-- ) |
| 221 | *ptr++ = pattern; |
| 222 | Data_Sync_Barrier(); |
| 223 | |
| 224 | return bufLen; |
| 225 | } |
| 226 | |
| 227 | |
| 228 | void pcmEx_hisrDlHdlr(void *param) |
| 229 | { |
| 230 | kal_take_spinlock(pcmEx.PCMEXspinLockID, KAL_INFINITE_WAIT); |
| 231 | if(pcmEx.running == 0){ |
| 232 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 237 | |
| 238 | // get SD buf data to temp buffer |
| 239 | pcmEx_dl_tempBufDataSize = pcmEx_getDataFromDsp(pcmEx_dl_tempBuf, SAL_PCMEX_PNW_BUF_D2M_DL1, KAL_FALSE); |
| 240 | |
| 241 | #endif |
| 242 | |
| 243 | // handler callback |
| 244 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 245 | if(pcmEx.pnw_dl_hdlr) |
| 246 | { |
| 247 | pcmEx.pnw_dl_hdlr(); |
| 248 | } |
| 249 | |
| 250 | } |
| 251 | |
| 252 | void pcmEx_hisrUlHdlr(void *param) |
| 253 | { |
| 254 | kal_take_spinlock(pcmEx.PCMEXspinLockID, KAL_INFINITE_WAIT); |
| 255 | if(pcmEx.running == 0){ |
| 256 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 257 | return; |
| 258 | } |
| 259 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 260 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 261 | |
| 262 | // mics' data to temp buffer |
| 263 | if(pcmEx.cfgUL1) { |
| 264 | pcmEx_ul1_tempBufDataSize = pcmEx_getDataFromDsp(pcmEx_ul1_tempBuf, SAL_PCMEX_PNW_BUF_D2M_UL1, KAL_TRUE); |
| 265 | } |
| 266 | |
| 267 | kal_take_spinlock(pcmEx.PCMEXspinLockID, KAL_INFINITE_WAIT); |
| 268 | if(pcmEx.running == 0){ |
| 269 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 274 | if(pcmEx.cfgUL2) { |
| 275 | pcmEx_ul2_tempBufDataSize = pcmEx_getDataFromDsp(pcmEx_ul2_tempBuf, SAL_PCMEX_PNW_BUF_D2M_UL2, KAL_TRUE); |
| 276 | } |
| 277 | |
| 278 | kal_take_spinlock(pcmEx.PCMEXspinLockID, KAL_INFINITE_WAIT); |
| 279 | if(pcmEx.running == 0){ |
| 280 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 285 | if(pcmEx.cfgUL3) { |
| 286 | pcmEx_ul3_tempBufDataSize = pcmEx_getDataFromDsp(pcmEx_ul3_tempBuf, SAL_PCMEX_PNW_BUF_D2M_UL3, KAL_TRUE); |
| 287 | } |
| 288 | |
| 289 | kal_take_spinlock(pcmEx.PCMEXspinLockID, KAL_INFINITE_WAIT); |
| 290 | if(pcmEx.running == 0){ |
| 291 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 292 | return; |
| 293 | } |
| 294 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 295 | if(pcmEx.cfgUL4) { |
| 296 | pcmEx_ul4_tempBufDataSize = pcmEx_getDataFromDsp(pcmEx_ul4_tempBuf, SAL_PCMEX_PNW_BUF_D2M_UL4, KAL_TRUE); |
| 297 | } |
| 298 | |
| 299 | #endif |
| 300 | |
| 301 | // handler callback |
| 302 | if(pcmEx.pnw_ul_hdlr) |
| 303 | { |
| 304 | pcmEx.pnw_ul_hdlr(); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | |
| 309 | /** |
| 310 | |
| 311 | @pcmNway_dl_hdlr |
| 312 | @pcmNway_ul_hdlr: |
| 313 | */ |
| 314 | void Idle_PcmEx_Start(void (*pcmNway_dl_hdlr)(void), void (*pcmNway_ul_hdlr)(void), |
| 315 | uint32 cfgUL1, uint32 cfgUL2, uint32 cfgUL3, uint32 cfgUL4, uint32 cfgDL, |
| 316 | PCMEX_BAND band, PCMEX_IDLE_ENH_SETTING enhSetting) |
| 317 | { |
| 318 | uint32 I; |
| 319 | kal_uint32 voc_ptn = TVCI_CLOSE_FILE; |
| 320 | kal_uint32 *voc_ptn_ptr = &voc_ptn; |
| 321 | |
| 322 | |
| 323 | // prevent re-entry!! |
| 324 | ASSERT(PNW_STATE_IDLE == pcmEx.state); |
| 325 | |
| 326 | pcmEx.aud_id = L1Audio_GetAudioID(); |
| 327 | L1Audio_SetFlag( pcmEx.aud_id ); /*Be careful.Before Locking SleepMode, to access DSP sherrif tasks much time. So access DSP must be after SetFlag*/ |
| 328 | |
| 329 | // band and am type setting |
| 330 | pcmEx.bandInfo = band; |
| 331 | switch(band){ |
| 332 | case PCMEX_BAND_NB: |
| 333 | { |
| 334 | ASSERT(enhSetting != PCMEX_IDLE_ENH_SETTING_NONE); |
| 335 | pcmEx.am_type = AM_PCMEX_TYPE_IDLE; |
| 336 | } |
| 337 | break; |
| 338 | case PCMEX_BAND_WB: |
| 339 | { |
| 340 | ASSERT(enhSetting != PCMEX_IDLE_ENH_SETTING_NONE); |
| 341 | pcmEx.am_type = AM_PCMEX_TYPE_IDLE; |
| 342 | } |
| 343 | break; |
| 344 | default: // include PCMEX_BAND_DYNAMIC and PCMEX_BAND_UNSET cases |
| 345 | ASSERT(0); |
| 346 | } |
| 347 | pcmEx.cfgUL1 = cfgUL1; |
| 348 | pcmEx.cfgUL2 = cfgUL2; |
| 349 | pcmEx.cfgUL3 = cfgUL3; |
| 350 | pcmEx.cfgUL4 = cfgUL4; |
| 351 | pcmEx.cfgDL = cfgDL; |
| 352 | |
| 353 | pcmEx.pnw_dl_hdlr = pcmNway_dl_hdlr; |
| 354 | pcmEx.pnw_ul_hdlr = pcmNway_ul_hdlr; |
| 355 | |
| 356 | L1Audio_HookHisrHandler(DP_D2C_PCM_EX_DL,(L1Audio_EventHandler)pcmEx_hisrDlHdlr, 0); |
| 357 | L1Audio_HookHisrHandler(DP_D2C_PCM_EX_UL,(L1Audio_EventHandler)pcmEx_hisrUlHdlr, 0); |
| 358 | |
| 359 | // check DSP state and turn on |
| 360 | ASSERT(SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF) && SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF)); |
| 361 | AM_PCM_EX_On(pcmEx.am_type, (uint32)(&pcmEx));//to config pnw |
| 362 | |
| 363 | SAL_PcmEx_SetStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); |
| 364 | SAL_PcmEx_SetStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); |
| 365 | |
| 366 | // wait for ready |
| 367 | for(I = 0; ;I ++){ |
| 368 | kal_bool is_ready = true; |
| 369 | |
| 370 | if( (pcmEx.cfgDL & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) |
| 371 | is_ready &= false; |
| 372 | if( (pcmEx.cfgUL1 & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) |
| 373 | is_ready &= false; |
| 374 | |
| 375 | if(is_ready) |
| 376 | break; |
| 377 | #ifndef L1D_TEST |
| 378 | ASSERT(I < 22); // wait 200ms |
| 379 | kal_sleep_task( AUD_1TICK(2) ); |
| 380 | #endif |
| 381 | } |
| 382 | |
| 383 | pcmEx.state = PNW_STATE_RUN; |
| 384 | #ifndef __L1_STANDALONE__ // avoid link error |
| 385 | if(ChkL1ClsFltr_L1Audio_VoC_TRACE_VM()) |
| 386 | { |
| 387 | MD_TRC_L1SP_PHONE_CALL(5, 1, 1); |
| 388 | if(ChkL1ClsFltr_L1Audio_VoC_TRACE_EPL()) { |
| 389 | MD_TRC_L1SP_PHONE_CALL(5, 1, 2); |
| 390 | } |
| 391 | tst_vc_response(TVCI_VM_LOGGING, (const kal_uint8*)voc_ptn_ptr, 4); |
| 392 | VMREC_Start(NULL, true); |
| 393 | idlePnwVm = true; |
| 394 | } |
| 395 | else { |
| 396 | MD_TRC_L1SP_PHONE_CALL(5, 1, 0); |
| 397 | } |
| 398 | #endif |
| 399 | |
| 400 | if(PCMEX_IDLE_ENH_SETTING_WITH == enhSetting) { |
| 401 | pcmEx.isEnhOn = true; |
| 402 | SetSpeechEnhancement(true); |
| 403 | } |
| 404 | kal_take_spinlock(pcmEx.PCMEXspinLockID, KAL_INFINITE_WAIT); |
| 405 | pcmEx.running = 1; |
| 406 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 407 | |
| 408 | /* the end of configure the SAL */ |
| 409 | } |
| 410 | |
| 411 | |
| 412 | |
| 413 | void Del_PcmEx_Start(void (*pcmNway_dl_hdlr)(void), void (*pcmNway_ul_hdlr)(void), |
| 414 | uint32 cfgUL1, uint32 cfgUL2, uint32 cfgUL3, uint32 cfgUL4, uint32 cfgDL) |
| 415 | { |
| 416 | uint32 I; |
| 417 | //kal_bool flag; |
| 418 | |
| 419 | // prevent re-entry!! |
| 420 | ASSERT(PNW_STATE_IDLE == pcmEx.state); |
| 421 | |
| 422 | pcmEx.aud_id = L1Audio_GetAudioID(); |
| 423 | L1Audio_SetFlag( pcmEx.aud_id ); /*Be careful.Before Locking SleepMode, to access DSP sherrif tasks much time. So access DSP must be after SetFlag*/ |
| 424 | |
| 425 | // band and am type setting |
| 426 | pcmEx.bandInfo = PCMEX_BAND_DYNAMIC; |
| 427 | pcmEx.am_type = AM_PCMEX_TYPE_DEDICATION; |
| 428 | |
| 429 | // pcmEx.dspPcmExMicLen = 0; |
| 430 | // pcmEx.dspPcmExSpkLen = 0; |
| 431 | |
| 432 | pcmEx.cfgUL1 = cfgUL1; |
| 433 | pcmEx.cfgUL2 = cfgUL2; |
| 434 | pcmEx.cfgUL3 = cfgUL3; |
| 435 | pcmEx.cfgUL4 = cfgUL4; |
| 436 | |
| 437 | pcmEx.cfgDL = cfgDL; |
| 438 | |
| 439 | pcmEx.pnw_dl_hdlr = pcmNway_dl_hdlr; |
| 440 | pcmEx.pnw_ul_hdlr = pcmNway_ul_hdlr; |
| 441 | |
| 442 | L1Audio_HookHisrHandler(DP_D2C_PCM_EX_DL,(L1Audio_EventHandler)pcmEx_hisrDlHdlr, 0); |
| 443 | L1Audio_HookHisrHandler(DP_D2C_PCM_EX_UL,(L1Audio_EventHandler)pcmEx_hisrUlHdlr, 0); |
| 444 | |
| 445 | // check DSP state and turn on |
| 446 | ASSERT(SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF) && SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF)); |
| 447 | AM_PCM_EX_On(pcmEx.am_type, (uint32)(&pcmEx));//to config pnw |
| 448 | |
| 449 | SAL_PcmEx_SetStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); |
| 450 | SAL_PcmEx_SetStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); |
| 451 | |
| 452 | // wait for ready |
| 453 | for(I = 0; ;I ++){ |
| 454 | kal_bool is_ready = true; |
| 455 | |
| 456 | if( (pcmEx.cfgDL & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) |
| 457 | is_ready &= false; |
| 458 | if( (pcmEx.cfgUL1 & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) |
| 459 | is_ready &= false; |
| 460 | |
| 461 | if(is_ready) |
| 462 | break; |
| 463 | #ifndef L1D_TEST |
| 464 | ASSERT(I < 22); // wait 200ms |
| 465 | kal_sleep_task( AUD_1TICK(2) ); |
| 466 | #endif |
| 467 | } |
| 468 | |
| 469 | pcmEx.state = PNW_STATE_RUN; |
| 470 | kal_take_spinlock(pcmEx.PCMEXspinLockID, KAL_INFINITE_WAIT); |
| 471 | pcmEx.running = 1; |
| 472 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 473 | /* the end of configure the SAL */ |
| 474 | } |
| 475 | |
| 476 | void PcmEx_Stop(void) |
| 477 | { |
| 478 | kal_uint32 voc_ptn = TVCI_CLOSE_FILE; |
| 479 | kal_uint32 *voc_ptn_ptr = &voc_ptn; |
| 480 | |
| 481 | ASSERT( PNW_STATE_RUN == pcmEx.state); |
| 482 | kal_take_spinlock(pcmEx.PCMEXspinLockID, KAL_INFINITE_WAIT); |
| 483 | pcmEx.running = 0; |
| 484 | kal_give_spinlock(pcmEx.PCMEXspinLockID); |
| 485 | if(true == pcmEx.isEnhOn) { |
| 486 | SetSpeechEnhancement(false); |
| 487 | } |
| 488 | |
| 489 | |
| 490 | if(idlePnwVm) |
| 491 | { |
| 492 | tst_vc_response(TVCI_VM_LOGGING, (const kal_uint8*)voc_ptn_ptr, 4); |
| 493 | VMREC_Stop(true); |
| 494 | idlePnwVm = false; |
| 495 | } |
| 496 | /* the begining of configure the SAL */ |
| 497 | ASSERT(SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF) || SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY)); |
| 498 | ASSERT(SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF) || SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY)); |
| 499 | |
| 500 | SAL_PcmEx_SetStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF); |
| 501 | SAL_PcmEx_SetStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF); |
| 502 | |
| 503 | AM_PCM_EX_Off(pcmEx.am_type, (uint32)(&pcmEx)); |
| 504 | |
| 505 | L1Audio_UnhookHisrHandler(DP_D2C_PCM_EX_DL); |
| 506 | L1Audio_UnhookHisrHandler(DP_D2C_PCM_EX_UL); |
| 507 | |
| 508 | L1Audio_ClearFlag( pcmEx.aud_id ); |
| 509 | L1Audio_FreeAudioID( pcmEx.aud_id ); |
| 510 | |
| 511 | // set to default. |
| 512 | pcmEx.pnw_dl_hdlr = pcmEx.pnw_ul_hdlr = NULL; |
| 513 | pcmEx.cfgUL1 = 0; |
| 514 | pcmEx.cfgUL2 = 0; |
| 515 | pcmEx.cfgUL3 = 0; |
| 516 | pcmEx.cfgUL4 = 0; |
| 517 | pcmEx.cfgDL = 0; |
| 518 | |
| 519 | // pcmEx.dspPcmExMicLen = 0; |
| 520 | // pcmEx.dspPcmExSpkLen = 0; |
| 521 | |
| 522 | pcmEx.bandInfo = PCMEX_BAND_UNSET; |
| 523 | pcmEx.am_type = AM_PCMEX_TYPE_UNDEF; |
| 524 | |
| 525 | pcmEx.state = PNW_STATE_IDLE; |
| 526 | |
| 527 | |
| 528 | } |
| 529 | |
| 530 | |
| 531 | uint16 PcmEx_GetFromMic1(uint16 *ul_buf) |
| 532 | { |
| 533 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 534 | |
| 535 | memcpy(ul_buf, pcmEx_ul1_tempBuf, pcmEx_ul1_tempBufDataSize*sizeof(uint16)); |
| 536 | return pcmEx_ul1_tempBufDataSize; |
| 537 | |
| 538 | #else |
| 539 | |
| 540 | return pcmEx_getDataFromDsp(ul_buf, SAL_PCMEX_PNW_BUF_D2M_UL1, KAL_TRUE); |
| 541 | |
| 542 | #endif |
| 543 | } |
| 544 | |
| 545 | uint16 PcmEx_GetFromMic2(uint16 *ul_buf) |
| 546 | { |
| 547 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 548 | |
| 549 | memcpy(ul_buf, pcmEx_ul2_tempBuf, pcmEx_ul2_tempBufDataSize*sizeof(uint16)); |
| 550 | return pcmEx_ul2_tempBufDataSize; |
| 551 | |
| 552 | #else |
| 553 | |
| 554 | return pcmEx_getDataFromDsp(ul_buf, SAL_PCMEX_PNW_BUF_D2M_UL2, KAL_TRUE); |
| 555 | |
| 556 | #endif |
| 557 | } |
| 558 | |
| 559 | uint16 PcmEx_GetFromMic3(uint16 *ul_buf) |
| 560 | { |
| 561 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 562 | |
| 563 | memcpy(ul_buf, pcmEx_ul3_tempBuf, pcmEx_ul3_tempBufDataSize*sizeof(uint16)); |
| 564 | return pcmEx_ul3_tempBufDataSize; |
| 565 | |
| 566 | #else |
| 567 | |
| 568 | return 0; |
| 569 | |
| 570 | #endif |
| 571 | } |
| 572 | |
| 573 | uint16 PcmEx_GetFromMic4(uint16 *ul_buf) |
| 574 | { |
| 575 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 576 | |
| 577 | memcpy(ul_buf, pcmEx_ul4_tempBuf, pcmEx_ul4_tempBufDataSize*sizeof(uint16)); |
| 578 | return pcmEx_ul4_tempBufDataSize; |
| 579 | |
| 580 | #else |
| 581 | |
| 582 | return 0 ; |
| 583 | |
| 584 | #endif |
| 585 | } |
| 586 | |
| 587 | uint16 PcmEx_PutToSE1(const uint16 *ul_data) |
| 588 | { |
| 589 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 590 | return pcmEx_writeDataToDsp(ul_data, SAL_PCMEX_PNW_BUF_M2D_UL1); |
| 591 | #else |
| 592 | return pcmEx_writeDataToDsp(ul_data, SAL_PCMEX_PNW_BUF_M2D_UL2); |
| 593 | #endif |
| 594 | } |
| 595 | |
| 596 | uint16 PcmEx_FillSE1(uint16 value) |
| 597 | { |
| 598 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 599 | return pcmEx_writePatternToDsp(value, SAL_PCMEX_PNW_BUF_M2D_UL1); |
| 600 | #else |
| 601 | return pcmEx_writePatternToDsp(value, SAL_PCMEX_PNW_BUF_M2D_UL2); |
| 602 | #endif |
| 603 | } |
| 604 | |
| 605 | uint16 PcmEx_PutToSE2(const uint16 *ul_data) |
| 606 | { |
| 607 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 608 | return pcmEx_writeDataToDsp(ul_data, SAL_PCMEX_PNW_BUF_M2D_UL2); |
| 609 | #else |
| 610 | return 0; |
| 611 | #endif |
| 612 | } |
| 613 | |
| 614 | uint16 PcmEx_FillSE2(uint16 value) |
| 615 | { |
| 616 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 617 | return pcmEx_writePatternToDsp(value, SAL_PCMEX_PNW_BUF_M2D_UL2); |
| 618 | #else |
| 619 | return 0; |
| 620 | #endif |
| 621 | } |
| 622 | |
| 623 | uint16 PcmEx_PutToSE3(const uint16 *ul_data) |
| 624 | { |
| 625 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 626 | return pcmEx_writeDataToDsp(ul_data, SAL_PCMEX_PNW_BUF_M2D_UL3); |
| 627 | #else |
| 628 | return 0; |
| 629 | #endif |
| 630 | } |
| 631 | |
| 632 | uint16 PcmEx_FillSE3(uint16 value) |
| 633 | { |
| 634 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 635 | return pcmEx_writePatternToDsp(value, SAL_PCMEX_PNW_BUF_M2D_UL3); |
| 636 | #else |
| 637 | return 0; |
| 638 | #endif |
| 639 | } |
| 640 | |
| 641 | uint16 PcmEx_PutToSE4(const uint16 *ul_data) |
| 642 | { |
| 643 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 644 | return pcmEx_writeDataToDsp(ul_data, SAL_PCMEX_PNW_BUF_M2D_UL4); |
| 645 | #else |
| 646 | return 0; |
| 647 | #endif |
| 648 | } |
| 649 | |
| 650 | uint16 PcmEx_FillSE4(uint16 value) |
| 651 | { |
| 652 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 653 | return pcmEx_writePatternToDsp(value, SAL_PCMEX_PNW_BUF_M2D_UL4); |
| 654 | #else |
| 655 | return 0; |
| 656 | #endif |
| 657 | } |
| 658 | |
| 659 | // -------------------------- |
| 660 | |
| 661 | uint16 PcmEx_GetFromSD(uint16 *dl_buf) |
| 662 | { |
| 663 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 664 | |
| 665 | memcpy(dl_buf, pcmEx_dl_tempBuf, pcmEx_dl_tempBufDataSize*sizeof(uint16)); |
| 666 | return pcmEx_dl_tempBufDataSize; |
| 667 | |
| 668 | #else |
| 669 | return pcmEx_getDataFromDsp(dl_buf,SAL_PCMEX_PNW_BUF_D2M_DL1 , KAL_FALSE); |
| 670 | #endif |
| 671 | } |
| 672 | |
| 673 | uint16 PcmEx_PutToSpk(const uint16 *dl_data) |
| 674 | { |
| 675 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 676 | return pcmEx_writeDataToDsp(dl_data, SAL_PCMEX_PNW_BUF_M2D_DL1); |
| 677 | #else |
| 678 | return pcmEx_writeDataToDsp(dl_data, SAL_PCMEX_PNW_BUF_M2D_DL1); |
| 679 | #endif |
| 680 | |
| 681 | } |
| 682 | |
| 683 | uint16 PcmEx_FillSpk(uint16 value) |
| 684 | { |
| 685 | #if PCMEX_CO_BUFFER_WHEN_RW |
| 686 | return pcmEx_writePatternToDsp(value, SAL_PCMEX_PNW_BUF_M2D_DL1); |
| 687 | #else |
| 688 | return pcmEx_writePatternToDsp(value, SAL_PCMEX_PNW_BUF_M2D_DL1); |
| 689 | #endif |
| 690 | |
| 691 | } |
| 692 | |
| 693 | |
| 694 | //************** PCM 4-WAY **************************************************** |
| 695 | |
| 696 | void PCM4WAY_Start(void (*pcm4way_hdlr)(void), uint32 type) |
| 697 | { |
| 698 | kal_prompt_trace(MOD_L1SP, "[Test] PCM4WAY_Start config type:%x", type); |
| 699 | switch(type) { |
| 700 | case P4W_APP_CTM: |
| 701 | Del_PcmEx_Start(pcm4way_hdlr, NULL, |
| 702 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul1 |
| 703 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul2 |
| 704 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul3 |
| 705 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul4 |
| 706 | USE_D2M_PATH + USE_M2D_PATH ); |
| 707 | break; |
| 708 | case P4W_APP_TYPE_UNDER_CALL: |
| 709 | Del_PcmEx_Start(pcm4way_hdlr, NULL, |
| 710 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul1 |
| 711 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul2 |
| 712 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul3 |
| 713 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul4 |
| 714 | USE_D2M_PATH + USE_M2D_PATH); |
| 715 | break; |
| 716 | case P4W_APP_TYPE_WITHOUT_CALL: |
| 717 | Idle_PcmEx_Start(pcm4way_hdlr, NULL, |
| 718 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul1 |
| 719 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul2 |
| 720 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul3 |
| 721 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul4 |
| 722 | USE_D2M_PATH + USE_M2D_PATH, |
| 723 | PCMEX_BAND_NB, PCMEX_IDLE_ENH_SETTING_WITH); // nb |
| 724 | break; |
| 725 | case P4W_APP_TYPE_WITHOUT_CALL_WB: |
| 726 | Idle_PcmEx_Start(pcm4way_hdlr, NULL, |
| 727 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul1 |
| 728 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul2 |
| 729 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul3 |
| 730 | USE_D2M_PATH + USE_M2D_PATH + DATA_SELECT_AFTER_ENH, // ul4 |
| 731 | USE_D2M_PATH + USE_M2D_PATH, |
| 732 | PCMEX_BAND_WB, PCMEX_IDLE_ENH_SETTING_WITH); |
| 733 | break; |
| 734 | case P4W_APP_ECALL_DETECT: |
| 735 | Del_PcmEx_Start(pcm4way_hdlr, NULL, |
| 736 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul1 |
| 737 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul2 |
| 738 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul3 |
| 739 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul4 |
| 740 | USE_D2M_PATH ); |
| 741 | break; |
| 742 | default: |
| 743 | ASSERT(0); |
| 744 | } |
| 745 | |
| 746 | |
| 747 | } |
| 748 | |
| 749 | void PCM4WAY_Stop(uint32 type) |
| 750 | { |
| 751 | PcmEx_Stop(); |
| 752 | } |
| 753 | |
| 754 | uint16 PCM4WAY_GetFromMic(uint16 *ul_buf) |
| 755 | { |
| 756 | return PcmEx_GetFromMic1(ul_buf); |
| 757 | } |
| 758 | uint16 PCM4WAY_GetFromMic2(uint16 *ul_buf) |
| 759 | { |
| 760 | return PcmEx_GetFromMic2(ul_buf); |
| 761 | } |
| 762 | |
| 763 | uint16 PCM4WAY_PutToSE(const uint16 *ul_data) |
| 764 | { |
| 765 | return PcmEx_PutToSE1(ul_data); |
| 766 | } |
| 767 | |
| 768 | uint16 PCM4WAY_PutToSE2(const uint16 *ul_data) |
| 769 | { |
| 770 | return PcmEx_PutToSE2(ul_data); |
| 771 | } |
| 772 | |
| 773 | uint16 PCM4WAY_FillSE(uint16 value) |
| 774 | { |
| 775 | return PcmEx_FillSE1(value); |
| 776 | } |
| 777 | |
| 778 | uint16 PCM4WAY_FillSE2(uint16 value) |
| 779 | { |
| 780 | return PcmEx_FillSE2(value); |
| 781 | } |
| 782 | |
| 783 | uint16 PCM4WAY_GetFromSD(uint16 *dl_buf) |
| 784 | { |
| 785 | return PcmEx_GetFromSD(dl_buf); |
| 786 | |
| 787 | } |
| 788 | |
| 789 | uint16 PCM4WAY_PutToSpk(const uint16 *dl_data) |
| 790 | { |
| 791 | return PcmEx_PutToSpk(dl_data); |
| 792 | } |
| 793 | |
| 794 | uint16 PCM4WAY_FillSpk(uint16 value) |
| 795 | { |
| 796 | return PcmEx_FillSpk(value); |
| 797 | |
| 798 | } |
| 799 | |
| 800 | //************** PCM 2-WAY **************************************************** |
| 801 | |
| 802 | void PCM2WAY_Start(void (*pcm2way_hdlr)(void), uint32 type) |
| 803 | { |
| 804 | switch(type) { |
| 805 | case P2W_APP_TYPE_UNDER_CALL: |
| 806 | Del_PcmEx_Start(pcm2way_hdlr, NULL, |
| 807 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul1 |
| 808 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul2 |
| 809 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul3 |
| 810 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul4 |
| 811 | USE_M2D_PATH); |
| 812 | break; |
| 813 | case P2W_APP_TYPE_VOIP: |
| 814 | case P2W_APP_TYPE_WITHOUT_CALL: |
| 815 | Idle_PcmEx_Start(pcm2way_hdlr, NULL, |
| 816 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul1 |
| 817 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul2 |
| 818 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul3 |
| 819 | USE_D2M_PATH + DATA_SELECT_AFTER_ENH, // ul4 |
| 820 | USE_M2D_PATH, |
| 821 | PCMEX_BAND_NB, PCMEX_IDLE_ENH_SETTING_WITH); // nb |
| 822 | break; |
| 823 | default: |
| 824 | ASSERT(0); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | void PCM2WAY_Stop(uint32 type) |
| 829 | { |
| 830 | PcmEx_Stop(); |
| 831 | } |
| 832 | |
| 833 | |
| 834 | |
| 835 | uint16 PCM2WAY_GetFromMic(uint16 *ul_buf) |
| 836 | { |
| 837 | #if 0 |
| 838 | /* under construction !*/ |
| 839 | /* under construction !*/ |
| 840 | /* under construction !*/ |
| 841 | /* under construction !*/ |
| 842 | /* under construction !*/ |
| 843 | /* under construction !*/ |
| 844 | /* under construction !*/ |
| 845 | /* under construction !*/ |
| 846 | /* under construction !*/ |
| 847 | /* under construction !*/ |
| 848 | /* under construction !*/ |
| 849 | /* under construction !*/ |
| 850 | /* under construction !*/ |
| 851 | /* under construction !*/ |
| 852 | /* under construction !*/ |
| 853 | #endif |
| 854 | return PcmEx_GetFromMic1(ul_buf); |
| 855 | // } |
| 856 | } |
| 857 | |
| 858 | uint16 PCM2WAY_PutToSpk(const uint16 *dl_data) |
| 859 | { |
| 860 | return PcmEx_PutToSpk(dl_data); |
| 861 | } |
| 862 | |
| 863 | |
| 864 | uint16 PCM2WAY_FillSpk(uint16 value) |
| 865 | { |
| 866 | return PcmEx_FillSpk(value); |
| 867 | } |
| 868 | |