dfu_bank_internal.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (c) 2014 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 dfu_bank_internal Device Firmware Update internal header for bank handling in DFU.
  15. * @{
  16. *
  17. * @brief Device Firmware Update Bank handling module interface.
  18. *
  19. * @details This header is intended for shared definition and functions between single and dual bank
  20. * implementations used for DFU support. It is not supposed to be used for external access
  21. * to the DFU module.
  22. *
  23. */
  24. #ifndef DFU_BANK_INTERNAL_H__
  25. #define DFU_BANK_INTERNAL_H__
  26. #include <dfu_types.h>
  27. /**@brief States of the DFU state machine. */
  28. typedef enum
  29. {
  30. DFU_STATE_INIT_ERROR, /**< State for: dfu_init(...) error. */
  31. DFU_STATE_IDLE, /**< State for: idle. */
  32. DFU_STATE_PREPARING, /**< State for: preparing, indicates that the flash is being erased and no data packets can be processed. */
  33. DFU_STATE_RDY, /**< State for: ready. */
  34. DFU_STATE_RX_INIT_PKT, /**< State for: receiving initialization packet. */
  35. DFU_STATE_RX_DATA_PKT, /**< State for: receiving data packet. */
  36. DFU_STATE_VALIDATE, /**< State for: validate. */
  37. DFU_STATE_WAIT_4_ACTIVATE /**< State for: waiting for dfu_image_activate(). */
  38. } dfu_state_t;
  39. #define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
  40. #define DFU_TIMEOUT_INTERVAL APP_TIMER_TICKS(120000, APP_TIMER_PRESCALER) /**< DFU timeout interval in units of timer ticks. */
  41. #define IS_UPDATING_SD(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_SD) /**< Macro for determining if a SoftDevice update is ongoing. */
  42. #define IS_UPDATING_BL(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_BL) /**< Macro for determining if a Bootloader update is ongoing. */
  43. #define IS_UPDATING_APP(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_APP) /**< Macro for determining if a Application update is ongoing. */
  44. #define IMAGE_WRITE_IN_PROGRESS() (m_data_received > 0) /**< Macro for determining if an image write is in progress. */
  45. #define IS_WORD_SIZED(SIZE) ((SIZE & (sizeof(uint32_t) - 1)) == 0) /**< Macro for checking that the provided is word sized. */
  46. /**@cond NO_DOXYGEN */
  47. static uint32_t m_data_received; /**< Amount of received data. */
  48. /**@endcond */
  49. /**@brief Type definition of function used for preparing of the bank before receiving of a
  50. * software image.
  51. *
  52. * @param[in] image_size Size of software image being received.
  53. */
  54. typedef void (*dfu_bank_prepare_t)(uint32_t image_size);
  55. /**@brief Type definition of function used for handling clear complete of the bank before
  56. * receiving of a software image.
  57. */
  58. typedef void (*dfu_bank_cleared_t)(void);
  59. /**@brief Type definition of function used for activating of the software image received.
  60. *
  61. * @return NRF_SUCCESS If the image has been successfully activated any other NRF_ERROR code in
  62. * case of a failure.
  63. */
  64. typedef uint32_t (*dfu_bank_activate_t)(void);
  65. /**@brief Structure for holding of function pointers for needed prepare and activate procedure for
  66. * the requested update procedure.
  67. */
  68. typedef struct
  69. {
  70. dfu_bank_prepare_t prepare; /**< Function pointer to the prepare function called on start of update procedure. */
  71. dfu_bank_cleared_t cleared; /**< Function pointer to the cleared function called after prepare function completes. */
  72. dfu_bank_activate_t activate; /**< Function pointer to the activate function called on finalizing the update procedure. */
  73. } dfu_bank_func_t;
  74. #endif // DFU_BANK_INTERNAL_H__
  75. /** @} */