dfu.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. /**@file
  13. *
  14. * @defgroup nrf_dfu Device Firmware Update API.
  15. * @{
  16. *
  17. * @brief Device Firmware Update module interface.
  18. */
  19. #ifndef DFU_H__
  20. #define DFU_H__
  21. #include <dfu_types.h>
  22. #include <stdbool.h>
  23. #include <stdint.h>
  24. /**@brief DFU event callback for asynchronous calls.
  25. *
  26. * @param[in] packet Packet type for which this callback is related. START_PACKET, DATA_PACKET.
  27. * @param[in] result Operation result code. NRF_SUCCESS when a queued operation was successful.
  28. * @param[in] p_data Pointer to the data to which the operation is related.
  29. */
  30. typedef void (*dfu_callback_t)(uint32_t packet, uint32_t result, uint8_t * p_data);
  31. /**@brief Function for initializing the Device Firmware Update module.
  32. *
  33. * @return NRF_SUCCESS on success, an error_code otherwise.
  34. */
  35. uint32_t dfu_init(void);
  36. /**@brief Function for registering a callback listener for \ref dfu_data_pkt_handle callbacks.
  37. *
  38. * @param[in] callback_handler Callback handler for receiving DFU events on completed operations
  39. * of DFU packets.
  40. */
  41. void dfu_register_callback(dfu_callback_t callback_handler);
  42. /**@brief Function for setting the DFU image size.
  43. *
  44. * @details Function sets the DFU image size. This function must be called when an update is started
  45. * in order to notify the DFU of the new image size. If multiple images are to be
  46. * transferred within the same update context then this function must be called with size
  47. * information for each image being transfered.
  48. * If an image type is not being transfered, e.g. SoftDevice but no Application , then the
  49. * image size for application must be zero.
  50. *
  51. * @param[in] p_packet Pointer to the DFU packet containing information on DFU update process to
  52. * be started.
  53. *
  54. * @return NRF_SUCCESS on success, an error_code otherwise.
  55. */
  56. uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet);
  57. /**@brief Function for handling DFU data packets.
  58. *
  59. * @param[in] p_packet Pointer to the DFU packet.
  60. *
  61. * @return NRF_SUCCESS on success, an error_code otherwise.
  62. */
  63. uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet);
  64. /**@brief Function for handling DFU init packets.
  65. *
  66. * @return NRF_SUCCESS on success, an error_code otherwise.
  67. */
  68. uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet);
  69. /**@brief Function for validating a transferred image after the transfer has completed.
  70. *
  71. * @return NRF_SUCCESS on success, an error_code otherwise.
  72. */
  73. uint32_t dfu_image_validate(void);
  74. /**@brief Function for activating the transfered image after validation has successfully completed.
  75. *
  76. * @return NRF_SUCCESS on success, an error_code otherwise.
  77. */
  78. uint32_t dfu_image_activate(void);
  79. /**@brief Function for reseting the current update procedure and return to initial state.
  80. *
  81. * @details This function call will result in a system reset to ensure correct system behavior.
  82. * The reset will might be scheduled to execute at a later point in time to ensure pending
  83. * flash operations has completed.
  84. */
  85. void dfu_reset(void);
  86. /**@brief Function for validating that new bootloader has been correctly installed.
  87. *
  88. * @return NRF_SUCCESS if install was successful. NRF_ERROR_NULL if the images differs.
  89. */
  90. uint32_t dfu_bl_image_validate(void);
  91. /**@brief Function for validating that new SoftDevicehas been correctly installed.
  92. *
  93. * @return NRF_SUCCESS if install was successful. NRF_ERROR_NULL if the images differs.
  94. */
  95. uint32_t dfu_sd_image_validate(void);
  96. /**@brief Function for swapping existing bootloader with newly received.
  97. *
  98. * @return NRF_SUCCESS on succesfull swapping. For error code please refer to
  99. * \ref sd_mbr_command_copy_bl_t.
  100. */
  101. uint32_t dfu_bl_image_swap(void);
  102. /**@brief Function for swapping existing SoftDevice with newly received.
  103. *
  104. * @return NRF_SUCCESS on succesfull swapping. For error code please refer to
  105. * \ref sd_mbr_command_copy_sd_t.
  106. */
  107. uint32_t dfu_sd_image_swap(void);
  108. /**@brief Function for handling DFU init packet complete.
  109. *
  110. * @return NRF_SUCCESS on success, an error_code otherwise.
  111. */
  112. uint32_t dfu_init_pkt_complete(void);
  113. #endif // DFU_H__
  114. /** @} */