Browse Source

DataFlash: removed the byte and word based interfaces

simplifing ready for PX4 flash logging
master
Andrew Tridgell 12 years ago
parent
commit
20825cc903
  1. 43
      libraries/DataFlash/DataFlash.cpp
  2. 7
      libraries/DataFlash/DataFlash.h
  3. 6
      libraries/DataFlash/DataFlash_APM1.cpp
  4. 6
      libraries/DataFlash/DataFlash_APM2.cpp
  5. 21
      libraries/DataFlash/LogFile.cpp

43
libraries/DataFlash/DataFlash.cpp

@ -64,21 +64,6 @@ void DataFlash_Class::WriteBlock(const void *pBuffer, uint16_t size)
} }
void DataFlash_Class::WriteByte(uint8_t data)
{
WriteBlock(&data, sizeof(data));
}
void DataFlash_Class::WriteInt(int16_t data)
{
WriteBlock(&data, sizeof(data));
}
void DataFlash_Class::WriteLong(int32_t data)
{
WriteBlock(&data, sizeof(data));
}
// Get the last page written to // Get the last page written to
int16_t DataFlash_Class::GetWritePage() int16_t DataFlash_Class::GetWritePage()
{ {
@ -143,27 +128,6 @@ void DataFlash_Class::ReadBlock(void *pBuffer, uint16_t size)
} }
} }
uint8_t DataFlash_Class::ReadByte()
{
uint8_t result = 0;
ReadBlock(&result, sizeof(result));
return result;
}
int16_t DataFlash_Class::ReadInt()
{
int16_t result;
ReadBlock(&result, sizeof(result));
return result;
}
int32_t DataFlash_Class::ReadLong()
{
int32_t result;
ReadBlock(&result, sizeof(result));
return result;
}
void DataFlash_Class::SetFileNumber(uint16_t FileNumber) void DataFlash_Class::SetFileNumber(uint16_t FileNumber)
{ {
df_FileNumber = FileNumber; df_FileNumber = FileNumber;
@ -190,7 +154,8 @@ void DataFlash_Class::EraseAll()
} }
// write the logging format in the last page // write the logging format in the last page
StartWrite(df_NumPages+1); StartWrite(df_NumPages+1);
WriteLong(DF_LOGGING_FORMAT); uint32_t version = DF_LOGGING_FORMAT;
WriteBlock(&version, sizeof(version));
FinishWrite(); FinishWrite();
} }
@ -199,7 +164,9 @@ void DataFlash_Class::EraseAll()
*/ */
bool DataFlash_Class::NeedErase(void) bool DataFlash_Class::NeedErase(void)
{ {
uint32_t version;
StartRead(df_NumPages+1); StartRead(df_NumPages+1);
return ReadLong() != DF_LOGGING_FORMAT; ReadBlock(&version, sizeof(version));
return version != DF_LOGGING_FORMAT;
} }

7
libraries/DataFlash/DataFlash.h

@ -77,17 +77,11 @@ public:
void StartWrite(int16_t PageAdr); void StartWrite(int16_t PageAdr);
void FinishWrite(void); void FinishWrite(void);
void WriteBlock(const void *pBuffer, uint16_t size); void WriteBlock(const void *pBuffer, uint16_t size);
void WriteByte(uint8_t data);
void WriteInt(int16_t data);
void WriteLong(int32_t data);
// Read methods // Read methods
void StartRead(int16_t PageAdr); void StartRead(int16_t PageAdr);
void ReadBlock(void *pBuffer, uint16_t size); void ReadBlock(void *pBuffer, uint16_t size);
uint8_t ReadByte();
int16_t ReadInt();
int32_t ReadLong();
// file numbers // file numbers
void SetFileNumber(uint16_t FileNumber); void SetFileNumber(uint16_t FileNumber);
@ -111,6 +105,7 @@ public:
void start_new_log(void); void start_new_log(void);
uint16_t log_read_process(uint16_t start_page, uint16_t end_page, uint16_t log_read_process(uint16_t start_page, uint16_t end_page,
void (*callback)(uint8_t msgid)); void (*callback)(uint8_t msgid));
void DumpPageInfo(AP_HAL::BetterStream *port);
/* /*
every logged packet starts with 3 bytes every logged packet starts with 3 bytes

6
libraries/DataFlash/DataFlash_APM1.cpp

@ -18,15 +18,9 @@
* Methods: * Methods:
* Init() : Library initialization (SPI initialization) * Init() : Library initialization (SPI initialization)
* StartWrite(page) : Start a write session. page=start page. * StartWrite(page) : Start a write session. page=start page.
* WriteByte(data) : Write a byte
* WriteInt(data) : Write an integer (2 bytes)
* WriteLong(data) : Write a long (4 bytes)
* StartRead(page) : Start a read on (page) * StartRead(page) : Start a read on (page)
* GetWritePage() : Returns the last page written to * GetWritePage() : Returns the last page written to
* GetPage() : Returns the last page read * GetPage() : Returns the last page read
* ReadByte()
* ReadInt()
* ReadLong()
* *
* Properties: * Properties:
* *

6
libraries/DataFlash/DataFlash_APM2.cpp

@ -18,15 +18,9 @@
* Methods: * Methods:
* Init() : Library initialization (SPI initialization) * Init() : Library initialization (SPI initialization)
* StartWrite(page) : Start a write session. page=start page. * StartWrite(page) : Start a write session. page=start page.
* WriteByte(data) : Write a byte
* WriteInt(data) : Write an integer (2 bytes)
* WriteLong(data) : Write a long (4 bytes)
* StartRead(page) : Start a read on (page) * StartRead(page) : Start a read on (page)
* GetWritePage() : Returns the last page written to * GetWritePage() : Returns the last page written to
* GetPage() : Returns the last page read * GetPage() : Returns the last page read
* ReadByte()
* ReadInt()
* ReadLong()
* *
* Properties: * Properties:
* *

21
libraries/DataFlash/LogFile.cpp

@ -239,7 +239,8 @@ uint16_t DataFlash_Class::log_read_process(uint16_t start_page, uint16_t end_pag
StartRead(start_page); StartRead(start_page);
while (true) { while (true) {
uint8_t data = ReadByte(); uint8_t data;
ReadBlock(&data, 1);
// This is a state machine to read the packets // This is a state machine to read the packets
switch(log_step) { switch(log_step) {
@ -265,10 +266,26 @@ uint16_t DataFlash_Class::log_read_process(uint16_t start_page, uint16_t end_pag
} }
uint16_t new_page = GetPage(); uint16_t new_page = GetPage();
if (new_page != page) { if (new_page != page) {
if (new_page == end_page) break; if (new_page == end_page) {
return packet_count;
}
page = new_page; page = new_page;
} }
} }
return packet_count; return packet_count;
} }
/*
dump header information from all log pages
*/
void DataFlash_Class::DumpPageInfo(AP_HAL::BetterStream *port)
{
for (uint16_t count=1; count<=df_NumPages; count++) {
StartRead(count);
port->printf_P(PSTR("DF page, log file #, log page: %u,\t"), (unsigned)count);
port->printf_P(PSTR("%u,\t"), (unsigned)GetFileNumber());
port->printf_P(PSTR("%u\n"), (unsigned)GetFilePage());
}
}

Loading…
Cancel
Save