Example #1
0
void usbc_core_notify_function_state_suspending(kal_uint8 class_device_id)
{
    kal_uint8 func_suspend_list;
    kal_uint8 func_wk_list = usbc_core_get_function_remote_wk_list();
    usbc_core_t *pUsbCore = usbc_core_get_instance();
    usbcore_usbidle_l4_power_saving_req_struct *rsp_msg_p;

    // Notify the specific function of USB suspended
    if ( !pUsbCore->class_device[class_device_id].is_func_suspend )
    {
        usbc_core_indicate_function_state(class_device_id, USBC_USB_STATE_SUSPENDING);
        usbc_core_indicate_function_state(class_device_id, USBC_USB_STATE_SUSPENDED);
        pUsbCore->class_device[class_device_id].is_func_suspend = KAL_TRUE;
    }

    // If all functions of the device are suspended, we notify L4 to do power saving
    func_suspend_list = usbc_core_get_function_suspend_list();
    if( !USBC_IS_IN_EXCEPTION_MODE() &&
        func_suspend_list == ((0x01 << pUsbCore->total_class_devices)-1) )
    {
        rsp_msg_p = (usbcore_usbidle_l4_power_saving_req_struct*)construct_local_para(sizeof(usbcore_usbidle_l4_power_saving_req_struct), TD_RESET);
        ASSERT(rsp_msg_p);
        rsp_msg_p->notify_suspend = KAL_TRUE;
        rsp_msg_p->notify_suspend_with_remote_wk = (func_wk_list==0)? KAL_FALSE:KAL_TRUE;
        usbc_trace_info(USBCORE_DEV_SUSPEND_L4, 1, 1, 1, (rsp_msg_p->notify_suspend_with_remote_wk? 0:1));
        usb_idle_set_l4_power_saving(KAL_TRUE);
        msg_send6(MOD_USBCORE,  // src module
                  MOD_USBIDLE,  // dst module
                  0,       // sap id
                  MSG_ID_USBCORE_IDLE_NOTIFY_TO_L4,
                  (local_para_struct*)rsp_msg_p,
                  0); //msg id
    }
}
/*****************************************************************************
 * FUNCTION
 *  rmmi_msgbased_send_ilm
 * DESCRIPTION
 *  This function is used to send ILM to dest_id using the msg_id with data local_param_ptr and peer_buf_ptr
 *
 * PARAMETERS
 *  dest_id             [IN]
 *  msg_id              [IN]
 *  local_param_ptr  [IN]
 *  peer_buf_ptr        [IN]
 *
 * RETURNS
 *  void
 *****************************************************************************/
