[Feature]Upload Modem source code

Change-Id: Id4294f30faced84d3e6fd6d5e61e1111bf287a37
diff --git a/mcu/middleware/media/audio/src/aud_ilm.c b/mcu/middleware/media/audio/src/aud_ilm.c
new file mode 100644
index 0000000..581ee32
--- /dev/null
+++ b/mcu/middleware/media/audio/src/aud_ilm.c
@@ -0,0 +1,662 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2012
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*******************************************************************************
+ * Filename:
+ * ---------
+ * aud_ilm.c
+ *
+ * Project:
+ * --------
+ *   Maui
+ *
+ * Description:
+ * ------------
+ *   This file includes send-ilm related funcions of audio manager task.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+
+#ifndef MED_NOT_PRESENT
+
+/*==== INCLUDES ===========*/
+
+/* system includes */ 
+#include "kal_general_types.h"
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "mw_sap.h"
+#include "svc_sap.h"
+#include "drv_sap.h"
+#include "med_msgid.h"
+#include "nvram_msgid.h"
+
+/* global includes */
+#include "l1audio.h"
+#include "nvram_struct.h"
+#include "audio_nvram_def.h"
+ 
+/* local includes */
+#include "med_global.h"
+#include "aud_defs.h"
+#include "med_struct.h"
+#include "med_context.h"
+#include "aud_main.h"
+
+
+#include "string.h"
+ 
+/*****************************************************************************
+ * FUNCTION
+ *  aud_send_ilm
+ * DESCRIPTION
+ *  This function is used to send ilm.
+ * PARAMETERS
+ *  dest_id             [IN]        
+ *  msg_id              [IN]        
+ *  local_param_ptr     [?]         
+ *  peer_buf_ptr        [?]         
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void aud_send_ilm(module_type dest_id, kal_uint16 msg_id, void *local_param_ptr, void *peer_buf_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    module_type src_id;
+    sap_type sap_id;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /* Check destination module ID */
+    if (dest_id == MOD_NIL)
+    {
+        return;
+    }
+
+    /* Get source module ID */
+    if (kal_if_hisr())
+    {
+//        src_id = MOD_VISUAL_HISR;
+        return;
+    }
+    else
+    {
+        src_id = kal_get_active_module_id();
+    }
+
+    switch (dest_id)
+    {
+        case MOD_MED:
+            sap_id = MED_SAP;
+            break;
+        case MOD_UEM:
+            sap_id = MED_SAP;
+            break;
+        case MOD_NVRAM:
+            sap_id = PS_NVRAM_SAP;
+            break;
+        default:
+            sap_id = MED_SAP;
+            break;
+    }
+    
+    msg_send6(src_id,dest_id,sap_id,msg_id,(local_para_struct*)local_param_ptr,(peer_buff_struct*)peer_buf_ptr);
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  aud_send_msg_to_nvram
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  msg_name        [IN]        
+ *  ef_id           [IN]        
+ *  data_ptr        [?]         
+ *  length          [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void aud_send_msg_to_nvram(msg_type msg_name, kal_uint16 ef_id, void *data_ptr, kal_uint16 length)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    peer_buff_struct *data_stream;
+    local_para_struct *parm_stream;
+    kal_uint16 pdu_len;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    switch (msg_name)
+    {
+        case MSG_ID_NVRAM_WRITE_REQ:
+            switch (ef_id)
+            {
+                case NVRAM_EF_CUST_ACOUSTIC_DATA_LID:
+                case NVRAM_EF_AUDIO_PARAM_LID:
+                case NVRAM_EF_AUDIO_DC_CALIBRATION_LID:
+            #ifdef __AMRWB_LINK_SUPPORT__
+                case NVRAM_EF_AUDIO_WB_SPEECH_INPUT_FIR_LID:
+                case NVRAM_EF_AUDIO_WB_SPEECH_OUTPUT_FIR_LID:
+                case NVRAM_EF_AUDIO_WB_SPEECH_MODE_PARAM_LID:
+            #endif /* __AMRWB_LINK_SUPPORT__ */
+                    parm_stream = construct_local_para(sizeof(nvram_write_req_struct), TD_CTRL);
+                    data_stream = construct_peer_buff(length, 0, 0, TD_CTRL);
+
+                    ((nvram_write_req_struct*) parm_stream)->file_idx = (kal_uint16) ef_id;
+                    ((nvram_write_req_struct*) parm_stream)->para = 1;
+                    ((nvram_write_req_struct*) parm_stream)->access_id = 0;
+
+                    pdu_len = length;
+                    kal_mem_cpy(get_peer_buff_pdu(data_stream, &pdu_len), data_ptr, length);
+
+                    aud_send_ilm(MOD_NVRAM, MSG_ID_NVRAM_WRITE_REQ, parm_stream, data_stream);
+                    break;
+                default:
+                    /* error write */
+                    break;
+            }
+            break;
+        case MSG_ID_NVRAM_READ_REQ:
+            switch (ef_id)
+            {
+                case NVRAM_EF_CUST_ACOUSTIC_DATA_LID:
+                case NVRAM_EF_AUDIO_PARAM_LID:
+                case NVRAM_EF_AUDIO_DC_CALIBRATION_LID:
+            #ifdef __GAIN_TABLE_SUPPORT__
+                case NVRAM_EF_AUDIO_GAIN_TABLE_LID:
+            #endif /* __GAIN_TABLE_SUPPORT__ */
+            #ifdef __SPEECH_MODE_TABLE_SUPPORT__
+                case NVRAM_EF_AUDIO_SPEECH_MODE_TABLE_LID:
+            #endif /* __SPEECH_MODE_TABLE_SUPPORT__ */
+            #ifdef __AMRWB_LINK_SUPPORT__
+                case NVRAM_EF_AUDIO_WB_SPEECH_INPUT_FIR_LID:
+                case NVRAM_EF_AUDIO_WB_SPEECH_OUTPUT_FIR_LID:
+                case NVRAM_EF_AUDIO_WB_SPEECH_MODE_PARAM_LID:
+            #endif /* __AMRWB_LINK_SUPPORT__ */
+            #ifdef __DUAL_MIC_SUPPORT__
+                case NVRAM_EF_AUDIO_DUAL_MIC_PARAM_LID:
+            #endif
+                    parm_stream = construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
+
+                    ((nvram_read_req_struct*) parm_stream)->file_idx = (kal_uint16) ef_id;
+                    ((nvram_read_req_struct*) parm_stream)->para = 1;
+
+                    aud_send_ilm(MOD_NVRAM, MSG_ID_NVRAM_READ_REQ, parm_stream, NULL);
+                    break;
+                default:
+                    /* error read */
+                    break;
+            }
+            break;
+        default:
+            break;
+    }   /* End Switch */
+
+    return;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  aud_send_startup_cnf
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  result      [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void aud_send_startup_cnf(kal_uint8 result)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    med_startup_cnf_struct *cnf_p = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    cnf_p = (med_startup_cnf_struct*) construct_local_para(sizeof(med_startup_cnf_struct), TD_CTRL);
+
+    /* send confirm message to L4 */
+    cnf_p->result = result;
+
+    aud_send_ilm(aud_context_p->src_mod, MSG_ID_MED_STARTUP_CNF, cnf_p, NULL);
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  aud_send_set_audio_profile_cnf
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  result      [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void aud_send_set_audio_profile_cnf(kal_uint8 result)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    media_aud_set_audio_profile_cnf_struct *cnf_p = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    cnf_p = (media_aud_set_audio_profile_cnf_struct*)
+        construct_local_para(sizeof(media_aud_set_audio_profile_cnf_struct), TD_CTRL);
+
+    /* send confirm message to L4 */
+    cnf_p->src_id = aud_context_p->src_id;
+    if(result == 0) /* MED_RES_OK */
+    {
+        cnf_p->result = KAL_TRUE;
+    }
+    else
+    {
+        cnf_p->result = KAL_FALSE;
+    }
+    cnf_p->cause = result;
+
+    aud_send_ilm(aud_context_p->src_mod, MSG_ID_MEDIA_AUD_SET_AUDIO_PROFILE_CNF, cnf_p, NULL);
+
+}
+
+void aud_send_in_proc_call_req(
+        module_type src_mod_id,
+        media_in_proc_call_type func,
+        kal_uint32 func_arg1,
+        void *func_arg2)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    media_in_proc_call_req_struct *msg_p = (media_in_proc_call_req_struct*)
+        construct_local_para(sizeof(media_in_proc_call_req_struct), TD_CTRL);
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    msg_p->func = func;
+    msg_p->func_arg1 = func_arg1;
+    msg_p->func_arg2 = func_arg2;
+
+    //aud_send_msg_to_med((module_type)src_mod_id, (kal_uint16) MSG_ID_MEDIA_IN_PROC_CALL_REQ, (void *)msg_p);
+    aud_send_ilm(MOD_MED, (kal_uint16) MSG_ID_MEDIA_IN_PROC_CALL_REQ, (void *)msg_p, NULL);
+}
+
+#ifdef __AMRWB_LINK_SUPPORT__
+/*****************************************************************************
+ * FUNCTION
+ *  aud_send_set_audio_wb_input_fir_cnf
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  result      [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void aud_send_set_audio_wb_input_fir_cnf(kal_uint8 result)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    media_aud_set_audio_wb_input_fir_param_cnf_struct *cnf_p = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    cnf_p = (media_aud_set_audio_wb_input_fir_param_cnf_struct*)
+        construct_local_para(sizeof(media_aud_set_audio_wb_input_fir_param_cnf_struct), TD_CTRL);
+
+    /* send confirm message to L4 */
+    cnf_p->src_id = aud_context_p->src_id;
+
+    if(result == 0) /* MED_RES_OK */
+    {
+        cnf_p->result = KAL_TRUE;
+    }
+    else
+    {
+        cnf_p->result = KAL_FALSE;
+    }
+    cnf_p->cause = result;
+
+    aud_send_ilm(aud_context_p->src_mod, MSG_ID_MEDIA_AUD_SET_AUDIO_WB_INPUT_FIR_PARAM_CNF, cnf_p, NULL);
+
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  aud_send_set_audio_wb_output_fir_cnf
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  input       [IN]
+ *  result      [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void aud_send_set_audio_wb_output_fir_cnf(kal_uint8 result)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    media_aud_set_audio_wb_output_fir_param_cnf_struct *cnf_p = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    cnf_p = (media_aud_set_audio_wb_output_fir_param_cnf_struct*)
+        construct_local_para(sizeof(media_aud_set_audio_wb_output_fir_param_cnf_struct), TD_CTRL);
+
+    /* send confirm message to L4 */
+    cnf_p->src_id = aud_context_p->src_id;
+
+    if(result == 0) /* MED_RES_OK */
+    {
+        cnf_p->result = KAL_TRUE;
+    }
+    else
+    {
+        cnf_p->result = KAL_FALSE;
+    }
+    cnf_p->cause = result;
+
+    aud_send_ilm(aud_context_p->src_mod, MSG_ID_MEDIA_AUD_SET_AUDIO_WB_OUTPUT_FIR_PARAM_CNF, cnf_p, NULL);
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  aud_send_set_audio_wb_mode_cnf
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  result      [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void aud_send_set_audio_wb_mode_cnf(kal_uint8 result)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    media_aud_set_audio_wb_mode_param_cnf_struct *cnf_p = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    cnf_p = (media_aud_set_audio_wb_mode_param_cnf_struct*)
+        construct_local_para(sizeof(media_aud_set_audio_wb_mode_param_cnf_struct), TD_CTRL);
+
+    /* send confirm message to L4 */
+    cnf_p->src_id = aud_context_p->src_id;
+
+    if(result == 0) /* MED_RES_OK */
+    {
+        cnf_p->result = KAL_TRUE;
+    }
+    else
+    {
+        cnf_p->result = KAL_FALSE;
+    }
+    cnf_p->cause = result;
+
+    aud_send_ilm(aud_context_p->src_mod, MSG_ID_MEDIA_AUD_SET_AUDIO_WB_MODE_PARAM_CNF, cnf_p, NULL);
+
+}
+
+#endif /*__AMRWB_LINK_SUPPORT__*/
+
+/*****************************************************************************
+ * FUNCTION
+ *  aud_send_set_audio_param_cnf
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  result      [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void aud_send_set_audio_param_cnf(kal_uint8 result)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    media_aud_set_audio_param_cnf_struct *cnf_p = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    cnf_p = (media_aud_set_audio_param_cnf_struct*)
+        construct_local_para(sizeof(media_aud_set_audio_param_cnf_struct), TD_CTRL);
+
+    /* send confirm message to L4 */
+    cnf_p->src_id = aud_context_p->src_id;
+    if(result == 0) /* MED_RES_OK */
+    {
+        cnf_p->result = KAL_TRUE;
+    }
+    else
+    {
+        cnf_p->result = KAL_FALSE;
+    }
+    cnf_p->cause = result;
+
+    aud_send_ilm(aud_context_p->src_mod, MSG_ID_MEDIA_AUD_SET_AUDIO_PARAM_CNF, cnf_p, NULL);
+
+}
+
+#else /* MED_NOT_PRESENT */ 
+
+/*==== INCLUDES ===========*/
+
+/* system includes */ 
+#include "kal_general_types.h"
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "mw_sap.h"
+#include "svc_sap.h"
+#include "drv_sap.h"
+#include "med_msgid.h"
+#include "nvram_msgid.h"
+
+/* global includes */
+#include "l1audio.h"
+#include "nvram_struct.h"
+#include "audio_nvram_def.h"
+ 
+/* local includes */
+#include "med_global.h"
+#include "aud_defs.h"
+#include "med_struct.h"
+#include "med_context.h"
+#include "aud_main.h"
+
+
+#include "string.h"
+ 
+/*****************************************************************************
+ * FUNCTION
+ *  aud_send_ilm
+ * DESCRIPTION
+ *  This function is used to send ilm.
+ * PARAMETERS
+ *  dest_id             [IN]        
+ *  msg_id              [IN]        
+ *  local_param_ptr     [?]         
+ *  peer_buf_ptr        [?]         
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void aud_send_ilm(module_type dest_id, kal_uint16 msg_id, void *local_param_ptr, void *peer_buf_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    module_type src_id;
+    sap_type sap_id;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    /* Check destination module ID */
+    if (dest_id == MOD_NIL)
+    {
+        return;
+    }
+
+    /* Get source module ID */
+    if (kal_if_hisr())
+    {
+        src_id = MOD_VISUAL_HISR;//MOD_VISUAL_HISR;//MOD_TIMER_HISR �٬O  MOD_GPT_TIMER
+
+       // return;
+    }
+    else
+    {
+        src_id = kal_get_active_module_id();
+    }
+
+    switch (dest_id)
+    {
+        case MOD_MED:
+            sap_id = MED_SAP;
+            break;
+        case MOD_UEM:
+            sap_id = MED_SAP;
+            break;
+        case MOD_NVRAM:
+            sap_id = PS_NVRAM_SAP;
+            break;
+        default:
+            sap_id = MED_SAP;
+            break;
+    }
+    
+    msg_send6(src_id,dest_id,sap_id,msg_id,(local_para_struct*)local_param_ptr,(peer_buff_struct*)peer_buf_ptr);
+}
+
+void aud_send_in_proc_call_req(
+        module_type src_mod_id,
+        media_in_proc_call_type func,
+        kal_uint32 func_arg1,
+        void *func_arg2)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    media_in_proc_call_req_struct *msg_p = (media_in_proc_call_req_struct*)
+        construct_local_para(sizeof(media_in_proc_call_req_struct), TD_CTRL);
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    msg_p->func = func;
+    msg_p->func_arg1 = func_arg1;
+    msg_p->func_arg2 = func_arg2;
+
+    //aud_send_msg_to_med((module_type)src_mod_id, (kal_uint16) MSG_ID_MEDIA_IN_PROC_CALL_REQ, (void *)msg_p);
+    aud_send_ilm(MOD_MED, (kal_uint16) MSG_ID_MEDIA_IN_PROC_CALL_REQ, (void *)msg_p, NULL);
+
+}
+
+
+#endif /* MED_NOT_PRESENT */ 
+
+
+
diff --git a/mcu/middleware/media/common/src/med_ext_smalloc.c b/mcu/middleware/media/common/src/med_ext_smalloc.c
new file mode 100644
index 0000000..d75afff
--- /dev/null
+++ b/mcu/middleware/media/common/src/med_ext_smalloc.c
@@ -0,0 +1,247 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2012
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*******************************************************************************
+ * Filename:
+ * ---------
+ *  med_ext_smalloc.c
+ *
+ * Project:
+ * --------
+ *  MAUI
+ *
+ * Description:
+ * ------------
+ *  
+ *
+ * Author:
+ * -------
+ *  
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+
+#include "kal_public_defs.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+
+#include "med_trc.h"
+#include "med_global.h"
+#include "med_mem.h"
+#include "med_smalloc.h"
+#include "init.h"
+
+
+typedef struct{
+    KAL_ADM_ID aud_mem_pool_id;
+    kal_uint32 aud_mem_alloc_count;
+    kal_uint32 aud_mem_left_size;
+}med_ext_mem_struct;
+
+med_ext_mem_struct g_med_ext_mem_cntx;
+
+#if defined(__MED_MEM_CACHEABLE_SUPPORT__)
+#define MED_MEM_CACHEABLE_ALIGN_SIZE  32
+#else
+#define MED_MEM_CACHEABLE_ALIGN_SIZE  4
+#endif
+
+#if defined(__MED_MEM_DEBUG_ON__)
+    #define MED_MEM_ALLOC(adm_id,size,f,l)                          kal_adm_alloc_dbg(adm_id,size,f,l)
+    #define MED_MEM_ALLOC_TOPMOST_CACHEABLE(adm_id, size, a, f, l)  kal_adm_alloc_c_topmost_dbg(adm_id, size, a, f, l)
+    #define MED_MEM_ALLOC_TOPMOST(adm_id, size, a, f, l)            kal_adm_alloc_topmost_dbg(adm_id, size, a, f, l)
+    #define MED_MEM_ALLOC_CACHEABLE(adm_id, size, option, f, l)     kal_adm_alloc_cacheable_dbg(adm_id, size, option, f, l)
+    #define MED_MEM_ALLOC_FRAMEBUFFER(adm_id, size, a, f, l)        kal_adm_alloc_align_dbg(adm_id, size, a, f, l)
+#else
+    #define MED_MEM_ALLOC(adm_id,size,f,l)                          kal_adm_alloc(adm_id,size)
+    #define MED_MEM_ALLOC_TOPMOST(adm_id, size, a, f, l)            kal_adm_alloc_topmost(adm_id, size, a)
+    #define MED_MEM_ALLOC_TOPMOST_CACHEABLE(adm_id, size, a, f, l)  kal_adm_alloc_c_topmost(adm_id, size, a)
+    #define MED_MEM_ALLOC_CACHEABLE(adm_id, size, option, f, l)     kal_adm_alloc_cacheable(adm_id, size, option)
+    #define MED_MEM_ALLOC_FRAMEBUFFER(adm_id, size, a, f, l)        kal_adm_alloc_align(adm_id, size, a)
+#endif
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_ext_smalloc_ext
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  size        [IN]        
+ * RETURNS
+ *  
+ *****************************************************************************/
+address_t med_ext_smalloc_ext(size_type size, unsigned short location, const char *file, int line)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    void *ptr;
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (size == 0)
+    {
+        return NULL;
+    }
+
+    switch(location)
+    {
+        case MED_EXT_MEMORY_TYPE_AUDIO_NONCACHEABLE:
+        case MED_EXT_MEMORY_TYPE_AUDIO_CACHEABLE:
+            if (g_med_ext_mem_cntx.aud_mem_pool_id == 0)
+                return NULL;
+        break;
+        default:
+            return NULL;
+    }
+
+    if (location == MED_EXT_MEMORY_TYPE_AUDIO_NONCACHEABLE)
+    {
+        ptr = MED_MEM_ALLOC(g_med_ext_mem_cntx.aud_mem_pool_id, size,basename((char *)file), line);
+    }
+    else if (location == MED_EXT_MEMORY_TYPE_AUDIO_CACHEABLE)
+    {
+        ptr = MED_MEM_ALLOC_CACHEABLE(g_med_ext_mem_cntx.aud_mem_pool_id, size, MED_MEM_CACHEABLE_ALIGN_SIZE, basename((char *)file), line);
+    }
+
+    if (ptr!=NULL)
+    {
+        g_med_ext_mem_cntx.aud_mem_alloc_count++;
+        g_med_ext_mem_cntx.aud_mem_left_size = kal_adm_get_total_left_size(g_med_ext_mem_cntx.aud_mem_pool_id);
+        MED_MEM_INFO_AUD(MED_AUD_MEM_SIZE, size, g_med_ext_mem_cntx.aud_mem_left_size, ptr, g_med_ext_mem_cntx.aud_mem_alloc_count);
+    }
+    else
+    {
+
+        if (size < kal_adm_get_total_left_size(g_med_ext_mem_cntx.aud_mem_pool_id))
+        {
+            /* fragmentation */
+            MED_MEM_FRAGMENTATION_AUD(MED_AUD_MEM_SIZE, size, g_med_ext_mem_cntx.aud_mem_left_size,g_med_ext_mem_cntx.aud_mem_alloc_count);
+        }
+        else
+        {
+            /* concurrent */
+            MED_MEM_CONCURRENT_AUD(MED_AUD_MEM_SIZE, size, g_med_ext_mem_cntx.aud_mem_left_size,g_med_ext_mem_cntx.aud_mem_alloc_count);
+        }
+    }
+    return (address_t) ptr;
+}   /* malloc */
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_aud_sfree
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  ptr     [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void med_aud_sfree(address_t ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    if (ptr!=NULL)
+    {
+        kal_adm_free(g_med_ext_mem_cntx.aud_mem_pool_id, ptr);
+        g_med_ext_mem_cntx.aud_mem_alloc_count--;
+        g_med_ext_mem_cntx.aud_mem_left_size = kal_adm_get_total_left_size(g_med_ext_mem_cntx.aud_mem_pool_id);
+        MED_FREE_MEM_INFO_AUD(g_med_ext_mem_cntx.aud_mem_left_size, ptr, g_med_ext_mem_cntx.aud_mem_alloc_count );
+    }
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_set_aud_memory_pool
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  memory      [IN]        
+ *  size        [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void med_set_aud_memory_pool(address_t memory, size_type size)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    g_med_ext_mem_cntx.aud_mem_pool_id = kal_adm_create(
+                                            memory,
+                                            size,
+                                            NULL,
+                                    #if defined(__MED_MEM_DEBUG_ON__)
+                                            KAL_TRUE
+                                    #else                                            
+                                            KAL_FALSE
+                                    #endif
+                                            );
+    g_med_ext_mem_cntx.aud_mem_alloc_count = 0;
+    g_med_ext_mem_cntx.aud_mem_left_size = size;
+}
+
diff --git a/mcu/middleware/media/common/src/med_main.c b/mcu/middleware/media/common/src/med_main.c
new file mode 100644
index 0000000..87b4610
--- /dev/null
+++ b/mcu/middleware/media/common/src/med_main.c
@@ -0,0 +1,892 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2012
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*******************************************************************************
+ * Filename:
+ * ---------
+ *   med_main.c
+ *
+ * Project:
+ * --------
+ *   Maui
+ *
+ * Description:
+ * ------------
+ *   This file includes primary functions of media task.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+
+/*==== INCLUDES =========*/
+
+/* system includes */
+
+#include "kal_public_defs.h"
+#include "kal_general_types.h"
+#include "kal_public_api.h"
+#include "kal_trace.h"
+#include "syscomp_config.h"
+#include "task_config.h"
+#include "nvram_msgid.h"
+#include "sysservice_msgid.h"
+#include "tst_msgid.h"
+#include "med_msgid.h"
+#include "drv_msgid.h"
+#include "cmux_msgid.h"
+#include "audio_msgid.h"
+#include "em_msgid.h"
+
+#include "tst_sap.h"
+#include "drv_sap.h"
+
+
+/* global includes */
+#include "l1audio.h"
+#include "nvram_struct.h"
+#include "audio_nvram_def.h"
+#include "nvram_editor_data_item.h"
+// #include "aud_common_config.h"
+
+/* local include */
+#include "med_global.h"
+#include "med_mem.h"
+#include "med_struct.h"
+#include "med_context.h"
+#include "med_utility.h"
+
+#include "aud_main.h"
+#include "med_main.h"
+
+#ifdef __SPEECH_MODE_TABLE_SUPPORT__
+#include "speech_mode_table.h"
+#endif
+
+//Only for AUDIO_DEVICE_MICROPHONE
+#include "device.h"
+
+#include "em_struct.h"
+
+#if defined(__VOLTE_SUPPORT__)
+#include "ltecsr_msgid.h"
+#endif //#if defined(__VOLTE_SUPPORT__)
+
+
+/* global variables */
+med_context_struct med_context;
+med_context_struct *med_context_p = &med_context;
+
+#ifdef __MTK_TARGET__
+   #if defined(__DYNAMIC_SWITCH_CACHEABILITY__)
+      __attribute__ ((section ("DYNAMICCACHEABLEZI_NC_MMIPOOL"))) 
+      __attribute__((aligned(4)))
+      kal_uint8 med_aud_mem[MED_AUD_MEM_SIZE];
+   #else
+      __attribute__ ((section ("LARGEPOOL_ZI"))) 
+      __attribute__((aligned(4)))
+      kal_uint8 med_aud_mem[MED_AUD_MEM_SIZE];
+   #endif
+#else
+    kal_uint8 med_aud_mem[MED_AUD_MEM_SIZE];
+#endif
+
+
+#if !defined(MED_NOT_PRESENT)
+
+/*==== FUNCTIONS ===========*/
+extern void med_timer_expiry_hdlr(ilm_struct *ilm_ptr);
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_nvram_read_data_cnf_hdlr
+ * DESCRIPTION
+ *  This function is to handle nvram read data confirm.
+ * PARAMETERS
+ *  local_para_ptr      [?]     
+ *  peer_buff_ptr       [?]     
+ * RETURNS
+ *  void
+ *****************************************************************************/
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+            #if defined(__SPEECH_MODE_TABLE_SUPPORT__)
+/* under construction !*/
+            #elif defined(__AMRWB_LINK_SUPPORT__)
+/* under construction !*/
+            #elif defined(__DUAL_MIC_SUPPORT__)
+/* under construction !*/
+            #else
+/* under construction !*/
+            #endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+    #ifdef __SPEECH_MODE_TABLE_SUPPORT__        
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+            #if defined(__AMRWB_LINK_SUPPORT__)
+/* under construction !*/
+            #elif defined( __DUAL_MIC_SUPPORT__)
+/* under construction !*/
+            #else
+/* under construction !*/
+            #endif
+/* under construction !*/
+/* under construction !*/
+    #endif /* __SPEECH_MODE_TABLE_SUPPORT__ */
+/* under construction !*/
+    #ifdef __AMRWB_LINK_SUPPORT__
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+            #if defined(__DUAL_MIC_SUPPORT__)
+/* under construction !*/
+            #else
+/* under construction !*/
+            #endif
+/* under construction !*/
+/* under construction !*/
+    #endif /* __AMRWB_LINK_SUPPORT__ */
+/* under construction !*/
+    #ifdef __DUAL_MIC_SUPPORT__
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+        #ifdef __AMRWB_LINK_SUPPORT__
+/* under construction !*/
+        #endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+        #ifdef __AMRWB_LINK_SUPPORT__
+/* under construction !*/
+        #endif     
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+    #endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+    #ifdef __AMRWB_LINK_SUPPORT__
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+    #endif
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif   // #if 0 
+#endif   // #if !defined(MED_NOT_PRESENT)
+
+//#if !defined(MED_NOT_PRESENT)
+//extern void l1audio_console_handler(kal_char *string); 
+//#endif // 
+/*****************************************************************************
+ * FUNCTION
+ *  med_main
+ * DESCRIPTION
+ *  This function is main message dispatching function of media task.
+ * PARAMETERS
+ *  ilm_ptr     [?]     
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void med_main(ilm_struct *ilm_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+#if defined(__VOLTE_SUPPORT__)
+    if (ilm_ptr->msg_id == MSG_ID_LTECSR_VOICE_UL_DATA_NOTIFY)
+    {
+#ifndef __MTK_TARGET__
+        return;
+#else //#ifndef __MTK_TARGET__
+       void sp4g_fake_loopback(void);
+       sp4g_fake_loopback();
+#endif //#ifndef __MTK_TARGET__
+    }
+    if (ilm_ptr->msg_id == MSG_ID_LTECSR_VOICE_UL_MUTE_NOTIFY)
+    {
+        return;
+    }
+#endif //#if defined(__VOLTE_SUPPORT__)
+
+#if !defined(MED_NOT_PRESENT)
+    if (ilm_ptr->msg_id == MSG_ID_TIMER_EXPIRY)
+    {
+    	  ASSERT(0);
+        //med_timer_expiry_hdlr(ilm_ptr);
+    }
+    /*else if (ilm_ptr->msg_id == MSG_ID_MED_STARTUP_REQ)
+    {
+        med_startup_hdlr(ilm_ptr);
+    }
+    else if (ilm_ptr->msg_id == MSG_ID_NVRAM_READ_CNF)
+    {
+        med_nvram_read_data_cnf_hdlr(ilm_ptr->local_para_ptr, ilm_ptr->peer_buff_ptr);
+    }
+    else if (ilm_ptr->msg_id == MSG_ID_NVRAM_WRITE_CNF)
+    {
+        med_nvram_write_data_cnf_hdlr(ilm_ptr->local_para_ptr, ilm_ptr->peer_buff_ptr);
+    }
+    else if ( (ilm_ptr->msg_id >= MSG_ID_MED_CODE_BEGIN) && (ilm_ptr->msg_id <= MSG_ID_MED_CODE_TAIL) )
+    {
+        aud_main(ilm_ptr);
+    }*/
+    else if(ilm_ptr->msg_id == MSG_ID_MEDIA_AUD_SP_SET_MODE_REQ)
+	  {
+		   meida_aud_sp_set_mode_req_struct *req_p;
+		   req_p = (meida_aud_sp_set_mode_req_struct*) ilm_ptr->local_para_ptr;
+		   if (req_p->speech_on)
+		   {
+	          L1SP_Speech_On(req_p->rat_mode);	   	
+		   }
+		   else
+		   {
+		      L1SP_Speech_Off();
+		   }
+    }
+
+    else 
+#endif    
+    if (ilm_ptr->msg_id == MSG_ID_TST_INJECT_STRING) {
+	 	tst_module_string_inject_struct *tstInj = (tst_module_string_inject_struct *)ilm_ptr->local_para_ptr;
+		if(tstInj->index == 99 ) {
+			void l1audio_console_handler(kal_char *string);
+			l1audio_console_handler((kal_char *)(tstInj->string));
+		} else {
+			kal_prompt_trace(MOD_MED, "unused inject string index = %d ", tstInj->index);
+		}			
+	} else if(ilm_ptr->msg_id == MSG_ID_L4CPS_EM_UPDATE_REQ ) {
+		l4cps_em_update_req_struct * em_update_ptr = (l4cps_em_update_req_struct *) ilm_ptr->local_para_ptr;
+		if(em_update_ptr->em_src == EM_FROM_ELT) {
+			void SP_setEmCodecNotifyOff(kal_bool isOff);
+			if(EM_OFF == em_update_ptr->info_request[EM_SPEECH_INFO_SPH_CODEC]) {
+				SP_setEmCodecNotifyOff(KAL_TRUE);
+			} else if(EM_ON == em_update_ptr->info_request[EM_SPEECH_INFO_SPH_CODEC]) {
+				SP_setEmCodecNotifyOff(KAL_FALSE);
+			} // EM_NC, no change do nothing
+		} // else from AT do nothing
+	}
+
+	 if (ilm_ptr->msg_id ==  MSG_ID_AUDIO_L4C_EPOF_NOTIFY) {
+#if defined( __SMART_PHONE_MODEM__ )	 	
+		kal_prompt_trace(MOD_L1SP, "[EPOF]med_main receive L4C EPOF notify");
+		set_spcGetEpofTimes(ENUM_EPOF_MD1_L4C_NOTIFY, 1);
+		if( 0 == get_spcGetEpofTimes(ENUM_EPOF_DO_FORCEENDALLAPP) )
+		{
+			void Spc_ForceEndAllApp(void);
+			Spc_ForceEndAllApp();
+		}
+		if(get_spcGetEpofTimes(ENUM_EPOF_AP_ACK_NOTIFY))
+		{
+			//Notify L4C: speech driver enter EPOF done
+			msg_send6(MOD_MED, MOD_L4C, AUDIO_SAP, MSG_ID_AUDIO_L4C_EPOF_ACK, (local_para_struct *)NULL, NULL);
+			kal_prompt_trace(MOD_L1SP, "[EPOF]med_main notify L4C done");
+		}
+#else // #if defined( __SMART_PHONE_MODEM__ )
+		//Notify L4C: speech driver enter EPOF done
+		msg_send6(MOD_MED, MOD_L4C, AUDIO_SAP, MSG_ID_AUDIO_L4C_EPOF_ACK, (local_para_struct *)NULL, NULL);
+		kal_prompt_trace(MOD_L1SP, "[EPOF]med_main notify L4C done 2");
+#endif // #if defined( __SMART_PHONE_MODEM__ )	 	
+	 }
+
+#if defined(SHASTA_L)
+	 if (ilm_ptr->msg_id ==  MSG_ID_AUDIO_C2K_EPOF_NOTIFY) {
+#if defined( __SMART_PHONE_MODEM__ )
+		kal_prompt_trace(MOD_L1SP, "[EPOF]med_main receive C2K EPOF notify");
+		set_spcGetEpofTimes(ENUM_EPOF_C2K_NOTIFY, 1);
+		if( 0 == get_spcGetEpofTimes(ENUM_EPOF_DO_FORCEENDALLAPP) )
+		{
+			Spc_ForceEndAllApp();
+		}
+#endif // #if defined( __SMART_PHONE_MODEM__ )
+	 }
+#endif //#if defined(SHASTA_L)
+
+	if(ilm_ptr->msg_id == MSG_ID_AUDIO_CUST_DUMP_REQ) {
+#if defined( __SMART_PHONE_MODEM__ ) 
+		void spc_sendCustomDump(void *ilm);
+		spc_sendCustomDump(ilm_ptr->local_para_ptr);
+#endif 
+	}
+#if !defined(L1_NOT_PRESENT) && !defined(__UE_SIMULATOR__)
+  #if defined( __DATA_CARD_SPEECH__ )
+    if ( ( (ilm_ptr->msg_id >= CMUX_MSG_CODE_BEGIN) && (ilm_ptr->msg_id <= MSG_ID_CMUX_CODE_TAIL) )
+    	   || ( (ilm_ptr->msg_id >= MSG_ID_SPEECH_ON_ACK) && (ilm_ptr->msg_id <= MSG_ID_STRM_SPEECH_UL_DATA_REQUEST ) )
+    	   || ( (ilm_ptr->msg_id >= DRIVER_MSG_CODE_BEGIN) && (ilm_ptr->msg_id <= MSG_ID_DRIVER_CODE_TAIL) ) )
+    {
+        SP_Strm_Audl_Handler(ilm_ptr);
+    }
+  #endif
+  #if defined( __SMART_PHONE_MODEM__ )
+    if (ilm_ptr->msg_id == MSG_ID_AUDIO_A2M_CCCI)
+    {
+        SpcIO_Msg_Handler_inAudL(ilm_ptr);
+    } else if (ilm_ptr->msg_id == MSG_ID_MEDIA_AUD_MUTE_REQ) {
+    	 /*----------------------------------------------------------------*/
+	    /* Local Variables                                                */
+	    /*----------------------------------------------------------------*/
+	    kal_uint16 cnf_msg_id;
+	    void *cnf_p = NULL;
+
+	    media_aud_mute_req_struct *req_p;
+
+	    /*----------------------------------------------------------------*/
+	    /* Code Body                                                      */
+	    /*----------------------------------------------------------------*/
+	    req_p = (media_aud_mute_req_struct*) ilm_ptr->local_para_ptr;
+
+	    switch (req_p->device)
+	    {
+	        case AUDIO_DEVICE_MICROPHONE:
+	            /* call L1AUD to set microphone mute */
+	            L1SP_MuteMicrophone(req_p->mute);
+	            // aud_context_p->audio_mute = req_p->mute;
+	            break;
+	        default:
+	            break;
+	    }
+
+	    cnf_p = (media_aud_mute_cnf_struct*) construct_local_para(sizeof(media_aud_mute_cnf_struct), TD_CTRL);
+
+	    cnf_msg_id = MSG_ID_MEDIA_AUD_MUTE_CNF;
+
+	    // aud_send_ilm(ilm_ptr->src_mod_id, cnf_msg_id, cnf_p, NULL);
+	    msg_send6(kal_get_active_module_id(),ilm_ptr->src_mod_id,AUDIO_SAP,cnf_msg_id,cnf_p, NULL);
+    }
+  #endif
+#endif
+
+    if ((ilm_ptr->msg_id > MSG_ID_AUDIO_M2M_BEGIN) && (ilm_ptr->msg_id < MSG_ID_AUDIO_M2M_TAIL))
+    {
+        #ifdef __MTK_TARGET__
+        void SP_M2M_Handler(ilm_struct *ilm_ptr);
+        SP_M2M_Handler(ilm_ptr);
+        #endif //#ifdef __MTK_TARGET__
+    }
+#if !defined(__L1_STANDALONE__)    
+    if ((ilm_ptr->msg_id > MSG_ID_AUDIO_L2P_BEGIN) && (ilm_ptr->msg_id < MSG_ID_AUDIO_L2P_TAIL))
+    {
+        #ifdef __MTK_TARGET__
+        void SP_L2P_Handler(ilm_struct *ilm_ptr);
+        SP_L2P_Handler(ilm_ptr);
+        #endif //#ifdef __MTK_TARGET__
+    }        
+#endif   
+#if defined(__VOLTE_SUPPORT__)    
+    if ( ilm_ptr->msg_id == MSG_ID_MEDIA_IN_PROC_CALL_REQ )
+    {
+        #ifdef __MTK_TARGET__
+        void aud_util_in_proc_call_req_hdlr(ilm_struct *ilm_ptr);
+        kal_prompt_trace(MOD_L1SP, "[TONEDEBUG]MSG_ID_MEDIA_IN_PROC_CALL_REQ1");
+        aud_util_in_proc_call_req_hdlr(ilm_ptr);
+        #endif //#ifdef __MTK_TARGET__
+    }
+#endif   
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_task_main
+ * DESCRIPTION
+ *  This function is main function of media task.
+ * PARAMETERS
+ *  task_entry_ptr      [?]     
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void med_task_main(task_entry_struct *task_entry_ptr)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    ilm_struct current_ilm;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+
+#if !defined(L1_NOT_PRESENT) && !defined(__UE_SIMULATOR__)
+    SP_Drv_Init_Task();
+#endif
+
+    while (1)
+    {
+        msg_receive_extq(&current_ilm);
+        
+        kal_set_active_module_id(current_ilm.dest_mod_id);
+
+        med_main((void*)&current_ilm);
+
+        destroy_ilm(&current_ilm);
+    }
+
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_init
+ * DESCRIPTION
+ *  This function is used to init media task.
+ * PARAMETERS
+ *  task_indx       [IN]        
+ * RETURNS
+ *  
+ *****************************************************************************/
+kal_bool med_init(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+#if !defined(MED_NOT_PRESENT)
+    med_context_p->aud_mem_p = med_aud_mem;
+
+    /*if (!aud_init())
+    {
+        return KAL_FALSE;
+    }*/
+#else //#if !defined(MED_NOT_PRESENT)
+    #if defined(__MCU_DTMF_SUPPORT__) 
+    med_context_p->aud_mem_p = med_aud_mem;
+    #endif //#if defined(__MCU_DTMF_SUPPORT__) 
+#endif //#if !defined(MED_NOT_PRESENT)
+
+    if (!med_utility_init())
+    {
+        return KAL_FALSE;
+    }
+
+#if !defined(L1_NOT_PRESENT) && !defined(__UE_SIMULATOR__)
+    if (!SP_Drv_Init_Bootup())
+    {
+        return KAL_FALSE;
+    }
+#endif
+
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_reset
+ * DESCRIPTION
+ *  This function is used to reset media task.
+ * PARAMETERS
+ *  task_indx       [IN]        
+ * RETURNS
+ *  
+ *****************************************************************************/
+kal_bool med_reset(void)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    return KAL_TRUE;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_create
+ * DESCRIPTION
+ *  This function is used to create media task configuration info.
+ * PARAMETERS
+ *  handle      [IN]        
+ * RETURNS
+ *  
+ *****************************************************************************/
+kal_bool med_create(comptask_handler_struct **handle)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    static const comptask_handler_struct med_handler_info = 
+    {
+        med_task_main,  /* task entry function */
+        med_init,       /* task initialization function */
+        med_reset       /* task reset handler */
+    };
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    *handle = (comptask_handler_struct*) & med_handler_info;
+
+    return KAL_TRUE;
+}
+
diff --git a/mcu/middleware/media/common/src/med_utility.c b/mcu/middleware/media/common/src/med_utility.c
new file mode 100644
index 0000000..f85efd1
--- /dev/null
+++ b/mcu/middleware/media/common/src/med_utility.c
@@ -0,0 +1,288 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2012
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*******************************************************************************
+ * Filename:
+ * ---------
+ * med_utility.c
+ *
+ * Project:
+ * --------
+ *   Maui
+ *
+ * Description:
+ * ------------
+ *   This file includes common used functions of media task.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *==============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *------------------------------------------------------------------------------
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
+ *==============================================================================
+ *******************************************************************************/
+
+/*==== INCLUDES =========*/
+#include "kal_public_defs.h"
+#include "kal_public_api.h"
+#include "kal_general_types.h"
+#include "kal_trace.h"
+
+/* global includes */
+#include "l1audio.h"
+
+/* local includes */
+#include "med_main.h"
+#include "med_global.h"
+#include "med_mem.h"
+#include "med_struct.h"
+#include "med_context.h"
+#include "med_smalloc.h"
+#include "med_utility.h"
+#include "med_trc.h"
+#include "aud_main.h"
+
+kal_mutexid med_mem_mutex;
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_alloc_ext_mem
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  size        [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void *med_alloc_ext_mem_ext(kal_int32 size, kal_uint8 location, char* file_p, long line_p)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    void *p = NULL;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_take_mutex(med_mem_mutex);
+    p = (void*)med_ext_smalloc_ext((size_type) size, location, file_p, line_p);
+    kal_give_mutex(med_mem_mutex);
+
+    return p;
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_free_aud_mem_ext
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  pointer     [IN]        
+ * RETURNS
+ *  void
+ *****************************************************************************/
+void med_free_aud_mem_ext(void **pointer,char* file_p, long line_p)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    kal_take_mutex(med_mem_mutex);
+    med_aud_sfree((address_t) * pointer);
+    kal_give_mutex(med_mem_mutex);
+    *pointer = NULL;
+}
+
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_util_alloc_aud_mem
+ * DESCRIPTION
+ *  This function is to allocate memory from audio memory pool.
+ * PARAMETERS
+ *  size        [IN]        Memory size to be allocated.
+ *  file_p      [IN]        File name.
+ *  line        [IN]        Line number in the file.
+ * RETURNS
+ *  Allocated memory address
+ *****************************************************************************/
+static void* med_util_alloc_aud_mem(kal_uint32 size, char* file_p, long line)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/ 
+    return med_alloc_ext_mem_ext(size, MED_EXT_MEMORY_TYPE_AUDIO_NONCACHEABLE, file_p, line);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_util_alloc_aud_cacheable_mem
+ * DESCRIPTION
+ *  This function is to allocate cacheable memory from audio memory pool.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  Allocated memory address
+ *****************************************************************************/
+static void* med_util_alloc_aud_cacheable_mem(kal_uint32 size, char* file_p, long line)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/ 
+    return med_alloc_ext_mem_ext(size, MED_EXT_MEMORY_TYPE_AUDIO_CACHEABLE, file_p, line);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_util_free_aud_mem
+ * DESCRIPTION
+ *  This function is to free audio memory.
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  Allocated memory address
+ *****************************************************************************/
+static void med_util_free_aud_mem(void** mem_p, char* file_p, long line)
+{
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    med_free_aud_mem_ext(mem_p, file_p, line);
+}
+
+/*****************************************************************************
+ * FUNCTION
+ *  med_utility_init
+ * DESCRIPTION
+ *  
+ * PARAMETERS
+ *  void
+ * RETURNS
+ *  
+ *****************************************************************************/
+kal_bool med_utility_init(void)
+{
+
+    /*----------------------------------------------------------------*/
+    /* Local Variables                                                */
+    /*----------------------------------------------------------------*/
+    Media_Func_Reg_Type media_func;
+
+    /*----------------------------------------------------------------*/
+    /* Code Body                                                      */
+    /*----------------------------------------------------------------*/
+    
+    med_mem_mutex = kal_create_mutex("MED MEM");
+    
+    /* Register callback functions to L1audio */
+    media_func.alloc_mem           = med_util_alloc_aud_mem;
+    media_func.alloc_mem_cacheable = med_util_alloc_aud_cacheable_mem;
+    media_func.free_mem            = med_util_free_aud_mem;
+    media_func.set_path_volume     = NULL;
+    media_func.get_active_mode     = NULL;
+#if defined(__VOLTE_SUPPORT__)    
+    media_func.send_proc_call      = aud_send_in_proc_call_req;   // is only used in VoLTE DTMF MCU destroy functions
+#else
+    media_func.send_proc_call      = NULL;   
+#endif    
+    media_func.send_proc_call2     = NULL;
+    media_func.get_meta_file       = NULL;
+    media_func.get_meta_array      = NULL;
+    
+#if !defined(L1_NOT_PRESENT)
+    Audio_MedFuncReg(&media_func);
+#endif
+
+    /* init audio memory */
+    med_set_aud_memory_pool((unsigned char*)med_context_p->aud_mem_p, MED_AUD_MEM_SIZE);
+
+    return KAL_TRUE;
+}
+
+