ble_proc.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #if USB_EN
  55. ble_hid_service_proc();
  56. #endif // USB_EN
  57. }
  58. AT(.com_sleep.ble.sleep)
  59. bool ble_proc_pending(void)
  60. {
  61. bool res = false;
  62. #if (AB_FOT_CHANNEL & AB_FOT_CHANNEL_BLE)
  63. res = fota_is_start();
  64. #endif
  65. if(!res){
  66. res = ble_user_service_pending();
  67. }
  68. return res;
  69. }