⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tst_i2ci2saudio.c

📁 优龙YLP270的I2C裸机测试程序
💻 C
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2001, 2002 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:       TST_I2cI2sAudio.c
**
**  PURPOSE: runs audio test for i2s compliant codec**                  
******************************************************************************/
#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "xllp_gpio.h"
#include "xllp_i2s.h"
#include "systypes.h"
#include "xsuart.h"
#include "DM_SerialInOut.h"
#include "DM_SerialInOut.h"
#include "WM_i2s_Codec.h"
#include "i2s.h"
#include "DM_Errors.h"
#include "SysAudioToneApi.h"
#include "XsGpioApi.h"
#include "TST_I2cI2sAudio.h"
#include "boardcontrol.h"

void KI2sI2cAudioTest(PVOID arg, PCHAR param)
{
    I2sI2cAudioTest();
}

/*
*******************************************************************************
*
* FUNCTION:         I2S_Test
*
* DESCRIPTION:      calls I2S_HWInit to set up the hardware; sets up the controller;
*					I2S_CodecSetup to power up the codec; I2C_DACSetup to set the 
*                   codec into a DAC state; generates a wav array that then gets shoved
*					into the transmit fifo and played out the codec speaker.
*
* INPUT PARAMETERS: None
*
* RETURNS:          XLLP_UINT32_T
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:
*
* CALLS:
*
* CALLED BY:		I2S_Test()
*
* PROTOTYPE:        XLLP_UINT32_T I2S_Test (void);
*
*******************************************************************************
*/

XLLP_UINT32_T I2sI2cAudioTest(void)
{
    UINT status=0;
    UINT errorLog=0;
    UINT32 i2sRegs;
    INT temp=0;
	UINT16 audioBuf[I2SBUF];
//   I2C_TX i2s_codec;

    volatile P_XLLP_I2C_T I2C_regs = (P_XLLP_I2C_T )STD_I2C_BASE;
    volatile P_XLLP_I2S_T I2S_regs = (P_XLLP_I2S_T )I2S_BASE;
    volatile P_XLLP_CLKMGR_T CLKMGR_regs = (P_XLLP_CLKMGR_T )CLKMGR_ADDR;
    volatile P_XLLP_GPIO_T GPIO_regs = (P_XLLP_GPIO_T)GPIO_ADDR;
    volatile P_XLLP_BCR_T BCR_regs = (P_XLLP_BCR_T)BCR_ADDR;

    printf(" Testing I2S and I2C with I2S Codec\r\n");
    printf(" User! Set SW20 to NODOT position and insert headset into J5\r\n");
    GetUserResponse(YES);

    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_AUDIO, 1);

    status=XllpI2sMInit(I2S_regs,I2C_regs, CLKMGR_regs, GPIO_regs, BCR_regs);
    if(status != ERR_T_NONE)
	{
        LOGERROR(errorLog, 
                 ERR_L_I2SCODEC, ERR_TS_I2S_INIT, ERR_T_UNEXPECTED, 
                 ZERO, ZERO, ZERO);					  
        XllpUtilityOutputError(errorLog);
        return(errorLog);
	}
 
    printf(" Testing I2S and I2C with I2S Codec\r\n");
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_AUDIO, 2);

//  setting the controller into the most functioning generic state with the sampling 
// frequency set to 8kHz
 
 	i2sRegs = I2S_regs->SACR0;
	I2S_regs->SACR0 = (i2sRegs & ~XLLP_SACR0_RST  );	
	I2S_regs->SACR0 = (i2sRegs | XLLP_SACR0_BCKD );	
 //   I2S_regs->SACR1 = 0x0;  // defaults to I2S this might need to be looked at later
	I2S_regs->SADIV = SAMP_FREQ8;
 	i2sRegs = I2S_regs->SACR0;
	I2S_regs->SACR0 = (i2sRegs | XLLP_SACR0_ENB );	
	i2sRegs=I2S_regs->SASR0;

//  XLLP_SASR0_BSY is an indication that the I2SLink is up and ready
// XLLP_SASR0_TNF is transmit fifo is not full (defaults to 1)
    printf(" User! Set SW20 to NODOT position and insert headset into J5\r\n");
    GetUserResponse(YES);

//    printf(" Testing I2S and I2C with I2S Codec i2sRegs %x\r\n", i2sRegs);
	if( i2sRegs != ( XLLP_SASR0_TNF | XLLP_SASR0_BSY ) )
	{
        LOGERRORX(errorLog, 
                 ERR_L_I2SCODEC, ERR_S_I2SSETUPBAD, i2sRegs, ERR_T_UNEXPECTED, 
                 ZERO, ZERO, ZERO);
        XllpUtilityOutputError(errorLog);
     	return(errorLog);
    }
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_AUDIO, 3);

    status = I2S_CodecSetup();
    if(status != ERR_T_NONE)
	{
        XllpUtilityOutputError(status);
        LOGERROR(errorLog, 
                 ERR_L_I2SCODEC, ERR_TS_CODECSETUP, ERR_T_UNEXPECTED, 
                 ZERO, ZERO, ZERO);					  
        XllpUtilityOutputError(errorLog);
        return(errorLog);
	}
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_AUDIO, 4);
   
    status = I2S_DACSetup();
    if(status != ERR_T_NONE)
	{
        XllpUtilityOutputError(status);
        LOGERROR(errorLog, 
                 ERR_L_I2SCODEC, ERR_TS_DAC, ERR_T_UNEXPECTED, 
                 ZERO, ZERO, ZERO);
        return(errorLog);
	}
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_AUDIO, 5);

//  1000 is the frequency for which the wav is generated and 
//  8000 is the sampling frequency that the i2s controller and codec are set to

    SysAudioToneFillBuf(I2S_FREQ, I2S_SAMP_FREQ, audioBuf, I2SBUF/2);   
 
    for (temp=ZERO;temp < (I2SBUF/2); )
    {
	    while((I2S_regs->SASR0 & XLLP_SASR0_TNF) != XLLP_SASR0_TNF);
		I2S_regs->SADR =  audioBuf[temp++];
	}

	CLKMGR_regs->cken &= ~XLLP_CLKEN_I2S;

	I2S_regs->SACR0 |=  XLLP_SACR0_RST;	
	I2S_regs->SACR0 &= ~XLLP_SACR0_RST;	

    I2S_regs->SACR0 &= ~XLLP_SACR0_ENB;	

   	printf(" User! Set SW20 to DOT position to continue the tests\r\n");
   	GetUserResponse(YES);
    
    printf(" User! Did you hear a tone?\r\n");

	if(GetUserResponse(YESNO))
 	{
 	   	printf(" Success!\r\n");
		return(ZERO);
	}
	else
 	{  
 	 	status = ERRORCODEX(ERR_L_I2SCODEC, 0x80, 1, ERR_T_UNSPECIFIED);
        XllpUtilityOutputError(status);
   		return(status);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -