int mca_send(int cmd_id, union mca_udata_req req_data, union mca_udata_rsp* p_rsp_data, int time_out)
{
    struct ipc_msg msg;
    struct mca_frame frame = {0};
    unsigned int data_len = 0;
    int ret = 0;

    if(!p_rsp_data)
        return -1;
        
    (msg.cmd_mix).cmd_type = TYPE_PWC;
    (msg.cmd_mix).cmd = CMD_SETTING;
    (msg.cmd_mix).cmd_obj = OBJ_MCA;
    (msg.cmd_mix).cmd_src = OBJ_AP;
    msg.mode = time_out ? SYNC_CMD : ASYNC_CMD;    
    memset(&frame, 0, sizeof(struct mca_frame));
    frame.cmd_id = cmd_id;
    memcpy((void*)&frame.udata, (void*)&req_data, sizeof(union mca_udata_req));       
    data_len = (sizeof(msg.data) - sizeof(msg.data[0])) < sizeof(frame) \
                ? (sizeof(msg.data) - sizeof(msg.data[0])) : sizeof(frame);  
                
    memcpy((void*)&msg.data[1], (void*)&frame, data_len);

    if(WARN_ON((sizeof(msg.data) - sizeof(msg.data[0])) < sizeof(frame))) 
    {
        MCA_DEBUG("mca_send frame size is out of range!!!\n");
    } 

    ret = ipc_msg_send(OBJ_LPM3, &msg, SYNC_MODE);
    if(0 != ret)
    {
        MCA_DEBUG("mca send cmd:%d ret:0x%x failed!!!\n",cmd_id, ret);
        return -1;
    }

    if (time_out) {
        data_len= ((sizeof(msg.data) - sizeof(msg.data[0])) < sizeof(union mca_udata_rsp)) ?
                        (sizeof(msg.data) - sizeof(msg.data[0])) : sizeof(union mca_udata_rsp);
        memcpy(p_rsp_data, &(msg.data[1]), data_len);
        if(-1 == p_rsp_data->dfs_default_rsp.ret)
        {
            MCA_DEBUG("mca send cmd:%d rsp.ret:-1 failed!!!\n",cmd_id);
            return -1;
        }
    }
    return 0;

}
int mca_send(int cmd_id, union mca_udata_req req_data, union mca_udata_rsp* p_rsp_data, int time_out)
{
    struct mca_frame frame = {0};
    union mca_udata_rsp rsp;
    unsigned long outputlen;
    unsigned char outbuf[512] = {0};
    int ret;
    
    // If user need response data, p_rsp_data != NULL
    if(p_rsp_data)
    {
        memset(&frame, 0, sizeof(struct mca_frame));
        frame.cmd_id = cmd_id;
        frame.udata  = req_data;

        outputlen = sizeof(union mca_udata_rsp);
        MCA_DEBUG("mca send cmd:%d\n", cmd_id);
#if 0 //monan for new ifc
        if(BSP_OK != MB_IFC_ExtendCall( IFCP_FUNC_MCU_MCA, BSP_MAILBOX_IFC_CALL_SYNC, (void *)0,(unsigned char*)(&frame),
                sizeof(struct mca_frame), (unsigned char*)(&outbuf[0]), &outputlen))
        {
            MCA_DEBUG("mca send cmd:%d failed!!!\n",cmd_id);
            goto ERR_DESTROY_EXIT;
        }
#endif
        if(BSP_OK != (ret = mcu_mca_cmd_handler((unsigned char*)(&frame), sizeof(struct mca_frame), (unsigned char*)(&outbuf[0]), outputlen, time_out)))
        {
            MCA_DEBUG("mca send cmd:%d ret:0x%x failed!!!\n",cmd_id, ret);
            goto ERR_DESTROY_EXIT;
        }

        if(sizeof(union mca_udata_rsp) != outputlen)
        {
            MCA_DEBUG("output len(%d) is error, mca send cmd:%d failed!!!\n",outputlen, cmd_id);
            goto ERR_DESTROY_EXIT;
        }
        else
        {
            memcpy(p_rsp_data, outbuf, outputlen);
        }
    }
    else /* If p_rsp_data == NULL, we'll think user needn't response.  */
    {
        memset(&frame, 0, sizeof(struct mca_frame));
        frame.cmd_id = cmd_id;
        frame.udata  = req_data;

        goto ERR_DESTROY_EXIT;
 #if 0   //monan for new ifc
        if(BSP_OK != MB_IFC_ExtendCall( IFCP_FUNC_MCU_MCA, BSP_MAILBOX_IFC_CALL_SYNC, (void *)0,(unsigned char*)(&frame),
                sizeof(struct mca_frame), (unsigned char*)(&outbuf[0]), &outputlen))
        {
            MCA_DEBUG("mca send cmd:%d failed!!!\n",cmd_id);
            goto ERR_DESTROY_EXIT;
        }
#endif
        if(sizeof(union mca_udata_rsp) != outputlen)
        {
            MCA_DEBUG("output len(%d) is error, mca send cmd:%d failed!!!\n",outputlen, cmd_id);
            goto ERR_DESTROY_EXIT;
        }
    }

    rsp = *(union mca_udata_rsp *)outbuf;
    if(-1 == rsp.dfs_default_rsp.ret)
    {
        goto ERR_DESTROY_EXIT;
    }

    return 0;

ERR_DESTROY_EXIT:

    return -1;
}