hal_dfu.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "hal_dfu.h"
  2. #include "system.h"
  3. #include "ble_dfu.h"
  4. #include "nrf_dfu_ble_svci_bond_sharing.h"
  5. #include "nrf_svci_async_function.h"
  6. #include "nrf_svci_async_handler.h"
  7. #if BLE_DFU_ENANBLE
  8. static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
  9. {
  10. switch (event)
  11. {
  12. case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
  13. {
  14. #if DEBUG_EN
  15. #if NRF_LOG_ENABLED
  16. NRF_LOG_INFO("Device is preparing to enter bootloader mode.\n");
  17. #endif
  18. #endif
  19. break;
  20. }
  21. case BLE_DFU_EVT_BOOTLOADER_ENTER:
  22. // YOUR_JOB: Write app-specific unwritten data to FLASH, control finalization of this
  23. // by delaying reset by reporting false in app_shutdown_handler
  24. #if DEBUG_EN
  25. #if NRF_LOG_ENABLED
  26. NRF_LOG_INFO("Device will enter bootloader mode.\n");
  27. #endif
  28. #endif
  29. break;
  30. case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
  31. #if DEBUG_EN
  32. #if NRF_LOG_ENABLED
  33. NRF_LOG_INFO("Request to enter bootloader mode failed asynchroneously.\n");
  34. #endif
  35. #endif
  36. // YOUR_JOB: Take corrective measures to resolve the issue
  37. // like calling APP_ERROR_CHECK to reset the device.
  38. break;
  39. case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
  40. #if DEBUG_EN
  41. #if NRF_LOG_ENABLED
  42. NRF_LOG_INFO("Request to send a response to client failed.\n");
  43. #endif
  44. #endif
  45. // YOUR_JOB: Take corrective measures to resolve the issue
  46. // like calling APP_ERROR_CHECK to reset the device.
  47. APP_ERROR_CHECK(false);
  48. break;
  49. default:
  50. #if DEBUG_EN
  51. #if NRF_LOG_ENABLED
  52. NRF_LOG_INFO("Unknown event from ble_dfu_buttonless.\n");
  53. #endif
  54. #endif
  55. break;
  56. }
  57. }
  58. void hal_dfu_init(void){
  59. ret_code_t err_code;
  60. err_code = ble_dfu_buttonless_async_svci_init();
  61. APP_ERROR_CHECK(err_code);
  62. }
  63. void hal_dfu_server_init(void){
  64. ret_code_t err_code;
  65. ble_dfu_buttonless_init_t dfus_init = {0}; //DFU
  66. dfus_init.evt_handler = ble_dfu_evt_handler;
  67. err_code = ble_dfu_buttonless_init(&dfus_init);
  68. APP_ERROR_CHECK(err_code);
  69. }
  70. #endif