spiffs_config.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #include "user_config.h"
  10. #include "c_stdio.h"
  11. #include "c_stdint.h"
  12. #include "c_string.h"
  13. // For u32_t etc
  14. #include "user_interface.h"
  15. // compile time switches
  16. // Set generic spiffs debug output call.
  17. #ifndef SPIFFS_DGB
  18. #define SPIFFS_DBG(...) //printf(__VA_ARGS__)
  19. #endif
  20. // Set spiffs debug output call for garbage collecting.
  21. #ifndef SPIFFS_GC_DGB
  22. #define SPIFFS_GC_DBG(...) //printf(__VA_ARGS__)
  23. #endif
  24. // Set spiffs debug output call for caching.
  25. #ifndef SPIFFS_CACHE_DGB
  26. #define SPIFFS_CACHE_DBG(...) //printf(__VA_ARGS__)
  27. #endif
  28. // Set spiffs debug output call for system consistency checks.
  29. #ifndef SPIFFS_CHECK_DGB
  30. #define SPIFFS_CHECK_DBG(...) //printf(__VA_ARGS__)
  31. #endif
  32. // Enable/disable API functions to determine exact number of bytes
  33. // for filedescriptor and cache buffers. Once decided for a configuration,
  34. // this can be disabled to reduce flash.
  35. #ifndef SPIFFS_BUFFER_HELP
  36. #define SPIFFS_BUFFER_HELP 0
  37. #endif
  38. // Enables/disable memory read caching of nucleus file system operations.
  39. // If enabled, memory area must be provided for cache in SPIFFS_mount.
  40. #ifndef SPIFFS_CACHE
  41. #define SPIFFS_CACHE 1
  42. #endif
  43. #if SPIFFS_CACHE
  44. // Enables memory write caching for file descriptors in hydrogen
  45. #ifndef SPIFFS_CACHE_WR
  46. #define SPIFFS_CACHE_WR 1
  47. #endif
  48. // Enable/disable statistics on caching. Debug/test purpose only.
  49. #ifndef SPIFFS_CACHE_STATS
  50. #define SPIFFS_CACHE_STATS 0
  51. #endif
  52. #else
  53. #define SPIFFS_CACHE_WR 0
  54. #endif
  55. // Always check header of each accessed page to ensure consistent state.
  56. // If enabled it will increase number of reads, will increase flash.
  57. #ifndef SPIFFS_PAGE_CHECK
  58. #define SPIFFS_PAGE_CHECK 1
  59. #endif
  60. // Define maximum number of gc runs to perform to reach desired free pages.
  61. #ifndef SPIFFS_GC_MAX_RUNS
  62. #define SPIFFS_GC_MAX_RUNS 5
  63. #endif
  64. // Enable/disable statistics on gc. Debug/test purpose only.
  65. #ifndef SPIFFS_GC_STATS
  66. #define SPIFFS_GC_STATS 0
  67. #endif
  68. // Garbage collecting examines all pages in a block which and sums up
  69. // to a block score. Deleted pages normally gives positive score and
  70. // used pages normally gives a negative score (as these must be moved).
  71. // To have a fair wear-leveling, the erase age is also included in score,
  72. // whose factor normally is the most positive.
  73. // The larger the score, the more likely it is that the block will
  74. // picked for garbage collection.
  75. // Garbage collecting heuristics - weight used for deleted pages.
  76. #ifndef SPIFFS_GC_HEUR_W_DELET
  77. #define SPIFFS_GC_HEUR_W_DELET (5)
  78. #endif
  79. // Garbage collecting heuristics - weight used for used pages.
  80. #ifndef SPIFFS_GC_HEUR_W_USED
  81. #define SPIFFS_GC_HEUR_W_USED (-1)
  82. #endif
  83. // Garbage collecting heuristics - weight used for time between
  84. // last erased and erase of this block.
  85. #ifndef SPIFFS_GC_HEUR_W_ERASE_AGE
  86. #define SPIFFS_GC_HEUR_W_ERASE_AGE (50)
  87. #endif
  88. // Object name maximum length.
  89. #ifndef SPIFFS_OBJ_NAME_LEN
  90. #define SPIFFS_OBJ_NAME_LEN (32)
  91. #endif
  92. // Size of buffer allocated on stack used when copying data.
  93. // Lower value generates more read/writes. No meaning having it bigger
  94. // than logical page size.
  95. #ifndef SPIFFS_COPY_BUFFER_STACK
  96. #define SPIFFS_COPY_BUFFER_STACK (64)
  97. #endif
  98. // Enable this to have an identifiable spiffs filesystem. This will look for
  99. // a magic in all sectors to determine if this is a valid spiffs system or
  100. // not on mount point. If not, SPIFFS_format must be called prior to mounting
  101. // again.
  102. #ifndef SPIFFS_USE_MAGIC
  103. #define SPIFFS_USE_MAGIC (0)
  104. #endif
  105. // SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level
  106. // These should be defined on a multithreaded system
  107. // define this to entering a mutex if you're running on a multithreaded system
  108. #ifndef SPIFFS_LOCK
  109. #define SPIFFS_LOCK(fs)
  110. #endif
  111. // define this to exiting a mutex if you're running on a multithreaded system
  112. #ifndef SPIFFS_UNLOCK
  113. #define SPIFFS_UNLOCK(fs)
  114. #endif
  115. // Enable if only one spiffs instance with constant configuration will exist
  116. // on the target. This will reduce calculations, flash and memory accesses.
  117. // Parts of configuration must be defined below instead of at time of mount.
  118. #ifndef SPIFFS_SINGLETON
  119. #define SPIFFS_SINGLETON 0
  120. #endif
  121. #if SPIFFS_SINGLETON
  122. // Instead of giving parameters in config struct, singleton build must
  123. // give parameters in defines below.
  124. #ifndef SPIFFS_CFG_PHYS_SZ
  125. #define SPIFFS_CFG_PHYS_SZ(ignore) (1024*1024*2)
  126. #endif
  127. #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
  128. #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (65536)
  129. #endif
  130. #ifndef SPIFFS_CFG_PHYS_ADDR
  131. #define SPIFFS_CFG_PHYS_ADDR(ignore) (0)
  132. #endif
  133. #ifndef SPIFFS_CFG_LOG_PAGE_SZ
  134. #define SPIFFS_CFG_LOG_PAGE_SZ(ignore) (256)
  135. #endif
  136. #ifndef SPIFFS_CFG_LOG_BLOCK_SZ
  137. #define SPIFFS_CFG_LOG_BLOCK_SZ(ignore) (65536)
  138. #endif
  139. #endif
  140. // Set SPFIFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function
  141. // in the api. This function will visualize all filesystem using given printf
  142. // function.
  143. #ifndef SPIFFS_TEST_VISUALISATION
  144. #define SPIFFS_TEST_VISUALISATION 1
  145. #endif
  146. #if SPIFFS_TEST_VISUALISATION
  147. #ifndef spiffs_printf
  148. #define spiffs_printf(...) c_printf(__VA_ARGS__)
  149. #endif
  150. // spiffs_printf argument for a free page
  151. #ifndef SPIFFS_TEST_VIS_FREE_STR
  152. #define SPIFFS_TEST_VIS_FREE_STR "_"
  153. #endif
  154. // spiffs_printf argument for a deleted page
  155. #ifndef SPIFFS_TEST_VIS_DELE_STR
  156. #define SPIFFS_TEST_VIS_DELE_STR "/"
  157. #endif
  158. // spiffs_printf argument for an index page for given object id
  159. #ifndef SPIFFS_TEST_VIS_INDX_STR
  160. #define SPIFFS_TEST_VIS_INDX_STR(id) "i"
  161. #endif
  162. // spiffs_printf argument for a data page for given object id
  163. #ifndef SPIFFS_TEST_VIS_DATA_STR
  164. #define SPIFFS_TEST_VIS_DATA_STR(id) "d"
  165. #endif
  166. #endif
  167. // Types depending on configuration such as the amount of flash bytes
  168. // given to spiffs file system in total (spiffs_file_system_size),
  169. // the logical block size (log_block_size), and the logical page size
  170. // (log_page_size)
  171. // Block index type. Make sure the size of this type can hold
  172. // the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size
  173. typedef u16_t spiffs_block_ix;
  174. // Page index type. Make sure the size of this type can hold
  175. // the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size
  176. typedef u16_t spiffs_page_ix;
  177. // Object id type - most significant bit is reserved for index flag. Make sure the
  178. // size of this type can hold the highest object id on a full system,
  179. // i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2
  180. typedef u16_t spiffs_obj_id;
  181. // Object span index type. Make sure the size of this type can
  182. // hold the largest possible span index on the system -
  183. // i.e. (spiffs_file_system_size / log_page_size) - 1
  184. typedef u16_t spiffs_span_ix;
  185. #endif /* SPIFFS_CONFIG_H_ */