Microchip® Advanced Software Framework

pds_nvm.h File Reference

This file for Persistent Data Storage - Non-Volatile Memory management.

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

Data Structures

struct  block_header
 Block header, located before each block of item data. More...
 
struct  pds_env
 containing environment parameters of the NVM module. More...
 
struct  sector_header
 Sector header, located at sector start. More...
 

Macros

#define NVM_MEMORY   ((volatile uint16_t *)FLASH_ADDR)
 
#define PDS_BLOCK_ACTIVE_FLAG_Pos   7
 
#define PDS_BLOCK_ACTIVE_MASK(value)   ((0x1ul << PDS_BLOCK_ACTIVE_FLAG_Pos) & value)
 PDS_BLOCK_DELETE_FLAG_Pos Flag. More...
 
#define PDS_BLOCK_DELETE_FLAG_Pos   5
 
#define PDS_BLOCK_DELETE_MASK(value)   ((0x1ul << PDS_BLOCK_DELETE_FLAG_Pos) & value)
 FLASH base address. More...
 
#define PDS_EXTERNAL_EEPROM_ID   (0x03)
 
#define PDS_EXTERNAL_FLASH_ID   (0x02)
 
#define PDS_ID(main_id, sub_id)   ((main_id << 8) | sub_id)
 PDS_BLOCK_ACTIVE_FLAG_Pos Flag. More...
 
#define PDS_ID_MAINID(pds_id)   (0x00FF & (pds_id >> 8))
 
#define PDS_ID_SUBID(pds_id)   (0x00FF & pds_id)
 
#define PDS_INTERNAL_EEPROM_ID   (0x04)
 PDS Identifier. More...
 
#define PDS_INTERNAL_FLASH_ID   (0x01)
 
#define PDS_INVALID_SECTOR   (0xFF)
 PDS Internal flash ID. More...
 

Typedefs

typedef struct block_header block_header_t
 Block header, located before each block of item data. More...
 
typedef struct pds_env pds_env_t
 containing environment parameters of the NVM module. More...
 
typedef enum pds_item_id pds_item_id_t
 < More...
 
typedef enum pds_status pds_status_t
 PDS Invalid sector identifier. More...
 
typedef struct sector_header sector_header_t
 Sector header, located at sector start. More...
 

Enumerations

enum  pds_item_id { BLE_BONDING_INFO = 0xB0 }
 < More...
 
enum  pds_status {
  PDS_SUCCESS = 0x00,
  PDS_INIT_ERROR = 0x01,
  PDS_NVM_INIT_ERROR,
  PDS_NVM_READ_ERROR,
  PDS_NVM_WRITE_ERROR,
  PDS_INVALID_FLASH_ID,
  PDS_NVM_DELETE_ERROR,
  PDS_NVM_NO_MEMORY,
  PDS_ITEM_NOT_FOUND,
  PDS_ITEM_EXISTS,
  PDS_ITEM_DELETED,
  PDS_ITEM_INACTIVE,
  PDS_ITEM_CRC_ERROR,
  PDS_ITEM_INVALID,
  PDS_ITEM_BIGGER_SIZE,
  PDS_NEW_SECTOR_INITIALIZED,
  PDS_SECTOR_ITEM_ERROR,
  PDS_INVALID_OPERATION,
  PDS_COMPACT_FAILED
}
 

Functions

 COMPILER_PACK_RESET () pds_status_t pds_nvm_init(pds_env_t *pds_instance)
 Initialize the PDS NVM memory controller. More...
 
 COMPILER_PACK_SET (1) typedef struct pds_item_type
 
pds_status_t pds_nvm_erase (pds_env_t *pds_instance, uint32_t mem_address, uint16_t len)
 PDS NVM erase operation. More...
 
pds_status_t pds_nvm_read (pds_env_t *pds_instance, uint32_t mem_address, uint8_t *buffer, uint16_t len)
 PDS NVM read operation. More...
 
pds_status_t pds_nvm_write (pds_env_t *pds_instance, uint32_t mem_address, uint8_t *buffer, uint16_t len)
 PDS NVM write operation. More...
 

Variables

 pds_item_type_t
 

#define NVM_MEMORY   ((volatile uint16_t *)FLASH_ADDR)
#define PDS_BLOCK_ACTIVE_FLAG_Pos   7

Referenced by pds_write().

#define PDS_BLOCK_ACTIVE_MASK (   value)    ((0x1ul << PDS_BLOCK_ACTIVE_FLAG_Pos) & value)

PDS_BLOCK_DELETE_FLAG_Pos Flag.

Referenced by pds_compact_sector(), pds_item_exist(), pds_list_item(), and pds_read().

#define PDS_BLOCK_DELETE_FLAG_Pos   5

Referenced by pds_delete(), and pds_write().

#define PDS_BLOCK_DELETE_MASK (   value)    ((0x1ul << PDS_BLOCK_DELETE_FLAG_Pos) & value)

FLASH base address.

Referenced by pds_compact_sector(), pds_item_exist(), pds_list_item(), and pds_read().

#define PDS_EXTERNAL_EEPROM_ID   (0x03)
#define PDS_EXTERNAL_FLASH_ID   (0x02)
#define PDS_ID (   main_id,
  sub_id 
)    ((main_id << 8) | sub_id)

PDS_BLOCK_ACTIVE_FLAG_Pos Flag.

Referenced by ble_remove_bonding_info(), ble_restore_bonding_info(), and ble_store_bonding_info().

#define PDS_ID_MAINID (   pds_id)    (0x00FF & (pds_id >> 8))
#define PDS_ID_SUBID (   pds_id)    (0x00FF & pds_id)
#define PDS_INTERNAL_EEPROM_ID   (0x04)

