Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
pstorage.h
00001 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * Terms and conditions of usage are described in detail in NORDIC 00005 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 */ 00012 00013 /**@file 00014 * 00015 * @defgroup persistent_storage Persistent Storage Interface 00016 * @{ 00017 * @ingroup app_common 00018 * @brief Abstracted flash interface. 00019 * 00020 * @details In order to ensure that the SDK and application be moved to alternate persistent storage 00021 * options other than the default provided with NRF solution, an abstracted interface is provided 00022 * by the module to ensure SDK modules and application can be ported to alternate option with ease. 00023 */ 00024 00025 #ifndef PSTORAGE_H__ 00026 #define PSTORAGE_H__ 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif /* #ifdef __cplusplus */ 00031 00032 #include "pstorage_platform.h" 00033 00034 00035 /**@defgroup ps_opcode Persistent Storage Access Operation Codes 00036 * @{ 00037 * @brief Persistent Storage Access Operation Codes. These are used to report any error during 00038 * a persistent storage access operation or any general error that may occur in the 00039 * interface. 00040 * 00041 * @details Persistent Storage Access Operation Codes used in error notification callback 00042 * registered with the interface to report any error during an persistent storage access 00043 * operation or any general error that may occur in the interface. 00044 */ 00045 #define PSTORAGE_ERROR_OP_CODE 0x01 /**< General Error Code */ 00046 #define PSTORAGE_STORE_OP_CODE 0x02 /**< Error when Store Operation was requested */ 00047 #define PSTORAGE_LOAD_OP_CODE 0x03 /**< Error when Load Operation was requested */ 00048 #define PSTORAGE_CLEAR_OP_CODE 0x04 /**< Error when Clear Operation was requested */ 00049 #define PSTORAGE_UPDATE_OP_CODE 0x05 /**< Update an already touched storage block */ 00050 00051 /**@} */ 00052 00053 /**@defgroup pstorage_data_types Persistent Memory Interface Data Types 00054 * @{ 00055 * @brief Data Types needed for interfacing with persistent memory. 00056 * 00057 * @details Data Types needed for interfacing with persistent memory. 00058 */ 00059 00060 /**@brief Persistent Storage Error Reporting Callback 00061 * 00062 * @details Persistent Storage Error Reporting Callback that is used by the interface to report 00063 * success or failure of a flash operation. Therefore, for any operations, application 00064 * can know when the procedure was complete. For store operation, since no data copy 00065 * is made, receiving a success or failure notification, indicated by the reason 00066 * parameter of callback is an indication that the resident memory could now be reused 00067 * or freed, as the case may be. 00068 * 00069 * @param[in] handle Identifies module and block for which callback is received. 00070 * @param[in] op_code Identifies the operation for which the event is notified. 00071 * @param[in] result Identifies the result of flash access operation. 00072 * NRF_SUCCESS implies, operation succeeded. 00073 * @param[in] p_data Identifies the application data pointer. In case of store operation, this 00074 * points to the resident source of application memory that application can now 00075 * free or reuse. In case of clear, this is NULL as no application pointer is 00076 * needed for this operation. 00077 * @param[in] data_len Length data application had provided for the operation. 00078 * 00079 */ 00080 typedef void (*pstorage_ntf_cb_t)(pstorage_handle_t * p_handle, 00081 uint8_t op_code, 00082 uint32_t result, 00083 uint8_t * p_data, 00084 uint32_t data_len); 00085 00086 00087 typedef struct 00088 { 00089 pstorage_ntf_cb_t cb; /**< Callback registered with the module to be notified of any error occurring in persistent memory management */ 00090 pstorage_size_t block_size; /**< Desired block size for persistent memory storage, for example, if a module has a table with 10 entries, each entry is size 64 bytes, 00091 * it can request 10 blocks with block size 64 bytes. On the other hand, the module can also request one block of size 640 based on 00092 * how it would like to access or alter memory in persistent memory. 00093 * First option is preferred when single entries that need to be updated often when having no impact on the other entries. 00094 * While second option is preferred when entries of table are not changed on individually but have common point of loading and storing 00095 * data. */ 00096 pstorage_size_t block_count; /** Number of blocks requested by the module, minimum values is 1. */ 00097 } pstorage_module_param_t; 00098 00099 /**@} */ 00100 00101 /**@defgroup pstorage_routines Persistent Storage Access Routines 00102 * @{ 00103 * @brief Functions/Interface SDK modules use to persistently store data. 00104 * 00105 * @details Interface for Application & SDK module to load/store information persistently. 00106 * Note: that while implementation of each of the persistent storage access function 00107 * depends on the system and can specific to system/solution, the signature of the 00108 * interface routines should not be altered. 00109 */ 00110 00111 /**@brief Module Initialization Routine. 00112 * 00113 * @details Initializes module. To be called once before any other APIs of the module are used. 00114 * 00115 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00116 */ 00117 uint32_t pstorage_init(void); 00118 00119 00120 /**@brief Register with persistent storage interface. 00121 * 00122 * @param[in] p_module_param Module registration param. 00123 * @param[out] p_block_id Block identifier to identify persistent memory blocks in case 00124 * registration succeeds. Application is expected to use the block ids 00125 * for subsequent operations on requested persistent memory. Maximum 00126 * registrations permitted is determined by configuration parameter 00127 * PSTORAGE_MAX_APPLICATIONS. 00128 * In case more than one memory blocks are requested, the identifier provided here is 00129 * the base identifier for the first block and to identify subsequent block, 00130 * application shall use \@ref pstorage_block_identifier_get with this base identifier 00131 * and block number. Therefore if 10 blocks of size 64 are requested and application 00132 * wishes to store memory in 6th block, it shall use 00133 * \@ref pstorage_block_identifier_get with based id and provide a block number of 5. 00134 * This way application is only expected to remember the base block identifier. 00135 * 00136 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00137 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00138 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00139 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00140 * @retval NRF_ERROR_NO_MEM in case no more registrations can be supported. 00141 */ 00142 uint32_t pstorage_register(pstorage_module_param_t * p_module_param, 00143 pstorage_handle_t * p_block_id); 00144 00145 00146 /** 00147 * @brief Function to get block id with reference to base block identifier provided at time of 00148 * registration. 00149 * 00150 * @details Function to get block id with reference to base block identifier provided at time of 00151 * registration. 00152 * In case more than one memory blocks were requested when registering, the identifier 00153 * provided here is the base identifier for the first block and to identify subsequent 00154 * block, application shall use this routine to get block identifier providing input as 00155 * base identifier and block number. Therefore if 10 blocks of size 64 are requested and 00156 * application wishes to store memory in 6th block, it shall use 00157 * \@ref pstorage_block_identifier_get with based id and provide a block number of 5. 00158 * This way application is only expected to remember the base block identifier. 00159 * 00160 * @param[in] p_base_id Base block id received at the time of registration. 00161 * @param[in] block_num Block Number, with first block numbered zero. 00162 * @param[out] p_block_id Block identifier for the block number requested in case the API succeeds. 00163 * 00164 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00165 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00166 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00167 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00168 */ 00169 uint32_t pstorage_block_identifier_get(pstorage_handle_t * p_base_id, 00170 pstorage_size_t block_num, 00171 pstorage_handle_t * p_block_id); 00172 00173 00174 /**@brief Routine to persistently store data of length 'size' contained in 'p_src' address 00175 * in storage module at 'p_dest' address; Equivalent to Storage Write. 00176 * 00177 * @param[in] p_dest Destination address where data is to be stored persistently. 00178 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident 00179 * memory and no intermediate copy of data is made by the API. 00180 * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned. 00181 * @param[in] offset Offset in bytes to be applied when writing to the block. 00182 * For example, if within a block of 100 bytes, application wishes to 00183 * write 20 bytes at offset of 12, then this field should be set to 12. 00184 * Should be word aligned. 00185 * 00186 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00187 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00188 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00189 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00190 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_src' is not aligned. 00191 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00192 * 00193 * @warning No copy of the data is made, and hence memory provided for data source to be written 00194 * to flash cannot be freed or reused by the application until this procedure 00195 * is complete. End of this procedure is notified to the application using the 00196 * notification callback registered by the application. 00197 */ 00198 uint32_t pstorage_store(pstorage_handle_t * p_dest, 00199 uint8_t * p_src, 00200 pstorage_size_t size, 00201 pstorage_size_t offset); 00202 00203 /**@brief Routine to update persistently stored data of length 'size' contained in 'p_src' address 00204 * in storage module at 'p_dest' address. 00205 * 00206 * @param[in] p_dest Destination address where data is to be updated. 00207 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident 00208 * memory and no intermediate copy of data is made by the API. 00209 * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned. 00210 * @param[in] offset Offset in bytes to be applied when writing to the block. 00211 * For example, if within a block of 100 bytes, application wishes to 00212 * write 20 bytes at offset of 12, then this field should be set to 12. 00213 * Should be word aligned. 00214 * 00215 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00216 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00217 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00218 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00219 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_src' is not aligned. 00220 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00221 * 00222 * @warning No copy of the data is made, and hence memory provided for data source to be written 00223 * to flash cannot be freed or reused by the application until this procedure 00224 * is complete. End of this procedure is notified to the application using the 00225 * notification callback registered by the application. 00226 */ 00227 uint32_t pstorage_update(pstorage_handle_t * p_dest, 00228 uint8_t * p_src, 00229 pstorage_size_t size, 00230 pstorage_size_t offset); 00231 00232 /**@brief Routine to load persistently stored data of length 'size' from 'p_src' address 00233 * to 'p_dest' address; Equivalent to Storage Read. 00234 * 00235 * @param[in] p_dest Destination address where persistently stored data is to be loaded. 00236 * @param[in] p_src Source from where data is to be loaded from persistent memory. 00237 * @param[in] size Size of data to be loaded from persistent memory expressed in bytes. 00238 * Should be word aligned. 00239 * @param[in] offset Offset in bytes to be applied when loading from the block. 00240 * For example, if within a block of 100 bytes, application wishes to 00241 * load 20 bytes from offset of 12, then this field should be set to 12. 00242 * Should be word aligned. 00243 * 00244 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00245 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00246 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00247 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00248 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_dst' is not aligned. 00249 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00250 */ 00251 uint32_t pstorage_load(uint8_t * p_dest, 00252 pstorage_handle_t * p_src, 00253 pstorage_size_t size, 00254 pstorage_size_t offset); 00255 00256 /**@brief Routine to clear data in persistent memory. 00257 * 00258 * @param[in] p_base_id Base block identifier in persistent memory that needs to cleared; 00259 * Equivalent to an Erase Operation. 00260 * 00261 * @param[in] size Size of data to be cleared from persistent memory expressed in bytes. 00262 * This parameter is to provision for clearing of certain blocks 00263 * of memory, or all memory blocks in a registered module. If the total size 00264 * of the application module is used (blocks * block size) in combination with 00265 * the identifier for the first block in the module, all blocks in the 00266 * module will be erased. 00267 * 00268 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00269 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00270 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00271 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00272 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_dst' is not aligned. 00273 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00274 * 00275 * @note Clear operations may take time. This API however, does not block until the clear 00276 * procedure is complete. Application is notified of procedure completion using 00277 * notification callback registered by the application. 'result' parameter of the 00278 * callback suggests if the procedure was successful or not. 00279 */ 00280 uint32_t pstorage_clear(pstorage_handle_t * p_base_id, pstorage_size_t size); 00281 00282 /** 00283 * @brief API to get status of number of pending operations with the module. 00284 * 00285 * @param[out] p_count Number of storage operations pending with the module, if 0, 00286 * there are no outstanding requests. 00287 * 00288 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00289 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00290 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00291 */ 00292 uint32_t pstorage_access_status_get(uint32_t * p_count); 00293 00294 #ifdef PSTORAGE_RAW_MODE_ENABLE 00295 00296 /**@brief Function for registering with persistent storage interface. 00297 * 00298 * @param[in] p_module_param Module registration param. 00299 * @param[out] p_block_id Block identifier to identify persistent memory blocks in case 00300 * registration succeeds. Application is expected to use the block ids 00301 * for subsequent operations on requested persistent memory. 00302 * In case more than one memory blocks are requested, the identifier provided here is 00303 * the base identifier for the first block and to identify subsequent block, 00304 * application shall use \@ref pstorage_block_identifier_get with this base identifier 00305 * and block number. Therefore if 10 blocks of size 64 are requested and application 00306 * wishes to store memory in 6th block, it shall use 00307 * \@ref pstorage_block_identifier_get with based id and provide a block number of 5. 00308 * This way application is only expected to remember the base block identifier. 00309 * 00310 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00311 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00312 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00313 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00314 * @retval NRF_ERROR_NO_MEM in case no more registrations can be supported. 00315 */ 00316 uint32_t pstorage_raw_register(pstorage_module_param_t * p_module_param, 00317 pstorage_handle_t * p_block_id); 00318 00319 /**@brief Raw mode function for persistently storing data of length 'size' contained in 'p_src' 00320 * address in storage module at 'p_dest' address; Equivalent to Storage Write. 00321 * 00322 * @param[in] p_dest Destination address where data is to be stored persistently. 00323 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident 00324 * memory and no intermediate copy of data is made by the API. 00325 * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned. 00326 * @param[in] offset Offset in bytes to be applied when writing to the block. 00327 * For example, if within a block of 100 bytes, application wishes to 00328 * write 20 bytes at offset of 12, then this field should be set to 12. 00329 * Should be word aligned. 00330 * 00331 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00332 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00333 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00334 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00335 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_src' is not aligned. 00336 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00337 * 00338 * @warning No copy of the data is made, and hence memory provided for data source to be written 00339 * to flash cannot be freed or reused by the application until this procedure 00340 * is complete. End of this procedure is notified to the application using the 00341 * notification callback registered by the application. 00342 */ 00343 uint32_t pstorage_raw_store(pstorage_handle_t * p_dest, 00344 uint8_t * p_src, 00345 pstorage_size_t size, 00346 pstorage_size_t offset); 00347 00348 /**@brief Function for clearing data in persistent memory in raw mode. 00349 * 00350 * @param[in] p_dest Base block identifier in persistent memory that needs to cleared; 00351 * Equivalent to an Erase Operation. 00352 * @param[in] size Size of data to be cleared from persistent memory expressed in bytes. 00353 * This is currently unused. And a clear would mean clearing all blocks, 00354 * however, this parameter is to provision for clearing of certain blocks 00355 * of memory only and not all if need be. 00356 * 00357 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00358 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00359 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00360 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00361 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00362 * 00363 * @note Clear operations may take time. This API however, does not block until the clear 00364 * procedure is complete. Application is notified of procedure completion using 00365 * notification callback registered by the application. 'result' parameter of the 00366 * callback suggests if the procedure was successful or not. 00367 */ 00368 uint32_t pstorage_raw_clear(pstorage_handle_t * p_dest, pstorage_size_t size); 00369 00370 #endif // PSTORAGE_RAW_MODE_ENABLE 00371 00372 #ifdef __cplusplus 00373 } 00374 #endif /* #ifdef __cplusplus */ 00375 00376 00377 /**@} */ 00378 /**@} */ 00379 00380 #endif // PSTORAGE_H__ 00381
Generated on Tue Jul 12 2022 14:11:57 by
