37 #define MFS_BANK_MAGIC_1                    0xEC705ADEU    38 #define MFS_BANK_MAGIC_2                    0xF0339CC5U    39 #define MFS_HEADER_MAGIC_1                  0x5FAE45F0U    40 #define MFS_HEADER_MAGIC_2                  0xF045AE5FU    54 #if !defined(MFS_CFG_MAX_RECORDS) || defined(__DOXYGEN__)    55 #define MFS_CFG_MAX_RECORDS                 32    61 #if !defined(MFS_CFG_MAX_REPAIR_ATTEMPTS) || defined(__DOXYGEN__)    62 #define MFS_CFG_MAX_REPAIR_ATTEMPTS         3    68 #if !defined(MFS_CFG_WRITE_VERIFY) || defined(__DOXYGEN__)    69 #define MFS_CFG_WRITE_VERIFY                TRUE    78 #if !defined(MFS_CFG_STRONG_CHECKING) || defined(__DOXYGEN__)    79 #define MFS_CFG_STRONG_CHECKING             TRUE    89 #if !defined(MFS_CFG_BUFFER_SIZE) || defined(__DOXYGEN__)    90 #define MFS_CFG_BUFFER_SIZE                 32   100 #if !defined(MFS_CFG_MEMORY_ALIGNMENT) || defined(__DOXYGEN__)   101 #define MFS_CFG_MEMORY_ALIGNMENT            2   107 #if !defined(MFS_CFG_TRANSACTION_MAX) || defined(__DOXYGEN__)   108 #define MFS_CFG_TRANSACTION_MAX             16   116 #if MFS_CFG_MAX_RECORDS < 0   117 #error "invalid MFS_CFG_MAX_RECORDS value"   120 #if (MFS_CFG_MAX_REPAIR_ATTEMPTS < 1) ||                                    \   121     (MFS_CFG_MAX_REPAIR_ATTEMPTS > 10)   122 #error "invalid MFS_MAX_REPAIR_ATTEMPTS value"   125 #if MFS_CFG_BUFFER_SIZE < 16   126 #error "invalid MFS_CFG_BUFFER_SIZE value"   129 #if (MFS_CFG_BUFFER_SIZE & (MFS_CFG_BUFFER_SIZE - 1)) != 0   130 #error "MFS_CFG_BUFFER_SIZE is not a power of two"   133 #if (MFS_CFG_MEMORY_ALIGNMENT < 1) ||                                       \   134     (MFS_CFG_MEMORY_ALIGNMENT > MFS_CFG_BUFFER_SIZE)   135 #error "invalid MFS_CFG_MEMORY_ALIGNMENT value"   138 #if (MFS_CFG_MEMORY_ALIGNMENT & (MFS_CFG_MEMORY_ALIGNMENT - 1)) != 0   139 #error "MFS_CFG_MEMORY_ALIGNMENT is not a power of two"   142 #if (MFS_CFG_TRANSACTION_MAX < 0) ||                                        \   143     (MFS_CFG_TRANSACTION_MAX > MFS_CFG_MAX_RECORDS)   144 #error "invalid MFS_CFG_TRANSACTION_MAX value"   179   MFS_ERR_INV_STATE = -1,
   180   MFS_ERR_INV_SIZE = -2,
   181   MFS_ERR_NOT_FOUND = -3,
   182   MFS_ERR_OUT_OF_MEM = -4,
   183   MFS_ERR_TRANSACTION_NUM = -5,
   184   MFS_ERR_TRANSACTION_SIZE = -6,
   185   MFS_ERR_NOT_ERASED = -7,
   186   MFS_ERR_FLASH_FAILURE = -8,
   187   MFS_ERR_INTERNAL = -9
   278 } mfs_record_descriptor_t;
   369 #if (MFS_CFG_TRANSACTION_MAX > 0) || defined(__DOXYGEN__)   407 #define MFS_IS_ERROR(err) ((err) < MFS_NO_ERROR)   408 #define MFS_IS_WARNING(err) ((err) > MFS_NO_ERROR)   415 #define MFS_ALIGN_MASK      ((uint32_t)MFS_CFG_MEMORY_ALIGNMENT - 1U)   416 #define MFS_IS_ALIGNED(v)   (((uint32_t)(v) & MFS_ALIGN_MASK) == 0U)   417 #define MFS_ALIGN_PREV(v)   ((uint32_t)(v) & ~MFS_ALIGN_MASK)   418 #define MFS_ALIGN_NEXT(v)   (MFS_ALIGN_PREV(((uint32_t)(v) - 1U)) +         \   419                                             MFS_CFG_MEMORY_ALIGNMENT)   434                             size_t *np, uint8_t *buffer);
   436                              size_t n, 
