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.
Dependencies: FXAS21002 FXOS8700Q
simple-mbed-cloud-client/mbed-cloud-client/nanostack-libservice/mbed-client-libservice/ns_nvm_helper.h@0:977e87915078, 2019-08-28 (annotated)
- Committer:
- vithyat
- Date:
- Wed Aug 28 19:24:56 2019 +0000
- Revision:
- 0:977e87915078
init
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vithyat | 0:977e87915078 | 1 | // ---------------------------------------------------------------------------- |
vithyat | 0:977e87915078 | 2 | // Copyright 2016-2017 ARM Ltd. |
vithyat | 0:977e87915078 | 3 | // |
vithyat | 0:977e87915078 | 4 | // SPDX-License-Identifier: Apache-2.0 |
vithyat | 0:977e87915078 | 5 | // |
vithyat | 0:977e87915078 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
vithyat | 0:977e87915078 | 7 | // you may not use this file except in compliance with the License. |
vithyat | 0:977e87915078 | 8 | // You may obtain a copy of the License at |
vithyat | 0:977e87915078 | 9 | // |
vithyat | 0:977e87915078 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
vithyat | 0:977e87915078 | 11 | // |
vithyat | 0:977e87915078 | 12 | // Unless required by applicable law or agreed to in writing, software |
vithyat | 0:977e87915078 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
vithyat | 0:977e87915078 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vithyat | 0:977e87915078 | 15 | // See the License for the specific language governing permissions and |
vithyat | 0:977e87915078 | 16 | // limitations under the License. |
vithyat | 0:977e87915078 | 17 | // ---------------------------------------------------------------------------- |
vithyat | 0:977e87915078 | 18 | |
vithyat | 0:977e87915078 | 19 | /** |
vithyat | 0:977e87915078 | 20 | * NanoStack NVM helper functions to read, write and delete key-value pairs to platform NVM. |
vithyat | 0:977e87915078 | 21 | * |
vithyat | 0:977e87915078 | 22 | * Client can use following methods: |
vithyat | 0:977e87915078 | 23 | * -ns_nvm_data_write to write data to a key in platform NVM |
vithyat | 0:977e87915078 | 24 | * -ns_nvm_data_read to read data from key in platform NVM |
vithyat | 0:977e87915078 | 25 | * -ns_nvm_key_delete to delete a key from platform NVM |
vithyat | 0:977e87915078 | 26 | * |
vithyat | 0:977e87915078 | 27 | * If a API call returns NS_NVM_OK then a provided callback function will be called |
vithyat | 0:977e87915078 | 28 | * and status argument indicates success or failure of the operation. If API call |
vithyat | 0:977e87915078 | 29 | * returns error then callback will not be called. |
vithyat | 0:977e87915078 | 30 | * |
vithyat | 0:977e87915078 | 31 | * When client writes data this module will: |
vithyat | 0:977e87915078 | 32 | * -initialize the NVM if not already initialized |
vithyat | 0:977e87915078 | 33 | * -(re)create the key with a given size |
vithyat | 0:977e87915078 | 34 | * -write data to the key |
vithyat | 0:977e87915078 | 35 | * -flush data to the NVM |
vithyat | 0:977e87915078 | 36 | * |
vithyat | 0:977e87915078 | 37 | * When client reads data this module will: |
vithyat | 0:977e87915078 | 38 | * -initialize the NVM if not initialized |
vithyat | 0:977e87915078 | 39 | * -read data from the key |
vithyat | 0:977e87915078 | 40 | * |
vithyat | 0:977e87915078 | 41 | * When client deletes a key this module will: |
vithyat | 0:977e87915078 | 42 | * -initialize the NVM if not initialized |
vithyat | 0:977e87915078 | 43 | * -delete the key from NVM |
vithyat | 0:977e87915078 | 44 | */ |
vithyat | 0:977e87915078 | 45 | |
vithyat | 0:977e87915078 | 46 | /* |
vithyat | 0:977e87915078 | 47 | * API function and callback function return statuses |
vithyat | 0:977e87915078 | 48 | */ |
vithyat | 0:977e87915078 | 49 | #define NS_NVM_OK 0 |
vithyat | 0:977e87915078 | 50 | #define NS_NVM_DATA_NOT_FOUND -1 |
vithyat | 0:977e87915078 | 51 | #define NS_NVM_ERROR -2 |
vithyat | 0:977e87915078 | 52 | #define NS_NVM_MEMORY -3 |
vithyat | 0:977e87915078 | 53 | |
vithyat | 0:977e87915078 | 54 | /** |
vithyat | 0:977e87915078 | 55 | * callback type for NanoStack NVM |
vithyat | 0:977e87915078 | 56 | */ |
vithyat | 0:977e87915078 | 57 | typedef void (ns_nvm_callback)(int status, void *context); |
vithyat | 0:977e87915078 | 58 | |
vithyat | 0:977e87915078 | 59 | /** |
vithyat | 0:977e87915078 | 60 | * \brief Delete key from NVM |
vithyat | 0:977e87915078 | 61 | * |
vithyat | 0:977e87915078 | 62 | * \param callback function to be called when key deletion is ready |
vithyat | 0:977e87915078 | 63 | * \param key_name Name of the key to be deleted from NVM |
vithyat | 0:977e87915078 | 64 | * \param context argument will be provided as an argument when callback is called |
vithyat | 0:977e87915078 | 65 | * |
vithyat | 0:977e87915078 | 66 | * \return NS_NVM_OK if key deletion is in progress and callback will be called |
vithyat | 0:977e87915078 | 67 | * \return NS_NVM_ERROR in error case, callback will not be called |
vithyat | 0:977e87915078 | 68 | * \return provided callback function will be called with status indicating success or failure. |
vithyat | 0:977e87915078 | 69 | */ |
vithyat | 0:977e87915078 | 70 | int ns_nvm_key_delete(ns_nvm_callback *callback, const char *key_name, void *context); |
vithyat | 0:977e87915078 | 71 | |
vithyat | 0:977e87915078 | 72 | /** |
vithyat | 0:977e87915078 | 73 | * \brief Read data from NVM |
vithyat | 0:977e87915078 | 74 | * |
vithyat | 0:977e87915078 | 75 | * \param callback function to be called when data is read |
vithyat | 0:977e87915078 | 76 | * \param key_name Name of the key whose data will be read |
vithyat | 0:977e87915078 | 77 | * \param buf buffer where data will be stored |
vithyat | 0:977e87915078 | 78 | * \param buf_len address of variable containing provided buffer length |
vithyat | 0:977e87915078 | 79 | * \param context argument will be provided as an argument when callback is called |
vithyat | 0:977e87915078 | 80 | * |
vithyat | 0:977e87915078 | 81 | * \return NS_NVM_OK if read is in progress and callback will be called |
vithyat | 0:977e87915078 | 82 | * \return NS_NVM_ERROR in error case, callback will not be called |
vithyat | 0:977e87915078 | 83 | * \return provided callback function will be called with status indicating success or failure. |
vithyat | 0:977e87915078 | 84 | */ |
vithyat | 0:977e87915078 | 85 | int ns_nvm_data_read(ns_nvm_callback *callback, const char *key_name, uint8_t *buf, uint16_t *buf_len, void *context); |
vithyat | 0:977e87915078 | 86 | |
vithyat | 0:977e87915078 | 87 | /** |
vithyat | 0:977e87915078 | 88 | * \brief Write data to NVM |
vithyat | 0:977e87915078 | 89 | * |
vithyat | 0:977e87915078 | 90 | * \param callback function to be called when data writing is completed |
vithyat | 0:977e87915078 | 91 | * \param key_name Name of the key whose data will be read |
vithyat | 0:977e87915078 | 92 | * \param buf buffer where data will be stored |
vithyat | 0:977e87915078 | 93 | * \param buf_len address of variable containing provided buffer length |
vithyat | 0:977e87915078 | 94 | * \param context argument will be provided as an argument when callback is called |
vithyat | 0:977e87915078 | 95 | * |
vithyat | 0:977e87915078 | 96 | * \return NS_NVM_OK if read is in progress and callback will be called |
vithyat | 0:977e87915078 | 97 | * \return NS_NVM_ERROR in error case, callback will not be called |
vithyat | 0:977e87915078 | 98 | * \return provided callback function will be called with status indicating success or failure. |
vithyat | 0:977e87915078 | 99 | */ |
vithyat | 0:977e87915078 | 100 | int ns_nvm_data_write(ns_nvm_callback *callback, const char *key_name, uint8_t *buf, uint16_t *buf_len, void *context); |