MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / _flash_write_data

Method _flash_write_data

libraries/AP_HAL_ChibiOS/Storage.cpp:363–392  ·  view source on GitHub ↗

callback to write data to flash */

Source from the content-addressed store, hash-verified

361 callback to write data to flash
362 */
363bool 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

Callers

nothing calls this directly

Calls 5

re_initialiseMethod · 0.80
millisFunction · 0.70
getpageaddrMethod · 0.45
writeMethod · 0.45
delayMethod · 0.45

Tested by

no test coverage detected