AP_FlashStorage: added re_initialise() API

This commit is contained in:
Andrew Tridgell 2017-03-22 19:36:45 +11:00
parent d1fd843539
commit 0bfbc4bf72
2 changed files with 19 additions and 4 deletions

View File

@ -277,9 +277,7 @@ bool AP_FlashStorage::erase_sector(uint8_t sector)
bool AP_FlashStorage::erase_all(void)
{
write_error = false;
// start with empty memory buffer
memset(mem_buffer, 0, storage_size);
current_sector = 0;
write_offset = sizeof(struct sector_header);
@ -374,3 +372,17 @@ bool AP_FlashStorage::switch_sectors(void)
write_offset = sizeof(header);
return true;
}
/*
re-initialise, using current mem_buffer
*/
bool AP_FlashStorage::re_initialise(void)
{
if (!flash_erase_ok()) {
return false;
}
if (!erase_all()) {
return false;
}
return write_all();
}

View File

@ -72,6 +72,9 @@ public:
// initialise storage, filling mem_buffer with current contents
bool init(void);
// re-initialise storage, using current mem_buffer
bool re_initialise(void);
// switch full sector - should only be called when safe to have CPU
// offline for considerable periods as an erase will be needed
bool switch_full_sector(void);
@ -135,7 +138,7 @@ private:
bool erase_sector(uint8_t sector);
// erase all sectors and reset
bool erase_all(void);
bool erase_all();
// write all of mem_buffer to current sector
bool write_all(void);