4 * Created on: Jul 3, 2013
8 #ifndef SPIFFS_CONFIG_H_
9 #define SPIFFS_CONFIG_H_
11 // ----------- 8< ------------
12 // Following includes are for the linux test build of spiffs
13 // These may/should/must be removed/altered/replaced in your target
21 // ----------- >8 ------------
23 #include "freertos/FreeRTOS.h"
24 #include "freertos/queue.h"
25 #include "freertos/semphr.h"
27 typedef signed int s32_t;
28 typedef unsigned int u32_t;
29 typedef signed short s16_t;
30 typedef unsigned short u16_t;
31 typedef signed char s8_t;
32 typedef unsigned char u8_t;
34 QueueHandle_t spiffs_mutex;
36 // compile time switches
38 // Set generic spiffs debug output call.
40 #define SPIFFS_DBG(...) //printf(__VA_ARGS__)
42 // Set spiffs debug output call for garbage collecting.
44 #define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
46 // Set spiffs debug output call for caching.
47 #ifndef SPIFFS_CACHE_DBG
48 #define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
50 // Set spiffs debug output call for system consistency checks.
51 #ifndef SPIFFS_CHECK_DBG
52 #define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
56 // Defines spiffs debug print formatters
57 // some general signed number
63 #define _SPIPRIad "%08x"
67 #define _SPIPRIbl "%04x"
71 #define _SPIPRIpg "%04x"
75 #define _SPIPRIsp "%04x"
79 #define _SPIPRIfd "%d"
83 #define _SPIPRIid "%04x"
87 #define _SPIPRIfl "%02x"
90 // Enable/disable API functions to determine exact number of bytes
91 // for filedescriptor and cache buffers. Once decided for a configuration,
92 // this can be disabled to reduce flash.
93 #ifndef SPIFFS_BUFFER_HELP
94 #define SPIFFS_BUFFER_HELP 0
97 // Enables/disable memory read caching of nucleus file system operations.
98 // If enabled, memory area must be provided for cache in SPIFFS_mount.
100 #define SPIFFS_CACHE 1
103 // Enables memory write caching for file descriptors in hydrogen
104 #ifndef SPIFFS_CACHE_WR
105 #define SPIFFS_CACHE_WR 1
108 // Enable/disable statistics on caching. Debug/test purpose only.
109 #ifndef SPIFFS_CACHE_STATS
110 #define SPIFFS_CACHE_STATS 0
114 // Always check header of each accessed page to ensure consistent state.
115 // If enabled it will increase number of reads, will increase flash.
116 #ifndef SPIFFS_PAGE_CHECK
117 #define SPIFFS_PAGE_CHECK 0
120 // Define maximum number of gc runs to perform to reach desired free pages.
121 #ifndef SPIFFS_GC_MAX_RUNS
122 #define SPIFFS_GC_MAX_RUNS 5
125 // Enable/disable statistics on gc. Debug/test purpose only.
126 #ifndef SPIFFS_GC_STATS
127 #define SPIFFS_GC_STATS 0
130 // Garbage collecting examines all pages in a block which and sums up
131 // to a block score. Deleted pages normally gives positive score and
132 // used pages normally gives a negative score (as these must be moved).
133 // To have a fair wear-leveling, the erase age is also included in score,
134 // whose factor normally is the most positive.
135 // The larger the score, the more likely it is that the block will
136 // picked for garbage collection.
138 // Garbage collecting heuristics - weight used for deleted pages.
139 #ifndef SPIFFS_GC_HEUR_W_DELET
140 #define SPIFFS_GC_HEUR_W_DELET (5)
142 // Garbage collecting heuristics - weight used for used pages.
143 #ifndef SPIFFS_GC_HEUR_W_USED
144 #define SPIFFS_GC_HEUR_W_USED (-1)
146 // Garbage collecting heuristics - weight used for time between
147 // last erased and erase of this block.
148 #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
149 #define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
152 // Object name maximum length. Note that this length include the
153 // zero-termination character, meaning maximum string of characters
154 // can at most be SPIFFS_OBJ_NAME_LEN - 1.
155 #ifndef SPIFFS_OBJ_NAME_LEN
156 #define SPIFFS_OBJ_NAME_LEN (64)
159 // Maximum length of the metadata associated with an object.
160 // Setting to non-zero value enables metadata-related API but also
161 // changes the on-disk format, so the change is not backward-compatible.
163 // Do note: the meta length must never exceed
164 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64)
166 // This is derived from following:
167 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
168 // spiffs_object_ix_header fields + at least some LUT entries)
169 #ifndef SPIFFS_OBJ_META_LEN
170 #define SPIFFS_OBJ_META_LEN (64)
173 // Size of buffer allocated on stack used when copying data.
174 // Lower value generates more read/writes. No meaning having it bigger
175 // than logical page size.
176 #ifndef SPIFFS_COPY_BUFFER_STACK
177 #define SPIFFS_COPY_BUFFER_STACK (256)
180 // Enable this to have an identifiable spiffs filesystem. This will look for
181 // a magic in all sectors to determine if this is a valid spiffs system or
182 // not on mount point. If not, SPIFFS_format must be called prior to mounting
184 #ifndef SPIFFS_USE_MAGIC
185 #define SPIFFS_USE_MAGIC (1)
189 // Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is
190 // enabled, the magic will also be dependent on the length of the filesystem.
191 // For example, a filesystem configured and formatted for 4 megabytes will not
192 // be accepted for mounting with a configuration defining the filesystem as 2
194 #ifndef SPIFFS_USE_MAGIC_LENGTH
195 #define SPIFFS_USE_MAGIC_LENGTH (1)
199 // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
200 // These should be defined on a multithreaded system
202 // define this to enter a mutex if you're running on a multithreaded system
204 #define SPIFFS_LOCK(fs) xSemaphoreTake(spiffs_mutex, portMAX_DELAY)
206 // define this to exit a mutex if you're running on a multithreaded system
207 #ifndef SPIFFS_UNLOCK
208 #define SPIFFS_UNLOCK(fs) xSemaphoreGive(spiffs_mutex)
211 // Enable if only one spiffs instance with constant configuration will exist
212 // on the target. This will reduce calculations, flash and memory accesses.
213 // Parts of configuration must be defined below instead of at time of mount.
214 #ifndef SPIFFS_SINGLETON
215 #define SPIFFS_SINGLETON 0
219 // Instead of giving parameters in config struct, singleton build must
220 // give parameters in defines below.
221 #ifndef SPIFFS_CFG_PHYS_SZ
222 #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2)
224 #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
225 #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536)
227 #ifndef SPIFFS_CFG_PHYS_ADDR
228 #define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
230 #ifndef SPIFFS_CFG_LOG_PAGE_SZ
231 #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
233 #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
234 #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536)
238 // Enable this if your target needs aligned data for index tables
239 #ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
240 #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
243 // Enable this if you want the HAL callbacks to be called with the spiffs struct
244 #ifndef SPIFFS_HAL_CALLBACK_EXTRA
245 #define SPIFFS_HAL_CALLBACK_EXTRA 0
248 // Enable this if you want to add an integer offset to all file handles
249 // (spiffs_file). This is useful if running multiple instances of spiffs on
250 // same target, in order to recognise to what spiffs instance a file handle
252 // NB: This adds config field fh_ix_offset in the configuration struct when
253 // mounting, which must be defined.
254 #ifndef SPIFFS_FILEHDL_OFFSET
255 #define SPIFFS_FILEHDL_OFFSET 0
258 // Enable this to compile a read only version of spiffs.
259 // This will reduce binary size of spiffs. All code comprising modification
260 // of the file system will not be compiled. Some config will be ignored.
261 // HAL functions for erasing and writing to spi-flash may be null. Cache
262 // can be disabled for even further binary size reduction (and ram savings).
263 // Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL.
264 // If the file system cannot be mounted due to aborted erase operation and
265 // SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be
267 // Might be useful for e.g. bootloaders and such.
268 #ifndef SPIFFS_READ_ONLY
269 #define SPIFFS_READ_ONLY 0
272 // Enable this to add a temporal file cache using the fd buffer.
273 // The effects of the cache is that SPIFFS_open will find the file faster in
274 // certain cases. It will make it a lot easier for spiffs to find files
275 // opened frequently, reducing number of readings from the spi flash for
276 // finding those files.
277 // This will grow each fd by 6 bytes. If your files are opened in patterns
278 // with a degree of temporal locality, the system is optimized.
279 // Examples can be letting spiffs serve web content, where one file is the css.
280 // The css is accessed for each html file that is opened, meaning it is
281 // accessed almost every second time a file is opened. Another example could be
282 // a log file that is often opened, written, and closed.
283 // The size of the cache is number of given file descriptors, as it piggybacks
284 // on the fd update mechanism. The cache lives in the closed file descriptors.
285 // When closed, the fd know the whereabouts of the file. Instead of forgetting
286 // this, the temporal cache will keep handling updates to that file even if the
287 // fd is closed. If the file is opened again, the location of the file is found
288 // directly. If all available descriptors become opened, all cache memory is
290 #ifndef SPIFFS_TEMPORAL_FD_CACHE
291 #define SPIFFS_TEMPORAL_FD_CACHE 1
294 // Temporal file cache hit score. Each time a file is opened, all cached files
295 // will lose one point. If the opened file is found in cache, that entry will
296 // gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this
297 // value for the specific access patterns of the application. However, it must
298 // be between 1 (no gain for hitting a cached entry often) and 255.
299 #ifndef SPIFFS_TEMPORAL_CACHE_HIT_SCORE
300 #define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 8
303 // Enable to be able to map object indices to memory.
304 // This allows for faster and more deterministic reading if cases of reading
305 // large files and when changing file offset by seeking around a lot.
306 // When mapping a file's index, the file system will be scanned for index pages
307 // and the info will be put in memory provided by user. When reading, the
308 // memory map can be looked up instead of searching for index pages on the
309 // medium. This way, user can trade memory against performance.
310 // Whole, parts of, or future parts not being written yet can be mapped. The
311 // memory array will be owned by spiffs and updated accordingly during garbage
312 // collecting or when modifying the indices. The latter is invoked by when the
313 // file is modified in some way. The index buffer is tied to the file
315 #ifndef SPIFFS_IX_MAP
316 #define SPIFFS_IX_MAP 1
319 // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
320 // in the api. This function will visualize all filesystem using given printf
322 #ifndef SPIFFS_TEST_VISUALISATION
323 #define SPIFFS_TEST_VISUALISATION 0
325 #if SPIFFS_TEST_VISUALISATION
326 #ifndef spiffs_printf
327 #define spiffs_printf(...) printf(__VA_ARGS__)
329 // spiffs_printf argument for a free page
330 #ifndef SPIFFS_TEST_VIS_FREE_STR
331 #define SPIFFS_TEST_VIS_FREE_STR "_"
333 // spiffs_printf argument for a deleted page
334 #ifndef SPIFFS_TEST_VIS_DELE_STR
335 #define SPIFFS_TEST_VIS_DELE_STR "/"
337 // spiffs_printf argument for an index page for given object id
338 #ifndef SPIFFS_TEST_VIS_INDX_STR
339 #define SPIFFS_TEST_VIS_INDX_STR(id) "i"
341 // spiffs_printf argument for a data page for given object id
342 #ifndef SPIFFS_TEST_VIS_DATA_STR
343 #define SPIFFS_TEST_VIS_DATA_STR(id) "d"
347 // Types depending on configuration such as the amount of flash bytes
348 // given to spiffs file system in total (spiffs_file_system_size),
349 // the logical block size (log_block_size), and the logical page size
352 // Block index type. Make sure the size of this type can hold
353 // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
354 typedef u16_t spiffs_block_ix;
355 // Page index type. Make sure the size of this type can hold
356 // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size
357 typedef u16_t spiffs_page_ix;
358 // Object id type - most significant bit is reserved for index flag. Make sure the
359 // size of this type can hold the highest object id on a full system,
360 // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2
361 typedef u16_t spiffs_obj_id;
362 // Object span index type. Make sure the size of this type can
363 // hold the largest possible span index on the system -
364 // i.e. (spiffs_file_system_size / log_page_size) - 1
365 typedef u16_t spiffs_span_ix;
367 #endif /* SPIFFS_CONFIG_H_ */