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

📄 audiodriver.c

📁 audio talktrough code. platform bf533 + audio card.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************************

Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.

*********************************************************************************/
/**************************************************************************************************

Description:    Configures the audio mode through the Audio EZ-Extender virtual driver.
                The audio data is received from the ADC and stored into the buffer iADCdata. 
                The output data is transmitted from the buffer iDACdata.
                One circular buffer, rxBuffer, is provided for the ADC data, and another circular 
                buffer, txBuffer, is for the DAC data. A double buffering scheme 
                is implemented so that data in one half is available for processing while the other 
                half is used for DMA operations.

**************************************************************************************************/

/*********************************************************************

Include files

*********************************************************************/

#include <stdio.h>
#include <services\services.h>
#include <drivers\adi_dev.h>
#include "Talkthrough.h"
#include "AudioDriver.h"
#include "adi_AudioEZExtender.h"

/*********************************************************************

Prototypes

*********************************************************************/
// Audio EZ-Extender operation mode index
#define ANALOG_MODE         5   // This is the only MODE supported by the AD1938 driver right now.
                                // TDM 48khz 8 channel per SPORT primary/secondary each
#define DIGITAL_MODE        6   // Not used currently.  Requires an ADAV801 driver.


/*********************************************************************

Local variables

*********************************************************************/

// handle to the Audio EZ-Extneder driver
static ADI_DEV_DEVICE_HANDLE    DriverHandle;

// device manager handle
static ADI_DEV_MANAGER_HANDLE   DevMgrHandle;    // handle for the device manager

// DMA manager handle
static ADI_DMA_MANAGER_HANDLE   DMAMgrHandle;    // handle for the DMA manager

// circular buffer for processing SPORT1 TDM RX/TX data
static ADI_DEV_CIRCULAR_BUFFER   rxBuffer;
static ADI_DEV_CIRCULAR_BUFFER   txBuffer;
#if (ADAV801_SUPPORT)
// circular buffer for processing SPORT0 I2S RX/TX data
static ADI_DEV_CIRCULAR_BUFFER   rxBuffer2;
static ADI_DEV_CIRCULAR_BUFFER   txBuffer2;
#endif

// interrupt manager memory (base memory + no secondary handler)
static u8 IntMgrMem[(0 * ADI_INT_SECONDARY_MEMORY)];

// storage for DMA manager memory (2 channel(RX/TX) usage)
static u8 DMAMgrMem[ADI_DMA_BASE_MEMORY + (2 * ADI_DMA_CHANNEL_MEMORY)];

#if (ADAV801_SUPPORT)
// device manager memory (base memory + 6 device memory (Audio EZ-Extender, AD1938A&B, ADAV801, SPI, SPORT1, SPORT0)
static u8 DevMgrMem[ADI_DEV_BASE_MEMORY + (6 * ADI_DEV_DEVICE_MEMORY)];
#else
// device manager memory (base memory + 4 device memory (Audio EZ-Extender, AD1938A&B, SPI, SPORT1)
static u8 DevMgrMem[ADI_DEV_BASE_MEMORY + (4 * ADI_DEV_DEVICE_MEMORY)];
#endif

// storage for critical region data
static ADI_INT_CRITICAL_REGION_DATA     CriticalRegionData;

// storage for audio PCM data
static int iADCdata[TDM_FRAME_SIZE * TICK_SAMPLE_SIZE * 2];  // 2: double buffering
static int iDACdata[TDM_FRAME_SIZE * TICK_SAMPLE_SIZE * 2];  // 2: double buffering

/*********************************************************************

Exported buffers

*********************************************************************/

// pointer array that contains base channel pointer of iDACdata for each portion of 2 buffer
int* pOutputSampleBasePtr[VALID_OUTPUT_CHANNEL_SIZE * 2]; // 2: double buffering

// pointer array that contains base channel pointer of iADCdata for each portion of 2 buffer
int* pInputSampleBasePtr[VALID_INPUT_CHANNEL_SIZE * 2];   // 2: double buffering

// single processing buffer for DSP modules
int ProcessingBuffer[VALID_OUTPUT_CHANNEL_SIZE][TICK_SAMPLE_SIZE] = {0};


