aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-11-13 16:30:27 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-11-13 16:30:27 +0000
commit08debc286839353dd5cba39d527214589686702e (patch)
treef8f06769e5e3ad2790110baa64a1995232750611 /os
parent1d6d312d43a5cceda95705b3a04eb21a5c4cb310 (diff)
downloadChibiOS-08debc286839353dd5cba39d527214589686702e.tar.gz
ChibiOS-08debc286839353dd5cba39d527214589686702e.tar.bz2
ChibiOS-08debc286839353dd5cba39d527214589686702e.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12417 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os')
-rw-r--r--os/hal/lib/complex/mfs/hal_mfs.c19
-rw-r--r--os/hal/lib/complex/mfs/hal_mfs.h38
2 files changed, 50 insertions, 7 deletions
diff --git a/os/hal/lib/complex/mfs/hal_mfs.c b/os/hal/lib/complex/mfs/hal_mfs.c
index d37326134..eadd3c9b4 100644
--- a/os/hal/lib/complex/mfs/hal_mfs.c
+++ b/os/hal/lib/complex/mfs/hal_mfs.c
@@ -276,11 +276,12 @@ static mfs_error_t mfs_record_check(MFSDriver *mfsp,
#if MFS_CFG_STRONG_CHECKING == TRUE
{
/* TODO: Checking the CRC while reading the record data.*/
- (void)mfsp;
+/* *sts = MFS_RECORD_CRC;
+ return MFS_NO_ERROR;*/
}
-#else
- (void)mfsp;
#endif
+ *sts = MFS_RECORD_OK;
+ return MFS_NO_ERROR;
}
}
@@ -439,6 +440,8 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp,
/* Scanning records.*/
hdr_offset = start_offset + (flash_offset_t)sizeof(mfs_bank_header_t);
while (hdr_offset < end_offset) {
+ uint32_t size;
+
/* Reading the current record header.*/
RET_ON_ERROR(mfs_flash_read(mfsp, hdr_offset,
sizeof (mfs_data_header_t),
@@ -453,7 +456,7 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp,
}
else if (sts == MFS_RECORD_OK) {
/* Record OK.*/
- uint32_t size = mfsp->buffer.dhdr.fields.size;
+ size = mfsp->buffer.dhdr.fields.size;
/* Zero-sized records are erase markers.*/
if (size == 0U) {
@@ -468,6 +471,7 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp,
else if (sts == MFS_RECORD_CRC) {
/* Record payload corrupted, scan can continue because the header
is OK.*/
+ size = mfsp->buffer.dhdr.fields.size;
warning = true;
}
else {
@@ -475,6 +479,9 @@ static mfs_error_t mfs_bank_scan_records(MFSDriver *mfsp,
warning = true;
break;
}
+ hdr_offset = hdr_offset +
+ (flash_offset_t)sizeof(mfs_data_header_t) +
+ (flash_offset_t)size;
}
if (hdr_offset > end_offset) {
@@ -926,7 +933,7 @@ mfs_error_t mfsReadRecord(MFSDriver *mfsp, mfs_id_t id,
uint16_t crc;
osalDbgCheck((mfsp != NULL) &&
- (id >= 1) && (id <= (mfs_id_t)MFS_CFG_MAX_RECORDS) &&
+ (id >= 1U) && (id <= (mfs_id_t)MFS_CFG_MAX_RECORDS) &&
(np != NULL) && (buffer != NULL));
if (mfsp->state != MFS_READY) {
@@ -992,7 +999,7 @@ mfs_error_t mfsWriteRecord(MFSDriver *mfsp, mfs_id_t id,
bool warning = false;
osalDbgCheck((mfsp != NULL) &&
- (id >= 1) && (id <= (mfs_id_t)MFS_CFG_MAX_RECORDS) &&
+ (id >= 1U) && (id <= (mfs_id_t)MFS_CFG_MAX_RECORDS) &&
(n > 0U) && (buffer != NULL));
if (mfsp->state != MFS_READY) {
diff --git a/os/hal/lib/complex/mfs/hal_mfs.h b/os/hal/lib/complex/mfs/hal_mfs.h
index 19c9b195f..56ff0b966 100644
--- a/os/hal/lib/complex/mfs/hal_mfs.h
+++ b/os/hal/lib/complex/mfs/hal_mfs.h
@@ -88,6 +88,23 @@
#if !defined(MFS_CFG_BUFFER_SIZE) || defined(__DOXYGEN__)
#define MFS_CFG_BUFFER_SIZE 32
#endif
+
+/**
+ * @brief Enforced memory alignment.
+ * @details This value must be a power of two, it enforces a memory alignment
+ * for records in the flash array. This is required when alignment
+ * constraints exist, for example when using a DTR mode on OSPI
+ * devices.
+ * @note When enforcing an alignment you need to use buffers with size
+ * aligned to the specified value. For example, if you need to
+ * write a 5 bytes object with alignment of 4 then you need to
+ * use a 8 bytes data buffer, the last 3 bytes are used as filler
+ * so ==initialize== those to zero (buffer->DDDDD000) or garbage
+ * will be written after data.
+ */
+#if !defined(MFS_CFG_MEMORY_ALIGNMENT) || defined(__DOXYGEN__)
+#define MFS_CFG_MEMORY_ALIGNMENT 1
+#endif
/** @} */
/*===========================================================================*/
@@ -102,7 +119,7 @@
#error "invalid MFS_MAX_REPAIR_ATTEMPTS value"
#endif
-#if MFS_CFG_BUFFER_SIZE <= 16
+#if MFS_CFG_BUFFER_SIZE < 16
#error "invalid MFS_CFG_BUFFER_SIZE value"
#endif
@@ -110,6 +127,14 @@
#error "MFS_CFG_BUFFER_SIZE is not a power of two"
#endif
+#if MFS_CFG_MEMORY_ALIGNMENT < 1
+#error "invalid MFS_CFG_MEMORY_ALIGNMENT value"
+#endif
+
+#if (MFS_CFG_MEMORY_ALIGNMENT & (MFS_CFG_MEMORY_ALIGNMENT - 1)) != 0
+#error "MFS_CFG_MEMORY_ALIGNMENT is not a power of two"
+#endif
+
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
@@ -228,6 +253,7 @@ typedef union {
uint16_t crc;
/**
* @brief Data size.
+ * @note The next record is located at @p MFS_ALIGN_NEXT(size).
*/
uint32_t size;
} fields;
@@ -343,6 +369,16 @@ typedef struct {
#define MFS_IS_WARNING(err) ((err) > MFS_NO_ERROR)
/** @} */
+/**
+ * @name Alignment macros
+ * @{
+ */
+#define MFS_ALIGN_MASK ((uint32_t)MFS_CFG_MEMORY_ALIGNMENT - 1U)
+#define MFS_IS_ALIGNED(v) (((uint32_t)(v) & MFS_ALIGN_MASK) == 0U)
+#define MFS_ALIGN_PREV(v) ((uint32_t)(v) & ~MFS_ALIGN_MASK)
+#define MFS_ALIGN_NEXT(v) MFS_ALIGN_PREV((size_t)(v) + MFS_ALIGN_MASK)
+/** @} */
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/