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

📄 i2s.c

📁 优龙YLP270开发板 光盘自带的BIOS和实验例程源码 强烈推荐
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
**
**  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:       xllp_I2S.c
**
**  PURPOSE: contains all primitive functions for Bulverde I2S register access 
**     and control
**                  
******************************************************************************/
#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "xllp_gpio.h"
#include "xllp_i2s.h"
#include "WM_i2s_Codec.h"
#include "i2s.h"
#include "DM_Errors.h"
#include "SysAudioToneApi.h"
#include "XsGpioApi.h"
#include "systypes.h"
#include "xsuart.h"
#include "DM_SerialInOut.h"
#include "boardcontrol.h"

/*
*******************************************************************************
*
* FUNCTION:         I2S_CodecSetup
*
* DESCRIPTION:      Turning on the codec and powering it up  
*
* INPUT PARAMETERS: None
*
* RETURNS:          XLLP_UINT32_T
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:
*
* CALLS:
*
* CALLED BY:		I2S_Test()
*
* PROTOTYPE:        XLLP_UINT32_T I2S_CodecSetup (void);
*
*******************************************************************************
*/

XLLP_UINT32_T I2S_CodecSetup()
{ 
    INT errorLog=0;
    INT status=0;
//   	XLLP_UINT32_T temp=0, temp2=0x445;
//   	int i[1001], j=0;
//  	volatile unsigned int *hexLed =  (volatile unsigned int *) 0x08000010;
	volatile P_XLLP_INTC_T intReg = (P_XLLP_INTC_T)0x40d00000;
	volatile P_POST_I2C_T i2c_regs = (P_POST_I2C_T)STD_I2C_BASE;
    I2C_TX i2s_codec;
    
	XLLP_UINT8_T PowerDownControl[]= {(PowerDownControlAddr), (PowerDownControlData)};
	XLLP_UINT8_T SamplingControl[]= {(SamplingControlAddr), (SamplingControlData)};
	XLLP_UINT8_T Reset[]={(ResetAddr), (ResetData)};
	 
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_SETUP, 1);
 

 // this value (I2SCODEC_ID) is gotten from the codec spec and is how the I2C bus communicates with 
// the codec
    
    i2s_codec.dev_id = I2SCODEC_ID;
    i2s_codec.data_len = sizeof(PowerDownControl);
    i2s_codec.data=PowerDownControl;
  
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_SETUP, 2);
    
    if((status= i2c_write(i2c_regs, intReg, &i2s_codec))!= ERR_T_NONE)
    {	
         XllpUtilityOutputError(status);
         LOGERRORX(errorLog, 
                   ERR_L_I2SCODEC,ERR_TS_I2C_CODWRITE,PWRDWN,ERR_T_NOTRANSMIT, 
                   0, 0, 0);
        return(status);
    }

    DM_WaitMs(1);  	
    
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_SETUP, 3);
    
    i2s_codec.data_len = sizeof(Reset);
    i2s_codec.data=Reset;
    
    if((status= i2c_write(i2c_regs, intReg, &i2s_codec))!= ERR_T_NONE)
    {	
        XllpUtilityOutputError(status);
        LOGERRORX(errorLog, 
                ERR_L_I2SCODEC, ERR_TS_I2C_CODWRITE,RESET, ERR_T_NOTRANSMIT, 
                 0, 0, 0);
        return(errorLog);
    }  	

    DM_WaitMs(1);  	

    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_SETUP, 4);
//  sampling rate is set by the processor, not the codec;  it is set to the fastest
//  sampling frequency it can handle and the processor scales it down appropriately 
//  the the DIV register
    i2s_codec.data_len = sizeof(SamplingControl);
    i2s_codec.data=SamplingControl;
    
    if((status= i2c_write(i2c_regs, intReg, &i2s_codec))!= ERR_T_NONE)
    {	
        XllpUtilityOutputError(status);
        LOGERRORX(errorLog, 
                 ERR_L_I2SCODEC, ERR_TS_I2C_CODWRITE,SAMPCONTROL, ERR_T_NOTRANSMIT, 
                 0, 0, 0);
        return(status);
    }  	
    DM_WaitMs(1);  	
    
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_SETUP, 5);
    return(errorLog);
}

/*
*******************************************************************************
*
* FUNCTION:         I2S_DACSetup
*
* DESCRIPTION:      putting the codec into Digital -to - analog state  
*
* INPUT PARAMETERS: None
*
* RETURNS:          XLLP_UINT32_T
*
* GLOBAL EFFECTS:   None
*
* ASSUMPTIONS:
*
* CALLS:
*
* CALLED BY:		I2S_Test()
*
* PROTOTYPE:        XLLP_UINT32_T I2S_DACSetup (void);
*
*******************************************************************************
*/

