To get started with Seeed Tiny BLE, include detecting motion, button and battery level.

Dependencies:   BLE_API eMPL_MPU6050 mbed nRF51822

Committer:
yihui
Date:
Wed Apr 22 07:47:17 2015 +0000
Revision:
1:fc2f9d636751
update libraries; ; delete nRF51822/nordic-sdk/components/gpiote/app_gpiote.c to solve GPIOTE_IRQHandler multiply defined issue. temperarily change nRF51822 library to folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 1:fc2f9d636751 1 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
yihui 1:fc2f9d636751 2 *
yihui 1:fc2f9d636751 3 * The information contained herein is property of Nordic Semiconductor ASA.
yihui 1:fc2f9d636751 4 * Terms and conditions of usage are described in detail in NORDIC
yihui 1:fc2f9d636751 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
yihui 1:fc2f9d636751 6 *
yihui 1:fc2f9d636751 7 * Licensees are granted free, non-transferable use of the information. NO
yihui 1:fc2f9d636751 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
yihui 1:fc2f9d636751 9 * the file.
yihui 1:fc2f9d636751 10 *
yihui 1:fc2f9d636751 11 */
yihui 1:fc2f9d636751 12
yihui 1:fc2f9d636751 13 /**@file
yihui 1:fc2f9d636751 14 *
yihui 1:fc2f9d636751 15 * @defgroup persistent_storage Persistent Storage Interface
yihui 1:fc2f9d636751 16 * @{
yihui 1:fc2f9d636751 17 * @ingroup app_common
yihui 1:fc2f9d636751 18 * @brief Abstracted flash interface.
yihui 1:fc2f9d636751 19 *
yihui 1:fc2f9d636751 20 * @details In order to ensure that the SDK and application be moved to alternate persistent storage
yihui 1:fc2f9d636751 21 * options other than the default provided with NRF solution, an abstracted interface is provided
yihui 1:fc2f9d636751 22 * by the module to ensure SDK modules and application can be ported to alternate option with ease.
yihui 1:fc2f9d636751 23 */
yihui 1:fc2f9d636751 24
yihui 1:fc2f9d636751 25 #ifndef PSTORAGE_H__
yihui 1:fc2f9d636751 26 #define PSTORAGE_H__
yihui 1:fc2f9d636751 27
yihui 1:fc2f9d636751 28 #include "pstorage_platform.h"
yihui 1:fc2f9d636751 29
yihui 1:fc2f9d636751 30 #ifdef __cplusplus
yihui 1:fc2f9d636751 31 extern "C" {
yihui 1:fc2f9d636751 32 #endif /* #ifdef __cplusplus */
yihui 1:fc2f9d636751 33
yihui 1:fc2f9d636751 34
yihui 1:fc2f9d636751 35 /**@defgroup ps_opcode Persistent Storage Access Operation Codes
yihui 1:fc2f9d636751 36 * @{
yihui 1:fc2f9d636751 37 * @brief Persistent Storage Access Operation Codes. These are used to report any error during
yihui 1:fc2f9d636751 38 * a persistent storage access operation or any general error that may occur in the
yihui 1:fc2f9d636751 39 * interface.
yihui 1:fc2f9d636751 40 *
yihui 1:fc2f9d636751 41 * @details Persistent Storage Access Operation Codes used in error notification callback
yihui 1:fc2f9d636751 42 * registered with the interface to report any error during an persistent storage access
yihui 1:fc2f9d636751 43 * operation or any general error that may occur in the interface.
yihui 1:fc2f9d636751 44 */
yihui 1:fc2f9d636751 45 #define PSTORAGE_ERROR_OP_CODE 0x01 /**< General Error Code */
yihui 1:fc2f9d636751 46 #define PSTORAGE_STORE_OP_CODE 0x02 /**< Error when Store Operation was requested */
yihui 1:fc2f9d636751 47 #define PSTORAGE_LOAD_OP_CODE 0x03 /**< Error when Load Operation was requested */
yihui 1:fc2f9d636751 48 #define PSTORAGE_CLEAR_OP_CODE 0x04 /**< Error when Clear Operation was requested */
yihui 1:fc2f9d636751 49 #define PSTORAGE_UPDATE_OP_CODE 0x05 /**< Update an already touched storage block */
yihui 1:fc2f9d636751 50
yihui 1:fc2f9d636751 51 /**@} */
yihui 1:fc2f9d636751 52
yihui 1:fc2f9d636751 53 /**@defgroup pstorage_data_types Persistent Memory Interface Data Types
yihui 1:fc2f9d636751 54 * @{
yihui 1:fc2f9d636751 55 * @brief Data Types needed for interfacing with persistent memory.
yihui 1:fc2f9d636751 56 *
yihui 1:fc2f9d636751 57 * @details Data Types needed for interfacing with persistent memory.
yihui 1:fc2f9d636751 58 */
yihui 1:fc2f9d636751 59
yihui 1:fc2f9d636751 60 /**@brief Persistent Storage Error Reporting Callback
yihui 1:fc2f9d636751 61 *
yihui 1:fc2f9d636751 62 * @details Persistent Storage Error Reporting Callback that is used by the interface to report
yihui 1:fc2f9d636751 63 * success or failure of a flash operation. Therefore, for any operations, application
yihui 1:fc2f9d636751 64 * can know when the procedure was complete. For store operation, since no data copy
yihui 1:fc2f9d636751 65 * is made, receiving a success or failure notification, indicated by the reason
yihui 1:fc2f9d636751 66 * parameter of callback is an indication that the resident memory could now be reused
yihui 1:fc2f9d636751 67 * or freed, as the case may be.
yihui 1:fc2f9d636751 68 *
yihui 1:fc2f9d636751 69 * @param[in] handle Identifies module and block for which callback is received.
yihui 1:fc2f9d636751 70 * @param[in] op_code Identifies the operation for which the event is notified.
yihui 1:fc2f9d636751 71 * @param[in] result Identifies the result of flash access operation.
yihui 1:fc2f9d636751 72 * NRF_SUCCESS implies, operation succeeded.
yihui 1:fc2f9d636751 73 * @param[in] p_data Identifies the application data pointer. In case of store operation, this
yihui 1:fc2f9d636751 74 * points to the resident source of application memory that application can now
yihui 1:fc2f9d636751 75 * free or reuse. In case of clear, this is NULL as no application pointer is
yihui 1:fc2f9d636751 76 * needed for this operation.
yihui 1:fc2f9d636751 77 * @param[in] data_len Length data application had provided for the operation.
yihui 1:fc2f9d636751 78 *
yihui 1:fc2f9d636751 79 */
yihui 1:fc2f9d636751 80 typedef void (*pstorage_ntf_cb_t)(pstorage_handle_t * p_handle,
yihui 1:fc2f9d636751 81 uint8_t op_code,
yihui 1:fc2f9d636751 82 uint32_t result,
yihui 1:fc2f9d636751 83 uint8_t * p_data,
yihui 1:fc2f9d636751 84 uint32_t data_len);
yihui 1:fc2f9d636751 85
yihui 1:fc2f9d636751 86
yihui 1:fc2f9d636751 87 typedef struct
yihui 1:fc2f9d636751 88 {
yihui 1:fc2f9d636751 89 pstorage_ntf_cb_t cb; /**< Callback registered with the module to be notified of any error occurring in persistent memory management */
yihui 1:fc2f9d636751 90 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,
yihui 1:fc2f9d636751 91 * 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
yihui 1:fc2f9d636751 92 * how it would like to access or alter memory in persistent memory.
yihui 1:fc2f9d636751 93 * First option is preferred when single entries that need to be updated often when having no impact on the other entries.
yihui 1:fc2f9d636751 94 * While second option is preferred when entries of table are not changed on individually but have common point of loading and storing
yihui 1:fc2f9d636751 95 * data. */
yihui 1:fc2f9d636751 96 pstorage_size_t block_count; /** Number of blocks requested by the module, minimum values is 1. */
yihui 1:fc2f9d636751 97 } pstorage_module_param_t;
yihui 1:fc2f9d636751 98
yihui 1:fc2f9d636751 99 /**@} */
yihui 1:fc2f9d636751 100
yihui 1:fc2f9d636751 101 /**@defgroup pstorage_routines Persistent Storage Access Routines
yihui 1:fc2f9d636751 102 * @{
yihui 1:fc2f9d636751 103 * @brief Functions/Interface SDK modules use to persistently store data.
yihui 1:fc2f9d636751 104 *
yihui 1:fc2f9d636751 105 * @details Interface for Application & SDK module to load/store information persistently.
yihui 1:fc2f9d636751 106 * Note: that while implementation of each of the persistent storage access function
yihui 1:fc2f9d636751 107 * depends on the system and can specific to system/solution, the signature of the
yihui 1:fc2f9d636751 108 * interface routines should not be altered.
yihui 1:fc2f9d636751 109 */
yihui 1:fc2f9d636751 110
yihui 1:fc2f9d636751 111 /**@brief Module Initialization Routine.
yihui 1:fc2f9d636751 112 *
yihui 1:fc2f9d636751 113 * @details Initializes module. To be called once before any other APIs of the module are used.
yihui 1:fc2f9d636751 114 *
yihui 1:fc2f9d636751 115 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 116 */
yihui 1:fc2f9d636751 117 uint32_t pstorage_init(void);
yihui 1:fc2f9d636751 118
yihui 1:fc2f9d636751 119
yihui 1:fc2f9d636751 120 /**@brief Register with persistent storage interface.
yihui 1:fc2f9d636751 121 *
yihui 1:fc2f9d636751 122 * @param[in] p_module_param Module registration param.
yihui 1:fc2f9d636751 123 * @param[out] p_block_id Block identifier to identify persistent memory blocks in case
yihui 1:fc2f9d636751 124 * registration succeeds. Application is expected to use the block ids
yihui 1:fc2f9d636751 125 * for subsequent operations on requested persistent memory. Maximum
yihui 1:fc2f9d636751 126 * registrations permitted is determined by configuration parameter
yihui 1:fc2f9d636751 127 * PSTORAGE_MAX_APPLICATIONS.
yihui 1:fc2f9d636751 128 * In case more than one memory blocks are requested, the identifier provided here is
yihui 1:fc2f9d636751 129 * the base identifier for the first block and to identify subsequent block,
yihui 1:fc2f9d636751 130 * application shall use \@ref pstorage_block_identifier_get with this base identifier
yihui 1:fc2f9d636751 131 * and block number. Therefore if 10 blocks of size 64 are requested and application
yihui 1:fc2f9d636751 132 * wishes to store memory in 6th block, it shall use
yihui 1:fc2f9d636751 133 * \@ref pstorage_block_identifier_get with based id and provide a block number of 5.
yihui 1:fc2f9d636751 134 * This way application is only expected to remember the base block identifier.
yihui 1:fc2f9d636751 135 *
yihui 1:fc2f9d636751 136 * @note To register an area with a total size (block count * block size) larger than the
yihui 1:fc2f9d636751 137 * page size (usually 1024 bytes), the block size must be a divisor of the page size
yihui 1:fc2f9d636751 138 * (page size % block size == 0).
yihui 1:fc2f9d636751 139 *
yihui 1:fc2f9d636751 140 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 141 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 142 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 143 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
yihui 1:fc2f9d636751 144 * @retval NRF_ERROR_NO_MEM in case no more registrations can be supported.
yihui 1:fc2f9d636751 145 */
yihui 1:fc2f9d636751 146 uint32_t pstorage_register(pstorage_module_param_t * p_module_param,
yihui 1:fc2f9d636751 147 pstorage_handle_t * p_block_id);
yihui 1:fc2f9d636751 148
yihui 1:fc2f9d636751 149
yihui 1:fc2f9d636751 150 /**
yihui 1:fc2f9d636751 151 * @brief Function to get block id with reference to base block identifier provided at time of
yihui 1:fc2f9d636751 152 * registration.
yihui 1:fc2f9d636751 153 *
yihui 1:fc2f9d636751 154 * @details Function to get block id with reference to base block identifier provided at time of
yihui 1:fc2f9d636751 155 * registration.
yihui 1:fc2f9d636751 156 * In case more than one memory blocks were requested when registering, the identifier
yihui 1:fc2f9d636751 157 * provided here is the base identifier for the first block and to identify subsequent
yihui 1:fc2f9d636751 158 * block, application shall use this routine to get block identifier providing input as
yihui 1:fc2f9d636751 159 * base identifier and block number. Therefore if 10 blocks of size 64 are requested and
yihui 1:fc2f9d636751 160 * application wishes to store memory in 6th block, it shall use
yihui 1:fc2f9d636751 161 * \@ref pstorage_block_identifier_get with based id and provide a block number of 5.
yihui 1:fc2f9d636751 162 * This way application is only expected to remember the base block identifier.
yihui 1:fc2f9d636751 163 *
yihui 1:fc2f9d636751 164 * @param[in] p_base_id Base block id received at the time of registration.
yihui 1:fc2f9d636751 165 * @param[in] block_num Block Number, with first block numbered zero.
yihui 1:fc2f9d636751 166 * @param[out] p_block_id Block identifier for the block number requested in case the API succeeds.
yihui 1:fc2f9d636751 167 *
yihui 1:fc2f9d636751 168 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 169 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 170 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 171 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
yihui 1:fc2f9d636751 172 */
yihui 1:fc2f9d636751 173 uint32_t pstorage_block_identifier_get(pstorage_handle_t * p_base_id,
yihui 1:fc2f9d636751 174 pstorage_size_t block_num,
yihui 1:fc2f9d636751 175 pstorage_handle_t * p_block_id);
yihui 1:fc2f9d636751 176
yihui 1:fc2f9d636751 177
yihui 1:fc2f9d636751 178 /**@brief Routine to persistently store data of length 'size' contained in 'p_src' address
yihui 1:fc2f9d636751 179 * in storage module at 'p_dest' address; Equivalent to Storage Write.
yihui 1:fc2f9d636751 180 *
yihui 1:fc2f9d636751 181 * @param[in] p_dest Destination address where data is to be stored persistently.
yihui 1:fc2f9d636751 182 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident
yihui 1:fc2f9d636751 183 * memory and no intermediate copy of data is made by the API.
yihui 1:fc2f9d636751 184 * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned.
yihui 1:fc2f9d636751 185 * @param[in] offset Offset in bytes to be applied when writing to the block.
yihui 1:fc2f9d636751 186 * For example, if within a block of 100 bytes, application wishes to
yihui 1:fc2f9d636751 187 * write 20 bytes at offset of 12, then this field should be set to 12.
yihui 1:fc2f9d636751 188 * Should be word aligned.
yihui 1:fc2f9d636751 189 *
yihui 1:fc2f9d636751 190 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 191 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 192 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 193 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
yihui 1:fc2f9d636751 194 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_src' is not aligned.
yihui 1:fc2f9d636751 195 * @retval NRF_ERROR_NO_MEM in case request cannot be processed.
yihui 1:fc2f9d636751 196 *
yihui 1:fc2f9d636751 197 * @warning No copy of the data is made, and hence memory provided for data source to be written
yihui 1:fc2f9d636751 198 * to flash cannot be freed or reused by the application until this procedure
yihui 1:fc2f9d636751 199 * is complete. End of this procedure is notified to the application using the
yihui 1:fc2f9d636751 200 * notification callback registered by the application.
yihui 1:fc2f9d636751 201 */
yihui 1:fc2f9d636751 202 uint32_t pstorage_store(pstorage_handle_t * p_dest,
yihui 1:fc2f9d636751 203 uint8_t * p_src,
yihui 1:fc2f9d636751 204 pstorage_size_t size,
yihui 1:fc2f9d636751 205 pstorage_size_t offset);
yihui 1:fc2f9d636751 206
yihui 1:fc2f9d636751 207 /**@brief Routine to update persistently stored data of length 'size' contained in 'p_src' address
yihui 1:fc2f9d636751 208 * in storage module at 'p_dest' address.
yihui 1:fc2f9d636751 209 *
yihui 1:fc2f9d636751 210 * @param[in] p_dest Destination address where data is to be updated.
yihui 1:fc2f9d636751 211 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident
yihui 1:fc2f9d636751 212 * memory and no intermediate copy of data is made by the API.
yihui 1:fc2f9d636751 213 * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned.
yihui 1:fc2f9d636751 214 * @param[in] offset Offset in bytes to be applied when writing to the block.
yihui 1:fc2f9d636751 215 * For example, if within a block of 100 bytes, application wishes to
yihui 1:fc2f9d636751 216 * write 20 bytes at offset of 12, then this field should be set to 12.
yihui 1:fc2f9d636751 217 * Should be word aligned.
yihui 1:fc2f9d636751 218 *
yihui 1:fc2f9d636751 219 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 220 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 221 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 222 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
yihui 1:fc2f9d636751 223 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_src' is not aligned.
yihui 1:fc2f9d636751 224 * @retval NRF_ERROR_NO_MEM in case request cannot be processed.
yihui 1:fc2f9d636751 225 *
yihui 1:fc2f9d636751 226 * @warning No copy of the data is made, and hence memory provided for data source to be written
yihui 1:fc2f9d636751 227 * to flash cannot be freed or reused by the application until this procedure
yihui 1:fc2f9d636751 228 * is complete. End of this procedure is notified to the application using the
yihui 1:fc2f9d636751 229 * notification callback registered by the application.
yihui 1:fc2f9d636751 230 */
yihui 1:fc2f9d636751 231 uint32_t pstorage_update(pstorage_handle_t * p_dest,
yihui 1:fc2f9d636751 232 uint8_t * p_src,
yihui 1:fc2f9d636751 233 pstorage_size_t size,
yihui 1:fc2f9d636751 234 pstorage_size_t offset);
yihui 1:fc2f9d636751 235
yihui 1:fc2f9d636751 236 /**@brief Routine to load persistently stored data of length 'size' from 'p_src' address
yihui 1:fc2f9d636751 237 * to 'p_dest' address; Equivalent to Storage Read.
yihui 1:fc2f9d636751 238 *
yihui 1:fc2f9d636751 239 * @param[in] p_dest Destination address where persistently stored data is to be loaded.
yihui 1:fc2f9d636751 240 * @param[in] p_src Source from where data is to be loaded from persistent memory.
yihui 1:fc2f9d636751 241 * @param[in] size Size of data to be loaded from persistent memory expressed in bytes.
yihui 1:fc2f9d636751 242 * Should be word aligned.
yihui 1:fc2f9d636751 243 * @param[in] offset Offset in bytes to be applied when loading from the block.
yihui 1:fc2f9d636751 244 * For example, if within a block of 100 bytes, application wishes to
yihui 1:fc2f9d636751 245 * load 20 bytes from offset of 12, then this field should be set to 12.
yihui 1:fc2f9d636751 246 * Should be word aligned.
yihui 1:fc2f9d636751 247 *
yihui 1:fc2f9d636751 248 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 249 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 250 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 251 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
yihui 1:fc2f9d636751 252 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_dst' is not aligned.
yihui 1:fc2f9d636751 253 * @retval NRF_ERROR_NO_MEM in case request cannot be processed.
yihui 1:fc2f9d636751 254 */
yihui 1:fc2f9d636751 255 uint32_t pstorage_load(uint8_t * p_dest,
yihui 1:fc2f9d636751 256 pstorage_handle_t * p_src,
yihui 1:fc2f9d636751 257 pstorage_size_t size,
yihui 1:fc2f9d636751 258 pstorage_size_t offset);
yihui 1:fc2f9d636751 259
yihui 1:fc2f9d636751 260 /**@brief Routine to clear data in persistent memory.
yihui 1:fc2f9d636751 261 *
yihui 1:fc2f9d636751 262 * @param[in] p_base_id Base block identifier in persistent memory that needs to cleared;
yihui 1:fc2f9d636751 263 * Equivalent to an Erase Operation.
yihui 1:fc2f9d636751 264 *
yihui 1:fc2f9d636751 265 * @param[in] size Size of data to be cleared from persistent memory expressed in bytes.
yihui 1:fc2f9d636751 266 * This parameter is to provision for clearing of certain blocks
yihui 1:fc2f9d636751 267 * of memory, or all memory blocks in a registered module. If the total size
yihui 1:fc2f9d636751 268 * of the application module is used (blocks * block size) in combination with
yihui 1:fc2f9d636751 269 * the identifier for the first block in the module, all blocks in the
yihui 1:fc2f9d636751 270 * module will be erased.
yihui 1:fc2f9d636751 271 *
yihui 1:fc2f9d636751 272 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 273 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 274 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 275 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
yihui 1:fc2f9d636751 276 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_dst' is not aligned.
yihui 1:fc2f9d636751 277 * @retval NRF_ERROR_NO_MEM in case request cannot be processed.
yihui 1:fc2f9d636751 278 *
yihui 1:fc2f9d636751 279 * @note Clear operations may take time. This API however, does not block until the clear
yihui 1:fc2f9d636751 280 * procedure is complete. Application is notified of procedure completion using
yihui 1:fc2f9d636751 281 * notification callback registered by the application. 'result' parameter of the
yihui 1:fc2f9d636751 282 * callback suggests if the procedure was successful or not.
yihui 1:fc2f9d636751 283 */
yihui 1:fc2f9d636751 284 uint32_t pstorage_clear(pstorage_handle_t * p_base_id, pstorage_size_t size);
yihui 1:fc2f9d636751 285
yihui 1:fc2f9d636751 286 /**
yihui 1:fc2f9d636751 287 * @brief API to get status of number of pending operations with the module.
yihui 1:fc2f9d636751 288 *
yihui 1:fc2f9d636751 289 * @param[out] p_count Number of storage operations pending with the module, if 0,
yihui 1:fc2f9d636751 290 * there are no outstanding requests.
yihui 1:fc2f9d636751 291 *
yihui 1:fc2f9d636751 292 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 293 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 294 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 295 */
yihui 1:fc2f9d636751 296 uint32_t pstorage_access_status_get(uint32_t * p_count);
yihui 1:fc2f9d636751 297
yihui 1:fc2f9d636751 298 #ifdef PSTORAGE_RAW_MODE_ENABLE
yihui 1:fc2f9d636751 299
yihui 1:fc2f9d636751 300 /**@brief Function for registering with persistent storage interface.
yihui 1:fc2f9d636751 301 *
yihui 1:fc2f9d636751 302 * @param[in] p_module_param Module registration param.
yihui 1:fc2f9d636751 303 * @param[out] p_block_id Block identifier to identify persistent memory blocks in case
yihui 1:fc2f9d636751 304 * registration succeeds. Application is expected to use the block ids
yihui 1:fc2f9d636751 305 * for subsequent operations on requested persistent memory.
yihui 1:fc2f9d636751 306 * In case more than one memory blocks are requested, the identifier provided here is
yihui 1:fc2f9d636751 307 * the base identifier for the first block and to identify subsequent block,
yihui 1:fc2f9d636751 308 * application shall use \@ref pstorage_block_identifier_get with this base identifier
yihui 1:fc2f9d636751 309 * and block number. Therefore if 10 blocks of size 64 are requested and application
yihui 1:fc2f9d636751 310 * wishes to store memory in 6th block, it shall use
yihui 1:fc2f9d636751 311 * \@ref pstorage_block_identifier_get with based id and provide a block number of 5.
yihui 1:fc2f9d636751 312 * This way application is only expected to remember the base block identifier.
yihui 1:fc2f9d636751 313 *
yihui 1:fc2f9d636751 314 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 315 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 316 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 317 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
yihui 1:fc2f9d636751 318 * @retval NRF_ERROR_NO_MEM in case no more registrations can be supported.
yihui 1:fc2f9d636751 319 */
yihui 1:fc2f9d636751 320 uint32_t pstorage_raw_register(pstorage_module_param_t * p_module_param,
yihui 1:fc2f9d636751 321 pstorage_handle_t * p_block_id);
yihui 1:fc2f9d636751 322
yihui 1:fc2f9d636751 323 /**@brief Raw mode function for persistently storing data of length 'size' contained in 'p_src'
yihui 1:fc2f9d636751 324 * address in storage module at 'p_dest' address; Equivalent to Storage Write.
yihui 1:fc2f9d636751 325 *
yihui 1:fc2f9d636751 326 * @param[in] p_dest Destination address where data is to be stored persistently.
yihui 1:fc2f9d636751 327 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident
yihui 1:fc2f9d636751 328 * memory and no intermediate copy of data is made by the API.
yihui 1:fc2f9d636751 329 * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned.
yihui 1:fc2f9d636751 330 * @param[in] offset Offset in bytes to be applied when writing to the block.
yihui 1:fc2f9d636751 331 * For example, if within a block of 100 bytes, application wishes to
yihui 1:fc2f9d636751 332 * write 20 bytes at offset of 12, then this field should be set to 12.
yihui 1:fc2f9d636751 333 * Should be word aligned.
yihui 1:fc2f9d636751 334 *
yihui 1:fc2f9d636751 335 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 336 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 337 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 338 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
yihui 1:fc2f9d636751 339 * @retval NRF_ERROR_INVALID_ADDR in case data address 'p_src' is not aligned.
yihui 1:fc2f9d636751 340 * @retval NRF_ERROR_NO_MEM in case request cannot be processed.
yihui 1:fc2f9d636751 341 *
yihui 1:fc2f9d636751 342 * @warning No copy of the data is made, and hence memory provided for data source to be written
yihui 1:fc2f9d636751 343 * to flash cannot be freed or reused by the application until this procedure
yihui 1:fc2f9d636751 344 * is complete. End of this procedure is notified to the application using the
yihui 1:fc2f9d636751 345 * notification callback registered by the application.
yihui 1:fc2f9d636751 346 */
yihui 1:fc2f9d636751 347 uint32_t pstorage_raw_store(pstorage_handle_t * p_dest,
yihui 1:fc2f9d636751 348 uint8_t * p_src,
yihui 1:fc2f9d636751 349 pstorage_size_t size,
yihui 1:fc2f9d636751 350 pstorage_size_t offset);
yihui 1:fc2f9d636751 351
yihui 1:fc2f9d636751 352 /**@brief Function for clearing data in persistent memory in raw mode.
yihui 1:fc2f9d636751 353 *
yihui 1:fc2f9d636751 354 * @param[in] p_dest Base block identifier in persistent memory that needs to cleared;
yihui 1:fc2f9d636751 355 * Equivalent to an Erase Operation.
yihui 1:fc2f9d636751 356 * @param[in] size Size of data to be cleared from persistent memory expressed in bytes.
yihui 1:fc2f9d636751 357 * This is currently unused. And a clear would mean clearing all blocks,
yihui 1:fc2f9d636751 358 * however, this parameter is to provision for clearing of certain blocks
yihui 1:fc2f9d636751 359 * of memory only and not all if need be.
yihui 1:fc2f9d636751 360 *
yihui 1:fc2f9d636751 361 * @retval NRF_SUCCESS on success, else an error code indicating reason for failure.
yihui 1:fc2f9d636751 362 * @retval NRF_ERROR_INVALID_STATE is returned is API is called without module initialization.
yihui 1:fc2f9d636751 363 * @retval NRF_ERROR_NULL if NULL parameter has been passed.
yihui 1:fc2f9d636751 364 * @retval NRF_ERROR_INVALID_PARAM if invalid parameters are passed to the API.
yihui 1:fc2f9d636751 365 * @retval NRF_ERROR_NO_MEM in case request cannot be processed.
yihui 1:fc2f9d636751 366 *
yihui 1:fc2f9d636751 367 * @note Clear operations may take time. This API however, does not block until the clear
yihui 1:fc2f9d636751 368 * procedure is complete. Application is notified of procedure completion using
yihui 1:fc2f9d636751 369 * notification callback registered by the application. 'result' parameter of the
yihui 1:fc2f9d636751 370 * callback suggests if the procedure was successful or not.
yihui 1:fc2f9d636751 371 */
yihui 1:fc2f9d636751 372 uint32_t pstorage_raw_clear(pstorage_handle_t * p_dest, pstorage_size_t size);
yihui 1:fc2f9d636751 373
yihui 1:fc2f9d636751 374 #endif // PSTORAGE_RAW_MODE_ENABLE
yihui 1:fc2f9d636751 375
yihui 1:fc2f9d636751 376 /**@} */
yihui 1:fc2f9d636751 377 /**@} */
yihui 1:fc2f9d636751 378
yihui 1:fc2f9d636751 379 #ifdef __cplusplus
yihui 1:fc2f9d636751 380 }
yihui 1:fc2f9d636751 381 #endif /* #ifdef __cplusplus */
yihui 1:fc2f9d636751 382
yihui 1:fc2f9d636751 383 #endif // PSTORAGE_H__
yihui 1:fc2f9d636751 384