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

📄 daa_bios.c

📁 在dsp芯片TOM320VC5402下电话接口的简单c程序实现
💻 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>

#include <std.h>
#include <swi.h>


/*****************************************************************************/
/* Constants                                                                 */
/*****************************************************************************/

#define McBSP1_RX_MASK    0x0400
#define McBSP0_RX_MASK    0x0010
#define WAITING           0x1000
#define FIRST_RING        0x2000
#define FIRST_PAUSE       0x3000
#define CALL_IN_PROGRESS  0x4000
#define RING_LENGTH       7500


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

void myBlink(void);                                     /* Periodic blink function */
void handsetCopy(void);                                 /* Handset Codec SWI function */
void daaCopy(void);                                     /* DAA Codec SWI function */
void pollRinger(void);                                  /* Periodic function to poll ring detect line */


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

extern SWI_Obj handsetCodec_swi;                        /* Handset Codec SWI - externally defined */
SWI_Handle handsetCodecSwiHandle = &handsetCodec_swi;   /* Handset Codec SWI Handle */
extern SWI_Obj daaCodec_swi;                            /* DAA Codec SWI - externally defined */
SWI_Handle daaCodecSwiHandle = &daaCodec_swi;           /* DAA Codec SWI Handle */
HANDLE hHandset;                                        /* Handset Codec Handle */
HANDLE hDaa;                                            /* DAA Codec Handle */
int currentLed;                                         /* LED to be toggled next */
s16 DAA_sample, Handset_sample;
u16 callStatus, ringStatus, ringDuration;


/*****************************************************************************/
/* void main(void)  -  MAIN                                                  */
/*                                                                           */
/* This functions initializes the "currentLed" variable and initializes the  */
/* the handset and daa codecs.                                               */
/*****************************************************************************/

void main()
{
    currentLed = BRD_LED0;                              /* set LED to be toggled to LED 0 */
    callStatus = WAITING;
    ringStatus = WAITING;
    ringDuration = 0;
        
    /* Set-up DAA codec */
    hDaa = codec_open(DAA_CODEC);

    /* Initialize DAA codec parameters */
    codec_dac_mode(hDaa, CODEC_DAC_15BIT);          /* DAC in 15-bit mode */
    codec_adc_mode(hDaa, CODEC_ADC_15BIT);          /* ADC in 15-bit mode */
    codec_ain_gain(hDaa, CODEC_AIN_6dB);            /* 6dB gain on analog input to ADC */
    codec_aout_gain(hDaa, CODEC_AOUT_MINUS_6dB);    /* -6dB gain on analog output from DAC */
    codec_sample_rate(hDaa,SR_16000);               /* 16KHz sampling rate */
    
    /* Set-up HANDSET codec */
    hHandset = codec_open(HANDSET_CODEC);

    /* Initialize Handset codec parameters */
    codec_dac_mode(hHandset, CODEC_DAC_15BIT);          /* DAC in 15-bit mode */
    codec_adc_mode(hHandset, CODEC_ADC_15BIT);          /* ADC in 15-bit mode */
    codec_ain_gain(hHandset, CODEC_AIN_6dB);            /* 6dB gain on analog input to ADC */
    codec_aout_gain(hHandset, CODEC_AOUT_MINUS_6dB);    /* -6dB gain on analog output from DAC */
    codec_sample_rate(hHandset, SR_16000);              /* 16KHz sampling rate */

    /* intializize DAA to default setting (off-hook, no caller ID) */
    daa_init();
    
    /* Enable McBSP0 and McBSP1 Receive Interrupts */
    C54_enableIMR(McBSP1_RX_MASK | McBSP0_RX_MASK);
}


/*****************************************************************************/
/* void handsetCodecService(void)  -  Handset Codec (McBSP 1) RX service     */
/*                                                                           */
/* This function posts a SWI which in turn copies samples from the Handset   */
/* to the DAA codec.                                                         */
/*****************************************************************************/

void handsetCodecService(void)
{
    SWI_post(handsetCodecSwiHandle);
}


