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

📄 evmdm642_edma_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)" */
/* 
 *  ======== evmdm642_edma_aic23.c ========
 * 
 *  Driver for the aic23 codec on the TMS320C642 EVM. 
 *  Requires the generic TMS320C6x1x McASP driver.
 */

#include <std.h>

#include <iom.h>
#include <csl.h>
#include <csl_mcasp.h>
#include <csl_edma.h>
#include <csl_i2c.h>
#include <aic23.h>
#include "evmdm642.h"
#include <evmdm642_edma_aic23.h>
#include <c6x1x_edma_mcasp.h>

#define MCASPPORT  0

#define GENERICDEVPARAMS {                                                 \
    C6X1X_EDMA_MCASP_VERSION_1, /* version id */                           \
    TRUE, /* True if buffers are in cacheable memory (set in mdBindDev) */ \
    /* Driver not enable the McASP high frequecy rate generator */         \
    C6X1X_EDMA_MCASP_EXTERNAL,                                             \
    /* Driver not enable the McASP clk rate generator */                   \
    C6X1X_EDMA_MCASP_EXTERNAL,                                             \
    /* Driver not enable the McASP frame sync generator */                 \
    C6X1X_EDMA_MCASP_EXTERNAL,                                             \
    0,     /* IRQ id to use for the EDMA (set in mdBindDev) */             \
    NULL,  /* McASP configuration for the loopback (set in mdBindDev) */   \
    -1,    /* input event irq id */                                        \
    -1,    /* output event irq id */                                       \
    NULL,   /* event callback NULL,*/                                           \
    EVMDM642_EDMA_AIC23_INTR_MASK_DEFAULT,                                 \
    EVMDM642_EDMA_AIC23_INTR_MASK_DEFAULT,                                 \
    EVMDM642_EDMA_AIC23_INTR_MASK_DEFAULT                                  \
}

EVMDM642_EDMA_AIC23_DevParams EVMDM642_EDMA_AIC23_DEVPARAMS = EVMDM642_EDMA_AIC23_DEFAULT_DEVPARAMS;


MCASP_ConfigGbl configGbl = {0,1,0,0,0};
	MCASP_ConfigRcv configRcv = {0x0, 0x000080f0,0,128,0,1,0,0};
	MCASP_ConfigXmt configXmt = {0x0, 0x000080f0,0,192,0,1,0,0};
	MCASP_ConfigSrctl configSrctl = {13,14,0,0,0,0,0,0};
/*
 *  ======== EVMDM642_DEVPARAMS ========
 *  This static initialization defines the default parameters used for
 *  EVMDM642_EDMA_AIC23 IOM driver
 */
EVMDM642_EDMA_AIC23_DevParams EVMDM642_CODEC_DEVPARAMS = EVMDM642_EDMA_AIC23_DEFAULT_DEVPARAMS;
        
#if 0       
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
/******************************************/
 
/******************************************/
/*
 * Forward declaration of the IOM interface functions. They are only
 * exposed via the IOM function table to avoid namespace pollution.
 */
static Int mdBindDev(Ptr *devp, Int devid, Ptr devParams);
static Int mdCreateChan(Ptr *chanp, Ptr devp, String name, Int mode,
                        Ptr chanParams, IOM_TiomCallback cbFxn, Ptr cbArg);

/*
 * The codec driver function table. Notice how we copy most functions
 * from the generic c6x1x edma mcasp driver.
 */
IOM_Fxns EVMDM642_EDMA_AIC23_FXNS = {
    &mdBindDev,
    NULL,
    NULL,
    &mdCreateChan,
  NULL,
    NULL
};

/*
 * ======== mdBindDev ========
 * This function allocates and configures the pcm3002 codec.
 */
static Int mdBindDev(Ptr *devp, Int devid, Ptr devParams)
{
   EVMDM642_EDMA_AIC23_DevParams *params =
        (EVMDM642_EDMA_AIC23_DevParams *) devParams;
    C6X1X_EDMA_MCASP_DevParams genericParams = GENERICDEVPARAMS;

 
    MCASP_Config mcaspCfg;
	
    mcaspCfg.global = &configGbl;
    mcaspCfg.receive = &configRcv;
    mcaspCfg.transmit = &configXmt;
    mcaspCfg.srctl = &configSrctl;

    
    /* If no device parameters are passed, use the defaults. */
    if (params == NULL) {
        params = &EVMDM642_EDMA_AIC23_DEVPARAMS;
    }

    /* Check if the version is supported by the driver. */
    if(params->versionId != EVMDM642_EDMA_AIC23_VERSION_1){
        /* Unsupported version */
        return(IOM_EBADARGS);
    }

    /* Set the McASP */ 
    genericParams.mcaspCfgPtr = &mcaspCfg;

    genericParams.irqId = params->irqId;
    genericParams.enableClkg = params->enableClkg;
    genericParams.enableHclkg = params->enableHclkg;
    genericParams.enableFsyncg = params->enableFsyncg;
    genericParams.cacheCalls = params->cacheCalls;
    genericParams.inEvtIrqId = params->inEvtIrqId;
    genericParams.outEvtIrqId = params->outEvtIrqId;
    genericParams.evtCallback = params->evtCallback;
    genericParams.inEvtIntrMask  = params->inEvtIntrMask;
    genericParams.outEvtIntrMask  = params->outEvtIntrMask;
    /* Set the interrupt mask */
    genericParams.edmaIntrMask = params->edmaIntrMask;

    /* Set codec parameters */
    if (!AIC23_setParams(&(params->aic23Config))) {
       return (IOM_EALLOC);
    }

    /* Call the generic mdBindDev to claim mcasp port MCASPPORT */
    return (C6X1X_EDMA_MCASP_FXNS.mdBindDev)(devp, MCASPPORT, &genericParams);
}