/*********************************************************************

    Function:       ExceptionHandler
    
    Description:    We should never get an exception,
                    but just in case we'll catch them and simply turn
                    on all the LEDS should one ever occur.

*********************************************************************/
static ADI_INT_HANDLER(ExceptionHandler)
{
    return (ADI_INT_RESULT_PROCESSED);
}

/*********************************************************************

    Function:       HWErrorHandler
    
    Description:    We should never get a hardware error,
                    but just in case we'll catch them and simply turn
                    on all the LEDS should one ever occur.

*********************************************************************/
static ADI_INT_HANDLER(HWErrorHandler)
{
    return (ADI_INT_RESULT_PROCESSED);
}


/*********************************************************************

    Function:       resolveChannelPointers
    
    Description:    To simplify the process of reformatting DMA ADC or DAC data
                    into/from the working buffer, it assign each element
                    of an pointer array with valid base channel pointers
                    to iDACdata and iADCdata buffer.
    
*********************************************************************/

// initialize the pointers to the DMA ADC/DAC buffer for double buffering
static void resolveChannelPointers(void)
{
    int i;
    
    //=====================================================
    // Output channels
    //=====================================================
    // Analog channels
    pOutputSampleBasePtr[0] = &iDACdata[INTERNAL_DAC_L1];
    pOutputSampleBasePtr[1] = &iDACdata[INTERNAL_DAC_R1];
    pOutputSampleBasePtr[2] = &iDACdata[INTERNAL_DAC_L2];
    pOutputSampleBasePtr[3] = &iDACdata[INTERNAL_DAC_R2];
    pOutputSampleBasePtr[4] = &iDACdata[INTERNAL_DAC_L3];
    pOutputSampleBasePtr[5] = &iDACdata[INTERNAL_DAC_R3];
    pOutputSampleBasePtr[6] = &iDACdata[INTERNAL_DAC_L4];
    pOutputSampleBasePtr[7] = &iDACdata[INTERNAL_DAC_R4];
    
    pOutputSampleBasePtr[8] = &iDACdata[INTERNAL_DAC_L5];
    pOutputSampleBasePtr[9] = &iDACdata[INTERNAL_DAC_R5];
    pOutputSampleBasePtr[10] = &iDACdata[INTERNAL_DAC_L6];
    pOutputSampleBasePtr[11] = &iDACdata[INTERNAL_DAC_R6];
    pOutputSampleBasePtr[12] = &iDACdata[INTERNAL_DAC_L7];
    pOutputSampleBasePtr[13] = &iDACdata[INTERNAL_DAC_R7];
    pOutputSampleBasePtr[14] = &iDACdata[INTERNAL_DAC_L8];
    pOutputSampleBasePtr[15] = &iDACdata[INTERNAL_DAC_R8];
#if (ADAV801_SUPPORT)
    // Digital channels
    pOutputSampleBasePtr[16] = &iDACdata[INTERNAL_SPDIF_OUT_L];
    pOutputSampleBasePtr[17] = &iDACdata[INTERNAL_SPDIF_OUT_R];
#endif
    // set up the buffer pointers for the second half of the double buffer.
    for (i = 0; i < VALID_OUTPUT_CHANNEL_SIZE; i++)
        pOutputSampleBasePtr[VALID_OUTPUT_CHANNEL_SIZE + i] = 
            pOutputSampleBasePtr[i] + (TDM_FRAME_SIZE * TICK_SAMPLE_SIZE);
            
    //=====================================================
    // Input channels
    //=====================================================            
    // Analog channels
    pInputSampleBasePtr[0] = &iADCdata[INTERNAL_ADC_L1];
    pInputSampleBasePtr[1] = &iADCdata[INTERNAL_ADC_R1];
    pInputSampleBasePtr[2] = &iADCdata[INTERNAL_ADC_L2];
    pInputSampleBasePtr[3] = &iADCdata[INTERNAL_ADC_R2];
    pInputSampleBasePtr[4] = &iADCdata[INTERNAL_ADC_L3];
    pInputSampleBasePtr[5] = &iADCdata[INTERNAL_ADC_R3];
    pInputSampleBasePtr[6] = &iADCdata[INTERNAL_ADC_L4];
    pInputSampleBasePtr[7] = &iADCdata[INTERNAL_ADC_R4];

⌨️ 快捷键说明

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