nrf_dfu_settings.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /**
  2. * Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /**@file
  41. *
  42. * @defgroup nrf_dfu_settings DFU settings
  43. * @{
  44. * @ingroup nrf_dfu
  45. */
  46. #ifndef NRF_DFU_SETTINGS_H__
  47. #define NRF_DFU_SETTINGS_H__
  48. #include <stdint.h>
  49. #include "nrf_dfu_types.h"
  50. #include "nrf_dfu_flash.h"
  51. #include "sdk_config.h"
  52. #include "sdk_errors.h"
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. /**@brief Global settings.
  57. *
  58. * @note Using this variable is not thread-safe.
  59. *
  60. */
  61. extern nrf_dfu_settings_t s_dfu_settings;
  62. /**@brief Function for writing DFU settings to flash.
  63. *
  64. * @param[in] callback Pointer to a function that is called after completing the write operation.
  65. *
  66. * @retval NRF_SUCCESS If the write process was successfully initiated.
  67. * @retval NRF_ERROR_INTERNAL If a flash error occurred.
  68. */
  69. ret_code_t nrf_dfu_settings_write(nrf_dfu_flash_callback_t callback);
  70. /**@brief Function for backing up the settings.
  71. *
  72. * This function copies the contents of the settings page (in flash) to a separate page (in flash).
  73. * During @ref nrf_dfu_settings_init, the backup is restored if the original is invalid.
  74. *
  75. * @param[in] callback Pointer to a function that is called after completing the write operation.
  76. */
  77. void nrf_dfu_settings_backup(nrf_dfu_flash_callback_t callback);
  78. /**@brief Function for writing DFU settings to flash and to backup.
  79. *
  80. * This function first calls @ref nrf_dfu_settings_write and then @ref nrf_dfu_settings_backup.
  81. *
  82. * @param[in] callback Pointer to a function that is called after completing the write and backup operation.
  83. *
  84. * @retval NRF_SUCCESS If the write process was successfully initiated.
  85. * @retval NRF_ERROR_INTERNAL If a flash error occurred during the first write.
  86. */
  87. ret_code_t nrf_dfu_settings_write_and_backup(nrf_dfu_flash_callback_t callback);
  88. /**@brief Function for initializing the DFU settings structure.
  89. *
  90. * Initializes the RAM structure from the flash contents.
  91. * This function is called as part of @ref nrf_dfu_settings_init.
  92. *
  93. * @retval NRF_SUCCESS If the initialization was successful.
  94. * @retval NRF_ERROR_INTERNAL If a flash error occurred.
  95. */
  96. void nrf_dfu_settings_reinit(void);
  97. /**@brief Function for initializing the DFU settings module.
  98. *
  99. * @retval NRF_SUCCESS If the initialization was successful.
  100. * @retval NRF_ERROR_INTERNAL If a flash error occurred.
  101. */
  102. ret_code_t nrf_dfu_settings_init(bool sd_irq_initialized);
  103. #if defined(NRF_DFU_TRANSPORT_BLE) && NRF_DFU_TRANSPORT_BLE
  104. /** @brief Function for storing peer data received through an SVCI call in DFU settings.
  105. *
  106. * @note The content of the type can be verified by a CRC value stored inside the struct
  107. * If the CRC value is 0xFFFFFFFF, it means that no data is set.
  108. *
  109. * @note The storage operation is an asynchronous progress. Success will be notified
  110. * through system events raised by the SoftDevice.
  111. *
  112. * @param[in] p_data Peer data to be stored in flash.
  113. *
  114. * @retval NRF_SUCCESS Asynchronous operation was successfully started.
  115. * @retval NRF_ERROR_NULL p_data was NULL.
  116. * @retval Any other error code reported by SoftDevice API calls.
  117. */
  118. ret_code_t nrf_dfu_settings_peer_data_write(nrf_dfu_peer_data_t * p_data);
  119. /** @brief Function for copying peer data from DFU settings to RAM.
  120. *
  121. * @param[in,out] p_data Structure to copy peer data to.
  122. *
  123. * @retval NRF_SUCCESS Peer data was successfully copied.
  124. * @retval NRF_ERROR_NULL p_data was NULL.
  125. */
  126. ret_code_t nrf_dfu_settings_peer_data_copy(nrf_dfu_peer_data_t * p_data);
  127. /** @brief Function for validating peer data in DFU settings.
  128. *
  129. * @retval True if peer data is validated by CRC, false if not.
  130. */
  131. bool nrf_dfu_settings_peer_data_is_valid(void);
  132. /** @brief Function for storing an advertisement name received through an SVCI call in DFU settings.
  133. *
  134. * @note The content of the type is verifyable by a CRC-value stored inside the struct.
  135. *
  136. * @note The storage operation is an asynchronous progress. Success will be notified
  137. * through system events raised by the SoftDevice.
  138. *
  139. * @param[in] p_adv_name Structure holding information about the new advertisement name.
  140. *
  141. * @retval NRF_SUCCESS Asynchronous operation was successfully started.
  142. * @retval NRF_ERROR_NULL p_adv_name was NULL.
  143. * @retval Any other error code reported by SoftDevice API calls.
  144. */
  145. ret_code_t nrf_dfu_settings_adv_name_write(nrf_dfu_adv_name_t * p_adv_name);
  146. /** @brief Function for copying the advertisement name from DFU settings to RAM.
  147. *
  148. * @param[in,out] p_adv_name Structure to copy the new advertisement name to.
  149. *
  150. * @retval NRF_SUCCESS Advertisement name was successfully copied.
  151. * @retval NRF_ERROR_NULL p_adv_name was NULL.
  152. */
  153. ret_code_t nrf_dfu_settings_adv_name_copy(nrf_dfu_adv_name_t * p_adv_name);
  154. /** @brief Function for validating advertisement data in DFU settings.
  155. *
  156. * @retval True if advertisement name is validated by CRC, false if not.
  157. */
  158. bool nrf_dfu_settings_adv_name_is_valid(void);
  159. #endif // NRF_DFU_TRANSPORT_BLE
  160. /** @brief Function for erasing additional data in DFU settings.
  161. *
  162. * @note Erasing additional data in DFU settings is only possible
  163. * if nrf_dfu_flash is initialized to not use SoftDevice calls.
  164. *
  165. * @retval NRF_SUCCESS Additional data was successfully erased.
  166. * @retval Any other error code reported by nrf_dfu_flash
  167. */
  168. ret_code_t nrf_dfu_settings_additional_erase(void);
  169. /** @brief Function for resetting both init command and DFU transfer progress inside settings structure.
  170. *
  171. * @note This function does not perform flash operation.
  172. * In order to save the reset state, please use @ref nrf_dfu_settings_write function.
  173. */
  174. void nrf_dfu_settings_progress_reset(void);
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. #endif // NRF_DFU_SETTINGS_H__
  179. /**@} */