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