diff options
-rw-r--r-- | os/hal/lib/complex/mfs/mfs.c | 13 | ||||
-rw-r--r-- | os/hal/lib/complex/mfs/mfs.h | 2 | ||||
-rw-r--r-- | testhal/STM32/multi/QSPI-MFS/main.c | 70 |
3 files changed, 23 insertions, 62 deletions
diff --git a/os/hal/lib/complex/mfs/mfs.c b/os/hal/lib/complex/mfs/mfs.c index 11c829eb4..a1decd519 100644 --- a/os/hal/lib/complex/mfs/mfs.c +++ b/os/hal/lib/complex/mfs/mfs.c @@ -442,7 +442,7 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp, hdr_offset = start_offset + (flash_offset_t)sizeof(mfs_bank_header_t);
while (hdr_offset < end_offset) {
/* Reading the current record header.*/
- RET_ON_ERROR(mfs_flash_read(mfsp, start_offset,
+ RET_ON_ERROR(mfs_flash_read(mfsp, hdr_offset,
sizeof (mfs_data_header_t),
(void *)&mfsp->buffer.dhdr));
@@ -632,12 +632,13 @@ static mfs_error_t mfs_garbage_collect(MFSDriver *mfsp) { /* Copying the most recent record instances only.*/
for (i = 0; i < MFS_CFG_MAX_RECORDS; i++) {
+ uint32_t totsize = mfsp->descriptors[i].size + sizeof (mfs_data_header_t);
if (mfsp->descriptors[i].offset != 0) {
RET_ON_ERROR(mfs_flash_copy(mfsp, dest_offset,
mfsp->descriptors[i].offset,
- mfsp->descriptors[i].size));
+ totsize));
mfsp->descriptors[i].offset = dest_offset;
- dest_offset += mfsp->descriptors[i].size;
+ dest_offset += totsize;
}
}
@@ -1059,15 +1060,15 @@ mfs_error_t mfsWriteRecord(MFSDriver *mfsp, uint32_t id, /* The size of the old record instance, if present, must be subtracted
to the total used size.*/
if (mfsp->descriptors[id - 1U].offset != 0U) {
- mfsp->used_space -= sizeof (mfs_data_header_t) +
- mfsp->descriptors[id - 1U].size;
+ mfsp->used_space -= sizeof (mfs_data_header_t) +
+ mfsp->descriptors[id - 1U].size;
}
/* Adjusting bank-related metadata.*/
mfsp->descriptors[id - 1U].offset = mfsp->next_offset;
mfsp->descriptors[id - 1U].size = (uint32_t)n;
mfsp->next_offset += sizeof (mfs_data_header_t) + n;
- mfsp->used_space -= sizeof (mfs_data_header_t) + n;
+ mfsp->used_space += sizeof (mfs_data_header_t) + n;
return warning ? MFS_WARN_GC : MFS_NO_ERROR;
}
diff --git a/os/hal/lib/complex/mfs/mfs.h b/os/hal/lib/complex/mfs/mfs.h index e3504e29a..49b1a342b 100644 --- a/os/hal/lib/complex/mfs/mfs.h +++ b/os/hal/lib/complex/mfs/mfs.h @@ -210,7 +210,7 @@ typedef union { * @brief Type of a data block header.
* @details This structure is placed before each written data block.
*/
-typedef struct {
+typedef union {
struct {
/**
* @brief Data header magic.
diff --git a/testhal/STM32/multi/QSPI-MFS/main.c b/testhal/STM32/multi/QSPI-MFS/main.c index c3c84a30a..9a874e47c 100644 --- a/testhal/STM32/multi/QSPI-MFS/main.c +++ b/testhal/STM32/multi/QSPI-MFS/main.c @@ -92,7 +92,7 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point.
*/
int main(void) {
- flash_error_t err;
+ mfs_error_t err;
uint8_t *addr;
/*
@@ -122,62 +122,22 @@ int main(void) { /* Mounting the MFS volume defined in the configuration.*/
mfsObjectInit(&mfs);
mfsStart(&mfs, &mfscfg1);
- mfsMount(&mfs);
+
+ err = mfsUnmount(&mfs);
+ err = mfsErase(&mfs);
+ err = mfsMount(&mfs);
+
+ err = mfsWriteRecord(&mfs, 1, 64, pattern);
+ err = mfsWriteRecord(&mfs, 2, 64, pattern);
+ err = mfsWriteRecord(&mfs, 1, 128, pattern);
+ err = mfsWriteRecord(&mfs, 2, 128, pattern);
+
+ err = mfsPerformGarbageCollection(&mfs);
/* Reading.*/
- err = flashRead(&m25q, 0, 128, buffer);
- if (err != FLASH_NO_ERROR)
- chSysHalt("read error");
-
- mfsUnmount(&mfs);
- mfsErase(&mfs);
-
-#if 0
- /* Erasing the first sector and waiting for completion.*/
- (void) flashStartEraseSector(&m25q, 0);
- err = flashWaitErase((BaseFlash *)&m25q);
- if (err != FLASH_NO_ERROR)
- chSysHalt("erase error");
-
- /* Verifying the erase operation.*/
- err = flashVerifyErase(&m25q, 0);
- if (err != FLASH_NO_ERROR)
- chSysHalt("verify erase error");
-
- /* Programming a pattern.*/
- err = flashProgram(&m25q, 0, 128, pattern);
- if (err != FLASH_NO_ERROR)
- chSysHalt("program error");
-
- /* Verifying the erase operation.*/
- err = flashVerifyErase(&m25q, 0);
- if (err != FLASH_ERROR_VERIFY)
- chSysHalt("verify non-erase error");
-
- /* Memory mapping the device.*/
- m25qMemoryMap(&m25q, &addr);
-
- /* Unmapping the device.*/
- m25qMemoryUnmap(&m25q);
-
- /* Reading it back.*/
- memset(buffer, 0, 128);
- err = flashRead(&m25q, 16, 128, buffer);
- if (err != FLASH_NO_ERROR)
- chSysHalt("read error");
-
- /* Reading it back.*/
- memset(buffer, 0, 128);
- err = flashRead(&m25q, 0, 128, buffer);
- if (err != FLASH_NO_ERROR)
- chSysHalt("read error");
-
- /* Erasing again.*/
- (void) flashStartEraseSector(&m25q, 0);
- err = flashWaitErase((BaseFlash *)&m25q);
- if (err != FLASH_NO_ERROR)
- chSysHalt("erase error");
-#endif
+ flashRead(&m25q, 0, 128, buffer);
+
+ err = mfsUnmount(&mfs);
/*
* Normal main() thread activity, in this demo it does nothing.
|