-

Committer:
aguscahya
Date:
Thu Apr 22 03:49:45 2021 +0000
Revision:
0:1f44439df816
-

Who changed what in which revision?

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