nRF51 SDK v10.0.0
Data Structures | Macros | Typedefs | Enumerations | Functions
Peer Data Storage

An internal module of Peer Manager. This module provides a Peer Manager-specific API to the persistent storage. More...

Data Structures

struct  pds_evt_t
 Events that can come from the peer_data_storage module. More...
 

Macros

#define PDS_PREPARE_TOKEN_INVALID   0
 
#define PDS_STORE_TOKEN_INVALID   0
 

Typedefs

typedef void(* pds_evt_handler_t )(pds_evt_t const *p_event)
 Event handler for events from the peer_data_storage module. More...
 

Enumerations

enum  pds_convert_t {
  peer_id_to_instance_id = 16384,
  instance_id_to_peer_id = -peer_id_to_instance_id,
  peer_data_id_to_type_id = 32768,
  type_id_to_peer_data_id = -peer_data_id_to_type_id
}
 
enum  pds_evt_id_t {
  PDS_EVT_STORED,
  PDS_EVT_CLEARED,
  PDS_EVT_PEER_ID_CLEAR,
  PDS_EVT_ERROR_STORE,
  PDS_EVT_ERROR_CLEAR,
  PDS_EVT_ERROR_PEER_ID_CLEAR,
  PDS_EVT_COMPRESSED
}
 The types of events that can come from the peer_data_storage module. More...
 

Functions

ret_code_t pds_register (pds_evt_handler_t evt_handler)
 Function for registering for events from the peer database. More...
 
ret_code_t pds_peer_data_read_ptr_get (pm_peer_id_t peer_id, pm_peer_data_id_t data_id, pm_peer_data_flash_t *p_data, pm_store_token_t *p_token)
 Function for retrieving a direct pointer to peer data in persistent storage. More...
 
ret_code_t pds_peer_data_lock (pm_store_token_t store_token)
 Function to lock the flash data (to defer compression from invalidating data) More...
 
ret_code_t pds_peer_data_verify (pm_store_token_t store_token)
 Function to verify flash data integrity. More...
 
ret_code_t pds_peer_data_read (pm_peer_id_t peer_id, pm_peer_data_id_t data_id, pm_peer_data_t *p_data, fds_length_t *p_len_words)
 Function for retrieving peer data from persistent storage by making a copy. More...
 
ret_code_t pds_peer_data_write_prepare (pm_peer_data_const_t const *p_peer_data, pm_prepare_token_t *p_prepare_token)
 Function for preparing persistent storage for a write. More...
 
ret_code_t pds_peer_data_write_prepare_cancel (pm_prepare_token_t prepare_token)
 Function for undoing a previous call to pds_peer_data_write_prepare. More...
 
ret_code_t pds_peer_data_write_prepared (pm_peer_id_t peer_id, pm_peer_data_const_t const *p_peer_data, pm_prepare_token_t prepare_token, pm_store_token_t *p_store_token)
 Function for writing prepared (reserved) peer data to persistent storage. More...
 
ret_code_t pds_peer_data_write (pm_peer_id_t peer_id, pm_peer_data_const_t const *p_peer_data, pm_store_token_t *p_store_token)
 Function for writing peer data to persistent storage. More...
 
ret_code_t pds_peer_data_update (pm_peer_id_t peer_id, pm_peer_data_const_t const *peer_data, pm_store_token_t old_token, pm_store_token_t *p_store_token)
 Function for updating currently stored peer data to a new version. More...
 
ret_code_t pds_peer_data_clear (pm_peer_id_t peer_id, pm_peer_data_id_t data_id)
 Function for clearing peer data from persistent storage. More...
 
pm_peer_id_t pds_peer_id_allocate (void)
 Function for claiming an unused peer ID. More...
 
ret_code_t pds_peer_id_free (pm_peer_id_t peer_id)
 Function for freeing a peer ID and clearing all data associated with it in persistent storage. More...
 
bool pds_peer_id_is_allocated (pm_peer_id_t peer_id)
 Function for finding out whether a peer ID is in use. More...
 
