⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m803xxvoip.c

📁 m80320 VoIP DSP驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
        }
    }

    if(Flag == 2)
    {
      Parameter[PortNo].bearerInformation = bearertemp ;/*将传下来的编加解码方式赋回*/
    }

    
    if(RemainedTxCmdNum[PortNo] >  MAX_LEN_OF_CMD_FIFO)
    {
        TxCmdFifoOverflowFlag[PortNo] = 1;
        if(M80320_Debug[PortNo] == 1)M80320_PRINTF("OpenChannel(): The array Tx_Cmd_Fifo of Port %d is overflow!!!\n", PortNo);
    }

}

/*************************************************************************/
/* Function name: Disable_Channel_Processing                             */
/* Description  : Disable the channel                                    */
/* Return type  : void                                                   */
/* Argument     : PortNo -- No. of Port Num                              */
/* Author/Date  :                                                        */
/* Note:                                                                 */
/*                                                                       */
/*************************************************************************/
UINT8 Disable_Channel_Processing(UINT8 PortNo)
{
    UINT16 InCmd;
    M803xx_PORT_STATE   *PortPtr;
    UINT8  Return_Flag = SENDTOM803xxOK;

    PortPtr = (M803xx_PORT_STATE *)&m_port[PortNo];
    VoIP_CALL_PRINTF("M80320 CloseChannel PortNo = %d\n", PortNo);

    semTake(M803xxQueueSem[PortNo/8], WAIT_FOREVER);
    if (OK == M80320_checkOpenChanQueue(PortNo, 0x02, FUN_VOPENA))
    {
        InCmd = PortPtr->InCmd;
        PortPtr->tx_cmd_fifo[InCmd] = 0x0000;
        if( ++InCmd >= MAX_LEN_OF_CMD_FIFO)  InCmd = 0;

        PortPtr->InCmd = InCmd;
        RemainedTxCmdNum[PortNo] += 1;

        PortPtr->Active = BUSY; /* channel busy */
        PortPtr->ExpectActiveStatus = LFXS_DOWN;
        PortPtr->ReOpenNum--;

        #if SendOpenChannelMsgFirst
        Return_Flag = SendMsgToOpenChannelQueue(CMD_CMDDAT, 0xfd02, 0x0200, FUN_VOPENA, PortNo);
        #else
        Return_Flag = QueueTxBoxMsg(CMD_CMDDAT, 0xfd02, 0x0200, FUN_VOPENA, PortNo);
        #endif

        if(RemainedTxCmdNum[PortNo] >  MAX_LEN_OF_CMD_FIFO)
        {
            TxCmdFifoOverflowFlag[PortNo] = 1;
            if(M80320_Debug[PortNo] == 1)
                M80320_PRINTF("Disable_Channel_Processing(): The array Tx_Cmd_Fifo of Port %d is overflow!!!\n", PortNo);
        }
    }
    
    Tone_Stop[PortNo] = 1;
    semGive(M803xxQueueSem[PortNo/8]);
    return Return_Flag;
}

UINT8 Tone_Err_Disable_Channel_Processing(UINT8 PortNo)
{
    UINT16 InCmd;
    M803xx_PORT_STATE   *PortPtr;
    UINT8  Return_Flag = SENDTOM803xxOK;

    PortPtr = (M803xx_PORT_STATE *)&m_port[PortNo];

    semTake(M803xxQueueSem[PortNo/8], WAIT_FOREVER);
    if (OK == M80320_checkOpenChanQueue(PortNo, 0x02, FUN_VOPENA))
    {
        InCmd = PortPtr->InCmd;
        PortPtr->tx_cmd_fifo[InCmd] = 0x0000;
        if( ++InCmd >= MAX_LEN_OF_CMD_FIFO)  InCmd = 0;

        PortPtr->InCmd = InCmd;
        RemainedTxCmdNum[PortNo] += 1;

        #if SendOpenChannelMsgFirst
        Return_Flag = SendMsgToOpenChannelQueue(CMD_CMDDAT, 0xfd02, 0x0200, FUN_VOPENA, PortNo);
        #else
        Return_Flag = QueueTxBoxMsg(CMD_CMDDAT, 0xfd02, 0x0200, FUN_VOPENA, PortNo);
        #endif

        if(RemainedTxCmdNum[PortNo] >  MAX_LEN_OF_CMD_FIFO)
        {
            TxCmdFifoOverflowFlag[PortNo] = 1;
            if(M80320_Debug[PortNo] == 1)
                M80320_PRINTF("Disable_Channel_Processing(): The array Tx_Cmd_Fifo of Port %d is overflow!!!\n", PortNo);
        }
    }
    
    semGive(M803xxQueueSem[PortNo/8]);
    return Return_Flag;
}

