NVSLPF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2023, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @file NVSLPF3.h
34  * @brief Non-Volatile Storage driver for Low Power F3 devices.
35  *
36  * ## Interrupt Latency During Flash Operations #
37  *
38  * When writing or erasing flash, interrupts must be disabled to avoid
39  * executing code in flash while the flash is being reprogrammed. This
40  * constraint is handled by the driver. Application code does not need to
41  * safeguard against this.
42  *
43  * Additionally, to avoid extremely large interrupt latencies that would be
44  * incurred if entire blocks were written with interrupts disabled, block
45  * writes to flash are broken into multiple smaller sizes. Even with this
46  * scheme in place, latencies of roughly 64 microseconds will be incurred while
47  * flash is being written to.
48  *
49  * A similar caveat applies to flash erase operations. Erasing an entire flash
50  * sector (the minimal amount that can be erased at a time) can take roughly 8
51  * milliseconds. This entire operation must be performed with interrupts
52  * disabled. Here again, this requirement is met internally by the driver and
53  * flash region erases are performed one sector at a time to minimize this
54  * significant latency impact.
55  *
56  * Care must be taken by the user to not perform flash write or erase
57  * operations during latency critical phases of an application. See the
58  * NVS_lock() and NVS_unlock() API descriptions for more information.
59  *
60  * ## Maximum flash writes before erase #
61  *
62  * On Low Power F3 devices, memory rows can be 128 or 256 bytes in length;
63  * refer to the device datasheet for the exact size. A maximum of 83 write
64  * operations can be performed on a memory row. Once the limit is reached, the
65  * row must be erased before it is written to again. It is the developer's
66  * responsibility to ensure that this limit is not exceeded in their
67  * applications. The developer may also opt to use the third party SPIFFS
68  * library implementation supported by TIRTOS which does track writes.
69  *
70  * \note The 83 write limit persists through device reset & power cycles. If 60
71  * write operations were performed on a memory row & the device is reset; the
72  * page can still only be written to 23 more times before it must be erased.
73  *
74  * A write "Scoreboard" can be enabled in this driver; the scoreboard keeps
75  * track of how many times a page has been written to. It is provided as a
76  * debug tool to ensure the 83 write limit is not exceeded. If a page is
77  * written to more than 83 times, the NVSLPF3 driver will spin forever. Each
78  * byte in the scoreboard corresponds to a memory page in the NVS region. The
79  * byte is incremented when the memory is written to & set to 0 when erased.
80  *
81  * To enable the "scoreboard" the "NVSLPF3_INSTRUMENTED" symbol must be
82  * defined when the driver is compiled. Three new fields are added to the
83  * #NVSLPF3_HWAttrs structure:
84  * * scoreboard - a buffer provided by the application where each byte
85  * represents how many times a page has been written to.
86  * * scoreboardSize - number of bytes in the scoreboard.
87  * * flashPageSize - number of bytes in a flash page (i.e. 128 or 256)
88  *
89  * When configured correctly, the scoreboard can be viewed in a memory browser.
90  *
91  * \note The scoreboard will only keep track of writes to flash within a NVS
92  * region using a NVS driver. Writes performed outside the NVS region
93  * or without the NVS driver are untracked.
94  *
95  * \note The scoreboard is in RAM & will be lost on reset or power cycle.
96  *
97  *
98  * ============================================================================
99  */
100 
101 #ifndef ti_drivers_nvs_NVSLPF3__include
102 #define ti_drivers_nvs_NVSLPF3__include
103 
104 #include <stdint.h>
105 #include <stdbool.h>
106 
107 #if defined(__cplusplus)
108 extern "C" {
109 #endif
110 
117 #define NVSLPF3_STATUS_LOW_VOLTAGE (NVS_STATUS_RESERVED - 1)
118 
151 extern const NVS_FxnTable NVSLPF3_fxnTable;
152 
293 typedef struct
294 {
295  void *regionBase;
302  size_t regionSize;
311 #if defined(NVSLPF3_INSTRUMENTED)
312  uint8_t *scoreboard;
313  size_t scoreboardSize;
314  uint32_t flashPageSize;
315 #endif
317 
318 /*
319  * @brief NVSLPF3 Object
320  *
321  * The application must not access any member variables of this structure!
322  */
323 typedef struct
324 {
325  bool opened; /* Has this region been opened */
327 
333 extern void NVSLPF3_close(NVS_Handle handle);
334 
335 extern int_fast16_t NVSLPF3_control(NVS_Handle handle, uint_fast16_t cmd, uintptr_t arg);
336 
337 extern int_fast16_t NVSLPF3_erase(NVS_Handle handle, size_t offset, size_t size);
338 
339 extern void NVSLPF3_getAttrs(NVS_Handle handle, NVS_Attrs *attrs);
340 
341 extern void NVSLPF3_init(void);
342 
343 extern int_fast16_t NVSLPF3_lock(NVS_Handle handle, uint32_t timeout);
344 
345 extern NVS_Handle NVSLPF3_open(uint_least8_t index, NVS_Params *params);
346 
347 extern int_fast16_t NVSLPF3_read(NVS_Handle handle, size_t offset, void *buffer, size_t bufferSize);
348 
349 extern void NVSLPF3_unlock(NVS_Handle handle);
350 
351 extern int_fast16_t NVSLPF3_write(NVS_Handle handle,
352  size_t offset,
353  void *buffer,
354  size_t bufferSize,
355  uint_fast16_t flags);
358 #if defined(__cplusplus)
359 }
360 #endif /* defined (__cplusplus) */
361 
363 #endif /* ti_drivers_nvs_NVSLPF3__include */
ADC_Params params
Definition: Driver_Init.h:11
NVS attributes.
Definition: NVS.h:495
size_t regionSize
Definition: NVSLPF3.h:302
Definition: NVSLPF3.h:323
bool opened
Definition: NVSLPF3.h:325
NVS Parameters.
Definition: NVS.h:483
void * regionBase
Definition: NVSLPF3.h:295
NVS Global configuration.
Definition: NVS.h:621
NVSLPF3 hardware attributes.
Definition: NVSLPF3.h:293
const NVS_FxnTable NVSLPF3_fxnTable
The definition of an NVS function table that contains the required set of functions to control a spec...
Definition: NVS.h:577
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale