TI-RTOS Drivers  tidrivers_full_2_20_00_08
NVS.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, 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  */
70 #ifndef ti_drivers_NVS__include
71 #define ti_drivers_NVS__include
72 
73 #include <stdint.h>
74 #include <stddef.h>
75 #include <stdbool.h>
76 
77 #if defined (__cplusplus)
78 extern "C" {
79 #endif
80 
98 #define NVS_CMD_RESERVED 32
99 
112 #define NVS_STATUS_RESERVED -32
113 
127 #define NVS_STATUS_SUCCESS 0
128 
135 #define NVS_STATUS_ERROR -1
136 
144 #define NVS_STATUS_UNDEFINEDCMD -2
145 
155 /* Add NVS_CMD_<commands> here */
156 
164 #define NVS_SOK (0)
165 
169 #define NVS_EFAIL (-1)
170 #define NVS_EOFFSET (-3)
171 #define NVS_EALIGN (-4)
172 #define NVS_ENOTENOUGHBYTES (-5)
173 #define NVS_EALREADYWRITTEN (-6)
174 #define NVS_ECOPYBLOCK (-7)
175 
195 #define NVS_WRITE_EXCLUSIVE (0x1)
196 
203 #define NVS_WRITE_ERASE (0x2)
204 
212 #define NVS_WRITE_VALIDATE (0x4)
213 
222 typedef struct NVS_Params {
223  bool eraseOnOpen;
224 } NVS_Params;
225 
246 typedef struct NVS_Attrs {
247  size_t pageSize;
248  size_t blockSize;
249 } NVS_Attrs;
250 
254 typedef struct NVS_Config *NVS_Handle;
255 
260 typedef void (*NVS_CloseFxn) (NVS_Handle handle);
261 
266 typedef int (*NVS_ControlFxn) (NVS_Handle handle, unsigned int cmd,
267  uintptr_t arg);
268 
273 typedef void (*NVS_ExitFxn) (NVS_Handle handle);
274 
279 typedef int (*NVS_GetAttrsFxn) (NVS_Handle handle, NVS_Attrs *attrs);
280 
285 typedef void (*NVS_InitFxn) (NVS_Handle handle);
286 
291 typedef NVS_Handle (*NVS_OpenFxn) (NVS_Handle handle, NVS_Params *params);
292 
297 typedef int (*NVS_ReadFxn) (NVS_Handle handle, size_t offset,
298  void *buffer, size_t bufferSize);
299 
304 typedef int (*NVS_WriteFxn) (NVS_Handle handle, size_t offset,
305  void *buffer, size_t bufferSize,
306  unsigned int flags);
307 
313 typedef struct NVS_FxnTable {
316 
319 
322 
325 
328 
331 
334 
337 } NVS_FxnTable;
338 
350 typedef struct NVS_Config {
353 
355  void *object;
356 
358  void const *hwAttrs;
359 } NVS_Config;
360 
368 extern void NVS_close(NVS_Handle handle);
369 
389 extern int NVS_control(NVS_Handle handle, unsigned int cmd, uintptr_t arg);
390 
399 extern int NVS_erase(NVS_Handle handle);
400 
406 extern void NVS_exit(void);
407 
415 extern int NVS_getAttrs(NVS_Handle handle, NVS_Attrs *attrs);
416 
424 extern void NVS_init(void);
425 
437 extern NVS_Handle NVS_open(int index, NVS_Params *params);
438 
457 extern int NVS_read(NVS_Handle handle, size_t offset, void *buffer,
458  size_t bufferSize);
459 
491 extern int NVS_write(NVS_Handle handle, size_t offset, void *buffer,
492  size_t bufferSize, unsigned int flags);
493 
494 #if defined (__cplusplus)
495 }
496 #endif /* defined (__cplusplus) */
497 
499 #endif /* ti_drivers_NVS__include */
struct NVS_FxnTable NVS_FxnTable
The definition of an NVS function table that contains the required set of functions to control a spec...
struct NVS_Attrs NVS_Attrs
NVS attributes.
int(* NVS_GetAttrsFxn)(NVS_Handle handle, NVS_Attrs *attrs)
A function pointer to a driver specific implementation of NVS_getAttrs().
Definition: NVS.h:279
NVS attributes.
Definition: NVS.h:246
void const * hwAttrs
Definition: NVS.h:358
void NVS_exit(void)
Function to de-initialize the NVS module.
void * object
Definition: NVS.h:355
int NVS_write(NVS_Handle handle, size_t offset, void *buffer, size_t bufferSize, unsigned int flags)
Write data to an NVS block.
NVS_CloseFxn closeFxn
Definition: NVS.h:315
struct NVS_Params NVS_Params
NVS Parameters.
NVS Global configuration.
Definition: NVS.h:350
NVS_Handle(* NVS_OpenFxn)(NVS_Handle handle, NVS_Params *params)
A function pointer to a driver specific implementation of NVS_open().
Definition: NVS.h:291
int NVS_control(NVS_Handle handle, unsigned int cmd, uintptr_t arg)
Function performs implementation specific features on a given NVS_Handle.
bool eraseOnOpen
Definition: NVS.h:223
void(* NVS_CloseFxn)(NVS_Handle handle)
A function pointer to a driver specific implementation of NVS_close().
Definition: NVS.h:260
NVS_GetAttrsFxn getAttrsFxn
Definition: NVS.h:324
struct NVS_Config NVS_Config
NVS Global configuration.
NVS_ReadFxn readFxn
Definition: NVS.h:333
void(* NVS_ExitFxn)(NVS_Handle handle)
A function pointer to a driver specific implementation of NVS_exit().
Definition: NVS.h:273
NVS_WriteFxn writeFxn
Definition: NVS.h:336
int(* NVS_WriteFxn)(NVS_Handle handle, size_t offset, void *buffer, size_t bufferSize, unsigned int flags)
A function pointer to a driver specific implementation of NVS_write().
Definition: NVS.h:304
void NVS_init(void)
Function to initialize the NVS module.
NVS Parameters.
Definition: NVS.h:222
NVS_ControlFxn controlFxn
Definition: NVS.h:318
size_t pageSize
Definition: NVS.h:247
struct NVS_Config * NVS_Handle
A handle that is returned from the NVS_open() call.
Definition: NVS.h:254
void(* NVS_InitFxn)(NVS_Handle handle)
A function pointer to a driver specific implementation of NVS_init().
Definition: NVS.h:285
int NVS_read(NVS_Handle handle, size_t offset, void *buffer, size_t bufferSize)
Read data from an NVS block.
NVS_InitFxn initFxn
Definition: NVS.h:327
NVS_Handle NVS_open(int index, NVS_Params *params)
Get an NVS block for reading and writing.
void NVS_close(NVS_Handle handle)
Function to close an NVS handle.
NVS_OpenFxn openFxn
Definition: NVS.h:330
int NVS_erase(NVS_Handle handle)
Erase the block of storage reference by an NVS handle.
NVS_FxnTable const * fxnTablePtr
Definition: NVS.h:352
The definition of an NVS function table that contains the required set of functions to control a spec...
Definition: NVS.h:313
int(* NVS_ControlFxn)(NVS_Handle handle, unsigned int cmd, uintptr_t arg)
A function pointer to a driver specific implementation of NVS_control().
Definition: NVS.h:266
NVS_ExitFxn exitFxn
Definition: NVS.h:321
int NVS_getAttrs(NVS_Handle handle, NVS_Attrs *attrs)
Function to get the NVS attributes.
int(* NVS_ReadFxn)(NVS_Handle handle, size_t offset, void *buffer, size_t bufferSize)
A function pointer to a driver specific implementation of NVS_read().
Definition: NVS.h:297
size_t blockSize
Definition: NVS.h:248
Copyright 2016, Texas Instruments Incorporated