1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-17 13:25:20 +03:00

SD read speed tests added to CLI

This commit is contained in:
Damjan Adamic 2016-02-29 22:14:45 +01:00
parent cc4e28857d
commit f65e42833e

View file

@ -19,6 +19,7 @@
*/
#include "opentx.h"
#include "diskio.h"
#include <ctype.h>
#include <malloc.h>
@ -133,6 +134,94 @@ int cliLs(const char ** argv)
return 0;
}
int cliRead(const char ** argv)
{
FIL file;
uint32_t bytesRead = 0;
int bufferSize;
if (toInt(argv, 2, &bufferSize) == 0 || bufferSize < 0 ) {
serialPrint("%s: Invalid buffer size \"%s\"", argv[0], argv[2]);
return 0;
}
uint8_t * buffer = (uint8_t*) malloc(bufferSize);
FRESULT result = f_open(&file, argv[1], FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) {
free(buffer);
serialPrint("%s: File not found \"%s\"", argv[0], argv[1]);
return 0;
}
tmr10ms_t start = get_tmr10ms();
while (true) {
UINT read;
result = f_read(&file, buffer, sizeof(buffer), &read);
if (result == FR_OK) {
if (read == 0) {
// end of file
f_close(&file);
break;
}
bytesRead += read;
}
}
uint32_t elapsedTime = (get_tmr10ms() - start) * 10;
if (elapsedTime == 0) elapsedTime = 1;
uint32_t speed = bytesRead / elapsedTime;
serialPrint("Read %d bytes in %d ms, speed %d kB/s", bytesRead, elapsedTime, speed);
free(buffer);
return 0;
}
int cliReadSD(const char ** argv)
{
int startSector;
int numberOfSectors;
int bufferSectors;
if (toInt(argv, 1, &startSector) == 0 || startSector < 0 ) {
serialPrint("%s: Invalid start sector \"%s\"", argv[0], argv[1]);
return 0;
}
if (toInt(argv, 2, &numberOfSectors) == 0 || numberOfSectors < 0 ) {
serialPrint("%s: Invalid number of sectors \"%s\"", argv[0], argv[2]);
return 0;
}
if (toInt(argv, 3, &bufferSectors) == 0 || bufferSectors < 0 ) {
serialPrint("%s: Invalid number of buffrer sectors \"%s\"", argv[0], argv[3]);
return 0;
}
uint8_t * buffer = (uint8_t*) malloc(512*bufferSectors);
uint32_t bytesRead = numberOfSectors * 512;
tmr10ms_t start = get_tmr10ms();
while (numberOfSectors > 0) {
DRESULT res = disk_read(0, buffer, startSector, bufferSectors);
if (res != RES_OK) {
serialPrint("disk_read error: %d", res);
free(buffer);
return 0;
}
if (numberOfSectors >= bufferSectors) {
numberOfSectors -= bufferSectors;
}
else {
numberOfSectors = 0;
}
}
uint32_t elapsedTime = (get_tmr10ms() - start) * 10;
if (elapsedTime == 0) elapsedTime = 1;
uint32_t speed = bytesRead / elapsedTime;
serialPrint("Read %d bytes in %d ms, speed %d kB/s", bytesRead, elapsedTime, speed);
free(buffer);
return 0;
}
int cliTrace(const char ** argv)
{
if (!strcmp(argv[1], "on")) {
@ -420,6 +509,8 @@ int cliShowJitter(const char ** argv)
const CliCommand cliCommands[] = {
{ "beep", cliBeep, "[<frequency>] [<duration>]" },
{ "ls", cliLs, "<directory>" },
{ "read", cliRead, "<filename>" },
{ "readsd", cliReadSD, "<start sector> <sectors count> <read buffer size (sectors)>" },
{ "play", cliPlay, "<filename>" },
{ "print", cliDisplay, "<address> [<size>] | <what>" },
{ "reboot", cliReboot, "" },