/*****************************************************************************/
/* void daaCodecService(void)  -  DAA Codec (McBSP 0) RX service             */
/*                                                                           */
/* This function posts a SWI which in turn copies samples from the DAA to    */
/* the Handset codec.                                                        */
/*****************************************************************************/

void daaCodecService(void)
{
    SWI_post(daaCodecSwiHandle);
}


/*****************************************************************************/
/* void pollRinger(void)  -  Ringer polling function                         */
/*                                                                           */
/* This function polls the DAA for the first ring, enables the caller-id     */
/* path, polls for the second ring, disables the caller-id path and then     */
/* answers the call (takes line off-hook).                                   */
/*****************************************************************************/

void pollRinger(void)
{
    /* do this to ensure that short pauses in the first ring are not treated */
    /* as inter-ring pauses                                                  */
    if ((ringStatus == FIRST_RING) && (ringDuration < RING_LENGTH))
    {
        ringDuration += 1;
        return;
    }
    
    /* do this if no ringer present or a call is in progress */
    if((!daa_ring_detect()) || (callStatus == CALL_IN_PROGRESS))
    {
        /* if FIRST RING, then first ring has ended, status is now FIRST PAUSE */
        if (ringStatus == FIRST_RING)
        {
            ringStatus = FIRST_PAUSE;
            daa_cid(DAA_CID_DISABLE);    /* disable caller ID path */
        }
        return;
    }
    
    switch(ringStatus)
    {
        case  WAITING:       daa_cid(DAA_CID_ENABLE);        /* enable caller ID path */
                             ringStatus = FIRST_RING;        /* set ring status to FIRST RING */
                             break;
                             
        case  FIRST_PAUSE:   daa_offhook();
                             ringStatus = WAITING;            /* set ring status to WAITING */
                             callStatus = CALL_IN_PROGRESS;   /* set call status to CALL IN PROGRESS */
                             break;
        
        default:             return;
    }
}


/*****************************************************************************/
/* void daaCopy(void)  -  SWI function for DAA                               */
/*                                                                           */
/* This function reads a sample from the DAA codec and copies it to the      */
/* Handset codec.                                                            */
/*****************************************************************************/

void daaCopy(void)
{
    /* Read DAA codec sample */
    /* We need to do this every time to ensure that the DRR data is read*/
    /* to allow the next interrupt to be generated (priming the serial port) */
    DAA_sample = *(volatile u16*)DRR1_ADDR(DAA_CODEC);

    
    if (callStatus == CALL_IN_PROGRESS)
    {
        /* Write DAA sample to Handset codec */
        *(volatile u16*)DXR1_ADDR(HANDSET_CODEC) = DAA_sample;
    }
}


/*****************************************************************************/
/* void handsetCopy(void)  -  SWI function for Handset                       */
/*                                                                           */
/* This function reads a sample from the Handset codec and copies it to the  */
/* DAA codec.                                                                */
/*****************************************************************************/

void handsetCopy(void)
{
    /* Read Handset codec sample */
    /* We need to do this every time to ensure that the DRR data is read*/
    /* to allow the next interrupt to be generated (priming the serial port) */
    Handset_sample = *(volatile u16*)DRR1_ADDR(HANDSET_CODEC);

    if (callStatus == CALL_IN_PROGRESS)
    {
        /* Write Handset sample to DAA codec */
        *(volatile u16*)DXR1_ADDR(DAA_CODEC) = Handset_sample;
    }
}


/*****************************************************************************/
/* void myBlink(void)  -  Periodic Blink Function                            */
/*                                                                           */
/* This function toggles one of the 3 board LED's based on the value of the  */
/* "currentLed" variable.  It is performed at a 750ms rate.                  */
/*****************************************************************************/

void myBlink(void)
{
    switch(currentLed)
    {
        case BRD_LED0:    brd_led_toggle(BRD_LED0);
                          currentLed = BRD_LED1;
                          break;

        case BRD_LED1:    brd_led_toggle(BRD_LED1);
                          currentLed = BRD_LED2;
                          break;    
		
        case BRD_LED2:    brd_led_toggle(BRD_LED2);
                          currentLed = BRD_LED0;
                          break;
        
        default:          return;
    }
    
    return;
}

⌨️ 快捷键说明

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