/*
 * ======== mdCreateChan ========
 * This function creates and configures a device channel.
 */
static Int mdCreateChan(Ptr *chanp, Ptr devp, String name, Int mode,
                        Ptr chanParams, IOM_TiomCallback cbFxn, Ptr cbArg)
{
    Int result;
    C6X1X_EDMA_MCASP_ChanParams genericParams;

    EDMA_Config edmaCfg = {
        EDMA_FMKS(OPT, PRI, HIGH)             |
        EDMA_FMKS(OPT, ESIZE, 32BIT)          |
        EDMA_FMKS(OPT, 2DS, NO)               |
        EDMA_FMKS(OPT, SUM, NONE)             |
        EDMA_FMKS(OPT, 2DD, NO)               |
        EDMA_FMKS(OPT, DUM, NONE)             |
        EDMA_FMKS(OPT, TCINT, YES)            |
        EDMA_FMK (OPT, TCC, NULL)             |
        EDMA_FMKS(OPT, LINK, YES)             |
        EDMA_FMKS(OPT, FS, YES),

        EDMA_FMK(SRC, SRC, NULL),

        EDMA_FMKS(CNT, FRMCNT, DEFAULT)       |
        EDMA_FMKS(CNT, ELECNT, DEFAULT),

        EDMA_FMK(DST, DST, NULL),

        EDMA_FMKS(IDX, FRMIDX, DEFAULT)       |
        EDMA_FMKS(IDX, ELEIDX, DEFAULT),

        EDMA_FMKS(RLD, ELERLD, DEFAULT)       |
        EDMA_FMK(RLD, LINK, NULL)
    };      

    /* Set ELECNT, ELERLD to the active serializers */
    /* FRMCNT will be 1 pair of SRCTL and set in C6x1x_edma_mcasp driver */
    EDMA_FSETA(&edmaCfg.cnt, CNT, ELECNT, 1);   
    EDMA_FSETA(&edmaCfg.rld, RLD, ELERLD, 1); 

    if (mode == IOM_INPUT) {
        EDMA_FSETSA(&edmaCfg.opt, OPT, DUM, INC);
        /* Select EDMA channel 13 for rcv here */
        genericParams.edmaChan = 13;
    } else {

        EDMA_FSETSA(&edmaCfg.opt, OPT, SUM, INC);

        /* Select EDMA channel 12 for xmt here */
        genericParams.edmaChan = 12;
    }

    genericParams.edmaCfgPtr = &edmaCfg;
    /* 
     * for loopback, no need to sync to external frame sync, 
     * set to 5 to run loop edma job long enough for sync real xmt & rcv job
     */  
    genericParams.tdmChans = 1;
    
    result = (C6X1X_EDMA_MCASP_FXNS.mdCreateChan)(chanp, devp, name, mode,
                                                &genericParams, cbFxn, cbArg);
    return (result);
}

/*
 * ======== EVMDM642_EDMA_AIC23_init ========
 * This function initializes the driver's structures.
 */

Void EVMDM642_EDMA_AIC23_init()
{

    /* Pass some IOM fxns straight to the generic driver */

    EVMDM642_EDMA_AIC23_FXNS.mdControlChan =
        C6X1X_EDMA_MCASP_FXNS.mdControlChan;
    EVMDM642_EDMA_AIC23_FXNS.mdDeleteChan =
        C6X1X_EDMA_MCASP_FXNS.mdDeleteChan;
    EVMDM642_EDMA_AIC23_FXNS.mdSubmitChan =
        C6X1X_EDMA_MCASP_FXNS.mdSubmitChan;
    EVMDM642_EDMA_AIC23_FXNS.mdUnBindDev =
        C6X1X_EDMA_MCASP_FXNS.mdUnBindDev;

    C6X1X_EDMA_MCASP_init();
}

⌨️ 快捷键说明

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