25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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