📄 tstac97.c
字号:
/******************************************************************************
**
** COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
** This software as well as the software described in it 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 Intel Corporation. Intel Corporation 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 Intel Corporation.
**
** FILENAME: TstAc97.c
**
** PURPOSE: This module contains the test code for the AC97 CODEC.
**
** LAST MODIFIED: $Modtime: 7/17/03 1:01p $
******************************************************************************/
/************* Header Files *************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "systypes.h"
#include "timedelays.h"
#include "dm_errors.h"
#include "DM_Debug.h"
#include "XsIntCtrlApi.h"
#include "XsDmaApi.h"
#include "Ac97MixerRegsApi.h"
#include "XsAc97CtrlApi.h"
#include "Ac97Api.h"
#include "TstAc97Api.h"
#include "DM_Debug.h"
#include "SysAudioToneApi.h"
#include "xsuart.h"
#include "DM_SerialInOut.h"
#include "boardControl.h"
/************* Local Functions *************/
/*
*******************************************************************************
*
* FUNCTION: TstAc97StandardMrInits
*
* DESCRIPTION: Some standard AC97 Codec Mixer Register initializations
* for AC97 tests.
*
* INPUT PARAMETERS: Ac97ContextT* ctxP - Context pointer.
*
* RETURNS: An error code.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS:
*
* CALLED BY: PostAc97RunTxToneDmaLoopPcm()
*
* PROTOTYPE: static ErrorT TstAc97StandardMrInits(Ac97ContextT* ctxP);
*
*******************************************************************************
*/
/*
static ErrorT TstAc97StandardMrInits(Ac97ContextT* ctxP)
{
ErrorT status;
////PostDisplayProgress(ERR_L_AC97, 0x80, 0);
// status = Ac97SetRecordSelectLeft(ctxP, AC97_MR_REC_SEL_MIC);
////PostDisplayProgress(ERR_L_AC97, 0x80, 1);
if (status) goto error;
// status = Ac97SetRecordSelectRight(ctxP, AC97_MR_REC_SEL_MIC);
////PostDisplayProgress(ERR_L_AC97, 0x80, 2);
if (status) goto error;
// Moderate level of record gain: max is 0x0F
status = Ac97SetRecordGainLeft(ctxP, 0xf);
////PostDisplayProgress(ERR_L_AC97, 0x80, 3);
if (status) goto error;
status = Ac97SetRecordGainRight(ctxP, 0xf);
////PostDisplayProgress(ERR_L_AC97, 0x80, 4);
if (status) goto error;
status = Ac97SetRecordGainMute(ctxP, FALSE);
////PostDisplayProgress(ERR_L_AC97, 0x80, 5);
if (status) goto error;
status = Ac97SetMasterVolLeft(ctxP, 4); // attenuation
////PostDisplayProgress(ERR_L_AC97, 0x80, 6);
if (status) goto error;
status = Ac97SetMasterVolRight(ctxP, 4); // attenuation
////PostDisplayProgress(ERR_L_AC97, 0x80, 7);
if (status) goto error;
status = Ac97SetMasterVolMute(ctxP, FALSE); // mute off
//PostDisplayProgress(ERR_L_AC97, 0x80, 8);
if (status) goto error;
// HW Loopback disabled
status = Ac97SetAnyMixerRegister(ctxP, 0x20, 0x0);
//PostDisplayProgress(ERR_L_AC97, 0x80, 9);
if (status) goto error;
// Variable sample rate audio disabled
status = Ac97SetAnyMixerRegister(ctxP, 0x2a, 0x0);
//PostDisplayProgress(ERR_L_AC97, 0x80, 0xa);
if (status) goto error;
// Disable bass and treble boosts, wakeups, headphone driver and filters.
status = Ac97SetAnyMixerRegister (ctxP, 0x6a, 0x0);
//PostDisplayProgress(ERR_L_AC97, 0x80, 0xb);
error:
return (status);
}
*/
/************* Global Functions *************/
/*
*******************************************************************************
*
* FUNCTION: PostAc97Tone
*
* DESCRIPTION: Test AC97 CODEC audio output.
*
* INPUT PARAMETERS: None.
*
* RETURNS: Number of errors.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: TstAc97StandardMrInits()
*
* CALLED BY: POST
*
* PROTOTYPE: UINT PostAc97Tone(void);
*
*******************************************************************************
*/
/*
UINT PostAc97Tone(void)
{
ErrorT status;
Ac97FifoProcessingInfoT* TstAc97PcmOutFifoP = NULL;
Ac97FifoProcessingInfoT* TstAc97PcmInFifoP = NULL;
//int x;
//PostDisplayProgress(ERR_L_AC97, 0x81, 0);
status = PostAc97Init();
//PostDisplayProgress(ERR_L_AC97, 0x81, 1);
if (status) return (status);
printf(" Testing AC97 Audio Output\r\n");
// printf(" User! Are you ready to listen for the tone?\r\n");
// GetUserResponse(YES);
// Need to open both FIFOs in pair for any DMA loop tests.
status = Ac97OpenFifoPcmOut(&Ac97ContextCodec0, &TstAc97PcmOutFifoP);
// //PostDisplayProgress(ERR_L_AC97, 0x81, 2);
if (status) goto error;
status = Ac97OpenFifoPcmIn(&Ac97ContextCodec0, &TstAc97PcmInFifoP);
// //PostDisplayProgress(ERR_L_AC97, 0x81, 3);
if (status) goto error;
status = TstAc97StandardMrInits (&Ac97ContextCodec0);
// //PostDisplayProgress(ERR_L_AC97, 0x81, 4);
if (status) goto error;
status = Ac97StartFifo(TstAc97PcmOutFifoP);
// //PostDisplayProgress(ERR_L_AC97, 0x81, 5);
if (status) goto error;
// Seed buffers with 1000 Hz tone. Assume 3 buffers for DMA loop.
// Note temporary assumption of 48,000 samples per second and hard-coded buffer size.
SysAudioToneFillBuf(1000, 48000,
(PUINT16)TstAc97PcmOutFifoP->dmaLoopDescriptorRootP->sourceVirtualAddr,
AC97_STANDARD_BUF_SIZE_BYTES/4);
//PostDisplayProgress(ERR_L_AC97, 0x81, 6);
SysAudioToneFillBuf(1000, 48000,
(PUINT16)TstAc97PcmOutFifoP->dmaLoopDescriptorRootP->nextVirtualAddr->sourceVirtualAddr,
AC97_STANDARD_BUF_SIZE_BYTES/4);
//PostDisplayProgress(ERR_L_AC97, 0x81, 7);
SysAudioToneFillBuf(1000, 48000,
(PUINT16)TstAc97PcmOutFifoP->dmaLoopDescriptorRootP->nextVirtualAddr->nextVirtualAddr->sourceVirtualAddr,
AC97_STANDARD_BUF_SIZE_BYTES/4);
//PostDisplayProgress(ERR_L_AC97, 0x81, 8);
ModifyMiscWr2Register(0, AC97_SPKROFF); // Turn the speaker on.
//for(x=0; x<1200; x += 4) { // Admire the sine wave.
//printf("%04x %04x : %04x %04x\r\n",
//(((PUINT16)TstAc97PcmOutFifoP->dmaLoopDescriptorRootP->sourceVirtualAddr)+x),
//(((PUINT16)TstAc97PcmOutFifoP->dmaLoopDescriptorRootP->sourceVirtualAddr)+x+1),
//(((PUINT16)TstAc97PcmOutFifoP->dmaLoopDescriptorRootP->sourceVirtualAddr)+x+2),
//(((PUINT16)TstAc97PcmOutFifoP->dmaLoopDescriptorRootP->sourceVirtualAddr)+x+3) );
//}
// Perform DMA Tone Transmission for 3 seconds
DM_WaitMs (3000);
// //PostDisplayProgress(ERR_L_AC97, 0x81, 9);
ModifyMiscWr2Register(1, AC97_SPKROFF); // Turn the speaker off.
//PostDisplayProgress(ERR_L_AC97, 0x81, 0xa);
status = Ac97StopFifo(TstAc97PcmOutFifoP);
//PostDisplayProgress(ERR_L_AC97, 0x81, 0xb);
if (status) goto error;
printf(" User! Did you hear a pure 1KHz tone?\r\n");
if (!GetUserResponse(YESNO)) {
status = ERRORCODEX(ERR_L_AC97, 0, 0, ERR_T_UNSPECIFIED);
goto error;
}
Ac97CloseFifo(TstAc97PcmOutFifoP);
//PostDisplayProgress(ERR_L_AC97, 0x81, 0xc);
Ac97CloseFifo(TstAc97PcmInFifoP);
//PostDisplayProgress(ERR_L_AC97, 0x81, 0xd);
printf (" Success!\r\n");
return 0;
error:
if (TstAc97PcmOutFifoP) {
//PostDisplayProgress(ERR_L_AC97, 0x81, 0xe);
Ac97CloseFifo(TstAc97PcmOutFifoP);
}
if (TstAc97PcmInFifoP) {
//PostDisplayProgress(ERR_L_AC97, 0x81, 0xf);
Ac97CloseFifo(TstAc97PcmInFifoP);
}
XllpUtilityOutputError(status);
return 1;
} // PostAc97Tone()
*/
/*
*******************************************************************************
*
* FUNCTION: PostAc97Init
*
* DESCRIPTION: Test the AC97 controller and CODEC.
*
* INPUT PARAMETERS: None.
*
* RETURNS: Number of errors.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS:
*
* CALLED BY: POST
*
* PROTOTYPE: UINT PostAc97Init(void);
*
*******************************************************************************
*/
UINT PostAc97Init(void)
{
static BOOL run1Yet = FALSE, run2Yet = FALSE;
ErrorT status;
//PostDisplayProgress(ERR_L_AC97, 0x82, 0);
if (run1Yet == FALSE) {
//PostDisplayProgress(ERR_L_AC97, 0x82, 1);
printf(" Testing AC97 Controller Init\r\n");
if ((status=XsAc97CtrlHWSetup()) != ERR_NONE) {
// XllpUtilityOutputError(status);
return 1;
}
run1Yet = TRUE;
printf(" Success!\r\n");
}
//PostDisplayProgress(ERR_L_AC97, 0x82, 2);
if (run2Yet == FALSE) {
//PostDisplayProgress(ERR_L_AC97, 0x82, 3);
printf(" Testing AC97 Codec Init\r\n");
// if ((status=Ac97HWSetup(&Ac97ContextCodec0)) != ERR_NONE) {
// XllpUtilityOutputError(status);
// return 1;
//}
run2Yet = TRUE;
printf(" Success!\r\n");
}
//PostDisplayProgress(ERR_L_AC97, 0x82, 4);
return 0;
}
/*
*******************************************************************************
*
* FUNCTION: PostAc97Mic
*
* DESCRIPTION: Test AC97 CODEC microphone input.
*
* INPUT PARAMETERS: None.
*
* RETURNS: Number of errors.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: TstAc97StandardMrInits()
*
* CALLED BY: POST
*
* PROTOTYPE: UINT PostAc97Mic(void);
*
*******************************************************************************
*/
/*
UINT PostAc97Mic(void)
{
ErrorT status;
//PostDisplayProgress(ERR_L_AC97, 0x85, 0);
status = PostAc97Init();
//PostDisplayProgress(ERR_L_AC97, 0x85, 1);
if (status) return (status);
printf(" Testing AC97 Microphone.\r\n");
printf(" User! Attach headset to J10 and speak into microphone.\r\n");
printf(" User! Test is complete after you continue.\r\n");
// status = Ac97PowerOnAudioSubsystems(&Ac97ContextCodec0);
// //PostDisplayProgress(ERR_L_AC97, 0x85, 2);
// if (status) goto error;
status = TstAc97StandardMrInits (&Ac97ContextCodec0);
//PostDisplayProgress(ERR_L_AC97, 0x85, 3);
if (status) goto error;
// HW Loopback enabled
status = Ac97SetAnyMixerRegister(&Ac97ContextCodec0, 0x20, 0x80);
//PostDisplayProgress(ERR_L_AC97, 0x85, 4);
if (status) goto error;
// // Select mono microphone input
// status = Ac97SetAnyMixerRegister(&Ac97ContextCodec0, 0x1a, 0);
// //PostDisplayProgress(ERR_L_AC97, 0x85, 4);
// if (status) goto error;
ModifyMiscWr2Register(0, AC97_SPKROFF); // Turn the speaker on.
//PostDisplayProgress(ERR_L_AC97, 0x85, 5);
GetUserResponse(YES);
//PostDisplayProgress(ERR_L_AC97, 0x85, 6);
ModifyMiscWr2Register(1, AC97_SPKROFF); // Turn the speaker off.
//PostDisplayProgress(ERR_L_AC97, 0x85, 7);
printf (" Success!\r\n");
return 0;
error:
XllpUtilityOutputError(status);
return 1;
} // TstAc97Mic ()
*/
/************* Global Kludge Functions *************/
/*
*******************************************************************************
*
* FUNCTION: KPostAc97Tone
*
* DESCRIPTION: Kludge for legacy code.
*
* INPUT PARAMETERS: void *arg - Ignored.
* CHAR *param - Ignored.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: PostAc97Tone()
*
* CALLED BY: Command List.
*
* PROTOTYPE: void KPostAc97Tone(PVOID arg, PCHAR param);
*
*******************************************************************************
*/
/*
void KPostAc97Tone(PVOID arg, PCHAR param)
{
PostAc97Tone();
}
*/
/*
*******************************************************************************
*
* FUNCTION: KPostAc97Init
*
* DESCRIPTION: Kludge for legacy code.
*
* INPUT PARAMETERS: void *arg - Ignored.
* CHAR *param - Ignored.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: PostAc97Init()
*
* CALLED BY: Command List.
*
* PROTOTYPE: void KPostAc97Init(PVOID arg, PCHAR param);
*
*******************************************************************************
*/
void KPostAc97Init(PVOID arg, PCHAR param)
{
PostAc97Init();
}
/*
*******************************************************************************
*
* FUNCTION: KPostAc97Mic
*
* DESCRIPTION: Kludge for legacy code.
*
* INPUT PARAMETERS: void *arg - Ignored.
* CHAR *param - Ignored.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: PostAc97Mic()
*
* CALLED BY: Command List.
*
* PROTOTYPE: void KPostAc97Mic(PVOID arg, PCHAR param);
*
*******************************************************************************
*/
/*
void KPostAc97Mic(PVOID arg, PCHAR param)
{
PostAc97Mic();
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -