Advertisement
Guest User

mmcConfigFS

a guest
Apr 9th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. /**
  2. * \brief Function to configure file system and perform
  3. * read/write operations
  4. *
  5. * \param fileName - Name of the file to be created
  6. *
  7. * \return Test result
  8. */
  9. AtaError mmcConfigFs(char *fileName)
  10. {
  11. Uint16 index;
  12. AtaError ata_error;
  13. unsigned int diskType;
  14.  
  15. ata_error = ATA_ERROR_NONE;
  16.  
  17. for(index = 0; index < CSL_MMCSD_ATA_BUF_SIZE; index++)
  18. {
  19. // gMmcWriteBuf[index] = 0x4142; //
  20. AtaWrBuf[index] = 0x4344;
  21. gMmcReadBuf[index] = 0x0;
  22. }
  23.  
  24. /* Call init function initialize ATA state structure */
  25. gpstrAtaDrive->AtaInitAtaMediaState = (AtaError (*)(void *))MMC_initState;
  26. gpstrAtaMMCState->hMmcSd = mmcsdHandle;
  27. gpstrAtaDrive->pAtaMediaState = gpstrAtaMMCState;
  28. gpstrAtaDrive->AtaInitAtaMediaState(gpstrAtaDrive);
  29.  
  30. /* For partitioned disk, 'diskType' should be 0
  31. and for unpartiotioned disk, it should be 1
  32. */
  33. /* chk_mmc() function is used to check the partition type of
  34. SD card.
  35. ATA_systemInit() function needs to be called
  36. with 'diskType' set to 0 before calling chk_mmc().
  37. chk_mmc() function will check whether the disk is partitioned
  38. or unpartitioned. If disk is not partitioned it will change the
  39. 'diskType' value to 1 otherwise it will not change the diskType value.
  40. After calling chk_mmc() if 'diskType' is not '0' , It means that
  41. the SD card is not partitioned and ATA_systemInit() needs to be
  42. called with 'diskType' value modified by chk_mmc() function */
  43.  
  44. diskType = CSL_MMCSD_ATAFS_DISKTYPE;
  45. /* Call ATA_systemInit() to intialize some values whcih are
  46. used by chk_mmc() function */
  47. ata_error = ATA_systemInit(gpstrAtaDrive, diskType);
  48.  
  49. chk_mmc(gpstrAtaDrive, &diskType);
  50. if(diskType != CSL_MMCSD_ATAFS_DISKTYPE)
  51. {
  52. ata_error = ATA_systemInit(gpstrAtaDrive, diskType);
  53. if(ata_error != ATA_ERROR_NONE)
  54. {
  55. printf("ATA_systemInit Failed\n");
  56. printf("Format the SD card\n");
  57. return(ata_error);
  58. }
  59. }
  60.  
  61. printf("\nATA File System Initialization successful\n");
  62.  
  63. /* Find the first file available */
  64. ata_error = ATA_fileInit(gpstrAtaDrive, pAtaFile);
  65. if(ata_error) {
  66. printf("ATA_fileInit error (0x%x)\n", ata_error);
  67. return(ata_error);
  68. }
  69.  
  70. /* Set the temp write buffer */
  71. pAtaFile->pDrive->_AtaWriteBuffer = AtaWrBuf;
  72.  
  73. #if 0
  74. /* Set the file name */
  75. ATA_setFileName(pAtaFile, fileName, "txt");
  76.  
  77. ata_error = ATA_create(pAtaFile);
  78. #else
  79. ata_error = ATA_fopen(pAtaFile, fileName, "txt");
  80. #endif
  81. if(ata_error != ATA_ERROR_NONE)
  82. {
  83. printf("ATA_fopen Failed\n");
  84. return(ata_error);
  85. }
  86. else
  87. {
  88. printf("\nFile Creation/Open on SD card is Successful\n");
  89. }
  90.  
  91. /* Write data to the file */
  92. ata_error = ATA_write(pAtaFile, gMmcWriteBuf, CSL_MMCSD_ATA_BUF_SIZE);
  93. if(ata_error != ATA_ERROR_NONE)
  94. {
  95. printf("ATA_write Failed\n");
  96. return(ata_error);
  97. }
  98. else
  99. {
  100. printf("\nWriting Data to the file on SD card successful\n");
  101. }
  102.  
  103. /* Reset the file pointer to the beginning */
  104. ATA_seek (pAtaFile, 0);
  105.  
  106. /* Read the data from the file in little endian mode */
  107. ata_error = ATA_readLittleEndian(pAtaFile,gMmcReadBuf, CSL_MMCSD_ATA_BUF_SIZE);
  108. if(ata_error != ATA_ERROR_NONE)
  109. {
  110. printf("ATA_readLittleEndian Failed\n");
  111. return(ata_error);
  112. }
  113. else
  114. {
  115. printf("\nReading Data from the file on SD card successful\n");
  116. }
  117.  
  118. /* Close the file */
  119. ata_error = ATA_close(pAtaFile);
  120. if(ata_error != ATA_ERROR_NONE)
  121. {
  122. printf("ATA_close Failed\n");
  123. return(ata_error);
  124. }
  125.  
  126. /* Compare the data read and data written */
  127. for(index = 0; index < CSL_MMCSD_ATA_BUF_SIZE; index++)
  128. {
  129. if(gMmcWriteBuf[index] != gMmcReadBuf[index])
  130. {
  131. ata_error = 1;
  132. printf("\nMMCSD Read and Write Buffers do not Match\n");
  133. break;
  134. }
  135. }
  136.  
  137. if(ata_error == 0)
  138. {
  139. printf("\nMMCSD Read and Write Buffers Match\n");
  140. }
  141.  
  142. return(ata_error);
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement