//***************************************************************************** // // Flashstore.h - Prototypes and definitions for flash storage module. // this module is responsible for all memory interfacess in the system // each storage type can be defined here and to be accessed from this interface. // This module manages the storage of data logger of sampeled data and configuration // into on chip flash memory. //***************************************************************************** #ifndef DRIVERS_FLASHSTORE_H_ #define DRIVERS_FLASHSTORE_H_ //***************************************************************************** // // If building with a C++ compiler, make all of the definitions in this header // have a C binding. // //***************************************************************************** #ifdef __cplusplus extern "C" { #endif //memory sections currently defined for storage on internal flash #define FLASH_STORE_START_ADDR 0x20000 #define FLASH_STORE_END_ADDR 0x40000 #define FLASH_CONFIG_START_ADDR 0x40000 #define FLASH_CONFIG_END_ADDR 0x50000 #define MAGIC_NUMBER_OF_FREE_REC_BEG 0x53554100 #define CRC_SEED_MASK 0xFFFFFF00 //used as crc seed and masking number for searching in flash records #define RECORD_LENGTH_MASK 0xFF #define FLASH_PAGE_BOUNDARY_MASK 0x3FF //beyond this mask begins new paging each page is of 1k - 0x3ff is the last addres #define FLASH_PAGE_SIZE_IN_BYTES 0x400 #define NUMBER_OF_BYTES_IN_INT 4 #define RECORD_HEADER_SIZE 4 #define FORMATED_FLASH_SIGNATURE 0xFFFFFFFF typedef enum { ADCData = 0, ConfigData, NumOfDataTypes } FlashDataType_t; //***************************************************************************** // // Module function prototypes. // //***************************************************************************** void FlashStoreInit(void); //***************************************************************************** // // This is called at the start of logging to prepare space in flash for // storage of logged data. It searches for the first blank area in the // flash storage to be used for storing records. // // If a starting address is specified then the search is skipped and it goes // directly to the new address. If the starting address is 0, then it performs // the search. // //***************************************************************************** int32_t FlashStoreOpenLogFile(FlashDataType_t _dataType,uint32_t _ui32StartAddr); //***************************************************************************** // function used to write into internal flash specific buffer //***************************************************************************** int32_t FlashStoreWriteBuffer(FlashDataType_t _dataType,uint32_t* _pui32Record,uint32_t _ui32ItemCount); //***************************************************************************** // // This is called each time there is a new data record to log to the flash // storage area. A simple algorithm is used which rotates programming // data log records through an area of flash. It is assumed that the current // page is blank. Records are stored on the current page until a page // boundary is crossed. If the page boundary is crossed and the new page // is not blank (testing only the first location), then the new page is // erased. Finally the entire record is programmed into flash and the // storage pointers are updated. // // While storing and when crossing to a new page, if the flash page is not // blank it is erased. So this algorithm overwrites old data. // // The data is stored in flash as a record, with a flash header prepended, // and with the record length padded to be a multiple of 4 bytes. The flash // header is a 3-byte magic number and one byte of record length. // //***************************************************************************** //int32_t FlashStoreWriteRecord(FlashDataType_t _dataType,tLogRecord *_psRecord); //***************************************************************************** // // Saves data records that are stored in the flash to an externally connected // USB memory storage device (USB stick). // The flash memory is scanned for the presence of store data records. When // records are found they are written in CSV format to the USB stick. This // function assumes a non-corrupted storage area, and that any records, once // found, are contiguous with all stored records. It will find the oldest // record and start with that when storing. // //***************************************************************************** int32_t FlashStoreSave(FlashDataType_t _dataType); //***************************************************************************** // // Erase the data storage area of flash. // //***************************************************************************** void FlashStoreErase(FlashDataType_t _dataType); void FlashStoreReport(FlashDataType_t _dataType); void FlashSendEndReq(FlashDataType_t _dataType); //***************************************************************************** // // Mark the end of the C bindings section for C++ compilers. // //***************************************************************************** #ifdef __cplusplus } #endif #endif /* DRIVERS_FLASHSTORE_H_ */