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

📄 daa.c

📁 在dsp芯片TOM320VC5402下的电话接口程序实现
💻 C
字号:
/*********************************************************************************/
/* daa.c
/*
/* This example demonstrates the use of the telephony interface of the DSK.
/* The DAA and handset codecs are setup and then the application waits for an
/* incoming ringer.  On the second ring detected, the line is picked up (off-hook)
/* and a conversation can be carried out between the DAA and handset interfaces.
/* This example also shows how the CALLER-ID enable feature is used if caller-id
/* detection is to be performed.
/*
/*********************************************************************************/

#include <type.h>
#include <board.h>
#include <codec.h>
#include <mcbsp54.h>
#include <daa.h>


/*****************************************************************************/
/* Function Prototypes
/*****************************************************************************/

/* This delay routine does not conflict with DSP/BIOS.  It is used in this  */
/* example rather than brd_delay_msec which causes DSP/BIOS conflicts just  */
/* because of this.  If you are not using DSP/BIOS, you can change the code */
/* to use brd_delay_msec.                                                   */

void delay(s16);


/*****************************************************************************/
/* Global variables
/*****************************************************************************/

HANDLE hDevice;


/*****************************************************************************/
/* MAIN
/*****************************************************************************/

void main()
{
    s16 cnt;
    u16 data;
    u16 silent_count;
	
	if (brd_init(100))
		return;
	
    cnt = 2;

    /* blink the leds a couple times */
	while ( cnt-- )
	{
		brd_led_toggle(0);
		/* brd_delay_msec(1000); */
		delay(1000);
		brd_led_toggle(1);
		/* brd_delay_msec(1000); */
		delay(1000);
		brd_led_toggle(2);
		/* brd_delay_msec(1000); */
		delay(1000);
	}
	
    /* Set-up DAA codec */
    hDevice = codec_open(DAA_CODEC);
    codec_sample_rate(hDevice,SR_8000);

    /* Set-up HANDSET codec */
    hDevice = codec_open(HANDSET_CODEC);
    codec_sample_rate(hDevice,SR_8000);

    /* intializize DAA to default setting (off-hook, no caller ID) */
    daa_init();

    /* wait for incoming ringer */

start:
    brd_led_disable(0);
    brd_led_disable(1);
    brd_led_disable(2);


    /* wait for initial ring */
    silent_count = 0;
    while (!daa_ring_detect())
    {
        brd_delay_msec(5);
        silent_count++;

        /* toggle LED 10x a second */
        if (silent_count == 20)
        {
            brd_led_toggle(0);
            silent_count = 0;
        }
    }


    /* enable caller ID path */
    brd_led_disable(0);
    brd_led_enable(1);
    daa_cid(DAA_CID_ENABLE);

    /* wait for 1st ring to end */
    silent_count = 0;
    do
    {
        brd_delay_msec(5);
        if (!daa_ring_detect())
            silent_count++;
        else silent_count = 0;
    } while (silent_count < 600);


    /* disable caller ID path */
    daa_cid(DAA_CID_DISABLE);

    brd_led_disable(1);
    brd_led_enable(2);

    /* wait for 2nd ring */
    silent_count = 0;
    do
    {
        brd_delay_msec(5);
        if (!daa_ring_detect())
            silent_count++;
        else break;
    } while (silent_count < 1200);

    /* check if phone was hung up before 2nd ring and restart */
    if (silent_count >= 1200) goto start;

    brd_led_disable(2);

    /* go off-hook */
    daa_offhook();

    /* enable all LEDs */
    brd_led_enable(0);
    brd_led_enable(1);
    brd_led_enable(2);

    while (1)
    {
        /* Check for sample from DAA */
        if (MCBSP_RRDY(DAA_CODEC))
        {
            /* Read DAA sample and write to handset codec */
            data = *(volatile u16*)DRR1_ADDR(DAA_CODEC);
            *(volatile u16*)DXR1_ADDR(HANDSET_CODEC) = data;
        }

        /* Check for sample from handset */
        if (MCBSP_RRDY(HANDSET_CODEC))
        {
            /* Read hadset codec sample and write to DAA */
            data = *(volatile u16*)DRR1_ADDR(HANDSET_CODEC);
            *(volatile u16*)DXR1_ADDR(DAA_CODEC) = data;
        }
    }

    return;
}


void delay(s16 period)
{
    int i, j;
    
    for(i=0; i<period; i++)
    {
        for(j=0; j<period>>1; j++);
    }
}

⌨️ 快捷键说明

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