static void rmmi_msgbased_send_ilm(module_type dest_id, kal_uint16 msg_id, void *local_param_ptr, void *peer_buf_ptr)
{
    module_type module = stack_get_active_module_id();
    

    msg_send6(module, dest_id, ATCI_SAP, (msg_type)msg_id, (local_para_struct *) local_param_ptr, (peer_buff_struct*) peer_buf_ptr);
}
void FTC_SEND_MSG(module_type  src_mod,
                  module_type  dest_mod,
                  sap_type  sap,
                  msg_type  msg,
                  ilm_struct  *ilm_ptr)
{
    msg_send6(src_mod, dest_mod, sap, msg, ilm_ptr->local_para_ptr, ilm_ptr->peer_buff_ptr);
}
/*****************************************************************************
 * 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);
}
Example #5
0
void usbc_core_notify_state_suspending()
{
    kal_uint8 func_list;
    usbcore_usbidle_l4_power_saving_req_struct *rsp_msg_p;

    // notify USBCLASS of USB suspended
    usbc_core_indicate_state(USBC_USB_STATE_SUSPENDING);
    usbc_core_indicate_state(USBC_USB_STATE_SUSPENDED);

    if( USBC_IS_IN_EXCEPTION_MODE() )
    {
        return;
    }	    

    // Updatea function pointer for setting GPDs in DRAM buffer
    usbc_trace_info(USBCORE_UPDATE_API_BUFF_GPD, 1);
    usbc_suspended_hif_factory();

    // Notify USBIDLE task to gate USB clock
    usbc_trace_info(USBCORE_DEV_SUSPEND_CLOCK, 1, 1);
    usb_idle_set_clockGating(KAL_TRUE);         // notify USBIDLE that it has to gate the clock of USB IP
    msg_send4(MOD_USBCORE,  // src module
              MOD_USBIDLE,  // dst module
              0,       // sap id
              MSG_ID_USBCORE_SUSPEND_TO_IDLE); //msg id

    // Ask USBIDLE to notify L4 to turn RF power off or go to fast dormancy
    func_list = usbc_core_get_function_remote_wk_list();
    rsp_msg_p = (usbcore_usbidle_l4_power_saving_req_struct*)construct_local_para(sizeof(usbcore_usbidle_l4_power_saving_req_struct), TD_RESET);
    ASSERT(rsp_msg_p);
    rsp_msg_p->notify_suspend = KAL_TRUE;
    rsp_msg_p->notify_suspend_with_remote_wk = (func_list==0)? KAL_FALSE:KAL_TRUE;
    usbc_trace_info(USBCORE_DEV_SUSPEND_L4, 1, 1, 1, (rsp_msg_p->notify_suspend_with_remote_wk? 1:0));
    usb_idle_set_l4_power_saving(KAL_TRUE);
    msg_send6(MOD_USBCORE,  // src module
              MOD_USBIDLE,  // dst module
              0,       // sap id
              MSG_ID_USBCORE_IDLE_NOTIFY_TO_L4,
              (local_para_struct*)rsp_msg_p,
              0); //msg id
 
    // Set USBCORE task to wait for indication events only
    usbc_trace_info(USBCORE_SUSPEND_STOP_POLL);
    usbc_core_get_instance()->hmu_indication = HIF_DRV_EG_USBC_IND_EVENT;   // Set USBCORE task to wait for indication events only
}
void usbc_class_device_netifx_suspend_notify(kal_uint8 class_device_id, kal_bool suspend, kal_bool remote_wakeup)
{
    usbcore_usbidle_l4_power_saving_req_struct *rsp_msg_p;
    usbc_core_t* pUsbCore = usbc_core_get_instance();

    if ( 1 
#ifdef __USB_RNDIS_SUPPORT__    
         && (pUsbCore->class_device[class_device_id].class_type != USB_CLASS_RNDIS)
#endif
#ifdef __USB_MBIM_SUPPORT__
         && (pUsbCore->class_device[class_device_id].class_type != USB_CLASS_MBIM)
#endif
#ifdef __USB_ECM_SUPPORT__
         && (pUsbCore->class_device[class_device_id].class_type != USB_CLASS_ECM)
#endif
       )
    {
        ASSERT(0);
        return;
    }       

    // In current implemnntation, only notifying L4 of USB suspended/resuming with remote wakeup is allowed
    ASSERT(remote_wakeup);
    if( suspend )
    {
        rsp_msg_p = (usbcore_usbidle_l4_power_saving_req_struct*)construct_local_para(sizeof(usbcore_usbidle_l4_power_saving_req_struct), TD_RESET);
        ASSERT(rsp_msg_p);
        rsp_msg_p->notify_suspend = suspend;
        rsp_msg_p->notify_suspend_with_remote_wk = remote_wakeup;
        usb_idle_set_l4_power_saving(KAL_TRUE);
        msg_send6(MOD_USBCORE,  // src module
                  MOD_USBIDLE,  // dst module
                  0,       // sap id
                  MSG_ID_USBCORE_IDLE_NOTIFY_TO_L4,
                  (local_para_struct*)rsp_msg_p,
                  0);    
    }
    else
    {
        usb_idle_set_l4_power_saving(KAL_FALSE);
        usb_idle_event_notify_to_l4(suspend, remote_wakeup);
    }        
}
void _FT_SendFtMsgByToken(module_type  src_mod, module_type  dest_mod, sap_type  sap, msg_type  msg, ilm_struct  *ilm_ptr, kal_uint16  token)
{
    ilm_ptr->src_mod_id  = src_mod;
    ilm_ptr->dest_mod_id = dest_mod;
    ilm_ptr->msg_id = msg;
    ilm_ptr->sap_id = sap;
#if !defined(__DHL_MODULE__)
    if (dest_mod == MOD_TST) {
#else
    if (dest_mod == MOD_DHL) {
#endif // #if !defined(__DHL_MODULE__)
        ((FT_H *)(ilm_ptr->local_para_ptr))->token=token;
        ilm_ptr->src_mod_id  = (module_type)0xA1;
        ilm_ptr->dest_mod_id = (module_type)0;
        ilm_ptr->sap_id      = (sap_type)0xA3;
        ilm_ptr->msg_id      = (msg_type)2;
#if !defined(__DHL_MODULE__)
        // directly copy primitive to TST ring buffer
        tst_log_primitive_without_filter_check(
                ilm_ptr,
                RS232_LOGGED_PRIMITIVE_TYPE,
                MSG_ID_LOGGED_PRIMITIVE);
#else
        dhl_FT_log_primitive(ilm_ptr);                
#endif // #if !defined(__DHL_MODULE__)
        // cancel ilm, because we directly access TST ring buffer, no need to send primitive to TST
        destroy_ilm(ilm_ptr);
        return;
    }
    msg_send6(src_mod, dest_mod, sap, msg, ilm_ptr->local_para_ptr, ilm_ptr->peer_buff_ptr);
}
/*******************************************************************************
 *
 *  FT Module Initialization Functions
 *
 *******************************************************************************/
/*******************************************************************************
 * FUNCTION
 *   FT_InitFtData
 *
 * DESCRIPTION
 *
 * CALLS
 *
 * PARAMETERS
 *
 * RETURNS
 *   None
 *
 * GLOBALS AFFECTED
 *******************************************************************************/
extern kal_int8 FT_FAT_Handle_Clear(void);
void FT_InitFtData()
{
    FT_FAT_Handle_Clear();
#if !defined(__LTE_SM__)
    FT_L1RfDataInit();
#endif // #if !defined(__LTE_SM__)    
    // init event group
    ft_event_group_ptr = (kal_uint32) kal_create_event_group("FtEvent");
}
/*!
 * @function        cccitty_ttyc_hdr_cmd_assign_rx_ior
 * @brief           TTY Core UL RPGD reload command, TTY_CMD_ASSIGN_RX_IOR, handler
 *                  Reference cdcacm_ttyhdr_cmd_assign_rx_ior -> usbc_class_device_submit_io_request
 *                  Reference ccmni_ipc_dl
 * @param port      [IN] UART port number
 * @param p_ior     [IN] Reload UL RGPD io_request
 * @param ownerid   [IN] module_type for the one opening this port, ex. MOD_xxx
 *
 * @return          DCL_STATUS
 *                  STATUS_OK:   success
 *                  STATUS_FAIL: ccci_write_gpd fail
 */
