Browse Source

DataFlash: prevent the dataflash erase problem

only allow writes to dataflash block devices once StartNewLog() has
been called
master
Andrew Tridgell 12 years ago
parent
commit
411e940342
  1. 7
      libraries/DataFlash/DataFlash_Block.cpp
  2. 1
      libraries/DataFlash/DataFlash_Block.h
  3. 2
      libraries/DataFlash/LogFile.cpp

7
libraries/DataFlash/DataFlash_Block.cpp

@ -37,7 +37,7 @@ void DataFlash_Block::FinishWrite(void)
void DataFlash_Block::WriteBlock(const void *pBuffer, uint16_t size) void DataFlash_Block::WriteBlock(const void *pBuffer, uint16_t size)
{ {
if (!CardInserted()) { if (!CardInserted() || !log_write_started) {
return; return;
} }
while (size > 0) { while (size > 0) {
@ -163,7 +163,9 @@ void DataFlash_Block::EraseAll()
hal.scheduler->delay(100); hal.scheduler->delay(100);
StartWrite(df_NumPages+1); StartWrite(df_NumPages+1);
uint32_t version = DF_LOGGING_FORMAT; uint32_t version = DF_LOGGING_FORMAT;
log_write_started = true;
WriteBlock(&version, sizeof(version)); WriteBlock(&version, sizeof(version));
log_write_started = false;
FinishWrite(); FinishWrite();
hal.scheduler->delay(100); hal.scheduler->delay(100);
} }
@ -173,8 +175,9 @@ void DataFlash_Block::EraseAll()
*/ */
bool DataFlash_Block::NeedErase(void) bool DataFlash_Block::NeedErase(void)
{ {
uint32_t version; uint32_t version = 0;
StartRead(df_NumPages+1); StartRead(df_NumPages+1);
ReadBlock(&version, sizeof(version)); ReadBlock(&version, sizeof(version));
StartRead(1);
return version != DF_LOGGING_FORMAT; return version != DF_LOGGING_FORMAT;
} }

1
libraries/DataFlash/DataFlash_Block.h

@ -53,6 +53,7 @@ private:
uint16_t df_Read_PageAdr; uint16_t df_Read_PageAdr;
uint16_t df_FileNumber; uint16_t df_FileNumber;
uint16_t df_FilePage; uint16_t df_FilePage;
bool log_write_started;
/* /*
functions implemented by the board specific backends functions implemented by the board specific backends

2
libraries/DataFlash/LogFile.cpp

@ -58,6 +58,7 @@ uint16_t DataFlash_Block::start_new_log(void)
SetFileNumber(1); SetFileNumber(1);
StartWrite(1); StartWrite(1);
//Serial.println("start log from 0"); //Serial.println("start log from 0");
log_write_started = true;
return 1; return 1;
} }
@ -78,6 +79,7 @@ uint16_t DataFlash_Block::start_new_log(void)
SetFileNumber(new_log_num); SetFileNumber(new_log_num);
StartWrite(last_page + 1); StartWrite(last_page + 1);
} }
log_write_started = true;
return new_log_num; return new_log_num;
} }

Loading…
Cancel
Save