APM:Libraries
Classes | Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
AP_FlashStorage Class Reference

#include <AP_FlashStorage.h>

Classes

struct  block_header
 
struct  sector_header
 

Public Member Functions

 FUNCTOR_TYPEDEF (FlashWrite, bool, uint8_t, uint32_t, const uint8_t *, uint16_t)
 
 FUNCTOR_TYPEDEF (FlashRead, bool, uint8_t, uint32_t, uint8_t *, uint16_t)
 
 FUNCTOR_TYPEDEF (FlashErase, bool, uint8_t)
 
 FUNCTOR_TYPEDEF (FlashEraseOK, bool)
 
 AP_FlashStorage (uint8_t *mem_buffer, uint32_t flash_sector_size, FlashWrite flash_write, FlashRead flash_read, FlashErase flash_erase, FlashEraseOK flash_erase_ok)
 
bool init (void)
 
bool re_initialise (void)
 
bool switch_full_sector (void)
 
bool write (uint16_t offset, uint16_t length)
 

Static Public Attributes

static const uint16_t storage_size = block_size * num_blocks
 

Private Types

enum  SectorState { SECTOR_STATE_AVAILABLE = 0xFF, SECTOR_STATE_IN_USE = 0xFE, SECTOR_STATE_FULL = 0xFC }
 
enum  BlockState { BLOCK_STATE_AVAILABLE = 0x3, BLOCK_STATE_WRITING = 0x1, BLOCK_STATE_VALID = 0x0 }
 

Private Member Functions

bool load_sector (uint8_t sector)
 
bool erase_sector (uint8_t sector)
 
bool erase_all ()
 
bool write_all (void)
 
bool all_zero (uint16_t ofs, uint16_t size)
 
bool switch_sectors (void)
 

Private Attributes

uint8_t * mem_buffer
 
const uint32_t flash_sector_size
 
FlashWrite flash_write
 
FlashRead flash_read
 
FlashErase flash_erase
 
FlashEraseOK flash_erase_ok
 
uint8_t current_sector
 
uint32_t write_offset
 
uint32_t reserved_space
 
bool write_error
 

Static Private Attributes

static const uint8_t block_size = 8
 
static const uint16_t num_blocks = HAL_STORAGE_SIZE / block_size
 
static const uint8_t max_write = 64
 
static const uint32_t signature = 0x51685B
 
static const uint32_t reserve_size = (storage_size / max_write) * (sizeof(block_header) + max_write) + max_write
 

Detailed Description

Definition at line 45 of file AP_FlashStorage.h.

Member Enumeration Documentation

◆ BlockState

Enumerator
BLOCK_STATE_AVAILABLE 
BLOCK_STATE_WRITING 
BLOCK_STATE_VALID 

Definition at line 118 of file AP_FlashStorage.h.

◆ SectorState

Enumerator
SECTOR_STATE_AVAILABLE 
SECTOR_STATE_IN_USE 
SECTOR_STATE_FULL 

Definition at line 105 of file AP_FlashStorage.h.

Constructor & Destructor Documentation

◆ AP_FlashStorage()

AP_FlashStorage::AP_FlashStorage ( uint8_t *  mem_buffer,
uint32_t  flash_sector_size,
FlashWrite  flash_write,
FlashRead  flash_read,
FlashErase  flash_erase,
FlashEraseOK  flash_erase_ok 
)

Definition at line 31 of file AP_FlashStorage.cpp.

Member Function Documentation

◆ all_zero()

bool AP_FlashStorage::all_zero ( uint16_t  ofs,
uint16_t  size 
)
private

Definition at line 327 of file AP_FlashStorage.cpp.

Referenced by write_all().

Here is the caller graph for this function:

◆ erase_all()

bool AP_FlashStorage::erase_all ( void  )
private

Definition at line 291 of file AP_FlashStorage.cpp.

Referenced by init(), and re_initialise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase_sector()

bool AP_FlashStorage::erase_sector ( uint8_t  sector)
private

Definition at line 276 of file AP_FlashStorage.cpp.

Referenced by erase_all(), init(), and switch_full_sector().

Here is the caller graph for this function:

◆ FUNCTOR_TYPEDEF() [1/4]

AP_FlashStorage::FUNCTOR_TYPEDEF ( FlashWrite  ,
bool  ,
uint8_t  ,
uint32_t  ,
const uint8_t *  ,
uint16_t   
)

◆ FUNCTOR_TYPEDEF() [2/4]

AP_FlashStorage::FUNCTOR_TYPEDEF ( FlashRead  ,
bool  ,
uint8_t  ,
uint32_t  ,
uint8_t *  ,
uint16_t   
)

◆ FUNCTOR_TYPEDEF() [3/4]

AP_FlashStorage::FUNCTOR_TYPEDEF ( FlashErase  ,
bool  ,
uint8_t   
)

◆ FUNCTOR_TYPEDEF() [4/4]

