?? analog_audio_test.c
字號:
/*****************************************************************************
** **
** Name: Analog_Audio_test.c **
** **
******************************************************************************
(C) Copyright 2006 - 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.
Purpose: Perform a POST analog audio test on the 21364 EZ-Kit Lite
******************************************************************************/
#include <Cdef21262.h>
#include <def21262.h>
#include <signal.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <filter.h>
#include "post_common.h"
//////////////////////////////////////////////////////////////////////////////
//
// definitions
//
//////////////////////////////////////////////////////////////////////////////
#define AD1835_REQUIRED_SAMPLES ((MAX_SAMPLES) * 100)
#define AD1835_DESIRED_FREQ ((float)3000.0)
#define AD1835_SAMPLE_RATE ((float)48000.0)
#define AD1835_AMPLITUDE ((float)8388607.5)
#define AD1835_ACCEPTABLE_DEVIATION_PCT ((float)0.015)
#define AD1835_ACCEPTABLE_DEVIATION_AMP ((float)0.15)
#define AD1835_MAX_SIGNAL_STRENGTH ((float)220000000.0)
#define DSxEN 0xF
//////////////////////////////////////////////////////////////////////////////
//
// constant values & data
//
//////////////////////////////////////////////////////////////////////////////
volatile unsigned int *g_pTXSPx_PTR;
volatile unsigned int * const g_pTXSPx[4] = {
((volatile unsigned int *)pTXSP1A),
((volatile unsigned int *)pTXSP1B),
((volatile unsigned int *)pTXSP2A),
((volatile unsigned int *)pTXSP2B) };
volatile unsigned int * const g_pSPCTLx[4] = {
((volatile unsigned int *)pSPCTL1),
((volatile unsigned int *)pSPCTL1),
((volatile unsigned int *)pSPCTL2),
((volatile unsigned int *)pSPCTL2) };
const unsigned int g_pSPCTLx_values[4] = {
(SPTRAN | BHD | OPMODE | SLEN24 | SPEN_A),
(SPTRAN | BHD | OPMODE | SLEN24 | SPEN_B),
(SPTRAN | BHD | OPMODE | SLEN24 | SPEN_A),
(SPTRAN | BHD | OPMODE | SLEN24 | SPEN_B) };
//////////////////////////////////////////////////////////////////////////////
//
// function prototypes
//
//////////////////////////////////////////////////////////////////////////////
int TEST_ANALOG_AUDIO(void);
void Init1835viaSPI(void);
void TalkThroughISR(int sig_int);
void InitSPORT(void);
int TEST_ANALOG_AUDIO(void)
{
long lTimeout = (AD1835_REQUIRED_SAMPLES * 4000);
volatile int n, j;
volatile int bError = 0; // returning 1 indicates a pass, anything else is a fail
//g_bLeftRight = 1;
g_iSampleIndex = 1;
g_iSampleCount = 0;
// Need to initialize DAI because the sport signals
// need to be routed
Config_SRU_DAI();
// This function will configure the codec on the kit
Init1835viaSPI();
// Finally setup the sport to receive / transmit the data
InitSPORT();
for(n = 0; n < 4; n++)
{
CreateSinTable(AD1835_AMPLITUDE, AD1835_DESIRED_FREQ, AD1835_SAMPLE_RATE);
// reconfigure the sports for the
// correct channel
*pSPCTL1 = 0 ;
*pSPCTL2 = 0 ;
*g_pSPCTLx[n] = g_pSPCTLx_values[n];
g_pTXSPx_PTR = g_pTXSPx[n];
// reset the buffer indexs
g_iSampleIndex = 0;
g_iSampleCount = 0;
// setup interrupts
interrupt(SIG_SP0,TalkThroughISR);
// Be in infinite loop and do nothing until done.
while( g_iSampleCount < AD1835_REQUIRED_SAMPLES )
{
if( 0 == lTimeout-- )
{
interrupt(SIG_SP0, SIG_IGN);
return 0; // failed to get enough samples
}
// once the required number of samples has been collected,
// process the signal.
};
// turn off interrupts so that the data is stable.
interrupt(SIG_SP0, SIG_IGN);
// test the left channel
bError = Test_Channel((float*)g_fSineWaveIn_Left, MAX_SAMPLES,
AD1835_SAMPLE_RATE, AD1835_DESIRED_FREQ,
AD1835_ACCEPTABLE_DEVIATION_PCT,
AD1835_MAX_SIGNAL_STRENGTH,
AD1835_ACCEPTABLE_DEVIATION_AMP);
if( 1 == bError )
{
// test the right channel
bError = Test_Channel((float*)g_fSineWaveIn_Right, MAX_SAMPLES,
AD1835_SAMPLE_RATE, AD1835_DESIRED_FREQ,
AD1835_ACCEPTABLE_DEVIATION_PCT,
AD1835_MAX_SIGNAL_STRENGTH,
AD1835_ACCEPTABLE_DEVIATION_AMP);
}
if( 0 == bError )
{
return bError;
}
}
//turn off DSxEN that will cause SPI flash memory test fail.
*pSPIFLG &= (~DSxEN);
return bError;
}
void TalkThroughISR(int sig_int)
{
// receive a sample (could be left or right)
int nInValue = (int)*pRXSP0A;
if( nInValue & 0x00800000)
{ // negative sign extend
nInValue |= 0xFF000000;
}
*g_pTXSPx_PTR = (int)g_fSineWaveOut[g_iSampleIndex];
if( g_bLeftRight )
{ // right side
g_fSineWaveIn_Right[g_iSampleIndex] = (float)nInValue;
}
else
{ // left side
g_fSineWaveIn_Left[g_iSampleIndex] = (float)nInValue;
g_iSampleIndex++; // only increment the index when both channels have been sent.
}
g_bLeftRight = !g_bLeftRight;
if( g_iSampleIndex > MAX_SAMPLES-1 )
g_iSampleIndex = 0;
g_iSampleCount++;
}
//////////////////////////////////////////////////////////////////////////////
//
// stand alone test harness
//
//////////////////////////////////////////////////////////////////////////////
#ifdef _STANDALONE_ // use this to run standalone tests
int g_loops = 0;
int main(void)
{
int bError = 1; // returning 1 indicates a pass, anything else is a fail
// Need to initialize DAI because the sport signals
// need to be routed
Config_SRU_DAI();
// This function will configure the codec on the kit
Init1835viaSPI();
// Finally setup the sport to receive / transmit the data
InitSPORT();
while(1)
{
bError = TEST_ANALOG_AUDIO();
if( 0 == bError )
{
asm("nop;");
asm("nop;");
asm("nop;");
asm("emuidle;");
asm("nop;");
asm("nop;");
}
g_loops++;
}
return bError;
}
#endif //#ifdef _STANDALONE_
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -