dataflash: fixed APM2 flash logging

we had log wrap disabled on APM2, and also had the wrong log size. The
mainline code assumed 4096, but it is 8192 pages long.
This commit is contained in:
Andrew Tridgell 2011-12-26 18:25:43 +11:00
parent 04daeab7c0
commit 13b2ddcbe1
5 changed files with 21 additions and 18 deletions

View File

@ -6,19 +6,21 @@
#include <stdint.h>
#define DF_OVERWRITE_DATA 1 // 0: When reach the end page stop, 1: Start overwriting from page 1
class DataFlash_Class
{
public:
DataFlash_Class() {} // Constructor
virtual void Init() = 0;
virtual void Init() = 0;
virtual void ReadManufacturerID() = 0;
virtual int16_t GetPage() = 0;
virtual int16_t GetWritePage() = 0;
virtual void PageErase (uint16_t PageAdr) = 0;
virtual void ChipErase () = 0;
// Write methods
// Write methods
virtual void StartWrite(int16_t PageAdr) = 0;
virtual void FinishWrite() = 0;
virtual void WriteByte(unsigned char data) = 0;

View File

@ -36,7 +36,8 @@
#include "DataFlash.h"
#include <SPI.h>
#define OVERWRITE_DATA 1 // 0: When reach the end page stop, 1: Start overwriting from page 1
// flash size
#define DF_LAST_PAGE 4096
// arduino mega SPI pins
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
@ -116,6 +117,7 @@ void DataFlash_APM1::Init(void)
// get page size: 512 or 528
df_PageSize=PageSize();
df_NumPages = DF_LAST_PAGE;
}
// This function is mainly to test the device
@ -323,7 +325,7 @@ void DataFlash_APM1::FinishWrite(void)
df_BufferIdx=0;
BufferToPage(df_BufferNum,df_PageAdr,0); // Write Buffer to memory, NO WAIT
df_PageAdr++;
if (OVERWRITE_DATA==1)
if (DF_OVERWRITE_DATA==1)
{
if (df_PageAdr>DF_LAST_PAGE) // If we reach the end of the memory, start from the begining
df_PageAdr = 1;
@ -352,7 +354,7 @@ void DataFlash_APM1::WriteByte(byte data)
df_BufferIdx=4; //(4 bytes for FileNumber, FilePage)
BufferToPage(df_BufferNum,df_PageAdr,0); // Write Buffer to memory, NO WAIT
df_PageAdr++;
if (OVERWRITE_DATA==1)
if (DF_OVERWRITE_DATA==1)
{
if (df_PageAdr>DF_LAST_PAGE) // If we reach the end of the memory, start from the begining
df_PageAdr = 1;

View File

@ -6,9 +6,6 @@
#include "DataFlash.h"
// flash size
#define DF_LAST_PAGE 4096
class DataFlash_APM1 : public DataFlash_Class
{
private:
@ -38,6 +35,7 @@ class DataFlash_APM1 : public DataFlash_Class
unsigned char df_device_0;
unsigned char df_device_1;
uint16_t df_PageSize;
uint16_t df_NumPages;
DataFlash_APM1(); // Constructor
void Init();

View File

@ -53,7 +53,7 @@ extern "C" {
# error Please check the Tools/Board menu to ensure you have selected Arduino Mega as your target.
#endif
#define DF_MAX_PAGE 8192
#define DF_LAST_PAGE 8192
// AT45DB321D Commands (from Datasheet)
#define DF_TRANSFER_PAGE_TO_BUFFER_1 0x53
@ -76,8 +76,6 @@ extern "C" {
#define DF_CHIP_ERASE_3 0x9A
#define OVERWRITE_DATA 0 // 0: When reach the end page stop, 1: Start overwritten from page 1
// *** INTERNAL FUNCTIONS ***
unsigned char DataFlash_APM2::SPI_transfer(unsigned char data)
{
@ -136,6 +134,7 @@ void DataFlash_APM2::Init(void)
// get page size: 512 or 528 (by default: 528)
df_PageSize=PageSize();
df_NumPages = DF_LAST_PAGE;
}
// This function is mainly to test the device
@ -335,14 +334,14 @@ void DataFlash_APM2::FinishWrite(void)
df_BufferIdx=0;
BufferToPage(df_BufferNum,df_PageAdr,0); // Write Buffer to memory, NO WAIT
df_PageAdr++;
if (OVERWRITE_DATA==1)
if (DF_OVERWRITE_DATA==1)
{
if (df_PageAdr>=DF_MAX_PAGE) // If we reach the end of the memory, start from the begining
if (df_PageAdr>DF_LAST_PAGE) // If we reach the end of the memory, start from the begining
df_PageAdr = 1;
}
else
{
if (df_PageAdr>=DF_MAX_PAGE) // If we reach the end of the memory, stop here
if (df_PageAdr>DF_LAST_PAGE) // If we reach the end of the memory, stop here
df_Stop_Write=1;
}
@ -364,14 +363,14 @@ void DataFlash_APM2::WriteByte(byte data)
df_BufferIdx=4; //(4 bytes for FileNumber, FilePage)
BufferToPage(df_BufferNum,df_PageAdr,0); // Write Buffer to memory, NO WAIT
df_PageAdr++;
if (OVERWRITE_DATA==1)
if (DF_OVERWRITE_DATA==1)
{
if (df_PageAdr>=DF_MAX_PAGE) // If we reach the end of the memory, start from the begining
if (df_PageAdr>DF_LAST_PAGE) // If we reach the end of the memory, start from the begining
df_PageAdr = 1;
}
else
{
if (df_PageAdr>=DF_MAX_PAGE) // If we reach the end of the memory, stop here
if (df_PageAdr>DF_LAST_PAGE) // If we reach the end of the memory, stop here
df_Stop_Write=1;
}
@ -437,13 +436,14 @@ byte DataFlash_APM2::ReadByte()
WaitReady();
result = BufferRead(df_Read_BufferNum,df_Read_BufferIdx);
df_Read_BufferIdx++;
if (df_Read_BufferIdx >= df_PageSize) // End of buffer?
{
df_Read_BufferIdx=4; //(4 bytes for FileNumber, FilePage)
PageToBuffer(df_Read_BufferNum,df_Read_PageAdr); // Write memory page to Buffer
df_Read_PageAdr++;
if (df_Read_PageAdr>=DF_MAX_PAGE) // If we reach the end of the memory, start from the begining
if (df_Read_PageAdr>DF_LAST_PAGE) // If we reach the end of the memory, start from the begining
{
df_Read_PageAdr = 0;
df_Read_END = true;

View File

@ -42,6 +42,7 @@ class DataFlash_APM2 : public DataFlash_Class
unsigned char df_device_0;
unsigned char df_device_1;
uint16_t df_PageSize;
uint16_t df_NumPages;
DataFlash_APM2(); // Constructor
void Init();