aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-06-09 17:09:02 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-06-09 17:09:02 +0000
commit0453f8b4366a66626ee9b4eaf300dd6c803ecc2d (patch)
treeacaf9e01a0ed67929403aff4817c4dd4911b190d
parenta104f03cd77472943129fe9d8985c100e23a0dbf (diff)
downloadChibiOS-0453f8b4366a66626ee9b4eaf300dd6c803ecc2d.tar.gz
ChibiOS-0453f8b4366a66626ee9b4eaf300dd6c803ecc2d.tar.bz2
ChibiOS-0453f8b4366a66626ee9b4eaf300dd6c803ecc2d.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9611 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/ex/subsystems/mfs/mfs.h110
1 files changed, 104 insertions, 6 deletions
diff --git a/os/ex/subsystems/mfs/mfs.h b/os/ex/subsystems/mfs/mfs.h
index 61310f91d..79e1e1023 100644
--- a/os/ex/subsystems/mfs/mfs.h
+++ b/os/ex/subsystems/mfs/mfs.h
@@ -41,17 +41,37 @@
* @name Configuration options
* @{
*/
+/**
+ * @brief Record identifiers cache size.
+ * @details Cache trades RAM for a faster access to stored records. If zero
+ * then the cache is disabled.
+ */
+#if !defined(MFS_CFG_ID_CACHE_SIZE) || defined(__DOXIGEN__)
+#define MFS_CFG_ID_CACHE_SIZE 16
+#endif
/** @} */
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
+#if MFS_CFG_ID_CACHE_SIZE < 0
+#error "invalid MFS_CFG_ID_CACHE_SIZE value"
+#endif
+
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/**
+ * @brief Type of a flash bank.
+ */
+typedef enum {
+ MFS_BANK_0 = 0,
+ MFS_BANK_1 = 1
+} mfs_bank_t;
+
+/**
* @brief Type of driver state machine states.
*/
typedef enum {
@@ -77,6 +97,16 @@ typedef enum {
} mfs_error_t;
/**
+ * @brief Type of a bank state assessment.
+ */
+typedef enum {
+ MFS_BANK_OK = 0,
+ MFS_BANK_ERASED = 1,
+ MFS_BANK_PROBLEMS = 2,
+ MFS_BANK_GARBAGE = 3
+} mfs_bank_state_t;
+
+/**
* @brief Type of a bank header.
* @note The header resides in the first 16 bytes of a bank extending
* to the next page boundary.
@@ -108,7 +138,11 @@ typedef union {
/**
* @brief Data header magic.
*/
- uint32_t magic;
+ uint16_t magic;
+ /**
+ * @brief Data CRC.
+ */
+ uint16_t crc;
/**
* @brief Data identifier.
*/
@@ -117,15 +151,53 @@ typedef union {
* @brief Data size.
*/
uint32_t size;
- /**
- * @brief Data CRC.
- */
- uint32_t crc;
} fields;
uint8_t h8[16];
uint32_t h32[4];
} mfs_data_header_t;
+#if (MFS_CFG_ID_CACHE_SIZE > 0) || defined(__DOXYGEN__)
+/**
+ * @brief Type of an element of the record identifiers cache.
+ */
+typedef struct mfs_cached_id {
+ /**
+ * @brief Pointer to the next element in the list.
+ */
+ struct mfs_cached_id *lru_next;
+ /**
+ * @brief Pointer to the previous element in the list.
+ */
+ struct mfs_cached_id *lru_prev;
+ /**
+ * @brief Identifier of the cached element.
+ */
+ uint32_t id;
+ /**
+ * @brief Data address of the cached element.
+ */
+ flash_address_t addr;
+ /**
+ * @brief Data size of the cached element.
+ */
+ uint32_t size;
+} mfs_cached_id_t;
+
+/**
+ * @brief Type of an element of the record identifiers cache.
+ */
+typedef struct mfs_cache_header {
+ /**
+ * @brief Pointer to the first element in the list.
+ */
+ struct mfs_cached_id *lru_next;
+ /**
+ * @brief Pointer to the last element in the list.
+ */
+ struct mfs_cached_id *lru_prev;
+} mfs_cache_header_t;
+#endif /* MFS_CFG_ID_CACHE_SIZE > 0 */
+
/**
* @brief Type of a MFS configuration structure.
*/
@@ -151,7 +223,7 @@ typedef struct {
*/
flash_sector_t bank1_sectors;
} MFSConfig;
-
+
/**
* @extends BaseFlash
*
@@ -166,6 +238,32 @@ typedef struct {
* @brief Current configuration data.
*/
const MFSConfig *config;
+ /**
+ * @brief Bank currently in use.
+ */
+ mfs_bank_t current_bank;
+ /**
+ * @brief Size in bytes of banks.
+ */
+ uint32_t banks_size;
+ /**
+ * @brief Pointer to the next free position in the current bank.
+ */
+ flash_address_t next_position;
+ /**
+ * @brief Used space in the current bank without considering erased records.
+ */
+ uint32_t used_space;
+#if (MFS_CFG_ID_CACHE_SIZE > 0) || defined(__DOXYGEN__)
+ /**
+ * @brief Header of the cache LRU list.
+ */
+ mfs_cache_header_t cache_header;
+ /**
+ * @brief Array of the cached identifiers.
+ */
+ mfs_cached_id_t cache_buffer[MFS_CFG_ID_CACHE_SIZE];
+#endif /* MFS_CFG_ID_CACHE_SIZE > 0 */
} MFSDriver;
/*===========================================================================*/