dfu.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "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_DFU_EN
  15. SEGGER_RTT_printf(0,"Device is preparing to enter bootloader mode.\n");
  16. #endif
  17. break;
  18. }
  19. case BLE_DFU_EVT_BOOTLOADER_ENTER:
  20. // YOUR_JOB: Write app-specific unwritten data to FLASH, control finalization of this
  21. // by delaying reset by reporting false in app_shutdown_handler
  22. #if DEBUG_DFU_EN
  23. SEGGER_RTT_printf(0,"Device will enter bootloader mode.\n");
  24. #endif
  25. break;
  26. case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
  27. #if DEBUG_DFU_EN
  28. SEGGER_RTT_printf(0,"Request to enter bootloader mode failed asynchroneously.\n");
  29. #endif
  30. // YOUR_JOB: Take corrective measures to resolve the issue
  31. // like calling APP_ERROR_CHECK to reset the device.
  32. break;
  33. case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
  34. #if DEBUG_DFU_EN
  35. SEGGER_RTT_printf(0,"Request to send a response to client failed.\n");
  36. #endif
  37. // YOUR_JOB: Take corrective measures to resolve the issue
  38. // like calling APP_ERROR_CHECK to reset the device.
  39. APP_ERROR_CHECK(false);
  40. break;
  41. default:
  42. #if DEBUG_DFU_EN
  43. SEGGER_RTT_printf(0,"Unknown event from ble_dfu_buttonless.\n");
  44. #endif
  45. break;
  46. }
  47. }
  48. void dfu_init(void){
  49. ret_code_t err_code;
  50. err_code = ble_dfu_buttonless_async_svci_init();
  51. APP_ERROR_CHECK(err_code);
  52. }
  53. void dfu_server_init(void){
  54. ret_code_t err_code;
  55. ble_dfu_buttonless_init_t dfus_init = {0}; //DFU
  56. dfus_init.evt_handler = ble_dfu_evt_handler;
  57. err_code = ble_dfu_buttonless_init(&dfus_init);
  58. APP_ERROR_CHECK(err_code);
  59. }
  60. #endif