ble_glue.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef enum {
  8. BleGlueC2ModeUnknown = 0,
  9. BleGlueC2ModeFUS,
  10. BleGlueC2ModeStack,
  11. } BleGlueC2Mode;
  12. typedef struct {
  13. BleGlueC2Mode mode;
  14. /**
  15. * Wireless Info
  16. */
  17. uint8_t VersionMajor;
  18. uint8_t VersionMinor;
  19. uint8_t VersionSub;
  20. uint8_t VersionBranch;
  21. uint8_t VersionReleaseType;
  22. uint8_t MemorySizeSram2B; /*< Multiple of 1K */
  23. uint8_t MemorySizeSram2A; /*< Multiple of 1K */
  24. uint8_t MemorySizeSram1; /*< Multiple of 1K */
  25. uint8_t MemorySizeFlash; /*< Multiple of 4K */
  26. uint8_t StackType;
  27. /**
  28. * Fus Info
  29. */
  30. uint8_t FusVersionMajor;
  31. uint8_t FusVersionMinor;
  32. uint8_t FusVersionSub;
  33. uint8_t FusMemorySizeSram2B; /*< Multiple of 1K */
  34. uint8_t FusMemorySizeSram2A; /*< Multiple of 1K */
  35. uint8_t FusMemorySizeFlash; /*< Multiple of 4K */
  36. } BleGlueC2Info;
  37. typedef enum {
  38. // Stage 1: core2 startup and FUS
  39. BleGlueStatusStartup,
  40. BleGlueStatusBroken,
  41. BleGlueStatusC2Started,
  42. // Stage 2: radio stack
  43. BleGlueStatusRadioStackRunning,
  44. BleGlueStatusRadioStackMissing
  45. } BleGlueStatus;
  46. typedef void (
  47. *BleGlueKeyStorageChangedCallback)(uint8_t* change_addr_start, uint16_t size, void* context);
  48. /** Initialize start core2 and initialize transport */
  49. void ble_glue_init();
  50. /** Start Core2 Radio stack
  51. *
  52. * @return true on success
  53. */
  54. bool ble_glue_start();
  55. /** Is core2 alive and at least FUS is running
  56. *
  57. * @return true if core2 is alive
  58. */
  59. bool ble_glue_is_alive();
  60. /** Waits for C2 to reports its mode to callback
  61. *
  62. * @return true if it reported before reaching timeout
  63. */
  64. bool ble_glue_wait_for_c2_start(int32_t timeout);
  65. BleGlueStatus ble_glue_get_c2_status();
  66. const BleGlueC2Info* ble_glue_get_c2_info();
  67. /** Is core2 radio stack present and ready
  68. *
  69. * @return true if present and ready
  70. */
  71. bool ble_glue_is_radio_stack_ready();
  72. /** Set callback for NVM in RAM changes
  73. *
  74. * @param[in] callback The callback to call on NVM change
  75. * @param context The context for callback
  76. */
  77. void ble_glue_set_key_storage_changed_callback(
  78. BleGlueKeyStorageChangedCallback callback,
  79. void* context);
  80. /** Stop SHCI thread */
  81. void ble_glue_thread_stop();
  82. bool ble_glue_reinit_c2();
  83. typedef enum {
  84. BleGlueCommandResultUnknown,
  85. BleGlueCommandResultOK,
  86. BleGlueCommandResultError,
  87. BleGlueCommandResultRestartPending,
  88. BleGlueCommandResultOperationOngoing,
  89. } BleGlueCommandResult;
  90. /** Restart MCU to launch radio stack firmware if necessary
  91. *
  92. * @return true on radio stack start command
  93. */
  94. BleGlueCommandResult ble_glue_force_c2_mode(BleGlueC2Mode mode);
  95. BleGlueCommandResult ble_glue_fus_stack_delete();
  96. BleGlueCommandResult ble_glue_fus_stack_install(uint32_t src_addr, uint32_t dst_addr);
  97. BleGlueCommandResult ble_glue_fus_get_status();
  98. BleGlueCommandResult ble_glue_fus_wait_operation();
  99. #ifdef __cplusplus
  100. }
  101. #endif