Beispiel #1
0
AtaError ATA_cd(AtaFile *pAtaFile)
{

  if (pAtaFile==NULL) return(ATA_ERROR_INVALID_PARAM); // KR042610

/*  AtaState *pAtaDrive = pAtaFile->pDrive;*//*SUSMIT_BUGFIX-Directory Browsing BUgfix*/
  if(pAtaFile->StartCluster)
  {
 /*SUSMIT_BUGFIX-Directory Browsing BUgfix*/
/*	pAtaFile->CurrentDirSector =
	  pAtaDrive->FirstDataSector +
	  (AtaSector)((AtaSector)(pAtaFile->StartCluster-2) * (AtaSector)pAtaDrive->LogSectorsPerCluster);*/
	pAtaFile->CurrentDirSectorTag = 0xFFFFFFFF; // Mistral: It was: -1L;
	pAtaFile->CurrentDirEntry = 0;
  }
  else
  {
 /*SUSMIT_BUGFIX-Directory Browsing BUgfix*/
/*	pAtaFile->CurrentDirSector = pAtaDrive->RootDirSector;*/
	return ATA_cdRoot(pAtaFile);
  }
 /*SUSMIT_BUGFIX-Directory Browsing BUgfix*/
/*  pAtaFile->CurrentDirCluster = pAtaFile->StartCluster;*/
  pAtaFile->StartDirCluster = pAtaFile->StartCluster;
  return(ATA_ERROR_NONE);
}
Beispiel #2
0
AtaError ATA_fileInit(AtaState *pAtaDrive, AtaFile *pAtaFile)
{
    AtaError kk = ATA_ERROR_NONE;
    pAtaFile->pDrive = pAtaDrive;

    if ((pAtaDrive==NULL)||(pAtaFile==NULL)) return(ATA_ERROR_INVALID_PARAM); //KR042110

    start_FAT_cluster=ATA_FIRST_CLUSTER; //KR012210

    kk = ATA_cdRoot(pAtaFile);
    if(kk) return(kk);
    /*  return(AtaFindFirst(pAtaFile));	*/	/*This is not a bug fix, this is a workaround so that ATA_fileInit doesn't return error for a formatted MMC - Susmit*/
    kk=ATA_findFirst(pAtaFile);
    if((kk==ATA_ERROR_NONE)||(kk==ATA_ERROR_FILE_NOT_FOUND)) return(ATA_ERROR_NONE);
    else return(kk);
}
Beispiel #3
0
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);

    /* Set the temp write buffer */
    gpstrAtaDrive->_AtaWriteBuffer = AtaWrBuf;

    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);
    }

    ata_error = ATA_setLongDirectoryName(pAtaFile, fileName);
    if (ata_error != ATA_ERROR_NONE) {
        printf("ATA_setLongDirectoryName Failed\n");
        return (ata_error);
    }

    ata_error = ATA_createDirectoryLong(pAtaFile, fileName);
    if (ata_error != ATA_ERROR_NONE) {
        printf("ATA_createDirectoryLong Failed\n");
        return (ata_error);
    }

    ata_error = ATA_cdRoot(pAtaFile);
    if (ata_error != ATA_ERROR_NONE) {
        printf("ATA_cdRoot Failed\n");
        return (ata_error);
    }

    do {
        ata_error = ATA_findNext(pAtaFile);
        if (ata_error != ATA_ERROR_NONE) {
            printf("Cannot find created directory\n");
            return (ata_error);
        }

        ata_error = ATA_getLongName(pAtaFile, ataFileName, 0, 10);
        if (ata_error != ATA_ERROR_NONE) {
            printf("ATA_getLongName failed\n");
            return (ata_error);
        }
    } while (strcmp(ataFileName, fileName) != 0);

    ata_error = ATA_cd(pAtaFile);
    if (ata_error != ATA_ERROR_NONE) {
        printf("ATA_cdRoot Failed\n");
        return (ata_error);
    }

    /* 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");
    }

    /* 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);
}