ESP8266
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 #include <stddef.h>
12 #include <stdint.h>
13 #include <string.h>
14 #include "c_types.h"
15 #include "ets_sys.h"
16 
17 
18 #define c_memcpy memcpy
19 #define c_printf ets_printf
20 #define c_memset memset
21 
22 typedef int16_t file_t;
23 typedef int32_t s32_t;
24 typedef uint32_t u32_t;
25 typedef int16_t s16_t;
26 typedef uint16_t u16_t;
27 typedef int8_t s8_t;
28 typedef uint8_t u8_t;
29 
30 #ifndef SEEK_SET
31 #define SEEK_SET 0 /* set file offset to offset */
32 #endif
33 
34 #ifndef SEEK_CUR
35 #define SEEK_CUR 1 /* set file offset to current plus offset */
36 #endif
37 
38 #ifndef SEEK_END
39 #define SEEK_END 2 /* set file offset to EOF plus offset */
40 #endif
41 
42 #ifndef EOF
43 #define EOF (-1)
44 #endif
45 
46 // compile time switches
47 
48 // Set generic spiffs debug output call.
49 #ifndef SPIFFS_DBG
50 #define SPIFFS_DBG(...) //printf(__VA_ARGS__)
51 #endif
52 // Set spiffs debug output call for garbage collecting.
53 #ifndef SPIFFS_GC_DBG
54 #define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
55 #endif
56 // Set spiffs debug output call for caching.
57 #ifndef SPIFFS_CACHE_DBG
58 #define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
59 #endif
60 // Set spiffs debug output call for system consistency checks.
61 #ifndef SPIFFS_CHECK_DBG
62 #define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
63 #endif
64 
65 // Enable/disable API functions to determine exact number of bytes
66 // for filedescriptor and cache buffers. Once decided for a configuration,
67 // this can be disabled to reduce flash.
68 #ifndef SPIFFS_BUFFER_HELP
69 #define SPIFFS_BUFFER_HELP 1
70 #endif
71 
72 // Enables/disable memory read caching of nucleus file system operations.
73 // If enabled, memory area must be provided for cache in SPIFFS_mount.
74 #ifndef SPIFFS_CACHE
75 #define SPIFFS_CACHE 1
76 #endif
77 #if SPIFFS_CACHE
78 // Enables memory write caching for file descriptors in hydrogen
79 #ifndef SPIFFS_CACHE_WR
80 #define SPIFFS_CACHE_WR 1
81 #endif
82 
83 // Enable/disable statistics on caching. Debug/test purpose only.
84 #ifndef SPIFFS_CACHE_STATS
85 #define SPIFFS_CACHE_STATS 0
86 #endif
87 #endif
88 
89 // Always check header of each accessed page to ensure consistent state.
90 // If enabled it will increase number of reads, will increase flash.
91 #ifndef SPIFFS_PAGE_CHECK
92 #define SPIFFS_PAGE_CHECK 1
93 #endif
94 
95 // Define maximum number of gc runs to perform to reach desired free pages.
96 #ifndef SPIFFS_GC_MAX_RUNS
97 #define SPIFFS_GC_MAX_RUNS 5
98 #endif
99 
100 // Enable/disable statistics on gc. Debug/test purpose only.
101 #ifndef SPIFFS_GC_STATS
102 #define SPIFFS_GC_STATS 0
103 #endif
104 
105 // Garbage collecting examines all pages in a block which and sums up
106 // to a block score. Deleted pages normally gives positive score and
107 // used pages normally gives a negative score (as these must be moved).
108 // To have a fair wear-leveling, the erase age is also included in score,
109 // whose factor normally is the most positive.
110 // The larger the score, the more likely it is that the block will
111 // picked for garbage collection.
112 
113 // Garbage collecting heuristics - weight used for deleted pages.
114 #ifndef SPIFFS_GC_HEUR_W_DELET
115 #define SPIFFS_GC_HEUR_W_DELET (5)
116 #endif
117 // Garbage collecting heuristics - weight used for used pages.
118 #ifndef SPIFFS_GC_HEUR_W_USED
119 #define SPIFFS_GC_HEUR_W_USED (-1)
120 #endif
121 // Garbage collecting heuristics - weight used for time between
122 // last erased and erase of this block.
123 #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
124 #define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
125 #endif
126 
127 // Object name maximum length.
128 #ifndef SPIFFS_OBJ_NAME_LEN
129 #define SPIFFS_OBJ_NAME_LEN (32)
130 #endif
131 
132 // Size of buffer allocated on stack used when copying data.
133 // Lower value generates more read/writes. No meaning having it bigger
134 // than logical page size.
135 #ifndef SPIFFS_COPY_BUFFER_STACK
136 #define SPIFFS_COPY_BUFFER_STACK (64)
137 #endif
138 
139 // Enable this to have an identifiable spiffs filesystem. This will look for
140 // a magic in all sectors to determine if this is a valid spiffs system or
141 // not on mount point. If not, SPIFFS_format must be called prior to mounting
142 // again.
143 #ifndef SPIFFS_USE_MAGIC
144 #define SPIFFS_USE_MAGIC (1)
145 #endif
146 
147 // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
148 // These should be defined on a multithreaded system
149 
150 // define this to enter a mutex if you're running on a multithreaded system
151 #ifndef SPIFFS_LOCK
152 #define SPIFFS_LOCK(fs)
153 #endif
154 // define this to exit a mutex if you're running on a multithreaded system
155 #ifndef SPIFFS_UNLOCK
156 #define SPIFFS_UNLOCK(fs)
157 #endif
158 
159 
160 // Enable if only one spiffs instance with constant configuration will exist
161 // on the target. This will reduce calculations, flash and memory accesses.
162 // Parts of configuration must be defined below instead of at time of mount.
163 #ifndef SPIFFS_SINGLETON
164 #define SPIFFS_SINGLETON 0
165 #endif
166 
167 #if SPIFFS_SINGLETON
168 // Instead of giving parameters in config struct, singleton build must
169 // give parameters in defines below.
170 #ifndef SPIFFS_CFG_PHYS_SZ
171 #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2)
172 #endif
173 #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
174 #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536)
175 #endif
176 #ifndef SPIFFS_CFG_PHYS_ADDR
177 #define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
178 #endif
179 #ifndef SPIFFS_CFG_LOG_PAGE_SZ
180 #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
181 #endif
182 #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
183 #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536)
184 #endif
185 #endif
186 
187 // Enable this if your target needs aligned data for index tables
188 #ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
189 #define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
190 #endif
191 
192 // Enable this if you want the HAL callbacks to be called with the spiffs struct
193 #ifndef SPIFFS_HAL_CALLBACK_EXTRA
194 #define SPIFFS_HAL_CALLBACK_EXTRA 0
195 #endif
196 
197 // Enable this if you want to add an integer offset to all file handles
198 // (spiffs_file). This is useful if running multiple instances of spiffs on
199 // same target, in order to recognise to what spiffs instance a file handle
200 // belongs.
201 // NB: This adds config field fh_ix_offset in the configuration struct when
202 // mounting, which must be defined.
203 #ifndef SPIFFS_FILEHDL_OFFSET
204 #define SPIFFS_FILEHDL_OFFSET 0
205 #endif
206 
207 // Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
208 // in the api. This function will visualize all filesystem using given printf
209 // function.
210 #ifndef SPIFFS_TEST_VISUALISATION
211 #define SPIFFS_TEST_VISUALISATION 1
212 #endif
213 #if SPIFFS_TEST_VISUALISATION
214 #ifndef spiffs_printf
215 #define spiffs_printf(...) c_printf(__VA_ARGS__)
216 #endif
217 // spiffs_printf argument for a free page
218 #ifndef SPIFFS_TEST_VIS_FREE_STR
219 #define SPIFFS_TEST_VIS_FREE_STR "_"
220 #endif
221 // spiffs_printf argument for a deleted page
222 #ifndef SPIFFS_TEST_VIS_DELE_STR
223 #define SPIFFS_TEST_VIS_DELE_STR "/"
224 #endif
225 // spiffs_printf argument for an index page for given object id
226 #ifndef SPIFFS_TEST_VIS_INDX_STR
227 #define SPIFFS_TEST_VIS_INDX_STR(id) "i"
228 #endif
229 // spiffs_printf argument for a data page for given object id
230 #ifndef SPIFFS_TEST_VIS_DATA_STR
231 #define SPIFFS_TEST_VIS_DATA_STR(id) "d"
232 #endif
233 #endif
234 
235 // Types depending on configuration such as the amount of flash bytes
236 // given to spiffs file system in total (spiffs_file_system_size),
237 // the logical block size (log_block_size), and the logical page size
238 // (log_page_size)
239 
240 // Block index type. Make sure the size of this type can hold
241 // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
242 typedef u16_t spiffs_block_ix;
243 // Page index type. Make sure the size of this type can hold
244 // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size
245 typedef u16_t spiffs_page_ix;
246 // Object id type - most significant bit is reserved for index flag. Make sure the
247 // size of this type can hold the highest object id on a full system,
248 // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2
249 typedef u16_t spiffs_obj_id;
250 // Object span index type. Make sure the size of this type can
251 // hold the largest possible span index on the system -
252 // i.e. (spiffs_file_system_size / log_page_size) - 1
253 typedef u16_t spiffs_span_ix;
254 
255 #endif /* SPIFFS_CONFIG_H_ */