nrf_dfu_flash.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 sdk_nrf_dfu_flash Flash operations
  43. * @{
  44. * @ingroup nrf_dfu
  45. */
  46. #ifndef NRF_DFU_FLASH_H__
  47. #define NRF_DFU_FLASH_H__
  48. #include <stdint.h>
  49. #include <stdbool.h>
  50. #include "sdk_errors.h"
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. /**@brief nrf_fstorage event handler function for DFU fstorage operations.
  55. *
  56. * This function will be called after a flash operation has completed.
  57. */
  58. typedef void (*nrf_dfu_flash_callback_t)(void * p_buf);
  59. /**@brief Function for initializing the flash module.
  60. *
  61. * Depending on whether or not the SoftDevice is present and its IRQ have been initialized,
  62. * this function initializes the correct @ref nrf_fstorage backend.
  63. *
  64. * @param[in] sd_irq_initialized Whether or not the SoftDevice IRQ have been initialized.
  65. *
  66. * @retval NRF_SUCCESS If the operation was successful.
  67. */
  68. ret_code_t nrf_dfu_flash_init(bool sd_irq_initialized);
  69. /**@brief Function for storing data to flash.
  70. *
  71. * This functions is asynchronous when the SoftDevice is enabled and synchronous when
  72. * the SoftDevice is not present or disabled. In both cases, if a callback function is provided,
  73. * it will be called when the operation has completed.
  74. *
  75. * @note The content of @p p_src should be kept in memory until the operation has completed.
  76. *
  77. * @param[in] dest The address where the data should be stored.
  78. * @param[in] p_src Pointer to the address where the data should be copied from.
  79. * This address can be in flash or RAM.
  80. * @param[in] len The number of bytes to be copied from @p p_src to @p dest.
  81. * @param[in] callback Callback function.
  82. *
  83. * @retval NRF_SUCCESS If the operation was successful.
  84. * @retval NRF_ERROR_INVALID_STATE If nrf_dfu_flash is not initialized.
  85. * @retval NRF_ERROR_INVALID_ADDR If @p p_src or @p dest is not word-aligned.
  86. * @retval NRF_ERROR_INVALID_LENGTH If @p len is zero.
  87. * @retval NRF_ERROR_NULL If @p p_src is NULL.
  88. * @retval NRF_ERROR_NO_MEM If nrf_fstorage is out of memory.
  89. */
  90. ret_code_t nrf_dfu_flash_store(uint32_t dest,
  91. void const * p_src,
  92. uint32_t len,
  93. nrf_dfu_flash_callback_t callback);
  94. /**@brief Function for erasing data from flash.
  95. *
  96. * This functions is asynchronous when the SoftDevice is enabled and synchronous when
  97. * the SoftDevice is not present or disabled. In both cases, if a callback function is provided,
  98. * it will be called when the operation has completed.
  99. *
  100. * @param[in] page_addr The address of the first flash page to be deleted.
  101. * @param[in] num_pages The number of flash pages to be deleted.
  102. * @param[in] callback Callback function.
  103. *
  104. * @retval NRF_SUCCESS If the operation was successful.
  105. * @retval NRF_ERROR_INVALID_STATE If nrf_dfu_flash is not initialized.
  106. * @retval NRF_ERROR_INVALID_ADDR If @p page_addr is not aligned to a page boundary or the
  107. * operation would go beyond the flash memory boundaries.
  108. * @retval NRF_ERROR_INVALID_LENGTH If @p num_pages is zero.
  109. * @retval NRF_ERROR_NULL If @p page_addr is NULL.
  110. * @retval NRF_ERROR_NO_MEM If the queue of nrf_fstorage is full.
  111. */
  112. ret_code_t nrf_dfu_flash_erase(uint32_t page_addr, uint32_t num_pages, nrf_dfu_flash_callback_t callback);
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif // NRF_DFU_FLASH_H__
  117. /** @} */