2011-11-12 23:29:07 -04:00
|
|
|
/* ************************************************************ */
|
|
|
|
/* Test for DataFlash Log library */
|
|
|
|
/* ************************************************************ */
|
|
|
|
#ifndef DataFlash_h
|
|
|
|
#define DataFlash_h
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2011-12-26 03:25:43 -04:00
|
|
|
#define DF_OVERWRITE_DATA 1 // 0: When reach the end page stop, 1: Start overwriting from page 1
|
|
|
|
|
2011-12-28 00:52:36 -04:00
|
|
|
// the last page holds the log format in first 4 bytes. Please change
|
|
|
|
// this if (and only if!) the low level format changes
|
|
|
|
#define DF_LOGGING_FORMAT 0x28122011
|
|
|
|
|
2012-07-03 23:36:42 -03:00
|
|
|
// we use an invalie logging format to test the chip erase
|
|
|
|
#define DF_LOGGING_FORMAT_INVALID 0x28122012
|
|
|
|
|
2011-11-12 23:29:07 -04:00
|
|
|
class DataFlash_Class
|
|
|
|
{
|
2011-12-26 04:11:18 -04:00
|
|
|
private:
|
|
|
|
// DataFlash Log variables...
|
|
|
|
unsigned char df_BufferNum;
|
|
|
|
unsigned char df_Read_BufferNum;
|
|
|
|
uint16_t df_BufferIdx;
|
|
|
|
uint16_t df_Read_BufferIdx;
|
|
|
|
uint16_t df_PageAdr;
|
|
|
|
uint16_t df_Read_PageAdr;
|
|
|
|
unsigned char df_Stop_Write;
|
|
|
|
uint16_t df_FileNumber;
|
|
|
|
uint16_t df_FilePage;
|
|
|
|
|
|
|
|
virtual void WaitReady() = 0;
|
|
|
|
virtual void BufferWrite (unsigned char BufferNum, uint16_t IntPageAdr, unsigned char Data) = 0;
|
|
|
|
virtual void BufferToPage (unsigned char BufferNum, uint16_t PageAdr, unsigned char wait) = 0;
|
|
|
|
virtual void PageToBuffer(unsigned char BufferNum, uint16_t PageAdr) = 0;
|
|
|
|
virtual unsigned char BufferRead (unsigned char BufferNum, uint16_t IntPageAdr) = 0;
|
2011-12-28 00:52:36 -04:00
|
|
|
virtual void PageErase(uint16_t PageAdr) = 0;
|
2012-07-03 23:36:42 -03:00
|
|
|
virtual void BlockErase(uint16_t BlockAdr) = 0;
|
2012-08-18 08:28:31 -03:00
|
|
|
virtual void ChipErase(void (*delay_cb)(unsigned long)) = 0;
|
2011-12-28 00:52:36 -04:00
|
|
|
|
|
|
|
// internal high level functions
|
2012-08-18 06:31:20 -03:00
|
|
|
int16_t find_last_page(void);
|
|
|
|
int16_t find_last_page_of_log(uint16_t log_number);
|
2011-12-28 00:52:36 -04:00
|
|
|
bool check_wrapped(void);
|
2011-12-26 04:11:18 -04:00
|
|
|
|
2011-11-12 23:29:07 -04:00
|
|
|
public:
|
2011-12-26 04:11:18 -04:00
|
|
|
unsigned char df_manufacturer;
|
2011-12-28 00:52:36 -04:00
|
|
|
uint16_t df_device;
|
|
|
|
uint16_t df_PageSize;
|
2011-12-26 04:11:18 -04:00
|
|
|
|
2011-11-12 23:29:07 -04:00
|
|
|
DataFlash_Class() {} // Constructor
|
|
|
|
|
2011-12-26 04:11:18 -04:00
|
|
|
virtual void Init(void) = 0;
|
2011-11-12 23:29:07 -04:00
|
|
|
virtual void ReadManufacturerID() = 0;
|
2011-12-28 00:52:36 -04:00
|
|
|
virtual bool CardInserted(void) = 0;
|
|
|
|
|
2011-12-26 04:11:18 -04:00
|
|
|
int16_t GetPage(void);
|
|
|
|
int16_t GetWritePage(void);
|
2011-12-28 00:52:36 -04:00
|
|
|
|
|
|
|
// erase handling
|
2012-08-18 08:28:31 -03:00
|
|
|
void EraseAll(void (*delay_cb)(unsigned long));
|
2011-12-28 00:52:36 -04:00
|
|
|
bool NeedErase(void);
|
2011-11-12 23:29:07 -04:00
|
|
|
|
2011-12-26 03:25:43 -04:00
|
|
|
// Write methods
|
2011-12-26 04:11:18 -04:00
|
|
|
void StartWrite(int16_t PageAdr);
|
|
|
|
void FinishWrite(void);
|
|
|
|
void WriteByte(unsigned char data);
|
|
|
|
void WriteInt(int16_t data);
|
|
|
|
void WriteLong(int32_t data);
|
2011-11-12 23:29:07 -04:00
|
|
|
|
|
|
|
// Read methods
|
2011-12-26 04:11:18 -04:00
|
|
|
void StartRead(int16_t PageAdr);
|
|
|
|
unsigned char ReadByte();
|
|
|
|
int16_t ReadInt();
|
|
|
|
int32_t ReadLong();
|
2011-11-12 23:29:07 -04:00
|
|
|
|
2011-12-28 00:52:36 -04:00
|
|
|
// file numbers
|
2011-11-12 23:29:07 -04:00
|
|
|
void SetFileNumber(uint16_t FileNumber);
|
|
|
|
uint16_t GetFileNumber();
|
|
|
|
uint16_t GetFilePage();
|
2011-12-26 04:11:18 -04:00
|
|
|
|
2011-12-28 00:52:36 -04:00
|
|
|
// page handling
|
2011-12-26 04:11:18 -04:00
|
|
|
uint16_t df_NumPages;
|
2011-12-28 00:52:36 -04:00
|
|
|
|
|
|
|
// high level interface
|
2012-08-18 06:31:20 -03:00
|
|
|
int16_t find_last_log(void);
|
2012-08-17 03:27:19 -03:00
|
|
|
void get_log_boundaries(uint8_t log_num, int16_t & start_page, int16_t & end_page);
|
2011-12-28 00:52:36 -04:00
|
|
|
uint8_t get_num_logs(void);
|
|
|
|
void start_new_log(void);
|
|
|
|
|
2011-11-12 23:29:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#include "DataFlash_APM1.h"
|
2011-11-25 19:11:14 -04:00
|
|
|
#include "DataFlash_APM2.h"
|
2011-11-12 23:29:07 -04:00
|
|
|
|
2011-11-07 07:21:29 -04:00
|
|
|
#endif
|