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

📄 new_aic23.c

📁 芯片AIC23使用dsp做功能上的配置
💻 C
字号:


/* 
 *  ========new_aic23.c ======== 
   initialize the  AIC23 codec driver ,
   the configure data is transfered by I2C bus,
   configure the I2c and finished the transferation successfully.
   note: should make sure where the data is transfered into and what the data is transfered again.
   the produced function:AIC23_setParams(AIC23_Params paramsp)
    
 */

#include <std.h>

#include <csl.h>
#include <csl_i2c.h>

#include <aic23.h>      
#include <evmdm642_edma_aic23.h>
#include <tistdtypes.h>

 I2C_Handle EVMDM642_I2C_hI2C;//I2C_Handle is a struct designed in csl_i2c.h

static void aic23Rset(Uint16 regnum, Uint16 regval);// unsigned int	Uint32;
                                                    // unsigned short	Uint16;
                                                    // unsigned char	Uint8;
                                                                   
static AIC23_Params codecstate = AIC23_DEFAULTPARAMS_EVMDM642;//designed in evmdm642_edma_aic23.h,aic23's default params
                                                              //AIC23_Params is a struct designed in aic23.h

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 */
    0x00000002, /* I2CCNT -    Data words per transmission */
    0x0000001a, /* I2CSAR -    Slave address */
    0x00004ea0, /* I2CMDR -    Mode */
    0x00000019  /* I2CPSC -    Prescale 300MHz to 12MHz */
};

/*
 *  ======== 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 AIC23_setParams(AIC23_Params *paramsp)//the paramsp is the interface between the last frame and the lowest frame
Int AIC23_setParams()
{
   // Int i;
    int i;
   // AIC23_Params *paramsp;// paramsp is the paramas of aic23
//    AIC23_Params *params = paramsp;//give the value to params,params will be changed in the followed code
   
    /*  set to AIC23_DEFAULTPARAMS_EVMDM642 if NULL */
	AIC23_Params *params;
    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]);//AIC23_NUMREGS is 10 in aic23
    }
    
    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.
 */
  void aic23Rset(Uint16 regnum, Uint16 regval)
{
    int a=20;// the delay for aic23
    Uint16 data;
    I2C_Config prevI2CCfg;
    
    /* Mask off lower 9 bits */
    regval &= 0x1ff;
    
    /* Set transmit data */
    data = (regnum << 9) | regval;
    
    /* Wait until bus is free */
    while (I2C_bb(EVMDM642_I2C_hI2C));
    
    /* Save old settings */
    I2C_getConfig(EVMDM642_I2C_hI2C, &prevI2CCfg);
    
    /* Restore settings for AIC23 */
    I2C_config(EVMDM642_I2C_hI2C, &aic23XmtCfg);

    /* Submit the MSB for transmit */
    I2C_writeByte(EVMDM642_I2C_hI2C, (data >> 8) & 0xff);
    
    /* Generate start condition, starts transmission */
    I2C_start(EVMDM642_I2C_hI2C);
    
    /* Wait until MSB transmit is done */
    while(!I2C_xrdy(EVMDM642_I2C_hI2C));

    /* Submit the LSB for transmit */ 
    I2C_writeByte(EVMDM642_I2C_hI2C, data & 0xff);
        
    /* 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 */ 
           
    while(a>0)
       {
           a--;
       }
    /* Reconfigure I2C with old settings */
    I2C_config(EVMDM642_I2C_hI2C, &prevI2CCfg);  
}

⌨️ 快捷键说明

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