Dmitry Kovalev / Mbed 2 deprecated LG2

Dependencies:   mbed

Fork of LG by igor Apu

DeviceFlash.h

Committer:
Diletant
Date:
2016-05-03
Revision:
149:abbf7663d27d
Child:
156:e68ee0bcdcda

File content as of revision 149:abbf7663d27d:

#ifndef __DEVICE_FLASH_H__
#define __DEVICE_FLASH_H__

#include "IAP.h"

//Flash memory page size: 256|512|1024|4096 allowed
#define FLASH_PAGE_SIZE 256

//Hash sector - 8 bytes per hash
typedef struct _DeviceFlashHash {
  uint32_t hash;    //Hash
  uint32_t address; //Address of data located in data sector
  //uint16_t size;    //Size of data
} DeviceFlashHash;

typedef struct _DeviceFlashSettings {
  uint16_t hashSector; //Sector of "hash - data address" pairs
  //uint16_t hashPageLength;
  uint16_t dataSector; //Sector of data, referenced from hash sector
  //uint16_t dataPageLength;
} DeviceFlashSettings;

typedef struct _DeviceFlashWriteOperation {
  uint8_t pageBuffer[FLASH_PAGE_SIZE]; //Page buffer
  //uint16_t pageLength;
  uint16_t pagePosition;               //Position in page buffer to write in
  
  uint16_t sector;                     //Current sector to write data in
  uint32_t sectorAddress;              //Starting address of sector to write data from page buffer
  uint16_t sectorPosition;             //Position in sector to write data from page buffer relative to sector start address
  uint16_t sectorLength;               //Length of current sector
  
  uint32_t bytes;                      //Count of bytes written
  uint32_t maxBytes;                   //Maximum allowed bytes to write
} DeviceFlashWriteOperation;

typedef struct _DeviceFlashState {
} DeviceFlashState;

typedef struct _DeviceFlash {
  DeviceFlashSettings settings;
  DeviceFlashState state;
} DeviceFlash;

void InitFlashWithDefaults(void);
void InitFlash(void);

uint32_t AddressFromSector(uint8_t sector);
uint16_t LengthFromSector(uint8_t sector);
//uint8_t sectorFromAddress(uint32_t address);

void FlashReadAll(void);
void FlashWriteAll(void);

#endif  /* __DEVICE_FLASH_H__ */