/*****************************************************************************
 函 数 名  : ftm_mailbox_init
 功能描述  : FTM模块邮箱适配初始化
 输入参数  : param 原语内容
             ulLen 原语长度
 输出参数  : 无
 返 回 值  : 无
*****************************************************************************/
VOS_UINT32 ftm_mailbox_init()
{
    if(VOS_OK != VOS_SmCCreate( "ftm_mailbox_taskproc", 0, VOS_SEMA4_FIFO, &g_mailbox_readsem))
    {
        HAL_SDMLOG("[%s] : VOS_SmCCreate failed.\n", __FUNCTION__);
        return ERR_MSP_FAILURE;
    }

    if(BSP_OK != BSP_MailBox_ComNotifyReg(EN_MAILBOX_SERVICE_LTE_CT, ftm_mailbox_ltect_cb))
    {
        HAL_SDMLOG("[%s] : BSP_MailBox_ComNotifyReg EN_MAILBOX_SERVICE_LTE_CT failed.\n", __FUNCTION__);
        return ERR_MSP_FAILURE;
    }

    if(BSP_OK != BSP_MailBox_ComNotifyReg(EN_MAILBOX_SERVICE_LTE_BT, ftm_mailbox_ltebt_cb))
    {
        HAL_SDMLOG("[%s] : BSP_MailBox_ComNotifyReg EN_MAILBOX_SERVICE_LTE_BT failed.\n", __FUNCTION__);
        return ERR_MSP_FAILURE;
    }

    if(BSP_OK != BSP_MailBox_ComNotifyReg(EN_MAILBOX_SERVICE_TDS_CT, ftm_mailbox_tdsct_cb))
    {
        HAL_SDMLOG("[%s] : BSP_MailBox_ComNotifyReg EN_MAILBOX_SERVICE_TDS_CT failed.\n", __FUNCTION__);
        return ERR_MSP_FAILURE;
    }

    if(BSP_OK != BSP_MailBox_ComNotifyReg(EN_MAILBOX_SERVICE_TDS_BT, ftm_mailbox_tdsbt_cb))
    {
        HAL_SDMLOG("[%s] : BSP_MailBox_ComNotifyReg EN_MAILBOX_SERVICE_TDS_BT failed.\n", __FUNCTION__);
        return ERR_MSP_FAILURE;
    }

    return ERR_MSP_SUCCESS;
}
VOS_VOID diag_MailboxSelfTask(VOS_VOID)
{
    VOS_UINT32 len, ret;
    DIAG_MSG_DSP_CNF_TO_AGENT_STRU * pData;

    if(ERR_MSP_SUCCESS != VOS_SmBCreate("diagmbx", 0, VOS_SEMA4_FIFO, &g_diagMbxSem))
    {
        diag_printf("[%s]:agent sem init err!\n",__FUNCTION__);
        return ;
    }

    /* 向邮箱注册回调函数 */
    if(ERR_MSP_SUCCESS != BSP_MailBox_ComNotifyReg(EN_MAILBOX_SERVICE_RTT_SYS_CTRL, diag_MailboxCb))
    {
        diag_printf("[%s]:BSP_MailBox_ComNotifyReg err!\n",__FUNCTION__);
        return ;
    }
    /*lint -save -e716*/
    while(1)
    /*lint -restore*/
    {
        if(VOS_OK != VOS_SmP(g_diagMbxSem, 0))
        {
            diag_printf("[%s] VOS_SmP failed.\n", __FUNCTION__);

            continue;
        }

        DIAG_DEBUG_SDM_FUN(EN_DIAG_AGENT_LDSP_MB_MSG, 0, 0, 0);

        len = BSP_MailBox_ComMsgSize(EN_MAILBOX_SERVICE_RTT_SYS_CTRL);
        if(0 == len)
        {
            DIAG_DEBUG_SDM_FUN(EN_DIAG_AGENT_LDSP_MB_MSG, 1, 0, 0);
            continue ;
        }

        /* VOS消息体在事先分配好的内存中查找空闲,没有阻塞操作 */
        pData = (DIAG_MSG_DSP_CNF_TO_AGENT_STRU *)VOS_AllocMsg(MSP_PID_DIAG_AGENT, len);
        if(VOS_NULL == pData)
        {
            DIAG_DEBUG_SDM_FUN(EN_DIAG_AGENT_LDSP_MB_MSG, 2, 0, 0);
            continue ;
        }

        /* (pData+20)表示把邮箱中的内容直接读取到消息中 */
        ret = BSP_MailBox_ComMsgRead(EN_MAILBOX_SERVICE_RTT_SYS_CTRL, ((VOS_UINT8 *)pData+VOS_MSG_HEAD_LENGTH), len, EN_MAILBOX_SLEEP_WAKEUP);
        if(ret)
        {
            DIAG_DEBUG_SDM_FUN(EN_DIAG_AGENT_LDSP_MB_MSG, 3, 0, 0);
            continue;
        }

        pData->ulReceiverPid = MSP_PID_DIAG_AGENT;
        pData->ulSenderPid   = MSP_PID_DIAG_AGENT;
        pData->ulLength      = len;

        /* 注意,只能给自己发消息,跨核发消息中会有阻塞接口,不能在中断中调用 */
        ret = VOS_SendMsg(MSP_PID_DIAG_AGENT, pData);
        if (ret != VOS_OK)
        {
            DIAG_DEBUG_SDM_FUN(EN_DIAG_AGENT_LDSP_MB_MSG, 4, 0, 0);
        }
    }
}