/*************************************************************************/
/* Function name: Send_RtcpStatics_Cmd                                   */
/* Description  : Send RtcpStatics Command                               */
/* Return type  : void                                                   */
/* Argument     : PortNo -- No. of Port Num                              */
/* Author/Date  :                                                        */
/* Note:                                                                 */
/*                                                                       */
/*************************************************************************/
void Send_RtcpStatics_Cmd(UINT8 PortNo)
{
   /* UINT16 InCmd;*/
   /* M803xx_PORT_STATE *PortPtr;

    PortPtr = (M803xx_PORT_STATE *)&m_port[PortNo];*/
   /* InCmd = PortPtr->InCmd;*/
   
    semTake(M803xxQueueSem[PortNo/8], WAIT_FOREVER);
    #if SendOpenChannelMsgFirst
    
    if (OK == M80320_checkOpenChanQueue(PortNo, 0x0, FUN_RTCPSTAT))
        SendMsgToOpenChannelQueue(CMD_CMDDAT, 0xfd00, 0x0201, FUN_RTCPSTAT, PortNo);
    
    #else
    QueueTxBoxMsg(CMD_CMDDAT, 0xfd00, 0x0201, FUN_RTCPSTAT, PortNo);
    #endif
    semGive(M803xxQueueSem[PortNo/8]);
}

void Send_CONFSUM_Cmd(UINT8 PortNo)
{
   /* UINT16 InCmd;
    M803xx_PORT_STATE *PortPtr;

    PortPtr = (M803xx_PORT_STATE *)&m_port[PortNo];
      InCmd = PortPtr->InCmd;*/

    semTake(M803xxQueueSem[PortNo/8], WAIT_FOREVER);
    if (OK == M80320_checkOpenChanQueue(PortNo, 0x0, 0x0000))
        SendMsgToOpenChannelQueue(CMD_CMDDAT, 0xfd00, 0x0110, 0x0000, PortNo);
    semGive(M803xxQueueSem[PortNo/8]);
}

char Dtmf_Digit[16] =
{
    '0',   '1',   '2',   '3',
    '4',   '5',   '6',   '7',
    '8',   '9',   '*',   '#',
    'A', 'B', 'C', 'D'
};