AP_FlashStorage::FUNCTOR_TYPEDEF ( FlashEraseOK  ,
bool   
)

◆ init()

bool AP_FlashStorage::init ( void  )

Definition at line 45 of file AP_FlashStorage.cpp.

Referenced by ChibiOS::Storage::_flash_load(), and FlashTest::setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_sector()

bool AP_FlashStorage::load_sector ( uint8_t  sector)
private

Definition at line 219 of file AP_FlashStorage.cpp.

Referenced by init().

Here is the caller graph for this function:

◆ re_initialise()

bool AP_FlashStorage::re_initialise ( void  )

Definition at line 395 of file AP_FlashStorage.cpp.

Referenced by ChibiOS::Storage::_flash_write_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ switch_full_sector()

bool AP_FlashStorage::switch_full_sector ( void  )

Definition at line 138 of file AP_FlashStorage.cpp.

Referenced by write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ switch_sectors()

bool AP_FlashStorage::switch_sectors ( void  )
private

Definition at line 338 of file AP_FlashStorage.cpp.

Referenced by switch_full_sector(), and write().

Here is the caller graph for this function:

◆ write()

bool AP_FlashStorage::write ( uint16_t  offset,
uint16_t  length 
)

Definition at line 158 of file AP_FlashStorage.cpp.

Referenced by ChibiOS::Storage::_flash_write(), FlashTest::write(), and write_all().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_all()

bool AP_FlashStorage::write_all ( void  )
private

Definition at line 312 of file AP_FlashStorage.cpp.

Referenced by init(), re_initialise(), and switch_full_sector().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ block_size

const uint8_t AP_FlashStorage::block_size = 8
staticprivate

Definition at line 47 of file AP_FlashStorage.h.

Referenced by load_sector(), and write().

◆ current_sector

uint8_t AP_FlashStorage::current_sector
private

Definition at line 96 of file AP_FlashStorage.h.

Referenced by erase_all(), init(), switch_full_sector(), switch_sectors(), write(), and write_all().

◆ flash_erase

FlashErase AP_FlashStorage::flash_erase
private

Definition at line 93 of file AP_FlashStorage.h.

Referenced by erase_sector().

◆ flash_erase_ok

FlashEraseOK AP_FlashStorage::flash_erase_ok
private

Definition at line 94 of file AP_FlashStorage.h.

Referenced by re_initialise(), and write().

◆ flash_read

FlashRead AP_FlashStorage::flash_read
private

Definition at line 92 of file AP_FlashStorage.h.

Referenced by init(), load_sector(), and switch_sectors().

◆ flash_sector_size

const uint32_t AP_FlashStorage::flash_sector_size
private

Definition at line 90 of file AP_FlashStorage.h.

Referenced by load_sector(), and write().

◆ flash_write

FlashWrite AP_FlashStorage::flash_write
private

Definition at line 91 of file AP_FlashStorage.h.

Referenced by erase_all(), erase_sector(), switch_sectors(), and write().

◆ max_write

const uint8_t AP_FlashStorage::max_write = 64
staticprivate

Definition at line 49 of file AP_FlashStorage.h.

Referenced by write(), and write_all().

◆ mem_buffer

uint8_t* AP_FlashStorage::mem_buffer
private

Definition at line 89 of file AP_FlashStorage.h.

Referenced by all_zero(), init(), load_sector(), and write().

◆ num_blocks

const uint16_t AP_FlashStorage::num_blocks = HAL_STORAGE_SIZE / block_size
staticprivate

Definition at line 48 of file AP_FlashStorage.h.

◆ reserve_size

const uint32_t AP_FlashStorage::reserve_size = (storage_size / max_write) * (sizeof(block_header) + max_write) + max_write
staticprivate

Definition at line 132 of file AP_FlashStorage.h.

Referenced by switch_sectors().

◆ reserved_space

uint32_t AP_FlashStorage::reserved_space
private

Definition at line 98 of file AP_FlashStorage.h.

Referenced by init(), switch_full_sector(), switch_sectors(), write(), and write_all().

◆ signature

const uint32_t AP_FlashStorage::signature = 0x51685B
staticprivate

Definition at line 102 of file AP_FlashStorage.h.

Referenced by erase_all(), erase_sector(), init(), and switch_sectors().

◆ storage_size

const uint16_t AP_FlashStorage::storage_size = block_size * num_blocks
static

Definition at line 86 of file AP_FlashStorage.h.

Referenced by init(), load_sector(), and write_all().

◆ write_error

bool AP_FlashStorage::write_error
private

Definition at line 99 of file AP_FlashStorage.h.

Referenced by erase_all(), init(), switch_full_sector(), switch_sectors(), and write().

◆ write_offset

uint32_t AP_FlashStorage::write_offset
private

Definition at line 97 of file AP_FlashStorage.h.

Referenced by erase_all(), load_sector(), switch_sectors(), write(), and write_all().


The documentation for this class was generated from the following files: