xref: /utopia/UTPA2-700.0.x/modules/audio/drv/audio/drvAUDIO.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 ///////////////////////////////////////////////////////////////////////////////
93 #define _DRVAUDIO_C
94 
95 ///////////////////////////////////////////////////////////////////////////////
96 /// file   drvAUDIO.c
97 /// @author MStar Semiconductor Inc.
98 /// @brief   Audio common driver
99 ///////////////////////////////////////////////////////////////////////////////
100 //
101 //------------------------------------------------------------------------------
102 // Header Files
103 //------------------------------------------------------------------------------
104 #ifdef MSOS_TYPE_LINUX_KERNEL
105 #include <linux/string.h>
106 #include <linux/delay.h>
107 #include <linux/slab.h>
108 #include <linux/vmalloc.h>
109 #else
110 #include <string.h>
111 #endif
112 
113 #include "ULog.h"
114 #include "MsCommon.h"
115 #include "MsVersion.h"
116 #include "MsIRQ.h"
117 #include "MsOS.h"
118 
119 #include "drvSYS.h"
120 #include "drvBDMA.h"
121 // Internal Definition
122 #include "drvMMIO.h"
123 
124 #include "drvAUDIO.h"
125 #include "drvAUDIO_if.h"
126 #include "./internal/drvAUDIO_internal.h"
127 #include "./internal/drvMAD.h"
128 #include "./internal/drvMAD2.h"
129 #include "./internal/drvSOUND.h"
130 #include "./internal/drvSIF.h"
131 #include "./internal/drvAudio_Common.h"
132 
133 #include "halMAD.h"
134 #include "halMAD2.h"
135 #include "halSIF.h"
136 #include "halAUDIO.h"
137 #include "regAUDIO.h"
138 
139 //-------------------------------------------------------------------------------------------------
140 //  Driver Compiler Options
141 //-------------------------------------------------------------------------------------------------
142 #define DRVAUDIO_CHECK_SHM_INIT \
143     do { \
144         if (g_AudioVars2 == NULL) \
145         { \
146             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Warning! g_AudioVars2 should not be NULL !!!\n", __FUNCTION__); \
147             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Perform SHM Init here !!!\n", __FUNCTION__); \
148             if ( MDrv_AUDIO_SHM_Init() == FALSE) \
149             { \
150                 MS_ASSERT(0); \
151             } \
152         } \
153     } while(0)
154 
155 #ifndef UNUSED
156 #define UNUSED(x) ((x)=(x))
157 #endif
158 
159 static MSIF_Version _drv_aud_version = {
160     .DDI = { AUD_DRV_VERSION, },
161 };
162 
163 static MS_BOOL _bMMIO_Init = FALSE;
164 static MS_BOOL _PreInit = FALSE;
165 static MS_VIRT _gu32AudioRiuBaseAddr;
166 
167 // Global variables for VoIP applications to register the CallBack.
168 static MS_VIRT (*audio_dec_app_callbk)(MS_U8) = NULL;
169 static MS_VIRT (*audio_se_app_callbk)(MS_U8) = NULL;
170 
171 AUDIO_DEC_ID (* gOpenDecodeSystemFuncPtr)(AudioDecStatus_t * p_AudioDecStatus) = NULL;
172 MS_BOOL (* gDigitalOutChannelStatusFuncPtr)(DIGITAL_OUTPUT_TYPE , Digital_Out_Channel_Status_t *) = NULL;
173 MS_PHY (* gGetDDRInfoFuncPtr)(AUDIO_DEC_ID DecId, EN_AUDIO_DDRINFO DDRInfo) = NULL;
174 
175 #define AUDIO_ASSERT(_cnd, _fmt, _args...)                                      \
176 				do {                                                            \
177                     if (!(_cnd)) {                                              \
178                         MS_ASSERT(0);                                           \
179                     }                                                           \
180                 } while(0)
181 
182 #if defined (MSOS_TYPE_NOS)
183     #define MDRV_FIQ_BEGIN          0x00
184     #define FIQ_DEC_DSP2UP          (MDRV_FIQ_BEGIN + 29)
185     #define FIQ_SE_DSP2UP           (MDRV_FIQ_BEGIN + 14)
186     void MDrv_AUDIO_DecDspISR(MHAL_SavedRegisters *pHalReg, MS_U32 u32Data);
187     void MDrv_AUDIO_SeDspISR(MHAL_SavedRegisters *pHalReg, MS_U32 u32Data);
188 #else // Ecos and Linux
189     void MDrv_AUDIO_DecDspISR( InterruptNum eIntNum );
190     void MDrv_AUDIO_SeDspISR( InterruptNum eIntNum );
191 #endif
192 
193 MS_U8  g_Dsp2CodeType;
194 AU_CHIP_TYPE gAudioChipType;
195 MS_BOOL bIsNonPCMInDec2 = TRUE;
196 AUDIO_SHARED_VARS2 * g_AudioVars2 = NULL;
197 
198 extern MS_S32  _s32AUDIOMutexReboot;
199 extern MS_BOOL g_bDSPLoadCode;
200 extern MS_U8 g_Common_PCM_IO_Init;
201 extern AUDIO_PCM_t *g_PCM[AUDIO_PCM_MAXNUM];
202 
203 extern MS_U8 MDrv_AUTH_IPCheck(MS_U8 u8Bit);
204 
205 //------------------------------------------------------------------------------
206 //  Global Functions
207 //------------------------------------------------------------------------------
208 //-----------------------------------------------------------------------------
209 ////////////////////////////////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////////////////////////////////
211 //
212 //        AUDIO Basic Read/Write Drv Function
213 //
214 ////////////////////////////////////////////////////////////////////////////////
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// @brief \b Function \b Name: MDrv_AUDIO_HDMI_RX_GetHdmiInAudioStatus()
218 /// @brief \b Function \b Description:  Return audio status.
219 /// @return MS_U16     \b : return structure which include pcm, non pcm, sampling rate.
220 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_RX_GetHdmiInAudioStatus(ST_HDMI_AUDIO_STATUS * p_hdmiAudioSts)221 MS_BOOL MDrv_AUDIO_HDMI_RX_GetHdmiInAudioStatus( ST_HDMI_AUDIO_STATUS *p_hdmiAudioSts)
222 {
223     return(HAL_AUDIO_HDMI_RX_GetHdmiInAudioStatus(p_hdmiAudioSts));
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 
228 ////////////////////////////////////////////////////////////////////////////////
229 /// @brief \b Function \b Name: MDrv_AUD_GetLibVer()
230 /// @brief \b Function \b Description:  This function is used to get version information for audio module
231 /// @return   MS_BOOL  \b : TRUE or FALSE
232 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUD_GetLibVer(const MSIF_Version ** ppVersion)233 MS_BOOL MDrv_AUD_GetLibVer(const MSIF_Version **ppVersion)
234 {
235     // No mutex check, it can be called before Init
236     if (!ppVersion)
237     {
238         return FALSE;
239     }
240 
241     *ppVersion = &_drv_aud_version;
242     return TRUE;
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// @brief \b Function \b Name: MDrv_AUDIO_ReadReg()
247 /// @brief \b Function \b Description:  This function is used to read the general register value
248 /// @param  u32RegAddr \b : Register address
249 /// @return MS_U16      \b : Register value
250 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_ReadReg(MS_U32 u32RegAddr)251 MS_U16 MDrv_AUDIO_ReadReg(MS_U32 u32RegAddr)
252 {
253     return (HAL_AUDIO_ReadReg(u32RegAddr));
254 }
255 
256 ////////////////////////////////////////////////////////////////////////////////
257 /// @brief \b Function \b Name: MDrv_AUDIO_WriteReg()
258 /// @brief \b Function \b Description:  This function is used to write value to general register
259 /// @param u32RegAddr  \b : Register address
260 /// @param u16Val       \b : Register value
261 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_WriteReg(MS_U32 u32RegAddr,MS_U16 u16Val)262 void MDrv_AUDIO_WriteReg(MS_U32 u32RegAddr, MS_U16  u16Val)
263 {
264     HAL_AUDIO_WriteReg(u32RegAddr, u16Val);
265 }
266 
267 ////////////////////////////////////////////////////////////////////////////////
268 /// @brief \b Function \b Name: MDrv_AUDIO_WriteMaskReg()
269 /// @brief \b Function \b Description:  This function is used to write mask value to general register
270 /// @param u32RegAddr  \b : Register address
271 /// @param u16Mask      \b : Mask value
272 /// @param u16Val       \b : Register value
273 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_WriteMaskReg(MS_U32 u32RegAddr,MS_U16 u16Mask,MS_U16 u16Val)274 void MDrv_AUDIO_WriteMaskReg(MS_U32 u32RegAddr, MS_U16  u16Mask, MS_U16  u16Val)
275 {
276     HAL_AUDIO_WriteMaskReg(u32RegAddr, u16Mask, u16Val);
277 }
278 
279 ////////////////////////////////////////////////////////////////////////////////
280 /// @brief \b Function \b Name: MDrv_AUDIO_ReadByte()
281 /// @brief \b Function \b Description:  This function is used to read the general register value
282 /// @param  u32RegAddr \b : Register address
283 /// @return MS_U8      \b : Register value
284 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_ReadByte(MS_U32 u32RegAddr)285 MS_U8 MDrv_AUDIO_ReadByte(MS_U32 u32RegAddr)
286 {
287     return (HAL_AUDIO_ReadByte(u32RegAddr));
288 }
289 
290 ////////////////////////////////////////////////////////////////////////////////
291 /// @brief \b Function \b Name: MDrv_AUDIO_WriteByte()
292 /// @brief \b Function \b Description:  This function is used to write value to general register
293 /// @param u32RegAddr  \b : Register address
294 /// @param u8Val       \b : Register value
295 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_WriteByte(MS_U32 u32RegAddr,MS_U8 u8Val)296 void MDrv_AUDIO_WriteByte(MS_U32 u32RegAddr, MS_U8  u8Val)
297 {
298     HAL_AUDIO_WriteByte(u32RegAddr, u8Val);
299 }
300 
301 ////////////////////////////////////////////////////////////////////////////////
302 /// @brief \b Function \b Name: MDrv_AUDIO_WriteMaskByte()
303 /// @brief \b Function \b Description:  This function is used to write mask value to general register
304 /// @param u32RegAddr  \b : Register address
305 /// @param u8Mask      \b : Mask value
306 /// @param u8Val       \b : Register value
307 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_WriteMaskByte(MS_U32 u32RegAddr,MS_U8 u8Mask,MS_U8 u8Val)308 void MDrv_AUDIO_WriteMaskByte(MS_U32 u32RegAddr, MS_U8  u8Mask, MS_U8  u8Val)
309 {
310     HAL_AUDIO_WriteMaskByte(u32RegAddr, u8Mask, u8Val);
311 }
312 
313 ////////////////////////////////////////////////////////////////////////////////
314 /// @brief \b Function \b Name: MDrv_AUDIO_DecReadByte()
315 /// @brief \b Function \b Description:  This function is used to read the Dec-DSP register value
316 /// @param u32RegAddr  \b : Register address
317 /// @return MS_U8      \b : Register value
318 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DecReadByte(MS_U32 u32RegAddr)319 MS_U8 MDrv_AUDIO_DecReadByte(MS_U32 u32RegAddr)
320 {
321     return (HAL_AUDIO_DecReadByte(u32RegAddr));
322 }
323 
324 ////////////////////////////////////////////////////////////////////////////////
325 /// @brief \b Function \b Name: MDrv_AUDIO_DecWriteByte()
326 /// @brief \b Function \b Description:  This function is used to write value to Dec_DSP register
327 /// @param u32RegAddr  \b : Register address
328 /// @param u8Val       \b : Register value
329 ///////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DecWriteByte(MS_U32 u32RegAddr,MS_U8 u8Val)330 void MDrv_AUDIO_DecWriteByte(MS_U32 u32RegAddr, MS_U8 u8Val)
331 {
332     HAL_AUDIO_DecWriteByte(u32RegAddr, u8Val);
333 }
334 
335 ////////////////////////////////////////////////////////////////////////////////
336 /// @brief \b Function \b Name: MDrv_AUDIO_SeReadByte()
337 /// @brief \b Function \b Description:  This function is used to read the Se-DSP register value
338 /// @param u32RegAddr  \b : Register address
339 /// @return MS_U8      \b : Register value
340 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SeReadByte(MS_U32 u32RegAddr)341 MS_U8 MDrv_AUDIO_SeReadByte(MS_U32 u32RegAddr)
342 {
343     return (HAL_AUDIO_SeReadByte(u32RegAddr));
344 }
345 
346 ////////////////////////////////////////////////////////////////////////////////
347 /// @brief \b Function \b Name: MDrv_AUDIO_SeWriteByte()
348 /// @brief \b Function \b Description:  This function is used to write value to Se_DSP register
349 /// @param u32RegAddr  \b : Register address
350 /// @param u8Val       \b : Register value
351 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SeWriteByte(MS_U32 u32RegAddr,MS_U8 u8Val)352 void MDrv_AUDIO_SeWriteByte(MS_U32 u32RegAddr, MS_U8  u8Val)
353 {
354     HAL_AUDIO_SeWriteByte(u32RegAddr, u8Val);
355 }
356 
357 ////////////////////////////////////////////////////////////////////////////////
358 /// @brief \b Function \b Name: MDrv_AUDIO_DecWriteMaskByte()
359 /// @brief \b Function \b Description:  This function is used to write mask value to Dec_DSP register
360 /// @param u32RegAddr  \b : Register address
361 /// @param u8Mask      \b : Mask value
362 /// @param u8Val       \b : Register value
363 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DecWriteMaskByte(MS_U32 u32RegAddr,MS_U8 u8Mask,MS_U8 u8Val)364 void MDrv_AUDIO_DecWriteMaskByte(MS_U32 u32RegAddr, MS_U8  u8Mask, MS_U8  u8Val)
365 {
366     HAL_AUDIO_DecWriteMaskByte(u32RegAddr, u8Mask, u8Val);
367 }
368 
369 ////////////////////////////////////////////////////////////////////////////////
370 /// @brief \b Function \b Name: MDrv_AUDIO_SeWriteMaskByte()
371 /// @brief \b Function \b Description:  This function is used to write mask value to Se_DSP register
372 /// @param u32RegAddr  \b : Register address
373 /// @param u8Mask      \b : Mask value
374 /// @param u8Val       \b : Register value
375 ////////////////////////////////////////////////////////////////////////////////
376 
MDrv_AUDIO_SeWriteMaskByte(MS_U32 u32RegAddr,MS_U8 u8Mask,MS_U8 u8Val)377 void MDrv_AUDIO_SeWriteMaskByte(MS_U32 u32RegAddr, MS_U8  u8Mask, MS_U8  u8Val)
378 {
379     HAL_AUDIO_SeWriteMaskByte(u32RegAddr, u8Mask, u8Val);
380 }
381 
382 ////////////////////////////////////////////////////////////////////////////////
383 /// @brief \b Function \b Name: MDrv_AUDIO_CheckBootOnInitState()
384 /// @brief \b Function \b Description:  This routine is used to check whether mboot load init script
385 /// @param void
386 /// @return MS_U16     \b : Mail Box value
387 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_CheckBootOnInitState(void)388 MS_BOOL MDrv_AUDIO_CheckBootOnInitState(void)
389 {
390     return HAL_AUDIO_CheckBootOnInitState();
391 }
392 
393 ////////////////////////////////////////////////////////////////////////////////
394 /// @brief \b Function \b Name: MDrv_AUDIO_WriteDecMailBox()
395 /// @brief \b Function \b Description:  This routine is used to read the Dec-DSP mail box value
396 /// @param u8ParamNum  \b : Mail box address
397 /// @return MS_U16     \b : Mail Box value
398 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_ReadDecMailBox(MS_U8 u8ParamNum)399 MS_U16 MDrv_AUDIO_ReadDecMailBox(MS_U8 u8ParamNum)
400 {
401     return(HAL_AUDIO_ReadMailBox(DSP_DEC, u8ParamNum));
402 }
403 
404 ////////////////////////////////////////////////////////////////////////////////
405 /// @brief \b Function \b Name: MDrv_AUDIO_WriteDecMailBox()
406 /// @brief \b Function \b Description:  This routine is used to write Dec-DSP mail box
407 /// @param u8ParamNum  \b : Mail box address
408 /// @param u16Data     \b : value
409 ////////////////////////////////////////////////////////////////////////////////
_MDrv_AUDIO_WriteDecMailBox(MS_U8 u8ParamNum,MS_U16 u16Data)410 void _MDrv_AUDIO_WriteDecMailBox(MS_U8 u8ParamNum, MS_U16 u16Data)
411 {
412     HAL_AUDIO_WriteMailBox(DSP_DEC, u8ParamNum, u16Data);
413 }
414 
415 ////////////////////////////////////////////////////////////////////////////////
416 /// @brief \b Function \b Name: MDrv_AUDIO_WriteSeMailBox()
417 /// @brief \b Function \b Description:  This routine is used to read the Dec-DSP mail box value
418 /// @param u8ParamNum  \b : Mail box address
419 /// @return MS_U16     \b : Mail Box value
420 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_ReadSeMailBox(MS_U8 u8ParamNum)421 MS_U16 MDrv_AUDIO_ReadSeMailBox(MS_U8 u8ParamNum)
422 {
423     return(HAL_AUDIO_ReadMailBox(DSP_SE, u8ParamNum));
424 }
425 
426 ////////////////////////////////////////////////////////////////////////////////
427 /// @brief \b Function \b Name: MDrv_AUDIO_WriteSeMailBox()
428 /// @brief \b Function \b Description:  This routine is used to write Dec-DSP mail box
429 /// @param u8ParamNum  \b : Mail box address
430 /// @param u16Data     \b : value
431 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_WriteSeMailBox(MS_U8 u8ParamNum,MS_U16 u16Data)432 void MDrv_AUDIO_WriteSeMailBox(MS_U8 u8ParamNum, MS_U16 u16Data)
433 {
434     HAL_AUDIO_WriteMailBox(DSP_SE, u8ParamNum, u16Data);
435 }
436 
437 
438 
439 //-----------------------------------------------------------------------------
440 ////////////////////////////////////////////////////////////////////////////////
441 ////////////////////////////////////////////////////////////////////////////////
442 //
443 //        AUDIO Initialize Relational Drv Function
444 //
445 ////////////////////////////////////////////////////////////////////////////////
446 ////////////////////////////////////////////////////////////////////////////////
447 
448 ////////////////////////////////////////////////////////////////////////////////
449 /// @brief \b Function \b Name: MDrv_AUDIO_InitMMIO()
450 /// @brief \b Function \b Description:  This routine is used to init audio MMIO
451 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_InitMMIO(void)452 void MDrv_AUDIO_InitMMIO(void)
453 {
454     MS_PHY u32NonPMBankSize;
455 
456 #ifndef CONFIG_MBOOT
457     if(_bMMIO_Init==TRUE)
458         return;
459 #endif
460 
461     // get MMIO base
462     if(MDrv_MMIO_GetBASE( &_gu32AudioRiuBaseAddr, &u32NonPMBankSize, MS_MODULE_AUDIO ) != TRUE)
463     {
464         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s\n", "Audio get base address failed\n");
465         return;
466     }
467     else
468     {
469         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG,  "MDrv_AUDIO_Init u32PnlRiuBaseAddr = %x\n", (unsigned int)_gu32AudioRiuBaseAddr);
470     }
471     HAL_AUDIO_Set_MMIO_BASE(_gu32AudioRiuBaseAddr);
472 
473     _bMMIO_Init = TRUE;
474 }
475 
476 ////////////////////////////////////////////////////////////////////////////////
477 /// @brief \b Function \b Name: MDrv_AUDIO_AttachInterrupt()
478 /// @brief \b Function \b Description:  This routine is used to attach/detach audio interrupts
479 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_AttachInterrupt(MS_BOOL bEnable)480 MS_BOOL MDrv_AUDIO_AttachInterrupt(MS_BOOL bEnable)
481 {
482     /*
483      * Note!
484      * HAL_AUDIO_Init() currently is designed to check if SE DSP is supported or not,
485      * so we need to call this function here!
486      */
487     MS_BOOL has_SE_DSP = HAL_AUDIO_Init(TRUE);
488 
489     /*
490      * Although MsOS_XXXInterrupt() can check if it's "Success" or "NOT Success",
491      * but we don't handle the failed case here!
492      */
493     if (bEnable)
494     {
495         MsOS_AttachInterrupt(E_INT_FIQ_DEC_DSP2UP, (InterruptCb)MDrv_AUDIO_DecDspISR);
496         MsOS_EnableInterrupt(E_INT_FIQ_DEC_DSP2UP);
497         if (has_SE_DSP)
498         {
499             MsOS_AttachInterrupt(E_INT_FIQ_SE_DSP2UP, (InterruptCb)MDrv_AUDIO_SeDspISR);
500             MsOS_EnableInterrupt(E_INT_FIQ_SE_DSP2UP);
501         }
502     }
503     else
504     {
505         MsOS_DisableInterrupt(E_INT_FIQ_DEC_DSP2UP);
506         MsOS_DetachInterrupt(E_INT_FIQ_DEC_DSP2UP);
507         if (has_SE_DSP)
508         {
509             MsOS_DisableInterrupt(E_INT_FIQ_SE_DSP2UP);
510             MsOS_DetachInterrupt(E_INT_FIQ_SE_DSP2UP);
511         }
512     }
513 
514     return TRUE;
515 }
516 
517 ////////////////////////////////////////////////////////////////////////////////
518 /// @brief \b Function \b Name: MDrv_AUDIO_Mutex_Init()
519 /// @brief \b Function \b Description: This routine is the initialization of Mutex for Audio module.
520 /// @param u8Standard  \b :
521 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_Mutex_Init(void)522 MS_BOOL MDrv_AUDIO_Mutex_Init(void)
523 {
524     MS_BOOL ret = TRUE;
525 
526     ret = HAL_AUDIO_Mutex_Init();
527 
528     return ret;
529 }
530 
531 ////////////////////////////////////////////////////////////////////////////////
532 /// @brief \b Function \b Name: MDrv_AUDIO_SHM_Init()
533 /// @brief \b Function \b Description: This routine is the initialization of SHM for Audio module.
534 /// @param u8Standard  \b :
535 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SHM_Init(void)536 MS_BOOL MDrv_AUDIO_SHM_Init(void)
537 {
538     MS_BOOL ret = TRUE;
539 
540     ret = MDrv_AUDIO_InitialVars();
541 
542     return ret;
543 }
544 
545 ////////////////////////////////////////////////////////////////////////////////
546 /// @brief \b Function \b Name: MDrv_AUDIO_Init()
547 /// @brief \b Function \b Description: This routine is the initialization for Audio module.
548 /// @param u8Standard  \b : Load Decoder type in audio initialize
549 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_Init(void)550 MS_BOOL MDrv_AUDIO_Init(void)
551 {
552     gAudioChipType = HAL_AUDIO_GetChipType();
553 
554     MDrv_AUDIO_InitMMIO();
555 
556     HAL_AUDIO_SetPlayFileFlag(DSP_DEC, 0);
557     HAL_AUDIO_SetPlayFileFlag(DSP_SE, 0);
558 
559     return TRUE;
560 }
561 
562 ////////////////////////////////////////////////////////////////////////////////
563 /// @brief \b Function \b Name: MDrv_AUDIO_SET_INIT_FLAG()
564 /// @brief \b Function \b Description: This routine set the initial status of Aduio module.
565 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SET_INIT_FLAG(MS_BOOL bSet)566 void MDrv_AUDIO_SET_INIT_FLAG(MS_BOOL bSet)
567 {
568     HAL_AUDIO_SET_INIT_FLAG(bSet);
569 }
570 
571 ////////////////////////////////////////////////////////////////////////////////
572 /// @brief \b Function \b Name: MDrv_AUDIO_GET_INIT_FLAG()
573 /// @brief \b Function \b Description: This routine get the initial status of Aduio module.
574 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GET_INIT_FLAG(void)575 MS_BOOL MDrv_AUDIO_GET_INIT_FLAG(void)
576 {
577     return HAL_AUDIO_GET_INIT_FLAG();
578 }
579 
580 ////////////////////////////////////////////////////////////////////////////////
581 /// @brief \b Function \b Name: MDrv_AUDIO_InitialVars()
582 /// @brief \b Function \b Description:  Initial variables in share memory
583 /// @param <IN>        \b NONE    :
584 /// @param <OUT>       \b NONE    :
585 /// @param <RET>       \b NONE    :
586 /// @param <GLOBAL>    \b NONE    :
587 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_InitialVars(void)588 MS_BOOL MDrv_AUDIO_InitialVars(void)
589 {
590     return HAL_AUDIO_InitialVars();
591 }
592 
593 ////////////////////////////////////////////////////////////////////////////////
594 /// @brief \b Function \b Name: MDrv_AUDIO_Close()
595 /// @brief \b Function \b Description: This routine is the close function for Audio module.
596 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_Close(void)597 MS_BOOL MDrv_AUDIO_Close(void)
598 {
599 
600     MDrv_AUDIO_AttachInterrupt(FALSE);
601 
602     return TRUE;
603 }
604 
605 ////////////////////////////////////////////////////////////////////////////////
606 /// @brief \b Function \b Name: MDrv_AUDIO_Open()
607 /// @brief \b Function \b Description: This routine is the open function for Audio module.
608 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_Open(void)609 MS_BOOL MDrv_AUDIO_Open(void)
610 {
611 
612     MDrv_AUDIO_AttachInterrupt(TRUE);
613 
614     return TRUE;
615 }
616 
617 ////////////////////////////////////////////////////////////////////////////////
618 /// @brief \b Function \b Name: MDrv_AUDIO_WriteInitTable()
619 /// @brief \b Function \b Description: This routine is used to write the audio initial table.
620 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_WriteInitTable(void)621 void MDrv_AUDIO_WriteInitTable(void)
622 {
623     DRVAUDIO_CHECK_SHM_INIT;
624 
625     g_AudioVars2->ChipRevision = MDrv_SYS_GetChipRev();
626 
627     HAL_AUDIO_WriteInitTable();
628 
629     return;
630 }
631 
632 ////////////////////////////////////////////////////////////////////////////////
633 /// @brief \b Function \b Name: MDrv_AUDIO_WritePreInitTable()
634 /// @brief \b Function \b Description: This routine is used to set power on DAC sequence before setting init table.
635 ////////////////////////////////////////////////////////////////////////////////
636 //Refine power on sequence for earphone & DAC pop noise issue
MDrv_AUDIO_WritePreInitTable(void)637 void MDrv_AUDIO_WritePreInitTable(void)
638 {
639     _PreInit = TRUE; // If open in Api layer, _PreInit will be true, to prevent do HAL_AUDIO_InitialVars() once
640 
641     HAL_AUDIO_WritePreInitTable();
642 
643    return;
644 }
645 
646 ////////////////////////////////////////////////////////////////////////////////
647 /// @brief \b Function \b Name: MDrv_AUDIO_WritePostInitTable()
648 /// @brief \b Function \b Description: This routine is used to enable earphone low power stage.
649 ////////////////////////////////////////////////////////////////////////////////
650 //Refine power on sequence for earphone & DAC pop noise issue
MDrv_AUDIO_EnaEarphone_LowPower_Stage(void)651 void MDrv_AUDIO_EnaEarphone_LowPower_Stage(void)
652 {
653    HAL_AUDIO_EnaEarphone_LowPower_Stage();
654    return;
655 }
656 
657 ////////////////////////////////////////////////////////////////////////////////
658 /// @brief \b Function \b Name: MDrv_AUDIO_WritePostInitTable()
659 /// @brief \b Function \b Description: This routine is used to enable earphone high driving stage.
660 ////////////////////////////////////////////////////////////////////////////////
661 //Refine power on sequence for earphone & DAC pop noise issue
MDrv_AUDIO_EnaEarphone_HighDriving_Stage(void)662 void MDrv_AUDIO_EnaEarphone_HighDriving_Stage(void)
663 {
664    HAL_AUDIO_EnaEarphone_HighDriving_Stage();
665    return;
666 }
667 
668 ////////////////////////////////////////////////////////////////////////////////
669 /// @brief \b Function \b Name: MDrv_AUDIO_SwResetMAD()
670 /// @brief \b Function \b Description: This function is used to software reset MAD
671 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SwResetMAD(void)672 void MDrv_AUDIO_SwResetMAD(void)
673 {
674     /* To prevent unexpected condition, set stop command to all R2/DSP */
675     MDrv_AUDIO_WriteStopDecTable();
676 
677     if (MDrv_AUDIO_CheckBootOnInitState() == TRUE)
678     {
679         HAL_AUDIO_SwResetMAD();
680     }
681 }
682 
683 ////////////////////////////////////////////////////////////////////////////////
684 /// @brief \b Function \b Name: MDrv_AUDIO_SetPowerOn()
685 /// @brief \b Function \b Description: This routine is used to execute DSP power on/down setting.
686 /// @param bPower_on   \b : TRUE --power on,
687 ///                         FALSE--power off
688 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetPowerOn(MS_BOOL bPower_on)689 void MDrv_AUDIO_SetPowerOn(MS_BOOL bPower_on)
690 {
691     HAL_AUDIO_SetPowerOn(bPower_on);
692 
693     if (bPower_on == FALSE)
694     {
695         MDrv_AUDIO_AttachInterrupt(FALSE);
696     }
697 }
698 
699 ////////////////////////////////////////////////////////////////////////////////
700 /// @brief \b Function \b Name: MDrv_AUDIO_SetDspBaseAddr()
701 /// @brief \b Function \b Description:  This function is used to set bin file base address in flash for Audio module.
702 /// @param u8Index     \b :
703 /// @param u32Bin_Base_Address    \b :
704 /// @param u32Mad_Base_Buffer_Adr \b :
705 ////////////////////////////////////////////////////////////////////////////////
_MDrv_AUDIO_SetDspBaseAddr(MS_U8 u8Index,MS_PHY phyBin_Base_Address,MS_PHY phyMad_Base_Buffer_Adr)706 void _MDrv_AUDIO_SetDspBaseAddr(MS_U8 u8Index, MS_PHY phyBin_Base_Address, MS_PHY phyMad_Base_Buffer_Adr)
707 {
708     HAL_AUDIO_SetDspBaseAddr(u8Index, phyBin_Base_Address, phyMad_Base_Buffer_Adr);
709 }
710 
711 ///////////////////////////////////////////////////////////////////////////////
712 ///
713 /// @brief \b Function \b Name: MDrv_AUDIO_GetDspBinBaseAddr()
714 /// @brief \b Function \b Description:  This function is used to get the Bin file base address.
715 /// @param u8Index     \b     :
716 /// @return MS_U32     \b     :
717 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GetDspBinBaseAddr(MS_U8 u8Index)718 MS_PHY MDrv_AUDIO_GetDspBinBaseAddr(MS_U8 u8Index)
719 {
720     return  (HAL_AUDIO_GetDspBinBaseAddr(u8Index));
721 }
722 
723 ////////////////////////////////////////////////////////////////////////////////
724 /// @brief \b Function \b Name: MDrv_AUDIO_GetDspMadBaseAddr()
725 /// @brief \b Function \b Description:  This function is used to get the MAD base address.
726 /// @param u8Index     \b     :
727 /// @return MS_U32     \b     :
728 ////////////////////////////////////////////////////////////////////////////////
_MDrv_AUDIO_GetDspMadBaseAddr(MS_U8 u8Index)729 MS_PHY _MDrv_AUDIO_GetDspMadBaseAddr(MS_U8 u8Index)
730 {
731     return (HAL_AUDIO_GetDspMadBaseAddr(u8Index));
732 }
733 
734 ///////////////////////////////////////////////////////////////////////////////
735 ///
736 /// @brief \b Function \b Name: MDrv_AUDIO_DspBootOnDDR()
737 /// @brief \b Function \b Description:  Enable DSP load / reload code from DDR
738 /// @param bEnable     \b : 0 -- load code from FLASH,
739 ///                         1 -- load code from DDR
740 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DspBootOnDDR(MS_BOOL bEnable)741 void MDrv_AUDIO_DspBootOnDDR(MS_BOOL bEnable)
742 {
743     HAL_AUDIO_DspBootOnDDR(bEnable);
744 }
745 
746 ////////////////////////////////////////////////////////////////////////////////
747 /// @brief \b Function \b Name: MDrv_AUDIO_DecoderLoadCode()
748 /// @brief \b Function \b Description: This routine is used to load Dec-DSP code
749 /// @return MS_BOOL    \b : TRUE --DEC-DSP load code okay,
750 ///                         FALSE--DEC-DSP load code fail
751 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DecoderLoadCode(void)752 MS_BOOL MDrv_AUDIO_DecoderLoadCode(void)
753 {
754     return HAL_AUDIO_DecoderLoadCode();
755 }
756 
757 ////////////////////////////////////////////////////////////////////////////////
758 /// @brief \b Function \b Name: MDrv_AUDIO_SeSystemLoadCode()
759 /// @brief \b Function \b Description: This routine is used to load DSP code for SE-DSP .
760 /// @return MS_BOOL    \b : TRUE --DEC-DSP load code okay,
761 ///                         FALSE--DEC-DSP load code fail
762 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SeSystemLoadCode(void)763 MS_BOOL MDrv_AUDIO_SeSystemLoadCode(void)
764 {
765     return HAL_AUDIO_SeSystemLoadCode();
766 }
767 
768 ////////////////////////////////////////////////////////////////////////////////
769 /// @brief \b Function \b Name: MDrv_AUDIO_RebootDecDSP()
770 /// @brief \b Function \b Description:  This routine reboot Decoder DSP.
771 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_RebootDSP(MS_BOOL bDspType)772 void MDrv_AUDIO_RebootDSP(MS_BOOL bDspType)
773 {
774     if (bDspType==DSP_SE)
775     {
776         MDrv_MAD2_RebootDsp();  //reboot sndEff DSP
777     }
778     else
779     {
780         MDrv_AUDIO_RebootDecDSP();  //reboot DEC DSP
781     }
782 }
783 
784 ////////////////////////////////////////////////////////////////////////////////
785 /// @brief \b Function \b Name: MDrv_AUDIO_TriggerSifPLL()
786 /// @brief \b Function \b Description:  This function is used to initialize SIF analog part .
787 ////////////////////////////////////////////////////////////////////////////////
_MDrv_AUDIO_TriggerSifPLL(void)788 void _MDrv_AUDIO_TriggerSifPLL(void)
789 {
790     HAL_SIF_TriggerSifPLL();
791 }
792 
793 
794 ////////////////////////////////////////////////////////////////////////////////
795 /// @brief \b Function \b Name: MDrv_AUDIO_DecDspISR()
796 /// @brief \b Function \b Description:  This function is used to set the Decoder DSP ISR
797 ////////////////////////////////////////////////////////////////////////////////
798 #if defined (MSOS_TYPE_NOS)
MDrv_AUDIO_DecDspISR(MHAL_SavedRegisters * pHalReg,MS_U32 u32Data)799 void MDrv_AUDIO_DecDspISR(MHAL_SavedRegisters *pHalReg, MS_U32 u32Data)
800 #else // Ecos and Linux
801 void MDrv_AUDIO_DecDspISR( InterruptNum eIntNum )
802 #endif
803 {
804     #if defined (MSOS_TYPE_NOS)
805         UNUSED(pHalReg);
806         UNUSED(u32Data);
807     #else // Ecos and Linux
808         UNUSED(eIntNum);
809     #endif
810 
811     HAL_AUDIO_DecDspISR();
812 
813     /* perfrom DEC CallBack for VoIP applications */
814     if(audio_dec_app_callbk != NULL)
815     {
816         (*audio_dec_app_callbk)(HAL_AUDIO_ReadByte(REG_D2M_MAILBOX_DEC_ISRCMD/*REG_D2M_MAILBOX_DEC_ISRCMD*/));
817     }
818 
819     MsOS_EnableInterrupt(E_INT_FIQ_DEC_DSP2UP);
820 }
821 
822 ////////////////////////////////////////////////////////////////////////////////
823 /// @brief \b Function \b Name: MDrv_AUDIO_DecDspISR()
824 /// @brief \b Function \b Description:  This function is used to set the Decoder DSP ISR
825 ////////////////////////////////////////////////////////////////////////////////
826 #if defined (MSOS_TYPE_NOS)
MDrv_AUDIO_SeDspISR(MHAL_SavedRegisters * pHalReg,MS_U32 u32Data)827     void MDrv_AUDIO_SeDspISR(MHAL_SavedRegisters *pHalReg, MS_U32 u32Data)
828 #else // Ecos and Linux
829     void MDrv_AUDIO_SeDspISR( InterruptNum eIntNum )
830 #endif
831 {
832     #if defined (MSOS_TYPE_NOS)
833         UNUSED(pHalReg);
834         UNUSED(u32Data);
835     #else // Ecos and Linux
836         UNUSED(eIntNum);
837     #endif
838 
839     HAL_AUDIO_SeDspISR();
840 
841     /* perfrom SE CallBack for VoIP applications */
842     if(audio_se_app_callbk != NULL)
843     {
844         (*audio_se_app_callbk)(HAL_AUDIO_ReadByte(REG_D2M_MAILBOX_SE_ISRCMD/*REG_D2M_MAILBOX_SE_ISRCMD*/));
845     }
846 
847     MsOS_EnableInterrupt(E_INT_FIQ_SE_DSP2UP);
848 }
849 
850 ////////////////////////////////////////////////////////////////////////////////
851 /// @brief \b Function \b Name: MDrv_AUDIO_SetPlayFileFlag()
852 /// @brief \b Function \b Description:  This function is used to set the Decoder DSP ISR
853 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetPlayFileFlag(MS_BOOL bDspType,MS_BOOL bSet)854 void MDrv_AUDIO_SetPlayFileFlag(MS_BOOL bDspType, MS_BOOL bSet)
855 {
856     HAL_AUDIO_SetPlayFileFlag(bDspType, bSet);
857 }
858 
859 ////////////////////////////////////////////////////////////////////////////////
860 /// @brief \b Function \b Name: MDrv_AUDIO_GetPlayFileFlag()
861 /// @brief \b Function \b Description:  This function is used to set the Decoder DSP ISR
862 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GetPlayFileFlag(MS_BOOL bDspType)863 MS_BOOL MDrv_AUDIO_GetPlayFileFlag(MS_BOOL bDspType)
864 {
865     return (HAL_AUDIO_GetPlayFileFlag(bDspType));
866 }
867 
868 ////////////////////////////////////////////////////////////////////////////////
869 /// @brief \b Function \b Name: MDrv_AUDIO_GetEncodeDoneFlag()
870 /// @brief \b Function \b Description:  This function is used to get the Encoder flag status
871 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GetEncodeDoneFlag(void)872 MS_BOOL MDrv_AUDIO_GetEncodeDoneFlag(void)
873 {
874     return (HAL_AUDIO_GetEncodeDoneFlag());
875 }
876 
877 //======================================================================
878 
879 ////////////////////////////////////////////////////////////////////////////////
880 //                                                                                                                                 ///
881 //        AUDIO I/O Config Relational Drv Function                                                             ///
882 //                                                                                                                                 ///
883 ////////////////////////////////////////////////////////////////////////////////
884 ////////////////////////////////////////////////////////////////////////////////
885 /// @brief \b Function \b Name: MDrv_AUDIO_GetPathGroup()
886 /// @brief \b Function \b Description: This routine is used to get Audio path group type .
887 /// @param output      \b : Audio output path-group type
888 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GetPathGroup(void)889 AUDIO_PATH_GROUP_TYPE MDrv_AUDIO_GetPathGroup(void)
890 {
891     return(HAL_AUDIO_GetPathGroup());
892 }
893 
894 ////////////////////////////////////////////////////////////////////////////////
895 /// @brief \b Function \b Name: MDrv_AUDIO_SetNormalPath()
896 /// @brief \b Function \b Description: This routine is used to set the topalogy for Audio Input .
897 /// @param path        \b : Audio DSP channel
898 /// @param input       \b : Audio input type
899 /// @param output      \b : Audio output type
900 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetNormalPath(AUDIO_PATH_TYPE path,AUDIO_INPUT_TYPE input,AUDIO_OUTPUT_TYPE output)901 void MDrv_AUDIO_SetNormalPath(AUDIO_PATH_TYPE path, AUDIO_INPUT_TYPE input, AUDIO_OUTPUT_TYPE output)
902 {
903     HAL_AUDIO_SetNormalPath(path, input, output);
904 }
905 
906 ////////////////////////////////////////////////////////////////////////////////
907 /// @brief \b Function \b Name: MDrv_AUDIO_SetInputPath()
908 /// @brief \b Function \b Description: This routine is used to set the topalogy for Audio Input and Output.
909 /// @param u8Path      \b : Audio DSP channel
910 /// @param u8Input     \b : Audio input type
911 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetInputPath(AUDIO_INPUT_TYPE u8Input,AUDIO_PATH_TYPE u8Path)912 void MDrv_AUDIO_SetInputPath( AUDIO_INPUT_TYPE u8Input, AUDIO_PATH_TYPE u8Path)
913 {
914     MS_U8 path;
915 
916     path=(MS_U8)u8Path;
917 
918 
919     if(u8Path == AUDIO_PATH_NULL)
920     {
921         return;    // path0~3 are used for multi-channel ; we've fixed the setting in audio init table.
922     }
923     HAL_AUDIO_SetInputPath(u8Input ,u8Path);
924 
925     if((u8Input != AUDIO_HDMI_INPUT) && (u8Input != AUDIO_DSP1_HDMI_INPUT) && (u8Input != AUDIO_DSP3_HDMI_INPUT))
926     {
927             HAL_AUDIO_WriteMaskByte((REG_AUDIO_MUTE_CTRL1+1) + (path-4)*2, 0x78, 0x00);
928     }
929     else if(u8Input == AUDIO_HDMI_INPUT)  // HDMI pcm in
930     {
931             HAL_AUDIO_WriteMaskByte((REG_AUDIO_MUTE_CTRL1+1) + (path-4)*2, 0x78, 0x78);
932     }
933     else if((u8Input == AUDIO_DSP1_HDMI_INPUT) ||(u8Input == AUDIO_DSP3_HDMI_INPUT))  // HDMI non-PCM in
934     {
935         HAL_AUDIO_WriteMaskByte((REG_AUDIO_MUTE_CTRL1+1) + (path-4)*2, 0x78, 0x70);
936     }
937 }
938 
939 ////////////////////////////////////////////////////////////////////////////////
940 /// @brief \b Function \b Name: MDrv_AUDIO_SetOutPath()
941 /// @brief \b Function \b Description: This routine is used to set the topalogy for Audio Output.
942 /// @param u8Path      \b : Audio DSP channel
943 /// @param u8Output    \b : Audio output type
944 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetOutputPath(AUDIO_PATH_TYPE u8Path,AUDIO_OUTPUT_TYPE u8Output)945 void MDrv_AUDIO_SetOutputPath(AUDIO_PATH_TYPE u8Path, AUDIO_OUTPUT_TYPE u8Output)
946 {
947     HAL_AUDIO_SetOutputPath(u8Path, u8Output);
948 }
949 
950 ////////////////////////////////////////////////////////////////////////////////
951 /// @brief \b Function \b Name: MDrv_AUDIO_SetInternalPath()    @@VVV
952 /// @brief \b Function \b Description: This routine is used to set the topalogy for Audio Output.
953 /// @param <IN>        \b u8Path    : Audio internal path
954 /// @param <IN>        \b output    : Audio output type
955 /// @param <OUT>       \b NONE    :
956 /// @param <RET>       \b  NONE    :
957 /// @param <GLOBAL>    \b NONE    :
958 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetInternalPath(AUDIO_INTERNAL_PATH_TYPE u8Path,AUDIO_OUTPUT_TYPE u8Output)959 void MDrv_AUDIO_SetInternalPath(AUDIO_INTERNAL_PATH_TYPE u8Path,  AUDIO_OUTPUT_TYPE u8Output)
960 {
961     HAL_AUDIO_SetInternalPath(u8Path, u8Output);
962 }
963 
964 ////////////////////////////////////////////////////////////////////////////////
965 /// @brief \b Function \b Name: MDrv_AUDIO_FwTriggerDSP()
966 /// @brief \b Function \b Description:  This routine send a PIO11 interrupt to DSP with a command on 0x2D34.
967 /// @param u16Cmd      \b : 0xF0-- for MHEG5 file protocol
968 ///////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_FwTriggerDSP(MS_U16 u16Cmd)969 void MDrv_AUDIO_FwTriggerDSP(MS_U16 u16Cmd)
970 {
971     HAL_AUDIO_FwTriggerDSP((MS_U16)u16Cmd);
972 }
973 
974 ////////////////////////////////////////////////////////////////////////////////
975 /// @brief \b Function \b Name: MDrv_AUDIO_I2S_SetMode()
976 /// @brief \b Function \b Description:  This routine is used to Set the I2S output mode.
977 /// @param u8Mode      \b : MCLK , MS_U16_WIDTH , SOURCE_CH , FORMAT
978 /// @param u8Val      \b : Please reference the register table 0x2C8C & 0x2C8D .
979 ///////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_I2S_SetMode(MS_U8 u8Mode,MS_U8 u8Val)980 void MDrv_AUDIO_I2S_SetMode(MS_U8 u8Mode, MS_U8  u8Val)
981 {
982    _HAL_AUDIO_I2S_SetMode(u8Mode, u8Val);
983 }
984 
985 ////////////////////////////////////////////////////////////////////////////////
986 /// @brief \b Function \b Name: MDrv_AUDIO_ReadDspCodeType()
987 /// @brief \b Function \b Description:  This routine is used to read the DSP code type.
988 /// @return MS_U8      \b : DSP code type
989 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_ReadDspCodeType(void)990 MS_U8 MDrv_AUDIO_ReadDspCodeType(void)
991 {
992     return HAL_AUDIO_GetDspCodeType();
993 }
994 
995 ////////////////////////////////////////////////////////////////////////////////
996 /// @brief \b Function \b Name: MDrv_AUDIO_BT_SetUploadRate()
997 /// @brief \b Function \b Description:  According Blue tooth upload path, for different sampling rate setting the Synthesizer.
998 /// @param bEnable     \b : 0 -- Disable Blue Tooth upload,
999 ///                         1 -- Enable Blue Tooth upload
1000 /// @param u8Samprate  \b : Sampling Rate
1001 ///                         0--no change,
1002 ///                         1--48KHz,
1003 ///                         2--44KHz,
1004 ///                         3--32KHz
1005 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_BT_SetUploadRate(MS_BOOL bEnable,MS_U8 u8Samprate)1006 void MDrv_AUDIO_BT_SetUploadRate(MS_BOOL bEnable,MS_U8 u8Samprate)
1007 {
1008     HAL_AUDIO_BT_SetUploadRate(bEnable,u8Samprate);
1009 }
1010 
1011 ////////////////////////////////////////////////////////////////////////////////
1012 /// @brief \b Function \b Name: MDrv_AUDIO_BT_SetBufferCounter()
1013 /// @brief \b Function \b Description:  Set the DDR buffer according the sampling rate and the frame time
1014 /// @param u32Counter  \b : if the sampling rate is 48KHz, the frame time is 40ms.
1015 ///                         ==> the frame buffer size is 48000*0x04*2 (L/R) *2(Bytes/sample) = 0x1E00,
1016 ///                             the counter is 0x1E00/8 = 960 (For 1*Burst DMA)
1017 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_BT_SetBufferCounter(MS_U32 u32Counter)1018 void MDrv_AUDIO_BT_SetBufferCounter(MS_U32 u32Counter)
1019 {
1020     HAL_AUDIO_BT_SetBufferCounter(u32Counter);
1021 }
1022 
1023 ////////////////////////////////////////////////////////////////////////////////
1024 /// @brief \b Function \b Name: MDrv_AUDIO_USBPCM_Enable()  @@Need_Modify
1025 /// @brief \b Function \b Description:  Enable/ Disable the path of USB PCM
1026 /// @param <IN>        \b bEnable : on: TRUE, off: FALSE
1027 /// @param <OUT>       \b NONE    :
1028 /// @param <RET>       \b NONE    :
1029 /// @param <GLOBAL>    \b NONE    :
1030 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_USBPCM_Enable(MS_BOOL bEnable)1031 void MDrv_AUDIO_USBPCM_Enable(MS_BOOL bEnable)
1032 {
1033     HAL_AUDIO_USBPCM_Enable(bEnable);
1034 }
1035 
1036 ////////////////////////////////////////////////////////////////////////////////
1037 /// @brief \b Function \b Name: MDrv_AUDIO_USBPCM_SetFlag()  @@Need_Modify
1038 /// @brief \b Function \b Description:  clear interrupt flag for USBPCM function
1039 ///                    \b               (Encoder path)
1040 /// @param <IN>        \b bEnable :  set false to clean interrupt flag
1041 /// @param <OUT>       \b NONE    :
1042 /// @param <RET>       \b NONE    :
1043 /// @param <GLOBAL>    \b NONE    :
1044 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_USBPCM_SetFlag(MS_BOOL bEnable)1045 void MDrv_AUDIO_USBPCM_SetFlag(MS_BOOL bEnable)
1046 {
1047     HAL_AUDIO_USBPCM_SetFlag(bEnable);
1048 }
1049 
1050 ////////////////////////////////////////////////////////////////////////////////
1051 /// @brief \b Function \b Name: MDrv_AUDIO_USBPCM_GetFlag()  @@Need_Modify
1052 /// @brief \b Function \b Description:  Get interrupt flag for USBPCM function
1053 ///                    \b               (Encoder path)
1054 /// @param <IN>        \b NONE    :
1055 /// @param <OUT>       \b NONE    :
1056 /// @param <RET>       \b BOOL    :   interrupt flag
1057 /// @param <GLOBAL>    \b NONE    :
1058 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_USBPCM_GetFlag(void)1059 MS_BOOL MDrv_AUDIO_USBPCM_GetFlag(void)
1060 {
1061     return HAL_AUDIO_USBPCM_GetFlag();
1062 }
1063 
1064 ////////////////////////////////////////////////////////////////////////////////
1065 /// @brief \b Function \b Name: MDrv_AUDIO_USBPCM_GetMemInfo()  @@Need_Modify
1066 /// @brief \b Function \b Description:  Get memory address and size for USBPCM function
1067 ///                    \b               (Encoder path)
1068 /// @param <IN>        \b NONE    :
1069 /// @param <OUT>       \b MS_U32  : address, size
1070 /// @param <RET>       \b NONE    :
1071 /// @param <GLOBAL>    \b NONE    :
1072 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_USBPCM_GetMemInfo(AUDIO_UPLOAD_INFO * uploadInfo)1073 void MDrv_AUDIO_USBPCM_GetMemInfo(AUDIO_UPLOAD_INFO *uploadInfo)
1074 {
1075 
1076     HAL_AUDIO_USBPCM_GetMemInfo(uploadInfo);
1077 }
1078 
1079 ////////////////////////////////////////////////////////////////////////////////
1080 /// @brief \b Function \b Name: MDrv_AUDIO_ReadDspCounter()
1081 /// @brief \b Function \b Description:  Read the DSP running counter
1082 /// @param CounterType \b  :
1083 ///                 - DSP_DEC_MAIN_COUNTER ==> Decoder DSP Main loop counter
1084 ///                 - DSP_DEC_TIMER_COUNTER ==> Decoder Timer counter
1085 ///                 - DSP_SE_MAIN_COUNTER ==> SE DSP Main loop counter
1086 ///                 - DSP_SE_TIMER_COUNTER ==> SE Timer counter
1087 ///                 - DSP_SE_ISR_COUNTER ==> SE Interrupt ISR counter
1088 ///                 - DEC_R2_MAIN_COUNTER   ==> DEC R2 Main loop counter
1089 ///                 - DEC_R2_TIMER_COUNTER  ==> DEC R2 Timer counter
1090 ///                 - SND_R2_MAIN_COUNTER   ==> SND R2 Main loop counter
1091 ///                 - SND_R2_TIMER_COUNTER  ==> SND R2 Timer counter
1092 /// @return MS_U8      \b  : Running counter value
1093 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_ReadDspCounter(AUDIO_DSP_COUNTER_TYPE CounterType)1094 MS_U8 MDrv_AUDIO_ReadDspCounter(AUDIO_DSP_COUNTER_TYPE  CounterType)
1095 {
1096        return HAL_AUDIO_ReadDspCounter(CounterType);
1097 }
1098 
1099 
1100 ////////////////////////////////////////////////////////////////////////////////
1101 /// @brief \b Function \b Name: MDrv_AuProcessPowerDown_Wait()
1102 /// @brief \b Function \b Description: This routine is used to DSP power-down wait function.
1103 /// @param bEnable     \b : TRUE --Not wait,
1104 ///                         FALSE--wait
1105 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetPowerDownWait(MS_BOOL bEnable)1106 void MDrv_AUDIO_SetPowerDownWait(MS_BOOL bEnable)
1107 {
1108     HAL_AUDIO_SetPowerDownWait(bEnable);
1109 }
1110 
1111 ////////////////////////////////////////////////////////////////////////////////
1112 /// @brief \b Function \b Name: MDrv_AUDIO_IsDTV()
1113 /// @brief \b Function \b Description:  Report the decoder type is ATV or DTV
1114 /// @return MS_BOOL    \b : 0 -> ATV , 1 -> DTV
1115 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_IsDTV(void)1116 MS_BOOL MDrv_AUDIO_IsDTV(void)
1117 {
1118     return HAL_AUDIO_GetIsDtvFlag();
1119 }
1120 
1121 ////////////////////////////////////////////////////////////////////////////////
1122 /// @brief \b Function \b Name: MDrv_AUDIO_SetFading()
1123 /// @brief \b Function \b Description:  This routine is used to set the Fading response time
1124 /// @param u32VolFading \b : Fading response time parameter
1125 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetFading(MS_U32 u32VolFading)1126 void MDrv_AUDIO_SetFading(MS_U32 u32VolFading)
1127 {
1128     HAL_AUDIO_Set_Fading(u32VolFading);
1129 }
1130 
1131 //-----------------------------------------------------------------------------
1132 ////////////////////////////////////////////////////////////////////////////////
1133 ////////////////////////////////////////////////////////////////////////////////
1134 //
1135 //        AUDIO SPDIF Relational Drv Function
1136 //
1137 ////////////////////////////////////////////////////////////////////////////////
1138 ////////////////////////////////////////////////////////////////////////////////
1139 //-----------------------------------------------------------------------------
1140 
1141 ////////////////////////////////////////////////////////////////////////////////
1142 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_HWEN()
1143 /// @brief \b Function \b Description:  This routine is used to enable S/PDIF output (Hardware)
1144 /// @param bEnable     \b : 0--Disable S/PDIF out,
1145 ///                         1--Enable S/PDIF out
1146 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_HWEN(MS_U8 bEnable)1147 void MDrv_AUDIO_SPDIF_HWEN(MS_U8 bEnable)
1148 {
1149     _HAL_AUDIO_SPDIF_HWEN((MS_BOOL)bEnable);
1150 }
1151 
1152 ////////////////////////////////////////////////////////////////////////////////
1153 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_SetMute()
1154 /// @brief \b Function \b Description:  This routine is used to enable S/PDIF output (Hardware)
1155 /// @param bEnMute     \b : 0--Disable mute,
1156 ///                         1--Enable mute
1157 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_SetMute(MS_U8 bEnMute)1158 void MDrv_AUDIO_SPDIF_SetMute(MS_U8 bEnMute)
1159 {
1160     DRVAUDIO_CHECK_SHM_INIT;
1161 
1162     g_AudioVars2->g_SPDIF_MuteStatus = bEnMute;
1163 
1164     _HAL_AUDIO_SPDIF_SetMute((MS_BOOL)bEnMute);
1165 }
1166 
1167 ////////////////////////////////////////////////////////////////////////////////
1168 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_SetMode()
1169 /// @brief \b Function \b Description:  This routine is used to set S/PDIF output mode
1170 /// @param u8Spdif_mode \b : Reg_2D2E
1171 ///                         - bit[0] = 0: spdif enable, 1: spdif disable (Se-DSP)
1172 ///                         - bit[1] = 0: PCM mode,     1: non-PCM mode
1173 ///                         - bit[2] = 1: non-PCM NULL Payload
1174 /// @param u8Input_src \b : DTV
1175 ///                         1 : ATV,
1176 ///                         2 : HDMI,
1177 ///                         3 : ADC,
1178 ///                         4 : CardReader,
1179 ///                         5 : SPDIF
1180 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_SetMode(MS_U8 u8Spdif_mode,MS_U8 u8Input_src)1181 void MDrv_AUDIO_SPDIF_SetMode(MS_U8 u8Spdif_mode, MS_U8 u8Input_src)
1182 {
1183     HAL_AUDIO_SPDIF_SetMode(u8Spdif_mode, u8Input_src);
1184 }
1185 
1186 ////////////////////////////////////////////////////////////////////////////////
1187 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_GetMode()
1188 /// @brief \b Function \b Description:  This routine is used to get S/PDIF mode.
1189 /// @return MS_U8      \b :  Se-DSP 0x2D2E value
1190 ///                        - u8Spdif_mode = 0x0 : SPDIF enable, PCM mode
1191 ///                        - u8Spdif_mode = 0x1 : SPDIF OFF
1192 ///                        - u8Spdif_mode = 0x2 : SPDIF enable, non-PCM mode
1193 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_GetMode(void)1194 MS_U8 MDrv_AUDIO_SPDIF_GetMode(void)
1195 {
1196     return _HAL_AUDIO_SPDIF_GetMode();
1197 }
1198 
1199 ////////////////////////////////////////////////////////////////////////////////
1200 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_ByPassChannel()
1201 /// @brief \b Function \b Description:  ByPass the SPDIF channel (CH4)
1202 /// @param bEnable     \b :  TRUE --BYPASS CH4,
1203 ///                          FALSE--OPEN CH4
1204 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_ByPassChannel(MS_BOOL bEnable)1205 void MDrv_AUDIO_SPDIF_ByPassChannel(MS_BOOL bEnable)
1206 {
1207     _HAL_AUDIO_SPDIF_ByPassChannel(bEnable);
1208 }
1209 
1210 ////////////////////////////////////////////////////////////////////////////////
1211 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_SetSCMS()
1212 /// @brief \b Function \b Description:  This routine is used to set SPDIF SCMS.
1213 /// @param C_bit_en  \b : copy right control bit
1214 /// @param L_bit_en  \b : generation bit
1215 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_SetSCMS(MS_U8 C_bit_en,MS_U8 L_bit_en)1216 void MDrv_AUDIO_SPDIF_SetSCMS(MS_U8 C_bit_en, MS_U8 L_bit_en)
1217 {
1218     HAL_AUDIO_SPDIF_SetSCMS(C_bit_en, L_bit_en);
1219 }
1220 
1221 ////////////////////////////////////////////////////////////////////////////////
1222 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_GetSCMS()
1223 /// @brief \b Function \b Description:  This routine is used to get SPDIF SCMS.
1224 /// @return MS_U8      \b :  SCMS[0] = C bit status, SCMS[1] = L bit status
1225 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_GetSCMS(void)1226 MS_U8 MDrv_AUDIO_SPDIF_GetSCMS(void)
1227 {
1228     return(HAL_AUDIO_SPDIF_GetSCMS());
1229 }
1230 
1231 ////////////////////////////////////////////////////////////////////////////////
1232 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_SetChannelStatus()
1233 /// @brief \b Function \b Description:  This routine is used to set S/PDIF CS mode.
1234 /// @return MS_U8      \b :
1235 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CS_MODE_TYPE eType,SPDIF_CS_MODE_VALUE eValue)1236 void MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CS_MODE_TYPE eType, SPDIF_CS_MODE_VALUE eValue)
1237 {
1238     HAL_AUDIO_SetChannelStatus(eType, eValue);
1239 }
1240 
1241 ////////////////////////////////////////////////////////////////////////////////
1242 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_ChannelStatus_CTRL()
1243 /// @brief \b Function \b Description:  This routine is used to control SPDIF CS in detail.
1244 /// @return MS_U8      \b :
1245 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_ChannelStatus_CTRL(AUDIO_SPDIF_CS_TYPE cs_mode,AUDIO_SPDIF_CS_TYPE_STATUS status)1246 MS_BOOL MDrv_AUDIO_SPDIF_ChannelStatus_CTRL(AUDIO_SPDIF_CS_TYPE cs_mode, AUDIO_SPDIF_CS_TYPE_STATUS status)
1247 {
1248     return(HAL_AUDIO_SPDIF_ChannelStatus_CTRL(cs_mode, status));
1249 }
1250 
1251 ////////////////////////////////////////////////////////////////////////////////
1252 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_SetOutputType()
1253 /// @brief \b Function \b Description:  New create to set S/PDIF output format
1254 /// @param eType \b :
1255 ///    SPDIF_OUT_PCM ==> S/PDIF always output PCM
1256 ///    SPDIF_OUT_AUTO ==> S/PDIF OUTPUT PCM or non-PCM automatic
1257 ///    SPDIF_OUT_BYPASS ==> S/PDIF OUTPUT the by-pass data from HDMI
1258 ///    SPDIF_OUT_NONE ==> S/PDIF OUTPUT nothing
1259 /// @param eSource \b : DTV
1260 ///    E_AUDIO_INFO_DTV_IN==> DTV input
1261 ///    E_AUDIO_INFO_ATV_IN==> ATV input
1262 ///    E_AUDIO_INFO_HDMI_IN==> HDMI Input
1263 ///    E_AUDIO_INFO_ADC_IN==> ADC input mode
1264 ///    E_AUDIO_INFO_MM_IN==> MM mode
1265 ///    E_AUDIO_INFO_SPDIF_IN==> SPDIF input mode
1266 ///    E_AUDIO_INFO_KTV_IN==> KTV input mode
1267 ///    E_AUDIO_INFO_GAME_IN==> Game mode
1268 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_SetOutputType(AUDIO_SOURCE_INFO_TYPE eSource,AUDIO_SPDIF_OUTPUT_TYPE eType)1269 void MDrv_AUDIO_SPDIF_SetOutputType (AUDIO_SOURCE_INFO_TYPE eSource, AUDIO_SPDIF_OUTPUT_TYPE eType)
1270 {
1271      HAL_AUDIO_SPDIF_SetOutputType(eSource, eType);
1272 }
1273 
1274 ////////////////////////////////////////////////////////////////////////////////
1275 /// @brief \b Function \b Name: HAL_AUDIO_Digital_Out_SetChannelStatus()
1276 /// @brief \b Function \b Description: This routine is used to set SPDIF/HDMI/ARC channel status.
1277 /// @param <IN>        \b   eType   :
1278 /// @param <OUT>       \b NONE    :
1279 /// @param <RET>       \b NONE    :
1280 ////////////////////////////////////////////////////////////////////////////////
Mdrv_AUDIO_DigitalOut_SetChannelStatus(DIGITAL_OUTPUT_TYPE ePath,Digital_Out_Channel_Status_t * stChannelStatus)1281 MS_BOOL Mdrv_AUDIO_DigitalOut_SetChannelStatus(DIGITAL_OUTPUT_TYPE ePath, Digital_Out_Channel_Status_t *stChannelStatus)
1282 {
1283     MS_BOOL RET = FALSE;
1284     if (gDigitalOutChannelStatusFuncPtr != NULL)
1285     {
1286         RET = gDigitalOutChannelStatusFuncPtr(ePath, stChannelStatus);
1287     }
1288 
1289     return RET;
1290 }
1291 
1292 //-----------------------------------------------------------------------------
1293 ////////////////////////////////////////////////////////////////////////////////
1294 ////////////////////////////////////////////////////////////////////////////////
1295 //
1296 //        AUDIO HDMI Relational Drv Function
1297 //
1298 ////////////////////////////////////////////////////////////////////////////////
1299 ////////////////////////////////////////////////////////////////////////////////
1300 //-----------------------------------------------------------------------------
1301 
1302 ////////////////////////////////////////////////////////////////////////////////
1303 /// @brief \b Function \b Name: MDrv_AUDIO_HDMI_Tx_SetMute()
1304 /// @brief \b Function \b Description:  This routine is used to enable HDMI output (Software)
1305 /// @param bEnMute     \b : 0--Disable mute,
1306 ///                         1--Enable mute
1307 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_Tx_SetMute(MS_U8 bEnMute)1308 void MDrv_AUDIO_HDMI_Tx_SetMute(MS_U8 bEnMute)
1309 {
1310     _HAL_AUDIO_HDMI_Tx_SetMute((MS_BOOL)bEnMute);
1311 }
1312 
1313 ////////////////////////////////////////////////////////////////////////////////
1314 /// @brief \b Function \b Name: MDrv_AUDIO_HDMI_Tx_GetStatus()
1315 /// @brief \b Function \b Description:  This routine is used to get HDMI Tx status
1316 /// @param onOff     \b : HDMI tx function is availible in this chip ?
1317 /// @param hdmi_SmpFreq \b : Audio current sample freq for tx
1318 /// @param outType \b   : PCM mode or nonPCM mode
1319 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_Tx_GetStatus(MS_BOOL * onOff,AUDIO_FS_TYPE * hdmi_SmpFreq,HDMI_TX_OUTPUT_TYPE * outType)1320 void MDrv_AUDIO_HDMI_Tx_GetStatus(MS_BOOL *onOff, AUDIO_FS_TYPE *hdmi_SmpFreq, HDMI_TX_OUTPUT_TYPE *outType )
1321 {
1322     HAL_AUDIO_HDMI_Tx_GetStatus(onOff, hdmi_SmpFreq, outType);
1323 }
1324 
1325 ////////////////////////////////////////////////////////////////////////////////
1326 /// @brief \b Function \b Name: HAL_AUDIO_HDMI_Monitor()
1327 /// @brief \b Function \b Description:  Report PCM/HDMI non-PCM status
1328 /// @return MS_U8      \b : return 0x2C0C value
1329 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_NonpcmMonitor(void)1330 MS_BOOL MDrv_AUDIO_HDMI_NonpcmMonitor(void)
1331 {
1332     return (HAL_AUDIO_HDMI_NonpcmMonitor());
1333 }
1334 
1335 ////////////////////////////////////////////////////////////////////////////////
1336 /// @brief \b Function \b Name: MDrv_AUDIO_HDMI_SetOutputType()
1337 /// @brief \b Function \b Description:  To set HDMI output type independently
1338 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_TX_SetMode(HDMI_TX_OUTPUT_TYPE outType,AUDIO_SOURCE_INFO_TYPE eSource)1339 void MDrv_AUDIO_HDMI_TX_SetMode(HDMI_TX_OUTPUT_TYPE outType, AUDIO_SOURCE_INFO_TYPE eSource)
1340 {
1341      HAL_AUDIO_HDMI_TX_SetMode(outType, eSource);
1342 }
1343 
1344 ////////////////////////////////////////////////////////////////////////////////
1345 /// @brief \b Function \b Name: MDrv_AUDIO_HDMI_DolbyMonitor()
1346 /// @brief \b Function \b Description:  Report HDMI non-PCM Dolby mod status
1347 /// @return MS_U8      \b : 0-- Other mode  ; 1-- Dolby mode
1348 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_DolbyMonitor(void)1349 MS_U8 MDrv_AUDIO_HDMI_DolbyMonitor(void)
1350 {
1351     return HAL_AUDIO_HDMI_DolbyMonitor();
1352 }
1353 
1354 ////////////////////////////////////////////////////////////////////////////////
1355 /// @brief \b Function \b Name: MDrv_AUDIO_SPDIF_Monitor_SamplingRate()
1356 /// @brief \b Function \b Description:  This routine is to set ADC clock for SPDIF raw out
1357 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SPDIF_Monitor_SamplingRate(void)1358 void MDrv_AUDIO_SPDIF_Monitor_SamplingRate(void)
1359 {
1360     HAL_AUDIO_SPDIF_Monitor_SamplingRate();
1361 }
1362 
1363 ////////////////////////////////////////////////////////////////////////////////
1364 /// @brief \b Function \b Name: MDrv_AUDIO_HDMI_SetNonpcm()
1365 /// @brief \b Function \b Description:  Set HDMI PCM/non-PCM Mode
1366 /// @param bEnNonPCM   \b : FALSE==> PCM mode
1367 ///                       : TRUE ==> non-PCM mode
1368 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_SetNonpcm(MS_U8 bEnNonPCM)1369 AUDIO_HDMI_RX_TYPE MDrv_AUDIO_HDMI_SetNonpcm(MS_U8 bEnNonPCM)
1370 {
1371     AUDIO_HDMI_RX_TYPE ret_type = HDMI_RX_PCM;
1372     MS_U8 HDMI_PC_Status;
1373 
1374     HDMI_PC_Status = MDrv_AUDIO_HDMI_DolbyMonitor();
1375 
1376     switch(HDMI_PC_Status)
1377     {
1378         case AU_HDMI_DTS_TYPE1:
1379         case AU_HDMI_DTS_TYPE2:
1380         case AU_HDMI_DTS_TYPE3:
1381             ret_type = HDMI_RX_DTS;
1382             break;
1383 
1384         case AU_HDMI_AC3:
1385             ret_type = HDMI_RX_DD;
1386             break;
1387 
1388         case AU_HDMI_AC3P:
1389             ret_type = HDMI_RX_DDP;
1390             break;
1391 
1392          default:
1393              ret_type = HDMI_RX_PCM;
1394             break;
1395     };
1396 
1397     HAL_AUDIO_HDMI_SetNonpcm(bEnNonPCM);
1398 
1399     return ret_type;
1400 }
1401 
1402 ////////////////////////////////////////////////////////////////////////////////
1403 /// @brief \b Function \b Name: MDrv_AUDIO_HDMI_AC3_PathCFG()
1404 /// @brief \b Function \b Description:  Set DVB/HDMI AC3 path Control
1405 /// @param u8Ctrl      \b :
1406 ///                     - 0==> DVB2_AD path
1407 ///                     - 1==> HDMI path
1408 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_AC3_PathCFG(MS_U8 u8Ctrl)1409 void MDrv_AUDIO_HDMI_AC3_PathCFG(MS_U8 u8Ctrl)
1410 {
1411     HAL_AUDIO_HDMI_AC3_PathCFG(u8Ctrl);
1412 }
1413 
1414 //-----------------------------------------------------------------------------
1415 ////////////////////////////////////////////////////////////////////////////////
1416 ////////////////////////////////////////////////////////////////////////////////
1417 //
1418 //        AUDIO Internal Use Drv Function
1419 //
1420 ////////////////////////////////////////////////////////////////////////////////
1421 ////////////////////////////////////////////////////////////////////////////////
1422 //-----------------------------------------------------------------------------
1423 
1424 ////////////////////////////////////////////////////////////////////////////////
1425 /// @brief \b Function \b Name: MDrv_AUDIO_AdcInit()
1426 /// @brief \b Function \b Description:  This routine is ADC relational register Init.
1427 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_AdcInit(void)1428 void MDrv_AUDIO_AdcInit(void)
1429 {
1430     HAL_AUDIO_ADCInit();
1431 }
1432 
1433 ////////////////////////////////////////////////////////////////////////////////
1434 /// @brief \b Function \b Name: MDrv_AUDIO_GetDecoderStatus()
1435 /// @brief \b Function \b Description:  This routine is used to read the Decoder status.
1436 /// @return MS_U8      \b : Decoder status
1437 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GetDecoderStatus(void)1438 MS_U8 MDrv_AUDIO_GetDecoderStatus(void)
1439 {
1440     return HAL_AUDIO_Dec_Status();
1441 }
1442 
1443 ////////////////////////////////////////////////////////////////////////////////
1444 /// @brief \b Function \b Name: MDrv_AUDIO_HDMI_GetSynthFreq()
1445 /// @brief \b Function \b Description:  Audio HDMI CTS-N synthesizer input signal detect.
1446 /// @return MS_U16     \b : return freq. If no signal, return 0
1447 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_GetSynthFreq(void)1448 MS_U16 MDrv_AUDIO_HDMI_GetSynthFreq(void)
1449 {
1450     return HAL_AUDIO_HDMI_Get_SYNTH_FREQ();
1451 }
1452 
1453 ////////////////////////////////////////////////////////////////////////////////
1454 /// @brief \b Function \b Name: MDrv_AUDIO_HDMI_SetDownSample()
1455 /// @brief \b Function \b Description:  set HDMI downsample rate
1456 /// @param ratio       \b : donwsample ratio. 00: Normal (from 1x to 1x),
1457 ///                         01: Down sample from 2x to 1x.
1458 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_HDMI_SetDownSample(MS_U8 ratio)1459 void MDrv_AUDIO_HDMI_SetDownSample(MS_U8 ratio)
1460 {
1461     HAL_AUDIO_HDMI_Set_DwonSample(ratio);
1462 }
1463 
1464 ////////////////////////////////////////////////////////////////////////////////
1465 /// @brief \b Function \b Name: MDrv_AUDIO_SendIntrupt()
1466 /// @brief \b Function \b Description:  send a PIO8 interrupt to DSP
1467 /// @param bDspType    \b :
1468 /// @param u8Cmd       \b :
1469 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SendIntrupt(MS_BOOL bDspType,MS_U16 u8Cmd)1470 void MDrv_AUDIO_SendIntrupt(MS_BOOL bDspType,MS_U16 u8Cmd)
1471 {
1472     HAL_AUDIO_SendIntrupt(bDspType, u8Cmd);
1473 }
1474 
1475 ////////////////////////////////////////////////////////////////////////////////
1476 /// @brief \b Function \b Name: MDrv_AUDIO_DmaReader_Init()
1477 /// @brief \b Function \b Description:
1478 /// @param <IN>        \b   eType   : sampleRate
1479 /// @param <OUT>       \b NONE    :
1480 /// @param <RET>       \b NONE    :
1481 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DmaReader_Init(SAMPLE_RATE sampleRate)1482 void MDrv_AUDIO_DmaReader_Init(SAMPLE_RATE sampleRate)
1483 {
1484     HAL_AUDIO_DmaReader_Init(sampleRate);
1485 }
1486 
1487 ////////////////////////////////////////////////////////////////////////////////
1488 /// @brief \b Function \b Name: MDrv_AUDIO_DmaReader_Init()
1489 /// @brief \b Function \b Description: Used DMA reader in all audio source application
1490 ///                    \b              (ex: Key sound) (CHIP_T8/T12)
1491 /// @param <IN>        \b   eType   : sampleRate
1492 /// @param <OUT>       \b NONE    :
1493 /// @param <RET>       \b NONE    :
1494 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DmaReader_AllInput_Init(void)1495 void MDrv_AUDIO_DmaReader_AllInput_Init(void)
1496 {
1497     HAL_AUDIO_DmaReader_AllInput_Init();
1498 }
1499 
1500 ////////////////////////////////////////////////////////////////////////////////
1501 /// @brief \b Function \b Name: MDrv_AUDIO_DmaReader_WritePCM()
1502 /// @brief \b Function \b Description: This routine is used to write PCM data into DMA reader Buffer
1503 /// @param <IN>        \b   eType   : buffer bytes
1504 /// @param <OUT>       \b NONE    : TRUE or FALSE
1505 /// @param <RET>       \b NONE    :
1506 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DmaReader_WritePCM(void * buffer,MS_U32 bytes)1507 MS_BOOL MDrv_AUDIO_DmaReader_WritePCM(void* buffer, MS_U32 bytes)
1508 {
1509     return(HAL_AUDIO_DmaReader_WritePCM(buffer,bytes));
1510 }
1511 
1512 ////////////////////////////////////////////////////////////////////////////////
1513 /// @brief \b Function \b Name: MDrv_AUDIO_DmaWriter_Init()
1514 /// @brief \b Function \b Description:
1515 /// @param <IN>        \b NONE    :
1516 /// @param <OUT>       \b NONE    :
1517 /// @param <RET>       \b NONE    :
1518 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DmaWriter_Init(void)1519 void MDrv_AUDIO_DmaWriter_Init(void)
1520 {
1521     HAL_AUDIO_DmaWriter_Init();
1522 }
1523 
1524 ////////////////////////////////////////////////////////////////////////////////
1525 /// @brief \b Function \b Name: MDrv_AUDIO_AbsReadReg()
1526 /// @brief \b Function \b Description:
1527 /// @param <IN>        \b NONE    :
1528 /// @param <OUT>       \b NONE    :
1529 /// @param <RET>       \b NONE    :
1530 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_AbsReadReg(MS_U32 u32RegAddr)1531 MS_U16 MDrv_AUDIO_AbsReadReg(MS_U32 u32RegAddr)
1532 {
1533     return HAL_AUDIO_AbsReadReg(u32RegAddr);
1534 }
1535 
1536 ////////////////////////////////////////////////////////////////////////////////
1537 /// @brief \b Function \b Name: MDrv_AUDIO_AbsWriteReg()
1538 /// @brief \b Function \b Description:
1539 /// @param <IN>        \b NONE    :
1540 /// @param <OUT>       \b NONE    :
1541 /// @param <RET>       \b NONE    :
1542 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_AbsWriteReg(MS_U32 u32RegAddr,MS_U16 u16Val)1543 void MDrv_AUDIO_AbsWriteReg(MS_U32 u32RegAddr, MS_U16 u16Val)
1544 {
1545     HAL_AUDIO_AbsWriteReg(u32RegAddr, u16Val);
1546 }
1547 
1548 ////////////////////////////////////////////////////////////////////////////////
1549 /// @brief \b Function \b Name: MDrv_AUDIO_SetEntertainmentMode()
1550 /// @brief \b Function \b Description: This routine is used to switch the DTV/KTV/GAME mode
1551 /// @param <IN>        \b   eType   : eMode
1552 /// @param <RET>       \b NONE    :
1553 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetEntertainmentMode(AUDIO_ENTERTAINMENT_MODE eMode)1554 void MDrv_AUDIO_SetEntertainmentMode(AUDIO_ENTERTAINMENT_MODE eMode)
1555 {
1556      HAL_AUDIO_SetEntertainmentMode(eMode);
1557 }
1558 
1559 ////////////////////////////////////////////////////////////////////////////////
1560 /// @brief \b Function \b Name: MDrv_AUDIO_GetDecSysSupportStatus()
1561 /// @brief \b Function \b Description: This function will report Audio Decoder support feature status when giving DecSystem type
1562 /// @param <IN>        \b   enDecSystem : Decoder type
1563 /// @param <RET>       \b   BOOL        : True or False
1564 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GetDecSysSupportStatus(En_DVB_decSystemType enDecSystem)1565 MS_BOOL MDrv_AUDIO_GetDecSysSupportStatus(En_DVB_decSystemType enDecSystem)
1566 {
1567     return(HAL_AUDIO_GetDecSysSupportStatus(enDecSystem));
1568 }
1569 
1570 ////////////////////////////////////////////////////////////////////////////////
1571 /// @brief \b Function \b Name: MDrv_AUDIO_DspReboot()
1572 /// @brief \b Function \b Description: This routine is used to do dsp reboot and some specific setting
1573 /// @param <IN>        \b   eType   : param
1574 /// @param <RET>       \b NONE    :
1575 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DspReboot(MS_U8 param)1576 void MDrv_AUDIO_DspReboot(MS_U8 param)
1577 {
1578     DRVAUDIO_CHECK_SHM_INIT;
1579 
1580     g_AudioVars2->g_bHashkeyFlag = FALSE;
1581 
1582     MsOS_DisableInterrupt(E_INT_FIQ_DEC_DSP2UP);
1583     MsOS_DisableInterrupt(E_INT_FIQ_SE_DSP2UP);
1584 
1585     OS_OBTAIN_MUTEX(_s32AUDIOMutexReboot, MSOS_WAIT_FOREVER);
1586 
1587      HAL_AUDIO_DspReboot(0);
1588 
1589      MsOS_DelayTask(2);
1590     HAL_AUDIO_WriteMaskByte(0x2c02, 0x04, 0x00);//disable SIF clock
1591     MsOS_DelayTask(1);
1592 
1593     HAL_AUDIO_BackupMailbox();
1594 
1595     if ( param == 0 )
1596         HAL_AUDIO_SwResetMAD();
1597 
1598     HAL_AUDIO_RebootDecDSP();
1599 
1600     if ( param == 0 )
1601         MDrv_MAD2_RebootDsp();
1602 
1603     //restore hash key after reboot DSP
1604     MDrv_AUDIO_CheckHashkey();
1605 
1606     HAL_AUDIO_RestoreMailbox();
1607 
1608     HAL_AUDIO_WriteMaskByte(0x2c02, 0x04, 0x04);//enable SIF clock
1609 
1610      HAL_AUDIO_DspReboot(1);
1611 
1612      OS_RELEASE_MUTEX(_s32AUDIOMutexReboot);
1613 
1614     MsOS_EnableInterrupt(E_INT_FIQ_DEC_DSP2UP);
1615     MsOS_EnableInterrupt(E_INT_FIQ_SE_DSP2UP);
1616 
1617 }
1618 
1619 ////////////////////////////////////////////////////////////////////////////////
1620 /// @brief \b Function \b Name: MDrv_AUDIO_GetUniDecodeDoneFlag()
1621 /// @brief \b Function \b Description:  This function is used to set the Decoder DSP ISR
1622 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GetUniDecodeDoneTag(void)1623 MS_U16 MDrv_AUDIO_GetUniDecodeDoneTag(void)
1624 {
1625     return (HAL_AUDIO_GetUniDecodeDoneTag());
1626 }
1627 
1628 ////////////////////////////////////////////////////////////////////////////////
1629 /// @brief \b Function \b Name: MDrv_AUDIO_RebootDecDSP()
1630 /// @brief \b Function \b Description:  This routine reboot Decoder DSP.
1631 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_RebootDecDSP(void)1632 void MDrv_AUDIO_RebootDecDSP(void)
1633 {
1634     HAL_AUDIO_RebootDecDSP();
1635 }
1636 
1637 ////////////////////////////////////////////////////////////////////////////////
1638 /// @brief \b Function \b Name: MDrv_AUDIO_VoIP_Config()
1639 /// @brief \b Function \b Description:  This routine is used for VoIP applications
1640 /// @param <IN>        \b AUDIO_VoIP_CONFIG_TYPE : configType
1641 /// @param <IN>        \b MS_U32 : param1
1642 /// @param <IN>        \b MS_U32 : param2
1643 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
1644 /// @param <RET>       \b NONE    :
1645 /// @param <GLOBAL>    \b NONE    :
1646 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_VoIP_Config(AUDIO_VoIP_CONFIG_TYPE configType,MS_VIRT param1,MS_VIRT param2)1647 MS_BOOL MDrv_AUDIO_VoIP_Config(AUDIO_VoIP_CONFIG_TYPE configType, MS_VIRT param1, MS_VIRT param2)
1648 {
1649     MS_BOOL ret = FALSE;
1650 
1651     /*
1652      * For the moment, param2 is not in used, it's just reserved for any advanced requirement in the future.
1653      * Please be remembered to remove below dummy once param2 is used, because this dummy is just to pass coverity check.
1654      */
1655     UNUSED(param2);
1656 
1657     switch(configType)
1658     {
1659         case AUDIO_VoIP_CONFIG_REGISTER_DEC_CB:
1660         {
1661             audio_dec_app_callbk = (void *)param1;
1662             ret = TRUE;
1663             break;
1664         }
1665 
1666         case AUDIO_VoIP_CONFIG_REGISTER_SE_CB:
1667         {
1668             audio_se_app_callbk = (void *)param1;
1669             ret = TRUE;
1670             break;
1671         }
1672 
1673         case AUDIO_VoIP_CONFIG_ALSA_PLAYBACK:
1674         {
1675             ret = MDrv_AUDIO_ALSA_Enable((MS_BOOL)param1);
1676             break;
1677         }
1678 
1679         case AUDIO_VOIP_CONFIG_PCM_UPLOAD:
1680         {
1681             MS_BOOL bVoipEnable = (MS_BOOL)param1;
1682             HAL_AUDIO_USBPCM_Enable(bVoipEnable);
1683             HAL_AUDIO_SetEntertainmentMode(bVoipEnable == 1 ? AUDIO_ETMODE_VOIP_ON : AUDIO_ETMODE_VOIP_OFF);
1684             ret = TRUE;
1685             break;
1686         }
1687 
1688         default:
1689         {
1690             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Invalid VoIP Config Type (%d) !!\n", __func__, (int)configType);
1691             break;
1692         }
1693     }
1694 
1695     return ret;
1696 }
1697 
1698 ////////////////////////////////////////////////////////////////////////////////
1699 /// @brief \b Function \b Name: MDrv_AUDIO_ALSA_Check()
1700 /// @brief \b Function \b Description:  Check if ALSA Interface is supported
1701 /// @param <IN>        \b bEnable : on: TRUE, off: FALSE
1702 /// @param <OUT>       \b MS_BOOL    : return TRUE if it's supported, else return FALSE
1703 /// @param <RET>       \b NONE    :
1704 /// @param <GLOBAL>    \b NONE    :
1705 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_ALSA_Check(void)1706 MS_BOOL MDrv_AUDIO_ALSA_Check(void)
1707 {
1708     return HAL_AUDIO_ALSA_Check();
1709 }
1710 
1711 ////////////////////////////////////////////////////////////////////////////////
1712 /// @brief \b Function \b Name: MDrv_AUDIO_ALSA_Enable()
1713 /// @brief \b Function \b Description:  Enable/ Disable the path of ALSA
1714 /// @param <IN>        \b bEnable : on: TRUE, off: FALSE
1715 /// @param <OUT>       \b MS_BOOL    : return TRUE if ok, else return FALSE
1716 /// @param <RET>       \b NONE    :
1717 /// @param <GLOBAL>    \b NONE    :
1718 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_ALSA_Enable(MS_BOOL bEnable)1719 MS_BOOL MDrv_AUDIO_ALSA_Enable(MS_BOOL bEnable)
1720 {
1721     return HAL_AUDIO_ALSA_Enable(bEnable);
1722 }
1723 
1724 ////////////////////////////////////////////////////////////////////////////////
1725 /// @brief \b Function \b Name: MDrv_AUDIO_SetDataCaptureSource()
1726 /// @brief \b Function \b Description:  Select source for data capture
1727 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
1728 /// @param <IN>        \b AUDIO_CAPTURE_SOURCE_TYPE : Data Source
1729 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
1730 /// @param <RET>       \b NONE    :
1731 /// @param <GLOBAL>    \b NONE    :
1732 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_SetDataCaptureSource(AUDIO_DEVICE_TYPE eID,AUDIO_CAPTURE_SOURCE_TYPE eSource)1733 MS_BOOL MDrv_AUDIO_SetDataCaptureSource(AUDIO_DEVICE_TYPE eID, AUDIO_CAPTURE_SOURCE_TYPE eSource)
1734 {
1735     return HAL_AUDIO_SetDataCaptureSource(eID, eSource);
1736 }
1737 
1738 ////////////////////////////////////////////////////////////////////////////////
1739 /// @brief \b Function \b Name: MDrv_AUDIO_PCMCapture_Init()
1740 /// @brief \b Function \b Description:  Select source for pcm capture
1741 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
1742 /// @param <IN>        \b AUDIO_CAPTURE_SOURCE_TYPE : Data Source
1743 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
1744 /// @param <RET>       \b NONE    :
1745 /// @param <GLOBAL>    \b NONE    :
1746 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCMCapture_Init(const AUDIO_DEVICE_TYPE eID,const AUDIO_CAPTURE_SOURCE_TYPE eSource)1747 MS_BOOL MDrv_AUDIO_PCMCapture_Init(const AUDIO_DEVICE_TYPE eID, const AUDIO_CAPTURE_SOURCE_TYPE eSource)
1748 {
1749     return HAL_AUDIO_PCMCapture_Init(eID, eSource);
1750 }
1751 
1752 ////////////////////////////////////////////////////////////////////////////////
1753 /// @brief \b Function \b Name: MDrv_AUDIO_PCMCapture_Start()
1754 /// @brief \b Function \b Description:  captrue pcm data to DDR
1755 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
1756 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
1757 /// @param <RET>       \b NONE    :
1758 /// @param <GLOBAL>    \b NONE    :
1759 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCMCapture_Start(const AUDIO_DEVICE_TYPE eID)1760 MS_BOOL MDrv_AUDIO_PCMCapture_Start(const AUDIO_DEVICE_TYPE eID)
1761 {
1762    return HAL_AUDIO_PCMCapture_Start(eID);
1763 }
1764 
1765 ////////////////////////////////////////////////////////////////////////////////
1766 /// @brief \b Function \b Name: MDrv_AUDIO_PCMCapture_Stop()
1767 /// @brief \b Function \b Description:  stop captrue pcm data from DDR
1768 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
1769 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
1770 /// @param <RET>       \b NONE    :
1771 /// @param <GLOBAL>    \b NONE    :
1772 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCMCapture_Stop(const AUDIO_DEVICE_TYPE eID)1773 MS_BOOL MDrv_AUDIO_PCMCapture_Stop(const AUDIO_DEVICE_TYPE eID)
1774 {
1775      return HAL_AUDIO_PCMCapture_Stop(eID);
1776 }
1777 
1778 ////////////////////////////////////////////////////////////////////////////////
1779 /// @brief \b Function \b Name: HAL_AUDIO_PCMCapture_Read()
1780 /// @brief \b Function \b Description:  captrue pcm data from DDR to device
1781 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
1782 /// @param <IN>        \b void* : destination buffer pointer
1783 /// @param <IN>        \b MS_U32 : buffer size need transfered in byte
1784 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
1785 /// @param <RET>       \b NONE    :
1786 /// @param <GLOBAL>    \b NONE    :
1787 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCMCapture_Read(const AUDIO_DEVICE_TYPE eID,void * buffer,const MS_U32 bytes)1788 MS_BOOL MDrv_AUDIO_PCMCapture_Read(const AUDIO_DEVICE_TYPE eID,  void* buffer, const MS_U32 bytes)
1789 {
1790     return HAL_AUDIO_PCMCapture_Read(eID, buffer, bytes);
1791 }
1792 
1793 ////////////////////////////////////////////////////////////////////////////////
1794 /// @brief \b Function \b Name: MDrv_AUDIO_DumpDspInfo()
1795 /// @brief \b Function \b Description:  Dump DSP infomation
1796 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_DumpDspInfo(void)1797 void MDrv_AUDIO_DumpDspInfo(void)
1798 {
1799     HAL_AUDIO_DumpDspInfo();
1800 }
1801 
MDrv_AUDIO_OpenDecodeSystem(AudioDecStatus_t * p_AudioDecStatus)1802 AUDIO_DEC_ID MDrv_AUDIO_OpenDecodeSystem(AudioDecStatus_t * p_AudioDecStatus)
1803 {
1804     if (gOpenDecodeSystemFuncPtr == NULL)
1805     {
1806         return AU_DEC_INVALID;
1807     }
1808 
1809     return gOpenDecodeSystemFuncPtr(p_AudioDecStatus);
1810 }
1811 
1812 ////////////////////////////////////////////////////////////////////////////////
1813 /// @brief \b Function \b Name: MDrv_AUDIO_GetDDRInfo()
1814 /// @brief \b Function \b Description:  Return Audio DDR info
1815 /// @param <IN>        \b AUDIO_DEC_ID : select audio processor
1816 /// @param <IN>        \b EN_AUDIO_DDRINFO : DDR info
1817 /// @param <OUT>       \b MS_U32  : return DDR info
1818 /// @param <RET>       \b NONE    :
1819 /// @param <GLOBAL>    \b NONE    :
1820 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GetDDRInfo(AUDIO_DEC_ID DecId,EN_AUDIO_DDRINFO DDRInfo)1821 MS_PHY MDrv_AUDIO_GetDDRInfo(AUDIO_DEC_ID DecId, EN_AUDIO_DDRINFO DDRInfo)
1822 {
1823     MS_PHY DDRValue = 0;
1824 
1825     if (gGetDDRInfoFuncPtr == NULL)
1826     {
1827         return DDRValue;
1828     }
1829 
1830     return gGetDDRInfoFuncPtr(DecId, DDRInfo);
1831 }
1832 
1833 ////////////////////////////////////////////////////////////////////////////////
1834 /// @brief \b Function \b Name: MDrv_AUDIO_update_DspUsage()
1835 /// @brief \b Function \b Description:  update DSP resource status when select input source
1836 /// @param <IN>        \b AUDIO_SOURCE_INFO_TYPE : select input source type
1837 /// @param <OUT>       \b NONE    :
1838 /// @param <RET>       \b NONE    :
1839 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_update_DspUsage(AUDIO_SOURCE_INFO_TYPE eSourceType)1840 void MDrv_AUDIO_update_DspUsage(AUDIO_SOURCE_INFO_TYPE eSourceType)
1841 {
1842     HAL_AUDIO_update_DspUsage(eSourceType);
1843 }
1844 
1845 ////////////////////////////////////////////////////////////////////////////////
1846 /// @brief \b Function \b Name: MDrv_AUDIO_GetCaps()
1847 /// @brief \b Function \b Description: Get Audio Capabilities
1848 /// @param <IN>        \b AUDIO_DEC_ID : select audio processor
1849 /// @param <IN>        \b MS_U32 * : Audio Capabilites pointer
1850 /// @param <OUT>        \b MS_BOOL : return TRUE if success, else return FALSE
1851 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_GetCaps(AUDIO_DEC_ID DecId,MS_U32 * pCaps)1852 MS_U32 MDrv_AUDIO_GetCaps(AUDIO_DEC_ID DecId, MS_U32 *pCaps)
1853 {
1854     MS_U32 ret = FALSE;
1855 
1856     ret = HAL_AUDIO_GetCaps(DecId, pCaps);
1857 
1858     return ret;
1859 }
1860 
1861 ////////////////////////////////////////////////////////////////////////////////
1862 /// @brief \b Function \b Name: MDrv_AUDIO_CheckPlayDone()
1863 /// @brief \b Function \b Description: Check file play done. If file play done, will return TRUE
1864 /// @param <IN>        \b NONE    :
1865 /// @param <OUT>       \b MS_BOOL : TRUE or FALSE
1866 /// @param <GLOBAL>    \b NONE    :
1867 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_CheckPlayDone(void)1868 MS_BOOL MDrv_AUDIO_CheckPlayDone(void)
1869 {
1870     return HAL_AUDIO_CheckPlayDone();
1871 }
1872 
1873 ////////////////////////////////////////////////////////////////////////////////
1874 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Xe8_16_24_32Bit_To_Le16Bit()
1875 /// @brief \b Function \b Description : Convert PCM date to 16bits/LE.
1876 /// @param <IN>        \b MS_U16 : Pointer to a block of memory of destination PCM date.
1877 /// @param <IN>        \b MS_U8 : Pointer to a block of memory of source PCM date.
1878 /// @param <IN>        \b MS_U32 : BitWidth of source PCM date.
1879 /// @param <IN>        \b MS_U32 : Endian type of source PCM date.
1880 /// @param <OUT>       \b NONE :
1881 /// @param <RET>       \b MS_S32 : On success a nonnegative value is returned. On error, a negative value is returned.
1882 /// @param <GLOBAL>    \b NONE :
1883 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Xe8_16_24_32Bit_To_Le16Bit(MS_U16 * pU16Dst,MS_U8 * pU8Src,MS_U32 u32BitWidth,MS_U32 u32BigEndian)1884 MS_S32 MDrv_AUDIO_PCM_Xe8_16_24_32Bit_To_Le16Bit(MS_U16 *pU16Dst, MS_U8 *pU8Src, MS_U32 u32BitWidth, MS_U32 u32BigEndian)
1885 {
1886     MS_S32 s32Ret = 0;
1887     MS_U8 *pU8Dst = NULL;
1888     MS_U8 u8SrcPcmHigh = 0;
1889     MS_U8 u8SrcPcmLow = 0;
1890 
1891     pU8Dst = (MS_U8 *)pU16Dst;
1892 
1893     if (u32BitWidth == 8)
1894     {
1895         MS_U16 u16PcmTmp = 0;
1896 
1897         u16PcmTmp = ((MS_U16)(*pU8Src - 128) << 8);
1898         u8SrcPcmLow = (MS_U8)(u16PcmTmp & 0xFF);
1899         u8SrcPcmHigh = (MS_U8)(u16PcmTmp >> 8);
1900     }
1901     else
1902     {
1903         MS_U8 u8PcmHighIndex = 0;
1904         MS_U8 u8PcmLowIndex = 0;
1905 
1906         if (u32BigEndian == TRUE)
1907         {
1908             u8PcmLowIndex = 1;
1909             u8PcmHighIndex = 0;
1910         }
1911         else
1912         {
1913             u8PcmLowIndex = (u32BitWidth / 8) - 2;
1914             u8PcmHighIndex = (u32BitWidth / 8) - 1;
1915         }
1916 
1917         u8SrcPcmLow = pU8Src[u8PcmLowIndex];
1918         u8SrcPcmHigh = pU8Src[u8PcmHighIndex];
1919     }
1920 
1921     pU8Dst[0] = u8SrcPcmLow;
1922     pU8Dst[1] = u8SrcPcmHigh;
1923 
1924     return s32Ret;
1925 }
1926 
1927 ////////////////////////////////////////////////////////////////////////////////
1928 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_converter()
1929 /// @brief \b Function \b Description : Convert PCM date to 16bits/LE, and specific channel number.
1930 /// @param <IN>        \b void : Pointer to a block of memory for storing converted PCM data.
1931 /// @param <IN>        \b MS_U32 : The requested PCM channel number.
1932 /// @param <IN>        \b MS_U32 : The requested PCM size.
1933 /// @param <IN>        \b void : Pointer to a block of memory with original PCM data.
1934 /// @param <IN>        \b AUDIO_PCM_INFO_t : The using PCM capabilities.
1935 /// @param <OUT>       \b NONE :
1936 /// @param <RET>       \b MS_S32 : On success a nonnegative value is returned. On error, a negative value is returned.
1937 /// @param <GLOBAL>    \b NONE :
1938 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_converter(void * pDstData,MS_U32 u32DstChannel,MS_U32 u32DstSize,const void * pSrcData,AUDIO_PCM_INFO_t * pSrcPCMInfo)1939 MS_S32 MDrv_AUDIO_PCM_converter(void *pDstData, MS_U32 u32DstChannel, MS_U32 u32DstSize, const void *pSrcData, AUDIO_PCM_INFO_t *pSrcPCMInfo)
1940 {
1941     MS_S32 s32Ret = 0;
1942     MS_U32 u32Channel = 0;
1943     MS_U32 u32BitWidth = 0;
1944     MS_U32 u32BigEndian = 0;
1945     MS_U32 u32DstBitWidth = 16;
1946 
1947     if (pDstData == NULL)
1948     {
1949         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pDstData should not be NULL!\n", __FUNCTION__);
1950         return -A_EFAULT;
1951     }
1952 
1953     if (pSrcData == NULL)
1954     {
1955         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pSrcData should not be NULL!\n", __FUNCTION__);
1956         return -A_EFAULT;
1957     }
1958 
1959     if (pSrcPCMInfo == NULL)
1960     {
1961         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pSrcPCMInfo should not be NULL!\n", __FUNCTION__);
1962         return -A_EFAULT;
1963     }
1964 
1965     if ((u32DstChannel != 2) && (u32DstChannel != 10))
1966     {
1967         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! u32DstChannel(%u) is invalid!\n", __FUNCTION__, (unsigned int)u32DstChannel);
1968         return -A_EINVAL;
1969     }
1970 
1971     if (u32DstSize == 0)
1972     {
1973         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! u32Size(%u) is invalid!\n", __FUNCTION__, (unsigned int)u32DstSize);
1974         return -A_EINVAL;
1975     }
1976 
1977     u32Channel = pSrcPCMInfo->u32Channel;
1978     if ((u32Channel < 1) || (u32Channel > 10))
1979     {
1980         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! u32Channel(%u) is invalid!\n", __FUNCTION__, (unsigned int)u32Channel);
1981         return -A_EINVAL;
1982     }
1983 
1984     u32BitWidth = pSrcPCMInfo->u32BitWidth;
1985     if ((u32BitWidth != 8) && (u32BitWidth != 16) && (u32BitWidth != 24) && (u32BitWidth != 32))
1986     {
1987         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! u32BitWidth(%u) is invalid!\n", __FUNCTION__, (unsigned int)u32BitWidth);
1988         return -A_EINVAL;
1989     }
1990 
1991     u32BigEndian = pSrcPCMInfo->u32BigEndian;
1992     if ((u32BigEndian != TRUE) && (u32BigEndian != FALSE))
1993     {
1994         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! u32BigEndian(%u) is invalid!\n", __FUNCTION__, (unsigned int)u32BigEndian);
1995         return -A_EINVAL;
1996     }
1997 
1998     if ((u32Channel == u32DstChannel) && (u32BitWidth == u32DstBitWidth) && (u32BigEndian == FALSE))
1999     {
2000         /* PCM format is exactly same, just copy PCM data from source to destination */
2001         memcpy(pDstData, pSrcData, u32DstSize);
2002     }
2003     else
2004     {
2005         MS_U8 *pU8SrcData = NULL;
2006         MS_U16 *pU16SrcData = NULL;
2007         MS_U16 *pU16DstData = NULL;
2008         MS_U16 u16PcmArray[10] = {0};
2009         MS_U32 u32PcmSample = 0;
2010         MS_U32 u32PcmSampleIndex = 0;
2011         MS_U32 u32ChannelIndex = 0;
2012 
2013         pU8SrcData = (MS_U8 *)pSrcData;
2014         pU16SrcData = (MS_U16 *)pSrcData;
2015         pU16DstData = (MS_U16 *)pDstData;
2016         u32PcmSample = (u32DstSize / u32DstChannel) / (u32DstBitWidth / 8);
2017 
2018         for (u32PcmSampleIndex = 0; u32PcmSampleIndex < u32PcmSample; u32PcmSampleIndex++)
2019         {
2020             for (u32ChannelIndex = 0; u32ChannelIndex < u32Channel; u32ChannelIndex++)
2021             {
2022                 MDrv_AUDIO_PCM_Xe8_16_24_32Bit_To_Le16Bit(&u16PcmArray[u32ChannelIndex], pU8SrcData, u32BitWidth, u32BigEndian);
2023                 pU8SrcData += (pSrcPCMInfo->u32BitWidth / 8);
2024             }
2025 
2026             if (u32Channel == 1)
2027             {
2028                 u16PcmArray[AUDIO_MULTICH_PCM_DMXR] = u16PcmArray[AUDIO_MULTICH_PCM_DMXL];
2029                 u16PcmArray[AUDIO_MULTICH_PCM_C] = u16PcmArray[AUDIO_MULTICH_PCM_DMXL];
2030             }
2031             else if (u32Channel == 2)
2032             {
2033                 u16PcmArray[AUDIO_MULTICH_PCM_L] = u16PcmArray[AUDIO_MULTICH_PCM_DMXL];
2034                 u16PcmArray[AUDIO_MULTICH_PCM_R] = u16PcmArray[AUDIO_MULTICH_PCM_DMXR];
2035             }
2036 
2037             *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_DMXL];
2038             *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_DMXR];
2039             if (u32DstChannel == 10)
2040             {
2041                 *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_L];
2042                 *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_C];
2043                 *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_R];
2044                 *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_LS];
2045                 *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_RS];
2046                 *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_LFE];
2047                 *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_LRS];
2048                 *pU16DstData++ = u16PcmArray[AUDIO_MULTICH_PCM_RRS];
2049             }
2050         }
2051     }
2052 
2053     return s32Ret;
2054 }
2055 
2056 ////////////////////////////////////////////////////////////////////////////////
2057 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Init()
2058 /// @brief \b Function \b Description : Init common PCM I/O.
2059 /// @param <IN>        \b NONE :
2060 /// @param <OUT>       \b NONE :
2061 /// @param <RET>       \b NONE :
2062 /// @param <GLOBAL>    \b NONE :
2063 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Init(void)2064 void MDrv_AUDIO_PCM_Init(void)
2065 {
2066     MS_S32 s32DeviceId = 0;
2067 
2068     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Init PCM device\n", __FUNCTION__);
2069 
2070     DRVAUDIO_CHECK_SHM_INIT;
2071 
2072     if (g_Common_PCM_IO_Init == TRUE)
2073     {
2074         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: already initialized\n", __FUNCTION__);
2075         return;
2076     }
2077 
2078     for (s32DeviceId = 0; s32DeviceId < AUDIO_PCM_MAXNUM; s32DeviceId++)
2079     {
2080         if (g_PCM[s32DeviceId] == NULL)
2081         {
2082             continue;
2083         }
2084 
2085         g_PCM[s32DeviceId]->pPcmInfo = &g_AudioVars2->g_PcmInfo[s32DeviceId];
2086     }
2087 
2088     g_Common_PCM_IO_Init = TRUE;
2089 
2090     return;
2091 }
2092 
2093 ////////////////////////////////////////////////////////////////////////////////
2094 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_DeInit()
2095 /// @brief \b Function \b Description : DeInit common PCM I/O.
2096 /// @param <IN>        \b NONE :
2097 /// @param <OUT>       \b NONE :
2098 /// @param <RET>       \b NONE :
2099 /// @param <GLOBAL>    \b NONE :
2100 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_DeInit(void)2101 void MDrv_AUDIO_PCM_DeInit(void)
2102 {
2103     MS_S32 s32DeviceId = 0;
2104 
2105     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: DeInit PCM device\n", __FUNCTION__);
2106 
2107     DRVAUDIO_CHECK_SHM_INIT;
2108 
2109     if (g_Common_PCM_IO_Init == FALSE)
2110     {
2111         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: no need to de-initialize\n", __FUNCTION__);
2112         return;
2113     }
2114 
2115     for (s32DeviceId = 0; s32DeviceId < AUDIO_PCM_MAXNUM; s32DeviceId++)
2116     {
2117         if (g_PCM[s32DeviceId] == NULL)
2118         {
2119             continue;
2120         }
2121 
2122         g_PCM[s32DeviceId]->pPcmInfo = NULL;
2123     }
2124 
2125     g_Common_PCM_IO_Init = FALSE;
2126 
2127     return;
2128 }
2129 
2130 ////////////////////////////////////////////////////////////////////////////////
2131 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Open()
2132 /// @brief \b Function \b Description : Open a PCM interface according to specific capabilities.
2133 /// @param <IN>        \b void : Pointer to a block of memory with PCM information.
2134 /// @param <OUT>       \b NONE :
2135 /// @param <RET>       \b MS_S32 : On success a nonnegative value is returned, and this value is the chosen device-id. On error, a negative value is returned.
2136 /// @param <GLOBAL>    \b NONE :
2137 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Open(void * pData)2138 MS_S32 MDrv_AUDIO_PCM_Open(void *pData)
2139 {
2140     AUDIO_PCM_t *pPCM = NULL;
2141     AUDIO_PCM_INFO_t *pUserPcmInfo = NULL;
2142     MS_S32 s32DeviceId = 0;
2143     MS_S32 s32Ret = 0;
2144     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Open PCM device\n", __FUNCTION__);
2145 
2146     DRVAUDIO_CHECK_SHM_INIT;
2147 
2148     if (pData == NULL)
2149     {
2150         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pData should not be NULL!\n", __FUNCTION__);
2151         return -A_EFAULT;
2152     }
2153 
2154     pUserPcmInfo = (AUDIO_PCM_INFO_t *)pData;
2155 
2156     if ((pUserPcmInfo->u32StructVersion & AUDIO_MAJOR_VERSION_MASK) != (AUDIO_PCM_INFO_VERSION & AUDIO_MAJOR_VERSION_MASK))
2157     {
2158         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! The version of PCM Info mismatch(0x%08X, 0x%08X)!\n", __FUNCTION__, (unsigned int)pUserPcmInfo->u32StructVersion, AUDIO_PCM_INFO_VERSION);
2159         return -A_EINVAL;
2160     }
2161 
2162     if (pUserPcmInfo->u32StructSize != sizeof(AUDIO_PCM_INFO_t))
2163     {
2164         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! The size of PCM Info mismatch(%u, %u)!\n", __FUNCTION__, (unsigned int)pUserPcmInfo->u32StructSize, (unsigned int)sizeof(AUDIO_PCM_INFO_t));
2165         return -A_EINVAL;
2166     }
2167 
2168     for (s32DeviceId = 0; s32DeviceId < AUDIO_PCM_MAXNUM; s32DeviceId++)
2169     {
2170         pPCM = g_PCM[s32DeviceId];
2171 
2172         if (pPCM == NULL)
2173         {
2174             continue;
2175         }
2176 
2177         if (pPCM->tPcmOps.open == NULL)
2178         {
2179             continue;
2180         }
2181 
2182         if (pUserPcmInfo->u8Name[0] != 0x00)
2183         {
2184             if (strcmp((char *)pUserPcmInfo->u8Name, (char *)pPCM->u8Name) != 0)
2185             {
2186                 continue;
2187             }
2188         }
2189 
2190         if (pPCM->pPcmInfo->u8ConnectFlag == TRUE)
2191         {
2192             continue;
2193         }
2194 
2195         s32Ret = pPCM->tPcmOps.open(pUserPcmInfo);
2196         if (s32Ret < 0)
2197         {
2198             continue;
2199         }
2200 
2201         break;
2202     }
2203 
2204     s32Ret = (s32DeviceId == AUDIO_PCM_MAXNUM) ? (-A_EBUSY) : s32DeviceId;
2205 
2206     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: return device-id %d\n", __FUNCTION__, (int)s32DeviceId);
2207 
2208     return s32Ret;
2209 }
2210 
2211 ////////////////////////////////////////////////////////////////////////////////
2212 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Close()
2213 /// @brief \b Function \b Description : Close an opened PCM interface.
2214 /// @param <IN>        \b MS_S32 : The chosen device-id.
2215 /// @param <OUT>       \b NONE :
2216 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
2217 /// @param <GLOBAL>    \b NONE :
2218 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Close(MS_S32 s32DeviceId)2219 MS_S32 MDrv_AUDIO_PCM_Close(MS_S32 s32DeviceId)
2220 {
2221     AUDIO_PCM_t *pPCM = NULL;
2222     MS_S32 s32Ret = 0;
2223     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Close PCM device-id %d\n", __FUNCTION__, (int)s32DeviceId);
2224 
2225     DRVAUDIO_CHECK_SHM_INIT;
2226 
2227     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_PCM_MAXNUM))
2228     {
2229         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
2230         return -A_EINVAL;
2231     }
2232 
2233     pPCM = g_PCM[s32DeviceId];
2234 
2235     if (pPCM == NULL)
2236     {
2237         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't support PCM I/O!\n", __FUNCTION__, (int)s32DeviceId);
2238         return -A_EPERM;
2239     }
2240 
2241     if (pPCM->tPcmOps.close == NULL)
2242     {
2243         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register close()!\n", __FUNCTION__, (int)s32DeviceId);
2244         return -A_EPERM;
2245     }
2246 
2247     if (pPCM->pPcmInfo->u8ConnectFlag == FALSE)
2248     {
2249         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not opened yet!\n", __FUNCTION__, (int)s32DeviceId);
2250         return -A_EPERM;
2251     }
2252 
2253     s32Ret = pPCM->tPcmOps.close();
2254 
2255     return s32Ret;
2256 }
2257 
2258 ////////////////////////////////////////////////////////////////////////////////
2259 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Start()
2260 /// @brief \b Function \b Description : Start an opened PCM interface.
2261 /// @param <IN>        \b MS_S32 : The chosen device-id.
2262 /// @param <OUT>       \b NONE :
2263 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
2264 /// @param <GLOBAL>    \b NONE :
2265 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Start(MS_S32 s32DeviceId)2266 MS_S32 MDrv_AUDIO_PCM_Start(MS_S32 s32DeviceId)
2267 {
2268     AUDIO_PCM_t *pPCM = NULL;
2269     MS_S32 s32Ret = 0;
2270     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Start PCM device-id %d\n", __FUNCTION__, (int)s32DeviceId);
2271 
2272     DRVAUDIO_CHECK_SHM_INIT;
2273 
2274     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_PCM_MAXNUM))
2275     {
2276         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
2277         return -A_EINVAL;
2278     }
2279 
2280     pPCM = g_PCM[s32DeviceId];
2281 
2282     if (pPCM == NULL)
2283     {
2284         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't support PCM I/O!\n", __FUNCTION__, (int)s32DeviceId);
2285         return -A_EPERM;
2286     }
2287 
2288     if (pPCM->tPcmOps.start == NULL)
2289     {
2290         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register start()!\n", __FUNCTION__, (int)s32DeviceId);
2291         return -A_EPERM;
2292     }
2293 
2294     if (pPCM->pPcmInfo->u8ConnectFlag == FALSE)
2295     {
2296         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not opened yet!\n", __FUNCTION__, (int)s32DeviceId);
2297         return -A_EPERM;
2298     }
2299 
2300     if (pPCM->pPcmInfo->u8StartFlag == FALSE)
2301     {
2302         s32Ret = pPCM->tPcmOps.start();
2303     }
2304 
2305     return s32Ret;
2306 }
2307 
2308 ////////////////////////////////////////////////////////////////////////////////
2309 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Stop()
2310 /// @brief \b Function \b Description : Stop a started PCM interface.
2311 /// @param <IN>        \b MS_S32 : The chosen device-id.
2312 /// @param <OUT>       \b NONE :
2313 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
2314 /// @param <GLOBAL>    \b NONE :
2315 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Stop(MS_S32 s32DeviceId)2316 MS_S32 MDrv_AUDIO_PCM_Stop(MS_S32 s32DeviceId)
2317 {
2318     AUDIO_PCM_t *pPCM = NULL;
2319     MS_S32 s32Ret = 0;
2320     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Stop PCM device-id %d\n", __FUNCTION__, (int)s32DeviceId);
2321 
2322     DRVAUDIO_CHECK_SHM_INIT;
2323 
2324     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_PCM_MAXNUM))
2325     {
2326         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
2327         return -A_EINVAL;
2328     }
2329 
2330     pPCM = g_PCM[s32DeviceId];
2331 
2332     if (pPCM == NULL)
2333     {
2334         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't support PCM I/O!\n", __FUNCTION__, (int)s32DeviceId);
2335         return -A_EPERM;
2336     }
2337 
2338     if (pPCM->tPcmOps.stop == NULL)
2339     {
2340         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register stop()!\n", __FUNCTION__, (int)s32DeviceId);
2341         return -A_EPERM;
2342     }
2343 
2344     if (pPCM->pPcmInfo->u8ConnectFlag == FALSE)
2345     {
2346         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not opened yet!\n", __FUNCTION__, (int)s32DeviceId);
2347         return -A_EPERM;
2348     }
2349 
2350     if (pPCM->pPcmInfo->u8StartFlag != FALSE)
2351     {
2352         s32Ret = pPCM->tPcmOps.stop();
2353     }
2354 
2355     return s32Ret;
2356 }
2357 
2358 ////////////////////////////////////////////////////////////////////////////////
2359 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Set()
2360 /// @brief \b Function \b Description : Set configuration to an opened PCM interface.
2361 /// @param <IN>        \b MS_S32 : The chosen device-id.
2362 /// @param <IN>        \b MS_U32 : The command type.
2363 /// @param <IN>        \b void : Pointer to a block of memory with specific configuration, and this memory is not allowed to be updated by this API.
2364 /// @param <OUT>       \b NONE :
2365 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
2366 /// @param <GLOBAL>    \b NONE :
2367 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Set(MS_S32 s32DeviceId,MS_U32 u32Cmd,const void * pData)2368 MS_S32 MDrv_AUDIO_PCM_Set(MS_S32 s32DeviceId, MS_U32 u32Cmd, const void *pData)
2369 {
2370     AUDIO_PCM_t *pPCM = NULL;
2371     MS_S32 s32Ret = 0;
2372     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Set command %u to PCM device-id %d\n", __FUNCTION__, u32Cmd, s32DeviceId);
2373 
2374     DRVAUDIO_CHECK_SHM_INIT;
2375 
2376     if (pData == NULL)
2377     {
2378         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pData should not be NULL!\n", __FUNCTION__);
2379         return -A_EFAULT;
2380     }
2381 
2382     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_PCM_MAXNUM))
2383     {
2384         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
2385         return -A_EINVAL;
2386     }
2387 
2388     pPCM = g_PCM[s32DeviceId];
2389 
2390     if (pPCM == NULL)
2391     {
2392         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't support PCM I/O!\n", __FUNCTION__, (int)s32DeviceId);
2393         return -A_EPERM;
2394     }
2395 
2396     if (pPCM->tPcmOps.set == NULL)
2397     {
2398         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register set()!\n", __FUNCTION__, (int)s32DeviceId);
2399         return -A_EPERM;
2400     }
2401 
2402     if (pPCM->pPcmInfo->u8ConnectFlag == FALSE)
2403     {
2404         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not opened yet!\n", __FUNCTION__, (int)s32DeviceId);
2405         return -A_EPERM;
2406     }
2407 
2408     if (pPCM->pPcmInfo->u8StartFlag != FALSE)
2409     {
2410         switch (u32Cmd)
2411         {
2412             case AUDIO_PCM_CMD_MIXINGGROUP:
2413             case AUDIO_PCM_CMD_TIMESTAMP:
2414             case AUDIO_PCM_CMD_WEIGHTING:
2415             case AUDIO_PCM_CMD_VOLUME:
2416             case AUDIO_PCM_CMD_MUTE:
2417             {
2418                 break;
2419             }
2420 
2421             default:
2422             {
2423                 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is running, can not be configured now!\n", __FUNCTION__, (int)s32DeviceId);
2424                 return -A_EBUSY;
2425             }
2426         }
2427     }
2428 
2429     s32Ret = pPCM->tPcmOps.set(u32Cmd, pData);
2430 
2431     return s32Ret;
2432 }
2433 
2434 ////////////////////////////////////////////////////////////////////////////////
2435 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Get()
2436 /// @brief \b Function \b Description : Get configuration from an opened PCM interface.
2437 /// @param <IN>        \b MS_S32 : The chosen device-id.
2438 /// @param <IN>        \b MS_U32 : The command type.
2439 /// @param <IN>        \b void : Pointer to a block of memory for receiving specific configuration.
2440 /// @param <OUT>       \b NONE :
2441 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
2442 /// @param <GLOBAL>    \b NONE :
2443 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Get(MS_S32 s32DeviceId,MS_U32 u32Cmd,void * pData)2444 MS_S32 MDrv_AUDIO_PCM_Get(MS_S32 s32DeviceId, MS_U32 u32Cmd, void *pData)
2445 {
2446     AUDIO_PCM_t *pPCM = NULL;
2447     MS_S32 s32Ret = 0;
2448     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Get command %u from PCM device-id %d\n", __FUNCTION__, u32Cmd, s32DeviceId);
2449 
2450     DRVAUDIO_CHECK_SHM_INIT;
2451 
2452     if (pData == NULL)
2453     {
2454         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pData should not be NULL!\n", __FUNCTION__);
2455         return -A_EFAULT;
2456     }
2457 
2458     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_PCM_MAXNUM))
2459     {
2460         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
2461         return -A_EINVAL;
2462     }
2463 
2464     pPCM = g_PCM[s32DeviceId];
2465 
2466     if (pPCM == NULL)
2467     {
2468         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't support PCM I/O!\n", __FUNCTION__, (int)s32DeviceId);
2469         return -A_EPERM;
2470     }
2471 
2472     if (pPCM->tPcmOps.get == NULL)
2473     {
2474         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register get()!\n", __FUNCTION__, (int)s32DeviceId);
2475         return -A_EPERM;
2476     }
2477 
2478     if (pPCM->pPcmInfo->u8ConnectFlag == FALSE)
2479     {
2480         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not opened yet!\n", __FUNCTION__, (int)s32DeviceId);
2481         return -A_EPERM;
2482     }
2483 
2484     s32Ret = pPCM->tPcmOps.get(u32Cmd, pData);
2485 
2486     return s32Ret;
2487 }
2488 
2489 ////////////////////////////////////////////////////////////////////////////////
2490 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Read()
2491 /// @brief \b Function \b Description : Read a specific amount of PCM data from a started PCM interface.
2492 /// @param <IN>        \b MS_S32 : The chosen device-id.
2493 /// @param <IN>        \b void : Pointer to a block of memory with PCM data.
2494 /// @param <IN>        \b MS_U32 : The size of PCM data.
2495 /// @param <OUT>       \b NONE :
2496 /// @param <RET>       \b MS_U32 : The total number of PCM data successfully written is returned.
2497 /// @param <GLOBAL>    \b NONE :
2498 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Read(MS_S32 s32DeviceId,void * pBuf,MS_U32 u32Size)2499 MS_U32 MDrv_AUDIO_PCM_Read(MS_S32 s32DeviceId, void *pBuf, MS_U32 u32Size)
2500 {
2501     AUDIO_PCM_t *pPCM = NULL;
2502     MS_U8 *pBufTmp = NULL;
2503     MS_U32 u32SizeToRead = 0;
2504     MS_U32 u32SizeToReadRemain = 0;
2505     MS_U32 u32BufferLevel = 0;
2506     MS_U32 u32ReadSize = 0;
2507     MS_U32 u32Loop = 0;
2508     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Read %u bytes from PCM device-id %d\n", __FUNCTION__, u32Size, s32DeviceId);
2509 
2510     DRVAUDIO_CHECK_SHM_INIT;
2511 
2512     if (pBuf == NULL)
2513     {
2514         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pBuf should not be NULL!\n", __FUNCTION__);
2515         return u32Size;
2516     }
2517 
2518     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_PCM_MAXNUM))
2519     {
2520         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
2521         return u32Size;
2522     }
2523 
2524     if (u32Size == 0)
2525     {
2526         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! u32Size(%u) is invalid!\n", __FUNCTION__, (unsigned int)u32Size);
2527         return u32Size;
2528     }
2529 
2530     pPCM = g_PCM[s32DeviceId];
2531 
2532     if (pPCM == NULL)
2533     {
2534         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't support PCM I/O!\n", __FUNCTION__, (int)s32DeviceId);
2535         return u32Size;
2536     }
2537 
2538     if (pPCM->tPcmOps.read == NULL)
2539     {
2540         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register read()!\n", __FUNCTION__, (int)s32DeviceId);
2541         return u32Size;
2542     }
2543 
2544     if (pPCM->pPcmInfo->u8ConnectFlag == FALSE)
2545     {
2546         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not opened yet!\n", __FUNCTION__, (int)s32DeviceId);
2547         return u32Size;
2548     }
2549 
2550     if (pPCM->pPcmInfo->u8StartFlag == FALSE)
2551     {
2552         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not started yet!\n", __FUNCTION__, (int)s32DeviceId);
2553         return u32Size;
2554     }
2555 
2556     if (pPCM->tPcmOps.get == NULL)
2557     {
2558         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register get()!\n", __FUNCTION__, (int)s32DeviceId);
2559         return u32Size;
2560     }
2561 
2562     pBufTmp = (MS_U8 *)pBuf;
2563     u32SizeToRead = u32Size;
2564     u32SizeToReadRemain = u32SizeToRead;
2565 
2566     do
2567     {
2568         pPCM->tPcmOps.get(AUDIO_PCM_CMD_BUFFERLEVEL, &u32BufferLevel);
2569 
2570         if (pPCM->pPcmInfo->u8NonBlockingFlag == TRUE)
2571         {
2572             u32SizeToRead = (u32SizeToRead > u32BufferLevel) ? u32BufferLevel : u32SizeToRead;
2573             if (u32SizeToRead == 0)
2574             {
2575                 break;
2576             }
2577 
2578             u32SizeToReadRemain = u32SizeToRead;
2579             u32ReadSize = u32SizeToReadRemain;
2580 
2581         }
2582         else
2583         {
2584             u32ReadSize = u32SizeToReadRemain;
2585             u32ReadSize = (u32ReadSize > u32BufferLevel) ? u32BufferLevel : u32ReadSize;
2586         }
2587 
2588         if (u32ReadSize == 0)
2589         {
2590             u32Loop++;
2591             if (u32Loop > 250)
2592             {
2593                 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: s32DeviceId(%d) read PCM timeout!\n", __FUNCTION__, (int)s32DeviceId);
2594                 break;
2595             }
2596 
2597 #ifdef MSOS_TYPE_LINUX_KERNEL
2598             msleep(2);
2599 #else
2600             AUDIO_DELAY1MS(2);
2601 #endif
2602         }
2603         else
2604         {
2605             u32ReadSize = pPCM->tPcmOps.read((void *)pBufTmp, u32ReadSize);
2606             u32Loop = 0;
2607         }
2608 
2609         pBufTmp += u32ReadSize;
2610         u32SizeToReadRemain -= u32ReadSize;
2611     } while (u32SizeToReadRemain > 0);
2612 
2613     return u32SizeToRead;
2614 }
2615 
2616 ////////////////////////////////////////////////////////////////////////////////
2617 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Write()
2618 /// @brief \b Function \b Description : Write a specific amount of PCM data to a started PCM interface.
2619 /// @param <IN>        \b MS_S32 : The chosen device-id.
2620 /// @param <IN>        \b void : Pointer to a block of memory with PCM data, and this memory is not allowed to be updated by this API.
2621 /// @param <IN>        \b MS_U32 : The size of PCM data.
2622 /// @param <OUT>       \b NONE :
2623 /// @param <RET>       \b MS_U32 : The total number of PCM data successfully written is returned.
2624 /// @param <GLOBAL>    \b NONE :
2625 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Write(MS_S32 s32DeviceId,const void * pBuf,MS_U32 u32Size)2626 MS_U32 MDrv_AUDIO_PCM_Write(MS_S32 s32DeviceId, const void *pBuf, MS_U32 u32Size)
2627 {
2628     AUDIO_PCM_t *pPCM = NULL;
2629     MS_U8 *pConvertedPcmBuf = NULL;
2630     MS_U8 *pConvertedPcmBufTmp = NULL;
2631     MS_U32 u32SampleToWrite = 0;
2632     MS_U32 u32TargetSizeToWrite = 0;
2633     MS_U32 u32TargetSizeToWriteRemain = 0;
2634     MS_U32 u32BufferLevel = 0;
2635     MS_U32 u32BufferSize = 0;
2636     MS_U32 u32AvailSize = 0;
2637     MS_U32 u32WriteSize = 0;
2638     MS_U32 u32TotalWriteSize = 0;
2639     MS_U32 u32TotalWriteSample = 0;
2640     MS_U32 u32TargetChannel = 0;
2641     MS_U32 u32TargetBitWidth = 0;
2642     MS_U32 u32TargetAlignmentSize = 0;
2643     MS_U32 u32Loop = 0;
2644     MS_S32 s32Ret = 0;
2645     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Write %u bytes to PCM device-id %d\n", __FUNCTION__, u32Size, s32DeviceId);
2646 
2647     DRVAUDIO_CHECK_SHM_INIT;
2648 
2649     if (pBuf == NULL)
2650     {
2651         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pBuf should not be NULL!\n", __FUNCTION__);
2652         return u32Size;
2653     }
2654 
2655     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_PCM_MAXNUM))
2656     {
2657         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
2658         return u32Size;
2659     }
2660 
2661     if (u32Size == 0)
2662     {
2663         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! u32Size(%u) is invalid!\n", __FUNCTION__, (int)u32Size);
2664         return u32Size;
2665     }
2666 
2667     pPCM = g_PCM[s32DeviceId];
2668 
2669     if (pPCM == NULL)
2670     {
2671         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't support PCM I/O!\n", __FUNCTION__, (int)s32DeviceId);
2672         return u32Size;
2673     }
2674 
2675     if (pPCM->tPcmOps.write == NULL)
2676     {
2677         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register write()!\n", __FUNCTION__, (int)s32DeviceId);
2678         return u32Size;
2679     }
2680 
2681     if (pPCM->pPcmInfo->u8ConnectFlag == FALSE)
2682     {
2683         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not opened yet!\n", __FUNCTION__, (int)s32DeviceId);
2684         return u32Size;
2685     }
2686 
2687     if (pPCM->pPcmInfo->u8StartFlag == FALSE)
2688     {
2689         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not started yet!\n", __FUNCTION__, (int)s32DeviceId);
2690         return u32Size;
2691     }
2692 
2693     if (pPCM->tPcmOps.get == NULL)
2694     {
2695         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register get()!\n", __FUNCTION__, (int)s32DeviceId);
2696         return u32Size;
2697     }
2698 
2699     u32SampleToWrite = (u32Size / (pPCM->pPcmInfo->u32BitWidth / 8)) / pPCM->pPcmInfo->u32Channel;
2700     if (u32SampleToWrite == 0)
2701     {
2702         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! u32Size(%u) is not a sample base size at %u channels!\n", __FUNCTION__, (unsigned int)u32Size, (unsigned int)pPCM->pPcmInfo->u32Channel);
2703         return u32Size;
2704     }
2705 
2706     pPCM->tPcmOps.get(AUDIO_PCM_CMD_BUFFERSIZE, &u32BufferSize);
2707 
2708     if (pPCM->pPcmInfo->u8MultiChFlag == TRUE)
2709     {
2710         /* total is 2 + 7.1 = 10 channels (DmxL, DmxR, L, C, R, Ls, Rs, LFE, Lrs, Rrs) */
2711         u32TargetChannel = 10;
2712     }
2713     else
2714     {
2715         /* total is stereo = 2 channels */
2716         u32TargetChannel = 2;
2717     }
2718 
2719     u32TargetBitWidth = 16; /* target is always 16 bits mode */
2720     u32TargetAlignmentSize = u32TargetChannel * (u32TargetBitWidth / 8);
2721 
2722     u32TargetSizeToWrite = (u32SampleToWrite * (u32TargetBitWidth / 8)) * u32TargetChannel;
2723     u32TargetSizeToWriteRemain = u32TargetSizeToWrite;
2724 
2725     do
2726     {
2727         pPCM->tPcmOps.get(AUDIO_PCM_CMD_BUFFERLEVEL, &u32BufferLevel);
2728         u32AvailSize = u32BufferSize - u32BufferLevel;
2729 
2730         /* find the maxium size of available size that can be aligned to both channel and bitwidth */
2731         AUDIO_DO_ALIGNMENT(u32AvailSize, u32TargetAlignmentSize);
2732 
2733         if (pPCM->pPcmInfo->u8NonBlockingFlag == TRUE)
2734         {
2735             u32TargetSizeToWrite = (u32TargetSizeToWrite > u32AvailSize) ? u32AvailSize : u32TargetSizeToWrite;
2736             if (u32TargetSizeToWrite == 0)
2737             {
2738                 break;
2739             }
2740 
2741             u32TargetSizeToWriteRemain = u32TargetSizeToWrite;
2742             u32WriteSize = u32TargetSizeToWriteRemain;
2743         }
2744         else
2745         {
2746             u32WriteSize = u32TargetSizeToWriteRemain;
2747             u32WriteSize = (u32WriteSize > u32AvailSize) ? u32AvailSize : u32WriteSize;
2748         }
2749 
2750         if (u32WriteSize == 0)
2751         {
2752             u32Loop++;
2753             if (u32Loop > 250)
2754             {
2755                 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) write PCM timeout!\n", __FUNCTION__, (int)s32DeviceId);
2756                 break;
2757             }
2758 
2759 #ifdef MSOS_TYPE_LINUX_KERNEL
2760             msleep(2);
2761 #else
2762             AUDIO_DELAY1MS(2);
2763 #endif
2764         }
2765         else
2766         {
2767             if (pConvertedPcmBuf == NULL)
2768             {
2769 #ifdef MSOS_TYPE_LINUX_KERNEL
2770                 pConvertedPcmBuf = (MS_U8 *)vmalloc(u32TargetSizeToWrite);
2771 #else
2772                 pConvertedPcmBuf = (MS_U8 *)malloc(u32TargetSizeToWrite);
2773 #endif
2774                 if (pConvertedPcmBuf == NULL)
2775                 {
2776                     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) can't allocate %u bytes for PCM buffer!\n", __FUNCTION__, (int)s32DeviceId, (unsigned int)u32TargetSizeToWrite);
2777                     return u32Size;
2778                 }
2779 
2780                 memset((void *)pConvertedPcmBuf, 0x00, u32TargetSizeToWrite);
2781                 s32Ret = MDrv_AUDIO_PCM_converter((void *)pConvertedPcmBuf, u32TargetChannel, u32TargetSizeToWrite, pBuf, pPCM->pPcmInfo);
2782                 if (s32Ret < 0)
2783                 {
2784                     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) fail to convert PCM data!\n", __FUNCTION__, (unsigned int)s32DeviceId);
2785                 }
2786 
2787                 pConvertedPcmBufTmp = pConvertedPcmBuf;
2788             }
2789 
2790             u32WriteSize = pPCM->tPcmOps.write((void *)pConvertedPcmBufTmp, u32WriteSize);
2791             u32Loop = 0;
2792         }
2793 
2794         pConvertedPcmBufTmp += u32WriteSize;
2795         u32TargetSizeToWriteRemain -= u32WriteSize;
2796         u32TotalWriteSample += ((u32WriteSize / (u32TargetBitWidth / 8)) / u32TargetChannel);
2797     } while (u32TargetSizeToWriteRemain > 0);
2798 
2799     if (pConvertedPcmBuf != NULL)
2800     {
2801 #ifdef MSOS_TYPE_LINUX_KERNEL
2802         vfree(pConvertedPcmBuf);
2803 #else
2804         free(pConvertedPcmBuf);
2805 #endif
2806         pConvertedPcmBuf = NULL;
2807     }
2808 
2809     u32TotalWriteSize = (u32TotalWriteSample * (pPCM->pPcmInfo->u32BitWidth / 8)) * pPCM->pPcmInfo->u32Channel;
2810 
2811     return u32TotalWriteSize;
2812 }
2813 
2814 ////////////////////////////////////////////////////////////////////////////////
2815 /// @brief \b Function \b Name: MDrv_AUDIO_PCM_Flush()
2816 /// @brief \b Function \b Description : Flush an opened PCM interface.
2817 /// @param <IN>        \b MS_S32 : The chosen device-id.
2818 /// @param <OUT>       \b NONE :
2819 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
2820 /// @param <GLOBAL>    \b NONE :
2821 ////////////////////////////////////////////////////////////////////////////////
MDrv_AUDIO_PCM_Flush(MS_S32 s32DeviceId)2822 MS_S32 MDrv_AUDIO_PCM_Flush(MS_S32 s32DeviceId)
2823 {
2824     AUDIO_PCM_t *pPCM = NULL;
2825     MS_S32 s32Ret = 0;
2826     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Flush PCM device-id %d\n", __FUNCTION__, (int)s32DeviceId);
2827 
2828     DRVAUDIO_CHECK_SHM_INIT;
2829 
2830     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_PCM_MAXNUM))
2831     {
2832         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
2833         return -A_EINVAL;
2834     }
2835 
2836     pPCM = g_PCM[s32DeviceId];
2837 
2838     if (pPCM == NULL)
2839     {
2840         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't support PCM I/O!\n", __FUNCTION__, (int)s32DeviceId);
2841         return -A_EPERM;
2842     }
2843 
2844     if (pPCM->tPcmOps.flush == NULL)
2845     {
2846         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) doesn't register flush()!\n", __FUNCTION__, (int)s32DeviceId);
2847         return -A_EPERM;
2848     }
2849 
2850     if (pPCM->pPcmInfo->u8ConnectFlag == FALSE)
2851     {
2852         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is not opened yet!\n", __FUNCTION__, (int)s32DeviceId);
2853         return -A_EPERM;
2854     }
2855 
2856     if (pPCM->pPcmInfo->u8StartFlag != FALSE)
2857     {
2858         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is running, can not do flush now!\n", __FUNCTION__, (int)s32DeviceId);
2859         return -A_EBUSY;
2860     }
2861 
2862     s32Ret = pPCM->tPcmOps.flush();
2863 
2864     return s32Ret;
2865 }
2866 
MDrv_AUDIO_ResetDspCodeType(void)2867 void MDrv_AUDIO_ResetDspCodeType(void)
2868 {
2869     HAL_AUDIO_ResetDspCodeType();
2870 }
2871 
MDrv_AUDIO_Check_AsndR2_SupportStatus(void)2872 MS_BOOL MDrv_AUDIO_Check_AsndR2_SupportStatus(void)
2873 {
2874     return ASND_R2_SUPPORT;
2875 }
2876 
MDrv_AUDIO_WriteStopDecTable(void)2877 void MDrv_AUDIO_WriteStopDecTable(void)
2878 {
2879     HAL_AUDIO_WriteStopDecTable();
2880 
2881     return;
2882 }
2883 
MDrv_AUDIO_InputSwitch(AUDIO_SWITCH_GROUP enGroup)2884 MS_S32 MDrv_AUDIO_InputSwitch(AUDIO_SWITCH_GROUP enGroup)
2885 {
2886     HAL_AUDIO_InputSwitch(enGroup);
2887 
2888     return 0;
2889 }
2890 
MDrv_AUDIO_ENCODER_StrCmd_To_U32Cmd(const char * pCmd,MS_U32 * pU32Cmd)2891 MS_S32 MDrv_AUDIO_ENCODER_StrCmd_To_U32Cmd(const char *pCmd, MS_U32 *pU32Cmd)
2892 {
2893     MS_S32 s32Ret = 0;
2894 
2895     if (strcmp("GetFrameSize", pCmd) == 0)
2896     {
2897        *pU32Cmd = AUDIO_ENCODER_IOCTL_GET_FRAME_SIZE;
2898     }
2899     else if (strcmp("GetAvailableSize", pCmd) == 0)
2900     {
2901        *pU32Cmd = AUDIO_ENCODER_IOCTL_GET_AVAILABLE_SIZE;
2902     }
2903     else if (strcmp("GetTimestampHigh32Bit", pCmd) == 0)
2904     {
2905        *pU32Cmd = AUDIO_ENCODER_IOCTL_GET_TIMESTAMP_HIGH32BIT;
2906     }
2907     else if (strcmp("GetTimestampLow32Bit", pCmd) == 0)
2908     {
2909        *pU32Cmd = AUDIO_ENCODER_IOCTL_GET_TIMESTAMP_LOW32BIT;
2910     }
2911     else
2912     {
2913         s32Ret = -A_EINVAL;
2914     }
2915 
2916     return s32Ret;
2917 }
2918 
MDrv_AUDIO_ENCODER_Open(const char * pName)2919 MS_S32 MDrv_AUDIO_ENCODER_Open(const char *pName)
2920 {
2921     MS_S32 s32DeviceId = 0;
2922     MS_S32 s32Ret = 0;
2923 
2924 
2925     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Open Encoder device\n", __FUNCTION__);
2926 
2927     DRVAUDIO_CHECK_SHM_INIT;
2928 
2929     if (pName == NULL)
2930     {
2931         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pName should not be NULL!\n", __FUNCTION__);
2932         return -A_EFAULT;
2933     }
2934 
2935     if (strcmp("MP3_ENCODER1", pName) == 0)
2936     {
2937         s32Ret = HAL_AUDIO_MP3_ENCODER1_Open();
2938         s32DeviceId = 0;
2939     }
2940     else if (strcmp("MP3_ENCODER2", pName) == 0)
2941     {
2942         s32Ret = HAL_AUDIO_MP3_ENCODER2_Open();
2943         s32DeviceId = 1;
2944     }
2945     else
2946     {
2947         s32Ret = -A_ENODEV;
2948     }
2949 
2950     if (s32Ret == 0)
2951     {
2952         s32Ret = s32DeviceId;
2953         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: return device-id %d\n", __FUNCTION__, (int)s32DeviceId);
2954     }
2955 
2956     return s32Ret;
2957 }
2958 
MDrv_AUDIO_ENCODER_Close(MS_S32 s32DeviceId)2959 MS_S32 MDrv_AUDIO_ENCODER_Close(MS_S32 s32DeviceId)
2960 {
2961     MS_S32 s32Ret = 0;
2962     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Close Encoder device-id %d\n", __FUNCTION__, (int)s32DeviceId);
2963 
2964     DRVAUDIO_CHECK_SHM_INIT;
2965 
2966     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_ENCODER_MAXNUM))
2967     {
2968         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
2969         return -A_EINVAL;
2970     }
2971 
2972     switch (s32DeviceId)
2973     {
2974         case 0:
2975         {
2976             s32Ret = HAL_AUDIO_MP3_ENCODER1_Close();
2977             break;
2978         }
2979 
2980         case 1:
2981         {
2982             s32Ret = HAL_AUDIO_MP3_ENCODER2_Close();
2983             break;
2984         }
2985 
2986         default:
2987         {
2988             s32Ret = -A_ENODEV;
2989             break;
2990         }
2991     }
2992 
2993     return s32Ret;
2994 }
2995 
MDrv_AUDIO_ENCODER_Start(MS_S32 s32DeviceId)2996 MS_S32 MDrv_AUDIO_ENCODER_Start(MS_S32 s32DeviceId)
2997 {
2998     MS_S32 s32Ret = 0;
2999     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Start Encoder device-id %d\n", __FUNCTION__, (int)s32DeviceId);
3000 
3001     DRVAUDIO_CHECK_SHM_INIT;
3002 
3003     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_ENCODER_MAXNUM))
3004     {
3005         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
3006         return -A_EINVAL;
3007     }
3008 
3009     switch (s32DeviceId)
3010     {
3011         case 0:
3012         {
3013             s32Ret = HAL_AUDIO_MP3_ENCODER1_Start();
3014             break;
3015         }
3016 
3017         case 1:
3018         {
3019             s32Ret = HAL_AUDIO_MP3_ENCODER2_Start();
3020             break;
3021         }
3022 
3023         default:
3024         {
3025             s32Ret = -A_ENODEV;
3026             break;
3027         }
3028     }
3029 
3030     return s32Ret;
3031 }
3032 
MDrv_AUDIO_ENCODER_Stop(MS_S32 s32DeviceId)3033 MS_S32 MDrv_AUDIO_ENCODER_Stop(MS_S32 s32DeviceId)
3034 {
3035     MS_S32 s32Ret = 0;
3036     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Stop Encoder device-id %d\n", __FUNCTION__, (int)s32DeviceId);
3037 
3038     DRVAUDIO_CHECK_SHM_INIT;
3039 
3040     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_ENCODER_MAXNUM))
3041     {
3042         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
3043         return -A_EINVAL;
3044     }
3045 
3046     switch (s32DeviceId)
3047     {
3048         case 0:
3049         {
3050             s32Ret = HAL_AUDIO_MP3_ENCODER1_Stop();
3051             break;
3052         }
3053 
3054         case 1:
3055         {
3056             s32Ret = HAL_AUDIO_MP3_ENCODER2_Stop();
3057             break;
3058         }
3059 
3060         default:
3061         {
3062             s32Ret = -A_ENODEV;
3063             break;
3064         }
3065     }
3066 
3067     return s32Ret;
3068 }
3069 
MDrv_AUDIO_ENCODER_Ioctl(MS_S32 s32DeviceId,const char * pCmd,void * pData)3070 MS_S32 MDrv_AUDIO_ENCODER_Ioctl(MS_S32 s32DeviceId, const char *pCmd, void *pData)
3071 {
3072     MS_U32 u32Cmd = 0;
3073     MS_S32 s32Ret = 0;
3074     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Ioctl command '%s' to Encoder device-id %d\n", __FUNCTION__, pCmd, s32DeviceId);
3075 
3076     DRVAUDIO_CHECK_SHM_INIT;
3077 
3078     if (pCmd == NULL)
3079     {
3080         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pCmd should not be NULL!\n", __FUNCTION__);
3081         return -A_EFAULT;
3082     }
3083 
3084     if (pData == NULL)
3085     {
3086         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pData should not be NULL!\n", __FUNCTION__);
3087         return -A_EFAULT;
3088     }
3089 
3090     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_ENCODER_MAXNUM))
3091     {
3092         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
3093         return -A_EINVAL;
3094     }
3095 
3096     if (MDrv_AUDIO_ENCODER_StrCmd_To_U32Cmd(pCmd, &u32Cmd) < 0)
3097     {
3098         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Warning! pCmd '%s' is not supported!\n", __FUNCTION__, pCmd);
3099         return -A_EINVAL;
3100     }
3101 
3102     switch (s32DeviceId)
3103     {
3104         case 0:
3105         {
3106             s32Ret = HAL_AUDIO_MP3_ENCODER1_Ioctl(u32Cmd, pData);
3107             break;
3108         }
3109 
3110         case 1:
3111         {
3112             s32Ret = HAL_AUDIO_MP3_ENCODER2_Ioctl(u32Cmd, pData);
3113             break;
3114         }
3115 
3116         default:
3117         {
3118             s32Ret = -A_ENODEV;
3119             break;
3120         }
3121     }
3122 
3123     return s32Ret;
3124 }
3125 
MDrv_AUDIO_ENCODER_Read(MS_S32 s32DeviceId,void * pBuf,MS_U32 u32Size)3126 MS_U32 MDrv_AUDIO_ENCODER_Read(MS_S32 s32DeviceId, void *pBuf, MS_U32 u32Size)
3127 {
3128     MS_S32 s32Ret = 0;
3129     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Read %u bytes from Encoder device-id %d\n", __FUNCTION__, u32Size, s32DeviceId);
3130 
3131     DRVAUDIO_CHECK_SHM_INIT;
3132 
3133     if (pBuf == NULL)
3134     {
3135         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! pBuf should not be NULL!\n", __FUNCTION__);
3136         return -A_EFAULT;
3137     }
3138 
3139     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_ENCODER_MAXNUM))
3140     {
3141         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
3142         return -A_EINVAL;
3143     }
3144 
3145     if (u32Size == 0)
3146     {
3147         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! u32Size(%u) is invalid!\n", __FUNCTION__, (unsigned int)u32Size);
3148         return u32Size;
3149     }
3150 
3151     switch (s32DeviceId)
3152     {
3153         case 0:
3154         {
3155             s32Ret = HAL_AUDIO_MP3_ENCODER1_Read(pBuf, u32Size);
3156             break;
3157         }
3158 
3159         case 1:
3160         {
3161             s32Ret = HAL_AUDIO_MP3_ENCODER2_Read(pBuf, u32Size);
3162             break;
3163         }
3164 
3165         default:
3166         {
3167             s32Ret = -A_ENODEV;
3168             break;
3169         }
3170     }
3171 
3172     return s32Ret;
3173 }
3174 
MDrv_AUDIO_ENCODER_Flush(MS_S32 s32DeviceId)3175 MS_S32 MDrv_AUDIO_ENCODER_Flush(MS_S32 s32DeviceId)
3176 {
3177     MS_S32 s32Ret = 0;
3178     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Flush Encoder device-id %d\n", __FUNCTION__, (int)s32DeviceId);
3179 
3180     DRVAUDIO_CHECK_SHM_INIT;
3181 
3182     if ((s32DeviceId < 0) || (s32DeviceId >= AUDIO_ENCODER_MAXNUM))
3183     {
3184         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: Error! s32DeviceId(%d) is invalid!\n", __FUNCTION__, (int)s32DeviceId);
3185         return -A_EINVAL;
3186     }
3187 
3188     switch (s32DeviceId)
3189     {
3190         case 0:
3191         {
3192             s32Ret = HAL_AUDIO_MP3_ENCODER1_Flush();
3193             break;
3194         }
3195 
3196         case 1:
3197         {
3198             s32Ret = HAL_AUDIO_MP3_ENCODER2_Flush();
3199             break;
3200         }
3201 
3202         default:
3203         {
3204             s32Ret = -A_ENODEV;
3205             break;
3206         }
3207     }
3208 
3209     return s32Ret;
3210 }