You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

362 line
13 KiB

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