S_XNv Driver Interface.
Copyright (c) 2018 Microchip Technology Inc. and its subsidiaries.
#include "N_Types.h"
Typedefs | |
typedef uint16_t | S_XNv_ItemId_t |
Identifier type to an item in Flash. More... | |
typedef bool(* | S_XNv_PowerSupplyCheckingFunction_t )(void) |
Function type used to check the external NV's power supply. More... | |
typedef enum S_XNv_ReturnValue_t | S_XNv_ReturnValue_t |
Return value type of most S_XNv functions. More... | |
Enumerations | |
enum | S_XNv_ReturnValue_t { S_XNv_ReturnValue_Ok, S_XNv_ReturnValue_Failure, S_XNv_ReturnValue_DidNotExist, S_XNv_ReturnValue_DoesNotExist, S_XNv_ReturnValue_BeyondEnd, S_XNv_ReturnValue_PowerSupplyTooLow } |
Return value type of most S_XNv functions. More... | |
Functions | |
S_XNv_ReturnValue_t | S_XNv_Delete (S_XNv_ItemId_t id) |
Deletes an item from non-volatile storage. More... | |
S_XNv_ReturnValue_t | S_XNv_EraseAll (bool includingPersistentItems) |
Erases all items (optionally except the persistent ones) from non-volatile storage. More... | |
bool | S_XNv_IsItemAvailable_Impl (S_XNv_ItemId_t id) |
Checks the item is available or not. More... | |
S_XNv_ReturnValue_t | S_XNv_ItemInit (S_XNv_ItemId_t id, uint16_t itemLength, void *pDefaultData) |
Initializes an item with default data, but only if it doesn't exit yet. More... | |
uint16_t | S_XNv_ItemLength (S_XNv_ItemId_t id) |
Returns the item length of an item. More... | |
S_XNv_ReturnValue_t | S_XNv_Read (S_XNv_ItemId_t id, uint16_t offset, uint16_t dataLength, void *pData) |
Reads an item. More... | |
void | S_XNv_SetPowerSupplyCheckingFunction (S_XNv_PowerSupplyCheckingFunction_t pf) |
Sets a function to check the power supply. More... | |
S_XNv_ReturnValue_t | S_XNv_Write (S_XNv_ItemId_t id, uint16_t offset, uint16_t dataLength, void *pData) |
Writes an item. More... | |
typedef uint16_t S_XNv_ItemId_t |
Identifier type to an item in Flash.
Valid range is 1..32767.
typedef bool(* S_XNv_PowerSupplyCheckingFunction_t)(void) |
Function type used to check the external NV's power supply.
Should only return TRUE if the power supply is high enough to reliably perform a write or erase operation.
typedef enum S_XNv_ReturnValue_t S_XNv_ReturnValue_t |
Return value type of most S_XNv functions.
enum S_XNv_ReturnValue_t |
Return value type of most S_XNv functions.
S_XNv_ReturnValue_t S_XNv_Delete | ( | S_XNv_ItemId_t | id | ) |
Deletes an item from non-volatile storage.
id | The item to delete. |
S_XNv_ReturnValue_t S_XNv_EraseAll | ( | bool | includingPersistentItems | ) |
Erases all items (optionally except the persistent ones) from non-volatile storage.
includingPersistentItems | Whether to also erase the peristent items. |
The persistent items should typically never be erased in an application!
bool S_XNv_IsItemAvailable_Impl | ( | S_XNv_ItemId_t | id | ) |
Checks the item is available or not.
id | The item to check |
S_XNv_ReturnValue_t S_XNv_ItemInit | ( | S_XNv_ItemId_t | id, |
uint16_t | itemLength, | ||
void * | pDefaultData | ||
) |
Initializes an item with default data, but only if it doesn't exit yet.
id | The item to initialize. |
itemLength | The length of the item. |
pDefaultData | Buffer to 'itemLength' bytes, or NULL. |
If the item doesn't exist, it is written with the given default data and the status code S_XNv_ReturnValue_DidNotExist is returned. Otherwise, the default data is not used, the item is kept as it was but read into pDefaultData, and S_XNv_ReturnValue_Ok is returned. If NULL is passed for pDefaultData, and the item doesn't exist all data is initialized to 0xFF.
uint16_t S_XNv_ItemLength | ( | S_XNv_ItemId_t | id | ) |
Returns the item length of an item.
id | The item to get the length from. |
S_XNv_ReturnValue_t S_XNv_Read | ( | S_XNv_ItemId_t | id, |
uint16_t | offset, | ||
uint16_t | dataLength, | ||
void * | pData | ||
) |
Reads an item.
id | The item to read. |
offset | The offset in the item to start reading from. |
dataLength | The length of the data to read. |
pData | Pointer to a buffer where the read bytes are to be written to. |
If any of the bytes fall outside the item length as passed during S_XNv_ItemInit(), the whole read operation does not occur and S_XNv_ReturnValue_BeyondEnd is returned.
void S_XNv_SetPowerSupplyCheckingFunction | ( | S_XNv_PowerSupplyCheckingFunction_t | pf | ) |
Sets a function to check the power supply.
pf | A pointer to a function that S_XNv uses to check the power supply. |
If the power supply checking function is not set, the default is to assume that the power supply is always high enough. This is not suitable for typical applications. When this function is called again,
S_XNv_ReturnValue_t S_XNv_Write | ( | S_XNv_ItemId_t | id, |
uint16_t | offset, | ||
uint16_t | dataLength, | ||
void * | pData | ||
) |
Writes an item.
id | The item to write. |
offset | The offset in the item to start writing to. |
dataLength | The length of the data to write. |
pData | Pointer to 'dataLength' bytes to write. |
If any of the bytes fall outside the item length as passed during S_XNv_ItemInit(), the whole write operation does not occur and S_XNv_ReturnValue_BeyondEnd is returned.