PDS Identifier.

#define PDS_INTERNAL_FLASH_ID   (0x01)
#define PDS_INVALID_SECTOR   (0xFF)

PDS Internal flash ID.

Referenced by pds_compact_sector(), and pds_init().

typedef struct block_header block_header_t

Block header, located before each block of item data.

typedef struct pds_env pds_env_t

containing environment parameters of the NVM module.

typedef enum pds_item_id pds_item_id_t

<

list of PDS Item-ID's list of possible PDS status

typedef enum pds_status pds_status_t

PDS Invalid sector identifier.

Sector header, located at sector start.

<

list of PDS Item-ID's

Enumerator
BLE_BONDING_INFO 
enum pds_status
Enumerator
PDS_SUCCESS 

All PDS successful operation status PDS Initialization failed

PDS_INIT_ERROR 

PDS NVM Initialization failures

PDS_NVM_INIT_ERROR 

PDS NVM Memory read error

PDS_NVM_READ_ERROR 

PDS NVM Memory Write error

PDS_NVM_WRITE_ERROR 

PDS Invalid Flash ID

PDS_INVALID_FLASH_ID 

PDS NVM memory delete operation error

PDS_NVM_DELETE_ERROR 

PDS NVM memory out of it's range

PDS_NVM_NO_MEMORY 

PDS Item ID Not found

PDS_ITEM_NOT_FOUND 

PDS Item ID not exists in the active sector

PDS_ITEM_EXISTS 

PDS Item already deleted

PDS_ITEM_DELETED 

PDS Item is inactive, might due to power failures etc.

PDS_ITEM_INACTIVE 

PDS item existing CRC and calculated CRC not matched, data inconsistent

PDS_ITEM_CRC_ERROR 

PDS item not valid

PDS_ITEM_INVALID 

PDS item is bigger than it's buffer size

PDS_ITEM_BIGGER_SIZE 

PDS new sector initialized and no active sector found

PDS_NEW_SECTOR_INITIALIZED 

PDS active item has error

PDS_SECTOR_ITEM_ERROR 

PDS Invalid operation

PDS_INVALID_OPERATION 

PDS compact operation failed

PDS_COMPACT_FAILED 

COMPILER_PACK_RESET ( )

Initialize the PDS NVM memory controller.

Initialize the NVM memory controller, based on the NVM id the respective driver API's must be called, If any errors in the initialization will result in PDS Initialization error

Parameters
[in]pds_instanceInitialized PDS environment structure
Returns
Status of the PDS Initialize procedure
Return values
PDS_SUCCESSPDS Initialize procedure is completed
PDS_INIT_ERRORPDS initialization failed, due to inactive sector or NVM Init failures
forother return values check pds_status_t enum values
COMPILER_PACK_SET ( )

Item structure for faster search of item

< Id of an item.

< Location of the this item.

pds_status_t pds_nvm_erase ( pds_env_t pds_instance,
uint32_t  mem_address,
uint16_t  len 
)

PDS NVM erase operation.

Erase the PDS data from NVM address location for the given size

Parameters
[in]pds_instanceInitialized PDS environment structure
[in]mem_addressNVM address location
[in]lenNVM erase size
Returns
Status of the NVM read operation
Return values
PDS_SUCCESSNVM erase procedure is completed
forother return values check pds_status_t enum values

References pds_env::flash_id, nvm_erase_row(), PDS_INTERNAL_FLASH_ID, PDS_INVALID_FLASH_ID, PDS_SUCCESS, status, system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by pds_compact_sector(), and pds_delete_all().

pds_status_t pds_nvm_read ( pds_env_t pds_instance,
uint32_t  mem_address,
uint8_t *  buffer,
uint16_t  len 
)

PDS NVM read operation.

Read the PDS data from NVM address location for the given size

Parameters
[in]pds_instanceInitialized PDS environment structure
[in]mem_addressNVM address location
[in]bufferNVM read buffer
[in]lenNVM read buffer size
Returns
Status of the NVM read operation
Return values
PDS_SUCCESSNVM read procedure is completed
forother return values check pds_status_t enum values

References Assert, data, pds_env::flash_id, len, nvm_is_ready(), NVM_MEMORY, PDS_INTERNAL_FLASH_ID, PDS_INVALID_FLASH_ID, PDS_NVM_READ_ERROR, and PDS_SUCCESS.

Referenced by pds_compact_sector(), pds_delete(), pds_init(), pds_item_exist(), pds_list_item(), pds_read(), and pds_write().

pds_status_t pds_nvm_write ( pds_env_t pds_instance,
uint32_t  mem_address,
uint8_t *  buffer,
uint16_t  len 
)

PDS NVM write operation.

Write the PDS data into NVM address location

Parameters
[in]pds_instanceInitialized PDS environment structure
[in]mem_addressNVM address location
[in]bufferNVM write buffer
[in]lenNVM write buffer size
Returns
Status of the NVM write procedure
Return values
PDS_SUCCESSNVM write procedure is completed
forother return values check pds_status_t enum values

References buffer, pds_env::flash_id, i, nvm_erase_row(), nvm_read_buffer(), nvm_write_buffer(), PDS_INTERNAL_FLASH_ID, PDS_INVALID_FLASH_ID, PDS_NVM_WRITE_ERROR, PDS_SUCCESS, STATUS_BUSY, STATUS_OK, system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().

Referenced by pds_compact_sector(), pds_delete(), pds_delete_all(), and pds_write().

pds_item_type_t