DCL_STATUS cccitty_ttyc_hdr_cmd_assign_rx_ior(UART_PORT port, ccci_io_request_t *p_ior, module_type ownerid)
{
    cccitty_dev_t       *p_cccidev = cccitty_get_dev_instance(CCCITTY_UARTP_TO_DEVID(port));
    cccitty_inst_t      *p_cccitty = cccitty_get_instance();
    ccci_io_request_t   *p_curr_ior, *p_next_ior;
    ccci_io_request_t   reload_ior;
    kal_uint32          gpd_num, gpd_num_rec;
    qbm_gpd             *p_gpd_h, *p_gpd_t;
    cccitty_deq_req_t   *cccitty_deq_req;
    kal_uint32          to_alloc, num_alloc;
    kal_int32           tmp;
    kal_bool            first_reload = KAL_FALSE;
    CCCI_RETURNVAL_T    ccci_ret;

    if(!cccitty_dev_active(p_cccidev)){
        cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_ASSIGN_RX_IOR_STATE_ERR, p_cccidev->state);
        return STATUS_NOT_OPENED;
    }
    if(NULL == p_ior){
        cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_RELOAD_NULL_IOR, port);
        return STATUS_OK;
    }
    if(NULL == p_ior->first_gpd){
        cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_RELOAD_EMPTY_IOR, port);
        return STATUS_OK;
    }

    if(KAL_TRUE == p_cccidev->ttyc_rgpd_first_reload){
        first_reload = KAL_TRUE;
    }

    /*
    Reload RGPD to HIF before enqueue the RGPD to internal tty queue.
    Otherwise, RGPD may be returned while first reload is not finished yet.
    */
    //4 <1> 1st time Reload the same number RGPD to the HIF    
    if(first_reload){
        /* ASSERT if there's already RGPD loaded in HIF*/
        EXT_ASSERT(0 >= p_cccidev->hwo_rgpd_cnt, p_cccidev->hwo_rgpd_cnt, 0, 0);

        /* construct reload_ior for HIF reload*/
        to_alloc = p_cccidev->hif_ul_ttl_rgpd_cnt;
        reload_ior.next_request = NULL;
        num_alloc = qbmt_alloc_q_no_tail(CCCI_TTY_UL_BUF_TYPE, to_alloc, (void **)&reload_ior.first_gpd, (void **)&reload_ior.last_gpd);
        /* ASSERT cannot allocate enough RGPD, each TTY_CHANNEL should pre-allocate enough RGPD*/
        if (num_alloc != to_alloc)
        {
            cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_TTYC_RGPD_INIT_ERR, to_alloc, num_alloc);
            EXT_ASSERT(KAL_FALSE, to_alloc, num_alloc, 0);
        }
#ifdef __SDIOC_PULL_Q_ENH_DL__
        reload_ior.num_gpd = num_alloc;
#endif
        ccci_ret = p_cccitty->ccci_write_gpd(p_cccidev->ccci_ch.cccitty_ch_ul, &reload_ior, NULL);
        if(CCCI_SUCCESS != ccci_ret){
            cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_RLD_CCCI_WRITE_FAIL, ccci_ret);
            return STATUS_FAIL;
        }
        CCCI_TTY_LOCK(p_cccidev->cccitty_mutex);
        {
            p_cccidev->hwo_rgpd_cnt += num_alloc;
            /* to prevent interrupted by SDIOCORE context*/
            tmp = p_cccidev->hwo_rgpd_cnt;
            p_cccidev->ttyc_rgpd_first_reload = KAL_FALSE;
        }
        CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);
        cccitty_trace(CCCI_TTY_TRACE, CCCI_TTY_MOD_UL, CCCI_TTY_TR_HIF_RGPD_RELOAD1,p_cccidev->dev_id, num_alloc, tmp);
    }
    
    //4 <2> check ttyc_rgpd_type
    if(CCCI_TTY_INVALID_GPD_TYPE == p_cccidev->ttyc_rgpd_type){
        /* if rgpd queue hasn't been initialized */
        p_cccidev->ttyc_rgpd_type = QBM_GET_TYPE(p_ior->first_gpd);
    }else{
        /* if rgpd type has been registered, new ior must match the type*/
        //4 <NOTE> only check the 1st gpd
        EXT_ASSERT(p_cccidev->ttyc_rgpd_type == QBM_GET_TYPE(p_ior->first_gpd), p_cccidev->ttyc_rgpd_type, QBM_GET_TYPE(p_ior->first_gpd), 0);
    }

    //4 <3> traverse the ior and queue all the gpd
    to_alloc = 0;
    p_curr_ior = (ccci_io_request_t*)p_ior;
    do {
        p_next_ior = p_curr_ior->next_request;
        CCCITTY_FIX_IOR_NULL_LAST(p_curr_ior);

        p_gpd_h = p_ior->first_gpd;
        p_gpd_t = p_ior->last_gpd;
        gpd_num = CCCITTY_GET_GPD_LIST_SIZE(p_gpd_h, p_gpd_t);
        to_alloc += gpd_num;
        
        CCCI_TTY_LOCK(p_cccidev->cccitty_mutex);
        {
            CCCITTY_QBM_ENQ(p_gpd_h, p_gpd_t, (void **)&p_cccidev->ttyc_rgpd_q_h, (void **)&p_cccidev->ttyc_rgpd_q_t);
            p_cccidev->ttyc_rgpd_cnt += gpd_num;
        }
        CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);

        p_curr_ior = p_next_ior;
    } while ( p_curr_ior != NULL );

    //4 <4> check ttyc_rgpd_cnt matches ttyc_rgpd_q size
    CCCI_TTY_LOCK(p_cccidev->cccitty_mutex);
    {
        p_gpd_h = p_cccidev->ttyc_rgpd_q_h;
        p_gpd_t = p_cccidev->ttyc_rgpd_q_t;
        gpd_num_rec = p_cccidev->ttyc_rgpd_cnt;
        gpd_num = CCCITTY_GET_GPD_LIST_SIZE(p_gpd_h, p_gpd_t);
    }
    CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);
    
    
    if(gpd_num_rec != gpd_num){
        /* warning the RGPD Q number is not match */
        cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_TTYC_RGPD_Q_NUM_ERR, gpd_num, gpd_num_rec);
        cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_TTYC_RGPD_Q_NUM_ERR_ACT1, gpd_num, gpd_num_rec);
    }

    //cccitty_trace(CCCI_TTY_TRACE, CCCI_TTY_MOD_UL, CCCI_TTY_TR_RGPD_RELOAD, CCCITTY_UARTP_TO_DEVID(port), to_alloc, p_cccidev->ttyc_rgpd_cnt);
    cccitty_trace(CCCI_TTY_TRACE, CCCI_TTY_MOD_UL, CCCI_TTY_TR_RGPD_RELOAD, CCCITTY_UARTP_TO_DEVID(port), to_alloc, gpd_num_rec);
       
    //4 <5> if ( hif_ul_rgpd_cnt != 0 ), sends MSG_ID_CCCI_TTY_UL_DEQUEUE_REQ to MOD_CCCITTY
    if(p_cccidev->hif_ul_rgpd_cnt){
        if(KAL_FALSE == p_cccidev->dev_ul_processing){
            CCCI_TTY_LOCK(p_cccidev->cccitty_mutex);
            {
                p_cccidev->dev_ul_processing = KAL_TRUE;
            }
            CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);
            cccitty_deq_req = (cccitty_deq_req_t *)construct_local_para(sizeof(cccitty_deq_req_t), 0);
            cccitty_deq_req->dev = p_cccidev;
            msg_send6(MOD_CCCITTY,                                  /* src_mod_id */
                      MOD_CCCITTY,                                  /* dest_mod_id */
                      0,                                            /* sap_id */
                      MSG_ID_CCCI_TTY_UL_DEQUEUE_REQ,               /* msg_id */
                      (struct local_para_struct *)cccitty_deq_req,  /* local_para_ptr */
                      NULL);                                        /* peer_buff_ptr */
        }else{
            /* there's MSG_ID_CCCI_TTY_UL_DEQUEUE_REQ message pending */
        }
    }
    return STATUS_OK;
}
/*!
 * @function        cccitty_ccci_ul_cb
 * @brief           uplink callback function register to CCCI, CCCI will callback during uplink process
 *                  Context: HIF context e.x. MOD_SIODCORE
 *                  process: <1> update the RGPD count in HIF
 *                           <2> remove CCCI header, CCCI_BUFF_T
 *                           <3> enqueue the RGPD to hif_ul_q_h 
 *                               or loopback, CCCITTY_LB_ENABLE
 *                           <4> send MSG_ID_CCCI_TTY_UL_DEQUEUE_REQ, change to MOD_CCCITTY context for dequeue(MOD_CCCIDEV)
 *                           <5> Error Handling: reload RGPD number error_reload_cnt
 *                               Function might free RGPDs for the following cases
 *                                      case 1. CCCI header corrupts, CCCITTY_RM_CCCI_HEADERS return false
 *                                      case 2. cccitty device state != CCCI_TTY_DEV_OPEN, cccitty_dev_active return false
 *
 * @param channel    [IN] ccci_channel id
 * @param io_request [IN] pointer to uplink io request 
 *
 * @return          void
 */
