blehr_app.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2021-2021, Bluetrum Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-10-15 greedyhao the first version
  9. */
  10. #include <rtthread.h>
  11. #include <stdint.h>
  12. #include <stddef.h>
  13. #ifdef BSP_USING_NIMBLE
  14. void nimble_port_run(void);
  15. void nimble_port_init(void);
  16. int ble_hci_rtthread_init(void);
  17. void ble_svc_gap_init(void);
  18. void ble_store_ram_init(void);
  19. int blehr_main(void);
  20. void bb_init(void);
  21. void bthw_get_heap_info(void **p_heap, uint16_t **p_heap_size, uint32_t *p_block_size);
  22. typedef void (*nsmem_cb_init_func)(void *heap_buf, void *heap_size_buf, uint32_t mem_block_max);
  23. #define nsmem_cb_init ((nsmem_cb_init_func)0x84140)
  24. int btctrl_mem_init(void)
  25. {
  26. void *heap_buf;
  27. uint16_t *heap_size_buf;
  28. uint32_t block_size;
  29. bthw_get_heap_info(&heap_buf, &heap_size_buf, &block_size);
  30. nsmem_cb_init(heap_buf, heap_size_buf, block_size);
  31. return 0;
  32. }
  33. INIT_BOARD_EXPORT(btctrl_mem_init);
  34. static void blehr_thread_entry(void *param)
  35. {
  36. bb_init();
  37. nimble_port_init();
  38. ble_hci_rtthread_init();
  39. ble_svc_gap_init();
  40. /* XXX Need to have template for store */
  41. ble_store_ram_init();
  42. blehr_main();
  43. nimble_port_run();
  44. }
  45. static int blehr_sample(void)
  46. {
  47. rt_thread_t tid = rt_thread_create(
  48. "blehr",
  49. blehr_thread_entry,
  50. RT_NULL,
  51. 1024,
  52. 15,
  53. 1);
  54. if (tid != RT_NULL)
  55. {
  56. rt_thread_startup(tid);
  57. }
  58. }
  59. MSH_CMD_EXPORT(blehr_sample, blehr_sample);
  60. #endif