pm_peer_id_t pds_next_peer_id_get (pm_peer_id_t prev_peer_id)
 Function for getting the next peer ID in the sequence of all used peer IDs. Can be used to loop through all used peer IDs. More...
 
uint32_t pds_n_peers (void)
 Function for querying the number of valid peer IDs available. I.E the number of peers in persistent storage. More...
 

Detailed Description

An internal module of Peer Manager. This module provides a Peer Manager-specific API to the persistent storage.

Typedef Documentation

typedef void(* pds_evt_handler_t)(pds_evt_t const *p_event)

Event handler for events from the peer_data_storage module.

Parameters
[in]eventThe event that has happened.
[in]peer_idThe id of the peer the event pertains to.
[in]flagsThe data the event pertains to.

Enumeration Type Documentation

The types of events that can come from the peer_data_storage module.

Enumerator
PDS_EVT_STORED 

The specified data has been successfully stored.

PDS_EVT_CLEARED 

The specified data has been successfully cleared.

PDS_EVT_PEER_ID_CLEAR 

The peer id has been successfully cleared.

PDS_EVT_ERROR_STORE 

The specified data could not be stored.

PDS_EVT_ERROR_CLEAR 

The specified data could not be cleared.

PDS_EVT_ERROR_PEER_ID_CLEAR 

The peer id has been successfully cleared.

PDS_EVT_COMPRESSED 

A compress procedure has finished successfully.

Function Documentation

uint32_t pds_n_peers ( void  )

Function for querying the number of valid peer IDs available. I.E the number of peers in persistent storage.

Returns
The number of valid peer IDs, or 0 if module is not initialized.
pm_peer_id_t pds_next_peer_id_get ( pm_peer_id_t  prev_peer_id)

Function for getting the next peer ID in the sequence of all used peer IDs. Can be used to loop through all used peer IDs.

Note
PM_PEER_ID_INVALID is considered to be before the first and after the last ordinary peer ID.
Parameters
[in]prev_peer_idThe previous peer ID.
Returns
The next peer ID.
The first ordinary peer ID if prev_peer_id was PM_PEER_ID_INVALID.
Return values
PM_PEER_ID_INVALIDif prev_peer_id was the last ordinary peer ID or the module is not initialized.
ret_code_t pds_peer_data_clear ( pm_peer_id_t  peer_id,
pm_peer_data_id_t  data_id 
)

Function for clearing peer data from persistent storage.

Clearing happens asynchronously. Expect a PDS_EVT_CLEARED or PDS_EVT_ERROR_CLEAR event.

Parameters
[in]peer_idThe id of the peer the data pertains to.
[in]data_idWhich data to clear.
Return values
NRF_SUCCESSThe clear was initiated successfully.
NRF_ERROR_INVALID_PARAMData ID or was invalid.
NRF_ERROR_NOT_FOUNDNothing to clear for this peer ID.
NRF_ERROR_INVALID_STATEModule is not initialized.
ret_code_t pds_peer_data_lock ( pm_store_token_t  store_token)

Function to lock the flash data (to defer compression from invalidating data)

Parameters
[in]store_tokenThe token representing the item to lock
ret_code_t pds_peer_data_read ( pm_peer_id_t  peer_id,
pm_peer_data_id_t  data_id,
pm_peer_data_t p_data,
fds_length_t *  p_len_words 
)

Function for retrieving peer data from persistent storage by making a copy.

Parameters
[in]peer_idThe id of the peer whose data to read.
[in]data_idWhich piece of data to read.
[out]p_dataPointer to the peer data.
[in,out]p_len_wordsLength available to copy to (in words). If set to NULL, then no copy will be made and the length will be reflected in p_len_words after the call returns.
Return values
NRF_SUCCESSThe read was successful.
NRF_ERROR_INVALID_PARAMInvalid data_id.
NRF_ERROR_NULLdata contained a NULL pointer.
NRF_ERROR_NOT_FOUNDThe requested data was not found in persistent storage.
NRF_ERROR_NO_MEMThe length of stored data too large to copy out
NRF_ERROR_INVALID_STATEModule is not initialized.
ret_code_t pds_peer_data_read_ptr_get ( pm_peer_id_t  peer_id,
pm_peer_data_id_t  data_id,
pm_peer_data_flash_t p_data,
pm_store_token_t p_token 
)

Function for retrieving a direct pointer to peer data in persistent storage.

Parameters
[in]peer_idThe id of the peer whose data to read.
[in]data_idWhich data to get.
[out]p_dataThe peer data pointer.
[out]p_tokenToken that can be used to lock data in flash and check data validity.
Return values
NRF_SUCCESSThe pointer was successfully retrieved.
NRF_ERROR_INVALID_PARAMInvalid data_id.
NRF_ERROR_NULLp_data was NULL.
NRF_ERROR_NOT_FOUNDThe requested data was not found in persistent storage.
NRF_ERROR_INVALID_STATEModule is not initialized.
ret_code_t pds_peer_data_update ( pm_peer_id_t  peer_id,
pm_peer_data_const_t const *  peer_data,
pm_store_token_t  old_token,
pm_store_token_t p_store_token 
)

Function for updating currently stored peer data to a new version.

Updating happens asynchronously. Expect a PDS_EVT_STORED or PDS_EVT_ERROR_STORE for the store token and a PDS_EVT_ERROR_CLEAR or PDS_EVT_ERROR_CLEAR for the old token

Parameters
[in]peer_idThe peer which the data is associated to.
[in]peer_dataNew data.
[in]old_tokenStore token for the old data.
[out]p_store_tokenStore token for the new data.
Return values
NRF_SUCESSThe update was initiated successfully
NRF_ERROR_NOT_FOUNDThe old store token was invalid.
NRF_ERROR_NULLData contained a NULL pointer.
NRF_ERROR_NO_MEMNo space available in persistent storage.
NRF_ERROR_BUSYFDS or underlying modules are busy and can't take any more requests
NRF_ERROR_INVALID_STATEModule is not initialized.
ret_code_t pds_peer_data_verify ( pm_store_token_t  store_token)

Function to verify flash data integrity.

Parameters
[in]store_tokenThe token representing the item to lock
Return values
NRF_SUCCESSThe data integrity is valid.
NRF_ERROR_NULLThe token is invalid.
NRF_ERROR_INVALID_DATAThe data integrity is not valid.
NRF_ERROR_INVALID_STATEModule is not initialized.
ret_code_t pds_peer_data_write ( pm_peer_id_t  peer_id,
pm_peer_data_const_t const *  p_peer_data,
pm_store_token_t p_store_token 
)

Function for writing peer data to persistent storage.

Writing happens asynchronously. Expect a PDS_EVT_STORED or PDS_EVT_ERROR_STORE event.

Parameters
[in]peer_idThe id of the peer the data pertains to.
[in]p_peer_dataThe peer data.
[out]p_store_tokenA token identifying this particular store operation. The token can be used to identify events pertaining to this operation.
Return values
NRF_SUCCESSThe write was initiated successfully.
NRF_ERROR_INVALID_PARAMInvalid data ID or store_flags.
NRF_ERROR_NULLData contained a NULL pointer.
NRF_ERROR_NO_MEMNo space available in persistent storage. This can only happen if p_prepare_token is NULL.
NRF_ERROR_BUSYFDS or underlying modules are busy and can't take any more requests
NRF_ERROR_INVALID_STATEModule is not initialized.
ret_code_t pds_peer_data_write_prepare ( pm_peer_data_const_t const *  p_peer_data,
pm_prepare_token_t p_prepare_token 
)

Function for preparing persistent storage for a write.

If this call succeeds, space is reserved in persistent storage, so the write will fit.

