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

📄 aic23.c

📁 用DSP5410实现对音乐文件音量的限制性调节
💻 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.11.00.00 11-04-03 (ddk-b13)" */
/*
 *  ======== aic23.c ========
 *
 *  AIC23 codec driver implementation specific to the
 *  Spectrum Digital DSK6416 board.
 */
 
#undef _INLINE          /* for debug so CSL functions are not inline'd */

#include <aic23.h>

#include <csl.h>
#include <csl_mcbsp.h>

static void aic23Rset(MCBSP_Handle hMcbsp, Uint16 regnum, Uint16 regval);

/* CSL handle to the McBSP1. The McBSP is used as the control channel in SPI */
static MCBSP_Config mcbspCfg1 = {
    MCBSP_FMKS(SPCR, FREE, NO)              |
    MCBSP_FMKS(SPCR, SOFT, NO)              |
    MCBSP_FMKS(SPCR, FRST, YES)             |
    MCBSP_FMKS(SPCR, GRST, YES)             |
    MCBSP_FMKS(SPCR, XINTM, XRDY)           |
    MCBSP_FMKS(SPCR, XSYNCERR, NO)          |
    MCBSP_FMKS(SPCR, XRST, YES)             |
    MCBSP_FMKS(SPCR, DLB, OFF)              |
    MCBSP_FMKS(SPCR, RJUST, RZF)            |
    MCBSP_FMKS(SPCR, CLKSTP, NODELAY)       |
    MCBSP_FMKS(SPCR, DXENA, OFF)            |
    MCBSP_FMKS(SPCR, RINTM, RRDY)           |
    MCBSP_FMKS(SPCR, RSYNCERR, NO)          |
    MCBSP_FMKS(SPCR, RRST, YES),

    MCBSP_FMKS(RCR, RPHASE, DEFAULT)        |
    MCBSP_FMKS(RCR, RFRLEN2, DEFAULT)       |
    MCBSP_FMKS(RCR, RWDLEN2, DEFAULT)       |
    MCBSP_FMKS(RCR, RCOMPAND, DEFAULT)      |
    MCBSP_FMKS(RCR, RFIG, DEFAULT)          |
    MCBSP_FMKS(RCR, RDATDLY, DEFAULT)       |
    MCBSP_FMKS(RCR, RFRLEN1, DEFAULT)       |
    MCBSP_FMKS(RCR, RWDLEN1, DEFAULT)       |
    MCBSP_FMKS(RCR, RWDREVRS, DEFAULT),

    MCBSP_FMKS(XCR, XPHASE, SINGLE)         |
    MCBSP_FMKS(XCR, XFRLEN2, OF(0))         |
    MCBSP_FMKS(XCR, XWDLEN2, 8BIT)          |
    MCBSP_FMKS(XCR, XCOMPAND, MSB)          |
    MCBSP_FMKS(XCR, XFIG, NO)               |
    MCBSP_FMKS(XCR, XDATDLY, 0BIT)          |
    MCBSP_FMKS(XCR, XFRLEN1, OF(0))         |
    MCBSP_FMKS(XCR, XWDLEN1, 16BIT)         |
    MCBSP_FMKS(XCR, XWDREVRS, DISABLE),
        
    MCBSP_FMKS(SRGR, GSYNC, FREE)           |
    MCBSP_FMKS(SRGR, CLKSP, RISING)         |
    MCBSP_FMKS(SRGR, CLKSM, INTERNAL)       |
    MCBSP_FMKS(SRGR, FSGM, DXR2XSR)         |
    MCBSP_FMKS(SRGR, FPER, OF(0))           |
    MCBSP_FMKS(SRGR, FWID, OF(19))          |
    MCBSP_FMKS(SRGR, CLKGDV, OF(99)),

    MCBSP_MCR_DEFAULT,
    MCBSP_RCERE0_DEFAULT,
    MCBSP_RCERE1_DEFAULT,
    MCBSP_RCERE2_DEFAULT,
    MCBSP_RCERE3_DEFAULT,
    MCBSP_XCERE0_DEFAULT,
    MCBSP_XCERE1_DEFAULT,
    MCBSP_XCERE2_DEFAULT,
    MCBSP_XCERE3_DEFAULT,

    MCBSP_FMKS(PCR, XIOEN, SP)              |
    MCBSP_FMKS(PCR, RIOEN, SP)              |
    MCBSP_FMKS(PCR, FSXM, INTERNAL)         |
    MCBSP_FMKS(PCR, FSRM, EXTERNAL)         |
    MCBSP_FMKS(PCR, CLKXM, OUTPUT)          |
    MCBSP_FMKS(PCR, CLKRM, INPUT)           |
    MCBSP_FMKS(PCR, CLKSSTAT, DEFAULT)      |
    MCBSP_FMKS(PCR, DXSTAT, DEFAULT)        |
    MCBSP_FMKS(PCR, FSXP, ACTIVELOW)        |
    MCBSP_FMKS(PCR, FSRP, DEFAULT)          |
    MCBSP_FMKS(PCR, CLKXP, FALLING)         |
    MCBSP_FMKS(PCR, CLKRP, DEFAULT)
};

/*
 *  ======== 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 *params)
{
    Int i;
    MCBSP_Handle hMcbsp;

    /* Open and configure McBSPs */
    hMcbsp = MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET);

    /* Check for valid handle */
    if (hMcbsp == INV) {
        return FALSE;
    }

    /* Configure control McBSP */    
    MCBSP_config(hMcbsp, &mcbspCfg1);

    /*
     *  Initialize the AIC23 codec
     */

    /* Start McBSP1 as the codec control channel */
    MCBSP_start(hMcbsp, MCBSP_XMIT_START |
        MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, 0);
    
    /* Reset the AIC23 */
    aic23Rset(hMcbsp, AIC23_RESET, 0);
    
    /* Assign each register */
    for (i = 0; i < AIC23_NUMREGS; i++) {
        aic23Rset(hMcbsp, 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(MCBSP_Handle hMcbsp, Uint16 regnum, Uint16 regval)
{
    /* Mask off all but lower 9 bits */
    regval &= 0x1ff;
    
    /* Wait while XRDY not asserted before writing data to DXR */
    while (!MCBSP_xrdy(hMcbsp));
    
    /* Write 16 bit data value to DXR */
    MCBSP_write(hMcbsp, (regnum << 9) | regval);

    /* Wait for the current transfer to completely get over */
    while (MCBSP_xempty(hMcbsp));
}

⌨️ 快捷键说明

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