HAL_PX4: read from FRAM in 128 byte chunks (2nd try)

this time without the amazingly silly bug
This commit is contained in:
Andrew Tridgell 2014-05-02 22:12:45 +10:00
parent db6b96caa0
commit 320834a5e7
1 changed files with 8 additions and 2 deletions

View File

@ -154,9 +154,15 @@ void PX4Storage::_storage_open(void)
if (fd == -1) { if (fd == -1) {
hal.scheduler->panic("Failed to open " MTD_PARAMS_FILE); hal.scheduler->panic("Failed to open " MTD_PARAMS_FILE);
} }
if (read(fd, _buffer, sizeof(_buffer)) != sizeof(_buffer)) { const uint16_t chunk_size = 128;
for (uint16_t ofs=0; ofs<sizeof(_buffer); ofs += chunk_size) {
ssize_t ret = read(fd, &_buffer[ofs], chunk_size);
if (ret != chunk_size) {
::printf("storage read of %u bytes at %u to %p failed - got %d errno=%d\n",
(unsigned)sizeof(_buffer), (unsigned)ofs, &_buffer[ofs], (int)ret, (int)errno);
hal.scheduler->panic("Failed to read " MTD_PARAMS_FILE); hal.scheduler->panic("Failed to read " MTD_PARAMS_FILE);
} }
}
close(fd); close(fd);
_initialised = true; _initialised = true;
} }