spiffs_config.h
Go to the documentation of this file.
1 /*
2  * spiffs_config.h
3  *
4  * Created on: Jul 3, 2013
5  * Author: petera
6  */
7 
8 #ifndef SPIFFS_CONFIG_H_
9 #define SPIFFS_CONFIG_H_
10 
11 #include <stddef.h>
12 #include <stdint.h>
13 #include <string.h>
14 
15 /* Type definitions */
16 typedef int32_t s32_t;
17 typedef uint32_t u32_t;
18 typedef int16_t s16_t;
19 typedef uint16_t u16_t;
20 typedef int8_t s8_t;
21 typedef uint8_t u8_t;
22 
23 // compile time switches
24 
25 // Set generic spiffs debug output call.
26 #ifndef SPIFFS_DBG
27 #define SPIFFS_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
28 #endif
29 // Set spiffs debug output call for garbage collecting.
30 #ifndef SPIFFS_GC_DBG
31 #define SPIFFS_GC_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
32 #endif
33 // Set spiffs debug output call for caching.
34 #ifndef SPIFFS_CACHE_DBG
35 #define SPIFFS_CACHE_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
36 #endif
37 // Set spiffs debug output call for system consistency checks.
38 #ifndef SPIFFS_CHECK_DBG
39 #define SPIFFS_CHECK_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
40 #endif
41 // Set spiffs debug output call for all api invocations.
42 #ifndef SPIFFS_API_DBG
43 #define SPIFFS_API_DBG(_f, ...) //printf(_f, ## __VA_ARGS__)
44 #endif
45 
46 
47 
48 // Defines spiffs debug print formatters
49 // some general signed number
50 #ifndef _SPIPRIi
51 #define _SPIPRIi "%d"
52 #endif
53 // address
54 #ifndef _SPIPRIad
55 #define _SPIPRIad "%08x"
56 #endif
57 // block
58 #ifndef _SPIPRIbl
59 #define _SPIPRIbl "%04x"
60 #endif
61 // page
62 #ifndef _SPIPRIpg
63 #define _SPIPRIpg "%04x"
64 #endif
65 // span index
66 #ifndef _SPIPRIsp
67 #define _SPIPRIsp "%04x"
68 #endif
69 // file descriptor
70 #ifndef _SPIPRIfd
71 #define _SPIPRIfd "%d"
72 #endif
73 // file object id
74 #ifndef _SPIPRIid
75 #define _SPIPRIid "%04x"
76 #endif
77 // file flags
78 #ifndef _SPIPRIfl
79 #define _SPIPRIfl "%02x"
80 #endif
81 
82 
83 // Enable/disable API functions to determine exact number of bytes
84 // for filedescriptor and cache buffers. Once decided for a configuration,
85 // this can be disabled to reduce flash.
86 #ifndef SPIFFS_BUFFER_HELP
87 #define SPIFFS_BUFFER_HELP 1
88 #endif
89 
90 // Enables/disable memory read caching of nucleus file system operations.
91 // If enabled, memory area must be provided for cache in SPIFFS_mount.
92 #ifndef SPIFFS_CACHE
93 #define SPIFFS_CACHE 1
94 #endif
95 #if SPIFFS_CACHE
96 // Enables memory write caching for file descriptors in hydrogen
97 #ifndef SPIFFS_CACHE_WR
98 #define SPIFFS_CACHE_WR 1
99 #endif
100 
101 // Enable/disable statistics on caching. Debug/test purpose only.
102 #ifndef SPIFFS_CACHE_STATS
103 #define SPIFFS_CACHE_STATS 0
104 #endif
105 #endif
106 
107 // Always check header of each accessed page to ensure consistent state.
108 // If enabled it will increase number of reads, will increase flash.
109 #ifndef SPIFFS_PAGE_CHECK
110 #define SPIFFS_PAGE_CHECK 1
111 #endif
112 
113 // Define maximum number of gc runs to perform to reach desired free pages.
114 #ifndef SPIFFS_GC_MAX_RUNS
115 #define SPIFFS_GC_MAX_RUNS 5
116 #endif
117 
118 // Enable/disable statistics on gc. Debug/test purpose only.
119 #ifndef SPIFFS_GC_STATS
120 #define SPIFFS_GC_STATS 0
121 #endif
122 
123 // Garbage collecting examines all pages in a block which and sums up
124 // to a block score. Deleted pages normally gives positive score and
125 // used pages normally gives a negative score (as these must be moved).
126 // To have a fair wear-leveling, the erase age is also included in score,
127 // whose factor normally is the most positive.
128 // The larger the score, the more likely it is that the block will
129 // picked for garbage collection.
130 
131 // Garbage collecting heuristics - weight used for deleted pages.
132 #ifndef SPIFFS_GC_HEUR_W_DELET
133 #define SPIFFS_GC_HEUR_W_DELET (5)
134 #endif
135 // Garbage collecting heuristics - weight used for used pages.
136 #ifndef SPIFFS_GC_HEUR_W_USED
137 #define SPIFFS_GC_HEUR_W_USED (-1)
138 #endif
139 // Garbage collecting heuristics - weight used for time between
140 // last erased and erase of this block.
141 #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
142 #define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
143 #endif
144 
145 // Object name maximum length. Note that this length include the
146 // zero-termination character, meaning maximum string of characters
147 // can at most be SPIFFS_OBJ_NAME_LEN - 1.
148 #ifndef SPIFFS_OBJ_NAME_LEN
149 #define SPIFFS_OBJ_NAME_LEN (64)
150 #endif
151 
152 // Maximum length of the metadata associated with an object.
153 // Setting to non-zero value enables metadata-related API but also
154 // changes the on-disk format, so the change is not backward-compatible.
155 //
156 // Do note: the meta length must never exceed
157 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64)
158 //
159 // This is derived from following:
160 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
161 // spiffs_object_ix_header fields + at least some LUT entries)
162 #ifndef SPIFFS_OBJ_META_LEN
163 #define SPIFFS_OBJ_META_LEN (0)
164 #endif
165 
166 // Size of buffer allocated on stack used when copying data.
167 // Lower value generates more read/writes. No meaning having it bigger
168 // than logical page size.
169 #ifndef SPIFFS_COPY_BUFFER_STACK
170 #define SPIFFS_COPY_BUFFER_STACK (64)
171 #endif
172 
173 // Enable this to have an identifiable spiffs filesystem. This will look for
174 // a magic in all sectors to determine if this is a valid spiffs system or
175 // not on mount point. If not, SPIFFS_format must be called prior to mounting
176 // again.
177 #ifndef SPIFFS_USE_MAGIC
178 #define SPIFFS_USE_MAGIC (1)
179 #endif
180 
181 #if SPIFFS_USE_MAGIC
182 // Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is
183 // enabled, the magic will also be dependent on the length of the filesystem.
184 // For example, a filesystem configured and formatted for 4 megabytes will not
185 // be accepted for mounting with a configuration defining the filesystem as 2
186 // megabytes.
187 #ifndef SPIFFS_USE_MAGIC_LENGTH
188 #define SPIFFS_USE_MAGIC_LENGTH (1)
189 #endif
190 #endif
191 
192 // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
193 // These should be defined on a multithreaded system
194 
195 // define this to enter a mutex if you're running on a multithreaded system
196 #ifndef SPIFFS_LOCK
197 extern void SPIFFSNVS_lock(void *fs);
198 #define SPIFFS_LOCK(fs) SPIFFSNVS_lock(fs)
199 #endif
200 // define this to exit a mutex if you're running on a multithreaded system
201 #ifndef SPIFFS_UNLOCK
202 extern void SPIFFSNVS_unlock(void *fs);
203 #define SPIFFS_UNLOCK(fs) SPIFFSNVS_unlock(fs)
204 #endif
205 
206 // Enable if only one spiffs instance with constant configuration will exist
207 // on the target. This will reduce calculations, flash and memory accesses.
208 // Parts of configuration must be defined below instead of at time of mount.
209 #ifndef SPIFFS_SINGLETON
210 #define SPIFFS_SINGLETON 0
211 #endif
212 
213 #if SPIFFS_SINGLETON
214 // Instead of giving parameters in config struct, singleton build must
215 // give parameters in defines below.
216 #ifndef SPIFFS_CFG_PHYS_SZ
217 #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2)
218 #endif
219 #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
220 #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536)
221 #endif
222 #ifndef SPIFFS_CFG_PHYS_ADDR
223 #define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
224 #endif
225 #ifndef SPIFFS_CFG_LOG_PAGE_SZ
226 #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
227 #endif
228 #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
229 #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536)
230 #endif
231 #endif
232 
233 // Enable this if your target needs aligned data for index tables
234 #ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
235 #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0
236 #endif
237 
238 // Enable this if you want the HAL callbacks to be called with the spiffs struct
239 #ifndef SPIFFS_HAL_CALLBACK_EXTRA
240 #define SPIFFS_HAL_CALLBACK_EXTRA 1
241 #endif
242 
243 // Enable this if you want to add an integer offset to all file handles
244 // (spiffs_file). This is useful if running multiple instances of spiffs on
245 // same target, in order to recognise to what spiffs instance a file handle
246 // belongs.
247 // NB: This adds config field fh_ix_offset in the configuration struct when
248 // mounting, which must be defined.
249 #ifndef SPIFFS_FILEHDL_OFFSET
250 #define SPIFFS_FILEHDL_OFFSET 0
251 #endif
252 
253 // Enable this to compile a read only version of spiffs.
254 // This will reduce binary size of spiffs. All code comprising modification
255 // of the file system will not be compiled. Some config will be ignored.
256 // HAL functions for erasing and writing to spi-flash may be null. Cache
257 // can be disabled for even further binary size reduction (and ram savings).
258 // Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL.
259 // If the file system cannot be mounted due to aborted erase operation and
260 // SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be
261 // returned.
262 // Might be useful for e.g. bootloaders and such.
263 #ifndef SPIFFS_READ_ONLY
264 #define SPIFFS_READ_ONLY 0
265 #endif
266 
267 // Enable this to add a temporal file cache using the fd buffer.
268 // The effects of the cache is that SPIFFS_open will find the file faster in
269 // certain cases. It will make it a lot easier for spiffs to find files
270 // opened frequently, reducing number of readings from the spi flash for
271 // finding those files.
272 // This will grow each fd by 6 bytes. If your files are opened in patterns
273 // with a degree of temporal locality, the system is optimized.
274 // Examples can be letting spiffs serve web content, where one file is the css.
275 // The css is accessed for each html file that is opened, meaning it is
276 // accessed almost every second time a file is opened. Another example could be
277 // a log file that is often opened, written, and closed.
278 // The size of the cache is number of given file descriptors, as it piggybacks
279 // on the fd update mechanism. The cache lives in the closed file descriptors.
280 // When closed, the fd know the whereabouts of the file. Instead of forgetting
281 // this, the temporal cache will keep handling updates to that file even if the
282 // fd is closed. If the file is opened again, the location of the file is found
283 // directly. If all available descriptors become opened, all cache memory is
284 // lost.
285 #ifndef SPIFFS_TEMPORAL_FD_CACHE
286 #define SPIFFS_TEMPORAL_FD_CACHE 1
287 #endif
288 
289 // Temporal file cache hit score. Each time a file is opened, all cached files
290 // will lose one point. If the opened file is found in cache, that entry will
291 // gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this
292 // value for the specific access patterns of the application. However, it must
293 // be between 1 (no gain for hitting a cached entry often) and 255.
294 #ifndef SPIFFS_TEMPORAL_CACHE_HIT_SCORE
295 #define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4
296 #endif
297 
298 // Enable to be able to map object indices to memory.
299 // This allows for faster and more deterministic reading if cases of reading
300 // large files and when changing file offset by seeking around a lot.
301 // When mapping a file's index, the file system will be scanned for index pages
302 // and the info will be put in memory provided by user. When reading, the
303 // memory map can be looked up instead of searching for index pages on the
304 // medium. This way, user can trade memory against performance.
305 // Whole, parts of, or future parts not being written yet can be mapped. The
306 // memory array will be owned by spiffs and updated accordingly during garbage
307 // collecting or when modifying the indices. The latter is invoked by when the
308 // file is modified in some way. The index buffer is tied to the file
309 // descriptor.
310 #ifndef SPIFFS_IX_MAP
311 #define SPIFFS_IX_MAP 1
312 #endif
313 
314 // By default SPIFFS in some cases relies on the property of NOR flash that bits
315 // cannot be set from 0 to 1 by writing and that controllers will ignore such
316 // bit changes. This results in fewer reads as SPIFFS can in some cases perform
317 // blind writes, with all bits set to 1 and only those it needs reset set to 0.
318 // Most of the chips and controllers allow this behavior, so the default is to
319 // use this technique. If your controller is one of the rare ones that don't,
320 // turn this option on and SPIFFS will perform a read-modify-write instead.
321 #ifndef SPIFFS_NO_BLIND_WRITES
322 #define SPIFFS_NO_BLIND_WRITES 1
323 #endif
324 
325 // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
326 // in the api. This function will visualize all filesystem using given printf
327 // function.
328 #ifndef SPIFFS_TEST_VISUALISATION
329 #define SPIFFS_TEST_VISUALISATION 0
330 #endif
331 #if SPIFFS_TEST_VISUALISATION
332 #ifndef spiffs_printf
333 #define spiffs_printf(...) printf(__VA_ARGS__)
334 #endif
335 // spiffs_printf argument for a free page
336 #ifndef SPIFFS_TEST_VIS_FREE_STR
337 #define SPIFFS_TEST_VIS_FREE_STR "_"
338 #endif
339 // spiffs_printf argument for a deleted page
340 #ifndef SPIFFS_TEST_VIS_DELE_STR
341 #define SPIFFS_TEST_VIS_DELE_STR "/"
342 #endif
343 // spiffs_printf argument for an index page for given object id
344 #ifndef SPIFFS_TEST_VIS_INDX_STR
345 #define SPIFFS_TEST_VIS_INDX_STR(id) "i"
346 #endif
347 // spiffs_printf argument for a data page for given object id
348 #ifndef SPIFFS_TEST_VIS_DATA_STR
349 #define SPIFFS_TEST_VIS_DATA_STR(id) "d"
350 #endif
351 #endif
352 
353 // Types depending on configuration such as the amount of flash bytes
354 // given to spiffs file system in total (spiffs_file_system_size),
355 // the logical block size (log_block_size), and the logical page size
356 // (log_page_size)
357 
358 // Block index type. Make sure the size of this type can hold
359 // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
361 // Page index type. Make sure the size of this type can hold
362 // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size
364 // Object id type - most significant bit is reserved for index flag. Make sure the
365 // size of this type can hold the highest object id on a full system,
366 // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2
368 // Object span index type. Make sure the size of this type can
369 // hold the largest possible span index on the system -
370 // i.e. (spiffs_file_system_size / log_page_size) - 1
372 
373 #endif /* SPIFFS_CONFIG_H_ */
void SPIFFSNVS_unlock(void *fs)
u16_t spiffs_block_ix
Definition: spiffs_config.h:360
int8_t s8_t
Definition: spiffs_config.h:20
uint8_t u8_t
Definition: spiffs_config.h:21
uint32_t u32_t
Definition: spiffs_config.h:17
void SPIFFSNVS_lock(void *fs)
u16_t spiffs_page_ix
Definition: spiffs_config.h:363
int32_t s32_t
Definition: spiffs_config.h:16
uint16_t u16_t
Definition: spiffs_config.h:19
u16_t spiffs_obj_id
Definition: spiffs_config.h:367
int16_t s16_t
Definition: spiffs_config.h:18
u16_t spiffs_span_ix
Definition: spiffs_config.h:371
Copyright 2018, Texas Instruments Incorporated