nrf_dfu_settings.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /**
  2. * Copyright (c) 2016 - 2019, 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 module.
  89. *
  90. * @retval NRF_SUCCESS If the initialization was successful.
  91. * @retval NRF_ERROR_INTERNAL If a flash error occurred.
  92. */
  93. ret_code_t nrf_dfu_settings_init(bool sd_irq_initialized);
  94. #if defined(NRF_DFU_TRANSPORT_BLE) && NRF_DFU_TRANSPORT_BLE
  95. /** @brief Function for storing peer data received through an SVCI call in DFU settings.
  96. *
  97. * @note The content of the type can be verified by a CRC value stored inside the struct
  98. * If the CRC value is 0xFFFFFFFF, it means that no data is set.
  99. *
  100. * @note The storage operation is an asynchronous progress. Success will be notified
  101. * through system events raised by the SoftDevice.
  102. *
  103. * @param[in] p_data Peer data to be stored in flash.
  104. *
  105. * @retval NRF_SUCCESS Asynchronous operation was successfully started.
  106. * @retval NRF_ERROR_NULL p_data was NULL.
  107. * @retval Any other error code reported by SoftDevice API calls.
  108. */
  109. ret_code_t nrf_dfu_settings_peer_data_write(nrf_dfu_peer_data_t * p_data);
  110. /** @brief Function for copying peer data from DFU settings to RAM.
  111. *
  112. * @param[in,out] p_data Structure to copy peer data to.
  113. *
  114. * @retval NRF_SUCCESS Peer data was successfully copied.
  115. * @retval NRF_ERROR_NULL p_data was NULL.
  116. */
  117. ret_code_t nrf_dfu_settings_peer_data_copy(nrf_dfu_peer_data_t * p_data);
  118. /** @brief Function for validating peer data in DFU settings.
  119. *
  120. * @retval True if peer data is validated by CRC, false if not.
  121. */
  122. bool nrf_dfu_settings_peer_data_is_valid(void);
  123. /** @brief Function for storing an advertisement name received through an SVCI call in DFU settings.
  124. *
  125. * @note The content of the type is verifyable by a CRC-value stored inside the struct.
  126. *
  127. * @note The storage operation is an asynchronous progress. Success will be notified
  128. * through system events raised by the SoftDevice.
  129. *
  130. * @param[in] p_adv_name Structure holding information about the new advertisement name.
  131. *
  132. * @retval NRF_SUCCESS Asynchronous operation was successfully started.
  133. * @retval NRF_ERROR_NULL p_adv_name was NULL.
  134. * @retval Any other error code reported by SoftDevice API calls.
  135. */
  136. ret_code_t nrf_dfu_settings_adv_name_write(nrf_dfu_adv_name_t * p_adv_name);
  137. /** @brief Function for copying the advertisement name from DFU settings to RAM.
  138. *
  139. * @param[in,out] p_adv_name Structure to copy the new advertisement name to.
  140. *
  141. * @retval NRF_SUCCESS Advertisement name was successfully copied.
  142. * @retval NRF_ERROR_NULL p_adv_name was NULL.
  143. */
  144. ret_code_t nrf_dfu_settings_adv_name_copy(nrf_dfu_adv_name_t * p_adv_name);
  145. /** @brief Function for validating advertisement data in DFU settings.
  146. *
  147. * @retval True if advertisement name is validated by CRC, false if not.
  148. */
  149. bool nrf_dfu_settings_adv_name_is_valid(void);
  150. #endif // NRF_DFU_TRANSPORT_BLE
  151. /** @brief Function for erasing additional data in DFU settings.
  152. *
  153. * @note Erasing additional data in DFU settings is only possible
  154. * if nrf_dfu_flash is initialized to not use SoftDevice calls.
  155. *
  156. * @retval NRF_SUCCESS Additional data was successfully erased.
  157. * @retval Any other error code reported by nrf_dfu_flash
  158. */
  159. ret_code_t nrf_dfu_settings_additional_erase(void);
  160. #ifdef __cplusplus
  161. }
  162. #endif
  163. #endif // NRF_DFU_SETTINGS_H__
  164. /**@} */