Hi
I am evaluating the C5515 EVM board now. What I need to do is to use the codec AIC3204 to record audio data to SD card, and play back the audio.
I installed CCS4.1 and downloaded the latest CSL library: TMS320C55XXCSL-LOWPWR-2.10.00.00-Setup.exe. And I can run the following demos properly:
1. "CSL_MMCSD_SdCardFSExample_Out" .
2. "aic3204" under "C:\Program Files\Texas Instruments\ccsv4\emulation\boards\evm5515_v1\tests\aic3204"
I tried to merge the aic3204 code into the project SdCardFSExample to realize it. I changed the aic3204 example to record the audio to the external SDRAM and play back, it works fine. And then I want to save the audio in SDRAM to a file in SD Card, and read the file and send to the codec to play the audio. But the file has all 0x00s. And I got error message “ATA_readLittleEndian Failed”. I do not know why? Could anyone tell me how to use ATA file system interface?
I would like to post part of the code I changed here, mostly same as the demo below, thanks.
#define DEBUG_RAM_SAVE_TONE
#ifdef DEBUG_RAM_SAVE_TONE
#define DEBUG_RAM_ADDRESS 0x100000ul
Uint32 debug_ram_for_sd_addr;
#endif
AtaError MountMmcDrive(void)
{
AtaError ata_error;
unsigned int diskType;
ata_error = ATA_ERROR_NONE;
/* Call init function initialize ATA state structure */
gpstrAtaDrive->AtaInitAtaMediaState = (AtaError (*)(void *))MMC_initState;
gpstrAtaMMCState->hMmcSd = mmcsdHandle;
gpstrAtaDrive->pAtaMediaState = gpstrAtaMMCState;
gpstrAtaDrive->AtaInitAtaMediaState(gpstrAtaDrive);
/* For partitioned disk, 'diskType' should be 0
and for unpartiotioned disk, it should be 1
*/
/* chk_mmc() function is used to check the partition type of
SD card.
ATA_systemInit() function needs to be called
with 'diskType' set to 0 before calling chk_mmc().
chk_mmc() function will check whether the disk is partitioned
or unpartitioned. If disk is not partitioned it will change the
'diskType' value to 1 otherwise it will not change the diskType value.
After calling chk_mmc() if 'diskType' is not '0' , It means that
the SD card is not partitioned and ATA_systemInit() needs to be
called with 'diskType' value modified by chk_mmc() function */
diskType = CSL_MMCSD_ATAFS_DISKTYPE;
/* Call ATA_systemInit() to intialize some values whcih are
used by chk_mmc() function */
ata_error = ATA_systemInit(gpstrAtaDrive, diskType);
chk_mmc(gpstrAtaDrive, &diskType);
if(diskType != CSL_MMCSD_ATAFS_DISKTYPE)
{
ata_error = ATA_systemInit(gpstrAtaDrive, diskType);
if(ata_error != ATA_ERROR_NONE)
{
printf("ATA_systemInit Failed\n");
printf("Format the SD card\n");
return(ata_error);
}
}
printf("\nATA File System Initialization successful\n");
return(ata_error);
}
AtaError CreateMmcFile(AtaFile *pAtaFile, char *fileName)
{
AtaError ata_error;
ata_error = ATA_ERROR_NONE;
/* Find the first file available */
ata_error = ATA_fileInit(gpstrAtaDrive, pAtaFile);
if(ata_error) {
printf("ATA_fileInit error (0x%x)\n", ata_error);
return(ata_error);
}
/* Set the temp write buffer */
pAtaFile->pDrive->_AtaWriteBuffer = AtaWrBuf;
/* Set the file name */
ATA_setFileName(pAtaFile, fileName, "txt");
ata_error = ATA_create(pAtaFile);
if(ata_error != ATA_ERROR_NONE)
{
printf("ATA_create Failed\n");
return(ata_error);
}
else
{
//printf("\nFile Creation on SD card is Successful\n");
}
return(ata_error);
}
AtaError OpenExistMmcFile(AtaFile *pAtaFile, char* filename)
{
AtaError ata_error;
ata_error = ATA_ERROR_NONE;
/* Find the first file available */
ata_error = ATA_fileInit(gpstrAtaDrive, pAtaFile);
if(ata_error) {
printf("ATA_fileInit error (0x%x)\n", ata_error);
return(ata_error);
}
/* Set the temp write buffer */
pAtaFile->pDrive->_AtaWriteBuffer = AtaWrBuf;
ata_error = ATA_fopen(pAtaFile, filename, "txt");
if(ata_error != ATA_ERROR_NONE)
{
printf("ATA_fopen Failed\n");
return(ata_error);
}
else
{
//printf("\nFile Open on SD card is Successful\n");
}
return(ata_error);
}
AtaError WriteMmcBuf(AtaFile *pAtaFile, Uint16* dat, Uint16 len)
{
AtaError ata_error;
ata_error = ATA_ERROR_NONE;
/* Write data to the file */
ata_error = ATA_write(pAtaFile, dat, CSL_MMCSD_ATA_BUF_SIZE);
if(ata_error != ATA_ERROR_NONE)
{
printf("ATA_write Failed\n");
return(ata_error);
}
else
{
//printf("\nWriting Data to the file on SD card successful\n");
}
return(ata_error);
}
AtaError ReadMmcBuf(AtaFile *pAtaFile, Uint32 loc, Uint16* dat, Uint16 len)
{
AtaError ata_error;
ata_error = ATA_ERROR_NONE;
/* Reset the file pointer to the beginning */
ATA_seek (pAtaFile, loc);
/* Read the data from the file in little endian mode */
ata_error = ATA_readLittleEndian(pAtaFile,dat, len);
if(ata_error != ATA_ERROR_NONE)
{
printf("ATA_readLittleEndian Failed\n");
return(ata_error);
}
else
{
//printf("\nReading Data from the file on SD card successful\n");
}
return(ata_error);
}
AtaError CloseMmcFile(AtaFile *pAtaFile)
{
AtaError ata_error;
ata_error = ATA_ERROR_NONE;
/* Close the file */
ata_error = ATA_close(pAtaFile);
if(ata_error != ATA_ERROR_NONE)
{
printf("ATA_close Failed\n");
return(ata_error);
}
return(ata_error);
}
void Debug_WriteSDRAMToSDCard(char* filename)
{
CSL_Status status;
AtaError ataStatus;
AtaFile fl;
Uint16* px;
Uint32 len,curlen;
status = configSdCard(CSL_MMCSD_OPMODE_DMA);
if(status != CSL_SOK)
{
printf("SD card initialization Failed\n");
return;
}
ataStatus = MountMmcDrive();
if(ataStatus != ATA_ERROR_NONE) return;
//record the tone to the SD
ataStatus = CreateMmcFile(&fl, filename);
if(ataStatus != ATA_ERROR_NONE) return;
debug_ram_for_sd_addr = DEBUG_RAM_ADDRESS;
px = (Uint16*)debug_ram_for_sd_addr;
GetCodecDataSize(&len);
while(len)
{
curlen = 256;
if(curlen > len) curlen = len;
ataStatus = WriteMmcBuf(&fl, px, curlen);
if(ataStatus != ATA_ERROR_NONE) return;
px += curlen;
len -= curlen;
}
if(ataStatus != ATA_ERROR_NONE) return;
CloseMmcFile(&fl);
}
void Debug_ReadSDRAMFromSDCard(char* filename)
{
CSL_Status status;
AtaError ataStatus;
AtaFile fl;
Uint16* px;
Uint32 len,curlen,loc;
status = configSdCard(CSL_MMCSD_OPMODE_DMA);
if(status != CSL_SOK)
{
printf("SD card initialization Failed\n");
return;
}
ataStatus = MountMmcDrive();
if(ataStatus != ATA_ERROR_NONE) return;
//record the tone to the SD
ataStatus = OpenExistMmcFile(&fl, filename);;
if(ataStatus != ATA_ERROR_NONE) return;
debug_ram_for_sd_addr = DEBUG_RAM_ADDRESS;
px = (Uint16*)debug_ram_for_sd_addr;
GetCodecDataSize(&len);
loc = 0;
while(len)
{
curlen = 256;
if(curlen > len) curlen = len;
ataStatus = ReadMmcBuf(&fl, loc, px, curlen);
if(ataStatus != ATA_ERROR_NONE) return;
px += curlen;
loc += curlen;
len -= curlen;
}
if(ataStatus != ATA_ERROR_NONE) return;
CloseMmcFile(&fl);
}
Void testcode(void) { Uint32 i; Uint16 *px; px = (Uint16*)DEBUG_RAM_ADDRESS; for(i=0;i<0x10000;i++) *px++ = 'A'; Debug_WriteSDRAMToSDCard("codec1"); Debug_ReadSDRAMFromSDCard("codec1"); }