我用的TMS320C6748 LCDK开发板,目前sd卡的读写没有问题,我想从mcasp回环程序中提取输入的音频保存在sd卡中,应该怎样去实现?下面是我的代码

Cmd_re(int argc, char *argv[])
		FRESULT fresult;UINT ByteWrite;unsigned short parToSend;unsigned short parToLink;int total = 0;/* Set up pin mux for I2C module 0 为I2C模块0设置PINMUX*/I2CPinMuxSetup(0);McASPPinMuxSetup();PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_MCASP0, PSC_POWERDOMAIN_ALWAYS_ON,PSC_MDCTL_NEXT_ENABLE);/* Power up EDMA3CC_0 and EDMA3TC_0  启动EDMA3通道控制器和传输控制器*/PSCModuleControl(SOC_PSC_0_REGS, HW_PSC_CC0, PSC_POWERDOMAIN_ALWAYS_ON,PSC_MDCTL_NEXT_ENABLE);PSCModuleControl(SOC_PSC_0_REGS, HW_PSC_TC0, PSC_POWERDOMAIN_ALWAYS_ON,PSC_MDCTL_NEXT_ENABLE);#ifdef _TMS320C6X// Initialize the DSP interrupt controller 初始化DSP中断控制器IntDSPINTCInit();#else/* Initialize the ARM Interrupt Controller. 初始化ARM中断控制器*/IntAINTCInit();#endif/* Initialize the I2C 0 interface for the codec AIC31* 初始化编解码器AIC31的I2C 0接口*/I2CCodecIfInit(SOC_I2C_0_REGS, INT_CHANNEL_I2C, I2C_SLAVE_CODEC_AIC31);EDMA3Init(SOC_EDMA30CC_0_REGS, 0);EDMA3IntSetup();McASPErrorIntSetup();#ifdef _TMS320C6XIntGlobalEnable();#else/* Enable the interrupts generation at global level* 启动所有级别的中断生成*/IntMasterIRQEnable();IntGlobalEnable();IntIRQEnable();#endif/*** Request EDMA channels. Channel 0 is used for reception and** Channel 1 is used for transmission** 请求EDMA通道,通道0用于接收,通道1用于发送*/EDMA3RequestChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA,EDMA3_CHA_MCASP0_TX, EDMA3_CHA_MCASP0_TX, 0);EDMA3RequestChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA,EDMA3_CHA_MCASP0_RX, EDMA3_CHA_MCASP0_RX, 0);/* Initialize the DMA parameters 初始化DMA参数*/I2SDMAParamInit();/* Configure the Codec for I2S mode 配置I2S模式的编解码器*/AIC31I2SConfigure();/* Configure the McASP for I2S 配置I2S模式的McASP*/McASPI2SConfigure();/* Activate the audio transmission and reception 激活音频发送和接收*/I2SDataTxRxActivate();

	#ifdef MMCSD_PERFunsigned int thrPutRead = 0;unsigned int timeRead = 0;unsigned int ticksRead = 0;unsigned int totalBytesRead = 0;
	#endif/*** First, check to make sure that the current path (CWD), plus the file** name, plus a separator and trailing null, will all fit in the temporary** buffer that will be used to hold the file name.  The file name must be** fully specified, with path, to FatFs.*/if(strlen(g_cCwdBuf) + strlen(argv[1]) + 1 + 1 > sizeof(g_cTmpBuf)){UARTprintf("Resulting path name is too long\n");return(0);}/*** Copy the current path to the temporary buffer so it can be manipulated.*/strcpy(g_cTmpBuf, g_cCwdBuf);/*** If not already at the root level, then append a separator.*/if(strcmp("/", g_cCwdBuf)){strcat(g_cTmpBuf, "/");}/*** Now finally, append the file name to result in a fully specified file.*/strcat(g_cTmpBuf, argv[1]);/*** Open the file for reading.*/fresult = f_open(&g_sFileObject, g_cTmpBuf, (BYTE)FA_WRITE | FA_CREATE_ALWAYS);/*** If there was some problem opening the file, then return an error.*/if(fresult != FR_OK){return(fresult);}while(1){	if(lastFullRxBuf != lastSentTxBuf){/*** Start the transmission from the link paramset. The param set** 1 will be linked to param set at PAR_TX_START. So do not** update paRAM set1.** 从链接参数开始传输,paRAM设置参数1将会链接到PAR_TX_START设置的参数.所以不要将paRAM更新设置1*/parToSend =  PAR_TX_START + (parOffTxToSend % NUM_PAR);parOffTxToSend = (parOffTxToSend + 1) % NUM_PAR;parToLink  = PAR_TX_START + parOffTxToSend;lastSentTxBuf = (lastSentTxBuf + 1) % NUM_BUF;/* Copy the buffer 复制缓冲区*/memcpy((void *)txBufPtr[lastSentTxBuf],(void *)rxBufPtr[lastFullRxBuf],AUDIO_BUF_SIZE);/*** Send the buffer by setting the DMA params accordingly.** 通过设置DMA params来发送缓冲区** Here the buffer to send and number of samples are passed as** parameters. This is important, if only transmit section** is to be used.** 这里要发送的缓冲区和样本数作为参数传递。 这是很重要的,如果只使用传输部分。*/BufferTxDMAActivate(lastSentTxBuf, NUM_SAMPLES_PER_AUDIO_BUF,(unsigned short)parToSend,(unsigned short)parToLink);fresult = f_write(&g_sFileObject, (void *)rxBufPtr[lastFullRxBuf], sizeof((void *)rxBufPtr[lastFullRxBuf]) - 1, &ByteWrite );	if(fresult != FR_OK)	{		UARTprintf("\n");		return(fresult);}total++;if(total >= 15)break;}}UARTprintf("the recording is complete \n");

	#ifdef MMCSD_PERF/*** Print card bus-width, transfer speed.*/UARTPuts("\r\n ************ MMCSD Settings ************ ", -1);UARTPuts("\r\n BUS WIDTH (BIT): ", -1);UARTPutNum((unsigned int) GET_SD_CARD_BUSWIDTH(sdCard));UARTPuts("\r\n TRANSFER SPEED (MHz): ", -1);UARTPutNum((unsigned int) GET_SD_CARD_FRE(sdCard));UARTPuts("\r\n **************************************** \r\n", -1);/*** Compute and print performance for file read.*//* Time read in milliSecs */timeRead = (unsigned int)(ticksRead / (CLK_EXT_CRYSTAL_SPEED / 1000));thrPutRead = ((totalBytesRead / timeRead) * 1000) ;UARTPuts("\r\n ****** MMCSD File Read Performance ***** ", -1);UARTPuts("\r\n READ BUFFER SIZE (BYTES): ", -1);UARTPutNum((unsigned int)DATA_BUF_SIZE);UARTPuts("\r\n TOTAL BYTES TRANSFERRED: ", -1);UARTPutNum((unsigned int)totalBytesRead);UARTPuts("\r\n TIME TAKEN (IN MILLISECS): ", -1);UARTPutNum((unsigned int)(timeRead));UARTPuts("\r\n THROUGHPUT (BYTES / SECS )  : ", -1);UARTPutNum((unsigned int)thrPutRead);UARTPuts("\r\n **************************************** \r\n", -1);
	#endif/*** Close the file.*/fresult = f_close(&g_sFileObject);/*** If there was an error closing, then print a newline and return the** error to the user.*/if(fresult != FR_OK){UARTPuts("\n", -1);return(fresult);}return(0);





未经允许不得转载:TI中文支持网 » mcasp录音保存到sd卡
分享到: 更多 (0)