Microchip® Advanced Software Framework

S_Nv.h File Reference

NV component header.

Copyright (c) 2018 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>

Macros

#define S_NV_APPLICATION_RANGE_MAX   0x3FFFu
 
#define S_NV_APPLICATION_RANGE_MIN   0x0900u
 The ranges of IDs that can be used by the application for storing flash data. More...
 
#define S_NV_PLATFORM_RANGE1_MAX   0x08FFu
 
#define S_NV_PLATFORM_RANGE1_MIN   0x0800u
 First reserved range for a platform. More...
 
#define S_NV_PLATFORM_RANGE2_MAX   0x7FFFu
 
#define S_NV_PLATFORM_RANGE2_MIN   0x7000u
 Second reserved range for a platform. More...
 
#define S_NV_RESERVED_RANGE_MAX   0x6FFFu
 
#define S_NV_RESERVED_RANGE_MIN   0x4000u
 Reserved range for future use. More...
 
#define S_NV_STACK_RANGE_MAX   0x07FFu
 
#define S_NV_STACK_RANGE_MIN   0x0001u
 The ranges of IDs that can be used by the stack for storing flash data. More...
 

Typedefs

typedef uint16_t S_Nv_ItemId_t
 Identifier type to an item in Flash. More...
 
typedef bool(* S_Nv_PowerSupplyCheckingFunction_t )(void)
 Function type used to check the external NV's power supply. More...
 
typedef enum S_Nv_ReturnValue_t S_Nv_ReturnValue_t
 Return value type of most S_Nv functions. More...
 

Enumerations

enum  S_Nv_ReturnValue_t {
  S_Nv_ReturnValue_Ok,
  S_Nv_ReturnValue_Failure,
  S_Nv_ReturnValue_DidNotExist,
  S_Nv_ReturnValue_DoesNotExist,
  S_Nv_ReturnValue_BeyondEnd,
  S_Nv_ReturnValue_PowerSupplyTooLow
}
 Return value type of most S_Nv functions. More...
 

Functions

S_Nv_ReturnValue_t S_Nv_Delete (S_Nv_ItemId_t id)
 Deletes an item from non-volatile storage. More...
 
S_Nv_ReturnValue_t S_Nv_EraseAll (bool includingPersistentItems)
 Erases all items (optionally except the persistent ones) from non-volatile storage. More...
 
bool S_Nv_IsItemAvailable (S_Nv_ItemId_t id)
 This will check whether the item is found in the storage area. More...
 
S_Nv_ReturnValue_t S_Nv_ItemInit (S_Nv_ItemId_t id, uint16_t itemLength, void *pDefaultData)
 Initializes an item with default data if it doesn't exist yet, or reads it when it does exist. More...
 
uint16_t S_Nv_ItemLength (S_Nv_ItemId_t id)
 Returns the item length of an item. More...
 
S_Nv_ReturnValue_t S_Nv_Read (S_Nv_ItemId_t id, uint16_t offset, uint16_t dataLength, void *pData)
 Reads an item. More...
 
void S_Nv_SetPowerSupplyCheckingFunction (S_Nv_PowerSupplyCheckingFunction_t pf)
 Sets a function to check the power supply. More...
 
void S_Nv_SetSystemIntegrityCheckFunction (void(*pf)(void))
 S_Nv Integrity check function. More...
 
S_Nv_ReturnValue_t S_Nv_Write (S_Nv_ItemId_t id, uint16_t offset, uint16_t dataLength, void *pData)
 Writes an item. More...
 

#define S_NV_APPLICATION_RANGE_MAX   0x3FFFu
#define S_NV_APPLICATION_RANGE_MIN   0x0900u

The ranges of IDs that can be used by the application for storing flash data.

#define S_NV_PLATFORM_RANGE1_MAX   0x08FFu
#define S_NV_PLATFORM_RANGE1_MIN   0x0800u

First reserved range for a platform.

#define S_NV_PLATFORM_RANGE2_MAX   0x7FFFu
#define S_NV_PLATFORM_RANGE2_MIN   0x7000u

Second reserved range for a platform.

#define S_NV_RESERVED_RANGE_MAX   0x6FFFu
#define S_NV_RESERVED_RANGE_MIN   0x4000u

Reserved range for future use.

