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

📄 aic23.c

📁 在海尔的DM642开发板实现RF5框架
💻 C
字号:
/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */
/* 
 *  ======== aic23.c ======== 
 *
 *  AIC23 codec driver implementation specific to the 
 *  Spectrum Digital DM642 EVM board.
 */

#include <std.h>

#include <csl.h>
#include <csl_i2c.h>
#include <aic23.h>
#include "evmdm642.h"
#include <evmdm642_edma_aic23.h>

static void aic23Rset(Uint16 regnum, Uint16 regval);
static AIC23_Params codecstate = AIC23_DEFAULTPARAMS_EVMDM642;
#define I2CDELAY(iterations)  {      \
    volatile Int j;                  \
    for(j = 0; j < iterations; j ++); \
}   
#define DELAY_TIME 1000
#if 1
static I2C_Config aic23XmtCfg = {
		0x0000007f, /* I2COAR -    Not used if master */
		0x00000000, /* I2CIER -    Disable interrupts, use polling */
		0x0000001b, /* I2CCLKL -   Low period for 100KHz operation */
		0x0000001b, /* I2CCLKH -   High period for 100KHz operation */
		0x00000000, /* I2CCNT -    Data words per transmission */
		0x0000001a, /* I2CSAR -    Slave address aic23 i2c address*/
		0x00004ea0,  /* I2CMDR -    Mode 4ea0*/
		0x0000004a  /* I2CPSC -    Prescale 300MHz to 12MHz */
};
#endif
/*
 *  ======== AIC23_setParams ========
 *
 *  This function takes a pointer to the object of type AIC23_Params,
 *  and writes all 11 control words found in it to the codec. Prior
 *  to that it initializes the codec if this is the first time the
 *  function is ever called.  Return TRUE for successful completion,
 *  FALSE if errors.
 */
Int AIC23_setParams(AIC23_Params *paramsp)
{
    Int i;
    AIC23_Params *params = paramsp;
   
    /*  set to AIC23_DEFAULTPARAMS_EVMDM642 if NULL */
    if (params == NULL) {
        params = &codecstate;
    }
    
    /* Reset the AIC23 */
    aic23Rset(AIC23_RESET, 0);
    
    /* Assign each register */
    for (i = 0; i < AIC23_NUMREGS; i++) {
        aic23Rset(i, params->regs[i]);
    }
    
    return TRUE;
}
/*
 *  ======== aic23Rset ========
 *  Set codec register regnum to value regval.  The 16-bit word is composed
 *  of register address in the upper 7 bits and the 9-bit register value
 *  stored in the parameters structure.
 */
static Void aic23Rset(Uint16 regnum, Uint16 regval)
{
    Uint16 data;
    int j=0;
    I2C_Config prevI2CCfg;
    /* Mask off lower 9 bits */
    regval &= 0x1ff;
    /* Set transmit data */
    data = (regnum << 9) | regval;
    I2C_sendStop(EVMDM642_I2C_hI2C);  
    /* Wait until bus is free */
    while (I2C_bb(EVMDM642_I2C_hI2C))
    {
			j++;
			if(j > 60000)
			{
				I2C_RSETH(EVMDM642_I2C_hI2C, I2CSTR, 0x10001000);
				j=0;
			}
			//I2CDELAY(DELAY_TIME);
	};
    /* Save old settings */
    I2C_getConfig(EVMDM642_I2C_hI2C, &prevI2CCfg);
    
 	/* Restore settings for AIC23 */
    I2C_config(EVMDM642_I2C_hI2C, &aic23XmtCfg);
    /* Submit the MSB for transmit ,reg address*/
    I2C_RSETH(EVMDM642_I2C_hI2C, I2CDXR, (data >> 8) & 0xff);
    /* Generate start condition, starts transmission */
    I2C_start(EVMDM642_I2C_hI2C);
    I2CDELAY(DELAY_TIME);
    /* Wait until MSB transmit is done */
    while(!I2C_xrdy(EVMDM642_I2C_hI2C))
 	{
			j++;
			if(j > 60000)
			{
				I2C_RSETH(EVMDM642_I2C_hI2C, I2CSTR, 0x00100010);
				j=0;
			}
			//I2CDELAY(DELAY_TIME);
	};
    /* Submit the LSB for transmit */ 
    I2C_writeByte(EVMDM642_I2C_hI2C, data & 0xff);
    I2CDELAY(DELAY_TIME);    
    /* Generate stop condition */
    I2C_sendStop(EVMDM642_I2C_hI2C);  

    /* Wait until bus is free */
    while (I2C_bb(EVMDM642_I2C_hI2C));
    
    /* Save register value if regnum is in range */
    if (regnum < AIC23_NUMREGS)
        codecstate.regs[regnum] = regval;

    /* Short delay for AIC23 to accept command */        
    EVMDM642_waitusec(20);
	 I2CDELAY(DELAY_TIME);  
    /* Reconfigure I2C with old settings */
    I2C_config(EVMDM642_I2C_hI2C, &prevI2CCfg);  
}

⌨️ 快捷键说明

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