📄 audiodriver.c
字号:
#if (ADAV801_SUPPORT)
// Digital channels
pInputSampleBasePtr[8] = &iADCdata[INTERNAL_SPDIF_IN_L];
pInputSampleBasePtr[9] = &iADCdata[INTERNAL_SPDIF_IN_R];
#endif
// set up the buffer pointers for the second half of the double buffer.
for (i = 0; i < VALID_INPUT_CHANNEL_SIZE; i++)
pInputSampleBasePtr[VALID_INPUT_CHANNEL_SIZE + i] =
pInputSampleBasePtr[i] + (TDM_FRAME_SIZE * TICK_SAMPLE_SIZE);
}
/*********************************************************************
*
* Function: InitSystem
*
* Description: This function initialize all the required system
* service routines and the device manager.
*
*********************************************************************/
static void InitSystem(void)
{
unsigned int result;
u32 ResponseCount;
// command pair for configuring the Power Manager
ADI_PWR_COMMAND_PAIR PwrMgrConfigTable[] =
{
{ ADI_PWR_CMD_SET_EZKIT, (void *)PWR_MANGER_EZKIT_PRESET },// configuration for the BlackFin EzKit
{ ADI_PWR_CMD_END, NULL },
};
// initialize the Interrupt Manger
result = adi_int_Init(IntMgrMem, // pointer to the memory used by the Interrupt Manger
sizeof(IntMgrMem), // size of the memory used by the Interrupt Manger
&ResponseCount, // response count of the instance
NULL); // NULL for critical section argument
if (result != ADI_DEV_RESULT_SUCCESS) printf("INT_MGR init failed!\n");
// initialize the Power Manger
result = adi_pwr_Init(PwrMgrConfigTable);
if (result != ADI_DEV_RESULT_SUCCESS) printf("PWR_MGR init failed!\n");
// initialize DMA Manger
result = adi_dma_Init(DMAMgrMem, // pointer to the memory used by the DMA Manager
sizeof(DMAMgrMem), // size of the memory used by the DMA Manager
&ResponseCount, // response count of the instance
&DMAMgrHandle, // pointer to the DMA Manger handle
NULL); // NULL for critical section argument
if (result != ADI_DEV_RESULT_SUCCESS) printf("DMA init failed!\n");
// hook the exception interrupt
adi_int_CECHook(3, ExceptionHandler, NULL, FALSE) ;
// hook the hardware error
adi_int_CECHook(5, HWErrorHandler, NULL, FALSE);
#if (SEPARATE_THREAD_FOR_RENDER)
// hook user ISR0
adi_int_CECHook(USER_ISR0, FWRender, NULL, FALSE);
#endif
// initialize Device Manager
result = adi_dev_Init(DevMgrMem, // pointer to memory use by Device Manager
sizeof(DevMgrMem), // size of memory for use by Device Manager
&ResponseCount, // response count of instances
&DevMgrHandle, // pointer to Device Manager handle
&CriticalRegionData); // global critical section argument
if (result != ADI_DEV_RESULT_SUCCESS) printf("DEV_MGR init failed!\n");
}
/*********************************************************************
*
* Function: InitAudioDriver
*
* Description: This function open the Audio EZ-Extender device instance.
* It uses the device instance to initialize registers in the AD1938A&B and ADAV801
* codecs, and configures them to the TDM 8 channel transferring mode.
* Two buffers (RX and TX) are required and configured
* for the 2-dimensional DMA transfer buffer allowing double buffering.
*
*********************************************************************/
static void InitAudioDriver(void)
{
int i;
unsigned int result;
u32 ResponseCount;
// open Audio EZ-Extender driver
result = adi_dev_Open(DevMgrHandle,
&ADIAudioEZExtenderEntryPoint, // entry point for the instance API
0, // device instance index (CODEC A&B)
NULL, // client handle callback identifier
&DriverHandle, // device handle for AD1938
ADI_DEV_DIRECTION_BIDIRECTIONAL,// direction for AD1938A&B
DMAMgrHandle, // DMA handle for SPORT
NULL, // Doesn't use deferred callback handle
TalkthroughCallback); // client's callback function from SPORT-DMA
if (result != ADI_DEV_RESULT_SUCCESS) printf("Failed to open Audio EZ-Extender!\n");
// configure the Audio EZ-Extender operation mode
result = adi_dev_Control(DriverHandle,
ADI_AUDIOEZEXTENDER_CMD_SET_OPERATION_MODE,
(void*)((ANALOG_MODE << 16) | (DIGITAL_MODE << 0))); // analog + digital mode together
if (result != ADI_DEV_RESULT_SUCCESS) printf("Audio EZ-Extender cmd-set-mode failed!\n");
/******************* Buffer preparation ***********************************************/
// Make sure the CallbackParameter as non-null to get the callback function working
// This is only needed for RX
rxBuffer.Data = &iADCdata[0]; // point to DMA RX buffer
rxBuffer.SubBufferCount = 2; // current DMA only supports 2D
rxBuffer.SubBufferElementCount = TDM_FRAME_SIZE * TICK_SAMPLE_SIZE; // size of the first dimension of the DMA buffer
rxBuffer.ElementWidth = 4;
rxBuffer.CallbackType = ADI_DEV_CIRC_SUB_BUFFER; // get interrupt/callback at each half of the buffer
rxBuffer.pAdditionalInfo = NULL;
txBuffer.Data = &iDACdata[0]; // point to DMA TX buffer
txBuffer.SubBufferCount = 2; // current DMA only supports 2D
txBuffer.SubBufferElementCount = TDM_FRAME_SIZE * TICK_SAMPLE_SIZE; // size of the first dimension of the DMA buffer
txBuffer.ElementWidth = 4;
txBuffer.CallbackType = ADI_DEV_CIRC_NO_CALLBACK; // No callback
txBuffer.pAdditionalInfo = NULL;
#if (ADAV801_SUPPORT)
// buffer perparation for digital codec is not supported for now
#endif
// redirect device selection to the ad1938 codec
result = adi_dev_Control(DriverHandle,
ADI_AUDIOEZEXTENDER_CMD_DEVICE_SELECT,
(void*)ADI_AD1938);
if (result != ADI_DEV_RESULT_SUCCESS) printf("Audio EZ-Extender device selection failed!\n");
// configure the Audio EZ-Extender dataflow method to circular(autobuffer) mode
result = adi_dev_Control(DriverHandle, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void*)ADI_DEV_MODE_CIRCULAR);
// assign rxBuffer and txBuffer for the Audio EZ-Extender driver (AD1938 codec)
result = adi_dev_Read(DriverHandle, ADI_DEV_CIRC, (ADI_DEV_BUFFER *)&rxBuffer);
result = adi_dev_Write(DriverHandle, ADI_DEV_CIRC, (ADI_DEV_BUFFER *)&txBuffer);
#if (ADAV801_SUPPORT)
// buffer perparation for digital codec is not supported for now
// redirect device selection to the ADAV801 codec
result = adi_dev_Control(DriverHandle,
ADI_AUDIOEZEXTENDER_CMD_DEVICE_SELECT,
(void*)ADI_ADAV801);
if (result != ADI_DEV_RESULT_SUCCESS) printf("Audio EZ-Extender device selection failed!\n");
// give the Audio EZ-Extender driver (ADAV801 codec) with the rxBuffer and txBuffer to work with.
// buffer perparation for digital codec is not supported for now
#endif
/******************* End of Buffer preparation ***********************************************/
// start the data flow
result = adi_dev_Control(DriverHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)TRUE);
}
/*********************************************************************
*
* Function: Close_Audio
*
*********************************************************************/
// Never called since it runs as infinite loop
void Close_Audio(void)
{
// disable data flow
adi_dev_Control(DriverHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)FALSE);
// close the device
adi_dev_Close(DriverHandle);
}
/*********************************************************************
*
* Function: Init_Audio
*
*********************************************************************/
void Init_Audio(void)
{
// initialize pointer array which is used in Audio callback function
resolveChannelPointers();
// initialize system services and device manager
InitSystem();
// initialize AudioEZExtender and run talkthrough mode
InitAudioDriver();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -