TI中文支持网
TI专业的中文技术问题搜集分享网站

5509A读取SD卡使能DMA

请问下有相关资料和例程吗?CSL库里面读取SD卡数据都没使能DMA

Shine:

可以参考C:\ti\C55xxCSL\examples\generic5509\csl\dma\dma4,这个例程是McBSP+DMA的。

需要做修改的地方:1. DMA event改成MMC receive event, MMC transmit eventTable 3−4. Synchronization Control Functionhttp://www.ti.com/lit/ds/symlink/tms320vc5509a.pdf2. MMCCTL.DMAEN位使能 

user4731232:

回复 Shine:

非常感谢您的回复,我想问下Serial Port 1 Mode这个是在哪个寄存器里面?我找了两天了都找不到

还有我想问下,retVal = MMC_read(mmc0,0x219a00,datareceive,512);这句话我想读取SD卡这段数据,对于DMA原地址的定义应该如何编写?

Shine:

这个在EBSR寄存器里设置。3.5.1 External Bus Selection Register (EBSR)http://www.ti.com/lit/ds/symlink/tms320vc5509a.pdf 

user4731232:

回复 Shine:

非常感谢您的回答,我想问下,CSL例程读取SD卡程序时应该已经设置了吧?如果没有设置的话他如何读取SD卡的数据呢?

请问下如果没有设置的话我要调用哪个函数来对EBSR进行设置?

Shine:

回复 user4731232:

如果你之前的SD卡程序已经可以读写了,那应该已经是设好了的,你也可以看一下EBSR的值确认。

可以用CHIP_FSET函数设置,也可以直接写代码,如下:#define EBSR            (*(volatile ioport unsigned short*)0x6c00)….EBSR =; 

user4731232:

回复 Shine:

好的,那应该是已经设置好了的,我SD读写的程序是直接拿CSL的例程的

还有我想问下,retVal = MMC_read(mmc0,0x219a00,datareceive,512);这句话,我如何将其应用到DMA的使用中?我想做的是将SD的一段数据取出来放到DARAM中

下面是我的程序