void cccitty_ccci_ul_cb(CCCI_CHANNEL_T channel, ccci_io_request_t* io_request){
    cccitty_inst_t      *p_cccitty = cccitty_get_instance();
    cccitty_dev_t       *p_cccidev;
    cccitty_device_id   dev_id = cccitty_get_ul_devid(channel);
    ccci_io_request_t   *curr_ior;
    ccci_io_request_t   *next_ior;
    kal_bool            end_of_list;

    qbm_gpd             *first_gpd;
    qbm_gpd             *last_gpd;
    qbm_gpd             *prev_gpd;
    qbm_gpd             *curr_gpd;
    qbm_gpd             *next_gpd;

    kal_int32           tmp;
    kal_uint32          num_gpd;
    kal_bool            valid_gpd = KAL_FALSE;
    kal_uint32          num_alloc;//, to_alloc; 
    CCCI_RETURNVAL_T    ccci_ret;
    kal_bool            ttydev_deq_msg = KAL_FALSE;
    cccitty_deq_req_t   *cccitty_deq_req;    

    /* error RPGD handling */
    ccci_io_request_t   err_reload_ior;
    kal_uint32          err_reload_cnt = 0;
    qbm_gpd             *err_gpd_h = NULL;
    qbm_gpd             *err_gpd_t = NULL;
    kal_uint32          NBPS_GPD_NUM = 0;
    CCCI_BUFF_T         *pdata;
    kal_int32           chkseqrtn = 0;

    if(CCCI_TTY_DEV_CNT == dev_id){
        /* cannot find dev_id for channel, please check g_cccitty_ccci_ch_mappping */
        return;
    }
    if(NULL == io_request){
        cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_NULL_IOR, dev_id, channel);
        return;
    }
    /* ASSERT if invalid channel number is received */
    EXT_ASSERT(dev_id < CCCI_TTY_DEV_CNT, channel, 0, 0);

    p_cccidev = cccitty_get_dev_instance(dev_id);
    if(!cccitty_dev_active(p_cccidev)){
        /* device is not at CCCI_TTY_DEV_OPEN state*/
        cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_DEV_NOT_OPEN,p_cccidev->dev_id, cccitty_get_dev_state(p_cccidev));

        /*for drop packet case, need to check sequence number first*/
        /*If there is mips issue, this action can be combined with reset function*/
        cccitty_check_ul_gpd_list_sequence(io_request->first_gpd, io_request->last_gpd);
        
        /* reset the gpds*/
        num_alloc = cccitty_reset_ccci_comm_gpd_list(io_request->first_gpd, io_request->last_gpd);
        //ASSERT (num_alloc == CCCITTY_GET_NONBPS_GPD_LIST_SIZE(io_request->first_gpd, io_request->last_gpd));
        NBPS_GPD_NUM = CCCITTY_GET_NONBPS_GPD_LIST_SIZE(io_request->first_gpd, io_request->last_gpd);
        EXT_ASSERT((num_alloc == NBPS_GPD_NUM), num_alloc, NBPS_GPD_NUM, 0);

        io_request->num_gpd = num_alloc;
        /* reload the gpds */
        ccci_ret = p_cccitty->ccci_write_gpd(p_cccidev->ccci_ch.cccitty_ch_ul, io_request, NULL);
        if(CCCI_SUCCESS != ccci_ret){
            /* NOTE!! might cause RGPD leackage here */
            cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_CCCI_WRITE_FAIL,p_cccidev->dev_id, ccci_ret);
            qbmt_dest_q(io_request->first_gpd, io_request->last_gpd);
        }else{
            CCCI_TTY_LOCK(p_cccidev->cccitty_mutex);
            {
                 /* should not increase hwo_rgpd_cnt, since this is the RGPD belongs to other user */
                 //p_cccidev->hwo_rgpd_cnt += num_alloc;
                 /* to prevent interrupted by SDIOCORE context*/
                 tmp = p_cccidev->hwo_rgpd_cnt;
            }            
            CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);
            cccitty_trace(CCCI_TTY_TRACE, CCCI_TTY_MOD_UL, CCCI_TTY_TR_HIF_RGPD_RELOAD5,p_cccidev->dev_id, num_alloc, tmp);    
        }
        return;
    }

    for (curr_ior = io_request; curr_ior; curr_ior = next_ior) {
        next_ior  = curr_ior->next_request;
        first_gpd = curr_ior->first_gpd;
        last_gpd  = curr_ior->last_gpd;
        //3 Note that, because GPD might be freeed in the following loop, we shall not access curr_ior from now.

        if (first_gpd && last_gpd){
            //4 <1> update the RGPD count in HIF
            num_gpd = CCCITTY_GET_GPD_LIST_SIZE(first_gpd, last_gpd);
            /* NOT allow BPS GPD inside */
            //ASSERT(num_gpd == CCCITTY_GET_NONBPS_GPD_LIST_SIZE(first_gpd, last_gpd));
            NBPS_GPD_NUM = CCCITTY_GET_NONBPS_GPD_LIST_SIZE(first_gpd, last_gpd);
            EXT_ASSERT((num_gpd == NBPS_GPD_NUM), num_gpd, NBPS_GPD_NUM, 0);

            CCCI_TTY_LOCK(p_cccidev->cccitty_mutex);
            {
                p_cccidev->hwo_rgpd_cnt -= num_gpd;
                tmp = p_cccidev->hwo_rgpd_cnt;
            }
            CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);
            
            cccitty_trace(CCCI_TTY_TRACE, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_RCV_GPD, p_cccidev->dev_id, num_gpd, tmp);
            if(p_cccidev->hwo_rgpd_cnt < 1){
                cccitty_trace(CCCI_TTY_WARN, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_RGPD_EMPTY, p_cccidev->dev_id, tmp);
            }

            prev_gpd = NULL;
            end_of_list = KAL_FALSE;
            for (curr_gpd = first_gpd; curr_gpd && !end_of_list; curr_gpd = next_gpd) {
                next_gpd = QBM_DES_GET_NEXT(curr_gpd);
                end_of_list = (curr_gpd == last_gpd);

                /*Check sequence number here!*/
                pdata = CCCIDEV_GET_QBM_DATAPTR(curr_gpd);
                chkseqrtn = ccci_debug_check_seq(pdata);
                if(chkseqrtn != CCCI_SUCCESS)
                {
                    cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_CHK_UL_SEQ_FAIL, chkseqrtn, channel);
                }
                
                //4 <2> remove CCCI header, CCCI_BUFF_T
                valid_gpd = CCCITTY_RM_CCCI_HEADERS(channel, curr_gpd);
                if(KAL_TRUE == valid_gpd){
                    prev_gpd = curr_gpd;
                }else{
                    p_cccidev->ul_invalid_ttl_cnt++;
                    err_reload_cnt ++;
                    cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_RPGD_ERR, err_reload_cnt, p_cccidev->ul_invalid_ttl_cnt);

                    if (curr_gpd == first_gpd) {
                        if (curr_gpd == last_gpd) {
                            first_gpd = NULL;
                            last_gpd = NULL;

                            EXT_ASSERT(end_of_list,0,0,0);
                            end_of_list = KAL_TRUE; /* All GPD's in the list are freed, exit the loop after curr_gpd released. */
                        } else {
                            EXT_ASSERT(next_gpd,0,0,0);
                            first_gpd = next_gpd;
                        }
                        prev_gpd = NULL;
                    } else {
                        EXT_ASSERT(prev_gpd,0,0,0);
                        if (curr_gpd == last_gpd) {
                            last_gpd = prev_gpd;
                            QBM_DES_SET_NEXT(prev_gpd, NULL);

                            EXT_ASSERT(end_of_list,0,0,0);
                            end_of_list = KAL_TRUE; /* To exit the loop after curr_gpd released. */
                        } else {
                            EXT_ASSERT(next_gpd,0,0,0);
                            QBM_DES_SET_NEXT(prev_gpd, next_gpd);
                        }

                        qbm_cal_set_checksum((kal_uint8 *)prev_gpd);
                        QBM_CACHE_FLUSH(prev_gpd, sizeof(qbm_gpd));
                    }

                    CCCITTY_QBM_ENQ(curr_gpd, curr_gpd, (void **)&err_gpd_h, (void **)&err_gpd_t);
                }
            } /* for (curr_gpd) */

            //4 <3> enqueue the RGPD to hif_ul_q_h
            if (first_gpd) {
                EXT_ASSERT(last_gpd,0,0,0);
                num_gpd = CCCITTY_GET_GPD_LIST_SIZE(first_gpd, last_gpd);
#if CCCITTY_LB_ENABLE
                // TODO: Provide the loopback function
                //4 nicc_ul2dl_loopback((ccci_io_request_t *)curr_ior, (nicc_dl_func)rndis_on_downlink, dev->ethc_inst);
#else
                /*enqueue to hif_ul_q*/
                CCCI_TTY_LOCK(p_cccidev->cccitty_mutex);
                {
                    CCCITTY_QBM_ENQ(first_gpd, last_gpd, (void **)&p_cccidev->hif_ul_q_h, (void **)&p_cccidev->hif_ul_q_t);
                    p_cccidev->hif_ul_rgpd_cnt += num_gpd;
                    tmp = p_cccidev->hif_ul_rgpd_cnt;
                }
                CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);
                ttydev_deq_msg = KAL_TRUE;
