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

📄 codec_b.c

📁 在dsp芯片TOM320VC5402下的codec编程
💻 C
字号:
/*****************************************************************************/
/* Codec.c                                                                   */
/*                                                                           */
/* Digital Loopback example                                                  */
/*                                                                           */
/*****************************************************************************/

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

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


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

#define McBSP1_RX_MASK    0x0400


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

void myBlink(void);                                     /* Periodic blink function */
void loopBack(void);                                    /* Handset Codec SWI function */


/*****************************************************************************/
/* Global Variables                                                          */
/*****************************************************************************/

extern SWI_Obj CODEC_swi;                               /* Handset Codec SWI - externally defined */
SWI_Handle codecSwiHandle = &CODEC_swi;                 /* Handset Codec SWI Handle */
HANDLE hHandset;                                        /* Handset Codec Handle */
int currentLed;                                         /* LED to be toggled next */
s16 data;


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

void main()
{
    currentLed = BRD_LED0;                              /* set LED to be toggled to LED 0 */
    
    /* Open Handset Codec */
    hHandset = codec_open(HANDSET_CODEC);               /* Acquire handle to handset codec */

    /* Set 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 */
    
    C54_enableIMR(McBSP1_RX_MASK);
}


/*****************************************************************************/
/* void handsetCodecService(void)  -  Handset Codec (McBSP 1) RX service     */
/*                                                                           */
/* This function posts a SWI which in turn performs the digital loopback.    */
/*****************************************************************************/

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


/*****************************************************************************/
/* void loopBack(void)  -  Handset Codec SWI Function                        */
/*                                                                           */
/* This function reads a data sample from the handset codec receive channel  */
/* and writes it back to the transmit channel (digital loopback).            */
/*****************************************************************************/

void loopBack(void)
{
        /* Read sample from and write back to handset codec */
        data = *(volatile u16*)DRR1_ADDR(HANDSET_CODEC);
        *(volatile u16*)DXR1_ADDR(HANDSET_CODEC) = data;
}


/*****************************************************************************/
/* 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 + -