ble_proc.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "include.h"
  2. #include "ble_user_service.h"
  3. #include "ble_hid_service.h"
  4. #include "ble_fota_service.h"
  5. #include "wireless_service.h"
  6. #include "fota_proc.h"
  7. #define BLE_ADV_SLEEP_INTERVAL 800 //500ms
  8. #define BLE_CON_SLEEP_INTERVAL 400 //500ms
  9. #define BLE_CON_SLEEP_LATENCY 0
  10. #define BLE_CON_SLEEP_TIMEOUT 1000 //10s
  11. static struct ble_param_t {
  12. uint16_t adv_interval;
  13. uint16_t conn_interval;
  14. uint16_t conn_latency;
  15. uint16_t conn_timeout;
  16. } ble_param;
  17. static void ble_update_param_before_enter_sleep(void)
  18. {
  19. if (ble_cb.con_hanle) {
  20. ble_enable_latency(ble_cb.con_hanle);
  21. } else {
  22. ble_get_adv_interval(&ble_param.adv_interval);
  23. ble_set_adv_interval(BLE_ADV_SLEEP_INTERVAL);
  24. }
  25. }
  26. static void ble_update_param_after_exit_sleep(void)
  27. {
  28. if (ble_cb.con_hanle) {
  29. ble_disable_latency(ble_cb.con_hanle);
  30. } else {
  31. ble_set_adv_interval(ble_param.adv_interval);
  32. }
  33. }
  34. void ble_enter_sleep_proc(void)
  35. {
  36. if (func_cb.sta == FUNC_BT) {
  37. ble_update_param_before_enter_sleep();
  38. } else if (func_cb.sta == FUNC_WIRELESS) {
  39. wireless_enter_sleep_hook();
  40. }
  41. }
  42. void ble_exit_sleep_proc(void)
  43. {
  44. if (func_cb.sta == FUNC_BT) {
  45. ble_update_param_after_exit_sleep();
  46. } else if (func_cb.sta == FUNC_WIRELESS) {
  47. wireless_exit_sleep_hook();
  48. }
  49. }
  50. AT(.text.app.proc.ble)
  51. void ble_app_proc(void)
  52. {
  53. ble_user_service_proc();
  54. ble_hid_service_proc();
  55. }
  56. AT(.com_sleep.ble.sleep)
  57. bool ble_proc_pending(void)
  58. {
  59. bool res = false;
  60. #if (AB_FOT_CHANNEL & AB_FOT_CHANNEL_BLE)
  61. res = fota_is_start();
  62. #endif
  63. if(!res){
  64. res = ble_user_service_pending();
  65. }
  66. return res;
  67. }