Nordic stack and drivers for the mbed BLE API
Fork of nRF51822 by
TARGET_MCU_NRF51822/sdk/source/ble/peer_manager/peer_data_storage.h@638:c90ae1400bf2, 2016-09-14 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Wed Sep 14 14:39:43 2016 +0100
- Revision:
- 638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
638:c90ae1400bf2 | 1 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 2 | * Copyright (c) Nordic Semiconductor ASA |
Vincent Coubard |
638:c90ae1400bf2 | 3 | * All rights reserved. |
Vincent Coubard |
638:c90ae1400bf2 | 4 | * |
Vincent Coubard |
638:c90ae1400bf2 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Vincent Coubard |
638:c90ae1400bf2 | 6 | * are permitted provided that the following conditions are met: |
Vincent Coubard |
638:c90ae1400bf2 | 7 | * |
Vincent Coubard |
638:c90ae1400bf2 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 9 | * list of conditions and the following disclaimer. |
Vincent Coubard |
638:c90ae1400bf2 | 10 | * |
Vincent Coubard |
638:c90ae1400bf2 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Vincent Coubard |
638:c90ae1400bf2 | 13 | * other materials provided with the distribution. |
Vincent Coubard |
638:c90ae1400bf2 | 14 | * |
Vincent Coubard |
638:c90ae1400bf2 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
Vincent Coubard |
638:c90ae1400bf2 | 16 | * contributors to this software may be used to endorse or promote products |
Vincent Coubard |
638:c90ae1400bf2 | 17 | * derived from this software without specific prior written permission. |
Vincent Coubard |
638:c90ae1400bf2 | 18 | * |
Vincent Coubard |
638:c90ae1400bf2 | 19 | * |
Vincent Coubard |
638:c90ae1400bf2 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Vincent Coubard |
638:c90ae1400bf2 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Vincent Coubard |
638:c90ae1400bf2 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Vincent Coubard |
638:c90ae1400bf2 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Vincent Coubard |
638:c90ae1400bf2 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Vincent Coubard |
638:c90ae1400bf2 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Vincent Coubard |
638:c90ae1400bf2 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Vincent Coubard |
638:c90ae1400bf2 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Vincent Coubard |
638:c90ae1400bf2 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Vincent Coubard |
638:c90ae1400bf2 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Vincent Coubard |
638:c90ae1400bf2 | 30 | * |
Vincent Coubard |
638:c90ae1400bf2 | 31 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 32 | |
Vincent Coubard |
638:c90ae1400bf2 | 33 | |
Vincent Coubard |
638:c90ae1400bf2 | 34 | #ifndef PEER_DATA_STORAGE_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 35 | #define PEER_DATA_STORAGE_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 36 | |
Vincent Coubard |
638:c90ae1400bf2 | 37 | |
Vincent Coubard |
638:c90ae1400bf2 | 38 | #include "stdint.h" |
Vincent Coubard |
638:c90ae1400bf2 | 39 | #include "sdk_errors.h" |
Vincent Coubard |
638:c90ae1400bf2 | 40 | #include "ble_gap.h" |
Vincent Coubard |
638:c90ae1400bf2 | 41 | #include "peer_manager_types.h" |
Vincent Coubard |
638:c90ae1400bf2 | 42 | #include "fds.h" |
Vincent Coubard |
638:c90ae1400bf2 | 43 | |
Vincent Coubard |
638:c90ae1400bf2 | 44 | |
Vincent Coubard |
638:c90ae1400bf2 | 45 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 46 | * @defgroup peer_data_storage Peer Data Storage |
Vincent Coubard |
638:c90ae1400bf2 | 47 | * @ingroup peer_manager |
Vincent Coubard |
638:c90ae1400bf2 | 48 | * @{ |
Vincent Coubard |
638:c90ae1400bf2 | 49 | * @brief An internal module of @ref peer_manager. This module provides a Peer Manager-specific API |
Vincent Coubard |
638:c90ae1400bf2 | 50 | * to the persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 51 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 52 | |
Vincent Coubard |
638:c90ae1400bf2 | 53 | #define PDS_PREPARE_TOKEN_INVALID 0 |
Vincent Coubard |
638:c90ae1400bf2 | 54 | #define PDS_STORE_TOKEN_INVALID 0 |
Vincent Coubard |
638:c90ae1400bf2 | 55 | |
Vincent Coubard |
638:c90ae1400bf2 | 56 | |
Vincent Coubard |
638:c90ae1400bf2 | 57 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 58 | { |
Vincent Coubard |
638:c90ae1400bf2 | 59 | peer_id_to_instance_id = 16384, |
Vincent Coubard |
638:c90ae1400bf2 | 60 | instance_id_to_peer_id = -peer_id_to_instance_id, |
Vincent Coubard |
638:c90ae1400bf2 | 61 | peer_data_id_to_type_id = 32768, |
Vincent Coubard |
638:c90ae1400bf2 | 62 | type_id_to_peer_data_id = -peer_data_id_to_type_id, |
Vincent Coubard |
638:c90ae1400bf2 | 63 | } pds_convert_t; |
Vincent Coubard |
638:c90ae1400bf2 | 64 | |
Vincent Coubard |
638:c90ae1400bf2 | 65 | |
Vincent Coubard |
638:c90ae1400bf2 | 66 | /**@brief The types of events that can come from the peer_data_storage module. |
Vincent Coubard |
638:c90ae1400bf2 | 67 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 68 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 69 | { |
Vincent Coubard |
638:c90ae1400bf2 | 70 | PDS_EVT_STORED, /**< The specified data has been successfully stored. */ |
Vincent Coubard |
638:c90ae1400bf2 | 71 | PDS_EVT_CLEARED, /**< The specified data has been successfully cleared. */ |
Vincent Coubard |
638:c90ae1400bf2 | 72 | PDS_EVT_PEER_ID_CLEAR, /**< The peer id has been successfully cleared. */ |
Vincent Coubard |
638:c90ae1400bf2 | 73 | PDS_EVT_ERROR_STORE, /**< The specified data could not be stored. */ |
Vincent Coubard |
638:c90ae1400bf2 | 74 | PDS_EVT_ERROR_CLEAR, /**< The specified data could not be cleared. */ |
Vincent Coubard |
638:c90ae1400bf2 | 75 | PDS_EVT_ERROR_PEER_ID_CLEAR, /**< The peer id has been successfully cleared. */ |
Vincent Coubard |
638:c90ae1400bf2 | 76 | PDS_EVT_COMPRESSED, /**< A compress procedure has finished successfully. */ |
Vincent Coubard |
638:c90ae1400bf2 | 77 | } pds_evt_id_t; |
Vincent Coubard |
638:c90ae1400bf2 | 78 | |
Vincent Coubard |
638:c90ae1400bf2 | 79 | |
Vincent Coubard |
638:c90ae1400bf2 | 80 | /**@brief Events that can come from the peer_data_storage module. |
Vincent Coubard |
638:c90ae1400bf2 | 81 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 82 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 83 | { |
Vincent Coubard |
638:c90ae1400bf2 | 84 | pds_evt_id_t evt_id; /**< The type of event. */ |
Vincent Coubard |
638:c90ae1400bf2 | 85 | pm_peer_id_t peer_id; /**< The peer the event pertains to. */ |
Vincent Coubard |
638:c90ae1400bf2 | 86 | pm_peer_data_id_t data_id; /**< The data the event pertains to. */ |
Vincent Coubard |
638:c90ae1400bf2 | 87 | pm_store_token_t store_token; |
Vincent Coubard |
638:c90ae1400bf2 | 88 | } pds_evt_t; |
Vincent Coubard |
638:c90ae1400bf2 | 89 | |
Vincent Coubard |
638:c90ae1400bf2 | 90 | |
Vincent Coubard |
638:c90ae1400bf2 | 91 | /**@brief Event handler for events from the peer_data_storage module. |
Vincent Coubard |
638:c90ae1400bf2 | 92 | * |
Vincent Coubard |
638:c90ae1400bf2 | 93 | * @param[in] event The event that has happened. |
Vincent Coubard |
638:c90ae1400bf2 | 94 | * @param[in] peer_id The id of the peer the event pertains to. |
Vincent Coubard |
638:c90ae1400bf2 | 95 | * @param[in] flags The data the event pertains to. |
Vincent Coubard |
638:c90ae1400bf2 | 96 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 97 | typedef void (*pds_evt_handler_t)(pds_evt_t const * p_event); |
Vincent Coubard |
638:c90ae1400bf2 | 98 | |
Vincent Coubard |
638:c90ae1400bf2 | 99 | |
Vincent Coubard |
638:c90ae1400bf2 | 100 | /**@brief Function for registering for events from the peer database. |
Vincent Coubard |
638:c90ae1400bf2 | 101 | * |
Vincent Coubard |
638:c90ae1400bf2 | 102 | * @note This function will initialize the module if it is not already initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 103 | * |
Vincent Coubard |
638:c90ae1400bf2 | 104 | * @param[in] evt_handler Event handler to register. |
Vincent Coubard |
638:c90ae1400bf2 | 105 | * |
Vincent Coubard |
638:c90ae1400bf2 | 106 | * @retval NRF_SUCCESS Registration successful. |
Vincent Coubard |
638:c90ae1400bf2 | 107 | * @retval NRF_ERROR_NO_MEM No more event handlers can be registered. |
Vincent Coubard |
638:c90ae1400bf2 | 108 | * @retval NRF_ERROR_NULL evt_handler was NULL. |
Vincent Coubard |
638:c90ae1400bf2 | 109 | * @retval NRF_ERROR_INVALID_PARAM Unexpected return code from @ref pm_buffer_init. |
Vincent Coubard |
638:c90ae1400bf2 | 110 | * @retval NRF_ERROR_INVALID_STATE FDS has not been initalized. |
Vincent Coubard |
638:c90ae1400bf2 | 111 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 112 | ret_code_t pds_register(pds_evt_handler_t evt_handler); |
Vincent Coubard |
638:c90ae1400bf2 | 113 | |
Vincent Coubard |
638:c90ae1400bf2 | 114 | |
Vincent Coubard |
638:c90ae1400bf2 | 115 | #if 0 |
Vincent Coubard |
638:c90ae1400bf2 | 116 | /**@brief Function for initializing Peer Data storage and registering a |
Vincent Coubard |
638:c90ae1400bf2 | 117 | * callback for its events. |
Vincent Coubard |
638:c90ae1400bf2 | 118 | * |
Vincent Coubard |
638:c90ae1400bf2 | 119 | * @param[in] evt_handler Event handler to register. |
Vincent Coubard |
638:c90ae1400bf2 | 120 | * |
Vincent Coubard |
638:c90ae1400bf2 | 121 | * @retval NRF_SUCCESS Registration successful. |
Vincent Coubard |
638:c90ae1400bf2 | 122 | * @retval NRF_ERROR_NO_MEM No more event handlers can be registered. |
Vincent Coubard |
638:c90ae1400bf2 | 123 | * @retval NRF_ERROR_NULL evt_handler was NULL. |
Vincent Coubard |
638:c90ae1400bf2 | 124 | * @retval NRF_ERROR_INVALID_STATE FDS has not completed initialization. |
Vincent Coubard |
638:c90ae1400bf2 | 125 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 126 | ret_code_t pds_init(pds_evt_handler_t evt_handler); |
Vincent Coubard |
638:c90ae1400bf2 | 127 | #endif |
Vincent Coubard |
638:c90ae1400bf2 | 128 | |
Vincent Coubard |
638:c90ae1400bf2 | 129 | /**@brief Function for retrieving a direct pointer to peer data in persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 130 | * |
Vincent Coubard |
638:c90ae1400bf2 | 131 | * @param[in] peer_id The id of the peer whose data to read. |
Vincent Coubard |
638:c90ae1400bf2 | 132 | * @param[in] data_id Which data to get. |
Vincent Coubard |
638:c90ae1400bf2 | 133 | * @param[out] p_data The peer data pointer. |
Vincent Coubard |
638:c90ae1400bf2 | 134 | * @param[out] p_token Token that can be used to lock data in flash and check data validity. |
Vincent Coubard |
638:c90ae1400bf2 | 135 | * |
Vincent Coubard |
638:c90ae1400bf2 | 136 | * @retval NRF_SUCCESS The pointer was successfully retrieved. |
Vincent Coubard |
638:c90ae1400bf2 | 137 | * @retval NRF_ERROR_INVALID_PARAM Invalid data_id. |
Vincent Coubard |
638:c90ae1400bf2 | 138 | * @retval NRF_ERROR_NULL p_data was NULL. |
Vincent Coubard |
638:c90ae1400bf2 | 139 | * @retval NRF_ERROR_NOT_FOUND The requested data was not found in persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 140 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 141 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 142 | ret_code_t pds_peer_data_read_ptr_get(pm_peer_id_t peer_id, |
Vincent Coubard |
638:c90ae1400bf2 | 143 | pm_peer_data_id_t data_id, |
Vincent Coubard |
638:c90ae1400bf2 | 144 | pm_peer_data_flash_t * p_data, |
Vincent Coubard |
638:c90ae1400bf2 | 145 | pm_store_token_t * p_token); |
Vincent Coubard |
638:c90ae1400bf2 | 146 | |
Vincent Coubard |
638:c90ae1400bf2 | 147 | /**@brief Function to lock the flash data (to defer compression from invalidating data) |
Vincent Coubard |
638:c90ae1400bf2 | 148 | * |
Vincent Coubard |
638:c90ae1400bf2 | 149 | * @param[in] store_token The token representing the item to lock |
Vincent Coubard |
638:c90ae1400bf2 | 150 | * |
Vincent Coubard |
638:c90ae1400bf2 | 151 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 152 | ret_code_t pds_peer_data_lock(pm_store_token_t store_token); |
Vincent Coubard |
638:c90ae1400bf2 | 153 | |
Vincent Coubard |
638:c90ae1400bf2 | 154 | |
Vincent Coubard |
638:c90ae1400bf2 | 155 | /**@brief Function to verify flash data integrity |
Vincent Coubard |
638:c90ae1400bf2 | 156 | * |
Vincent Coubard |
638:c90ae1400bf2 | 157 | * @param[in] store_token The token representing the item to lock |
Vincent Coubard |
638:c90ae1400bf2 | 158 | * |
Vincent Coubard |
638:c90ae1400bf2 | 159 | * @retval NRF_SUCCESS The data integrity is valid. |
Vincent Coubard |
638:c90ae1400bf2 | 160 | * @retval NRF_ERROR_NULL The token is invalid. |
Vincent Coubard |
638:c90ae1400bf2 | 161 | * @retval NRF_ERROR_INVALID_DATA The data integrity is not valid. |
Vincent Coubard |
638:c90ae1400bf2 | 162 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 163 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 164 | ret_code_t pds_peer_data_verify(pm_store_token_t store_token); |
Vincent Coubard |
638:c90ae1400bf2 | 165 | |
Vincent Coubard |
638:c90ae1400bf2 | 166 | |
Vincent Coubard |
638:c90ae1400bf2 | 167 | /**@brief Function for retrieving peer data from persistent storage by making a copy |
Vincent Coubard |
638:c90ae1400bf2 | 168 | * |
Vincent Coubard |
638:c90ae1400bf2 | 169 | * @param[in] peer_id The id of the peer whose data to read. |
Vincent Coubard |
638:c90ae1400bf2 | 170 | * @param[in] data_id Which piece of data to read. |
Vincent Coubard |
638:c90ae1400bf2 | 171 | * @param[out] p_data Pointer to the peer data. |
Vincent Coubard |
638:c90ae1400bf2 | 172 | * @param[in,out] p_len_words Length available to copy to (in words). |
Vincent Coubard |
638:c90ae1400bf2 | 173 | * If set to NULL, then no copy will be made and the |
Vincent Coubard |
638:c90ae1400bf2 | 174 | * length will be reflected in p_len_words after the call returns. |
Vincent Coubard |
638:c90ae1400bf2 | 175 | * |
Vincent Coubard |
638:c90ae1400bf2 | 176 | * @retval NRF_SUCCESS The read was successful. |
Vincent Coubard |
638:c90ae1400bf2 | 177 | * @retval NRF_ERROR_INVALID_PARAM Invalid data_id. |
Vincent Coubard |
638:c90ae1400bf2 | 178 | * @retval NRF_ERROR_NULL data contained a NULL pointer. |
Vincent Coubard |
638:c90ae1400bf2 | 179 | * @retval NRF_ERROR_NOT_FOUND The requested data was not found in persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 180 | * @retval NRF_ERROR_NO_MEM The length of stored data too large to copy out |
Vincent Coubard |
638:c90ae1400bf2 | 181 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 182 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 183 | ret_code_t pds_peer_data_read(pm_peer_id_t peer_id, |
Vincent Coubard |
638:c90ae1400bf2 | 184 | pm_peer_data_id_t data_id, |
Vincent Coubard |
638:c90ae1400bf2 | 185 | pm_peer_data_t * p_data, |
Vincent Coubard |
638:c90ae1400bf2 | 186 | fds_length_t * p_len_words); |
Vincent Coubard |
638:c90ae1400bf2 | 187 | |
Vincent Coubard |
638:c90ae1400bf2 | 188 | |
Vincent Coubard |
638:c90ae1400bf2 | 189 | /**@brief Function for preparing persistent storage for a write. |
Vincent Coubard |
638:c90ae1400bf2 | 190 | * |
Vincent Coubard |
638:c90ae1400bf2 | 191 | * @details If this call succeeds, space is reserved in persistent storage, so the write will fit. |
Vincent Coubard |
638:c90ae1400bf2 | 192 | * |
Vincent Coubard |
638:c90ae1400bf2 | 193 | * @note If space has already been prepared for this peer_id/data_id pair, no new space will be |
Vincent Coubard |
638:c90ae1400bf2 | 194 | * reserved, unless the previous reservation had too small size. |
Vincent Coubard |
638:c90ae1400bf2 | 195 | * |
Vincent Coubard |
638:c90ae1400bf2 | 196 | * @param[in] p_peer_data Data to prepare for. The data needs not be ready, but length and type |
Vincent Coubard |
638:c90ae1400bf2 | 197 | * values must. |
Vincent Coubard |
638:c90ae1400bf2 | 198 | * @param[out] p_prepare_token A token identifying the prepared memory area. |
Vincent Coubard |
638:c90ae1400bf2 | 199 | * |
Vincent Coubard |
638:c90ae1400bf2 | 200 | * @retval NRF_SUCCESS The call was successful. |
Vincent Coubard |
638:c90ae1400bf2 | 201 | * @retval NRF_ERROR_INVALID_PARAM Invalid data ID. |
Vincent Coubard |
638:c90ae1400bf2 | 202 | * @retval NRF_ERROR_INVALID_LENGTH Data length above the maximum allowed. |
Vincent Coubard |
638:c90ae1400bf2 | 203 | * @retval NRF_ERROR_NO_MEM No space available in persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 204 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 205 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 206 | ret_code_t pds_peer_data_write_prepare(pm_peer_data_const_t const * p_peer_data, |
Vincent Coubard |
638:c90ae1400bf2 | 207 | pm_prepare_token_t * p_prepare_token); |
Vincent Coubard |
638:c90ae1400bf2 | 208 | |
Vincent Coubard |
638:c90ae1400bf2 | 209 | |
Vincent Coubard |
638:c90ae1400bf2 | 210 | /**@brief Function for undoing a previous call to @ref pds_peer_data_write_prepare. |
Vincent Coubard |
638:c90ae1400bf2 | 211 | * |
Vincent Coubard |
638:c90ae1400bf2 | 212 | * @param[in] prepare_token A token identifying the prepared memory area to cancel. |
Vincent Coubard |
638:c90ae1400bf2 | 213 | * |
Vincent Coubard |
638:c90ae1400bf2 | 214 | * @retval NRF_SUCCESS The call was successful. |
Vincent Coubard |
638:c90ae1400bf2 | 215 | * @retval NRF_ERROR_NOT_FOUND Invalid peer ID and/or prepare token. |
Vincent Coubard |
638:c90ae1400bf2 | 216 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 217 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 218 | ret_code_t pds_peer_data_write_prepare_cancel(pm_prepare_token_t prepare_token); |
Vincent Coubard |
638:c90ae1400bf2 | 219 | |
Vincent Coubard |
638:c90ae1400bf2 | 220 | |
Vincent Coubard |
638:c90ae1400bf2 | 221 | /**@brief Function for writing prepared (reserved) peer data to persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 222 | * |
Vincent Coubard |
638:c90ae1400bf2 | 223 | * @details Writing happens asynchronously. Expect a @ref PDS_EVT_STORED or @ref PDS_EVT_ERROR_STORE |
Vincent Coubard |
638:c90ae1400bf2 | 224 | * event. |
Vincent Coubard |
638:c90ae1400bf2 | 225 | * |
Vincent Coubard |
638:c90ae1400bf2 | 226 | * @param[in] peer_id The id of the peer the data pertains to. |
Vincent Coubard |
638:c90ae1400bf2 | 227 | * @param[in] p_peer_data The peer data. |
Vincent Coubard |
638:c90ae1400bf2 | 228 | * @param[in] prepare_token A token identifying the prepared memory area to write into. If |
Vincent Coubard |
638:c90ae1400bf2 | 229 | * the prepare token is invalid, e.g. PDS_PREPARE_TOKEN_INVALID, the |
Vincent Coubard |
638:c90ae1400bf2 | 230 | * prepare/write sequence will happen atomically. |
Vincent Coubard |
638:c90ae1400bf2 | 231 | * @param[out] p_store_token A token identifying this particular store operation. The token can be |
Vincent Coubard |
638:c90ae1400bf2 | 232 | * used to identify events pertaining to this operation. |
Vincent Coubard |
638:c90ae1400bf2 | 233 | * |
Vincent Coubard |
638:c90ae1400bf2 | 234 | * @retval NRF_SUCCESS The write was initiated successfully. |
Vincent Coubard |
638:c90ae1400bf2 | 235 | * @retval NRF_ERROR_INVALID_PARAM Invalid data ID or store_flags. |
Vincent Coubard |
638:c90ae1400bf2 | 236 | * @retval NRF_ERROR_INVALID_LENGTH Length of data longer than in prepare call. |
Vincent Coubard |
638:c90ae1400bf2 | 237 | * @retval NRF_ERROR_NULL data contained a NULL pointer. |
Vincent Coubard |
638:c90ae1400bf2 | 238 | * @retval NRF_ERROR_NO_MEM No space available in persistent storage. This can only happen |
Vincent Coubard |
638:c90ae1400bf2 | 239 | * if p_prepare_token is NULL. |
Vincent Coubard |
638:c90ae1400bf2 | 240 | * @retval NRF_ERROR_BUSY FDS or underlying modules are busy and can't take any |
Vincent Coubard |
638:c90ae1400bf2 | 241 | * more requests |
Vincent Coubard |
638:c90ae1400bf2 | 242 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 243 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 244 | ret_code_t pds_peer_data_write_prepared(pm_peer_id_t peer_id, |
Vincent Coubard |
638:c90ae1400bf2 | 245 | pm_peer_data_const_t const * p_peer_data, |
Vincent Coubard |
638:c90ae1400bf2 | 246 | pm_prepare_token_t prepare_token, |
Vincent Coubard |
638:c90ae1400bf2 | 247 | pm_store_token_t * p_store_token); |
Vincent Coubard |
638:c90ae1400bf2 | 248 | |
Vincent Coubard |
638:c90ae1400bf2 | 249 | |
Vincent Coubard |
638:c90ae1400bf2 | 250 | /**@brief Function for writing peer data to persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 251 | * |
Vincent Coubard |
638:c90ae1400bf2 | 252 | * @details Writing happens asynchronously. Expect a @ref PDS_EVT_STORED or @ref PDS_EVT_ERROR_STORE |
Vincent Coubard |
638:c90ae1400bf2 | 253 | * event. |
Vincent Coubard |
638:c90ae1400bf2 | 254 | * |
Vincent Coubard |
638:c90ae1400bf2 | 255 | * @param[in] peer_id The id of the peer the data pertains to. |
Vincent Coubard |
638:c90ae1400bf2 | 256 | * @param[in] p_peer_data The peer data. |
Vincent Coubard |
638:c90ae1400bf2 | 257 | * @param[out] p_store_token A token identifying this particular store operation. The token can be |
Vincent Coubard |
638:c90ae1400bf2 | 258 | * used to identify events pertaining to this operation. |
Vincent Coubard |
638:c90ae1400bf2 | 259 | * |
Vincent Coubard |
638:c90ae1400bf2 | 260 | * @retval NRF_SUCCESS The write was initiated successfully. |
Vincent Coubard |
638:c90ae1400bf2 | 261 | * @retval NRF_ERROR_INVALID_PARAM Invalid data ID or store_flags. |
Vincent Coubard |
638:c90ae1400bf2 | 262 | * @retval NRF_ERROR_NULL Data contained a NULL pointer. |
Vincent Coubard |
638:c90ae1400bf2 | 263 | * @retval NRF_ERROR_NO_MEM No space available in persistent storage. This can only happen |
Vincent Coubard |
638:c90ae1400bf2 | 264 | * if p_prepare_token is NULL. |
Vincent Coubard |
638:c90ae1400bf2 | 265 | * @retval NRF_ERROR_BUSY FDS or underlying modules are busy and can't take any |
Vincent Coubard |
638:c90ae1400bf2 | 266 | * more requests |
Vincent Coubard |
638:c90ae1400bf2 | 267 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 268 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 269 | ret_code_t pds_peer_data_write(pm_peer_id_t peer_id, |
Vincent Coubard |
638:c90ae1400bf2 | 270 | pm_peer_data_const_t const * p_peer_data, |
Vincent Coubard |
638:c90ae1400bf2 | 271 | pm_store_token_t * p_store_token); |
Vincent Coubard |
638:c90ae1400bf2 | 272 | |
Vincent Coubard |
638:c90ae1400bf2 | 273 | |
Vincent Coubard |
638:c90ae1400bf2 | 274 | /**@brief Function for updating currently stored peer data to a new version |
Vincent Coubard |
638:c90ae1400bf2 | 275 | * |
Vincent Coubard |
638:c90ae1400bf2 | 276 | * @details Updating happens asynchronously. |
Vincent Coubard |
638:c90ae1400bf2 | 277 | * Expect a @ref PDS_EVT_STORED or @ref PDS_EVT_ERROR_STORE for the store token |
Vincent Coubard |
638:c90ae1400bf2 | 278 | * and a @ref PDS_EVT_ERROR_CLEAR or @ref PDS_EVT_ERROR_CLEAR for the old token |
Vincent Coubard |
638:c90ae1400bf2 | 279 | * |
Vincent Coubard |
638:c90ae1400bf2 | 280 | * @param[in] peer_id The peer which the data is associated to. |
Vincent Coubard |
638:c90ae1400bf2 | 281 | * @param[in] peer_data New data. |
Vincent Coubard |
638:c90ae1400bf2 | 282 | * @param[in] old_token Store token for the old data. |
Vincent Coubard |
638:c90ae1400bf2 | 283 | * @param[out] p_store_token Store token for the new data. |
Vincent Coubard |
638:c90ae1400bf2 | 284 | * |
Vincent Coubard |
638:c90ae1400bf2 | 285 | * @retval NRF_SUCESS The update was initiated successfully |
Vincent Coubard |
638:c90ae1400bf2 | 286 | * @retval NRF_ERROR_NOT_FOUND The old store token was invalid. |
Vincent Coubard |
638:c90ae1400bf2 | 287 | * @retval NRF_ERROR_NULL Data contained a NULL pointer. |
Vincent Coubard |
638:c90ae1400bf2 | 288 | * @retval NRF_ERROR_NO_MEM No space available in persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 289 | * @retval NRF_ERROR_BUSY FDS or underlying modules are busy and can't take any |
Vincent Coubard |
638:c90ae1400bf2 | 290 | * more requests |
Vincent Coubard |
638:c90ae1400bf2 | 291 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 292 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 293 | ret_code_t pds_peer_data_update(pm_peer_id_t peer_id, |
Vincent Coubard |
638:c90ae1400bf2 | 294 | pm_peer_data_const_t const * peer_data, |
Vincent Coubard |
638:c90ae1400bf2 | 295 | pm_store_token_t old_token, |
Vincent Coubard |
638:c90ae1400bf2 | 296 | pm_store_token_t * p_store_token); |
Vincent Coubard |
638:c90ae1400bf2 | 297 | |
Vincent Coubard |
638:c90ae1400bf2 | 298 | |
Vincent Coubard |
638:c90ae1400bf2 | 299 | /**@brief Function for clearing peer data from persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 300 | * |
Vincent Coubard |
638:c90ae1400bf2 | 301 | * @details Clearing happens asynchronously. Expect a @ref PDS_EVT_CLEARED or @ref PDS_EVT_ERROR_CLEAR |
Vincent Coubard |
638:c90ae1400bf2 | 302 | * event. |
Vincent Coubard |
638:c90ae1400bf2 | 303 | * |
Vincent Coubard |
638:c90ae1400bf2 | 304 | * @param[in] peer_id The id of the peer the data pertains to. |
Vincent Coubard |
638:c90ae1400bf2 | 305 | * @param[in] data_id Which data to clear. |
Vincent Coubard |
638:c90ae1400bf2 | 306 | * |
Vincent Coubard |
638:c90ae1400bf2 | 307 | * @retval NRF_SUCCESS The clear was initiated successfully. |
Vincent Coubard |
638:c90ae1400bf2 | 308 | * @retval NRF_ERROR_INVALID_PARAM Data ID or was invalid. |
Vincent Coubard |
638:c90ae1400bf2 | 309 | * @retval NRF_ERROR_NOT_FOUND Nothing to clear for this peer ID. |
Vincent Coubard |
638:c90ae1400bf2 | 310 | * @retval NRF_ERROR_INVALID_STATE Module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 311 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 312 | ret_code_t pds_peer_data_clear(pm_peer_id_t peer_id, pm_peer_data_id_t data_id); |
Vincent Coubard |
638:c90ae1400bf2 | 313 | |
Vincent Coubard |
638:c90ae1400bf2 | 314 | |
Vincent Coubard |
638:c90ae1400bf2 | 315 | /**@brief Function for claiming an unused peer ID. |
Vincent Coubard |
638:c90ae1400bf2 | 316 | * |
Vincent Coubard |
638:c90ae1400bf2 | 317 | * @return The first unused peer ID. |
Vincent Coubard |
638:c90ae1400bf2 | 318 | * @retval PM_PEER_ID_INVALID If no peer ID is available or module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 319 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 320 | pm_peer_id_t pds_peer_id_allocate(void); |
Vincent Coubard |
638:c90ae1400bf2 | 321 | |
Vincent Coubard |
638:c90ae1400bf2 | 322 | |
Vincent Coubard |
638:c90ae1400bf2 | 323 | /**@brief Function for freeing a peer ID and clearing all data associated with it in persistent |
Vincent Coubard |
638:c90ae1400bf2 | 324 | * storage. |
Vincent Coubard |
638:c90ae1400bf2 | 325 | * |
Vincent Coubard |
638:c90ae1400bf2 | 326 | * @param[in] peer_id Peer ID to free. |
Vincent Coubard |
638:c90ae1400bf2 | 327 | * |
Vincent Coubard |
638:c90ae1400bf2 | 328 | * @retval NRF_SUCCESS The clear was initiated successfully |
Vincent Coubard |
638:c90ae1400bf2 | 329 | * @retval NRF_ERROR_BUSY Another peer_id clear was already requested or fds queue full |
Vincent Coubard |
638:c90ae1400bf2 | 330 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 331 | ret_code_t pds_peer_id_free(pm_peer_id_t peer_id); |
Vincent Coubard |
638:c90ae1400bf2 | 332 | |
Vincent Coubard |
638:c90ae1400bf2 | 333 | |
Vincent Coubard |
638:c90ae1400bf2 | 334 | /**@brief Function for finding out whether a peer ID is in use. |
Vincent Coubard |
638:c90ae1400bf2 | 335 | * |
Vincent Coubard |
638:c90ae1400bf2 | 336 | * @param[in] peer_id The peer ID to inquire about. |
Vincent Coubard |
638:c90ae1400bf2 | 337 | * |
Vincent Coubard |
638:c90ae1400bf2 | 338 | * @retval true peer_id is in use. |
Vincent Coubard |
638:c90ae1400bf2 | 339 | * @retval false peer_id is free, or the module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 340 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 341 | bool pds_peer_id_is_allocated(pm_peer_id_t peer_id); |
Vincent Coubard |
638:c90ae1400bf2 | 342 | |
Vincent Coubard |
638:c90ae1400bf2 | 343 | |
Vincent Coubard |
638:c90ae1400bf2 | 344 | /**@brief Function for getting the next peer ID in the sequence of all used peer IDs. Can be |
Vincent Coubard |
638:c90ae1400bf2 | 345 | * used to loop through all used peer IDs. |
Vincent Coubard |
638:c90ae1400bf2 | 346 | * |
Vincent Coubard |
638:c90ae1400bf2 | 347 | * @note @ref PM_PEER_ID_INVALID is considered to be before the first and after the last ordinary |
Vincent Coubard |
638:c90ae1400bf2 | 348 | * peer ID. |
Vincent Coubard |
638:c90ae1400bf2 | 349 | * |
Vincent Coubard |
638:c90ae1400bf2 | 350 | * @param[in] prev_peer_id The previous peer ID. |
Vincent Coubard |
638:c90ae1400bf2 | 351 | * |
Vincent Coubard |
638:c90ae1400bf2 | 352 | * @return The next peer ID. |
Vincent Coubard |
638:c90ae1400bf2 | 353 | * @return The first ordinary peer ID if prev_peer_id was @ref PM_PEER_ID_INVALID. |
Vincent Coubard |
638:c90ae1400bf2 | 354 | * @retval PM_PEER_ID_INVALID if prev_peer_id was the last ordinary peer ID or the module |
Vincent Coubard |
638:c90ae1400bf2 | 355 | * is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 356 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 357 | pm_peer_id_t pds_next_peer_id_get(pm_peer_id_t prev_peer_id); |
Vincent Coubard |
638:c90ae1400bf2 | 358 | |
Vincent Coubard |
638:c90ae1400bf2 | 359 | |
Vincent Coubard |
638:c90ae1400bf2 | 360 | /**@brief Function for querying the number of valid peer IDs available. I.E the number of peers |
Vincent Coubard |
638:c90ae1400bf2 | 361 | * in persistent storage. |
Vincent Coubard |
638:c90ae1400bf2 | 362 | * |
Vincent Coubard |
638:c90ae1400bf2 | 363 | * @return The number of valid peer IDs, or 0 if module is not initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 364 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 365 | uint32_t pds_n_peers(void); |
Vincent Coubard |
638:c90ae1400bf2 | 366 | |
Vincent Coubard |
638:c90ae1400bf2 | 367 | |
Vincent Coubard |
638:c90ae1400bf2 | 368 | /** @} */ |
Vincent Coubard |
638:c90ae1400bf2 | 369 | |
Vincent Coubard |
638:c90ae1400bf2 | 370 | #endif /* PEER_DATA_STORAGE_H__ */ |