mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 12:33:33 +08:00
Merge branch 'sdtest' of github.com:PX4/Firmware into hil_usb_only
This commit is contained in:
@@ -95,6 +95,8 @@ extern device::Device *PX4IO_serial_interface() weak_function;
|
|||||||
#define PX4IO_SET_DEBUG _IOC(0xff00, 0)
|
#define PX4IO_SET_DEBUG _IOC(0xff00, 0)
|
||||||
#define PX4IO_INAIR_RESTART_ENABLE _IOC(0xff00, 1)
|
#define PX4IO_INAIR_RESTART_ENABLE _IOC(0xff00, 1)
|
||||||
|
|
||||||
|
#define UPDATE_INTERVAL_MIN 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The PX4IO class.
|
* The PX4IO class.
|
||||||
*
|
*
|
||||||
@@ -817,8 +819,8 @@ PX4IO::task_main()
|
|||||||
|
|
||||||
/* adjust update interval */
|
/* adjust update interval */
|
||||||
if (_update_interval != 0) {
|
if (_update_interval != 0) {
|
||||||
if (_update_interval < 5)
|
if (_update_interval < UPDATE_INTERVAL_MIN)
|
||||||
_update_interval = 5;
|
_update_interval = UPDATE_INTERVAL_MIN;
|
||||||
if (_update_interval > 100)
|
if (_update_interval > 100)
|
||||||
_update_interval = 100;
|
_update_interval = 100;
|
||||||
orb_set_interval(_t_actuators, _update_interval);
|
orb_set_interval(_t_actuators, _update_interval);
|
||||||
@@ -2058,8 +2060,8 @@ int
|
|||||||
PX4IO::set_update_rate(int rate)
|
PX4IO::set_update_rate(int rate)
|
||||||
{
|
{
|
||||||
int interval_ms = 1000 / rate;
|
int interval_ms = 1000 / rate;
|
||||||
if (interval_ms < 3) {
|
if (interval_ms < UPDATE_INTERVAL_MIN) {
|
||||||
interval_ms = 3;
|
interval_ms = UPDATE_INTERVAL_MIN;
|
||||||
warnx("update rate too high, limiting interval to %d ms (%d Hz).", interval_ms, 1000 / interval_ms);
|
warnx("update rate too high, limiting interval to %d ms (%d Hz).", interval_ms, 1000 / interval_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2442,7 +2444,7 @@ px4io_main(int argc, char *argv[])
|
|||||||
if ((argc > 2)) {
|
if ((argc > 2)) {
|
||||||
g_dev->set_update_rate(atoi(argv[2]));
|
g_dev->set_update_rate(atoi(argv[2]));
|
||||||
} else {
|
} else {
|
||||||
errx(1, "missing argument (50 - 400 Hz)");
|
errx(1, "missing argument (50 - 500 Hz)");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|||||||
@@ -63,24 +63,38 @@ test_file(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t buf[512];
|
uint8_t write_buf[512 + 64];
|
||||||
|
|
||||||
|
/* fill write buffer with known values */
|
||||||
|
for (int i = 0; i < sizeof(write_buf); i++) {
|
||||||
|
/* this will wrap, but we just need a known value with spacing */
|
||||||
|
write_buf[i] = i+11;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t read_buf[512 + 64];
|
||||||
hrt_abstime start, end;
|
hrt_abstime start, end;
|
||||||
perf_counter_t wperf = perf_alloc(PC_ELAPSED, "SD writes (aligned)");
|
perf_counter_t wperf = perf_alloc(PC_ELAPSED, "SD writes (aligned)");
|
||||||
|
|
||||||
int fd = open("/fs/microsd/testfile", O_TRUNC | O_WRONLY | O_CREAT);
|
int fd = open("/fs/microsd/testfile", O_TRUNC | O_WRONLY | O_CREAT);
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
|
|
||||||
warnx("aligned write - please wait..");
|
warnx("testing aligned and unaligned writes - please wait..");
|
||||||
|
|
||||||
if ((0x3 & (uintptr_t)buf))
|
|
||||||
warnx("memory is unaligned!");
|
|
||||||
|
|
||||||
start = hrt_absolute_time();
|
start = hrt_absolute_time();
|
||||||
for (unsigned i = 0; i < iterations; i++) {
|
for (unsigned i = 0; i < iterations; i++) {
|
||||||
perf_begin(wperf);
|
perf_begin(wperf);
|
||||||
write(fd, buf, sizeof(buf));
|
int wret = write(fd, write_buf + (i % 64), 512);
|
||||||
|
|
||||||
|
if (wret != 512) {
|
||||||
|
warn("WRITE ERROR!");
|
||||||
|
|
||||||
|
if ((0x3 & (uintptr_t)(write_buf + (i % 64))))
|
||||||
|
warnx("memory is unaligned, align shift: %d", (i % 64));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
perf_end(wperf);
|
perf_end(wperf);
|
||||||
|
|
||||||
}
|
}
|
||||||
end = hrt_absolute_time();
|
end = hrt_absolute_time();
|
||||||
|
|
||||||
@@ -89,39 +103,36 @@ test_file(int argc, char *argv[])
|
|||||||
perf_print_counter(wperf);
|
perf_print_counter(wperf);
|
||||||
perf_free(wperf);
|
perf_free(wperf);
|
||||||
|
|
||||||
|
/* read back data for validation */
|
||||||
|
for (unsigned i = 0; i < iterations; i++) {
|
||||||
|
int rret = read(fd, read_buf, 512);
|
||||||
|
|
||||||
|
/* compare value */
|
||||||
|
|
||||||
|
for (int j = 0; j < 512; j++) {
|
||||||
|
if (read_buf[j] != write_buf[j + (i % 64)]) {
|
||||||
|
warnx("COMPARISON ERROR: byte %d, align shift: %d", j, (i % 64));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read back data for alignment checks */
|
||||||
|
// for (unsigned i = 0; i < iterations; i++) {
|
||||||
|
// perf_begin(wperf);
|
||||||
|
// int rret = read(fd, buf + (i % 64), sizeof(buf));
|
||||||
|
// fsync(fd);
|
||||||
|
// perf_end(wperf);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
int ret = unlink("/fs/microsd/testfile");
|
int ret = unlink("/fs/microsd/testfile");
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
err(1, "UNLINKING FILE FAILED");
|
err(1, "UNLINKING FILE FAILED");
|
||||||
|
|
||||||
warnx("unaligned write - please wait..");
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint8_t byte;
|
|
||||||
uint8_t unaligned[512];
|
|
||||||
} unaligned_buf;
|
|
||||||
|
|
||||||
if ((0x3 & (uintptr_t)unaligned_buf.unaligned) == 0)
|
|
||||||
warnx("creating unaligned memory failed.");
|
|
||||||
|
|
||||||
wperf = perf_alloc(PC_ELAPSED, "SD writes (unaligned)");
|
|
||||||
|
|
||||||
start = hrt_absolute_time();
|
|
||||||
for (unsigned i = 0; i < iterations; i++) {
|
|
||||||
perf_begin(wperf);
|
|
||||||
write(fd, unaligned_buf.unaligned, sizeof(unaligned_buf.unaligned));
|
|
||||||
fsync(fd);
|
|
||||||
perf_end(wperf);
|
|
||||||
}
|
|
||||||
end = hrt_absolute_time();
|
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
warnx("%dKiB in %llu microseconds", iterations / 2, end - start);
|
|
||||||
|
|
||||||
perf_print_counter(wperf);
|
|
||||||
perf_free(wperf);
|
|
||||||
|
|
||||||
/* list directory */
|
/* list directory */
|
||||||
DIR *d;
|
DIR *d;
|
||||||
struct dirent *dir;
|
struct dirent *dir;
|
||||||
|
|||||||
Reference in New Issue
Block a user