Filesystem library designed for flash devices
Dependents: flash-fs-example Dragonfly_Filesystem_Example STM32F407VET6_SPIFlash Dragonfly_Filesystem_Example_mbed_5
spiffs_config.h@0:bb4e812f7c97, 2014-12-16 (annotated)
- Committer:
- mfiore
- Date:
- Tue Dec 16 15:13:10 2014 +0000
- Revision:
- 0:bb4e812f7c97
- Child:
- 3:9adcf49bb77d
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:bb4e812f7c97 | 1 | /* |
mfiore | 0:bb4e812f7c97 | 2 | * spiffs_config.h |
mfiore | 0:bb4e812f7c97 | 3 | * |
mfiore | 0:bb4e812f7c97 | 4 | * Created on: Jul 3, 2013 |
mfiore | 0:bb4e812f7c97 | 5 | * Author: petera |
mfiore | 0:bb4e812f7c97 | 6 | */ |
mfiore | 0:bb4e812f7c97 | 7 | |
mfiore | 0:bb4e812f7c97 | 8 | #ifndef SPIFFS_CONFIG_H_ |
mfiore | 0:bb4e812f7c97 | 9 | #define SPIFFS_CONFIG_H_ |
mfiore | 0:bb4e812f7c97 | 10 | |
mfiore | 0:bb4e812f7c97 | 11 | // ----------- 8< ------------ |
mfiore | 0:bb4e812f7c97 | 12 | // Following includes are for the linux test build of spiffs |
mfiore | 0:bb4e812f7c97 | 13 | // These may/should/must be removed/altered/replaced in your target |
mfiore | 0:bb4e812f7c97 | 14 | #include <stdio.h> |
mfiore | 0:bb4e812f7c97 | 15 | #include <stdlib.h> |
mfiore | 0:bb4e812f7c97 | 16 | #include <string.h> |
mfiore | 0:bb4e812f7c97 | 17 | #include <stddef.h> |
mfiore | 0:bb4e812f7c97 | 18 | // ----------- >8 ------------ |
mfiore | 0:bb4e812f7c97 | 19 | |
mfiore | 0:bb4e812f7c97 | 20 | typedef signed int s32_t; |
mfiore | 0:bb4e812f7c97 | 21 | typedef unsigned int u32_t; |
mfiore | 0:bb4e812f7c97 | 22 | typedef signed short s16_t; |
mfiore | 0:bb4e812f7c97 | 23 | typedef unsigned short u16_t; |
mfiore | 0:bb4e812f7c97 | 24 | typedef signed char s8_t;; |
mfiore | 0:bb4e812f7c97 | 25 | typedef unsigned char u8_t; |
mfiore | 0:bb4e812f7c97 | 26 | |
mfiore | 0:bb4e812f7c97 | 27 | // compile time switches |
mfiore | 0:bb4e812f7c97 | 28 | |
mfiore | 0:bb4e812f7c97 | 29 | // Set generic spiffs debug output call. |
mfiore | 0:bb4e812f7c97 | 30 | #ifndef SPIFFS_DGB |
mfiore | 0:bb4e812f7c97 | 31 | #define SPIFFS_DBG(...) |
mfiore | 0:bb4e812f7c97 | 32 | #endif |
mfiore | 0:bb4e812f7c97 | 33 | // Set spiffs debug output call for garbage collecting. |
mfiore | 0:bb4e812f7c97 | 34 | #ifndef SPIFFS_GC_DGB |
mfiore | 0:bb4e812f7c97 | 35 | #define SPIFFS_GC_DBG(...) |
mfiore | 0:bb4e812f7c97 | 36 | #endif |
mfiore | 0:bb4e812f7c97 | 37 | // Set spiffs debug output call for caching. |
mfiore | 0:bb4e812f7c97 | 38 | #ifndef SPIFFS_CACHE_DGB |
mfiore | 0:bb4e812f7c97 | 39 | #define SPIFFS_CACHE_DBG(...) |
mfiore | 0:bb4e812f7c97 | 40 | #endif |
mfiore | 0:bb4e812f7c97 | 41 | // Set spiffs debug output call for system consistency checks. |
mfiore | 0:bb4e812f7c97 | 42 | #ifndef SPIFFS_CHECK_DGB |
mfiore | 0:bb4e812f7c97 | 43 | #define SPIFFS_CHECK_DBG(...) |
mfiore | 0:bb4e812f7c97 | 44 | #endif |
mfiore | 0:bb4e812f7c97 | 45 | |
mfiore | 0:bb4e812f7c97 | 46 | // Enable/disable API functions to determine exact number of bytes |
mfiore | 0:bb4e812f7c97 | 47 | // for filedescriptor and cache buffers. Once decided for a configuration, |
mfiore | 0:bb4e812f7c97 | 48 | // this can be disabled to reduce flash. |
mfiore | 0:bb4e812f7c97 | 49 | #ifndef SPIFFS_BUFFER_HELP |
mfiore | 0:bb4e812f7c97 | 50 | #define SPIFFS_BUFFER_HELP 0 |
mfiore | 0:bb4e812f7c97 | 51 | #endif |
mfiore | 0:bb4e812f7c97 | 52 | |
mfiore | 0:bb4e812f7c97 | 53 | // Enables/disable memory read caching of nucleus file system operations. |
mfiore | 0:bb4e812f7c97 | 54 | // If enabled, memory area must be provided for cache in SPIFFS_mount. |
mfiore | 0:bb4e812f7c97 | 55 | #ifndef SPIFFS_CACHE |
mfiore | 0:bb4e812f7c97 | 56 | #define SPIFFS_CACHE 1 |
mfiore | 0:bb4e812f7c97 | 57 | #endif |
mfiore | 0:bb4e812f7c97 | 58 | #if SPIFFS_CACHE |
mfiore | 0:bb4e812f7c97 | 59 | // Enables memory write caching for file descriptors in hydrogen |
mfiore | 0:bb4e812f7c97 | 60 | #ifndef SPIFFS_CACHE_WR |
mfiore | 0:bb4e812f7c97 | 61 | #define SPIFFS_CACHE_WR 1 |
mfiore | 0:bb4e812f7c97 | 62 | #endif |
mfiore | 0:bb4e812f7c97 | 63 | |
mfiore | 0:bb4e812f7c97 | 64 | // Enable/disable statistics on caching. Debug/test purpose only. |
mfiore | 0:bb4e812f7c97 | 65 | #ifndef SPIFFS_CACHE_STATS |
mfiore | 0:bb4e812f7c97 | 66 | #define SPIFFS_CACHE_STATS 0 |
mfiore | 0:bb4e812f7c97 | 67 | #endif |
mfiore | 0:bb4e812f7c97 | 68 | #endif |
mfiore | 0:bb4e812f7c97 | 69 | |
mfiore | 0:bb4e812f7c97 | 70 | // Always check header of each accessed page to ensure consistent state. |
mfiore | 0:bb4e812f7c97 | 71 | // If enabled it will increase number of reads, will increase flash. |
mfiore | 0:bb4e812f7c97 | 72 | #ifndef SPIFFS_PAGE_CHECK |
mfiore | 0:bb4e812f7c97 | 73 | #define SPIFFS_PAGE_CHECK 1 |
mfiore | 0:bb4e812f7c97 | 74 | #endif |
mfiore | 0:bb4e812f7c97 | 75 | |
mfiore | 0:bb4e812f7c97 | 76 | // Define maximum number of gc runs to perform to reach desired free pages. |
mfiore | 0:bb4e812f7c97 | 77 | #ifndef SPIFFS_GC_MAX_RUNS |
mfiore | 0:bb4e812f7c97 | 78 | #define SPIFFS_GC_MAX_RUNS 3 |
mfiore | 0:bb4e812f7c97 | 79 | #endif |
mfiore | 0:bb4e812f7c97 | 80 | |
mfiore | 0:bb4e812f7c97 | 81 | // Enable/disable statistics on gc. Debug/test purpose only. |
mfiore | 0:bb4e812f7c97 | 82 | #ifndef SPIFFS_GC_STATS |
mfiore | 0:bb4e812f7c97 | 83 | #define SPIFFS_GC_STATS 0 |
mfiore | 0:bb4e812f7c97 | 84 | #endif |
mfiore | 0:bb4e812f7c97 | 85 | |
mfiore | 0:bb4e812f7c97 | 86 | // Garbage collecting examines all pages in a block which and sums up |
mfiore | 0:bb4e812f7c97 | 87 | // to a block score. Deleted pages normally gives positive score and |
mfiore | 0:bb4e812f7c97 | 88 | // used pages normally gives a negative score (as these must be moved). |
mfiore | 0:bb4e812f7c97 | 89 | // To have a fair wear-leveling, the erase age is also included in score, |
mfiore | 0:bb4e812f7c97 | 90 | // whose factor normally is the most positive. |
mfiore | 0:bb4e812f7c97 | 91 | // The larger the score, the more likely it is that the block will |
mfiore | 0:bb4e812f7c97 | 92 | // picked for garbage collection. |
mfiore | 0:bb4e812f7c97 | 93 | |
mfiore | 0:bb4e812f7c97 | 94 | // Garbage collecting heuristics - weight used for deleted pages. |
mfiore | 0:bb4e812f7c97 | 95 | #ifndef SPIFFS_GC_HEUR_W_DELET |
mfiore | 0:bb4e812f7c97 | 96 | #define SPIFFS_GC_HEUR_W_DELET (5) |
mfiore | 0:bb4e812f7c97 | 97 | #endif |
mfiore | 0:bb4e812f7c97 | 98 | // Garbage collecting heuristics - weight used for used pages. |
mfiore | 0:bb4e812f7c97 | 99 | #ifndef SPIFFS_GC_HEUR_W_USED |
mfiore | 0:bb4e812f7c97 | 100 | #define SPIFFS_GC_HEUR_W_USED (-1) |
mfiore | 0:bb4e812f7c97 | 101 | #endif |
mfiore | 0:bb4e812f7c97 | 102 | // Garbage collecting heuristics - weight used for time between |
mfiore | 0:bb4e812f7c97 | 103 | // last erased and erase of this block. |
mfiore | 0:bb4e812f7c97 | 104 | #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE |
mfiore | 0:bb4e812f7c97 | 105 | #define SPIFFS_GC_HEUR_W_ERASE_AGE (50) |
mfiore | 0:bb4e812f7c97 | 106 | #endif |
mfiore | 0:bb4e812f7c97 | 107 | |
mfiore | 0:bb4e812f7c97 | 108 | // Object name maximum length. |
mfiore | 0:bb4e812f7c97 | 109 | #ifndef SPIFFS_OBJ_NAME_LEN |
mfiore | 0:bb4e812f7c97 | 110 | #define SPIFFS_OBJ_NAME_LEN (32) |
mfiore | 0:bb4e812f7c97 | 111 | #endif |
mfiore | 0:bb4e812f7c97 | 112 | |
mfiore | 0:bb4e812f7c97 | 113 | // Size of buffer allocated on stack used when copying data. |
mfiore | 0:bb4e812f7c97 | 114 | // Lower value generates more read/writes. No meaning having it bigger |
mfiore | 0:bb4e812f7c97 | 115 | // than logical page size. |
mfiore | 0:bb4e812f7c97 | 116 | #ifndef SPIFFS_COPY_BUFFER_STACK |
mfiore | 0:bb4e812f7c97 | 117 | #define SPIFFS_COPY_BUFFER_STACK (64) |
mfiore | 0:bb4e812f7c97 | 118 | #endif |
mfiore | 0:bb4e812f7c97 | 119 | |
mfiore | 0:bb4e812f7c97 | 120 | // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level |
mfiore | 0:bb4e812f7c97 | 121 | // These should be defined on a multithreaded system |
mfiore | 0:bb4e812f7c97 | 122 | |
mfiore | 0:bb4e812f7c97 | 123 | // define this to entering a mutex if you're running on a multithreaded system |
mfiore | 0:bb4e812f7c97 | 124 | #ifndef SPIFFS_LOCK |
mfiore | 0:bb4e812f7c97 | 125 | #define SPIFFS_LOCK(fs) |
mfiore | 0:bb4e812f7c97 | 126 | #endif |
mfiore | 0:bb4e812f7c97 | 127 | // define this to exiting a mutex if you're running on a multithreaded system |
mfiore | 0:bb4e812f7c97 | 128 | #ifndef SPIFFS_UNLOCK |
mfiore | 0:bb4e812f7c97 | 129 | #define SPIFFS_UNLOCK(fs) |
mfiore | 0:bb4e812f7c97 | 130 | #endif |
mfiore | 0:bb4e812f7c97 | 131 | |
mfiore | 0:bb4e812f7c97 | 132 | |
mfiore | 0:bb4e812f7c97 | 133 | // Enable if only one spiffs instance with constant configuration will exist |
mfiore | 0:bb4e812f7c97 | 134 | // on the target. This will reduce calculations, flash and memory accesses. |
mfiore | 0:bb4e812f7c97 | 135 | // Parts of configuration must be defined below instead of at time of mount. |
mfiore | 0:bb4e812f7c97 | 136 | #ifndef SPIFFS_SINGLETON |
mfiore | 0:bb4e812f7c97 | 137 | #define SPIFFS_SINGLETON 0 |
mfiore | 0:bb4e812f7c97 | 138 | #endif |
mfiore | 0:bb4e812f7c97 | 139 | |
mfiore | 0:bb4e812f7c97 | 140 | #if SPIFFS_SINGLETON |
mfiore | 0:bb4e812f7c97 | 141 | // Instead of giving parameters in config struct, singleton build must |
mfiore | 0:bb4e812f7c97 | 142 | // give parameters in defines below. |
mfiore | 0:bb4e812f7c97 | 143 | #ifndef SPIFFS_CFG_PHYS_SZ |
mfiore | 0:bb4e812f7c97 | 144 | #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2) |
mfiore | 0:bb4e812f7c97 | 145 | #endif |
mfiore | 0:bb4e812f7c97 | 146 | #ifndef SPIFFS_CFG_PHYS_ERASE_SZ |
mfiore | 0:bb4e812f7c97 | 147 | #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536) |
mfiore | 0:bb4e812f7c97 | 148 | #endif |
mfiore | 0:bb4e812f7c97 | 149 | #ifndef SPIFFS_CFG_PHYS_ADDR |
mfiore | 0:bb4e812f7c97 | 150 | #define SPIFFS_CFG_PHYS_ADDR(ignore) (0) |
mfiore | 0:bb4e812f7c97 | 151 | #endif |
mfiore | 0:bb4e812f7c97 | 152 | #ifndef SPIFFS_CFG_LOG_PAGE_SZ |
mfiore | 0:bb4e812f7c97 | 153 | #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256) |
mfiore | 0:bb4e812f7c97 | 154 | #endif |
mfiore | 0:bb4e812f7c97 | 155 | #ifndef SPIFFS_CFG_LOG_BLOCK_SZ |
mfiore | 0:bb4e812f7c97 | 156 | #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536) |
mfiore | 0:bb4e812f7c97 | 157 | #endif |
mfiore | 0:bb4e812f7c97 | 158 | #endif |
mfiore | 0:bb4e812f7c97 | 159 | |
mfiore | 0:bb4e812f7c97 | 160 | // Set SPFIFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function |
mfiore | 0:bb4e812f7c97 | 161 | // in the api. This function will visualize all filesystem using given printf |
mfiore | 0:bb4e812f7c97 | 162 | // function. |
mfiore | 0:bb4e812f7c97 | 163 | #ifndef SPIFFS_TEST_VISUALISATION |
mfiore | 0:bb4e812f7c97 | 164 | #define SPIFFS_TEST_VISUALISATION 1 |
mfiore | 0:bb4e812f7c97 | 165 | #endif |
mfiore | 0:bb4e812f7c97 | 166 | #if SPIFFS_TEST_VISUALISATION |
mfiore | 0:bb4e812f7c97 | 167 | #ifndef spiffs_printf |
mfiore | 0:bb4e812f7c97 | 168 | #define spiffs_printf(...) printf(__VA_ARGS__) |
mfiore | 0:bb4e812f7c97 | 169 | #endif |
mfiore | 0:bb4e812f7c97 | 170 | // spiffs_printf argument for a free page |
mfiore | 0:bb4e812f7c97 | 171 | #ifndef SPIFFS_TEST_VIS_FREE_STR |
mfiore | 0:bb4e812f7c97 | 172 | #define SPIFFS_TEST_VIS_FREE_STR "_" |
mfiore | 0:bb4e812f7c97 | 173 | #endif |
mfiore | 0:bb4e812f7c97 | 174 | // spiffs_printf argument for a deleted page |
mfiore | 0:bb4e812f7c97 | 175 | #ifndef SPIFFS_TEST_VIS_DELE_STR |
mfiore | 0:bb4e812f7c97 | 176 | #define SPIFFS_TEST_VIS_DELE_STR "/" |
mfiore | 0:bb4e812f7c97 | 177 | #endif |
mfiore | 0:bb4e812f7c97 | 178 | // spiffs_printf argument for an index page for given object id |
mfiore | 0:bb4e812f7c97 | 179 | #ifndef SPIFFS_TEST_VIS_INDX_STR |
mfiore | 0:bb4e812f7c97 | 180 | #define SPIFFS_TEST_VIS_INDX_STR(id) "i" |
mfiore | 0:bb4e812f7c97 | 181 | #endif |
mfiore | 0:bb4e812f7c97 | 182 | // spiffs_printf argument for a data page for given object id |
mfiore | 0:bb4e812f7c97 | 183 | #ifndef SPIFFS_TEST_VIS_DATA_STR |
mfiore | 0:bb4e812f7c97 | 184 | #define SPIFFS_TEST_VIS_DATA_STR(id) "d" |
mfiore | 0:bb4e812f7c97 | 185 | #endif |
mfiore | 0:bb4e812f7c97 | 186 | #endif |
mfiore | 0:bb4e812f7c97 | 187 | |
mfiore | 0:bb4e812f7c97 | 188 | // Types depending on configuration such as the amount of flash bytes |
mfiore | 0:bb4e812f7c97 | 189 | // given to spiffs file system in total (spiffs_file_system_size), |
mfiore | 0:bb4e812f7c97 | 190 | // the logical block size (log_block_size), and the logical page size |
mfiore | 0:bb4e812f7c97 | 191 | // (log_page_size) |
mfiore | 0:bb4e812f7c97 | 192 | |
mfiore | 0:bb4e812f7c97 | 193 | // Block index type. Make sure the size of this type can hold |
mfiore | 0:bb4e812f7c97 | 194 | // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size |
mfiore | 0:bb4e812f7c97 | 195 | typedef u8_t spiffs_block_ix; |
mfiore | 0:bb4e812f7c97 | 196 | // Page index type. Make sure the size of this type can hold |
mfiore | 0:bb4e812f7c97 | 197 | // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size |
mfiore | 0:bb4e812f7c97 | 198 | typedef u16_t spiffs_page_ix; |
mfiore | 0:bb4e812f7c97 | 199 | // Object id type - most significant bit is reserved for index flag. Make sure the |
mfiore | 0:bb4e812f7c97 | 200 | // size of this type can hold the highest object id on a full system, |
mfiore | 0:bb4e812f7c97 | 201 | // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2 |
mfiore | 0:bb4e812f7c97 | 202 | typedef u16_t spiffs_obj_id; |
mfiore | 0:bb4e812f7c97 | 203 | // Object span index type. Make sure the size of this type can |
mfiore | 0:bb4e812f7c97 | 204 | // hold the largest possible span index on the system - |
mfiore | 0:bb4e812f7c97 | 205 | // i.e. (spiffs_file_system_size / log_page_size) - 1 |
mfiore | 0:bb4e812f7c97 | 206 | typedef u16_t spiffs_span_ix; |
mfiore | 0:bb4e812f7c97 | 207 | |
mfiore | 0:bb4e812f7c97 | 208 | #endif /* SPIFFS_CONFIG_H_ */ |