/********************************************************************* * * _GetData * * Purpose: * Reading data directly from file system */ int _GetData(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off) { U32 NumBytesRead; #ifdef WIN32 HANDLE hFile; hFile = *(HANDLE *)p; SetFilePointer(hFile, Off, 0, FILE_BEGIN); ReadFile(hFile, (U8 *)*ppData, NumBytes, &NumBytesRead, NULL); #else FS_FILE * pFile; pFile = (FS_FILE *)p; FS_SetFilePos(pFile, Off, FS_FILE_BEGIN); NumBytesRead = FS_Read(pFile, (U8 *)*ppData, NumBytes); #endif return NumBytesRead; }
void MainTask(void) { unsigned i; U32 Space; U32 NumLoops; U32 NumBytes; U32 NumBytesAtOnce; FS_FILE * pFile; I32 t; FS_Init(); _TestNo = -1; // // Check if we need to low-level format the volume // if (FS_IsLLFormatted(VOLUME_NAME) == 0) { FS_X_Log("Low level formatting\n"); FS_FormatLow(VOLUME_NAME); /* Erase & Low-level format the flash */ } // // Volume is always high level formatted // before doing any performance tests. // FS_X_Log("High level formatting\n"); #if FS_SUPPORT_FAT if (FS_FormatSD(VOLUME_NAME) == 0) { #else if (FS_Format(VOLUME_NAME, NULL) == 0) { #endif // // Disable that the directory entry is every time // updated after a write operation // FS_ConfigUpdateDirOnWrite(0); // // Fill the buffer with data // FS_MEMSET((void*)_aBuffer, 'a', sizeof(_aBuffer)); // // Get some general info // Space = FS_GetVolumeFreeSpace(VOLUME_NAME); Space = MIN(Space, FILE_SIZE); NumBytes = BLOCK_SIZE * NUM_BLOCKS_MEASURE; NumBytesAtOnce = BLOCK_SIZE; NumLoops = Space / NumBytes; // // Create file of full size // _StartTest("W", NumBytes); pFile = FS_FOpen(FILE_NAME, "w"); // // Preallocate the file, setting the file pointer to the highest position // and declare it as the end of the file. // FS_SetFilePos(pFile, Space, FS_FILE_BEGIN); FS_SetEndOfFile(pFile); // // Set file position to the beginning // FS_SetFilePos(pFile, 0, FS_FILE_BEGIN); // // Check write performance with clusters/file size preallocated // sprintf(_ac, "Writing %lu chunks of %lu Bytes: ", NumLoops, NumBytes); FS_X_Log(_ac); for (i = 0; i < NumLoops ; i++) { t = _WriteFile(pFile, &_aBuffer[0], NumBytesAtOnce); _StoreResult(t); FS_X_Log("."); } FS_X_Log("OK\n"); FS_FClose(pFile); // // Check read performance // _StartTest("R", NumBytes); sprintf(_ac, "Reading %lu chunks of %lu Bytes: " , NumLoops, NumBytes); FS_X_Log(_ac); pFile = FS_FOpen(FILE_NAME, "r"); for (i = 0; i < NumLoops; i++) { t = _ReadFile(pFile, _aBuffer, NumBytesAtOnce); _StoreResult(t); FS_X_Log("."); } FS_X_Log("OK\n\n"); FS_FClose(pFile); // // Show results for performance list // for (i = 0; i <= (unsigned)_TestNo; i++) { sprintf(_ac, "%s Speed: %f kByte/s\n", _aResult[i].sName, _GetAverage(i)); FS_X_Log(_ac); } FS_X_Log("Finished\n"); FS_Unmount(VOLUME_NAME); } else { FS_X_Log("Volume could not be formatted!\n"); } while (1) { ; } }