📄 talkthrough.c
字号:
/*********************************************************************************
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: Supports conversion of non-interleaved per channel data array
from/to SPORT DMA data frame. The processData() function copies the
processed output data from the Audio Handling function into DAC's buffer.
It also copies ADC's input audio data into the working memory buffer
that acts as the Audio Handling function's input buffer
The Audio Handling is invoked through the separate
interrupt thread for the function, or directly called by processData,
depending on the SEPARATE_THREAD_FOR_RENDER definition.
*********************************************************************************/
/*********************************************************************
Include files
*********************************************************************/
#include <services\services.h>
#include <drivers\adi_dev.h>
#include "AudioDriver.h"
#if (SEPARATE_THREAD_FOR_RENDER)
#include <signal.h>
#endif
/*********************************************************************
Prototypes
*********************************************************************/
// external render function prototype
extern void DoProcessing(u32 *);
// flag for which buffer is being processed
static int bWhichBuffer = 1; // 1 : first buffer, 0 : second buffer
/*********************************************************************
Function: FWRender
Description: This is the user interrupt service routine which
runs on user interrupt 0. It simply calls the glue function
for the DSP to handle input data.
*********************************************************************/
#if (SEPARATE_THREAD_FOR_RENDER)
// user interrupt 0 ISR
ADI_INT_HANDLER(FWRender)
{
// do standalone DSP processing
DoProcessing((u32*)ProcessingBuffer);
return (ADI_INT_RESULT_PROCESSED);
}
#endif
/*********************************************************************
Function: processData
Description: Called by the audio driver ISR. Copies the processed output
data into the DMA transmit buffer and copies the input data
from the DMA receive buffer into the same processing buffer.
Then it invokes user interrupt ISR or directly
calls a render function to handle the input data.
Double buffering scheme is used for DMA buffers.
*********************************************************************/
static void processData(void)
{
int i, j;
int **pOutputPtr, **pInputPtr;
int *pSrc, *pDst;
// switch ping pong variable for double buffering
if (bWhichBuffer) // indicating first portion is transferred
{
// toggle buffer flag
bWhichBuffer = 0;
// store local pointer for the first DMA buffer
pOutputPtr = &pOutputSampleBasePtr[0];
pInputPtr = &pInputSampleBasePtr[0];
}
else // indicating second portion is transferred
{
// toggle buffer flag
bWhichBuffer = 1;
// store local pointer for the second DMA buffer
pOutputPtr = &pOutputSampleBasePtr[VALID_OUTPUT_CHANNEL_SIZE];
pInputPtr = &pInputSampleBasePtr[VALID_INPUT_CHANNEL_SIZE];
}
//===========================================================================
// write output buffer
// convert array of valid output channels into TX DMA frame formatted data
for (i = 0, pSrc = (int*)ProcessingBuffer; i < VALID_OUTPUT_CHANNEL_SIZE; i++)
{
for (j = 0; j < TDM_FRAME_SIZE * TICK_SAMPLE_SIZE; j += TDM_FRAME_SIZE)
pOutputPtr[i][j] = *pSrc++;
}
//===========================================================================
// handle input buffer
// convert RX DMA frame formatted data into sequential array for each valid input channel
for (i = 0, pDst = (int*)ProcessingBuffer; i < VALID_INPUT_CHANNEL_SIZE; i++)
{
for (j = 0; j < TDM_FRAME_SIZE * TICK_SAMPLE_SIZE; j += TDM_FRAME_SIZE)
*pDst++ = pInputPtr[i][j];
}
#if (SEPARATE_THREAD_FOR_RENDER)
// call other interrupt for rendering
raise(USER_ISR0);
#else
// do standalone DSP processing
DoProcessing((AMF_Signal*)ProcessingBuffer);
#endif
}
/*********************************************************************
Function: TalkthroughCallback
Description: Each type of callback event has it's own unique ID
so we can use a single callback function for all
callback events. The switch statement tells us
which event has occurred.
Note that in the device driver model, in order to
generate a callback for buffer completion, the
CallbackType of the buffer must be set to a flag
indicating which pointer it will generate an interrupt
(each sub buffer (2D) or at the end of full buffer).
In this example, 2D is used for DMA transfer and we
need sub buffer callback type to do double buffering.
*********************************************************************/
void TalkthroughCallback(void* AppHandle, u32 Event, void* pArg)
{
switch (Event)
{
// CASE (DMA buffer processed)
case ADI_DEV_EVENT_BUFFER_PROCESSED:
break;
case ADI_DEV_EVENT_SUB_BUFFER_PROCESSED:
processData();
break;
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
printf("DMA error interrupt\n");
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -