nvs_flash.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef nvs_flash_h
  14. #define nvs_flash_h
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "nvs.h"
  19. /**
  20. * @brief Initialize the default NVS partition.
  21. *
  22. * This API initialises the default NVS partition. The default NVS partition
  23. * is the one that is labeled "nvs" in the partition table.
  24. *
  25. * @return
  26. * - ESP_OK if storage was successfully initialized.
  27. * - ESP_ERR_NVS_NO_FREE_PAGES if the NVS storage contains no empty pages
  28. * (which may happen if NVS partition was truncated)
  29. * - ESP_ERR_NOT_FOUND if no partition with label "nvs" is found in the partition table
  30. * - one of the error codes from the underlying flash storage driver
  31. */
  32. esp_err_t nvs_flash_init(void);
  33. /**
  34. * @brief Initialize NVS flash storage for the specified partition.
  35. *
  36. * @param[in] partition_label Label of the partition. Note that internally a reference to
  37. * passed value is kept and it should be accessible for future operations
  38. *
  39. * @return
  40. * - ESP_OK if storage was successfully initialized.
  41. * - ESP_ERR_NVS_NO_FREE_PAGES if the NVS storage contains no empty pages
  42. * (which may happen if NVS partition was truncated)
  43. * - ESP_ERR_NOT_FOUND if specified partition is not found in the partition table
  44. * - one of the error codes from the underlying flash storage driver
  45. */
  46. esp_err_t nvs_flash_init_partition(const char *partition_label);
  47. /**
  48. * @brief Deinitialize NVS storage for the default NVS partition
  49. *
  50. * Default NVS partition is the partition with "nvs" label in the partition table.
  51. *
  52. * @return
  53. * - ESP_OK on success (storage was deinitialized)
  54. * - ESP_ERR_NVS_NOT_INITIALIZED if the storage was not initialized prior to this call
  55. */
  56. esp_err_t nvs_flash_deinit(void);
  57. /**
  58. * @brief Deinitialize NVS storage for the given NVS partition
  59. *
  60. * @param[in] partition_label Label of the partition
  61. *
  62. * @return
  63. * - ESP_OK on success
  64. * - ESP_ERR_NVS_NOT_INITIALIZED if the storage for given partition was not
  65. * initialized prior to this call
  66. */
  67. esp_err_t nvs_flash_deinit_partition(const char* partition_label);
  68. /**
  69. * @brief Erase the default NVS partition
  70. *
  71. * This function erases all contents of the default NVS partition (one with label "nvs")
  72. *
  73. * @return
  74. * - ESP_OK on success
  75. * - ESP_ERR_NOT_FOUND if there is no NVS partition labeled "nvs" in the
  76. * partition table
  77. */
  78. esp_err_t nvs_flash_erase(void);
  79. /**
  80. * @brief Erase specified NVS partition
  81. *
  82. * This function erases all contents of specified NVS partition
  83. *
  84. * @param[in] part_name Name (label) of the partition to be erased
  85. *
  86. * @return
  87. * - ESP_OK on success
  88. * - ESP_ERR_NOT_FOUND if there is no NVS partition with the specified name
  89. * in the partition table
  90. */
  91. esp_err_t nvs_flash_erase_partition(const char *part_name);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* nvs_flash_h */