/*************************************************************************/
/* Function name: Tone_Detect_Process                                    */
/* Description  : DTMF Detect Process                                    */
/* Return type  : void                                                   */
/* Argument     : PortNo -- No. of Port Num                              */
/*                ptr    -- the pointer pointed to data read from fifo   */
/*                len    -- the data length in the fifo                  */
/* Author/Date  :                                                        */
/* Note:                                                                 */
/*                                                                       */
/*************************************************************************/
void Tone_Detect_Process(UINT8 PortNo, UINT16* ptr, UINT8 len)
{
    char   digit;
    /*用于保留每一个端口上一次的FIFO的值*/
    static UINT16 fifo_value_last[65]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    UINT16 fifo_value;
    M803xx_PORT_STATE   *PortPtr;
    UINT8  Dtmf_Power;
    UINT32 Port;
    VOIP_MUX_STRUCT Msg;

    PortPtr = (M803xx_PORT_STATE *)&m_port[PortNo];
    Port = (((UINT32)((CON_TO_DP[m_port[PortNo].Channel].chan)+1))<<16)+(UINT32)((CON_TO_DP[m_port[PortNo].Channel].chip+1)<<24);  /* 全局端口号 */

    if((PortPtr->status == CIDStatus)||(PortPtr->status == WaitCIDStatus)||(PortPtr->status == CIDTalkStatus))
    {
        return;
    }

    /*当FIFO value 小于等于0x0F,为DTMF拔号;FIFO value = 0xFF为FAX开始;FIFO value  == 0x31,为传真结束 */
    fifo_value = ptr[0];
    Dtmf_Power = (UINT8)(ptr[3]);

    if (senddtmf[PortNo] != 0)
    {
        printf("PortNo %d :The Digit = %d, Power = %d, Dtmf_Level = %d\n",PortNo,fifo_value,Dtmf_Power, Parameter[PortNo].DTMF_LEVEL);
    }
    if(fifo_value == 0x30)  /* Tone */
    {
        Msg.mestype = SEND_TONE;
        Msg.portno  = Port;
        Msg.singleMsgPara  = 0;
        Msg.mesptr  = 0;
        M803xxMsgProcess((VOIP_MUX_STRUCT *)&Msg);
    }

    if(fifo_value <= 0xf)  /* dtmf digit */
    {
        if( Dtmf_Power > (Parameter[PortNo].DTMF_LEVEL))
        {
            printf("PortNo %d DTMF Err:Power = %d, Dtmf_Level = %d\n",PortNo,Dtmf_Power, Parameter[PortNo].DTMF_LEVEL);
            return;
        }
        digit = Dtmf_Digit[fifo_value];

        if(M80320_Debug[PortNo] == 1)
            M80320_PRINTF("dtmf signal detected, the digit is %d.\n", digit);

        if(PortPtr->Dtmf_Receive_Flag == 0)
        {
            if(PortPtr->status !=TalkStatus)
            {
                Msg.mestype = SEND_DTMF;
                Msg.portno  = Port;
                Msg.singleMsgPara  = (UINT16)((UINT8)digit);
                Msg.mesptr  = 0;
                M803xxMsgProcess((VOIP_MUX_STRUCT *)&Msg);
            }
            else
            {
                if(Parameter[PortNo].DTMFSendMode == DTMF_OUT_BAND_TRANSFER)
                {
                    Msg.mestype = SEND_DTMF;
                    Msg.portno  = Port;
                    Msg.singleMsgPara  = (UINT16)((UINT8)digit);
                    Msg.mesptr  = 0;
                    M803xxMsgProcess((VOIP_MUX_STRUCT *)&Msg);
                }
            }
        }
        return;
    }
    else if( (fifo_value==255)&& (fifo_value_last[PortNo] == 0x20)) /* CNG detect*/
    {
        M80320_PRINTF("Port %d T.30 CNG start detected, fifo value is 0x%x, last value  is 0x%x!\n", PortNo, fifo_value,fifo_value_last[PortNo]);
        if((PortPtr->VAD == Voice)&&(PortPtr->Active == LFXS_UP)) /* enable fax channel processing */
    {
            /*驱动将状态通告给上层协议(H.323),由上层确定什么时候初始化T.38 FAX通道,
              如果走T.30透传,不用重新创建通道*/
            if (Parameter[PortNo].faxMode == VOIP_FAX_PROTOCOL_T38) 
            {
                Msg.mestype = VoIP_CHANNEL_MODE;
                Msg.portno  = Port;
                Msg.singleMsgPara  = CODER_TYPE_T38;
                Msg.mesptr  = (UINT32 *)NULL;
                M803xxMsgProcess(&Msg);
                if(PortPtr->CallType == LFXS_CALLTYPE_IN)
                {
                    faxDebug(/*faxrelaymsg |*/ faxrelaymsgcalled, Port, " %s FAX Relay %s\n", "det ", "CNG (Calling tone)");
                }
                else if(PortPtr->CallType == LFXS_CALLTYPE_OUT)
                {
                    faxDebug(/*faxrelaymsg |*/ faxrelaymsgcalling, Port, " %s FAX Relay %s\n", "det ", "CNG (Calling tone)");
                }
            }
        }
    }
    else if( (fifo_value == 255)&& (fifo_value_last[PortNo] == 0x22)) /*V.21 detect*/
    {
        M80320_PRINTF("Port %d V.21 flags detected, fifo value is 0x%x,last value  is 0x%x!\n", PortNo, fifo_value,fifo_value_last[PortNo]);
       if((PortPtr->VAD == Voice)&&(PortPtr->Active == LFXS_UP)) /* enable fax channel processing */
        {
            /*驱动将状态通告给上层协议(H.323),由上层确定什么时候初始化T.38 FAX通道,
              如果走T.30透传,不用重新创建通道*/
            if (Parameter[PortNo].faxMode == VOIP_FAX_PROTOCOL_T38) 
            {
                Msg.mestype = VoIP_CHANNEL_MODE;
                Msg.portno  = Port;
                Msg.singleMsgPara  = CODER_TYPE_T38;
                Msg.mesptr  = (UINT32 *)NULL;
                M803xxMsgProcess(&Msg);
                if(PortPtr->CallType == LFXS_CALLTYPE_IN)
                {
                    faxDebug(/*faxrelaymsg |*/ faxrelaymsgcalled, Port, " %s FAX Relay %s\n", "det ", "V.21 flags");
                }
                else if(PortPtr->CallType == LFXS_CALLTYPE_OUT)
                {
                    faxDebug(/*faxrelaymsg |*/ faxrelaymsgcalling, Port, " %s FAX Relay %s\n", "det ", "V.21 flags");
                }
            }
        }
    }
    else if( fifo_value == 0x31 ) /* the end of fax detected */
    {
        if(M80320_Debug[PortNo] == 1)
        {
            M80320_PRINTF("The end of fax detected!\n");
        }

        Msg.mestype = VoIP_CHANNEL_MODE;
        Msg.portno  = Port;
        Msg.singleMsgPara  = (UINT16)(Parameter[PortNo].bearerInformation);
        Msg.mesptr  = (UINT32 *)NULL;
        M803xxMsgProcess(&Msg);
        if(PortPtr->CallType == LFXS_CALLTYPE_IN)
        {
            faxDebug(/*faxrelaymsg |*/ faxrelaymsgcalled, Port, " %s FAX Relay %s\n", "det ", "DCN (Distroy chain)");
        }
        else if(PortPtr->CallType == LFXS_CALLTYPE_OUT)
        {
            faxDebug(/*faxrelaymsg |*/ faxrelaymsgcalling, Port, " %s FAX Relay %s\n", "det ", "DCN (Distroy chain)");
        }
    }
    fifo_value_last[PortNo]=fifo_value;
}

