From c2fb8a7a981bf9a2691d2b2691c10e03ad693317 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 22 May 2012 16:35:53 +1000 Subject: [PATCH] DataFlash: use ChipErase() instead of PageErase() on all pages This makes the DataFlash erase much faster (about 6 seconds instead of about 60 seconds). We need to test and ensure the behaviour is equivalent apart from the speed --- libraries/DataFlash/DataFlash.cpp | 7 +------ libraries/DataFlash/DataFlash.h | 2 +- libraries/DataFlash/DataFlash_APM1.cpp | 6 ++++-- libraries/DataFlash/DataFlash_APM1.h | 2 +- libraries/DataFlash/DataFlash_APM2.cpp | 9 ++++++--- libraries/DataFlash/DataFlash_APM2.h | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libraries/DataFlash/DataFlash.cpp b/libraries/DataFlash/DataFlash.cpp index 5e192ea041..3a7d8db9ed 100644 --- a/libraries/DataFlash/DataFlash.cpp +++ b/libraries/DataFlash/DataFlash.cpp @@ -188,13 +188,8 @@ uint16_t DataFlash_Class::GetFilePage() void DataFlash_Class::EraseAll(void (*delay_cb)(unsigned long)) { + ChipErase(delay_cb); SetFileNumber(0xFFFF); - for(uint16_t j = 1; j <= df_NumPages; j++) { - PageErase(j); - StartWrite(j); - delay_cb(1); - } - // write the logging format in the last page StartWrite(df_NumPages+1); WriteLong(DF_LOGGING_FORMAT); diff --git a/libraries/DataFlash/DataFlash.h b/libraries/DataFlash/DataFlash.h index c4af0eb567..371bf0af60 100644 --- a/libraries/DataFlash/DataFlash.h +++ b/libraries/DataFlash/DataFlash.h @@ -32,7 +32,7 @@ class DataFlash_Class virtual void PageToBuffer(unsigned char BufferNum, uint16_t PageAdr) = 0; virtual unsigned char BufferRead (unsigned char BufferNum, uint16_t IntPageAdr) = 0; virtual void PageErase(uint16_t PageAdr) = 0; - virtual void ChipErase(void) = 0; + virtual void ChipErase(void (*delay_cb)(unsigned long)) = 0; // internal high level functions int find_last_page(void); diff --git a/libraries/DataFlash/DataFlash_APM1.cpp b/libraries/DataFlash/DataFlash_APM1.cpp index 9057c8b8f2..cbbf30c2c2 100644 --- a/libraries/DataFlash/DataFlash_APM1.cpp +++ b/libraries/DataFlash/DataFlash_APM1.cpp @@ -294,7 +294,7 @@ void DataFlash_APM1::PageErase (uint16_t PageAdr) } -void DataFlash_APM1::ChipErase () +void DataFlash_APM1::ChipErase(void (*delay_cb)(unsigned long)) { dataflash_CS_active(); // activate dataflash command decoder @@ -306,7 +306,9 @@ void DataFlash_APM1::ChipErase () dataflash_CS_inactive(); //initiate flash page erase dataflash_CS_active(); - while(!ReadStatus()); + while (!ReadStatus()) { + delay_cb(1); + } dataflash_CS_inactive(); // deactivate dataflash command decoder } diff --git a/libraries/DataFlash/DataFlash_APM1.h b/libraries/DataFlash/DataFlash_APM1.h index 9761c08ada..1bff7b4d99 100644 --- a/libraries/DataFlash/DataFlash_APM1.h +++ b/libraries/DataFlash/DataFlash_APM1.h @@ -19,7 +19,7 @@ class DataFlash_APM1 : public DataFlash_Class unsigned char ReadStatus(); uint16_t PageSize(); void PageErase (uint16_t PageAdr); - void ChipErase (); + void ChipErase(void (*delay_cb)(unsigned long)); public: diff --git a/libraries/DataFlash/DataFlash_APM2.cpp b/libraries/DataFlash/DataFlash_APM2.cpp index 8f5fd5204b..b9d4639ce9 100644 --- a/libraries/DataFlash/DataFlash_APM2.cpp +++ b/libraries/DataFlash/DataFlash_APM2.cpp @@ -350,7 +350,7 @@ void DataFlash_APM2::PageErase (uint16_t PageAdr) } -void DataFlash_APM2::ChipErase () +void DataFlash_APM2::ChipErase(void (*delay_cb)(unsigned long)) { // activate dataflash command decoder CS_active(); @@ -364,8 +364,11 @@ void DataFlash_APM2::ChipErase () //initiate flash page erase CS_inactive(); CS_active(); - while(!ReadStatus()); + + while(!ReadStatus()) { + delay_cb(1); + } // release SPI bus for use by other sensors CS_inactive(); -} \ No newline at end of file +} diff --git a/libraries/DataFlash/DataFlash_APM2.h b/libraries/DataFlash/DataFlash_APM2.h index 73a3ce5fce..cb4d343a6b 100644 --- a/libraries/DataFlash/DataFlash_APM2.h +++ b/libraries/DataFlash/DataFlash_APM2.h @@ -23,7 +23,7 @@ class DataFlash_APM2 : public DataFlash_Class void CS_inactive(); void CS_active(); void PageErase (uint16_t PageAdr); - void ChipErase (); + void ChipErase(void (*delay_cb)(unsigned long)); public: DataFlash_APM2(); // Constructor