From b0832e6c15881b04e5ef62eecd604f20cc53cba8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Nov 2016 18:36:37 +1100 Subject: [PATCH] HAL_PX4: factor out storage functions ready for multiple backends --- libraries/AP_HAL_PX4/Storage.cpp | 96 +++++++++++++++++--------------- libraries/AP_HAL_PX4/Storage.h | 5 +- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/libraries/AP_HAL_PX4/Storage.cpp b/libraries/AP_HAL_PX4/Storage.cpp index 70246884e8..e4484ef70a 100644 --- a/libraries/AP_HAL_PX4/Storage.cpp +++ b/libraries/AP_HAL_PX4/Storage.cpp @@ -27,7 +27,6 @@ using namespace PX4; extern const AP_HAL::HAL& hal; PX4Storage::PX4Storage(void) : - _fd(-1), _perf_storage(perf_alloc(PC_ELAPSED, "APM_storage")), _perf_errors(perf_alloc(PC_COUNT, "APM_storage_errors")) { @@ -39,32 +38,10 @@ void PX4Storage::_storage_open(void) return; } - struct stat st; - bool have_mtd = (stat(MTD_PARAMS_FILE, &st) == 0); - - // PX4 should always have /fs/mtd_params - if (!have_mtd) { - AP_HAL::panic("Failed to find " MTD_PARAMS_FILE); - } - _dirty_mask.clearall(); - - int fd = open(MTD_PARAMS_FILE, O_RDONLY); - if (fd == -1) { - AP_HAL::panic("Failed to open " MTD_PARAMS_FILE); - } - const uint16_t chunk_size = 128; - for (uint16_t ofs=0; ofs>PX4_STORAGE_LINE_SHIFT; + for (uint16_t line=loc>>PX4_STORAGE_LINE_SHIFT; line <= end>>PX4_STORAGE_LINE_SHIFT; line++) { _dirty_mask.set(line); @@ -166,28 +143,59 @@ void PX4Storage::_timer_tick(void) return; } + // write the line + _mtd_write(i); + + perf_end(_perf_storage); +} - /* - write the lines. This also updates _dirty_mask. Note that - because this is a SCHED_FIFO thread it will not be preempted - by the main task except during blocking calls. This means we - don't need a semaphore around the _dirty_mask updates. - */ - if (lseek(_fd, i<