XLLP_UINT32_T I2S_DACSetup(void)
{
    INT errorLog=0;
 	INT status=0;
    I2C_TX i2s_codec;
	volatile P_POST_I2C_T i2c_regs = (P_POST_I2C_T)STD_I2C_BASE;
	volatile P_XLLP_INTC_T intReg = (P_XLLP_INTC_T)0x40d00000;
 
 //  these are standard value recommended by wolfson for DAC 
    XLLP_UINT8_T LeftLineIn[]= {(LeftLineInAddr), (DAC_LeftLineInData)};
    XLLP_UINT8_T RightLineIN[]={(RightLineINAddr), (DAC_RightLineINData)};
    XLLP_UINT8_T AAPathControl[]= {(AAPathControlAddr), (DAC_AAPathControlData)};
    XLLP_UINT8_T DAPathControl[]={(DAPathControlAddr), (DAC_DAPathControlData)};
    XLLP_UINT8_T DAInterfaceFormat[]={(DAInterfaceFormatAddr), (DAC_DAInterfaceFormatData)};
    XLLP_UINT8_T PowerDownControl[]= {(PowerDownControlAddr), (DAC_PowerDownControlData)};
    XLLP_UINT8_T ActiveControlOn[]={(ActiveControlAddr), (ActiveControlOnData)}; 
    XLLP_UINT8_T ActiveControlOff[]={(ActiveControlAddr), (ActiveControlOffData)}; 

// this value (I2SCODEC_ID) is gotten from the codec spec and is how the I2C bus communicates with 
// the codec

    i2s_codec.dev_id = I2SCODEC_ID;

    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_DAC, 1);
//  must deactivate the codec before writing to it to ensure no noise occurs when changing
//  the register settings
    i2s_codec.data_len = sizeof(ActiveControlOff);
    i2s_codec.data=ActiveControlOff;
    
    if((status= i2c_write(i2c_regs, intReg, &i2s_codec))!= ERR_T_NONE)
    {	
        LOGERRORX(errorLog, 
                 ERR_L_I2SCODEC, ERR_TS_I2C_DACWRITE,ACTIVECONTROLOFF, ERR_T_NOTRANSMIT, 
                 0, 0, 0);
        XllpUtilityOutputError(errorLog);
        return(errorLog);
    }  	 
    DM_WaitMs(1);  	
	
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_DAC, 2);

    i2s_codec.data_len = sizeof(PowerDownControl);
    i2s_codec.data=PowerDownControl;
    
    if((status= i2c_write(i2c_regs, intReg, &i2s_codec))!= ERR_T_NONE)
    {	
        LOGERRORX(errorLog, 
                 ERR_L_I2SCODEC, ERR_TS_I2C_DACWRITE,PWRDWN, ERR_T_NOTRANSMIT, 
                 0, 0, 0);
        XllpUtilityOutputError(errorLog);
        return(errorLog);
    }  	
  	
    DM_WaitMs(1);  	
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_DAC, 3);
    
    i2s_codec.data_len = sizeof(DAInterfaceFormat);
    i2s_codec.data=DAInterfaceFormat;
    
    if((status= i2c_write(i2c_regs, intReg, &i2s_codec))!= ERR_T_NONE)
    {	
        LOGERRORX(errorLog, 
                 ERR_L_I2SCODEC, ERR_TS_I2C_DACWRITE, DAINTERFACEFORMAT, ERR_T_NOTRANSMIT, 
                 0, 0, 0);
        XllpUtilityOutputError(errorLog);
        return(errorLog);
    }  	

    DM_WaitMs(1);  	
    PostDisplayProgress(ERR_L_I2SCODEC, ERR_TS_DAC, 4);
    
    i2s_codec.data_len = sizeof(LeftLineIn);
    i2s_codec.data=LeftLineIn;
    
    if((status= i2c_write(i2c_regs, intReg, &i2s_codec))!= ERR_T_NONE)
    {	
        LOGERRORX(errorLog, 
                 ERR_L_I2SCODEC, ERR_TS_I2C_DACWRITE, LEFTLINEIN, ERR_T_NOTRANSMIT, 
                 0, 0, 0);
        XllpUtilityOutputError(errorLog);
        return(errorLog);
    }  	

    DM_WaitMs(1);  	

⌨️ 快捷键说明

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