#endif
            } else {
                EXT_ASSERT((NULL == last_gpd),0,0,0);
                cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_EMPTY_IOR, p_cccidev->dev_id);
            }

        } else {/* if (first_gpd && last_gpd) */
            cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_INVALID_IOR, p_cccidev->dev_id, curr_ior, first_gpd, last_gpd);
            EXT_ASSERT(KAL_FALSE, (kal_uint32)first_gpd, (kal_uint32)last_gpd, 0); /* Invalid IOR */
        }
    } /*for (curr_ior...*/

    //4 <4> send MSG_ID_CCCI_TTY_UL_DEQUEUE_REQ
    if(KAL_TRUE == ttydev_deq_msg){
        CCCI_TTY_LOCK(p_cccidev->cccitty_mutex);
        if(KAL_FALSE == p_cccidev->dev_ul_processing){
            {
                p_cccidev->dev_ul_processing = KAL_TRUE;
            }
            CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);
            cccitty_deq_req = (cccitty_deq_req_t *)construct_local_para(sizeof(cccitty_deq_req_t), 0);
            cccitty_deq_req->dev = p_cccidev;
            msg_send6(MOD_CCCITTY,                                 /* src_mod_id, depending on the HIF type */
                      MOD_CCCITTY,                                  /* dest_mod_id */
                      0,                                            /* sap_id */
                      MSG_ID_CCCI_TTY_UL_DEQUEUE_REQ,               /* msg_id */
                      (struct local_para_struct *)cccitty_deq_req,  /* local_para_ptr */
                      NULL);                                        /* peer_buff_ptr */
            cccitty_trace(CCCI_TTY_TRACE, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_SEND_DEQ, p_cccidev->dev_id);
        }else{
            CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);
            /* there's MSG_ID_CCCI_TTY_UL_DEQUEUE_REQ message pending */
        }
    }
    //4 <5> Error Handling: reload RGPD number err_reload_cnt
    if (err_reload_cnt > 0){
        cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_INVALID_PKT, p_cccidev->dev_id, err_reload_cnt, p_cccidev->ul_invalid_ttl_cnt);
        /* reset the rgpd content with HWO = 1*/
        num_alloc = cccitty_reset_ccci_comm_gpd_list(err_gpd_h, err_gpd_t);
    //    num_alloc = CCCITTY_GET_GPD_LIST_SIZE(err_gpd_h, err_gpd_t);
        if(num_alloc != err_reload_cnt){
            cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_TTYC_ERR_RGPD_LEAK, p_cccidev->dev_id, num_alloc, err_reload_cnt);
            EXT_ASSERT(num_alloc == err_reload_cnt, num_alloc, err_reload_cnt, 0);
        }
    
        err_reload_ior.next_request = NULL;
        err_reload_ior.first_gpd = err_gpd_h;
        err_reload_ior.last_gpd = err_gpd_t;
        /* reload the gpds */
        ccci_ret = p_cccitty->ccci_write_gpd(p_cccidev->ccci_ch.cccitty_ch_ul, &err_reload_ior, NULL);

        if(CCCI_SUCCESS != ccci_ret){
            /* NOTE!! might cause RGPD leackage here */
            cccitty_trace(CCCI_TTY_ERR, CCCI_TTY_MOD_UL, CCCI_TTY_TR_UL_CCCI_WRITE_FAIL,p_cccidev->dev_id, ccci_ret);
            qbmt_dest_q(err_reload_ior.first_gpd, err_reload_ior.last_gpd);
        }else{
            CCCI_TTY_LOCK(p_cccidev->cccitty_mutex);
            {
                 /* should not increase hwo_rgpd_cnt, since this is the RGPD belongs to other user */
                 p_cccidev->hwo_rgpd_cnt += num_alloc;
                 /* to prevent interrupted by SDIOCORE context*/
                 tmp = p_cccidev->hwo_rgpd_cnt;
            }            
            CCCI_TTY_UNLOCK(p_cccidev->cccitty_mutex);
            cccitty_trace(CCCI_TTY_TRACE, CCCI_TTY_MOD_UL, CCCI_TTY_TR_HIF_RGPD_RELOAD4,p_cccidev->dev_id, num_alloc, tmp);
        }
    }
    
    return;
}
Example #10
0
void usbc_cosim_core_task_main(task_entry_struct* task_entry_ptr)
{
    kal_uint8 wait_count = 0;
    ilm_struct current_ilm;
    kal_uint32 rt_event;
    kal_uint16 timer_index;
    module_type dest_mod;
    msg_type msg_id;
    usbc_class_device_esl_connect_parm  *rsp_msg_p;
    usbc_core_t* pUsbCore = usbc_core_get_instance();

    kal_set_active_module_id(MOD_USBCORE);
    kal_mem_set(&current_ilm, 0, sizeof(ilm_struct));

    usbc_esl_printf("Start USBCORE task loop...\n");
    while(1)
    {
        while ( msg_get_extq_messages() > 0 )
        {
            if ( msg_receive_extq(&current_ilm) != KAL_TRUE )
            {
                break;
            }

            switch (current_ilm.msg_id)
            {
                case MSG_ID_TIMER_EXPIRY:
                    timer_index = evshed_get_index(&current_ilm);
                    switch (timer_index)
                    {
                        case USBC_WK_NOTIFY_INDEX:
                            ASSERT(0);
                            evshed_timer_handler(pUsbCore->usbc_es_wk_notify_g);
                            break;

                        default:
                            break;
                    }
                    break;

                default:
                    break;
            }

            destroy_ilm(&current_ilm);
        }

        /* Wait someone notify HMU to wake up HIF. */
        rt_event = hmu_hifeg_wait(HIF_DRV_EG_HIF_TICK_EVENT | HIF_DRV_EG_USBC_IND_EVENT);
        if ((HIF_DRV_EG_HIF_TICK_EVENT & rt_event) &&
            (pUsbCore->state != USBC_USB_STATE_SUSPENDED))
        {
            /* poll HIF queue data */
            usbc_esl_printf("Start HIF USB poll queue...\n");
            usbc_normal_hif_poll_queue();
            usbc_esl_printf("End HIF USB poll queue...\n");
        }
        if ((HIF_DRV_EG_USBC_IND_EVENT & rt_event))
        {
            /* Handle indications */
            usbc_normal_hif_process_indications();
        }

        // wait for IPCORE finishing handling ILMs in ipc_init
        if (wait_count < 1)
        {
            wait_count++;

            if(wait_count == 1)
            {
                usbc_esl_printf("Emulare USB enumeration...\n");
                // Emulate USB plug-in for ESL COSIM
                usbc_cosim_hif_attach();

                usbc_esl_printf("Set USB class to connected state...\n");
                // change USB classes state to transfer data
                rsp_msg_p = (usbc_class_device_esl_connect_parm*)construct_local_para(sizeof(usbc_class_device_esl_connect_parm), TD_RESET);
                ASSERT(rsp_msg_p);
                rsp_msg_p->class_device_id = 0;
                msg_id = MSG_ID_USBCLASS_USBCORE_ESL_ENTER_CONNECTED_STATE_REQ;

                switch ((pUsbCore->class_device[0]).class_type)
                {
#ifdef __USB_MBIM_SUPPORT__
                    case USB_CLASS_MBIM:
                        dest_mod = MOD_MBIM;
                        break;
#endif
#ifdef __USB_ECM_SUPPORT__
                    case USB_CLASS_ECM:
                        dest_mod = MOD_ECM;
                        break;
#endif
#ifdef __USB_RNDIS_SUPPORT__			
                    case USB_CLASS_RNDIS:
                        dest_mod = MOD_RNDIS;
                        break;
#endif			
                    default:
                        // We assume the first class device must be a NIC for ESL CO-SIM
                        ASSERT(0);
                        return;
                        break;
                }

                msg_send6(MOD_USBCORE,  // src module
                          dest_mod,  // dst module
                          0,       // sap id
                          msg_id,
                          (local_para_struct*)rsp_msg_p,
                          0); //msg id
            }
        }
    }
}
Example #11
0
void ccci_ipc_receive_msg_cb(CCCI_CHANNEL_T channel, ccci_io_request_t* ior)
{
    kal_uint32	i = 0;
    ipc_ilm_t	*temp_ipc_ilm = NULL;
    void        *local_param = NULL, *peer_buff = NULL;
    kal_uint32  len = 0;
    kal_uint32  gpd_num = 0;
    ccci_io_request_t *current_ior = ior;
    ccci_io_request_t *reload_ior = NULL;
    qbm_gpd           *current_gpd;
    qbm_gpd           *next_gpd;
    kal_bool    is_process_cb = KAL_FALSE;

    ccci_ipc_trace(CCCI_IPC_TRACE, CCCI_IPC_MOD_DATA, CCCI_RECEIVE_MSG_FUNC_TRA);
    while(current_ior != NULL){
        current_gpd = current_ior->first_gpd ;
        gpd_num = 0;
        while( current_gpd != NULL){
            CCCI_BUFF_T *bufp = CCCIDEV_GET_QBM_DATAPTR(current_gpd);
            next_gpd = current_gpd->p_next;
            local_param = NULL;
            peer_buff = NULL;
            ccci_ipc_trace(CCCI_IPC_TRACE, CCCI_IPC_MOD_DATA, CCCI_RECEIVE_MSG_TRA_CCCI,
                bufp->data[0], bufp->data[1], bufp->channel, bufp->reserved);
            ccci_debug_check_seq(bufp); // check ccci seq
            /* get task id from mapping table of ext queue id */
            for (i = 0; i < MAX_CCCI_IPC_TASKS; i++) 
            {
            	if ( ccci_ipc_maptbl[i].extq_id == bufp->reserved )
            	{
               	    break;
            	}
            }
        		
            /* check if the extquque id can not be found */
            if (i >= MAX_CCCI_IPC_TASKS) 
            {
        	    EXT_ASSERT(0, i, bufp->reserved, MAX_CCCI_IPC_TASKS);
            }

            /* check if the extquque id is to MD */
            if ((ccci_ipc_maptbl[i].extq_id & AP_UINFY_ID_FLAG) != 0)
            {
        	    EXT_ASSERT(0, i, bufp->reserved, ccci_ipc_maptbl[i].extq_id);
            }
        		
    	    temp_ipc_ilm = (ipc_ilm_t *)(bufp + 1);
            ccci_ipc_trace(CCCI_IPC_TRACE, CCCI_IPC_MOD_DATA, CCCI_RECEIVE_MSG_TRA_ILM,
                temp_ipc_ilm, temp_ipc_ilm->src_mod_id, temp_ipc_ilm->dest_mod_id,
                temp_ipc_ilm->sap_id, temp_ipc_ilm->msg_id,
                temp_ipc_ilm->local_para_ptr, temp_ipc_ilm->peer_buff_ptr);
		
    	    if(temp_ipc_ilm->local_para_ptr)
    	    {
    			// copy local_para_struct
    		    temp_ipc_ilm->local_para_ptr = 	(local_para_struct *)((char*)temp_ipc_ilm + sizeof(ipc_ilm_t));
                len += temp_ipc_ilm->local_para_ptr->msg_len; // need 4 bytes alignment or not??
                //assert if ilm size > CCCI_IPC_GPD size
	            EXT_ASSERT(len < CCCI_IPC_GPD_SIZE, len, CCCI_IPC_GPD_SIZE,0);
    			local_param = construct_local_para(temp_ipc_ilm->local_para_ptr->msg_len, 1);
    			kal_mem_cpy((kal_uint8 *)local_param, temp_ipc_ilm->local_para_ptr, temp_ipc_ilm->local_para_ptr->msg_len);
                ((local_para_struct *)local_param)->ref_count = 1 ; 
                temp_ipc_ilm->local_para_ptr = local_param;	    			
    	    }

    	    if (temp_ipc_ilm->peer_buff_ptr)
    	    {
                //copy peer_buff_struct
                if(temp_ipc_ilm->local_para_ptr)
    	        {
    		        temp_ipc_ilm->peer_buff_ptr = 	(peer_buff_struct *)((char*)temp_ipc_ilm->local_para_ptr 
    		                                                         + temp_ipc_ilm->local_para_ptr->msg_len);	
                }
                else
                {
                    temp_ipc_ilm->peer_buff_ptr = 	(peer_buff_struct *)((char*)temp_ipc_ilm + sizeof(ipc_ilm_t));
                }
                len += sizeof(peer_buff_struct) 
                       + temp_ipc_ilm->peer_buff_ptr->pdu_len 
                       + temp_ipc_ilm->peer_buff_ptr->free_header_space 
                       + temp_ipc_ilm->peer_buff_ptr->free_tail_space;
                //assert if ilm size > CCCI_IPC_GPD size 
                EXT_ASSERT(len < CCCI_IPC_GPD_SIZE, len, CCCI_IPC_GPD_SIZE, 0);
    			peer_buff = construct_peer_buff(temp_ipc_ilm->peer_buff_ptr->pdu_len, \
    			temp_ipc_ilm->peer_buff_ptr->free_header_space, \
    			temp_ipc_ilm->peer_buff_ptr->free_tail_space, 1);
    			kal_mem_cpy((kal_uint8 *)peer_buff, temp_ipc_ilm->peer_buff_ptr, 
                             sizeof(peer_buff_struct) 
                             + temp_ipc_ilm->peer_buff_ptr->pdu_len 
                             + temp_ipc_ilm->peer_buff_ptr->free_header_space 
                             + temp_ipc_ilm->peer_buff_ptr->free_tail_space);	
                temp_ipc_ilm->peer_buff_ptr = peer_buff;
    	    }

            CCCI_AP_MSG_TO_KAL_MSG(temp_ipc_ilm->msg_id, temp_ipc_ilm->msg_id);

	        if(ccci_ipc_ch.it_mode == CCCI_IPC_IT_DISABLE){ // if current is not IT mode, then need to send upper layer
                //4 <1> process ccci ipc cb function
                is_process_cb = ccci_ipc_process_cb_funp(temp_ipc_ilm);
                //4 <2> Determine send ilm to upper layer or destroy ilm
                if(!is_process_cb){ // no process cb, then send ilm to upper layer
    	            msg_send6 (MOD_CCCIIPC, ccci_ipc_maptbl[i].task_id, temp_ipc_ilm->sap_id, temp_ipc_ilm->msg_id, local_param, peer_buff);
	            }
            }
            #ifdef CCCI_IT_MODE_CONTROL_CCCI_IPC
            if(ccci_ipc_ch.it_mode == CCCI_IPC_IT_LB){
			    CCCI_KAL_MSG_TO_AP_MSG(temp_ipc_ilm->msg_id, temp_ipc_ilm->msg_id);
                bufp->reserved |=  (AP_UINFY_ID_FLAG | temp_ipc_ilm->src_mod_id ); // for Loopback to ccci ipc port 1
                bufp->channel   =  ccci_ipc_ch.send_channel; // for Loopback
                ccci_debug_add_seq(bufp, CCCI_DEBUG_ASSERT_BIT); // add ccci seq
            }
            #endif 
            QBM_CACHE_INVALID(temp_ipc_ilm,sizeof(temp_ipc_ilm)); // prevent cache co-herence problem
            gpd_num++;
    	    if (current_gpd == current_ior->last_gpd){
                break;
    	    }
            else{    
                current_gpd = next_gpd;
            }   
            
        }// process gpds
        reload_ior = current_ior;
        current_ior = current_ior->next_request;
        reload_ior->next_request = NULL;
        
        #ifdef __SDIOC_PULL_Q_ENH_DL__
            reload_ior->num_gpd = gpd_num;
        #endif
        
        #ifdef __CCCI_IPC_UT__
            qbmt_dest_q(reload_ior->first_gpd, reload_ior->last_gpd);
        #else
            #ifdef CCCI_IT_MODE_CONTROL_CCCI_IPC
            if(ccci_ipc_ch.it_mode == CCCI_IPC_IT_LB){
                ccci_ipc_ch.ccci_write_gpd(ccci_ipc_ch.send_channel, reload_ior, NULL);
                ccci_ipc_ch.reload_rgpd_number -= gpd_num;
                ccci_ipc_reload_rgpds();
            }else
            #endif
            {
                CCCIDEV_RST_CCCI_COMM_GPD_LIST(reload_ior->first_gpd, reload_ior->last_gpd);
                ccci_ipc_ch.ccci_write_gpd(ccci_ipc_ch.receive_channel, reload_ior, NULL);
            }
        #endif 
    }//process iors
    ccci_ipc_trace(CCCI_IPC_TRACE, CCCI_IPC_MOD_DATA, CCCI_RECEIVE_MSG_FUNC_PASS_TRA);
}
/*****************************************************************************
 * 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(MED_NOT_PRESENT)
    if (ilm_ptr->msg_id == MSG_ID_TIMER_EXPIRY)
    {
        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 
#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 ) {
			l1audio_console_handler(tstInj->string);
		} else {
			kal_prompt_trace(MOD_MED, "unused inject string index = %d ", tstInj->index);
		}			
	 }

	 if (ilm_ptr->msg_id ==  MSG_ID_AUDIO_L4C_EPOF_NOTIFY) {
#if defined( __SMART_PHONE_MODEM__ )	 	
		Spc_ForceEndAllApp();
#endif // #if defined( __SMART_PHONE_MODEM__ )	 	
	 }

#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__
        SP_M2M_Handler(ilm_ptr);
        #endif //#ifdef __MTK_TARGET__
    }
#if defined(__VOLTE_SUPPORT__)	
    if ( ilm_ptr->msg_id == MSG_ID_MEDIA_IN_PROC_CALL_REQ )
    {
        #ifdef __MTK_TARGET__
        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   
}