main.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "main.h"
  2. #include "bsp_time.h"
  3. #include "hal_ble_client.h"
  4. #include "hal_ble_host.h"
  5. #include "nrf_delay.h"
  6. void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
  7. {
  8. switch (event)
  9. {
  10. case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
  11. {
  12. #if DEBUG_EN
  13. #if NRF_LOG_ENABLED
  14. NRF_LOG_INFO("Device is preparing to enter bootloader mode.\n");
  15. #endif
  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_EN
  23. #if NRF_LOG_ENABLED
  24. NRF_LOG_INFO("Device will enter bootloader mode.\n");
  25. #endif
  26. #endif
  27. break;
  28. case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
  29. #if DEBUG_EN
  30. #if NRF_LOG_ENABLED
  31. NRF_LOG_INFO("Request to enter bootloader mode failed asynchroneously.\n");
  32. #endif
  33. #endif
  34. // YOUR_JOB: Take corrective measures to resolve the issue
  35. // like calling APP_ERROR_CHECK to reset the device.
  36. break;
  37. case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
  38. #if DEBUG_EN
  39. NRF_LOG_INFO("Request to send a response to client failed.\n");
  40. #endif
  41. // YOUR_JOB: Take corrective measures to resolve the issue
  42. // like calling APP_ERROR_CHECK to reset the device.
  43. APP_ERROR_CHECK(false);
  44. break;
  45. default:
  46. #if DEBUG_EN
  47. #if NRF_LOG_ENABLED
  48. NRF_LOG_INFO("Unkn own event from ble_dfu_buttonless.\n");
  49. #endif
  50. #endif
  51. break;
  52. }
  53. }
  54. #if NRF_LOG_ENABLED
  55. static void log_init(void)
  56. {
  57. ret_code_t err_code = NRF_LOG_INIT(NULL);
  58. APP_ERROR_CHECK(err_code);
  59. NRF_LOG_DEFAULT_BACKENDS_INIT();
  60. }
  61. #endif
  62. extern void PRE_Init(void);
  63. extern void USR_Init(void);
  64. extern void USR_Process(void);
  65. int main(void)
  66. {
  67. #if BLE_DFU_ENANBLE
  68. ret_code_t err_code;
  69. err_code = ble_dfu_buttonless_async_svci_init();
  70. APP_ERROR_CHECK(err_code);
  71. #endif
  72. #if NRF_LOG_ENABLED
  73. log_init();
  74. #endif
  75. PRE_Init(); //Óû§³õʼ»¯
  76. #if BLE_DFU_ENANBLE
  77. ble_dfu_buttonless_init_t dfus_init = {0}; //DFU
  78. dfus_init.evt_handler = ble_dfu_evt_handler;
  79. err_code = ble_dfu_buttonless_init(&dfus_init);
  80. APP_ERROR_CHECK(err_code);
  81. #endif
  82. USR_Init(); //Óû§³õʼ»¯
  83. while (1)
  84. {
  85. #if NRF_LOG_ENABLED
  86. NRF_LOG_FLUSH();
  87. #endif
  88. USR_Process();
  89. }
  90. }