Microchip® Advanced Software Framework

S_XNv.h File Reference

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.

Return value type of most S_XNv functions.

Return value type of most S_XNv functions.

Enumerator
S_XNv_ReturnValue_Ok 

The operation succeeded.

S_XNv_ReturnValue_Failure 

Unable to write to flash.

S_XNv_ReturnValue_DidNotExist 

The item didn't exist but was successfully created and initialised.

No error.

S_XNv_ReturnValue_DoesNotExist 

The item that was attempted to access doesn't exist.

S_XNv_ReturnValue_BeyondEnd 

An attempt was made to read or write beyond the length of the item.

S_XNv_ReturnValue_PowerSupplyTooLow 

The power supply voltage was too low to reliably perform the requested operation.

The operation has not been executed.

S_XNv_ReturnValue_t S_XNv_Delete ( S_XNv_ItemId_t  id)

Deletes an item from non-volatile storage.

Parameters
idThe item to delete.
Returns
S_XNv_ReturnValue_Ok, S_XNv_ReturnValue_DoesntExist or S_XNv_ReturnValue_PowerSupplyTooLow.
S_XNv_ReturnValue_t S_XNv_EraseAll ( bool  includingPersistentItems)

Erases all items (optionally except the persistent ones) from non-volatile storage.

Parameters
includingPersistentItemsWhether to also erase the peristent items.
Returns
S_XNv_ReturnValue_Ok or S_XNv_ReturnValue_PowerSupplyTooLow.

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.

Parameters
idThe item to check
Returns
true if item is available, false if not.
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.

Parameters
idThe item to initialize.
itemLengthThe length of the item.
pDefaultDataBuffer to 'itemLength' bytes, or NULL.
Returns
S_XNv_ReturnValue_Ok, S_XNv_ReturnValue_DidNotExist or S_XNv_ReturnValue_PowerSupplyTooLow.

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.

Note
pDefaultData must not point to constant data.
uint16_t S_XNv_ItemLength ( S_XNv_ItemId_t  id)

Returns the item length of an item.

Parameters
idThe item to get the length from.
Returns
The length of the item, in bytes, as passed during S_XNv_ItemInit(), or 0 if the item doesn't exist.
S_XNv_ReturnValue_t S_XNv_Read ( S_XNv_ItemId_t  id,
uint16_t  offset,
uint16_t  dataLength,
void *  pData 
)

Reads an item.

Parameters
idThe item to read.
offsetThe offset in the item to start reading from.
dataLengthThe length of the data to read.
pDataPointer to a buffer where the read bytes are to be written to.
Returns
S_XNv_ReturnValue_Ok, S_XNv_ReturnValue_DoesntExist or S_XNv_ReturnValue_BeyondEnd.

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.

Parameters
pfA 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.

Parameters
idThe item to write.
offsetThe offset in the item to start writing to.
dataLengthThe length of the data to write.
pDataPointer to 'dataLength' bytes to write.
Returns
S_XNv_ReturnValue_Ok, S_XNv_ReturnValue_DoesNotExist, S_XNv_ReturnValue_BeyondEnd or S_XNv_ReturnValue_PowerSupplyTooLow.

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.