Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sun May 14 23:18:57 2017 +0000
Revision:
18:6a4db94011d3
Publishing again

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /*
sahilmgandhi 18:6a4db94011d3 2 * Copyright (c) 2013 Nordic Semiconductor ASA
sahilmgandhi 18:6a4db94011d3 3 * All rights reserved.
sahilmgandhi 18:6a4db94011d3 4 *
sahilmgandhi 18:6a4db94011d3 5 * Redistribution and use in source and binary forms, with or without modification,
sahilmgandhi 18:6a4db94011d3 6 * are permitted provided that the following conditions are met:
sahilmgandhi 18:6a4db94011d3 7 *
sahilmgandhi 18:6a4db94011d3 8 * 1. Redistributions of source code must retain the above copyright notice, this list
sahilmgandhi 18:6a4db94011d3 9 * of conditions and the following disclaimer.
sahilmgandhi 18:6a4db94011d3 10 *
sahilmgandhi 18:6a4db94011d3 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
sahilmgandhi 18:6a4db94011d3 12 * integrated circuit in a product or a software update for such product, must reproduce
sahilmgandhi 18:6a4db94011d3 13 * the above copyright notice, this list of conditions and the following disclaimer in
sahilmgandhi 18:6a4db94011d3 14 * the documentation and/or other materials provided with the distribution.
sahilmgandhi 18:6a4db94011d3 15 *
sahilmgandhi 18:6a4db94011d3 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
sahilmgandhi 18:6a4db94011d3 17 * used to endorse or promote products derived from this software without specific prior
sahilmgandhi 18:6a4db94011d3 18 * written permission.
sahilmgandhi 18:6a4db94011d3 19 *
sahilmgandhi 18:6a4db94011d3 20 * 4. This software, with or without modification, must only be used with a
sahilmgandhi 18:6a4db94011d3 21 * Nordic Semiconductor ASA integrated circuit.
sahilmgandhi 18:6a4db94011d3 22 *
sahilmgandhi 18:6a4db94011d3 23 * 5. Any software provided in binary or object form under this license must not be reverse
sahilmgandhi 18:6a4db94011d3 24 * engineered, decompiled, modified and/or disassembled.
sahilmgandhi 18:6a4db94011d3 25 *
sahilmgandhi 18:6a4db94011d3 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
sahilmgandhi 18:6a4db94011d3 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
sahilmgandhi 18:6a4db94011d3 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
sahilmgandhi 18:6a4db94011d3 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
sahilmgandhi 18:6a4db94011d3 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
sahilmgandhi 18:6a4db94011d3 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
sahilmgandhi 18:6a4db94011d3 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
sahilmgandhi 18:6a4db94011d3 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
sahilmgandhi 18:6a4db94011d3 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
sahilmgandhi 18:6a4db94011d3 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sahilmgandhi 18:6a4db94011d3 36 *
sahilmgandhi 18:6a4db94011d3 37 */
sahilmgandhi 18:6a4db94011d3 38
sahilmgandhi 18:6a4db94011d3 39
sahilmgandhi 18:6a4db94011d3 40 /**@file
sahilmgandhi 18:6a4db94011d3 41 *
sahilmgandhi 18:6a4db94011d3 42 * @defgroup persistent_storage Persistent Storage Interface
sahilmgandhi 18:6a4db94011d3 43 * @{
sahilmgandhi 18:6a4db94011d3 44 * @ingroup app_common
sahilmgandhi 18:6a4db94011d3 45 * @brief Abstracted flash interface.
sahilmgandhi 18:6a4db94011d3 46 *
sahilmgandhi 18:6a4db94011d3 47 * @details An abstracted interface is provided by the module to easily port the application and
sahilmgandhi 18:6a4db94011d3 48 * SDK modules to an alternate option. This ensures that the SDK and application are moved
sahilmgandhi 18:6a4db94011d3 49 * to alternate persistent storage instead of the one provided by default.
sahilmgandhi 18:6a4db94011d3 50 */
sahilmgandhi 18:6a4db94011d3 51
sahilmgandhi 18:6a4db94011d3 52 #ifndef PSTORAGE_H__
sahilmgandhi 18:6a4db94011d3 53 #define PSTORAGE_H__
sahilmgandhi 18:6a4db94011d3 54
sahilmgandhi 18:6a4db94011d3 55 #include "pstorage_platform.h"
sahilmgandhi 18:6a4db94011d3 56
sahilmgandhi 18:6a4db94011d3 57
sahilmgandhi 18:6a4db94011d3 58 /**@defgroup ps_opcode Persistent Storage Access Operation Codes
sahilmgandhi 18:6a4db94011d3 59 * @{
sahilmgandhi 18:6a4db94011d3 60 * @brief Persistent Storage Access Operation Codes.
sahilmgandhi 18:6a4db94011d3 61 *
sahilmgandhi 18:6a4db94011d3 62 * @details Persistent Storage Access Operation Codes are used by Persistent storage operation
sahilmgandhi 18:6a4db94011d3 63 * completion callback @ref pstorage_ntf_cb_t to identify the operation type requested by
sahilmgandhi 18:6a4db94011d3 64 * the application.
sahilmgandhi 18:6a4db94011d3 65 */
sahilmgandhi 18:6a4db94011d3 66 #define PSTORAGE_STORE_OP_CODE 0x01 /**< Store Operation type. */
sahilmgandhi 18:6a4db94011d3 67 #define PSTORAGE_LOAD_OP_CODE 0x02 /**< Load Operation type. */
sahilmgandhi 18:6a4db94011d3 68 #define PSTORAGE_CLEAR_OP_CODE 0x03 /**< Clear Operation type. */
sahilmgandhi 18:6a4db94011d3 69 #define PSTORAGE_UPDATE_OP_CODE 0x04 /**< Update Operation type. */
sahilmgandhi 18:6a4db94011d3 70
sahilmgandhi 18:6a4db94011d3 71 /**@} */
sahilmgandhi 18:6a4db94011d3 72
sahilmgandhi 18:6a4db94011d3 73 /**@defgroup pstorage_data_types Persistent Memory Interface Data Types
sahilmgandhi 18:6a4db94011d3 74 * @{
sahilmgandhi 18:6a4db94011d3 75 * @brief Data Types needed for interfacing with persistent memory.
sahilmgandhi 18:6a4db94011d3 76 *
sahilmgandhi 18:6a4db94011d3 77 * @details Data Types needed for interfacing with persistent memory.
sahilmgandhi 18:6a4db94011d3 78 */
sahilmgandhi 18:6a4db94011d3 79
sahilmgandhi 18:6a4db94011d3 80 /**@brief Persistent storage operation completion callback function type.
sahilmgandhi 18:6a4db94011d3 81 *
sahilmgandhi 18:6a4db94011d3 82 * @details The persistent storage operation completion callback is used by the interface to report
sahilmgandhi 18:6a4db94011d3 83 * success or failure of a flash operation. Since data is not copied for a store operation,
sahilmgandhi 18:6a4db94011d3 84 * a callback is an indication that the resident memory can now be reused or freed.
sahilmgandhi 18:6a4db94011d3 85 *
sahilmgandhi 18:6a4db94011d3 86 * @param[in] handle Identifies the module and block for the callback that is received.
sahilmgandhi 18:6a4db94011d3 87 * @param[in] op_code Identifies the operation for the event that is notified.
sahilmgandhi 18:6a4db94011d3 88 * @param[in] result Identifies the result of a flash access operation. NRF_SUCCESS implies
sahilmgandhi 18:6a4db94011d3 89 * operation succeeded.
sahilmgandhi 18:6a4db94011d3 90 *
sahilmgandhi 18:6a4db94011d3 91 * @note Unmanaged (abnormal behaviour) error codes from the SoftDevice flash
sahilmgandhi 18:6a4db94011d3 92 * access API are forwarded as is and are expected to be handled by the
sahilmgandhi 18:6a4db94011d3 93 * application. For details refer to the implementation file and corresponding
sahilmgandhi 18:6a4db94011d3 94 * SoftDevice flash API documentation.
sahilmgandhi 18:6a4db94011d3 95 *
sahilmgandhi 18:6a4db94011d3 96 * @param[in] p_data Identifies the application data pointer. For a store operation, this points
sahilmgandhi 18:6a4db94011d3 97 * to the resident source of application memory that the application can now
sahilmgandhi 18:6a4db94011d3 98 * free or reuse. When there is a clear operation, this is NULL since no
sahilmgandhi 18:6a4db94011d3 99 * application pointer is needed for this operation.
sahilmgandhi 18:6a4db94011d3 100 * @param[in] data_len Length data the application provided for the operation.
sahilmgandhi 18:6a4db94011d3 101 */
sahilmgandhi 18:6a4db94011d3 102 typedef void (*pstorage_ntf_cb_t)(pstorage_handle_t * p_handle,
sahilmgandhi 18:6a4db94011d3 103 uint8_t op_code,
sahilmgandhi 18:6a4db94011d3 104 uint32_t result,
sahilmgandhi 18:6a4db94011d3 105 uint8_t * p_data,
sahilmgandhi 18:6a4db94011d3 106 uint32_t data_len);
sahilmgandhi 18:6a4db94011d3 107
sahilmgandhi 18:6a4db94011d3 108 /**@brief Struct containing module registration context. */
sahilmgandhi 18:6a4db94011d3 109 typedef struct
sahilmgandhi 18:6a4db94011d3 110 {
sahilmgandhi 18:6a4db94011d3 111 pstorage_ntf_cb_t cb; /**< Persistent storage operation completion callback function @ref pstorage_ntf_cb_t. */
sahilmgandhi 18:6a4db94011d3 112 pstorage_size_t block_size; /**< Desired block size for persistent memory storage. For example, if a module has a table with 10 entries, and each entry is 64 bytes in size,
sahilmgandhi 18:6a4db94011d3 113 * it can request 10 blocks with a block size of 64 bytes. The module can also request one block that is 640 bytes depending
sahilmgandhi 18:6a4db94011d3 114 * on how it would like to access or alter the memory in persistent memory.
sahilmgandhi 18:6a4db94011d3 115 * The first option is preferred when it is a single entry that needs to be updated often and doesn't impact the other entries.
sahilmgandhi 18:6a4db94011d3 116 * The second option is preferred when table entries are not changed individually but have a common point of loading and storing
sahilmgandhi 18:6a4db94011d3 117 * data. */
sahilmgandhi 18:6a4db94011d3 118 pstorage_size_t block_count; /** Number of blocks requested by the module; minimum values is 1. */
sahilmgandhi 18:6a4db94011d3 119 } pstorage_module_param_t;
sahilmgandhi 18:6a4db94011d3 120
sahilmgandhi 18:6a4db94011d3 121 /**@} */
sahilmgandhi 18:6a4db94011d3 122
sahilmgandhi 18:6a4db94011d3 123 /**@defgroup pstorage_routines Persistent Storage Access Routines
sahilmgandhi 18:6a4db94011d3 124 * @{
sahilmgandhi 18:6a4db94011d3 125 * @brief Functions/Interface SDK modules used to persistently store data.
sahilmgandhi 18:6a4db94011d3 126 *
sahilmgandhi 18:6a4db94011d3 127 * @details Interface for the Application and SDK modules to load/store information persistently.
sahilmgandhi 18:6a4db94011d3 128 * Note: While implementation of each of the persistent storage access functions
sahilmgandhi 18:6a4db94011d3 129 * depends on the system and is specific to system/solution, the signature of the
sahilmgandhi 18:6a4db94011d3 130 * interface routines should not be altered.
sahilmgandhi 18:6a4db94011d3 131 */
sahilmgandhi 18:6a4db94011d3 132
sahilmgandhi 18:6a4db94011d3 133 /**@brief Function for initializing the module.
sahilmgandhi 18:6a4db94011d3 134 *
sahilmgandhi 18:6a4db94011d3 135 * @details Function for initializing the module. This function is called once before any other APIs
sahilmgandhi 18:6a4db94011d3 136 * of the module are used.
sahilmgandhi 18:6a4db94011d3 137 *
sahilmgandhi 18:6a4db94011d3 138 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 139 */
sahilmgandhi 18:6a4db94011d3 140 uint32_t pstorage_init(void);
sahilmgandhi 18:6a4db94011d3 141
sahilmgandhi 18:6a4db94011d3 142 /**@brief Function for registering with persistent storage interface.
sahilmgandhi 18:6a4db94011d3 143 *
sahilmgandhi 18:6a4db94011d3 144 * @param[in] p_module_param Module registration parameter.
sahilmgandhi 18:6a4db94011d3 145 * @param[out] p_block_id Block identifier to identify persistent memory blocks when
sahilmgandhi 18:6a4db94011d3 146 * registration succeeds. Application is expected to use the block IDs
sahilmgandhi 18:6a4db94011d3 147 * for subsequent operations on requested persistent memory. Maximum
sahilmgandhi 18:6a4db94011d3 148 * registrations permitted is determined by the configuration of the
sahilmgandhi 18:6a4db94011d3 149 * parameter PSTORAGE_NUM_OF_PAGES. If more than one memory block is
sahilmgandhi 18:6a4db94011d3 150 * requested, the identifier provided here is the base identifier for the
sahilmgandhi 18:6a4db94011d3 151 * first block and used to identify the subsequent block. The application
sahilmgandhi 18:6a4db94011d3 152 * uses \@ref pstorage_block_identifier_get with this base identifier and
sahilmgandhi 18:6a4db94011d3 153 * block number. Therefore if 10 blocks of size 64 are requested and the
sahilmgandhi 18:6a4db94011d3 154 * application wishes to store memory in the 6th block, it shall use
sahilmgandhi 18:6a4db94011d3 155 * \@ref pstorage_block_identifier_get with the base ID and provide a
sahilmgandhi 18:6a4db94011d3 156 * block number of 5. This way the application is only expected to
sahilmgandhi 18:6a4db94011d3 157 * remember the base block identifier.
sahilmgandhi 18:6a4db94011d3 158 *
sahilmgandhi 18:6a4db94011d3 159 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 160 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 161 * initialization.
sahilmgandhi 18:6a4db94011d3 162 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 163 * @retval NRF_ERROR_INVALID_PARAM Operation failure. Invalid parameter has been passed.
sahilmgandhi 18:6a4db94011d3 164 * @retval NRF_ERROR_NO_MEM Operation failure. Additional registrations can't be
sahilmgandhi 18:6a4db94011d3 165 * supported.
sahilmgandhi 18:6a4db94011d3 166 */
sahilmgandhi 18:6a4db94011d3 167 uint32_t pstorage_register(pstorage_module_param_t * p_module_param,
sahilmgandhi 18:6a4db94011d3 168 pstorage_handle_t * p_block_id);
sahilmgandhi 18:6a4db94011d3 169
sahilmgandhi 18:6a4db94011d3 170 /**@brief Function for getting block ID with reference to base block identifier provided at the time
sahilmgandhi 18:6a4db94011d3 171 * of registration.
sahilmgandhi 18:6a4db94011d3 172 *
sahilmgandhi 18:6a4db94011d3 173 * @details Function to get the block ID with reference to base block identifier provided at the
sahilmgandhi 18:6a4db94011d3 174 * time of registration.
sahilmgandhi 18:6a4db94011d3 175 * If more than one memory block was requested when registering, the identifier provided
sahilmgandhi 18:6a4db94011d3 176 * here is the base identifier for the first block which is used to identify subsequent
sahilmgandhi 18:6a4db94011d3 177 * blocks. The application shall use this routine to get the block identifier, providing
sahilmgandhi 18:6a4db94011d3 178 * input as base identifier and block number. Therefore, if 10 blocks of size 64 are
sahilmgandhi 18:6a4db94011d3 179 * requested and the application wishes to store memory in the 6th block, it shall use
sahilmgandhi 18:6a4db94011d3 180 * \@ref pstorage_block_identifier_get with the base ID and provide a block number of 5.
sahilmgandhi 18:6a4db94011d3 181 * This way the application is only expected to remember the base block identifier.
sahilmgandhi 18:6a4db94011d3 182 *
sahilmgandhi 18:6a4db94011d3 183 * @param[in] p_base_id Base block ID received at the time of registration.
sahilmgandhi 18:6a4db94011d3 184 * @param[in] block_num Block Number, with first block numbered zero.
sahilmgandhi 18:6a4db94011d3 185 * @param[out] p_block_id Block identifier for the block number requested when the API succeeds.
sahilmgandhi 18:6a4db94011d3 186 *
sahilmgandhi 18:6a4db94011d3 187 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 188 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 189 * initialization.
sahilmgandhi 18:6a4db94011d3 190 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 191 * @retval NRF_ERROR_INVALID_PARAM Operation failure. Invalid parameter has been passed.
sahilmgandhi 18:6a4db94011d3 192 */
sahilmgandhi 18:6a4db94011d3 193 uint32_t pstorage_block_identifier_get(pstorage_handle_t * p_base_id,
sahilmgandhi 18:6a4db94011d3 194 pstorage_size_t block_num,
sahilmgandhi 18:6a4db94011d3 195 pstorage_handle_t * p_block_id);
sahilmgandhi 18:6a4db94011d3 196
sahilmgandhi 18:6a4db94011d3 197 /**@brief Function for persistently storing data of length 'size' contained in the 'p_src' address
sahilmgandhi 18:6a4db94011d3 198 * in the storage module at 'p_dest' address. Equivalent to Storage Write.
sahilmgandhi 18:6a4db94011d3 199 *
sahilmgandhi 18:6a4db94011d3 200 * @param[in] p_dest Destination address where data is to be stored persistently.
sahilmgandhi 18:6a4db94011d3 201 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident
sahilmgandhi 18:6a4db94011d3 202 * memory and no intermediate copy of data is made by the API. Must be word
sahilmgandhi 18:6a4db94011d3 203 * aligned.
sahilmgandhi 18:6a4db94011d3 204 * @param[in] size Size of data to be stored expressed in bytes. Must be word aligned and size +
sahilmgandhi 18:6a4db94011d3 205 * offset must be <= block size.
sahilmgandhi 18:6a4db94011d3 206 * @param[in] offset Offset in bytes to be applied when writing to the block.
sahilmgandhi 18:6a4db94011d3 207 * For example, if within a block of 100 bytes, the application wishes to
sahilmgandhi 18:6a4db94011d3 208 * write 20 bytes at an offset of 12, then this field should be set to 12.
sahilmgandhi 18:6a4db94011d3 209 * Must be word aligned.
sahilmgandhi 18:6a4db94011d3 210 *
sahilmgandhi 18:6a4db94011d3 211 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 212 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 213 * initialization.
sahilmgandhi 18:6a4db94011d3 214 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 215 * @retval NRF_ERROR_INVALID_PARAM Operation failure. Invalid parameter has been passed.
sahilmgandhi 18:6a4db94011d3 216 * @retval NRF_ERROR_INVALID_ADDR Operation failure. Parameter is not aligned.
sahilmgandhi 18:6a4db94011d3 217 * @retval NRF_ERROR_NO_MEM Operation failure. No storage space available.
sahilmgandhi 18:6a4db94011d3 218 *
sahilmgandhi 18:6a4db94011d3 219 * @warning No copy of the data is made, meaning memory provided for the data source that is to
sahilmgandhi 18:6a4db94011d3 220 * be written to flash cannot be freed or reused by the application until this procedure
sahilmgandhi 18:6a4db94011d3 221 * is complete. The application is notified when the procedure is finished using the
sahilmgandhi 18:6a4db94011d3 222 * notification callback registered by the application.
sahilmgandhi 18:6a4db94011d3 223 */
sahilmgandhi 18:6a4db94011d3 224 uint32_t pstorage_store(pstorage_handle_t * p_dest,
sahilmgandhi 18:6a4db94011d3 225 uint8_t * p_src,
sahilmgandhi 18:6a4db94011d3 226 pstorage_size_t size,
sahilmgandhi 18:6a4db94011d3 227 pstorage_size_t offset);
sahilmgandhi 18:6a4db94011d3 228
sahilmgandhi 18:6a4db94011d3 229 /**@brief Function for updating persistently stored data of length 'size' contained in the 'p_src'
sahilmgandhi 18:6a4db94011d3 230 * address in the storage module at 'p_dest' address.
sahilmgandhi 18:6a4db94011d3 231 *
sahilmgandhi 18:6a4db94011d3 232 * @param[in] p_dest Destination address where data is to be updated.
sahilmgandhi 18:6a4db94011d3 233 * @param[in] p_src Source address containing data to be stored. API assumes this to be resident
sahilmgandhi 18:6a4db94011d3 234 * memory and no intermediate copy of data is made by the API.
sahilmgandhi 18:6a4db94011d3 235 * @param[in] size Size of data to be stored expressed in bytes. Must be word aligned and size +
sahilmgandhi 18:6a4db94011d3 236 * offset must be <= block size.
sahilmgandhi 18:6a4db94011d3 237 * @param[in] offset Offset in bytes to be applied when writing to the block.
sahilmgandhi 18:6a4db94011d3 238 * For example, if within a block of 100 bytes, the application wishes to
sahilmgandhi 18:6a4db94011d3 239 * write 20 bytes at an offset of 12 bytes, then this field should be set to 12.
sahilmgandhi 18:6a4db94011d3 240 * Must be word aligned.
sahilmgandhi 18:6a4db94011d3 241 *
sahilmgandhi 18:6a4db94011d3 242 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 243 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 244 * initialization.
sahilmgandhi 18:6a4db94011d3 245 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 246 * @retval NRF_ERROR_INVALID_PARAM Operation failure. Invalid parameter has been passed.
sahilmgandhi 18:6a4db94011d3 247 * @retval NRF_ERROR_INVALID_ADDR Operation failure. Parameter is not aligned.
sahilmgandhi 18:6a4db94011d3 248 * @retval NRF_ERROR_NO_MEM Operation failure. No storage space available.
sahilmgandhi 18:6a4db94011d3 249 *
sahilmgandhi 18:6a4db94011d3 250 * @warning No copy of the data is made, meaning memory provided for the data source that is to
sahilmgandhi 18:6a4db94011d3 251 * be written to flash cannot be freed or reused by the application until this procedure
sahilmgandhi 18:6a4db94011d3 252 * is complete. The application is notified when the procedure is finished using the
sahilmgandhi 18:6a4db94011d3 253 * notification callback registered by the application.
sahilmgandhi 18:6a4db94011d3 254 */
sahilmgandhi 18:6a4db94011d3 255 uint32_t pstorage_update(pstorage_handle_t * p_dest,
sahilmgandhi 18:6a4db94011d3 256 uint8_t * p_src,
sahilmgandhi 18:6a4db94011d3 257 pstorage_size_t size,
sahilmgandhi 18:6a4db94011d3 258 pstorage_size_t offset);
sahilmgandhi 18:6a4db94011d3 259
sahilmgandhi 18:6a4db94011d3 260 /**@brief Function for loading persistently stored data of length 'size' from 'p_src' address
sahilmgandhi 18:6a4db94011d3 261 * to 'p_dest' address. Equivalent to Storage Read.
sahilmgandhi 18:6a4db94011d3 262 *
sahilmgandhi 18:6a4db94011d3 263 * @param[in] p_dest Destination address where persistently stored data is to be loaded.
sahilmgandhi 18:6a4db94011d3 264 * @param[in] p_src Source where data is loaded from persistent memory.
sahilmgandhi 18:6a4db94011d3 265 * @param[in] size Size of data to be loaded from persistent memory expressed in bytes.
sahilmgandhi 18:6a4db94011d3 266 * Should be word aligned.
sahilmgandhi 18:6a4db94011d3 267 * @param[in] offset Offset in bytes, to be applied when loading from the block.
sahilmgandhi 18:6a4db94011d3 268 * For example, if within a block of 100 bytes, the application wishes to
sahilmgandhi 18:6a4db94011d3 269 * load 20 bytes from offset of 12 bytes, then this field should be set to 12.
sahilmgandhi 18:6a4db94011d3 270 * Should be word aligned.
sahilmgandhi 18:6a4db94011d3 271 *
sahilmgandhi 18:6a4db94011d3 272 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 273 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 274 * initialization.
sahilmgandhi 18:6a4db94011d3 275 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 276 * @retval NRF_ERROR_INVALID_PARAM Operation failure. Invalid parameter has been passed.
sahilmgandhi 18:6a4db94011d3 277 * @retval NRF_ERROR_INVALID_ADDR Operation failure. Parameter is not aligned.
sahilmgandhi 18:6a4db94011d3 278 * @retval NRF_ERROR_NO_MEM Operation failure. No storage space available.
sahilmgandhi 18:6a4db94011d3 279 */
sahilmgandhi 18:6a4db94011d3 280 uint32_t pstorage_load(uint8_t * p_dest,
sahilmgandhi 18:6a4db94011d3 281 pstorage_handle_t * p_src,
sahilmgandhi 18:6a4db94011d3 282 pstorage_size_t size,
sahilmgandhi 18:6a4db94011d3 283 pstorage_size_t offset);
sahilmgandhi 18:6a4db94011d3 284
sahilmgandhi 18:6a4db94011d3 285 /**@brief Function for clearing data in persistent memory.
sahilmgandhi 18:6a4db94011d3 286 *
sahilmgandhi 18:6a4db94011d3 287 * @param[in] p_base_id Base block identifier in persistent memory that needs to be cleared;
sahilmgandhi 18:6a4db94011d3 288 * equivalent to an Erase Operation.
sahilmgandhi 18:6a4db94011d3 289 * @param[in] size Size of data to be cleared from persistent memory expressed in bytes.
sahilmgandhi 18:6a4db94011d3 290 * This parameter is to provision for clearing of certain blocks
sahilmgandhi 18:6a4db94011d3 291 * of memory, or all memory blocks in a registered module. If the total size
sahilmgandhi 18:6a4db94011d3 292 * of the application module is used (blocks * block size) in combination with
sahilmgandhi 18:6a4db94011d3 293 * the identifier for the first block in the module, all blocks in the
sahilmgandhi 18:6a4db94011d3 294 * module will be erased. Must be multiple of block size.
sahilmgandhi 18:6a4db94011d3 295 *
sahilmgandhi 18:6a4db94011d3 296 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 297 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 298 * initialization.
sahilmgandhi 18:6a4db94011d3 299 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 300 * @retval NRF_ERROR_INVALID_PARAM Operation failure. Invalid parameter has been passed.
sahilmgandhi 18:6a4db94011d3 301 * @retval NRF_ERROR_INVALID_ADDR Operation failure. Parameter is not aligned.
sahilmgandhi 18:6a4db94011d3 302 * @retval NRF_ERROR_NO_MEM Operation failure. No storage space available.
sahilmgandhi 18:6a4db94011d3 303 *
sahilmgandhi 18:6a4db94011d3 304 * @note Clear operations may take time. This API however, does not block until the clear
sahilmgandhi 18:6a4db94011d3 305 * procedure is complete. The application is notified of procedure completion using
sahilmgandhi 18:6a4db94011d3 306 * a notification callback registered by the application. The 'result' parameter of the
sahilmgandhi 18:6a4db94011d3 307 * callback indicates if the procedure was successful or not.
sahilmgandhi 18:6a4db94011d3 308 */
sahilmgandhi 18:6a4db94011d3 309 uint32_t pstorage_clear(pstorage_handle_t * p_base_id, pstorage_size_t size);
sahilmgandhi 18:6a4db94011d3 310
sahilmgandhi 18:6a4db94011d3 311 /**@brief Function for getting the number of pending operations with the module.
sahilmgandhi 18:6a4db94011d3 312 *
sahilmgandhi 18:6a4db94011d3 313 * @param[out] p_count Number of storage operations pending with the module. If 0, there are no
sahilmgandhi 18:6a4db94011d3 314 * outstanding requests.
sahilmgandhi 18:6a4db94011d3 315 *
sahilmgandhi 18:6a4db94011d3 316 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 317 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 318 * initialization.
sahilmgandhi 18:6a4db94011d3 319 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 320 */
sahilmgandhi 18:6a4db94011d3 321 uint32_t pstorage_access_status_get(uint32_t * p_count);
sahilmgandhi 18:6a4db94011d3 322
sahilmgandhi 18:6a4db94011d3 323 #ifdef PSTORAGE_RAW_MODE_ENABLE
sahilmgandhi 18:6a4db94011d3 324
sahilmgandhi 18:6a4db94011d3 325 /**@brief Function for registering with the persistent storage interface.
sahilmgandhi 18:6a4db94011d3 326 *
sahilmgandhi 18:6a4db94011d3 327 * @param[in] p_module_param Module registration parameter.
sahilmgandhi 18:6a4db94011d3 328 * @param[out] p_block_id Block identifier used to identify persistent memory blocks upon
sahilmgandhi 18:6a4db94011d3 329 * successful registration. The application is expected to use the block
sahilmgandhi 18:6a4db94011d3 330 * IDs for subsequent operations on requested persistent memory. When
sahilmgandhi 18:6a4db94011d3 331 * more than one memory block is requested, this identifier is the base
sahilmgandhi 18:6a4db94011d3 332 * identifier for the first block and used to identify subsequent blocks.
sahilmgandhi 18:6a4db94011d3 333 * The application shall use \@ref pstorage_block_identifier_get with
sahilmgandhi 18:6a4db94011d3 334 * this base identifier and block number. Therefore if 10 blocks of size
sahilmgandhi 18:6a4db94011d3 335 * 64 are requested and the application wishes to store memory in the 6th
sahilmgandhi 18:6a4db94011d3 336 * block, it shall use \@ref pstorage_block_identifier_get with the base
sahilmgandhi 18:6a4db94011d3 337 * ID and provide a block number of 5. Therefore, the application is only
sahilmgandhi 18:6a4db94011d3 338 * expected to remember the base block identifier.
sahilmgandhi 18:6a4db94011d3 339 *
sahilmgandhi 18:6a4db94011d3 340 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 341 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 342 * initialization.
sahilmgandhi 18:6a4db94011d3 343 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 344 * @retval NRF_ERROR_INVALID_PARAM Operation failure. Invalid parameter has been passed.
sahilmgandhi 18:6a4db94011d3 345 * @retval NRF_ERROR_NO_MEM Operation failure. No storage space available.
sahilmgandhi 18:6a4db94011d3 346 */
sahilmgandhi 18:6a4db94011d3 347 uint32_t pstorage_raw_register(pstorage_module_param_t * p_module_param,
sahilmgandhi 18:6a4db94011d3 348 pstorage_handle_t * p_block_id);
sahilmgandhi 18:6a4db94011d3 349
sahilmgandhi 18:6a4db94011d3 350 /**@brief Function for persistently storing data of length 'size' contained in 'p_src' address in
sahilmgandhi 18:6a4db94011d3 351 * storage module at 'p_dest' address. Equivalent to Storage Write.
sahilmgandhi 18:6a4db94011d3 352 *
sahilmgandhi 18:6a4db94011d3 353 * @param[in] p_dest Destination address where data is to be stored persistently.
sahilmgandhi 18:6a4db94011d3 354 * @param[in] p_src Source address containing data to be stored. The API assumes this is resident
sahilmgandhi 18:6a4db94011d3 355 * memory and no intermediate copy of data is made by the API. Must be word
sahilmgandhi 18:6a4db94011d3 356 * aligned.
sahilmgandhi 18:6a4db94011d3 357 * @param[in] size Size of data to be stored expressed in bytes. Must be word aligned.
sahilmgandhi 18:6a4db94011d3 358 * @param[in] offset Offset in bytes to be applied when writing to the block.
sahilmgandhi 18:6a4db94011d3 359 * For example, if within a block of 100 bytes, the application wishes to
sahilmgandhi 18:6a4db94011d3 360 * write 20 bytes at an offset of 12 bytes, this field should be set to 12.
sahilmgandhi 18:6a4db94011d3 361 * Must be word aligned.
sahilmgandhi 18:6a4db94011d3 362 *
sahilmgandhi 18:6a4db94011d3 363 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 364 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 365 * initialization.
sahilmgandhi 18:6a4db94011d3 366 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 367 * @retval NRF_ERROR_INVALID_PARAM Operation failure. Invalid parameter has been passed.
sahilmgandhi 18:6a4db94011d3 368 * @retval NRF_ERROR_INVALID_ADDR Operation failure. Parameter is not aligned.
sahilmgandhi 18:6a4db94011d3 369 * @retval NRF_ERROR_NO_MEM Operation failure. No storage space available.
sahilmgandhi 18:6a4db94011d3 370 *
sahilmgandhi 18:6a4db94011d3 371 * @warning No copy of the data is made, meaning memory provided for data source that is to be
sahilmgandhi 18:6a4db94011d3 372 * written to flash cannot be freed or reused by the application until this procedure
sahilmgandhi 18:6a4db94011d3 373 * is complete. The application is notified when the procedure is finished using the
sahilmgandhi 18:6a4db94011d3 374 * notification callback registered by the application.
sahilmgandhi 18:6a4db94011d3 375 */
sahilmgandhi 18:6a4db94011d3 376 uint32_t pstorage_raw_store(pstorage_handle_t * p_dest,
sahilmgandhi 18:6a4db94011d3 377 uint8_t * p_src,
sahilmgandhi 18:6a4db94011d3 378 pstorage_size_t size,
sahilmgandhi 18:6a4db94011d3 379 pstorage_size_t offset);
sahilmgandhi 18:6a4db94011d3 380
sahilmgandhi 18:6a4db94011d3 381 /**@brief Function for clearing data in persistent memory in raw mode.
sahilmgandhi 18:6a4db94011d3 382 *
sahilmgandhi 18:6a4db94011d3 383 * @param[in] p_dest Base block identifier in persistent memory that needs to be cleared.
sahilmgandhi 18:6a4db94011d3 384 * Equivalent to an Erase Operation.
sahilmgandhi 18:6a4db94011d3 385 * @param[in] size Size of data to be cleared from persistent memory expressed in bytes.
sahilmgandhi 18:6a4db94011d3 386 * Not used.
sahilmgandhi 18:6a4db94011d3 387 *
sahilmgandhi 18:6a4db94011d3 388 * @retval NRF_SUCCESS Operation success.
sahilmgandhi 18:6a4db94011d3 389 * @retval NRF_ERROR_INVALID_STATE Operation failure. API is called without module
sahilmgandhi 18:6a4db94011d3 390 * initialization.
sahilmgandhi 18:6a4db94011d3 391 * @retval NRF_ERROR_NULL Operation failure. NULL parameter has been passed.
sahilmgandhi 18:6a4db94011d3 392 * @retval NRF_ERROR_INVALID_PARAM Operation failure. Invalid parameter has been passed.
sahilmgandhi 18:6a4db94011d3 393 * @retval NRF_ERROR_NO_MEM Operation failure. No storage space available.
sahilmgandhi 18:6a4db94011d3 394 *
sahilmgandhi 18:6a4db94011d3 395 * @note Clear operations may take time. This API, however, does not block until the clear
sahilmgandhi 18:6a4db94011d3 396 * procedure is complete. The application is notified of procedure completion using
sahilmgandhi 18:6a4db94011d3 397 * a notification callback registered by the application. The 'result' parameter of the
sahilmgandhi 18:6a4db94011d3 398 * callback indicates if the procedure was successful or not.
sahilmgandhi 18:6a4db94011d3 399 */
sahilmgandhi 18:6a4db94011d3 400 uint32_t pstorage_raw_clear(pstorage_handle_t * p_dest, pstorage_size_t size);
sahilmgandhi 18:6a4db94011d3 401
sahilmgandhi 18:6a4db94011d3 402 #endif // PSTORAGE_RAW_MODE_ENABLE
sahilmgandhi 18:6a4db94011d3 403
sahilmgandhi 18:6a4db94011d3 404 /**@} */
sahilmgandhi 18:6a4db94011d3 405 /**@} */
sahilmgandhi 18:6a4db94011d3 406
sahilmgandhi 18:6a4db94011d3 407 #endif // PSTORAGE_H__
sahilmgandhi 18:6a4db94011d3 408