/** Copyright (C) 2003 Texas Instruments Incorporated* All Rights Reserved*/
/**---------main_dma4.c---------* This example places the MCBSP in digital loopback mode and* syncs MCBSP receive with DMA channel 4 and MCBSP transmit* with DMA channel 5.* The example uses predefined CSL macros and symbolic* constants to create the initialization values needed for* the MCBSP and DMA control registers to effect the transfer*/
#include <stdio.h>#include <csl_mmc.h>
#include <csl_mcbsp.h>
#include <csl_dma.h>
#include <csl_irq.h>#define EBSR(*(volatile ioport unsigned short*)0x6c00)#pragma DATA_SECTION(mmc0,"cslmem")
MMC_Handle mmc0;
MMC_CardObj *card, cardalloc;
MMC_CardIdObj *cid, cardid;int count, retVal;
Uint16 rca;
Uint16 cardtype;/* Because of different operating clock frequencies, the Init structure for c5509** and c5509a have different values for memory and function clock divide down values */
#if CHIP_5509AMMC_SetupNative Init = {0,/* Disable DMA for data read/write*/0,/* Set level of edge detection for DAT3 pin*/0,/* Determines if MMC goes IDLE during IDLE instr*/1,/* Memory clk reflected on CLK Pin*/7,/* CPU CLK to MMC function clk divide down*/5,/* MMC function clk to memory clk divide down*/0,/* No. memory clks to wait before response timeout */0,/* No. memory clks to wait before data timeout*/512, /* Block Length must be same as CSD*/};
#elseMMC_SetupNative Init = {0,/* Disable DMA for data read/write*/0,/* Set level of edge detection for DAT3 pin*/0,/* Determines if MMC goes IDLE during IDLE instr*/1,/* Memory clk reflected on CLK Pin*/3,/* CPU CLK to MMC function clk divide down*/3,/* MMC function clk to memory clk divide down*/0,/* No. memory clks to wait before response timeout */0,/* No. memory clks to wait before data timeout*/512, /* Block Length must be same as CSD*/};
#endif/* Read and write buffers */
Uint16 datasend[512];
Uint16 datareceive[512];//---------Global constants---------
#define N128//---------Global data definition---------/* Define transmit and receive buffers */
#pragma DATA_SECTION(xmt,"dmaMem")
Uint16 xmt[N];
#pragma DATA_SECTION(rcv,"dmaMem")
Uint16 rcv[N];MCBSP_Config ConfigLoopBack16= {MCBSP_SPCR1_RMK(MCBSP_SPCR1_DLB_ON,/* DLB= 1 数字回环模式使能*/MCBSP_SPCR1_RJUST_RZF,/* RJUST= 0 接收数据符号扩展和调节方式(左对齐数据和右对齐数据等等)*/MCBSP_SPCR1_CLKSTP_DISABLE,/* CLKSTP = 0 Clock stop mode disable */MCBSP_SPCR1_DXENA_NA,/* DXENA= 0 DX引脚延时使能*/MCBSP_SPCR1_ABIS_DISABLE,/* ABIS= 0 reserved always write 0*/MCBSP_SPCR1_RINTM_RRDY,/* RINTM= 0 接收中断模式(可能需要设置?)*/0,/* RSYNCER = 0 接收帧同步错误标志*/MCBSP_SPCR1_RRST_DISABLE/* RRST= 0 禁止接收器复位*/),MCBSP_SPCR2_RMK(MCBSP_SPCR2_FREE_NO,/* FREE= 0 free run bit, The McBSP transmit and receive clocks are affected as determined by the SOFT bit*/MCBSP_SPCR2_SOFT_NO,/* SOFT= 0 Soft stop bit, Hard stop*/MCBSP_SPCR2_FRST_FSG,/* FRST= 0 帧同步逻辑复位*/MCBSP_SPCR2_GRST_CLKG,/* GRST= 0 采样率发生器复位*/MCBSP_SPCR2_XINTM_XRDY,/* XINTM= 0 发送中断模式(可能需要设置?)*/0,/* XSYNCER = N/A transmit frame-sync error bit, no error*/MCBSP_SPCR2_XRST_DISABLE/* XRST= 0 发送器复位*///注意:开始一定要设置为disable,否则不能设置它的寄存器,全部为默认值,导致不能正常接收,//在程序调用C库函数mcbspstart时会在设为1,McBSP便退出reset状态开始工作),MCBSP_RCR1_RMK(MCBSP_RCR1_RFRLEN1_OF(0),/* RFRLEN1 = 0 接收阶段1的帧长(1-128)个字*/MCBSP_RCR1_RWDLEN1_16BIT/* RWDLEN1 = 5 接收阶段1的字长*/),MCBSP_RCR2_RMK(MCBSP_RCR2_RPHASE_SINGLE,/* RPHASE= 0 接收帧的阶段数*/MCBSP_RCR2_RFRLEN2_OF(0),/* RFRLEN2 = 0 接收阶段2关闭*/MCBSP_RCR2_RWDLEN2_8BIT,/* RWDLEN2 = 0 接收阶段2的字长为8位*/MCBSP_RCR2_RCOMPAND_MSB,/* RCOMPAND = 0 接收数据压扩模式*/MCBSP_RCR2_RFIG_YES,/* RFIG= 0 忽略不期望接收的帧同步信号*/MCBSP_RCR2_RDATDLY_0BIT/* RDATDLY = 0 接收数据不延时*/),MCBSP_XCR1_RMK(MCBSP_XCR1_XFRLEN1_OF(0),/* XFRLEN1 = 0 发送阶段1的帧长(1-128)个字*/MCBSP_XCR1_XWDLEN1_16BIT/* XWDLEN1 = 5 发送阶段1的字长*/),MCBSP_XCR2_RMK(MCBSP_XCR2_XPHASE_SINGLE,/* XPHASE= 0 Transmit phase number bit, single-phase frame*/MCBSP_XCR2_XFRLEN2_OF(0),/* XFRLEN2 = 0 */MCBSP_XCR2_XWDLEN2_8BIT,/* XWDLEN2 = 0 */MCBSP_XCR2_XCOMPAND_MSB,/* XCOMPAND = 0 Transmit companding mode bits, 0, no companding,MSB received first*/MCBSP_XCR2_XFIG_YES,/* XFIG= 0 Transmit frame-sync ignore bit, 1, frame-sync detect*/MCBSP_XCR2_XDATDLY_0BIT/* XDATDLY = 0 Transmit data delay bits*/),MCBSP_SRGR1_RMK(MCBSP_SRGR1_FWID_OF(1),/* FWID= 1 帧同步信号FSG的脉冲宽度*/MCBSP_SRGR1_CLKGDV_OF(1)/* CLKGDV= 1 输出时钟信号CLKG的分频值*/),MCBSP_SRGR2_RMK(MCBSP_SRGR2_GSYNC_FREE,/* FREE= 0 */MCBSP_SRGR2_CLKSP_RISING,/* CLKSP= 0 */MCBSP_SRGR2_CLKSM_INTERNAL,/* CLKSM= 1 */MCBSP_SRGR2_FSGM_DXR2XSR,/* FSGM= 0 */MCBSP_SRGR2_FPER_OF(15)/* FPER= 0 */),MCBSP_MCR1_DEFAULT,//MCR是通道控制器MCBSP_MCR2_DEFAULT,MCBSP_PCR_RMK(MCBSP_PCR_IDLEEN_RESET,/* IDLEEN= 0The McBSP remains active when the PERIPH domain is idled */MCBSP_PCR_XIOEN_SP,/* XIOEN= 0Transmit I/O enable bit, CLKX,FSX,DX,CLKS pins are serial port pins*/MCBSP_PCR_RIOEN_SP,/* RIOEN= 0Receive I/O enable bit, CLKR,FSR,DR,CLKS pins are serial port pins*/MCBSP_PCR_FSXM_INTERNAL,/* FSXM= 1发送帧同步模式:1为由MCBSP提供*/MCBSP_PCR_FSRM_EXTERNAL,/* FSRM= 0接收帧同步模式:0为FSR引脚提供*/MCBSP_PCR_CLKXM_OUTPUT,/* CLKXM= 1Transmit clock mode bit*/MCBSP_PCR_CLKRM_INPUT,/* CLKRM= 0Receive clock mode bit*/MCBSP_PCR_SCLKME_NO,/* SCLKME= 0Sample rate generator input clock mode bit,used with CLKSM to select the input clock*/0,/* DXSTAT = N/A*/MCBSP_PCR_FSXP_ACTIVEHIGH,/* FSXP= 0Transmit frame-sync polarity bit, 0,transmit frame-sync pulses are active high*/MCBSP_PCR_FSRP_ACTIVEHIGH,/* FSRP= 0Receive frame-sync polarity bit, 0,receive frame-sync pulses are active high*/MCBSP_PCR_CLKXP_RISING,/* CLKXP= 0Transmit clock polarity bit,1,transmit data is driven on the rising edge of CLKX*/MCBSP_PCR_CLKRP_FALLING/* CLKRP= 0Receive clock polarity bit*/),MCBSP_RCERA_DEFAULT,//通道使能寄存器MCBSP_RCERB_DEFAULT,MCBSP_RCERC_DEFAULT,MCBSP_RCERD_DEFAULT,MCBSP_RCERE_DEFAULT,MCBSP_RCERF_DEFAULT,MCBSP_RCERG_DEFAULT,MCBSP_RCERH_DEFAULT,MCBSP_XCERA_DEFAULT,MCBSP_XCERB_DEFAULT,MCBSP_XCERC_DEFAULT,MCBSP_XCERD_DEFAULT,MCBSP_XCERE_DEFAULT,MCBSP_XCERF_DEFAULT,MCBSP_XCERG_DEFAULT,MCBSP_XCERH_DEFAULT
};/* Create DMA Receive Side Configuration */
DMA_ConfigdmaRcvConfig = {DMA_DMACSDP_RMK(DMA_DMACSDP_DSTBEN_NOBURST,//Destination burst :-不使用突发DMA_DMACSDP_DSTPACK_OFF,//Destination packing :-目标口禁止打包DMA_DMACSDP_DST_DARAM,//Destination selection :-接收的目标口是DARAM//00 SARAM;01 DARAM;10 EMIF;11 PERIPHDMA_DMACSDP_SRCBEN_NOBURST,//Source burst :-源突发禁止DMA_DMACSDP_SRCPACK_OFF,//Source packing :-源口禁止打包DMA_DMACSDP_SRC_PERIPH,//Source selection :-外设mcbspDMA_DMACSDP_DATATYPE_16BIT//Data type :-设置数据类型16bit字长),/* DMACSDP*/DMA_DMACCR_RMK(DMA_DMACCR_DSTAMODE_POSTINC,//Destination address mode :-自动执行后增量(由于本程序中数据类型是16bit,所以+2)DMA_DMACCR_SRCAMODE_CONST,//Source address mode :-源地址为恒定地址DMA_DMACCR_ENDPROG_ON,//End of programmation bit :-DMA_DMACCR_REPEAT_OFF,//Repeat condition :(AUTOINIT=1)才有效?-0 管编程配置结束位 1 不管编程配置结束位,结束传输自动初始化开始//0:Repeat only if ENDPROG = 1(AUTOINIT=1)DMA_DMACCR_AUTOINIT_OFF,//Auto initialization bit :-DMA_DMACCR_EN_STOP,//Channel enable :-设置时先关闭通道DMA_DMACCR_PRIO_LOW,//Channel priority :-设置为低优先级DMA_DMACCR_FS_DISABLE,//(FS_ELEMENT 单元事件同步)DMA_DMACCR_SYNC_REVT1//Synchronization control bits),/* DMACCR*/DMA_DMACICR_RMK(DMA_DMACICR_BLOCKIE_OFF,//Whole block interrupt enable :-块传输完成后中断不使能DMA_DMACICR_LASTIE_OFF,//Last frame interrupt enable :-DMA_DMACICR_FRAMEIE_ON,//Whole frame interrupt enable :-帧传输完成后中断使能DMA_DMACICR_FIRSTHALFIE_OFF,//Half frame interrupt enable :-DMA_DMACICR_DROPIE_OFF,//Sync. event drop interrupt enable :-DMA_DMACICR_TIMEOUTIE_OFF//Time out interrupt enable :-),/* DMACICR*/(DMA_AdrPtr)(MCBSP_ADDR(DRR11)),/* DMACSSAL 源地址低位*/0,/* DMACSSAU 源地址高位*/(DMA_AdrPtr)&rcv,/* DMACDSAL 目的地址低位*/0,/* DMACDSAU 目的地址高位*/N,/* DMACEN1帧内数据长度 N个数据一个帧*/1,/* DMACFN帧数大小*/0,/* DMACFI*/0/* DMACEI*/};/* Create DMA Transmit Side Configuration */
DMA_ConfigdmaXmtConfig = {DMA_DMACSDP_RMK(DMA_DMACSDP_DSTBEN_NOBURST,DMA_DMACSDP_DSTPACK_OFF,DMA_DMACSDP_DST_PERIPH,//Destination selection :-外设mcbspDMA_DMACSDP_SRCBEN_NOBURST,DMA_DMACSDP_SRCPACK_OFF,DMA_DMACSDP_SRC_DARAM,//Source selection :DARAMDMA_DMACSDP_DATATYPE_16BIT),/* DMACSDP*/DMA_DMACCR_RMK(DMA_DMACCR_DSTAMODE_CONST,//Destination address mode :-恒定地址DMA_DMACCR_SRCAMODE_POSTINC,//Source address mode :-自动执行后增量(由于本程序中数据类型是16bit,所以+2DMA_DMACCR_ENDPROG_ON,DMA_DMACCR_REPEAT_OFF,DMA_DMACCR_AUTOINIT_OFF,DMA_DMACCR_EN_STOP,DMA_DMACCR_PRIO_LOW,DMA_DMACCR_FS_DISABLE,DMA_DMACCR_SYNC_XEVT1//Synchronization control bits),/* DMACCR*/DMA_DMACICR_RMK(DMA_DMACICR_BLOCKIE_OFF,DMA_DMACICR_LASTIE_OFF,DMA_DMACICR_FRAMEIE_ON,DMA_DMACICR_FIRSTHALFIE_OFF,DMA_DMACICR_DROPIE_OFF,DMA_DMACICR_TIMEOUTIE_OFF),/* DMACICR*/(DMA_AdrPtr)&xmt[1],/* DMACSSAL */0,/* DMACSSAU */(DMA_AdrPtr)(MCBSP_ADDR(DXR11)),/* DMACDSAL */0,/* DMACDSAU */N,/* DMACEN*/1,/* DMACFN*/0,/* DMACFI*/0/* DMACEI*/
};/* Define a DMA_Handle object to be used with DMA_open function */
DMA_Handle hDmaRcv, hDmaXmt;/* Define a MCBSP_Handle object to be used with MCBSP_open function */
MCBSP_Handle hMcbsp;volatile Uint16 transferComplete = FALSE;
Uint16 err = 0;
Uint16 old_intm;
Uint16 xmtEventId, rcvEventId;//---------Function prototypes---------
/* Reference start of interrupt vector table*/
/* This symbol is defined in file, vectors.s55 */
extern void VECSTART(void);/* Protoype for interrupt functions */
interrupt void dmaXmtIsr(void);
interrupt void dmaRcvIsr(void);
void taskFxn(void);//---------main routine---------
void main(void)
{Uint16 i;/* Initialize CSL library - This is REQUIRED !!! */CSL_init();/* Set IVPD/IVPH to start of interrupt vector table */IRQ_setVecs((Uint32)(&VECSTART));for (i = 0; i <= N - 1; i++) {xmt[i] =i + 1;rcv[i] = 0;}printf ("\nMMC Single block read-write test\n");for (count=0;count<=256;count++){datasend[count]= count;datareceive[count] = 0xFFFF;}/* A detailed explanation of MMC initialization is provided in mmc_setup example */mmc0 = MMC_open(MMC_DEV1);MMC_setupNative(mmc0,&Init);MMC_sendGoIdle(mmc0);for (count=0;count<4016;count++)asm("	NOP");cardtype = MMC_sendOpCond(mmc0,0x00100000);if (cardtype == MMC_CARD){cid = &cardid;MMC_sendAllCID(mmc0,cid); // get the CID structure for all cards.rca = 10;card = &cardalloc;retVal = MMC_setRca(mmc0,card,rca);} else {cid = &cardid;SD_sendAllCID(mmc0,cid); // get the CID structure for all cards.card = &cardalloc;rca = SD_sendRca(mmc0,card);printf ("RCA sent by the SD card is 0x%x\n", rca);}/* Select the card to transfer data to/from. This step puts the card into the ** transfer state where it is ready to read/write data*/retVal = MMC_selectCard(mmc0,card);printf ("Reading data from card...\n");retVal = MMC_read(mmc0,0x219a00,datareceive,512);for (count = 0; count < 6000; ++count);printf ("TEST PASSED\n");/* Call function to effect transfer */taskFxn();
}void taskFxn(void)
{Uint16 srcAddrHi, srcAddrLo;Uint16 dstAddrHi, dstAddrLo;Uint16 i;/* By default, the TMS320C55xx compiler assigns all data symbols word *//* addresses. The DMA however, expects all addresses to be byte*//* addresses. Therefore, we must shift the address by 2 in order to*//* change the word address to a byte address for the DMA transfer.*/srcAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DRR11))) >> 15) & 0xFFFFu;srcAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DRR11))) << 1) & 0xFFFFu;dstAddrHi = (Uint16)(((Uint32)(&rcv)) >> 15) & 0xFFFFu;dstAddrLo = (Uint16)(((Uint32)(&rcv)) << 1) & 0xFFFFu;dmaRcvConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;dmaRcvConfig.dmacssau = srcAddrHi;dmaRcvConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;dmaRcvConfig.dmacdsau = dstAddrHi;srcAddrHi = (Uint16)(((Uint32)(&xmt[0])) >> 15) & 0xFFFFu;srcAddrLo = (Uint16)(((Uint32)(&xmt[0])) << 1) & 0xFFFFu;dstAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DXR11))) >> 15) & 0xFFFFu;dstAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DXR11))) << 1) & 0xFFFFu;dmaXmtConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;dmaXmtConfig.dmacssau = srcAddrHi;dmaXmtConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;dmaXmtConfig.dmacdsau = dstAddrHi;/* Open MCBSP Port 1 and set registers to their power on defaults */hMcbsp = MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET);/* Open DMA channels 4 & 5 and set regs to power on defaults */hDmaRcv = DMA_open(DMA_CHA4,DMA_OPEN_RESET);hDmaXmt = DMA_open(DMA_CHA5,DMA_OPEN_RESET);/* Get interrupt event associated with DMA receive and transmit */xmtEventId = DMA_getEventId(hDmaXmt);rcvEventId = DMA_getEventId(hDmaRcv);/* Temporarily disable interrupts and clear any pending *//* interrupts for MCBSP transmit */old_intm = IRQ_globalDisable();/* Clear any pending interrupts for DMA channels */IRQ_clear(xmtEventId);IRQ_clear(rcvEventId);/* Enable DMA interrupt in IER register */IRQ_enable(xmtEventId);IRQ_enable(rcvEventId);/* Set Start Of Interrupt Vector Table */IRQ_setVecs(0x10000);/* Place DMA interrupt service addresses at associate vector */IRQ_plug(xmtEventId,&dmaXmtIsr);IRQ_plug(rcvEventId,&dmaRcvIsr);/* Write values from configuration structure to MCBSP control regs */MCBSP_config(hMcbsp, &ConfigLoopBack16);/* Write values from configuration structure to DMA control regs */DMA_config(hDmaRcv,&dmaRcvConfig);DMA_config(hDmaXmt,&dmaXmtConfig);#if 0/* Take MCBSP transmit and receive out of reset */MCBSP_start(hMcbsp,MCBSP_XMIT_START | MCBSP_RCV_START,0u);/* Prime MCBSP DXR */while (!(MCBSP_xrdy(hMcbsp))){;}MCBSP_write16(hMcbsp,xmt[0]);/* Enable all maskable interrupts */IRQ_globalEnable();/* Enable DMA */DMA_start(hDmaRcv);DMA_start(hDmaXmt);/* Start Sample Rate Generator and Enable Frame Sync */MCBSP_start(hMcbsp,MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC,0x300u);
#else/* Enable all maskable interrupts */IRQ_globalEnable();/* Start Sample Rate Generator and Enable Frame Sync */MCBSP_start(hMcbsp,MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC,0x300u);/* Enable DMA */DMA_start(hDmaRcv);DMA_start(hDmaXmt);/* Take MCBSP transmit and receive out of reset */MCBSP_start(hMcbsp,MCBSP_XMIT_START | MCBSP_RCV_START,0u);
#endif/* Wait for DMA transfer to be complete */while (!transferComplete){;}/*------------------------------------------*\* Compare values\*------------------------------------------*/for(i = 0; i <= N - 1; i++){if (rcv[i] != xmt[i]){++err;break;}}printf ("%s\n",err?"TEST FAILED" : "TEST PASSED");/* Restore status of global interrupt enable flag */IRQ_globalRestore(old_intm);/* We're done with MCBSP and DMA , so close them */MCBSP_close(hMcbsp);DMA_close(hDmaRcv);DMA_close(hDmaXmt);
}interrupt void dmaXmtIsr(void) {DMA_stop(hDmaXmt);IRQ_disable(xmtEventId);
}interrupt void dmaRcvIsr(void) {DMA_stop(hDmaRcv);IRQ_disable(rcvEventId);transferComplete = TRUE;
}

