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"
380#if (MFS_CFG_TRANSACTION_MAX > 0) || defined(__DOXYGEN__)
412#define MFS_IS_ERROR(err) ((err) < MFS_NO_ERROR)
413#define MFS_IS_WARNING(err) ((err) > MFS_NO_ERROR)
420#define MFS_ALIGN_MASK ((uint32_t)MFS_CFG_MEMORY_ALIGNMENT - 1U)
421#define MFS_IS_ALIGNED(v) (((uint32_t)(v) & MFS_ALIGN_MASK) == 0U)
422#define MFS_ALIGN_PREV(v) ((uint32_t)(v) & ~MFS_ALIGN_MASK)
423#define MFS_ALIGN_NEXT(v) (MFS_ALIGN_PREV(((uint32_t)(v) - 1U)) + \
424 MFS_CFG_MEMORY_ALIGNMENT)
439 size_t *np, uint8_t *buffer);
441 size_t n,
const uint8_t *buffer);
444#if MFS_CFG_TRANSACTION_MAX > 0
uint32_t flash_sector_t
Type of a flash sector number.
uint32_t flash_offset_t
Type of a flash offset.
union mfs_nocache_buffer mfs_nocache_buffer_t
Type of an non-cacheable MFS buffer.
mfs_error_t mfsEraseRecord(MFSDriver *mfsp, mfs_id_t id)
Erases a data record.
#define MFS_CFG_MAX_RECORDS
Maximum number of indexed records in the managed storage.
#define MFS_CFG_BUFFER_SIZE
Size of the buffer used for data copying.
mfs_error_t mfsReadRecord(MFSDriver *mfsp, mfs_id_t id, size_t *np, uint8_t *buffer)
Retrieves and reads a data record.
mfs_error_t
Type of an MFS error code.
mfs_state_t
Type of driver state machine states.
mfs_error_t mfsStart(MFSDriver *mfsp, const MFSConfig *config)
Configures and activates a MFS driver.
#define MFS_CFG_TRANSACTION_MAX
Maximum number of objects writable in a single transaction.
mfs_error_t mfsPerformGarbageCollection(MFSDriver *mfsp)
Enforces a garbage collection operation.
void mfsObjectInit(MFSDriver *mfsp, mfs_nocache_buffer_t *ncbuf)
Initializes an instance.
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 mfsStartTransaction(MFSDriver *mfsp, size_t size)
Puts the driver in transaction mode.
uint32_t mfs_id_t
Type of a record identifier.
mfs_error_t mfsRollbackTransaction(MFSDriver *mfsp)
A transaction is rolled back atomically.
mfs_bank_t
Type of a flash bank.
mfs_error_t mfsCommitTransaction(MFSDriver *mfsp)
A transaction is committed and finalized atomically.
void mfsStop(MFSDriver *mfsp)
Deactivates a MFS driver.
mfs_error_t mfsErase(MFSDriver *mfsp)
Destroys the state of the managed storage by erasing the flash.
mfs_bank_state_t
Type of a bank state assessment.
@ MFS_ERR_TRANSACTION_SIZE
@ MFS_ERR_TRANSACTION_NUM
Generic flash driver class header.
Type of a MFS configuration structure.
uint32_t erased
Erased value.
flash_sector_t bank1_start
Base sector index for bank 1.
flash_sector_t bank0_start
Base sector index for bank 0.
flash_sector_t bank0_sectors
Number of sectors for bank 0.
flash_offset_t bank_size
Banks size.
BaseFlash * flashp
Flash driver associated to this MFS instance.
flash_sector_t bank1_sectors
Number of sectors for bank 1.
uint32_t current_counter
Usage counter of the current bank.
flash_offset_t tr_limit_offet
Maximum offset for the transaction.
flash_offset_t next_offset
Pointer to the next free position in the current bank.
mfs_transaction_op_t tr_ops[MFS_CFG_TRANSACTION_MAX]
Buffered operations in current transaction.
mfs_bank_t current_bank
Bank currently in use.
mfs_record_descriptor_t descriptors[MFS_CFG_MAX_RECORDS]
Offsets of the most recent instance of the records.
const MFSConfig * config
Current configuration data.
uint32_t tr_nops
Number of buffered operations in current transaction.
flash_offset_t tr_next_offset
Next write offset for current transaction.
mfs_nocache_buffer_t * ncbuf
Associated non-cacheable buffer.
flash_offset_t used_space
Used space in the current bank without considering erased records.
mfs_state_t state
Driver state.
flash_offset_t offset
Offset of the record header.
uint32_t size
Record data size.
Type of a buffered write/erase operation within a transaction.
flash_offset_t offset
Written header offset.
size_t size
Written data size.
mfs_id_t id
Record identifier.
Type of an non-cacheable MFS buffer.
uint8_t data8[MFS_CFG_BUFFER_SIZE]
uint16_t data16[MFS_CFG_BUFFER_SIZE/sizeof(uint16_t)]
uint32_t data32[MFS_CFG_BUFFER_SIZE/sizeof(uint32_t)]