From eb6848b8c2bb6c0f11cc1115f05d5b880efece13 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 23 Feb 2016 16:32:19 +1100 Subject: [PATCH] HAL_PX4: work around a bus locking issue on Pixracer Pixracer has FRAM on the same bus as the ms5611 and the FRAM ramtron driver does not use the same locking mechanism as other px4 SPI drivers. We need to disable interrupts during FRAM transfers to ensure we don't get FRAM corruption --- libraries/AP_HAL_PX4/Storage.cpp | 43 +++++++++++++++++++++++++++----- libraries/AP_HAL_PX4/Storage.h | 5 ++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/libraries/AP_HAL_PX4/Storage.cpp b/libraries/AP_HAL_PX4/Storage.cpp index 3024b8b675..f7e07aac73 100644 --- a/libraries/AP_HAL_PX4/Storage.cpp +++ b/libraries/AP_HAL_PX4/Storage.cpp @@ -51,9 +51,11 @@ uint32_t PX4Storage::_mtd_signature(void) if (lseek(mtd_fd, MTD_SIGNATURE_OFFSET, SEEK_SET) != MTD_SIGNATURE_OFFSET) { hal.scheduler->panic("Failed to seek in " MTD_PARAMS_FILE); } + bus_lock(true); if (read(mtd_fd, &v, sizeof(v)) != sizeof(v)) { hal.scheduler->panic("Failed to read signature from " MTD_PARAMS_FILE); } + bus_lock(false); close(mtd_fd); return v; } @@ -71,9 +73,11 @@ void PX4Storage::_mtd_write_signature(void) if (lseek(mtd_fd, MTD_SIGNATURE_OFFSET, SEEK_SET) != MTD_SIGNATURE_OFFSET) { hal.scheduler->panic("Failed to seek in " MTD_PARAMS_FILE); } + bus_lock(true); if (write(mtd_fd, &v, sizeof(v)) != sizeof(v)) { hal.scheduler->panic("Failed to write signature in " MTD_PARAMS_FILE); } + bus_lock(false); close(mtd_fd); } @@ -103,10 +107,12 @@ void PX4Storage::_upgrade_to_mtd(void) } close(old_fd); ssize_t ret; + bus_lock(true); if ((ret=::write(mtd_fd, _buffer, sizeof(_buffer))) != sizeof(_buffer)) { ::printf("mtd write of %u bytes returned %d errno=%d\n", sizeof(_buffer), ret, errno); hal.scheduler->panic("Unable to write MTD for upgrade"); } + bus_lock(false); close(mtd_fd); #if STORAGE_RENAME_OLD_FILE rename(OLD_STORAGE_FILE, OLD_STORAGE_FILE_BAK); @@ -156,7 +162,9 @@ void PX4Storage::_storage_open(void) } const uint16_t chunk_size = 128; for (uint16_t ofs=0; ofs