|
|
@ -6,6 +6,7 @@ |
|
|
|
#include <AP_Math/AP_Math.h> |
|
|
|
#include <AP_Math/AP_Math.h> |
|
|
|
#include <AP_FlashStorage/AP_FlashStorage.h> |
|
|
|
#include <AP_FlashStorage/AP_FlashStorage.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
#include <AP_HAL/utility/sparse-endian.h> |
|
|
|
|
|
|
|
|
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL(); |
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL(); |
|
|
|
|
|
|
|
|
|
|
@ -60,11 +61,11 @@ bool FlashTest::flash_write(uint8_t sector, uint32_t offset, const uint8_t *data |
|
|
|
(unsigned)offset, |
|
|
|
(unsigned)offset, |
|
|
|
(unsigned)length); |
|
|
|
(unsigned)length); |
|
|
|
} |
|
|
|
} |
|
|
|
const uint16_t *data16 = (const uint16_t *)data; |
|
|
|
|
|
|
|
uint16_t *b16 = (uint16_t *)&b[0]; |
|
|
|
|
|
|
|
uint16_t len16 = length/2; |
|
|
|
uint16_t len16 = length/2; |
|
|
|
for (uint16_t i=0; i<len16; i++) { |
|
|
|
for (uint16_t i=0; i<len16; i++) { |
|
|
|
if (data16[i] & !b16[i]) { |
|
|
|
const uint16_t v = le16toh_ptr(&data[i*2]); |
|
|
|
|
|
|
|
uint16_t v2 = le16toh_ptr(&b[i*2]); |
|
|
|
|
|
|
|
if (v & !v2) { |
|
|
|
AP_HAL::panic("FATAL: invalid write16 at %u:%u 0x%04x 0x%04x\n", |
|
|
|
AP_HAL::panic("FATAL: invalid write16 at %u:%u 0x%04x 0x%04x\n", |
|
|
|
(unsigned)sector, |
|
|
|
(unsigned)sector, |
|
|
|
unsigned(offset+i), |
|
|
|
unsigned(offset+i), |
|
|
@ -72,7 +73,7 @@ bool FlashTest::flash_write(uint8_t sector, uint32_t offset, const uint8_t *data |
|
|
|
data[i]); |
|
|
|
data[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
#ifndef AP_FLASHSTORAGE_MULTI_WRITE |
|
|
|
#ifndef AP_FLASHSTORAGE_MULTI_WRITE |
|
|
|
if (data16[i] != b16[i] && data16[i] != 0xFFFF && b16[i] != 0xFFFF) { |
|
|
|
if (v != v2 && v != 0xFFFF && v2 != 0xFFFF) { |
|
|
|
AP_HAL::panic("FATAL: invalid write16 at %u:%u 0x%04x 0x%04x\n", |
|
|
|
AP_HAL::panic("FATAL: invalid write16 at %u:%u 0x%04x 0x%04x\n", |
|
|
|
(unsigned)sector, |
|
|
|
(unsigned)sector, |
|
|
|
unsigned(offset+i), |
|
|
|
unsigned(offset+i), |
|
|
@ -80,7 +81,8 @@ bool FlashTest::flash_write(uint8_t sector, uint32_t offset, const uint8_t *data |
|
|
|
data[i]); |
|
|
|
data[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
b16[i] &= data16[i]; |
|
|
|
v2 &= v; |
|
|
|
|
|
|
|
put_le16_ptr(&b[i*2], v2); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|