dsk5510_dma_aic23.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:13k
源码类别:

DSP编程

开发平台:

C/C++

  1. /*
  2.  *  Copyright 2003 by Texas Instruments Incorporated.
  3.  *  All rights reserved. Property of Texas Instruments Incorporated.
  4.  *  Restricted rights to use, duplicate or disclose this code are
  5.  *  granted through contract.
  6.  *  
  7.  */
  8. /* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */
  9. /* 
  10.  *  ======== dsk5510_dma_aic23.c ========
  11.  * 
  12.  *  DMA interrupt-driven low-level streaming device driver for TI
  13.  *  5510 DSK. Uses the C55x Chip Support Library. 
  14.  *
  15.  *  DSP/BIOS configuration:
  16.  *     DMA channel 4 RX ISR plugged to DSK5510_DMA_AIC23_isr with arg = 0
  17.  *     DMA channel 5 TX ISR plugged to DSK5510_DMA_AIC23_isr with arg = 1
  18.  */
  19. #include <std.h>
  20. #include <csl.h>
  21. #include <csl_dma.h>
  22. #include <csl_mcbsp.h>
  23. #include <iom.h>
  24. #include <c55xx_dma_mcbsp.h>
  25. #include <dsk5510_dma_aic23.h>
  26. #include <aic23.h>
  27. /*
  28.  * Forward declaration of IOM interface functions.
  29.  */
  30. static Int mdBindDev(Ptr *hDevice, Int devid, Ptr devParams);
  31. static Int mdCreateChan(Ptr *chanp, Ptr devp, String name, Int mode,
  32.         Ptr chanParams, IOM_TiomCallback cbFxn, Ptr cbArg);
  33. /*
  34.  * Public IOM interface table.
  35.  */
  36. IOM_Fxns DSK5510_DMA_AIC23_FXNS;
  37. /* CSL handle to the McBSP2. The McBSP is shared between the two channels */
  38. static MCBSP_Config mcbspCfg2 = {
  39.     MCBSP_SPCR1_RMK(
  40.         MCBSP_SPCR1_DLB_OFF,                   /* DLB      = 0 */
  41.         MCBSP_SPCR1_RJUST_RZF,                 /* RJUST    = 0 */
  42.         MCBSP_SPCR1_CLKSTP_DISABLE,            /* CLKSTP   = 0 */
  43.         MCBSP_SPCR1_DXENA_NA,                  /* DXENA    = 0 */
  44.         MCBSP_SPCR1_ABIS_DISABLE,              /* ABIS     = 0 */
  45.         MCBSP_SPCR1_RINTM_RRDY,                /* RINTM    = 0 */
  46.         0,                                     /* RSYNCER  = 0 */
  47.         0,                                     /* RFULL    = 0 */
  48.         0,                                     /* RRDY     = 0 */
  49.         MCBSP_SPCR1_RRST_DISABLE               /* RRST     = 0 */
  50.     ),
  51.     MCBSP_SPCR2_RMK(
  52.         MCBSP_SPCR2_FREE_NO,                   /* FREE     = 0 */
  53.         MCBSP_SPCR2_SOFT_YES,                  /* SOFT     = 1 */
  54.         MCBSP_SPCR2_FRST_RESET,                /* FRST     = 0 */
  55.         MCBSP_SPCR2_GRST_RESET,                /* GRST     = 0 */
  56.         MCBSP_SPCR2_XINTM_XRDY,                /* XINTM    = 0 */
  57.         0,                                     /* XSYNCER  = 0 */
  58.         0,                                     /* XEMPTY   = 0 */
  59.         0,                                     /* XRDY     = 0 */
  60.         MCBSP_SPCR2_XRST_DISABLE               /* XRST     = 0 */
  61.     ),
  62.     MCBSP_RCR1_RMK(
  63.         MCBSP_RCR1_RFRLEN1_OF(1),              /* RFRLEN1  = 1 */
  64.         MCBSP_RCR1_RWDLEN1_16BIT               /* RWDLEN1  = 2 */
  65.     ),
  66.     MCBSP_RCR2_RMK(
  67.         MCBSP_RCR2_RPHASE_SINGLE,              /* RPHASE   = 0 */
  68.         MCBSP_RCR2_RFRLEN2_OF(0),              /* RFRLEN2  = 0 */
  69.         MCBSP_RCR2_RWDLEN2_8BIT,               /* RWDLEN2  = 0 */
  70.         MCBSP_RCR2_RCOMPAND_MSB,               /* RCOMPAND = 0 */
  71.         MCBSP_RCR2_RFIG_YES,                   /* RFIG     = 0 */
  72.         MCBSP_RCR2_RDATDLY_0BIT                /* RDATDLY  = 0 */
  73.     ),
  74.     MCBSP_XCR1_RMK(
  75.         MCBSP_XCR1_XFRLEN1_OF(1),              /* XFRLEN1  = 1 */
  76.         MCBSP_XCR1_XWDLEN1_16BIT               /* XWDLEN1  = 2 */
  77.     ),
  78.     MCBSP_XCR2_RMK(
  79.         MCBSP_XCR2_XPHASE_SINGLE,              /* XPHASE   = 0 */
  80.         MCBSP_XCR2_XFRLEN2_OF(0),              /* XFRLEN2  = 0 */
  81.         MCBSP_XCR2_XWDLEN2_8BIT,               /* XWDLEN2  = 0 */
  82.         MCBSP_XCR2_XCOMPAND_MSB,               /* XCOMPAND = 0 */
  83.         MCBSP_XCR2_XFIG_YES,                   /* XFIG     = 0 */
  84.         MCBSP_XCR2_XDATDLY_0BIT                /* XDATDLY  = 0 */
  85.     ),
  86.     MCBSP_SRGR1_RMK(
  87.         MCBSP_SRGR1_FWID_OF(0),                /* FWID     = 0 */
  88.         MCBSP_SRGR1_CLKGDV_OF(0)               /* CLKGDV   = 0 */
  89.     ),
  90.     MCBSP_SRGR2_RMK(
  91.         MCBSP_SRGR2_GSYNC_FREE,                /* FREE     = 0 */
  92.         MCBSP_SRGR2_CLKSP_RISING,              /* CLKSP    = 0 */
  93.         MCBSP_SRGR2_CLKSM_CLKS,                /* CLKSM    = 0 */
  94.         MCBSP_SRGR2_FSGM_DXR2XSR,              /* FSGM     = 0 */
  95.         MCBSP_SRGR2_FPER_OF(0)                 /* FPER     = 0 */
  96.     ),
  97.     MCBSP_MCR1_DEFAULT,
  98.     MCBSP_MCR2_DEFAULT,
  99.     MCBSP_PCR_RMK(
  100.         MCBSP_PCR_IDLEEN_RESET,                /* IDLEEN   = 0 */
  101.         MCBSP_PCR_XIOEN_SP,                    /* XIOEN    = 0 */
  102.         MCBSP_PCR_RIOEN_SP,                    /* RIOEN    = 0 */
  103.         MCBSP_PCR_FSXM_EXTERNAL,               /* FSXM     = 0 */
  104.         MCBSP_PCR_FSRM_EXTERNAL,               /* FSRM     = 0 */
  105.         MCBSP_PCR_SCLKME_NO,                   /* SCLKME   = 0 */
  106.         0,                                     /* CLKSSTAT = 0 */
  107.         0,                                     /* DXSTAT   = 0 */
  108.         0,                                     /* DRSTAT   = 0 */
  109.         MCBSP_PCR_CLKXM_INPUT,                 /* CLKXM    = 0 */
  110.         MCBSP_PCR_CLKRM_INPUT,                 /* CLKRM    = 0 */
  111.         MCBSP_PCR_FSXP_ACTIVEHIGH,             /* FSXP     = 0 */
  112.         MCBSP_PCR_FSRP_ACTIVEHIGH,             /* FSRP     = 0 */
  113.         MCBSP_PCR_CLKXP_FALLING,               /* CLKXP    = 1 */
  114.         MCBSP_PCR_CLKRP_RISING                 /* CLKRP    = 1 */
  115.     ),
  116.     MCBSP_RCERA_DEFAULT,
  117.     MCBSP_RCERB_DEFAULT,
  118.     MCBSP_RCERC_DEFAULT,
  119.     MCBSP_RCERD_DEFAULT,
  120.     MCBSP_RCERE_DEFAULT,
  121.     MCBSP_RCERF_DEFAULT,
  122.     MCBSP_RCERG_DEFAULT,
  123.     MCBSP_RCERH_DEFAULT,
  124.     MCBSP_XCERA_DEFAULT,
  125.     MCBSP_XCERB_DEFAULT,
  126.     MCBSP_XCERC_DEFAULT,
  127.     MCBSP_XCERD_DEFAULT,
  128.     MCBSP_XCERE_DEFAULT,
  129.     MCBSP_XCERF_DEFAULT,
  130.     MCBSP_XCERG_DEFAULT,
  131.     MCBSP_XCERH_DEFAULT
  132. };
  133. /*  CSL to handle the DMA Channels 4 and 5 */
  134. static DMA_Config dmaRxCfg = {
  135.     0,                         /* DMACSDP will be initialized by mdBindDev */
  136.     DMA_DMACCR_RMK(
  137.         DMA_DMACCR_DSTAMODE_POSTINC,
  138.         DMA_DMACCR_SRCAMODE_CONST,
  139.         DMA_DMACCR_ENDPROG_OFF,
  140.         DMA_DMACCR_REPEAT_OFF,
  141.         DMA_DMACCR_AUTOINIT_OFF,
  142.         DMA_DMACCR_EN_STOP,
  143.         DMA_DMACCR_PRIO_HI,
  144.         DMA_DMACCR_FS_DISABLE,
  145.         DMA_DMACCR_SYNC_REVT2
  146.     ),                              /* DMACCR   */
  147.     DMA_DMACICR_RMK(
  148.         DMA_DMACICR_BLOCKIE_OFF,
  149.         DMA_DMACICR_LASTIE_OFF,
  150.         DMA_DMACICR_FRAMEIE_ON,
  151.         DMA_DMACICR_FIRSTHALFIE_OFF,
  152.         DMA_DMACICR_DROPIE_OFF,
  153.         DMA_DMACICR_TIMEOUTIE_OFF
  154.     ),                             /* DMACICR                          */
  155.     (DMA_AdrPtr)((Uint32)(_MCBSP_DRR12_ADDR<<1)), /*DMACSSAL=MCBSP2 DRR*/
  156.     0x0000,                        /* DMACSSAU                         */
  157.     (DMA_AdrPtr)0x0000,            /* DMACDSAL, to be loaded by submit */
  158.     0x0000,                        /* DMACDSAU                         */
  159.     0x0000,                        /* DMACEN                           */
  160.     0x0001,                        /* DMACFN                           */
  161.     0x0000,                        /* DMACFI                           */
  162.     0x0000                         /* DMACEI                           */
  163. };
  164. static DMA_Config dmaTxCfg = {
  165.     0,                           /* DMACSDP will be initialized by mdBindDev */
  166.     DMA_DMACCR_RMK(
  167.         DMA_DMACCR_DSTAMODE_CONST,
  168.         DMA_DMACCR_SRCAMODE_POSTINC,
  169.         DMA_DMACCR_ENDPROG_OFF,
  170.         DMA_DMACCR_REPEAT_OFF,
  171.         DMA_DMACCR_AUTOINIT_OFF,
  172.         DMA_DMACCR_EN_STOP,
  173.         DMA_DMACCR_PRIO_HI,
  174.         DMA_DMACCR_FS_DISABLE,
  175.         DMA_DMACCR_SYNC_XEVT2
  176.     ),                              /* DMACCR   */
  177.     DMA_DMACICR_RMK(
  178.         DMA_DMACICR_BLOCKIE_OFF,
  179.         DMA_DMACICR_LASTIE_OFF,
  180.         DMA_DMACICR_FRAMEIE_ON,
  181.         DMA_DMACICR_FIRSTHALFIE_OFF,
  182.         DMA_DMACICR_DROPIE_OFF,
  183.         DMA_DMACICR_TIMEOUTIE_OFF
  184.     ),                              /* DMACICR                          */
  185.     (DMA_AdrPtr)0x0000,             /* DMACSSAL, to be loaded by submit */
  186.     0x0000,                         /* DMACSSAU                         */
  187.     (DMA_AdrPtr)((Uint32)(_MCBSP_DXR12_ADDR<<1)), /* DMACDSAL=MCBSP2 DXR */
  188.     0x0000,                         /* DMACDSAU                         */
  189.     0x0000,                         /* DMACEN                           */
  190.     0x0001,                         /* DMACFN                           */
  191.     0x0000,                         /* DMACFI                           */
  192.     0x0000                          /* DMACEI                           */
  193. };
  194. /*
  195.  * These arrays are used to initialized csdp value for different DMA port
  196.  * type. This is done by mdBindDev using params->dmaPortType
  197.  */
  198. static Uns rxCsdpValue[3] = {
  199.     DMA_DMACSDP_RMK(            /* DSK5510_DMA_AIC23_PORTTYPE_DARAM */
  200.         DMA_DMACSDP_DSTBEN_NOBURST,
  201.         DMA_DMACSDP_DSTPACK_OFF,
  202.         DMA_DMACSDP_DST_DARAM,
  203.         DMA_DMACSDP_SRCBEN_NOBURST,
  204.         DMA_DMACSDP_SRCPACK_OFF,
  205.         DMA_DMACSDP_SRC_PERIPH,
  206.         DMA_DMACSDP_DATATYPE_16BIT
  207.     ),
  208.     DMA_DMACSDP_RMK(            /* DSK5510_DMA_AIC23_PORTTYPE_SARAM */
  209.         DMA_DMACSDP_DSTBEN_NOBURST,
  210.         DMA_DMACSDP_DSTPACK_OFF,
  211.         DMA_DMACSDP_DST_SARAM,
  212.         DMA_DMACSDP_SRCBEN_NOBURST,
  213.         DMA_DMACSDP_SRCPACK_OFF,
  214.         DMA_DMACSDP_SRC_PERIPH,
  215.         DMA_DMACSDP_DATATYPE_16BIT
  216.     ),
  217.     DMA_DMACSDP_RMK(            /* DSK5510_DMA_AIC23_PORTTYPE_EMIF */
  218.         DMA_DMACSDP_DSTBEN_NOBURST,
  219.         DMA_DMACSDP_DSTPACK_OFF,
  220.         DMA_DMACSDP_DST_EMIF,
  221.         DMA_DMACSDP_SRCBEN_NOBURST,
  222.         DMA_DMACSDP_SRCPACK_OFF,
  223.         DMA_DMACSDP_SRC_PERIPH,
  224.         DMA_DMACSDP_DATATYPE_16BIT
  225.     )
  226. };
  227. static Uns txCsdpValue[3] = {
  228.     DMA_DMACSDP_RMK(            /* DSK5510_DMA_AIC23_PORTTYPE_DARAM */
  229.         DMA_DMACSDP_DSTBEN_NOBURST,
  230.         DMA_DMACSDP_DSTPACK_OFF,
  231.         DMA_DMACSDP_DST_PERIPH,
  232.         DMA_DMACSDP_SRCBEN_NOBURST,
  233.         DMA_DMACSDP_SRCPACK_OFF,
  234.         DMA_DMACSDP_SRC_DARAM,
  235.         DMA_DMACSDP_DATATYPE_16BIT
  236.     ),
  237.     DMA_DMACSDP_RMK(            /* DSK5510_DMA_AIC23_PORTTYPE_SARAM */
  238.         DMA_DMACSDP_DSTBEN_NOBURST,
  239.         DMA_DMACSDP_DSTPACK_OFF,
  240.         DMA_DMACSDP_DST_PERIPH,
  241.         DMA_DMACSDP_SRCBEN_NOBURST,
  242.         DMA_DMACSDP_SRCPACK_OFF,
  243.         DMA_DMACSDP_SRC_SARAM,
  244.         DMA_DMACSDP_DATATYPE_16BIT
  245.     ),
  246.     DMA_DMACSDP_RMK(            /* DSK5510_DMA_AIC23_PORTTYPE_EMIF */
  247.         DMA_DMACSDP_DSTBEN_NOBURST,
  248.         DMA_DMACSDP_DSTPACK_OFF,
  249.         DMA_DMACSDP_DST_PERIPH,
  250.         DMA_DMACSDP_SRCBEN_NOBURST,
  251.         DMA_DMACSDP_SRCPACK_OFF,
  252.         DMA_DMACSDP_SRC_EMIF,
  253.         DMA_DMACSDP_DATATYPE_16BIT
  254.     )
  255. };
  256. /*
  257.  *  ======== mdBindDev ========
  258.  */
  259. #pragma CODE_SECTION(mdBindDev, ".text:init")
  260. static Int mdBindDev(Ptr *devp, Int devid, Ptr devParams)
  261. {
  262.     DSK5510_DMA_AIC23_DevParams *params =
  263.         (DSK5510_DMA_AIC23_DevParams *)devParams;
  264.     C55XX_DMA_MCBSP_DevParams genericDevParams;
  265.     DSK5510_DMA_AIC23_DevParams defaultParams = 
  266.                         DSK5510_DMA_AIC23_DEVPARAMS_DEFAULT;
  267.     /* use default parameters if none are given */
  268.     if (params == NULL) {
  269.         params = &defaultParams;
  270.     }
  271.     /* Check the version number */
  272.     if (params->versionId != DSK5510_DMA_AIC23_VERSION_1){
  273.         /* Unsupported version */
  274.         return(IOM_EBADARGS);
  275.     }
  276.     /* set codec parameters (this will also initialize the codec) */
  277.     if (!AIC23_setParams(&(params->aic23))) {
  278.         return(IOM_EBADIO);
  279.     }
  280.     /* set dmacsdp register to the right dma port type */
  281.     dmaRxCfg.dmacsdp = rxCsdpValue[params->dmaPortType];
  282.     dmaTxCfg.dmacsdp = txCsdpValue[params->dmaPortType];
  283.     genericDevParams.versionId = C55XX_DMA_MCBSP_VERSION_1;
  284.     genericDevParams.rxDmaId = params->rxDmaId;
  285.     genericDevParams.txDmaId = params->txDmaId;
  286.     genericDevParams.mcbspCfg = &mcbspCfg2;
  287.     genericDevParams.rxIerMask[0] = params->rxIerMask[0];
  288.     genericDevParams.rxIerMask[1] = params->rxIerMask[1];
  289.     genericDevParams.txIerMask[0] = params->txIerMask[0];
  290.     genericDevParams.txIerMask[1] = params->txIerMask[1];
  291.     
  292.     return (C55XX_DMA_MCBSP_FXNS.mdBindDev(devp, MCBSP_PORT2,
  293.             &genericDevParams));
  294. }
  295. /*
  296.  *  ======== mdCreateChan ========
  297.  */
  298. static Int mdCreateChan(Ptr *chanp, Ptr devp, String name, Int mode,
  299.                 Ptr chanParams, IOM_TiomCallback cbFxn, Ptr cbArg)
  300. {
  301.     C55XX_DMA_MCBSP_ChanParams genericChanParams;
  302.     if (mode == IOM_INPUT) {
  303.         genericChanParams.dmaCfg = &dmaRxCfg;
  304.     }
  305.     else if (mode == IOM_OUTPUT) {
  306.         genericChanParams.dmaCfg = &dmaTxCfg;
  307.     }
  308.     else {
  309.         return (IOM_EBADMODE);
  310.     }
  311.     return (C55XX_DMA_MCBSP_FXNS.mdCreateChan(chanp, devp, name, mode,
  312.         &genericChanParams, cbFxn, cbArg));
  313. }
  314. /*
  315.  *  ======== DSK5510_DMA_AIC23_init ========
  316.  *
  317.  *  Controller initialization function
  318.  */
  319. #pragma CODE_SECTION(DSK5510_DMA_AIC23_init, ".text:init")
  320. Void DSK5510_DMA_AIC23_init(Void)
  321. {
  322.     /*
  323.      * Use C55XX_DMA_MCBSP_FXNS functions for the heart of the 
  324.      * controller.  This is common DMA/MCBSP code that works for
  325.      * many DMA/MCBSP/codec combinations.
  326.      */
  327.     C55XX_DMA_MCBSP_init();
  328.     DSK5510_DMA_AIC23_FXNS = C55XX_DMA_MCBSP_FXNS;
  329.     DSK5510_DMA_AIC23_FXNS.mdBindDev = mdBindDev;
  330.     DSK5510_DMA_AIC23_FXNS.mdCreateChan = mdCreateChan;
  331. }