ChibiOS/HAL
7.0.3
|
Managed Flash Storage module code. More...
Go to the source code of this file.
Macros | |
#define | ALIGNED_REC_SIZE(n) (flash_offset_t)MFS_ALIGN_NEXT(sizeof (mfs_data_header_t) + (size_t)(n)) |
Data record size aligned. More... | |
#define | ALIGNED_DHDR_SIZE ALIGNED_REC_SIZE(0) |
Data record header size aligned. More... | |
#define | ALIGNED_SIZEOF(t) (((sizeof (t) - 1U) | MFS_ALIGN_MASK) + 1U) |
Aligned size of a type. More... | |
#define | PAIR(a, b) (((unsigned)(a) << 2U) | (unsigned)(b)) |
Combines two values (0..3) in one (0..15). More... | |
#define | RET_ON_ERROR(err) |
Error check helper. More... | |
Functions | |
static mfs_error_t | mfs_flash_read (MFSDriver *mfsp, flash_offset_t offset, size_t n, uint8_t *rp) |
Flash read. More... | |
static mfs_error_t | mfs_flash_write (MFSDriver *mfsp, flash_offset_t offset, size_t n, const uint8_t *wp) |
Flash write. More... | |
static mfs_error_t | mfs_flash_copy (MFSDriver *mfsp, flash_offset_t doffset, flash_offset_t soffset, uint32_t n) |
Flash copy. More... | |
static mfs_error_t | mfs_bank_erase (MFSDriver *mfsp, mfs_bank_t bank) |
Erases and verifies all sectors belonging to a bank. More... | |
static mfs_error_t | mfs_bank_verify_erase (MFSDriver *mfsp, mfs_bank_t bank) |
Erases and verifies all sectors belonging to a bank. More... | |
static mfs_error_t | mfs_bank_write_header (MFSDriver *mfsp, mfs_bank_t bank, uint32_t cnt) |
Writes the validation header in a bank. More... | |
static mfs_bank_state_t | mfs_bank_check_header (MFSDriver *mfsp) |
Checks integrity of the header in the shared buffer. More... | |
static mfs_error_t | mfs_bank_scan_records (MFSDriver *mfsp, mfs_bank_t bank, bool *wflagp) |
Scans blocks searching for records. More... | |
static mfs_error_t | mfs_bank_get_state (MFSDriver *mfsp, mfs_bank_t bank, mfs_bank_state_t *statep, uint32_t *cntp) |
Determines the state of a bank. More... | |
static mfs_error_t | mfs_garbage_collect (MFSDriver *mfsp) |
Enforces a garbage collection. More... | |
static mfs_error_t | mfs_try_mount (MFSDriver *mfsp) |
Performs a flash partition mount attempt. More... | |
mfs_error_t | mfs_mount (MFSDriver *mfsp) |
Configures and activates a MFS driver. More... | |
void | mfsObjectInit (MFSDriver *mfsp) |
Initializes an instance. More... | |
mfs_error_t | mfsStart (MFSDriver *mfsp, const MFSConfig *config) |
Configures and activates a MFS driver. More... | |
void | mfsStop (MFSDriver *mfsp) |
Deactivates a MFS driver. More... | |
mfs_error_t | mfsErase (MFSDriver *mfsp) |
Destroys the state of the managed storage by erasing the flash. More... | |
mfs_error_t | mfsReadRecord (MFSDriver *mfsp, mfs_id_t id, size_t *np, uint8_t *buffer) |
Retrieves and reads a data record. More... | |
mfs_error_t | mfsWriteRecord (MFSDriver *mfsp, mfs_id_t id, size_t n, const uint8_t *buffer) |
Creates or updates a data record. More... | |
mfs_error_t | mfsEraseRecord (MFSDriver *mfsp, mfs_id_t id) |
Erases a data record. More... | |
mfs_error_t | mfsPerformGarbageCollection (MFSDriver *mfsp) |
Enforces a garbage collection operation. More... | |
mfs_error_t | mfsStartTransaction (MFSDriver *mfsp, size_t size) |
Puts the driver in transaction mode. More... | |
mfs_error_t | mfsCommitTransaction (MFSDriver *mfsp) |
A transaction is committed and finalized atomically. More... | |
mfs_error_t | mfsRollbackTransaction (MFSDriver *mfsp) |
A transaction is rolled back atomically. More... | |
Managed Flash Storage module code.
This module manages a flash partition as a generic storage where arbitrary data records can be created, updated, deleted and retrieved.
A managed partition is composed of two banks of equal size, a bank is composed of one or more erasable sectors, a sector is divided in writable pages.
The module handles flash wear leveling and recovery of damaged banks (where possible) caused by power loss during operations. Both operations are transparent to the user.
Definition in file hal_mfs.c.