#define S_NV_STACK_RANGE_MAX   0x07FFu
#define S_NV_STACK_RANGE_MIN   0x0001u

The ranges of IDs that can be used by the stack for storing flash data.

See wlPdsMemIds.h

typedef uint16_t S_Nv_ItemId_t

Identifier type to an item in Flash.

Valid range is 1..32767.

typedef bool(* S_Nv_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_Nv functions.

Return value type of most S_Nv functions.

Enumerator
S_Nv_ReturnValue_Ok 

The operation succeeded.

S_Nv_ReturnValue_Failure 

Unable to write to flash.

S_Nv_ReturnValue_DidNotExist 

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

No error.

S_Nv_ReturnValue_DoesNotExist 

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

S_Nv_ReturnValue_BeyondEnd 

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

S_Nv_ReturnValue_PowerSupplyTooLow 

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

The operation has not been executed.

S_Nv_ReturnValue_t S_Nv_Delete ( S_Nv_ItemId_t  id)

Deletes an item from non-volatile storage.

Parameters
idThe item to delete.
Returns
S_Nv_ReturnValue_Ok, S_Nv_ReturnValue_DoesntExist or S_Nv_ReturnValue_PowerSupplyTooLow.

Referenced by PDS_Delete().

S_Nv_ReturnValue_t S_Nv_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_Nv_ReturnValue_Ok or S_Nv_ReturnValue_PowerSupplyTooLow.

The persistent items should typically never be erased in an application!

Referenced by PDS_DeleteAll().

bool S_Nv_IsItemAvailable ( S_Nv_ItemId_t  id)

This will check whether the item is found in the storage area.

Parameters
id- Id of the item to be checked.
Returns
true or false

Referenced by PDS_IsAbleToRestore(), and pdsStoreItemTaskHandler().

S_Nv_ReturnValue_t S_Nv_ItemInit ( S_Nv_ItemId_t  id,
uint16_t  itemLength,
void *  pDefaultData 
)

Initializes an item with default data if it doesn't exist yet, or reads it when it does exist.

Parameters
idThe item to initialize.
itemLengthThe length of the item.
pDefaultDataBuffer to 'itemLength' bytes, or NULL.
Returns
S_Nv_ReturnValue_Ok, S_Nv_ReturnValue_DidNotExist or S_Nv_ReturnValue_PowerSupplyTooLow.

If the item doesn't exist, it is written with the given default data and the status code S_Nv_ReturnValue_DidNotExist is returned. Otherwise, the default data is not used, the item is kept as it was but read into pDefaultData, and S_Nv_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.

Referenced by PDS_InitItems(), pdsRestoreItem(), and pdsStoreItemTaskHandler().

uint16_t S_Nv_ItemLength ( S_Nv_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_Nv_ItemInit(), or 0 if the item doesn't exist.

Referenced by pdsRestoreItem().

S_Nv_ReturnValue_t S_Nv_Read ( S_Nv_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_Nv_ReturnValue_Ok, S_Nv_ReturnValue_DoesntExist or S_Nv_ReturnValue_BeyondEnd.

If any of the bytes fall outside the item lenght as passed during S_Nv_ItemInit(), the whole read operation does not occur and S_Nv_ReturnValue_BeyondEnd is returned.

void S_Nv_SetPowerSupplyCheckingFunction ( S_Nv_PowerSupplyCheckingFunction_t  pf)

Sets a function to check the power supply.

Parameters
pfA pointer to a function that S_Nv 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,

void S_Nv_SetSystemIntegrityCheckFunction ( void(*)(void)  pf)

S_Nv Integrity check function.

S_Nv_ReturnValue_t S_Nv_Write ( S_Nv_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_Nv_ReturnValue_Ok, S_Nv_ReturnValue_DoesNotExist, S_Nv_ReturnValue_BeyondEnd or S_Nv_ReturnValue_PowerSupplyTooLow.

If any of the bytes fall outside the item lenght as passed during S_Nv_ItemInit(), the whole write operation does not occur and S_Nv_ReturnValue_BeyondEnd is returned.

Referenced by pdsStoreItem(), updatecommnDevTable(), updateCoordHopTable(), updateCoordRouteTable(), updateCoordTable(), updateNonSleepDevTable(), and updateSleepDevTable().