NHS31xx SW API
storage_dft.h
1 /*
2  * Copyright 2016-2020 NXP
3  * This software is owned or controlled by NXP and may only be used strictly
4  * in accordance with the applicable license terms. By expressly accepting
5  * such terms or by downloading, installing, activating and/or otherwise using
6  * the software, you are agreeing that you have read, and that you agree to
7  * comply with and are bound by, such license terms. If you do not agree to
8  * be bound by the applicable license terms, then you may not retain, install,
9  * activate or otherwise use the software.
10  */
11 
149 #ifndef __STORAGE_DFT_H_
150 #define __STORAGE_DFT_H_
151 
158 #define STORAGE_IDIVUP(n, d) (((n)+(d)-1)/(d))
159 
160 #ifdef STORAGE_CONFIG_ALON_REGISTER
161 
162  #define STORAGE_FIRST_ALON_REGISTER STORAGE_CONFIG_ALON_REGISTER
163 #endif
164 
165 #ifndef STORAGE_FIRST_ALON_REGISTER
166 
176  #define STORAGE_FIRST_ALON_REGISTER 4
177 #endif
178 #if !(STORAGE_FIRST_ALON_REGISTER >= 0) || !(STORAGE_FIRST_ALON_REGISTER <= 4)
179  #error Invalid value for STORAGE_FIRST_ALON_REGISTER
180 #endif
181 
182 /* ------------------------------------------------------------------------- */
183 
184 #ifndef STORAGE_EEPROM_FIRST_ROW
185 
190  #define STORAGE_EEPROM_FIRST_ROW (EEPROM_NR_OF_RW_ROWS - (2048 / EEPROM_ROW_SIZE))
191 #endif
192 #if !(STORAGE_EEPROM_FIRST_ROW >= 0) || !(STORAGE_EEPROM_FIRST_ROW < EEPROM_NR_OF_RW_ROWS)
193  #error Invalid value for STORAGE_EEPROM_FIRST_ROW
194 #endif
195 
196 #ifndef STORAGE_EEPROM_LAST_ROW
197 
202  #define STORAGE_EEPROM_LAST_ROW (EEPROM_NR_OF_RW_ROWS - 1)
203 #endif
204 #if !(STORAGE_EEPROM_LAST_ROW >= STORAGE_EEPROM_FIRST_ROW) || !(STORAGE_EEPROM_LAST_ROW < EEPROM_NR_OF_RW_ROWS)
205  #error Invalid value for STORAGE_EEPROM_LAST_ROW
206 #endif
207 
209 #define STORAGE_EEPROM_ROW_COUNT (STORAGE_EEPROM_LAST_ROW - STORAGE_EEPROM_FIRST_ROW + 1)
210 #if STORAGE_EEPROM_ROW_COUNT < 3
211  #error STORAGE_EEPROM_LAST_ROW and STORAGE_EEPROM_FIRST_ROW must be farther apart: at least 3 EEPROM pages must be assigned for storage
212 #endif
213 
215 #define STORAGE_EEPROM_SIZE (STORAGE_EEPROM_ROW_COUNT * EEPROM_ROW_SIZE)
216 
217 /* ------------------------------------------------------------------------- */
218 
219 #ifndef STORAGE_FLASH_FIRST_PAGE
220 
233  #define STORAGE_FLASH_FIRST_PAGE 0
234 #endif
235 #if !(STORAGE_FLASH_FIRST_PAGE >= 0) || (STORAGE_FLASH_FIRST_PAGE >= FLASH_NR_OF_RW_SECTORS * FLASH_PAGES_PER_SECTOR)
236  #error Invalid value for STORAGE_FLASH_FIRST_PAGE
237 #endif
238 
239 #ifndef STORAGE_FLASH_LAST_PAGE
240 
246  #define STORAGE_FLASH_LAST_PAGE (FLASH_NR_OF_RW_SECTORS * FLASH_PAGES_PER_SECTOR - 1)
247 #endif
248 #if (STORAGE_FLASH_LAST_PAGE < STORAGE_FLASH_FIRST_PAGE) || (STORAGE_FLASH_LAST_PAGE >= FLASH_NR_OF_RW_SECTORS * FLASH_PAGES_PER_SECTOR)
249  #error Invalid value for STORAGE_FLASH_LAST_PAGE
250 #endif
251 #if (STORAGE_FLASH_FIRST_PAGE == 0) && (STORAGE_FLASH_LAST_PAGE != (FLASH_NR_OF_RW_SECTORS * FLASH_PAGES_PER_SECTOR - 1))
252  #error STORAGE_FLASH_FIRST_PAGE is determined at link time; STORAGE_FLASH_LAST_PAGE can thus not be checked at precompilation time.
253  #error STORAGE_FLASH_LAST_PAGE must be set to the highest possible value in this case.
254 #endif
255 
256 /* ------------------------------------------------------------------------- */
257 
258 #ifndef STORAGE_TYPE
259 
264  #define STORAGE_TYPE uint8_t
265 #endif
266 
267 #ifndef STORAGE_BITSIZE
268 
272  #define STORAGE_BITSIZE 8
273 #endif
274 #if (STORAGE_BITSIZE <= 0)
275  #error Invalid value for STORAGE_BITSIZE
276 #endif
277 
281 #define STORAGE_MAX_SAMPLE_ALON_CACHE_COUNT ((141 - STORAGE_FIRST_ALON_REGISTER * 32) / STORAGE_BITSIZE)
282 /* Magic value 141 is checked at compile time in storage.c */
283 
284 #ifndef STORAGE_SAMPLE_ALON_CACHE_COUNT
285 
288  #define STORAGE_SAMPLE_ALON_CACHE_COUNT STORAGE_MAX_SAMPLE_ALON_CACHE_COUNT
289 #endif
290 #if STORAGE_SAMPLE_ALON_CACHE_COUNT > STORAGE_MAX_SAMPLE_ALON_CACHE_COUNT
291  #error STORAGE_SAMPLE_ALON_CACHE_COUNT must be less than or equal to STORAGE_MAX_SAMPLE_ALON_CACHE_COUNT
292 #endif
293 #if (STORAGE_MAX_SAMPLE_ALON_CACHE_COUNT - STORAGE_SAMPLE_ALON_CACHE_COUNT) * STORAGE_BITSIZE >= 32
294  #warning STORAGE_FIRST_ALON_REGISTER can be set higher, as the last general purpose register is reserved by but will not be used by the storage module
295 #endif
296 
297 
298 #ifndef STORAGE_SIGNED
299 
309  #define STORAGE_SIGNED 0
310 #endif
311 
312 /* ------------------------------------------------------------------------- */
313 
314 #ifndef STORAGE_WRITE_RECOVERY_EVERY_X_SAMPLES
315 
323  #define STORAGE_WRITE_RECOVERY_EVERY_X_SAMPLES (1 + STORAGE_SAMPLE_ALON_CACHE_COUNT)
324 #endif
325 #if STORAGE_WRITE_RECOVERY_EVERY_X_SAMPLES <= 0
326  #error STORAGE_WRITE_RECOVERY_EVERY_X_SAMPLES must be a strict positive number
327 #endif
328 #if STORAGE_WRITE_RECOVERY_EVERY_X_SAMPLES < STORAGE_SAMPLE_ALON_CACHE_COUNT
329  #warning STORAGE_WRITE_RECOVERY_EVERY_X_SAMPLES is smaller than STORAGE_SAMPLE_ALON_CACHE_COUNT, which makes little sense.
330  #warning Recovery information will be written in Storage_DeInit after STORAGE_SAMPLE_ALON_CACHE_COUNT samples.
331 #endif
332 
333 #ifndef STORAGE_REDUCE_RECOVERY_WRITES
334 
343  #define STORAGE_REDUCE_RECOVERY_WRITES 0
344 #endif
345 #if (STORAGE_REDUCE_RECOVERY_WRITES != 0) && (STORAGE_REDUCE_RECOVERY_WRITES != 1)
346  #error Leave STORAGE_REDUCE_RECOVERY_WRITES undefined in app_sel.h, or define it to 0 (--> 2 recovery rows) or 1 (--> 1 recovery row)
347 #endif
348 
358 #define STORAGE_MAX_LOSS_AFTER_CORRUPTION 1 \
359  + STORAGE_SAMPLE_ALON_CACHE_COUNT \
360  + STORAGE_WRITE_RECOVERY_EVERY_X_SAMPLES \
361  + STORAGE_REDUCE_RECOVERY_WRITES * STORAGE_IDIVUP(8 * 8, STORAGE_BITSIZE)
362 
368 #if STORAGE_REDUCE_RECOVERY_WRITES
369  #define STORAGE_MAX_BLOCK_SIZE_IN_SAMPLES (((STORAGE_EEPROM_SIZE - 76) * 8) / STORAGE_BITSIZE)
370  /* Magic value 76 is checked at compile time in storage.c */
371 #else
372  #define STORAGE_MAX_BLOCK_SIZE_IN_SAMPLES (((STORAGE_EEPROM_SIZE - 140) * 8) / STORAGE_BITSIZE)
373  /* Magic value 140 is checked at compile time in storage.c */
374 #endif
375 
377 #define STORAGE_MAX_UNCOMPRESSED_BLOCK_SIZE_IN_BITS (STORAGE_MAX_BLOCK_SIZE_IN_SAMPLES * STORAGE_BITSIZE)
378 
382 #define STORAGE_BLOCK_HEADER_SIZE 2
383 
384 #ifndef STORAGE_BLOCK_SIZE_IN_SAMPLES
385 
393  #define STORAGE_BLOCK_SIZE_IN_SAMPLES (((1024 - STORAGE_BLOCK_HEADER_SIZE) * 8) / STORAGE_BITSIZE)
394  #if STORAGE_BLOCK_SIZE_IN_SAMPLES > STORAGE_MAX_BLOCK_SIZE_IN_SAMPLES
395  #undef STORAGE_BLOCK_SIZE_IN_SAMPLES
396  #define STORAGE_BLOCK_SIZE_IN_SAMPLES STORAGE_MAX_BLOCK_SIZE_IN_SAMPLES
397  #endif
398 #endif
399 #if ((STORAGE_BLOCK_SIZE_IN_SAMPLES <= 1) || (STORAGE_BLOCK_SIZE_IN_SAMPLES > STORAGE_MAX_BLOCK_SIZE_IN_SAMPLES))
400  #error Invalid value for STORAGE_BLOCK_SIZE_IN_SAMPLES
401 #endif
402 
404 #define STORAGE_UNCOMPRESSED_BLOCK_SIZE_IN_BITS (STORAGE_BLOCK_SIZE_IN_SAMPLES * STORAGE_BITSIZE)
405 
407 #define STORAGE_UNCOMPRESSED_BLOCK_SIZE_IN_BYTES STORAGE_IDIVUP(STORAGE_UNCOMPRESSED_BLOCK_SIZE_IN_BITS, 8)
408 
410 #define STORAGE_WORKAREA_SIZE ((FLASH_PAGE_SIZE * 2) + STORAGE_UNCOMPRESSED_BLOCK_SIZE_IN_BYTES)
411 
412 #ifdef STORAGE_WORKAREA
413  #undef STORAGE_WORKAREA_SELF_DEFINED
414 #else
415 
419  #define STORAGE_WORKAREA_SELF_DEFINED 1
420 
426  #define STORAGE_WORKAREA sStorage_Workarea
427 #endif
428 
429 /* ------------------------------------------------------------------------- */
430 
431 #ifdef STORAGE_COMPRESS_CB
432  #undef STORAGE_COMPRESS_CB_SELF_DEFINED
433 #else
434 
442  #define STORAGE_COMPRESS_CB Storage_DummyCompressCb
443 #endif
444 
445 #ifdef STORAGE_DECOMPRESS_CB
446  #undef STORAGE_DECOMPRESS_CB_SELF_DEFINED
447 #else
448 
454  #define STORAGE_DECOMPRESS_CB Storage_DummyDecompressCb
455 #endif
456 
457 #endif