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

Method _flash_write_data

libraries/AP_HAL_ESP32/Storage.cpp:145–168  ·  view source on GitHub ↗

callback to write data to flash */

Source from the content-addressed store, hash-verified

143 callback to write data to flash
144 */
145bool Storage::_flash_write_data(uint8_t sector, uint32_t offset, const uint8_t *data, uint16_t length)
146{
147#ifdef STORAGEDEBUG
148 printf("%s:%d \n", __PRETTY_FUNCTION__, __LINE__);
149#endif
150 size_t address = sector * STORAGE_SECTOR_SIZE + offset;
151 bool ret = esp_partition_write(p, address, data, length) == ESP_OK;
152 if (!ret && _flash_erase_ok()) {
153 // we are getting flash write errors while disarmed. Try
154 // re-writing all of flash
155 uint32_t now = AP_HAL::millis();
156 if (now - _last_re_init_ms > 5000) {
157 _last_re_init_ms = now;
158 bool ok = _flash.re_initialise();
159 DEV_PRINTF("Storage: failed at %u:%u for %u - re-init %u\n",
160 (unsigned)sector, (unsigned)offset, (unsigned)length, (unsigned)ok);
161#ifdef STORAGEDEBUG
162 printf("Storage: failed at %u:%u for %u - re-init %u\n",
163 (unsigned)sector, (unsigned)offset, (unsigned)length, (unsigned)ok);
164#endif
165 }
166 }
167 return ret;
168}
169
170/*
171 callback to read data from flash

Callers

nothing calls this directly

Calls 2

re_initialiseMethod · 0.80
millisFunction · 0.70

Tested by

no test coverage detected