/* * Copyright (C) 2003 Texas Instruments Incorporated * All Rights Reserved *//* *———main_dma4.c——— * This example places the MCBSP in digital loopback mode and * syncs MCBSP receive with DMA channel 4 and MCBSP transmit * with DMA channel 5. * The example uses predefined CSL macros and symbolic * constants to create the initialization values needed for * the MCBSP and DMA control registers to effect the transfer */#include <stdio.h>

#include <csl_mmc.h>#include <csl_mcbsp.h>#include <csl_dma.h>#include <csl_irq.h>

#define EBSR            (*(volatile ioport unsigned short*)0x6c00)

#pragma DATA_SECTION(mmc0,"cslmem")MMC_Handle mmc0;MMC_CardObj *card, cardalloc;MMC_CardIdObj *cid, cardid;

int count, retVal;Uint16 rca;Uint16 cardtype;

/* Because of different operating clock frequencies, the Init structure for c5509    * * and c5509a have different values for memory and function clock divide down values */#if CHIP_5509A  MMC_SetupNative Init = {    0,   /* Disable DMA for data read/write                 */    0,   /* Set level of edge detection for DAT3 pin        */    0,   /* Determines if MMC goes IDLE during IDLE instr   */    1,   /* Memory clk reflected on CLK Pin                 */    7,   /* CPU CLK to MMC function clk divide down         */    5,   /* MMC function clk to memory clk divide down      */    0,   /* No. memory clks to wait before response timeout */    0,   /* No. memory clks to wait before data timeout     */    512, /* Block Length must be same as CSD                */  };#else  MMC_SetupNative Init = {    0,   /* Disable DMA for data read/write                 */    0,   /* Set level of edge detection for DAT3 pin        */    0,   /* Determines if MMC goes IDLE during IDLE instr   */    1,   /* Memory clk reflected on CLK Pin                 */    3,   /* CPU CLK to MMC function clk divide down         */    3,   /* MMC function clk to memory clk divide down      */    0,   /* No. memory clks to wait before response timeout */    0,   /* No. memory clks to wait before data timeout     */    512, /* Block Length must be same as CSD                */  };#endif