const uint8_t *buffer);
   439 #if MFS_CFG_TRANSACTION_MAX > 0 mfs_error_t mfsReadRecord(MFSDriver *mfsp, mfs_id_t id, size_t *np, uint8_t *buffer)
Retrieves and reads a data record. 
void mfsObjectInit(MFSDriver *mfsp)
Initializes an instance. 
Type of a buffered write/erase operation within a transaction. 
uint32_t flash_sector_t
Type of a flash sector number. 
uint32_t erased
Erased value. 
#define MFS_CFG_TRANSACTION_MAX
Maximum number of objects writable in a single transaction. 
mfs_state_t state
Driver state. 
mfs_id_t id
Record identifier. 
size_t size
Written data size. 
Type of a MFS configuration structure. 
uint32_t mfs_id_t
Type of a record identifier. 
void mfsStop(MFSDriver *mfsp)
Deactivates a MFS driver. 
flash_offset_t used_space
Used space in the current bank without considering erased records. 
mfs_error_t mfsRollbackTransaction(MFSDriver *mfsp)
A transaction is rolled back atomically. 
uint32_t tr_nops
Number of buffered operations in current transaction. 
flash_offset_t tr_next_offset
Next write offset for current transaction. 
mfs_error_t mfsPerformGarbageCollection(MFSDriver *mfsp)
Enforces a garbage collection operation. 
mfs_bank_state_t
Type of a bank state assessment. 
mfs_error_t mfsStart(MFSDriver *mfsp, const MFSConfig *config)
Configures and activates a MFS driver. 
mfs_error_t mfsCommitTransaction(MFSDriver *mfsp)
A transaction is committed and finalized atomically. 
flash_offset_t bank_size
Banks size. 
flash_offset_t offset
Written header offset. 
#define MFS_CFG_BUFFER_SIZE
Size of the buffer used for data copying. 
mfs_state_t
Type of driver state machine states. 
mfs_error_t mfsEraseRecord(MFSDriver *mfsp, mfs_id_t id)
Erases a data record. 
flash_sector_t bank1_start
Base sector index for bank 1. 
flash_sector_t bank0_sectors
Number of sectors for bank 0. 
mfs_error_t mfsStartTransaction(MFSDriver *mfsp, size_t size)
Puts the driver in transaction mode. 
flash_sector_t bank1_sectors
Number of sectors for bank 1. 
flash_offset_t next_offset
Pointer to the next free position in the current bank. 
mfs_error_t mfsErase(MFSDriver *mfsp)
Destroys the state of the managed storage by erasing the flash. 
uint32_t flash_offset_t
Type of a flash offset. 
#define MFS_CFG_MAX_RECORDS
Maximum number of indexed records in the managed storage. 
mfs_error_t mfsWriteRecord(MFSDriver *mfsp, mfs_id_t id, size_t n, const uint8_t *buffer)
Creates or updates a data record. 
mfs_error_t
Type of an MFS error code. 
mfs_bank_t current_bank
Bank currently in use. 
uint32_t current_counter
Usage counter of the current bank. 
Generic flash driver class header. 
flash_sector_t bank0_start
Base sector index for bank 0. 
BaseFlash * flashp
Flash driver associated to this MFS instance. 
mfs_bank_t
Type of a flash bank. 
flash_offset_t tr_limit_offet
Maximum offset for the transaction. 
const MFSConfig * config
Current configuration data.