Note
If space has already been prepared for this peer_id/data_id pair, no new space will be reserved, unless the previous reservation had too small size.
Parameters
[in]p_peer_dataData to prepare for. The data needs not be ready, but length and type values must.
[out]p_prepare_tokenA token identifying the prepared memory area.
Return values
NRF_SUCCESSThe call was successful.
NRF_ERROR_INVALID_PARAMInvalid data ID.
NRF_ERROR_INVALID_LENGTHData length above the maximum allowed.
NRF_ERROR_NO_MEMNo space available in persistent storage.
NRF_ERROR_INVALID_STATEModule is not initialized.
ret_code_t pds_peer_data_write_prepare_cancel ( pm_prepare_token_t  prepare_token)

Function for undoing a previous call to pds_peer_data_write_prepare.

Parameters
[in]prepare_tokenA token identifying the prepared memory area to cancel.
Return values
NRF_SUCCESSThe call was successful.
NRF_ERROR_NOT_FOUNDInvalid peer ID and/or prepare token.
NRF_ERROR_INVALID_STATEModule is not initialized.
ret_code_t pds_peer_data_write_prepared ( pm_peer_id_t  peer_id,
pm_peer_data_const_t const *  p_peer_data,
pm_prepare_token_t  prepare_token,
pm_store_token_t p_store_token 
)

Function for writing prepared (reserved) peer data to persistent storage.

Writing happens asynchronously. Expect a PDS_EVT_STORED or PDS_EVT_ERROR_STORE event.

Parameters
[in]peer_idThe id of the peer the data pertains to.
[in]p_peer_dataThe peer data.
[in]prepare_tokenA token identifying the prepared memory area to write into. If the prepare token is invalid, e.g. PDS_PREPARE_TOKEN_INVALID, the prepare/write sequence will happen atomically.
[out]p_store_tokenA token identifying this particular store operation. The token can be used to identify events pertaining to this operation.
Return values
NRF_SUCCESSThe write was initiated successfully.
NRF_ERROR_INVALID_PARAMInvalid data ID or store_flags.
NRF_ERROR_INVALID_LENGTHLength of data longer than in prepare call.
NRF_ERROR_NULLdata contained a NULL pointer.
NRF_ERROR_NO_MEMNo space available in persistent storage. This can only happen if p_prepare_token is NULL.
NRF_ERROR_BUSYFDS or underlying modules are busy and can't take any more requests
NRF_ERROR_INVALID_STATEModule is not initialized.
pm_peer_id_t pds_peer_id_allocate ( void  )

Function for claiming an unused peer ID.

Returns
The first unused peer ID.
Return values
PM_PEER_ID_INVALIDIf no peer ID is available or module is not initialized.
ret_code_t pds_peer_id_free ( pm_peer_id_t  peer_id)

Function for freeing a peer ID and clearing all data associated with it in persistent storage.

Parameters
[in]peer_idPeer ID to free.
Return values
NRF_SUCCESSThe clear was initiated successfully
NRF_ERROR_BUSYAnother peer_id clear was already requested or fds queue full
bool pds_peer_id_is_allocated ( pm_peer_id_t  peer_id)

Function for finding out whether a peer ID is in use.

Parameters
[in]peer_idThe peer ID to inquire about.
Return values
truepeer_id is in use.
falsepeer_id is free, or the module is not initialized.
ret_code_t pds_register ( pds_evt_handler_t  evt_handler)

Function for registering for events from the peer database.

Note
This function will initialize the module if it is not already initialized.
Parameters
[in]evt_handlerEvent handler to register.
Return values
NRF_SUCCESSRegistration successful.
NRF_ERROR_NO_MEMNo more event handlers can be registered.
NRF_ERROR_NULLevt_handler was NULL.
NRF_ERROR_INVALID_PARAMUnexpected return code from pm_buffer_init.
NRF_ERROR_INVALID_STATEFDS has not been initalized.

This document was last updated on Mon Nov 9 2015.
Please send us your feedback about the documentation! For technical questions, visit the Nordic Developer Zone.