/* Read and write buffers */Uint16 datasend[512];Uint16 datareceive[512];

//———Global constants———#define N       128

//———Global data definition———

/* Define transmit and receive buffers */#pragma DATA_SECTION(xmt,"dmaMem")Uint16 xmt[N];#pragma DATA_SECTION(rcv,"dmaMem")Uint16 rcv[N];

  MCBSP_Config ConfigLoopBack16= {  MCBSP_SPCR1_RMK(    MCBSP_SPCR1_DLB_ON,                    /* DLB    = 1 数字回环模式使能*/    MCBSP_SPCR1_RJUST_RZF,                 /* RJUST  = 0 接收数据符号扩展和调节方式(左对齐数据和右对齐数据等等)*/    MCBSP_SPCR1_CLKSTP_DISABLE,            /* CLKSTP = 0 Clock stop mode disable */    MCBSP_SPCR1_DXENA_NA,                  /* DXENA  = 0 DX引脚延时使能*/    MCBSP_SPCR1_ABIS_DISABLE,              /* ABIS   = 0 reserved always write 0*/    MCBSP_SPCR1_RINTM_RRDY,                /* RINTM  = 0 接收中断模式(可能需要设置?)*/    0,                                     /* RSYNCER = 0 接收帧同步错误标志*/    MCBSP_SPCR1_RRST_DISABLE               /* RRST   = 0 禁止接收器复位*/   ),    MCBSP_SPCR2_RMK(    MCBSP_SPCR2_FREE_NO,                   /* FREE   = 0 free run bit, The McBSP transmit and receive clocks are affected as determined by the SOFT bit*/    MCBSP_SPCR2_SOFT_NO,                   /* SOFT   = 0 Soft stop bit, Hard stop*/    MCBSP_SPCR2_FRST_FSG,                  /* FRST   = 0 帧同步逻辑复位*/    MCBSP_SPCR2_GRST_CLKG,                 /* GRST   = 0 采样率发生器复位*/    MCBSP_SPCR2_XINTM_XRDY,                /* XINTM  = 0 发送中断模式(可能需要设置?)*/    0,                                     /* XSYNCER = N/A transmit frame-sync error bit, no error*/    MCBSP_SPCR2_XRST_DISABLE               /* XRST   = 0 发送器复位*/    //注意:开始一定要设置为disable,否则不能设置它的寄存器,全部为默认值,导致不能正常接收,

    //在程序调用C库函数mcbspstart时会在设为1,McBSP便退出reset状态开始工作

   ),  MCBSP_RCR1_RMK(  MCBSP_RCR1_RFRLEN1_OF(0),                /* RFRLEN1 = 0 接收阶段1的帧长(1-128)个字*/  MCBSP_RCR1_RWDLEN1_16BIT                 /* RWDLEN1 = 5 接收阶段1的字长*/  ), MCBSP_RCR2_RMK(    MCBSP_RCR2_RPHASE_SINGLE,              /* RPHASE  = 0 接收帧的阶段数*/    MCBSP_RCR2_RFRLEN2_OF(0),              /* RFRLEN2 = 0 接收阶段2关闭*/    MCBSP_RCR2_RWDLEN2_8BIT,               /* RWDLEN2 = 0 接收阶段2的字长为8位*/    MCBSP_RCR2_RCOMPAND_MSB,               /* RCOMPAND = 0 接收数据压扩模式*/    MCBSP_RCR2_RFIG_YES,                   /* RFIG    = 0 忽略不期望接收的帧同步信号*/    MCBSP_RCR2_RDATDLY_0BIT                /* RDATDLY = 0 接收数据不延时*/    ),   MCBSP_XCR1_RMK(    MCBSP_XCR1_XFRLEN1_OF(0),              /* XFRLEN1 = 0 发送阶段1的帧长(1-128)个字*/    MCBSP_XCR1_XWDLEN1_16BIT               /* XWDLEN1 = 5 发送阶段1的字长*/

 ), MCBSP_XCR2_RMK(    MCBSP_XCR2_XPHASE_SINGLE,              /* XPHASE  = 0 Transmit phase number bit, single-phase frame*/    MCBSP_XCR2_XFRLEN2_OF(0),              /* XFRLEN2 = 0 */    MCBSP_XCR2_XWDLEN2_8BIT,               /* XWDLEN2 = 0 */    MCBSP_XCR2_XCOMPAND_MSB,               /* XCOMPAND = 0 Transmit companding mode bits, 0, no companding,MSB received first*/    MCBSP_XCR2_XFIG_YES,                   /* XFIG    = 0 Transmit frame-sync ignore bit, 1, frame-sync detect*/    MCBSP_XCR2_XDATDLY_0BIT                /* XDATDLY = 0 Transmit data delay bits*/  ), MCBSP_SRGR1_RMK(   MCBSP_SRGR1_FWID_OF(1),                /* FWID    = 1 帧同步信号FSG的脉冲宽度*/   MCBSP_SRGR1_CLKGDV_OF(1)               /* CLKGDV  = 1 输出时钟信号CLKG的分频值*/ ), MCBSP_SRGR2_RMK(    MCBSP_SRGR2_GSYNC_FREE,                /* FREE    = 0 */    MCBSP_SRGR2_CLKSP_RISING,              /* CLKSP   = 0 */    MCBSP_SRGR2_CLKSM_INTERNAL,            /* CLKSM   = 1 */    MCBSP_SRGR2_FSGM_DXR2XSR,              /* FSGM    = 0 */    MCBSP_SRGR2_FPER_OF(15)                /* FPER    = 0 */ ), MCBSP_MCR1_DEFAULT,      //MCR是通道控制器 MCBSP_MCR2_DEFAULT, MCBSP_PCR_RMK(   MCBSP_PCR_IDLEEN_RESET,                 /* IDLEEN   = 0   The McBSP remains active when the PERIPH domain is idled */   MCBSP_PCR_XIOEN_SP,                     /* XIOEN    = 0   Transmit I/O enable bit, CLKX,FSX,DX,CLKS pins are serial port pins*/   MCBSP_PCR_RIOEN_SP,                     /* RIOEN    = 0   Receive I/O enable bit, CLKR,FSR,DR,CLKS pins are serial port pins*/   MCBSP_PCR_FSXM_INTERNAL,                /* FSXM     = 1   发送帧同步模式:1为由MCBSP提供*/   MCBSP_PCR_FSRM_EXTERNAL,                /* FSRM     = 0   接收帧同步模式:0为FSR引脚提供*/   MCBSP_PCR_CLKXM_OUTPUT,                 /* CLKXM    = 1   Transmit clock mode bit*/   MCBSP_PCR_CLKRM_INPUT,                  /* CLKRM    = 0   Receive clock mode bit*/   MCBSP_PCR_SCLKME_NO,                    /* SCLKME   = 0   Sample rate generator input clock mode bit,used with CLKSM to select the input clock*/   0,                                      /* DXSTAT = N/A   */   MCBSP_PCR_FSXP_ACTIVEHIGH,              /* FSXP     = 0   Transmit frame-sync polarity bit, 0,transmit frame-sync pulses are active high*/   MCBSP_PCR_FSRP_ACTIVEHIGH,              /* FSRP     = 0   Receive frame-sync polarity bit, 0,receive frame-sync pulses are active high*/   MCBSP_PCR_CLKXP_RISING,                 /* CLKXP    = 0   Transmit clock polarity bit,1,transmit data is driven on the rising edge of CLKX*/   MCBSP_PCR_CLKRP_FALLING                 /* CLKRP    = 0   Receive clock polarity bit*/ ), MCBSP_RCERA_DEFAULT,      //通道使能寄存器 MCBSP_RCERB_DEFAULT, MCBSP_RCERC_DEFAULT, MCBSP_RCERD_DEFAULT, MCBSP_RCERE_DEFAULT, MCBSP_RCERF_DEFAULT, MCBSP_RCERG_DEFAULT, MCBSP_RCERH_DEFAULT, MCBSP_XCERA_DEFAULT, MCBSP_XCERB_DEFAULT, MCBSP_XCERC_DEFAULT, MCBSP_XCERD_DEFAULT, MCBSP_XCERE_DEFAULT, MCBSP_XCERF_DEFAULT, MCBSP_XCERG_DEFAULT, MCBSP_XCERH_DEFAULT};

/* Create DMA Receive Side Configuration */DMA_Config  dmaRcvConfig = {  DMA_DMACSDP_RMK(    DMA_DMACSDP_DSTBEN_NOBURST,    //Destination burst :-不使用突发    DMA_DMACSDP_DSTPACK_OFF,    //Destination packing :-目标口禁止打包    DMA_DMACSDP_DST_DARAM,     //Destination selection :-接收的目标口是DARAM //00 SARAM;01 DARAM;10 EMIF;11 PERIPH    DMA_DMACSDP_SRCBEN_NOBURST,    //Source burst :-源突发禁止    DMA_DMACSDP_SRCPACK_OFF,    //Source packing :-源口禁止打包    DMA_DMACSDP_SRC_PERIPH,     //Source selection :-外设mcbsp    DMA_DMACSDP_DATATYPE_16BIT     //Data type :-设置数据类型16bit字长  ),                                       /* DMACSDP  */  DMA_DMACCR_RMK(    DMA_DMACCR_DSTAMODE_POSTINC,   //Destination address mode :-自动执行后增量(由于本程序中数据类型是16bit,所以+2)    DMA_DMACCR_SRCAMODE_CONST,    //Source address mode :-源地址为恒定地址    DMA_DMACCR_ENDPROG_ON,     //End of programmation bit :-    DMA_DMACCR_REPEAT_OFF,     //Repeat condition :(AUTOINIT=1)才有效?-0 管编程配置结束位 1 不管编程配置结束位,结束传输自动初始化开始           //0:Repeat only if ENDPROG = 1(AUTOINIT=1)    DMA_DMACCR_AUTOINIT_OFF,    //Auto initialization bit :-    DMA_DMACCR_EN_STOP,      //Channel enable :-设置时先关闭通道    DMA_DMACCR_PRIO_LOW,     //Channel priority :-设置为低优先级    DMA_DMACCR_FS_DISABLE,     //(FS_ELEMENT 单元事件同步)    DMA_DMACCR_SYNC_REVT1     //Synchronization control bits  ),                                       /* DMACCR   */  DMA_DMACICR_RMK(    DMA_DMACICR_BLOCKIE_OFF,    //Whole block interrupt enable :-块传输完成后中断不使能    DMA_DMACICR_LASTIE_OFF,     //Last frame interrupt enable :-    DMA_DMACICR_FRAMEIE_ON,     //Whole frame interrupt enable :-帧传输完成后中断使能    DMA_DMACICR_FIRSTHALFIE_OFF,   //Half frame interrupt enable :-    DMA_DMACICR_DROPIE_OFF,     //Sync. event drop interrupt enable :-    DMA_DMACICR_TIMEOUTIE_OFF    //Time out interrupt enable :-  ),                                       /* DMACICR  */    (DMA_AdrPtr)(MCBSP_ADDR(DRR11)),        /* DMACSSAL 源地址低位*/    0,                                     /* DMACSSAU 源地址高位*/    (DMA_AdrPtr)&rcv,                      /* DMACDSAL 目的地址低位*/    0,                                     /* DMACDSAU 目的地址高位*/    N,                                     /* DMACEN   1帧内数据长度 N个数据一个帧*/    1,                                     /* DMACFN   帧数大小*/    0,                                     /* DMACFI  */    0                                      /* DMACEI  */  };

/* Create DMA Transmit Side Configuration */DMA_Config  dmaXmtConfig = {  DMA_DMACSDP_RMK(    DMA_DMACSDP_DSTBEN_NOBURST,    DMA_DMACSDP_DSTPACK_OFF,    DMA_DMACSDP_DST_PERIPH,     //Destination selection :-外设mcbsp    DMA_DMACSDP_SRCBEN_NOBURST,    DMA_DMACSDP_SRCPACK_OFF,    DMA_DMACSDP_SRC_DARAM,     //Source selection :DARAM    DMA_DMACSDP_DATATYPE_16BIT  ),                                       /* DMACSDP  */  DMA_DMACCR_RMK(    DMA_DMACCR_DSTAMODE_CONST,    //Destination address mode :-恒定地址    DMA_DMACCR_SRCAMODE_POSTINC,   //Source address mode :-自动执行后增量(由于本程序中数据类型是16bit,所以+2    DMA_DMACCR_ENDPROG_ON,    DMA_DMACCR_REPEAT_OFF,    DMA_DMACCR_AUTOINIT_OFF,    DMA_DMACCR_EN_STOP,    DMA_DMACCR_PRIO_LOW,    DMA_DMACCR_FS_DISABLE,    DMA_DMACCR_SYNC_XEVT1     //Synchronization control bits  ),                                       /* DMACCR   */  DMA_DMACICR_RMK(    DMA_DMACICR_BLOCKIE_OFF,    DMA_DMACICR_LASTIE_OFF,    DMA_DMACICR_FRAMEIE_ON,    DMA_DMACICR_FIRSTHALFIE_OFF,    DMA_DMACICR_DROPIE_OFF,    DMA_DMACICR_TIMEOUTIE_OFF  ),                                       /* DMACICR  */    (DMA_AdrPtr)&xmt[1],                   /* DMACSSAL */    0,                                     /* DMACSSAU */    (DMA_AdrPtr)(MCBSP_ADDR(DXR11)),       /* DMACDSAL */    0,                                     /* DMACDSAU */    N,                                     /* DMACEN   */    1,                                     /* DMACFN   */    0,                                     /* DMACFI   */    0                                      /* DMACEI   */};

/* Define a DMA_Handle object to be used with DMA_open function */DMA_Handle hDmaRcv, hDmaXmt;

/* Define a MCBSP_Handle object to be used with MCBSP_open function */MCBSP_Handle hMcbsp;

volatile Uint16 transferComplete = FALSE;Uint16 err = 0;Uint16 old_intm;Uint16 xmtEventId, rcvEventId;

//———Function prototypes———/* Reference start of interrupt vector table   *//* This symbol is defined in file, vectors.s55 */extern void VECSTART(void);

/* Protoype for interrupt functions */interrupt void dmaXmtIsr(void);interrupt void dmaRcvIsr(void);void taskFxn(void);

//———main routine———void main(void){    Uint16 i;

    /* Initialize CSL library – This is REQUIRED !!! */    CSL_init();

    /* Set IVPD/IVPH to start of interrupt vector table */    IRQ_setVecs((Uint32)(&VECSTART));

    for (i = 0; i <= N – 1; i++) {        xmt[i] =  i + 1;        rcv[i] = 0;    }

    printf ("\nMMC Single block read-write test\n");

    for (count=0;count<=256;count++){        datasend[count]    = count;        datareceive[count] = 0xFFFF;    }

    /* A detailed explanation of MMC initialization is provided in mmc_setup example */    mmc0 = MMC_open(MMC_DEV1);    MMC_setupNative(mmc0,&Init);

    MMC_sendGoIdle(mmc0);    for (count=0;count<4016;count++)     asm(" NOP");

    cardtype = MMC_sendOpCond(mmc0,0x00100000);

    if (cardtype == MMC_CARD){       cid = &cardid;       MMC_sendAllCID(mmc0,cid); // get the CID structure for all cards.       rca = 10;       card = &cardalloc;       retVal = MMC_setRca(mmc0,card,rca);    } else {       cid = &cardid;       SD_sendAllCID(mmc0,cid); // get the CID structure for all cards.       card = &cardalloc;       rca = SD_sendRca(mmc0,card);       printf ("RCA sent by the SD card is 0x%x\n", rca);    }

    /* Select the card to transfer data to/from. This step puts the card into the *     * transfer state where it is ready to read/write data                        */

    retVal = MMC_selectCard(mmc0,card);

    printf ("Reading data from card…\n");    retVal = MMC_read(mmc0,0x219a00,datareceive,512);    for (count = 0; count < 6000; ++count);

    printf ("TEST PASSED\n");

    /* Call function to effect transfer */    taskFxn();}

void taskFxn(void){    Uint16 srcAddrHi, srcAddrLo;    Uint16 dstAddrHi, dstAddrLo;    Uint16 i;

    /* By default, the TMS320C55xx compiler assigns all data symbols word */    /* addresses. The DMA however, expects all addresses to be byte       */    /* addresses. Therefore, we must shift the address by 2 in order to   */    /* change the word address to a byte address for the DMA transfer.    */    srcAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DRR11))) >> 15) & 0xFFFFu;    srcAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DRR11))) << 1) & 0xFFFFu;    dstAddrHi = (Uint16)(((Uint32)(&rcv)) >> 15) & 0xFFFFu;    dstAddrLo = (Uint16)(((Uint32)(&rcv)) << 1) & 0xFFFFu;

    dmaRcvConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;    dmaRcvConfig.dmacssau = srcAddrHi;    dmaRcvConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;    dmaRcvConfig.dmacdsau = dstAddrHi;

    srcAddrHi = (Uint16)(((Uint32)(&xmt[0])) >> 15) & 0xFFFFu;    srcAddrLo = (Uint16)(((Uint32)(&xmt[0])) << 1) & 0xFFFFu;    dstAddrHi = (Uint16)(((Uint32)(MCBSP_ADDR(DXR11))) >> 15) & 0xFFFFu;    dstAddrLo = (Uint16)(((Uint32)(MCBSP_ADDR(DXR11))) << 1) & 0xFFFFu;

    dmaXmtConfig.dmacssal = (DMA_AdrPtr)srcAddrLo;    dmaXmtConfig.dmacssau = srcAddrHi;    dmaXmtConfig.dmacdsal = (DMA_AdrPtr)dstAddrLo;    dmaXmtConfig.dmacdsau = dstAddrHi;

    /* Open MCBSP Port 1 and set registers to their power on defaults */    hMcbsp = MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET);

    /* Open DMA channels 4 & 5 and set regs to power on defaults */    hDmaRcv = DMA_open(DMA_CHA4,DMA_OPEN_RESET);    hDmaXmt = DMA_open(DMA_CHA5,DMA_OPEN_RESET);

    /* Get interrupt event associated with DMA receive and transmit */    xmtEventId = DMA_getEventId(hDmaXmt);    rcvEventId = DMA_getEventId(hDmaRcv);

    /* Temporarily disable interrupts and clear any pending */    /* interrupts for MCBSP transmit */    old_intm = IRQ_globalDisable();

    /* Clear any pending interrupts for DMA channels */    IRQ_clear(xmtEventId);    IRQ_clear(rcvEventId);

    /* Enable DMA interrupt in IER register */    IRQ_enable(xmtEventId);    IRQ_enable(rcvEventId);

    /* Set Start Of Interrupt Vector Table */    IRQ_setVecs(0x10000);

    /* Place DMA interrupt service addresses at associate vector */    IRQ_plug(xmtEventId,&dmaXmtIsr);    IRQ_plug(rcvEventId,&dmaRcvIsr);

    /* Write values from configuration structure to MCBSP control regs */    MCBSP_config(hMcbsp, &ConfigLoopBack16);

    /* Write values from configuration structure to DMA control regs */    DMA_config(hDmaRcv,&dmaRcvConfig);    DMA_config(hDmaXmt,&dmaXmtConfig);

