Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / common / m5stack-tft / repo / components / spiffs / spiffs_config.h
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 // ----------- 8< ------------
12 // Following includes are for the linux test build of spiffs
13 // These may/should/must be removed/altered/replaced in your target
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <stddef.h>
18 #include <unistd.h>
19 #include <stdint.h>
20 #include <ctype.h>
21 // ----------- >8 ------------
22
23 #include "freertos/FreeRTOS.h"
24 #include "freertos/queue.h"
25 #include "freertos/semphr.h"
26
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;
33
34 QueueHandle_t spiffs_mutex;
35
36 // compile time switches
37
38 // Set generic spiffs debug output call.
39 #ifndef SPIFFS_DBG
40 #define SPIFFS_DBG(...) //printf(__VA_ARGS__)
41 #endif
42 // Set spiffs debug output call for garbage collecting.
43 #ifndef SPIFFS_GC_DBG
44 #define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
45 #endif
46 // Set spiffs debug output call for caching.
47 #ifndef SPIFFS_CACHE_DBG
48 #define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
49 #endif
50 // Set spiffs debug output call for system consistency checks.
51 #ifndef SPIFFS_CHECK_DBG
52 #define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
53 #endif
54
55
56 // Defines spiffs debug print formatters
57 // some general signed number
58 #ifndef _SPIPRIi
59 #define _SPIPRIi   "%d"
60 #endif
61 // address
62 #ifndef _SPIPRIad
63 #define _SPIPRIad  "%08x"
64 #endif
65 // block
66 #ifndef _SPIPRIbl
67 #define _SPIPRIbl  "%04x"
68 #endif
69 // page
70 #ifndef _SPIPRIpg
71 #define _SPIPRIpg  "%04x"
72 #endif
73 // span index
74 #ifndef _SPIPRIsp
75 #define _SPIPRIsp  "%04x"
76 #endif
77 // file descriptor
78 #ifndef _SPIPRIfd
79 #define _SPIPRIfd  "%d"
80 #endif
81 // file object id
82 #ifndef _SPIPRIid
83 #define _SPIPRIid  "%04x"
84 #endif
85 // file flags
86 #ifndef _SPIPRIfl
87 #define _SPIPRIfl  "%02x"
88 #endif
89
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
95 #endif
96
97 // Enables/disable memory read caching of nucleus file system operations.
98 // If enabled, memory area must be provided for cache in SPIFFS_mount.
99 #ifndef  SPIFFS_CACHE
100 #define SPIFFS_CACHE                    1
101 #endif
102 #if SPIFFS_CACHE
103 // Enables memory write caching for file descriptors in hydrogen
104 #ifndef  SPIFFS_CACHE_WR
105 #define SPIFFS_CACHE_WR                 1
106 #endif
107
108 // Enable/disable statistics on caching. Debug/test purpose only.
109 #ifndef  SPIFFS_CACHE_STATS
110 #define SPIFFS_CACHE_STATS              0
111 #endif
112 #endif
113
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
118 #endif
119
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
123 #endif
124
125 // Enable/disable statistics on gc. Debug/test purpose only.
126 #ifndef SPIFFS_GC_STATS
127 #define SPIFFS_GC_STATS                 0
128 #endif
129
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.
137
138 // Garbage collecting heuristics - weight used for deleted pages.
139 #ifndef SPIFFS_GC_HEUR_W_DELET
140 #define SPIFFS_GC_HEUR_W_DELET          (5)
141 #endif
142 // Garbage collecting heuristics - weight used for used pages.
143 #ifndef SPIFFS_GC_HEUR_W_USED
144 #define SPIFFS_GC_HEUR_W_USED           (-1)
145 #endif
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)
150 #endif
151
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)
157 #endif
158
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.
162 //
163 // Do note: the meta length must never exceed
164 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64)
165 //
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)
171 #endif
172
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)
178 #endif
179
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
183 // again.
184 #ifndef SPIFFS_USE_MAGIC
185 #define SPIFFS_USE_MAGIC                (1)
186 #endif
187
188 #if SPIFFS_USE_MAGIC
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
193 // megabytes.
194 #ifndef SPIFFS_USE_MAGIC_LENGTH
195 #define SPIFFS_USE_MAGIC_LENGTH         (1)
196 #endif
197 #endif
198
199 // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
200 // These should be defined on a multithreaded system
201
202 // define this to enter a mutex if you're running on a multithreaded system
203 #ifndef SPIFFS_LOCK
204 #define SPIFFS_LOCK(fs) xSemaphoreTake(spiffs_mutex, portMAX_DELAY)
205 #endif
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)
209 #endif
210
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
216 #endif
217
218 #if SPIFFS_SINGLETON
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)
223 #endif
224 #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
225 #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore)  (65536)
226 #endif
227 #ifndef SPIFFS_CFG_PHYS_ADDR
228 #define SPIFFS_CFG_PHYS_ADDR(ignore)      (0)
229 #endif
230 #ifndef SPIFFS_CFG_LOG_PAGE_SZ
231 #define SPIFFS_CFG_LOG_PAGE_SZ(ignore)    (256)
232 #endif
233 #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
234 #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore)   (65536)
235 #endif
236 #endif
237
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
241 #endif
242
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
246 #endif
247
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
251 // belongs.
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
256 #endif
257
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
266 // returned.
267 // Might be useful for e.g. bootloaders and such.
268 #ifndef SPIFFS_READ_ONLY
269 #define SPIFFS_READ_ONLY                      0
270 #endif
271
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
289 // lost.
290 #ifndef SPIFFS_TEMPORAL_FD_CACHE
291 #define SPIFFS_TEMPORAL_FD_CACHE              1
292 #endif
293
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
301 #endif
302
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
314 // descriptor.
315 #ifndef SPIFFS_IX_MAP
316 #define SPIFFS_IX_MAP                         1
317 #endif
318
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
321 // function.
322 #ifndef SPIFFS_TEST_VISUALISATION
323 #define SPIFFS_TEST_VISUALISATION         0
324 #endif
325 #if SPIFFS_TEST_VISUALISATION
326 #ifndef spiffs_printf
327 #define spiffs_printf(...)                printf(__VA_ARGS__)
328 #endif
329 // spiffs_printf argument for a free page
330 #ifndef SPIFFS_TEST_VIS_FREE_STR
331 #define SPIFFS_TEST_VIS_FREE_STR          "_"
332 #endif
333 // spiffs_printf argument for a deleted page
334 #ifndef SPIFFS_TEST_VIS_DELE_STR
335 #define SPIFFS_TEST_VIS_DELE_STR          "/"
336 #endif
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"
340 #endif
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"
344 #endif
345 #endif
346
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
350 // (log_page_size)
351
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;
366
367 #endif /* SPIFFS_CONFIG_H_ */