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 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
80 // All rights reserved.
81 //
82 // [Module Name]:
83 // drvMAD2.c
84 // [Abstract]:
85 // This module contains code for Audio 2nd DSP driver
86 // procedure and subroutin
87 // [Reversion History]:
88 // Initial release: 15 July, 2005
89 //
90 // [Doxygen]
91 /// file drvMAD2.c
92 /// @brief Subroutine for Audio 2nd DSP
93 /// @author MStarSemi Inc.
94 //*******************************************************************************
95
96 #include "MsCommon.h"
97 #include "MsIRQ.h"
98 #include "MsOS.h"
99 #include "MsTypes.h"
100
101 // Internal
102 #include "drvAUDIO_if.h"
103 #include "drvAUDIO.h"
104
105 #include "./internal/drvSOUND.h"
106 #include "./internal/drvMAD.h"
107 #include "./internal/drvMAD2.h"
108 #include "./internal/drvAUDIO_internal.h"
109
110 #include "halAUDIO.h"
111 #include "halMAD.h"
112 #include "halMAD2.h"
113 #include "halSIF.h"
114 #include "regAUDIO.h"
115
116 //-------------------------------------------------------------------------------------------------
117 // Driver Compiler Options
118 //-------------------------------------------------------------------------------------------------
119 #define H2BYTE(value) ((MS_U8)((value) / 0x10000))
120
121 extern MS_U8 g_Dsp2CodeType;
122 extern MS_U32 MadBaseBufferAdr;
123
124 //Temp mask by Cathy extern MS_U8 CheckIPControlBit(MS_U8 u8Bit);
125
126
127 MS_U8 DVB2_IP_CONTROL_BIT[] =
128 {
129 255, //MPEG_AD
130 11, //AC3_AD
131 12, //AC3P_AD
132 255, //AAC_AD
133 13, //DDE
134 255, //SBC
135 255, //MP3
136 255, //MPEG_EN
137 255, //DTSE
138 255, //XPCM
139 255, //KTV
140 255, //KTV2
141 255, //NONE
142 };
143
144 //======================================================================
145 ////////////////////////////////////////////////////////////////////////////////
146 /// @brief \b Function \b Name: MDrv_MAD2_SetMemInfo()
147 /// @brief \b Function \b Description: This routine is used to set the SE-DSP memory information
148 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_SetMemInfo(void)149 void MDrv_MAD2_SetMemInfo(void)
150 {
151 HAL_MAD2_SetMemInfo();
152 }
153
154 ////////////////////////////////////////////////////////////////////////////////
155 /// @brief \b Function \b Name: MDrv_MAD2_SetDecCmd()
156 /// @brief \b Function \b Description: This routine is to set the DVB2 decoder command.
157 /// @param u8DecCmd \b system command :
158 /// AU_DVB2_DECCMD_STOP, //0
159 /// AU_DVB2_DECCMD_PLAY, //1
160 /// AU_DVB2_DECCMD_PLAYFILETSP = 2,
161 /// AU_DVB2_DECCMD_RESYNC,
162 /// AU_DVB2_DECCMD_PLAYFILE = 4,
163 /// AU_DVB2_DECCMD_PAUSE = 6
164 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_SetDecCmd(AU_DVB2_DECCMD u8DecCmd)165 void MDrv_MAD2_SetDecCmd(AU_DVB2_DECCMD u8DecCmd)
166 {
167 HAL_MAD2_SetDecCmd((AU_DVB_DECCMD)u8DecCmd);
168 }
169
170 ///////////////////////////////////////////////////////////////////////////////////////
171 /// @brief \b Function \b Name: MDrv_MAD2_GetDecCmd()
172 /// @brief \b Function \b Description: This routine is to get the DVB2 decode command.
173 /// @return AU_DVB_DECCMD \b command type:
174 /// AU_DVB_DECCMD_STOP, //0
175 /// AU_DVB_DECCMD_PLAY, //1
176 /// AU_DVB_DECCMD_PLAYFILETSP = 2,
177 /// AU_DVB_DECCMD_RESYNC,
178 /// ....etc
179 ///////////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_GetDecCmd(void)180 AU_DVB_DECCMD MDrv_MAD2_GetDecCmd(void)
181 {
182 return (AU_DVB_DECCMD) (HAL_MAD2_GetDecCmd()&0xF);
183 }
184
185 ////////////////////////////////////////////////////////////////////////////////
186 /// @brief \b Function \b Name: MDrv_MAD2_SetFreeRun()
187 /// @brief \b Function \b Description: This routine is to set the DVB2 decoder in free run or AV-sync mode.
188 /// @param u8FreeRun \b AU_DVB2_FreeRunMode_AVsync 0--normal AV sync
189 /// AU_DVB2_FreeRunMode_FreeRun 1--free-run mode
190 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_SetFreeRun(AU_DVB2_FreeRunMode u8FreeRun)191 void MDrv_MAD2_SetFreeRun(AU_DVB2_FreeRunMode u8FreeRun)
192 {
193 HAL_MAD2_SetFreeRun((MS_U8)u8FreeRun);
194 }
195
196 ////////////////////////////////////////////////////////////////////////////////
197 /// @brief \b Function \b Name: MDrv_MAD2_RebootDsp(void)
198 /// @brief \b Function \b Description: This routine reboot Sound Effect DSP.
199 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_RebootDsp(void)200 void MDrv_MAD2_RebootDsp(void)
201 {
202 HAL_MAD2_RebootDsp();
203 }
204
205 ////////////////////////////////////////////////////////////////////////////////
206 /// @brief \b Function \b Name: MDrv_MAD2_DisEn_MIUREQ()
207 /// @brief \b Function \b Description: This routine is to reset DVB2 MIU request command.
208 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_DisEn_MIUREQ(void)209 void MDrv_MAD2_DisEn_MIUREQ(void)
210 {
211 HAL_MAD2_DisEn_MIUREQ();
212 }
213
214 ////////////////////////////////////////////////////////////////////////////////
215 /// @brief \b Function \b Name: MDrv_MAD2_DisEn_MIUREQ()
216 /// @brief \b Function \b Description: This routine is to reset DVB2 MIU request command.
217 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_DisMiuReq(void)218 void MDrv_MAD2_DisMiuReq(void)
219 {
220 HAL_MAD2_DisMiuReq();
221 }
222
223 ////////////////////////////////////////////////////////////////////////////////
224 /// @brief \b Function \b Name: MDrv_MAD2_DisEn_MIUREQ()
225 /// @brief \b Function \b Description: This routine is to reset DVB2 MIU request command.
226 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_RSTMAD_DisEn_MIUREQ(void)227 void MDrv_MAD2_RSTMAD_DisEn_MIUREQ(void)
228 {
229 HAL_MAD2_RSTMAD_DisEn_MIUREQ();
230
231 }
232
233
234
235 ////////////////////////////////////////////////////////////////////////////////
236 /// @brief \b Function \b Name: MDrv_MAD2_XPCM2_CheckIntStatus()
237 /// @brief \b Function \b Description: This routine is used to Read DSP internal sram value for int status by IDMA
238 /// @param <OUT> \b NONE :
239 /// @param <RET> \b value : MS_U32 sram value for interrupt status
240 /// @param <GLOBAL> \b NONE :
241 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_XPCM2_CheckIntStatus(void)242 MS_U16 MDrv_MAD2_XPCM2_CheckIntStatus(void)
243 {
244 return (MS_U16)HAL_MAD2_Read_DSP_sram(0x1494, DSP_MEM_TYPE_DM);
245
246 }
247
248 ////////////////////////////////////////////////////////////////////////////////
249 /// @brief \b Function \b Name: MDrv_MAD2_XPCM_setParam()
250 /// @brief \b Function \b Description: This routine configures necessary parameters when playing XPCM data
251 /// @param audioType \b type: 1--lpcm
252 /// 2--MS-ADPCM
253 /// 17--IMA-ADPCM
254 /// @param Channels \b channel num: 0-- mono
255 /// 1-- stereo
256 /// @param sampleRate \b sample rate: 8, 11.025, 16, 22.05, 44.1, 48 (KHz)
257 /// @param bitsPerSample \b bit per sample: 8--8 bits
258 /// 16--16 bits
259 /// @param blockSize \b block size
260 /// @param samplePerBlock \b samples per block
261 /// @return MS_U8 \b TRUE--parameters are correct
262 /// FALSE--parameters are incorrect
263 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_XPCM_setParam(XPCM_TYPE audioType,MS_U8 channels,MS_U16 sampleRate,MS_U8 bitsPerSample,MS_U16 blockSize,MS_U16 samplePerBlock)264 void MDrv_MAD2_XPCM_setParam (XPCM_TYPE audioType, MS_U8 channels, MS_U16 sampleRate,
265 MS_U8 bitsPerSample, MS_U16 blockSize, MS_U16 samplePerBlock)
266 {
267 HAL_MAD2_XPCM_setParam (audioType,channels, sampleRate,
268 bitsPerSample, blockSize, samplePerBlock);
269 }
270
271 ////////////////////////////////////////////////////////////////////////////////
272 /// @brief \b Function \b Name: MDrv_MAD2_Read_DSP_sram()
273 /// @brief \b Function \b Description: This routine is used to Read DSP internal sram value by IDMA
274 /// @param <IN> \b u16Dsp_addr : DSP internal sram address
275 /// @param <IN> \b dm : 0--DSP_MEM_TYPE_PM
276 /// 1--DSP_MEM_TYPE_DM
277 /// @param <OUT> \b NONE :
278 /// @param <RET> \b value : MS_U32 sram value
279 /// @param <GLOBAL> \b NONE :
280 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_Read_DSP_sram(MS_U16 u16Dsp_addr,AUDIO_DSP_MEMORY_TYPE dsp_memory_type)281 MS_U32 MDrv_MAD2_Read_DSP_sram(MS_U16 u16Dsp_addr,AUDIO_DSP_MEMORY_TYPE dsp_memory_type)
282 {
283 return (HAL_MAD2_Read_DSP_sram(u16Dsp_addr, dsp_memory_type));
284 }
285
286 ////////////////////////////////////////////////////////////////////////////////
287 /// @brief \b Function \b Name: MDrv_MAD2_Write_DSP_sram()
288 /// @brief \b Function \b Description: This routine is used to Write DSP internal sram value by IDMA
289 /// @param <IN> \b u16Dsp_addr : DSP internal sram address
290 /// @param <IN> \b u32Value : data want to write
291 /// @param <IN> \b dm : 0-- write to DSP_MEM_TYPE_PM
292 /// 1-- write to DSP_MEM_TYPE_DM
293 /// @param <OUT> \b NONE :
294 /// @param <RET> \b NONE :
295 /// @param <GLOBAL> \b NONE :
296 ////////////////////////////////////////////////////////////////////////////////
MDrv_MAD2_Write_DSP_sram(MS_U16 u16Dsp_addr,MS_U32 u32Value,AUDIO_DSP_MEMORY_TYPE dsp_memory_type)297 MS_BOOL MDrv_MAD2_Write_DSP_sram(MS_U16 u16Dsp_addr, MS_U32 u32Value, AUDIO_DSP_MEMORY_TYPE dsp_memory_type)
298 {
299 return(HAL_MAD2_Write_DSP_sram(u16Dsp_addr, u32Value, dsp_memory_type));
300 }
301
302
303