Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * \brief Function to configure file system and perform
- * read/write operations
- *
- * \param fileName - Name of the file to be created
- *
- * \return Test result
- */
- AtaError mmcConfigFs(char *fileName)
- {
- Uint16 index;
- AtaError ata_error;
- unsigned int diskType;
- ata_error = ATA_ERROR_NONE;
- for(index = 0; index < CSL_MMCSD_ATA_BUF_SIZE; index++)
- {
- // gMmcWriteBuf[index] = 0x4142; //
- AtaWrBuf[index] = 0x4344;
- gMmcReadBuf[index] = 0x0;
- }
- /* 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");
- /* 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;
- #if 0
- /* Set the file name */
- ATA_setFileName(pAtaFile, fileName, "txt");
- ata_error = ATA_create(pAtaFile);
- #else
- ata_error = ATA_fopen(pAtaFile, fileName, "txt");
- #endif
- if(ata_error != ATA_ERROR_NONE)
- {
- printf("ATA_fopen Failed\n");
- return(ata_error);
- }
- else
- {
- printf("\nFile Creation/Open on SD card is Successful\n");
- }
- /* Write data to the file */
- ata_error = ATA_write(pAtaFile, gMmcWriteBuf, 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");
- }
- /* Reset the file pointer to the beginning */
- ATA_seek (pAtaFile, 0);
- /* Read the data from the file in little endian mode */
- ata_error = ATA_readLittleEndian(pAtaFile,gMmcReadBuf, CSL_MMCSD_ATA_BUF_SIZE);
- 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");
- }
- /* Close the file */
- ata_error = ATA_close(pAtaFile);
- if(ata_error != ATA_ERROR_NONE)
- {
- printf("ATA_close Failed\n");
- return(ata_error);
- }
- /* Compare the data read and data written */
- for(index = 0; index < CSL_MMCSD_ATA_BUF_SIZE; index++)
- {
- if(gMmcWriteBuf[index] != gMmcReadBuf[index])
- {
- ata_error = 1;
- printf("\nMMCSD Read and Write Buffers do not Match\n");
- break;
- }
- }
- if(ata_error == 0)
- {
- printf("\nMMCSD Read and Write Buffers Match\n");
- }
- return(ata_error);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement