📄 wm8753test.c
字号:
/*-----------------------------------------------------------------------------
* Copyright (c) Wolfson Microelectronics plc. All rights reserved.
*
* This software as well as any related documentation is furnished under
* license and may only be used or copied in accordance with the terms of the
* license. The information in this file is furnished for informational use
* only, is subject to change without notice, and should not be construed as
* a commitment by Wolfson Microelectronics plc. Wolfson Microelectronics plc
* assumes no responsibility or liability for any errors or inaccuracies that
* may appear in this document or any software that may be provided in
* association with this document.
*
* Except as permitted by such license, no part of this document may be
* reproduced, stored in a retrieval system, or transmitted in any form or by
* any means without the express written consent of Wolfson Microelectronics plc.
*
* $Id: WM8753Test.c 1472 2005-03-23 14:35:19Z ib $
*
* This file contains the Windows CE/XScale platform layer for the drivers for
* the Wolfson WM97xx chips.
*
* Warning:
* This driver is specifically written for Wolfson AC97 Audio Codecs. It is
* not a general AC 97 CODEC device driver.
*
* This platform file is specifically designed to work with the Cotulla AC'97
* controller and the Lubbock and Mainstone XScale platforms from Intel. There
* is no guarantee of correct operation with other platforms/controllers.
*
* -----------------------------------------------------------------------------*/
/*
* Include files
*/
#include "WMCommon.h"
#include "WMWaveGen.h"
#include "WMAudio.h"
#include "WMPlatform_Raw.h"
#include "WMPlatformDeviceContext.h"
#include "WMVoice.h"
#include "Test/WMTestCommon.h"
#include "Test/WMTestHelpers.h"
#include "Test/WMPlatformTests.h"
#include "Test/WMAudioTestHelpers.h"
#include "WM8753Defs.h"
#include "WM87xx.h"
/*
* Global definitions
*/
#define TEST_SAMPLE_RATE_HIFI 48000
#define TEST_SAMPLE_RATE_VOICE 8000
#define TEST_BUFFER_SIZE 256
#define TEST_BUFFER_DURATION 2000 /* in ms */
/*
* The frequency is worked out carefully so that we fill the
* buffer with a sequence of sine waves that will loop correctly
* from the end point of the buffer to the start point of the buffer.
*/
#define TEST_FREQUENCY (sampleRate*2/samplesPerBuffer)
#define TEST_AMPLITUDE 32768 /* 0dBFS */
#define TRANSMIT_TIMEOUT 100000
/*
* Debugging defines - uncomment these for test builds.
*
* CONTINUAL_HIFI/VOICE outputs to that DAC forever.
* FIXED_VALUE outputs a single known value instead of a sine wave.
*/
#define CONTINUAL_HIFI TRUE
#define CONTINUAL_VOICE FALSE
/* #define FIXED_VALUE 0x0*/
/*
* Private data
*/
/*
* Function prototypes
*/
WM_BOOL WM87TestHiFiDACDirect( WM_DEVICE_HANDLE hDevice );
/*-----------------------------------------------------------------------------
* Function: WM87Test
*
* WM87xx tests - plays sound via the various DACs
*
* Parameters:
* pDeviceContext pointer to the device context
*
* Returns: WMSTATUS
* See WMStatus.h
*---------------------------------------------------------------------------*/
WMTEST_START( WM87Test( WM_DEVICE_HANDLE hDevice ) )
{
/*
* And with the HIFI DAC.
*/
WMTEST_RUN( WM87TestHiFiDACDirect( hDevice ) );
}
WMTEST_END
/*-----------------------------------------------------------------------------
* Function: WM87TestHiFiDACDirect
*
* Plays a sound via I2S to the HIFI DAC.
*
* Parameters:
* pDeviceContext pointer to the device context
*
* Returns: void
*---------------------------------------------------------------------------*/
WMTEST_START( WM87TestHiFiDACDirect( WM_DEVICE_HANDLE hDevice ) )
{
WM_AUDIO_STEREO_SAMPLE buffer[TEST_BUFFER_SIZE];
unsigned int currPoint = 0;
unsigned int repeat;
unsigned int repeats;
unsigned int samplesPerBuffer = WM_ARRAY_COUNT( buffer );
WM_XSCALE_DEVICE_CONTEXT *pDeviceContext =
(WM_XSCALE_DEVICE_CONTEXT*) hDevice;
/* The following values are put into variables so they can be
* altered in a debugger. */
int loopForever = CONTINUAL_HIFI;
int sampleRate = TEST_SAMPLE_RATE_HIFI;
int frequency = TEST_FREQUENCY;
int amplitude = TEST_AMPLITUDE;
#ifdef FIXED_VALUE
unsigned short knownValue = FIXED_VALUE;
#endif
/*
* Set the sample rate for the HIFI.
*/
WMTEST_CALL( WM8753SetSampleRate( pDeviceContext, TEST_SAMPLE_RATE_HIFI ) );
/* Make sure we'll output the sound */
WMTEST_CALL( WM87EnableHiFiPath( pDeviceContext ) );
//WMTEST_CALL( WM8753SetSampleRate( pDeviceContext, TEST_SAMPLE_RATE_HIFI ) );
/*
* Work out the number of repeats to get our duration.
* One buffer contains WMAUDIO_MAX_BUFFER_SIZE bytes.
*/
repeats = WM_TEST_REPEATS( TEST_BUFFER_DURATION,
sampleRate,
samplesPerBuffer
);
/*
* Generate a sine wave. The parameters should work out so an exact
* number of cycles fits in the buffer.
*/
WMGenerateSineWave( buffer,
samplesPerBuffer,
sampleRate,
frequency,
amplitude,
WM_WAVEGEN_LEFT,
NULL
);
WMGenerateSineWave( buffer,
samplesPerBuffer,
sampleRate,
frequency * 2,
amplitude,
WM_WAVEGEN_RIGHT,
NULL
);
/*
* Now keep pumping the sine waves at the registers.
*/
do
{
for ( repeat = 0; repeat < repeats; repeat++ )
{
for ( currPoint = 0; currPoint < samplesPerBuffer; currPoint++ )
{
unsigned int timeout = 0;
while ( !(pDeviceContext->v_pI2SRegs->SASR0 & 0x8) && timeout < TRANSMIT_TIMEOUT )
{
timeout++;
}
#ifdef FIXED_VALUE
pDeviceContext->v_pI2SRegs->SADR = (knownValue << 16) | knownValue;
#else
pDeviceContext->v_pI2SRegs->SADR = buffer[currPoint].sampleVal;
#endif
}
}
}
while ( loopForever );
}
WMTEST_END
#if 0
/*-----------------------------------------------------------------------------
* Function: WM87TestHiFiADC
*
* Records a sound via SSP from the HIFI ADC.
*
* Parameters:
* pDeviceContext pointer to the device context
* buffer the buffer to play
* buflen the number of samples in the buffer
*
* Returns: void
*---------------------------------------------------------------------------*/
WMSTATUS WM87TestHiFiADC( XLLP_ACODEC_CONTEXT_T *pDeviceContext )
{
BOOL RetVal=TRUE;
int i=0, k=0;
int need_num=0, receive_num = 0;
static short test_receive_buffer[12500];
while(1)
{
//EdbgOutputDebugString ( "this time, status is %x \r\n", (myDeviceContext.pSSPReg)->ssr);
while ( ( (m_DrvContext.pSSPReg)->ssr & XLLP_SSSP_RNE) == 0 )
{
//EdbgOutputDebugString ( "During loop, status is %x \r\n", (m_DrvContext.pSSPReg)->ssr);
}
receive_num = ((m_DrvContext.pSSPReg)->ssr & XLLP_SSSP_RFL_MASK) >> 12;
RETAILMSG( 1, (TEXT("pSSPReg 0x%0x \r\n"), (m_DrvContext.pSSPReg)->ssr));
for (i=0; i<receive_num; i++)
{
// test_receive_buffer[k] = (m_DrvContext.pSSPReg)->ssdr;
//(m_DrvContext.pPCMReg)->SADR = ((m_DrvContext.pSSPReg)->ssdr)<<16;
// EdbgOutputDebugString ( "this time, status is %x \r\n", (myDeviceContext.pSSPReg)->ssr);
//RETAILMSG(1, (TEXT("this time, test_receive_buffer is %d \r\n"), (m_DrvContext.pSSPReg)->ssdr));
// Bcr->HLDR1 = test_receive_buffer[k];
m_vpBLReg->hex_led = (m_DrvContext.pSSPReg)->ssdr;
k++;
}
// after_num = ((myDeviceContext.pSSPReg)->ssr & XLLP_SSSP_RFL_MASK) >> 12;
//EdbgOutputDebugString ( "after reading, receive_num is %d \r\n", after_num);
}
return (RetVal);
}
#endif
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -