diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2019-04-14 10:56:33 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2019-04-14 10:56:33 +0000 |
commit | cd70e6ce8bc1bc3d4a000fd310f7853fb86ed07b (patch) | |
tree | a6b7c57d7c3f9e3d5d38e89c997bca16ba90ea59 /os | |
parent | 33479f263aff0e2c5354b9d22c43f759a05a4d52 (diff) | |
download | ChibiOS-cd70e6ce8bc1bc3d4a000fd310f7853fb86ed07b.tar.gz ChibiOS-cd70e6ce8bc1bc3d4a000fd310f7853fb86ed07b.tar.bz2 ChibiOS-cd70e6ce8bc1bc3d4a000fd310f7853fb86ed07b.zip |
Re-merged MFS from trunk.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_19.1.x@12742 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/lib/complex/mfs/hal_mfs.c | 61 | ||||
-rw-r--r-- | os/hal/lib/complex/mfs/hal_mfs.h | 15 |
2 files changed, 41 insertions, 35 deletions
diff --git a/os/hal/lib/complex/mfs/hal_mfs.c b/os/hal/lib/complex/mfs/hal_mfs.c index 2687fa8f8..f6e596e57 100644 --- a/os/hal/lib/complex/mfs/hal_mfs.c +++ b/os/hal/lib/complex/mfs/hal_mfs.c @@ -472,7 +472,8 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp, }
/* It is not erased so checking for integrity.*/
- if ((u.dhdr.fields.magic != MFS_HEADER_MAGIC) ||
+ if ((u.dhdr.fields.magic1 != MFS_HEADER_MAGIC_1) ||
+ (u.dhdr.fields.magic2 != MFS_HEADER_MAGIC_2) ||
(u.dhdr.fields.id < 1U) ||
(u.dhdr.fields.id > (uint32_t)MFS_CFG_MAX_RECORDS) ||
(u.dhdr.fields.size > end_offset - hdr_offset)) {
@@ -1037,14 +1038,13 @@ mfs_error_t mfsWriteRecord(MFSDriver *mfsp, mfs_id_t id, }
/* Writing the data header without the magic, it will be written last.*/
- mfsp->buffer.dhdr.fields.magic = (uint32_t)mfsp->config->erased;
- mfsp->buffer.dhdr.fields.id = (uint16_t)id;
- mfsp->buffer.dhdr.fields.size = (uint32_t)n;
- mfsp->buffer.dhdr.fields.crc = crc16(0xFFFFU, buffer, n);
+ mfsp->buffer.dhdr.fields.id = (uint16_t)id;
+ mfsp->buffer.dhdr.fields.size = (uint32_t)n;
+ mfsp->buffer.dhdr.fields.crc = crc16(0xFFFFU, buffer, n);
RET_ON_ERROR(mfs_flash_write(mfsp,
- mfsp->next_offset,
- sizeof (mfs_data_header_t),
- mfsp->buffer.data8));
+ mfsp->next_offset + (sizeof (uint32_t) * 2U),
+ sizeof (mfs_data_header_t) - (sizeof (uint32_t) * 2U),
+ mfsp->buffer.data8 + (sizeof (uint32_t) * 2U)));
/* Writing the data part.*/
RET_ON_ERROR(mfs_flash_write(mfsp,
@@ -1053,10 +1053,11 @@ mfs_error_t mfsWriteRecord(MFSDriver *mfsp, mfs_id_t id, buffer));
/* Finally writing the magic number, it seals the operation.*/
- mfsp->buffer.dhdr.fields.magic = (uint32_t)MFS_HEADER_MAGIC;
+ mfsp->buffer.dhdr.fields.magic1 = (uint32_t)MFS_HEADER_MAGIC_1;
+ mfsp->buffer.dhdr.fields.magic2 = (uint32_t)MFS_HEADER_MAGIC_2;
RET_ON_ERROR(mfs_flash_write(mfsp,
mfsp->next_offset,
- sizeof (uint32_t),
+ sizeof (uint32_t) * 2U,
mfsp->buffer.data8));
/* The size of the old record instance, if present, must be subtracted
@@ -1093,14 +1094,13 @@ mfs_error_t mfsWriteRecord(MFSDriver *mfsp, mfs_id_t id, }
/* Writing the data header without the magic, it will be written last.*/
- mfsp->buffer.dhdr.fields.magic = (uint32_t)mfsp->config->erased;
- mfsp->buffer.dhdr.fields.id = (uint16_t)id;
- mfsp->buffer.dhdr.fields.size = (uint32_t)n;
- mfsp->buffer.dhdr.fields.crc = crc16(0xFFFFU, buffer, n);
+ mfsp->buffer.dhdr.fields.id = (uint16_t)id;
+ mfsp->buffer.dhdr.fields.size = (uint32_t)n;
+ mfsp->buffer.dhdr.fields.crc = crc16(0xFFFFU, buffer, n);
RET_ON_ERROR(mfs_flash_write(mfsp,
- mfsp->tr_next_offset,
- sizeof (mfs_data_header_t),
- mfsp->buffer.data8));
+ mfsp->tr_next_offset + (sizeof (uint32_t) * 2U),
+ sizeof (mfs_data_header_t) - (sizeof (uint32_t) * 2U),
+ mfsp->buffer.data8 + (sizeof (uint32_t) * 2U)));
/* Writing the data part.*/
RET_ON_ERROR(mfs_flash_write(mfsp,
@@ -1189,10 +1189,11 @@ mfs_error_t mfsEraseRecord(MFSDriver *mfsp, mfs_id_t id) { /* Writing the data header with size set to zero, it means that the
record is logically erased.*/
- mfsp->buffer.dhdr.fields.magic = (uint32_t)MFS_HEADER_MAGIC;
- mfsp->buffer.dhdr.fields.id = (uint16_t)id;
- mfsp->buffer.dhdr.fields.size = (uint32_t)0;
- mfsp->buffer.dhdr.fields.crc = (uint16_t)0xFFFF;
+ mfsp->buffer.dhdr.fields.magic1 = (uint32_t)MFS_HEADER_MAGIC_1;
+ mfsp->buffer.dhdr.fields.magic2 = (uint32_t)MFS_HEADER_MAGIC_2;
+ mfsp->buffer.dhdr.fields.id = (uint16_t)id;
+ mfsp->buffer.dhdr.fields.size = (uint32_t)0;
+ mfsp->buffer.dhdr.fields.crc = (uint16_t)0xFFFF;
RET_ON_ERROR(mfs_flash_write(mfsp,
mfsp->next_offset,
sizeof (mfs_data_header_t),
@@ -1232,14 +1233,13 @@ mfs_error_t mfsEraseRecord(MFSDriver *mfsp, mfs_id_t id) { /* Writing the data header with size set to zero, it means that the
record is logically erased. Note, the magic number is not set.*/
- mfsp->buffer.dhdr.fields.magic = mfsp->config->erased;
- mfsp->buffer.dhdr.fields.id = (uint16_t)id;
- mfsp->buffer.dhdr.fields.size = (uint32_t)0;
- mfsp->buffer.dhdr.fields.crc = (uint16_t)0xFFFF;
+ mfsp->buffer.dhdr.fields.id = (uint16_t)id;
+ mfsp->buffer.dhdr.fields.size = (uint32_t)0;
+ mfsp->buffer.dhdr.fields.crc = (uint16_t)0xFFFF;
RET_ON_ERROR(mfs_flash_write(mfsp,
- mfsp->next_offset,
- sizeof (mfs_data_header_t),
- mfsp->buffer.data8));
+ mfsp->tr_next_offset + (sizeof (uint32_t) * 2U),
+ sizeof (mfs_data_header_t) - (sizeof (uint32_t) * 2U),
+ mfsp->buffer.data8 + (sizeof (uint32_t) * 2U)));
/* Adding a transaction operation record.*/
top = &mfsp->tr_ops[mfsp->tr_nops];
@@ -1385,7 +1385,8 @@ mfs_error_t mfsCommitTransaction(MFSDriver *mfsp) { }
/* Scanning all buffered operations in reverse order.*/
- mfsp->buffer.dhdr.fields.magic = (uint32_t)MFS_HEADER_MAGIC;
+ mfsp->buffer.dhdr.fields.magic1 = (uint32_t)MFS_HEADER_MAGIC_1;
+ mfsp->buffer.dhdr.fields.magic2 = (uint32_t)MFS_HEADER_MAGIC_2;
top = &mfsp->tr_ops[mfsp->tr_nops];
while (top > &mfsp->tr_ops[0]) {
/* On the previous element.*/
@@ -1394,7 +1395,7 @@ mfs_error_t mfsCommitTransaction(MFSDriver *mfsp) { /* Finalizing the operation by writing the magic number.*/
RET_ON_ERROR(mfs_flash_write(mfsp,
top->offset,
- sizeof (uint32_t),
+ sizeof (uint32_t) * 2U,
mfsp->buffer.data8));
}
diff --git a/os/hal/lib/complex/mfs/hal_mfs.h b/os/hal/lib/complex/mfs/hal_mfs.h index 14dfc75ee..43ffcbd47 100644 --- a/os/hal/lib/complex/mfs/hal_mfs.h +++ b/os/hal/lib/complex/mfs/hal_mfs.h @@ -36,7 +36,8 @@ #define MFS_BANK_MAGIC_1 0xEC705ADEU
#define MFS_BANK_MAGIC_2 0xF0339CC5U
-#define MFS_HEADER_MAGIC 0x5FAE45F0U
+#define MFS_HEADER_MAGIC_1 0x5FAE45F0U
+#define MFS_HEADER_MAGIC_2 0xF045AE5FU
/*===========================================================================*/
/* Driver pre-compile time settings. */
@@ -240,9 +241,13 @@ typedef union { typedef union {
struct {
/**
- * @brief Data header magic.
+ * @brief Data header magic 1.
*/
- uint32_t magic;
+ uint32_t magic1;
+ /**
+ * @brief Data header magic 2.
+ */
+ uint32_t magic2;
/**
* @brief Record identifier.
*/
@@ -257,8 +262,8 @@ typedef union { */
uint32_t size;
} fields;
- uint8_t hdr8[12];
- uint32_t hdr32[3];
+ uint8_t hdr8[16];
+ uint32_t hdr32[4];
} mfs_data_header_t;
typedef struct {
|