#if 0    /* Take MCBSP transmit and receive out of reset */    MCBSP_start(hMcbsp,                MCBSP_XMIT_START | MCBSP_RCV_START,                0u);

    /* Prime MCBSP DXR */    while (!(MCBSP_xrdy(hMcbsp))){      ;    }    MCBSP_write16(hMcbsp,xmt[0]);

   /* Enable all maskable interrupts */    IRQ_globalEnable();

    /* Enable DMA */    DMA_start(hDmaRcv);    DMA_start(hDmaXmt);

    /* Start Sample Rate Generator and Enable Frame Sync */    MCBSP_start(hMcbsp,                MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC,                0x300u);#else /* Enable all maskable interrupts */    IRQ_globalEnable();

    /* Start Sample Rate Generator and Enable Frame Sync */    MCBSP_start(hMcbsp,                MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC,                0x300u);

    /* Enable DMA */    DMA_start(hDmaRcv);    DMA_start(hDmaXmt);

    /* Take MCBSP transmit and receive out of reset */    MCBSP_start(hMcbsp,                MCBSP_XMIT_START | MCBSP_RCV_START,                0u);#endif    /* Wait for DMA transfer to be complete */    while (!transferComplete){        ;    }

    /*——————————————*\     * Compare values    \*——————————————*/    for(i = 0; i <= N – 1; i++){        if (rcv[i] != xmt[i]){            ++err;            break;       }    }

    printf ("%s\n",err?"TEST FAILED" : "TEST PASSED");

    /* Restore status of global interrupt enable flag */    IRQ_globalRestore(old_intm);

    /* We're done with MCBSP and DMA , so close them */    MCBSP_close(hMcbsp);    DMA_close(hDmaRcv);    DMA_close(hDmaXmt);}

interrupt void dmaXmtIsr(void) {   DMA_stop(hDmaXmt);   IRQ_disable(xmtEventId);}

interrupt void dmaRcvIsr(void) {   DMA_stop(hDmaRcv);   IRQ_disable(rcvEventId);   transferComplete = TRUE;}

user4731232:

回复 Shine:

感谢您的回答,还有我想问下retVal = MMC_read(mmc0,0x219a00,datareceive,512);这句读取SD的程序,我如何更改DMA和MCBSP的设置?我看了下关于MCBSP读SD卡的说明,貌似还要发命令什么的,我上一条回复贴上了我的代码,但是提示说需要等待版主通过才行

赞(0)
未经允许不得转载:TI中文支持网 » 5509A读取SD卡使能DMA
分享到: 更多 (0)