Wallbot_CaaS
Dependencies: MPU6050 mbed PID
Fork of BLE_MPU6050_test6_challenge_sb 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 * @note To register an area with a total size (block count * block size) larger than the 00137 * page size (usually 1024 bytes), the block size must be a divisor of the page size 00138 * (page size % block size == 0). 00139 * 00140 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00141 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00142 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00143 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00144 * @retval NRF_ERROR_NO_MEM in case no more registrations can be supported. 00145 */ 00146 uint32_t pstorage_register(pstorage_module_param_t * p_module_param, 00147 pstorage_handle_t * p_block_id); 00148 00149 00150 /** 00151 * @brief Function to get block id with reference to base block identifier provided at time of 00152 * registration. 00153 * 00154 * @details Function to get block id with reference to base block identifier provided at time of 00155 * registration. 00156 * In case more than one memory blocks were requested when registering, the identifier 00157 * provided here is the base identifier for the first block and to identify subsequent 00158 * block, application shall use this routine to get block identifier providing input as 00159 * base identifier and block number. Therefore if 10 blocks of size 64 are requested and 00160 * application wishes to store memory in 6th block, it shall use 00161 * \@ref pstorage_block_identifier_get with based id and provide a block number of 5. 00162 * This way application is only expected to remember the base block identifier. 00163 * 00164 * @param[in] p_base_id Base block id received at the time of registration. 00165 * @param[in] block_num Block Number, with first block numbered zero. 00166 * @param[out] p_block_id Block identifier for the block number requested in case the API succeeds. 00167 * 00168 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00169 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00170 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00171 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00172 */ 00173 uint32_t pstorage_block_identifier_get(pstorage_handle_t * p_base_id, 00174 pstorage_size_t block_num, 00175 pstorage_handle_t * p_block_id); 00176 00177 00178 /**@brief Routine to persistently store data of length 'size' contained in 'p_src' address 00179 * in storage module at 'p_dest' address; Equivalent to Storage Write. 00180 * 00181 * @param[in] p_dest Destination address where data is to be stored persistently. 00182 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident 00183 * memory and no intermediate copy of data is made by the API. 00184 * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned. 00185 * @param[in] offset Offset in bytes to be applied when writing to the block. 00186 * For example, if within a block of 100 bytes, application wishes to 00187 * write 20 bytes at offset of 12, then this field should be set to 12. 00188 * Should be word aligned. 00189 * 00190 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00191 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00192 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00193 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00194 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_src' is not aligned. 00195 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00196 * 00197 * @warning No copy of the data is made, and hence memory provided for data source to be written 00198 * to flash cannot be freed or reused by the application until this procedure 00199 * is complete. End of this procedure is notified to the application using the 00200 * notification callback registered by the application. 00201 */ 00202 uint32_t pstorage_store(pstorage_handle_t * p_dest, 00203 uint8_t * p_src, 00204 pstorage_size_t size, 00205 pstorage_size_t offset); 00206 00207 /**@brief Routine to update persistently stored data of length 'size' contained in 'p_src' address 00208 * in storage module at 'p_dest' address. 00209 * 00210 * @param[in] p_dest Destination address where data is to be updated. 00211 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident 00212 * memory and no intermediate copy of data is made by the API. 00213 * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned. 00214 * @param[in] offset Offset in bytes to be applied when writing to the block. 00215 * For example, if within a block of 100 bytes, application wishes to 00216 * write 20 bytes at offset of 12, then this field should be set to 12. 00217 * Should be word aligned. 00218 * 00219 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00220 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00221 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00222 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00223 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_src' is not aligned. 00224 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00225 * 00226 * @warning No copy of the data is made, and hence memory provided for data source to be written 00227 * to flash cannot be freed or reused by the application until this procedure 00228 * is complete. End of this procedure is notified to the application using the 00229 * notification callback registered by the application. 00230 */ 00231 uint32_t pstorage_update(pstorage_handle_t * p_dest, 00232 uint8_t * p_src, 00233 pstorage_size_t size, 00234 pstorage_size_t offset); 00235 00236 /**@brief Routine to load persistently stored data of length 'size' from 'p_src' address 00237 * to 'p_dest' address; Equivalent to Storage Read. 00238 * 00239 * @param[in] p_dest Destination address where persistently stored data is to be loaded. 00240 * @param[in] p_src Source from where data is to be loaded from persistent memory. 00241 * @param[in] size Size of data to be loaded from persistent memory expressed in bytes. 00242 * Should be word aligned. 00243 * @param[in] offset Offset in bytes to be applied when loading from the block. 00244 * For example, if within a block of 100 bytes, application wishes to 00245 * load 20 bytes from offset of 12, then this field should be set to 12. 00246 * Should be word aligned. 00247 * 00248 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00249 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00250 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00251 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00252 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_dst' is not aligned. 00253 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00254 */ 00255 uint32_t pstorage_load(uint8_t * p_dest, 00256 pstorage_handle_t * p_src, 00257 pstorage_size_t size, 00258 pstorage_size_t offset); 00259 00260 /**@brief Routine to clear data in persistent memory. 00261 * 00262 * @param[in] p_base_id Base block identifier in persistent memory that needs to cleared; 00263 * Equivalent to an Erase Operation. 00264 * 00265 * @param[in] size Size of data to be cleared from persistent memory expressed in bytes. 00266 * This parameter is to provision for clearing of certain blocks 00267 * of memory, or all memory blocks in a registered module. If the total size 00268 * of the application module is used (blocks * block size) in combination with 00269 * the identifier for the first block in the module, all blocks in the 00270 * module will be erased. 00271 * 00272 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00273 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00274 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00275 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00276 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_dst' is not aligned. 00277 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00278 * 00279 * @note Clear operations may take time. This API however, does not block until the clear 00280 * procedure is complete. Application is notified of procedure completion using 00281 * notification callback registered by the application. 'result' parameter of the 00282 * callback suggests if the procedure was successful or not. 00283 */ 00284 uint32_t pstorage_clear(pstorage_handle_t * p_base_id, pstorage_size_t size); 00285 00286 /** 00287 * @brief API to get status of number of pending operations with the module. 00288 * 00289 * @param[out] p_count Number of storage operations pending with the module, if 0, 00290 * there are no outstanding requests. 00291 * 00292 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00293 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00294 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00295 */ 00296 uint32_t pstorage_access_status_get(uint32_t * p_count); 00297 00298 #ifdef PSTORAGE_RAW_MODE_ENABLE 00299 00300 /**@brief Function for registering with persistent storage interface. 00301 * 00302 * @param[in] p_module_param Module registration param. 00303 * @param[out] p_block_id Block identifier to identify persistent memory blocks in case 00304 * registration succeeds. Application is expected to use the block ids 00305 * for subsequent operations on requested persistent memory. 00306 * In case more than one memory blocks are requested, the identifier provided here is 00307 * the base identifier for the first block and to identify subsequent block, 00308 * application shall use \@ref pstorage_block_identifier_get with this base identifier 00309 * and block number. Therefore if 10 blocks of size 64 are requested and application 00310 * wishes to store memory in 6th block, it shall use 00311 * \@ref pstorage_block_identifier_get with based id and provide a block number of 5. 00312 * This way application is only expected to remember the base block identifier. 00313 * 00314 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00315 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00316 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00317 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00318 * @retval NRF_ERROR_NO_MEM in case no more registrations can be supported. 00319 */ 00320 uint32_t pstorage_raw_register(pstorage_module_param_t * p_module_param, 00321 pstorage_handle_t * p_block_id); 00322 00323 /**@brief Raw mode function for persistently storing data of length 'size' contained in 'p_src' 00324 * address in storage module at 'p_dest' address; Equivalent to Storage Write. 00325 * 00326 * @param[in] p_dest Destination address where data is to be stored persistently. 00327 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident 00328 * memory and no intermediate copy of data is made by the API. 00329 * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned. 00330 * @param[in] offset Offset in bytes to be applied when writing to the block. 00331 * For example, if within a block of 100 bytes, application wishes to 00332 * write 20 bytes at offset of 12, then this field should be set to 12. 00333 * Should be word aligned. 00334 * 00335 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00336 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00337 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00338 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00339 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_src' is not aligned. 00340 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00341 * 00342 * @warning No copy of the data is made, and hence memory provided for data source to be written 00343 * to flash cannot be freed or reused by the application until this procedure 00344 * is complete. End of this procedure is notified to the application using the 00345 * notification callback registered by the application. 00346 */ 00347 uint32_t pstorage_raw_store(pstorage_handle_t * p_dest, 00348 uint8_t * p_src, 00349 pstorage_size_t size, 00350 pstorage_size_t offset); 00351 00352 /**@brief Function for clearing data in persistent memory in raw mode. 00353 * 00354 * @param[in] p_dest Base block identifier in persistent memory that needs to cleared; 00355 * Equivalent to an Erase Operation. 00356 * @param[in] size Size of data to be cleared from persistent memory expressed in bytes. 00357 * This is currently unused. And a clear would mean clearing all blocks, 00358 * however, this parameter is to provision for clearing of certain blocks 00359 * of memory only and not all if need be. 00360 * 00361 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. 00362 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization. 00363 * @retval NRF_ERROR_NULL if NULL parameter has been passed. 00364 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API. 00365 * @retval NRF_ERROR_NO_MEM in case request cannot be processed. 00366 * 00367 * @note Clear operations may take time. This API however, does not block until the clear 00368 * procedure is complete. Application is notified of procedure completion using 00369 * notification callback registered by the application. 'result' parameter of the 00370 * callback suggests if the procedure was successful or not. 00371 */ 00372 uint32_t pstorage_raw_clear(pstorage_handle_t * p_dest, pstorage_size_t size); 00373 00374 #endif // PSTORAGE_RAW_MODE_ENABLE 00375 00376 #ifdef __cplusplus 00377 } 00378 #endif /* #ifdef __cplusplus */ 00379 00380 /**@} */ 00381 /**@} */ 00382 00383 #endif // PSTORAGE_H__ 00384
Generated on Tue Jul 12 2022 18:33:09 by 1.7.2