callback to write data to flash */
| 361 | callback to write data to flash |
| 362 | */ |
| 363 | bool Storage::_flash_write_data(uint8_t sector, uint32_t offset, const uint8_t *data, uint16_t length) |
| 364 | { |
| 365 | #ifdef STORAGE_FLASH_PAGE |
| 366 | #if AP_FLASH_STORAGE_DOUBLE_PAGE |
| 367 | sector *= 2; |
| 368 | #endif |
| 369 | size_t base_address = hal.flash->getpageaddr(_flash_page+sector); |
| 370 | for (uint8_t i=0; i<STORAGE_FLASH_RETRIES; i++) { |
| 371 | EXPECT_DELAY_MS(1); |
| 372 | if (hal.flash->write(base_address+offset, data, length)) { |
| 373 | return true; |
| 374 | } |
| 375 | hal.scheduler->delay(1); |
| 376 | } |
| 377 | if (_flash_erase_ok()) { |
| 378 | // we are getting flash write errors while disarmed. Try |
| 379 | // re-writing all of flash |
| 380 | uint32_t now = AP_HAL::millis(); |
| 381 | if (now - _last_re_init_ms > 5000) { |
| 382 | _last_re_init_ms = now; |
| 383 | bool ok = _flash.re_initialise(); |
| 384 | ::printf("Storage: failed at %u:%u for %u - re-init %u\n", |
| 385 | (unsigned)sector, (unsigned)offset, (unsigned)length, (unsigned)ok); |
| 386 | } |
| 387 | } |
| 388 | return false; |
| 389 | #else |
| 390 | return false; |
| 391 | #endif |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | callback to read data from flash |
nothing calls this directly
no test coverage detected