leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Committer:
leothedragon
Date:
Tue May 04 08:55:12 2021 +0000
Revision:
0:8f0bb79ddd48
nmn

Who changed what in which revision?

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