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