/*************************************************************************/
void Event_Detect_Process(UINT8 PortNo, UINT16* ptr, UINT8 len)
{
    UINT16 fifo_value;
    M803xx_PORT_STATE *PortPtr;
#if 0
    VOIP_MUX_STRUCT Msg;
#endif

    PortPtr = (M803xx_PORT_STATE *)&m_port[PortNo];
    fifo_value = ptr[0];
    if(M80320_Debug[PortNo] == 1)
        M80320_PRINTF("PortNo %d Event:Dtmf = %d\n", PortNo, fifo_value);
        
    if( (fifo_value == 0x41)&&(PortPtr->VAD == Voice)&&(PortPtr->Active == LFXS_UP))  /*fax detect*/
    {
        if(M80320_Debug[PortNo] == 1)
            M80320_PRINTF("Port %d change from voice mode to fax mode, fifo value is %d!\n", PortNo, fifo_value);
        #if 0
        Msg.mestype = SEND_DTMF;
        Msg.portno  = ((UINT32)((CON_TO_DP[m_port[PortNo].Channel].chan)+1)<<16)+(((CON_TO_DP[m_port[PortNo].Channel].chip)+1)<<24); /* 全局端口号 */
        Msg.meslen  = 0;
        Msg.mesptr  = 0;
        M803xxMsgProcess((VOIP_MUX_STRUCT *)&Msg);
        #endif
    }
}

/*************************************************************************/
/* Function name: SelectDtmfFrequency                                    */
/* Description  : Select Dtmf Frequency                                  */
/* Return type  : 0:error ; 1:Ok                                         */
/* Argument     : in -- digit to be generated                            */
/*                PriToneFreq -- Primary tone frequency                  */
/*                SecToneFreq -- Se

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -