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